Skip to content

Commit 2b5775b

Browse files
ampagenttmm
andcommitted
chore(zero-swift): follow upstream to sync protocol 57
Upstream's protocol versions 54-57 add aggregates, groupBy, distinct and JSON path filters to the query AST; zero-cache handles older clients the same, and the regenerated vectors differ only in the connect path (/sync/v53 to /sync/v57). This bumps protocolVersion, regenerates the vectors and codegen (a new login column in the test schema), widens the fuzz generator's right-hand type past the new json reference, and expects zbugs' drift test to report issueListCount (a count()) as not ported until the Swift client has aggregates. Co-authored-by: tmm <tmm@tmm.dev> Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859
1 parent a9c738e commit 2b5775b

17 files changed

Lines changed: 318 additions & 285 deletions

File tree

‎.changeset/sync-protocol-57.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'zero-swift': patch
3+
---
4+
5+
The client now speaks sync protocol 57, the version the JS client uses. Versions 54–57 only add query features the Swift client doesn't send yet (aggregates, `groupBy`, `distinct`, JSON path filters), so nothing else changes, and zero-cache keeps accepting older versions.

‎apps/zbugs-swift/Tests/ZBugsTests/DriftTests.swift‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import ZeroTesting
1313
.appendingPathComponent("drift-vectors.json"), encoding: .utf8)
1414
let failures = try Drift.failures(
1515
vectors: vectors, schema: .zbugs, queries: Queries.all, mutators: Mutators.all)
16-
#expect(failures == [])
16+
// Not ported yet: issueListCount is a count(), and the Swift client has no
17+
// aggregates. Exact, so this fails once it is ported and must be removed.
18+
#expect(failures == ["query issueListCount: no Swift definition"])
1719
}
1820
}

‎apps/zbugs-swift/Tests/ZBugsTests/drift-vectors.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"emojiChange",
1010
"issueDetail",
1111
"issueList",
12+
"issueListCount",
1213
"issueListV2",
1314
"issuePreloadV2",
1415
"labels",

‎packages/zero-conformance/src/primitives/ast.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ function literal(r: Random): ValuePosition {
6868
return {type: 'literal', value: r.pick(scalars)};
6969
}
7070

71-
function right(r: Random): Exclude<ValuePosition, {type: 'column'}> {
71+
function right(r: Random): Exclude<ValuePosition, {type: 'column' | 'json'}> {
7272
if (r.bool(0.1)) {
7373
return {
7474
type: 'static',
7575
anchor: r.pick(['authData', 'preMutationRow'] as const),
7676
field: r.bool() ? r.pick(['sub', 'role']) : ['a', r.pick(['b', 'c'])],
7777
};
7878
}
79-
return literal(r) as Exclude<ValuePosition, {type: 'column'}>;
79+
return literal(r) as Exclude<ValuePosition, {type: 'column' | 'json'}>;
8080
}
8181

8282
function left(r: Random): ValuePosition {

‎packages/zero-conformance/vectors/client-harden-connection.json‎

Lines changed: 62 additions & 62 deletions
Large diffs are not rendered by default.

‎packages/zero-conformance/vectors/client-harden-mutations.json‎

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

‎packages/zero-conformance/vectors/client.json‎

Lines changed: 149 additions & 149 deletions
Large diffs are not rendered by default.

‎packages/zero-conformance/vectors/harden-queries.json‎

Lines changed: 41 additions & 41 deletions
Large diffs are not rendered by default.

‎packages/zero-conformance/vectors/meta.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Protocol versions of the JS implementation the vectors were generated from.",
55
"cases": [
66
{
7-
"protocolVersion": 53,
7+
"protocolVersion": 57,
88
"minServerSupportedSyncProtocol": 30
99
}
1010
]

‎swift/DESIGN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Rationale:
125125
- `URLSessionTransport` implements it with `URLSessionWebSocketTask` and is the default socket on Apple platforms. It accepts frames up to 64 MB (a poke can exceed URLSession's 1 MB default) and reports the server's close code and reason, which the client's error handling reads. Like a browser `WebSocket`, it doesn't follow redirects of the upgrade, so the auth token never goes to another server. Unlike a browser, when the connection ends partway through a frame, URLSession returns the part it has as a whole message. So on its sockets, a message that doesn't make sense holds its error for up to 1 s: when the connection ends without a close frame by then, the client reconnects, as JS does after a browser's abrupt close; otherwise the error stands. Messages that make sense aren't delayed, and other transports keep JS's immediate error. Also unlike a browser, a close right after the upgrade can end the TCP connection without a close frame: URLSession reports the socket open before it has switched the connection to WebSocket (Network.framework logs `No connected endpoint handler found`). The server then sees an abrupt close instead of the code. Zero closes that early only when the app is hidden or the client closed while connecting, and zero-cache closes the connection the same way either way, only counting it as an `unclean_close` in its WebSocket error metric.
126126
- One writer task per connection sends frames in order.
127127
- Tests use an in-memory transport that replays scenario vectors, and, on Linux end-to-end runs, `NIOTransport` in `Tests/E2ETests` (plain `ws://`). Linux needs it because corelibs Foundation's `URLSessionWebSocketTask` compiles but never completes a connection. On macOS the end-to-end tests use `URLSessionTransport` (`ZERO_E2E_TRANSPORT=nio` switches back).
128-
- Wire details follow `zero-protocol`: connect to `/sync/v53/connect`, put `initConnection` and the auth token in `Sec-WebSocket-Protocol` while they fit under `maxHeaderLength`, and accept binary poke chunks (protocol 52 and later).
128+
- Wire details follow `zero-protocol`: connect to `/sync/v57/connect`, put `initConnection` and the auth token in `Sec-WebSocket-Protocol` while they fit under `maxHeaderLength`, and accept binary poke chunks (protocol 52 and later).
129129

130130
### App lifecycle and recovery
131131

0 commit comments

Comments
 (0)