@spooky-sync/core 0.0.1-canary.26 → 0.0.1-canary.260

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/AGENTS.md +78 -0
  2. package/README.md +56 -16
  3. package/dist/index.d.ts +2197 -80
  4. package/dist/index.js +12745 -2588
  5. package/dist/otel/index.d.ts +2 -2
  6. package/dist/otel/index.js +6 -6
  7. package/dist/sqlite-open.js +331 -0
  8. package/dist/sqlite-worker.d.ts +1 -0
  9. package/dist/sqlite-worker.js +439 -0
  10. package/dist/tabs-broker-worker.d.ts +8 -0
  11. package/dist/tabs-broker-worker.js +472 -0
  12. package/dist/types.d.ts +787 -46
  13. package/package.json +16 -8
  14. package/scripts/check-broker-bundle.mjs +33 -0
  15. package/skills/{spooky-core → sp00ky-core}/SKILL.md +30 -12
  16. package/skills/{spooky-core → sp00ky-core}/references/auth.md +1 -1
  17. package/skills/{spooky-core → sp00ky-core}/references/config.md +2 -2
  18. package/src/boot/auth-flip.saga.test.ts +82 -0
  19. package/src/boot/auth-flip.saga.ts +62 -0
  20. package/src/boot/boot.saga.test.ts +151 -0
  21. package/src/boot/boot.saga.ts +128 -0
  22. package/src/boot/bucket-switch.saga.test.ts +158 -0
  23. package/src/boot/bucket-switch.saga.ts +115 -0
  24. package/src/boot/preload.saga.test.ts +51 -0
  25. package/src/boot/preload.saga.ts +31 -0
  26. package/src/bucket-blurhash.test.ts +148 -0
  27. package/src/build-globals.d.ts +12 -0
  28. package/src/client/bucket-handle.test.ts +117 -0
  29. package/src/client/bucket-handle.ts +227 -0
  30. package/src/client/router.test.ts +56 -0
  31. package/src/client/router.ts +96 -0
  32. package/src/client/runtime.test.ts +192 -0
  33. package/src/client/runtime.ts +296 -0
  34. package/src/client/services.ts +382 -0
  35. package/src/client/sp00ky-client.test.ts +264 -0
  36. package/src/client/sp00ky-client.ts +499 -0
  37. package/src/events/events.test.ts +2 -1
  38. package/src/events/index.ts +3 -0
  39. package/src/index.ts +37 -2
  40. package/src/kernel/constants.test.ts +19 -0
  41. package/src/kernel/constants.ts +61 -0
  42. package/src/kernel/effects.test.ts +40 -0
  43. package/src/kernel/effects.ts +159 -0
  44. package/src/kernel/events.ts +56 -0
  45. package/src/kernel/interpreter.test.ts +116 -0
  46. package/src/kernel/interpreter.ts +148 -0
  47. package/src/kernel/saga.test.ts +89 -0
  48. package/src/kernel/saga.ts +73 -0
  49. package/src/modules/app-release/index.test.ts +125 -0
  50. package/src/modules/app-release/index.ts +209 -0
  51. package/src/modules/auth/auth.local-first.test.ts +141 -0
  52. package/src/modules/auth/events/index.ts +2 -1
  53. package/src/modules/auth/index.ts +138 -25
  54. package/src/modules/crdt/crdt-field.ts +294 -0
  55. package/src/modules/crdt/crdt-hydration.test.ts +210 -0
  56. package/src/modules/crdt/crdt-reconnect.test.ts +195 -0
  57. package/src/modules/crdt/index.ts +463 -0
  58. package/src/modules/crdt/loro-loader.ts +25 -0
  59. package/src/modules/devtools/flags.ts +349 -0
  60. package/src/modules/devtools/index.ts +459 -47
  61. package/src/modules/devtools/notify-throttle.test.ts +154 -0
  62. package/src/modules/devtools/state-shape.test.ts +149 -0
  63. package/src/modules/devtools/storage-info.test.ts +79 -0
  64. package/src/modules/devtools/storage-info.ts +168 -0
  65. package/src/modules/devtools/versions.test.ts +74 -0
  66. package/src/modules/devtools/versions.ts +110 -0
  67. package/src/modules/feature-flag/index.test.ts +251 -0
  68. package/src/modules/feature-flag/index.ts +316 -0
  69. package/src/modules/ref-tables.test.ts +91 -0
  70. package/src/modules/ref-tables.ts +88 -0
  71. package/src/mutation/jobs.test.ts +25 -0
  72. package/src/mutation/jobs.ts +41 -0
  73. package/src/mutation/mutation-id.test.ts +37 -0
  74. package/src/mutation/mutation-id.ts +35 -0
  75. package/src/mutation/push.saga.test.ts +285 -0
  76. package/src/mutation/push.saga.ts +215 -0
  77. package/src/mutation/rows.test.ts +201 -0
  78. package/src/mutation/rows.ts +377 -0
  79. package/src/mutation/tray.saga.test.ts +63 -0
  80. package/src/mutation/tray.saga.ts +48 -0
  81. package/src/mutation/write.saga.test.ts +163 -0
  82. package/src/mutation/write.saga.ts +166 -0
  83. package/src/otel/index.ts +13 -10
  84. package/src/query/env.test.ts +23 -0
  85. package/src/query/env.ts +56 -0
  86. package/src/query/fetch.saga.test.ts +156 -0
  87. package/src/query/fetch.saga.ts +115 -0
  88. package/src/query/hash.test.ts +14 -0
  89. package/src/query/hash.ts +18 -0
  90. package/src/query/id-set-plan.test.ts +132 -0
  91. package/src/query/lifecycle.saga.test.ts +122 -0
  92. package/src/query/lifecycle.saga.ts +101 -0
  93. package/src/query/materialize.saga.test.ts +82 -0
  94. package/src/query/materialize.saga.ts +75 -0
  95. package/src/query/materialize.test.ts +50 -0
  96. package/src/query/materialize.ts +44 -0
  97. package/src/query/membership.saga.test.ts +317 -0
  98. package/src/query/membership.saga.ts +262 -0
  99. package/src/query/membership.test.ts +118 -0
  100. package/src/query/membership.ts +171 -0
  101. package/src/query/register.saga.test.ts +293 -0
  102. package/src/query/register.saga.ts +226 -0
  103. package/src/query/render-set.test.ts +36 -0
  104. package/src/query/render-set.ts +60 -0
  105. package/src/query/sql.test.ts +62 -0
  106. package/src/query/sql.ts +79 -0
  107. package/src/query/window-query.test.ts +70 -0
  108. package/src/query/window-query.ts +195 -0
  109. package/src/services/blobs/blob-cache.test.ts +359 -0
  110. package/src/services/blobs/blob-cache.ts +603 -0
  111. package/src/services/blobs/blob-manifest.ts +227 -0
  112. package/src/services/blobs/blob-store.test.ts +77 -0
  113. package/src/services/blobs/blob-store.ts +359 -0
  114. package/src/services/blobs/blob.fixture.ts +90 -0
  115. package/src/services/blobs/index.ts +70 -0
  116. package/src/services/database/cache-engine.ts +193 -0
  117. package/src/services/database/connection-supervisor.test.ts +318 -0
  118. package/src/services/database/connection-supervisor.ts +422 -0
  119. package/src/services/database/database.query-timeout.test.ts +140 -0
  120. package/src/services/database/database.responses.test.ts +43 -0
  121. package/src/services/database/database.ts +145 -62
  122. package/src/services/database/engine-factory.ts +33 -0
  123. package/src/services/database/errors.ts +34 -0
  124. package/src/services/database/events/index.ts +2 -1
  125. package/src/services/database/index.ts +7 -0
  126. package/src/services/database/local-migrator.ts +30 -27
  127. package/src/services/database/local.test.ts +64 -0
  128. package/src/services/database/local.ts +484 -67
  129. package/src/services/database/plan-render.test.ts +159 -0
  130. package/src/services/database/plan-render.ts +108 -0
  131. package/src/services/database/relation-resolver.test.ts +467 -0
  132. package/src/services/database/relation-resolver.ts +0 -0
  133. package/src/services/database/remote.ts +222 -15
  134. package/src/services/database/sqlite-cache-engine.test.ts +617 -0
  135. package/src/services/database/sqlite-cache-engine.timeout.test.ts +61 -0
  136. package/src/services/database/sqlite-cache-engine.ts +1349 -0
  137. package/src/services/database/sqlite-devtools-queries.integration.test.ts +143 -0
  138. package/src/services/database/sqlite-devtools-queries.test.ts +154 -0
  139. package/src/services/database/sqlite-lock-verify.test.ts +33 -0
  140. package/src/services/database/sqlite-lock-verify.ts +45 -0
  141. package/src/services/database/sqlite-open.test.ts +150 -0
  142. package/src/services/database/sqlite-open.ts +164 -0
  143. package/src/services/database/sqlite-plan-sql.test.ts +104 -0
  144. package/src/services/database/sqlite-plan-sql.ts +153 -0
  145. package/src/services/database/sqlite-projection.test.ts +121 -0
  146. package/src/services/database/sqlite-select.integration.test.ts +185 -0
  147. package/src/services/database/sqlite-select.test.ts +246 -0
  148. package/src/services/database/sqlite-select.ts +131 -0
  149. package/src/services/database/sqlite-transport.fixture.ts +30 -0
  150. package/src/services/database/sqlite-transport.ts +224 -0
  151. package/src/services/database/sqlite-worker.ts +437 -0
  152. package/src/services/database/surql-translate.ts +416 -0
  153. package/src/services/database/surreal-cache-engine.ts +161 -0
  154. package/src/services/logger/index.ts +3 -2
  155. package/src/services/persistence/localstorage.ts +2 -2
  156. package/src/services/persistence/resilient.ts +11 -4
  157. package/src/services/persistence/surrealdb.ts +10 -10
  158. package/src/services/stream-processor/index.ts +796 -84
  159. package/src/services/stream-processor/permissions.test.ts +47 -0
  160. package/src/services/stream-processor/permissions.ts +53 -0
  161. package/src/services/stream-processor/stream-processor.batch.test.ts +186 -0
  162. package/src/services/stream-processor/stream-processor.prime.test.ts +198 -0
  163. package/src/services/stream-processor/stream-processor.reset.test.ts +226 -0
  164. package/src/services/stream-processor/stream-processor.test.ts +1 -1
  165. package/src/services/stream-processor/wasm-types.ts +59 -3
  166. package/src/services/tabs/broker-client.ts +283 -0
  167. package/src/services/tabs/broker.test.ts +327 -0
  168. package/src/services/tabs/coordinator.test.ts +365 -0
  169. package/src/services/tabs/coordinator.ts +633 -0
  170. package/src/services/tabs/fake-ports.fixture.ts +112 -0
  171. package/src/services/tabs/leader-locks.ts +75 -0
  172. package/src/services/tabs/protocol.ts +262 -0
  173. package/src/services/tabs/support.ts +36 -0
  174. package/src/services/tabs/tabs-broker-worker.ts +640 -0
  175. package/src/sp00ky.ts +5 -0
  176. package/src/state/client-state.ts +191 -0
  177. package/src/state/lifecycle.test.ts +118 -0
  178. package/src/state/lifecycle.ts +86 -0
  179. package/src/state/reducers.test.ts +280 -0
  180. package/src/state/reducers.ts +488 -0
  181. package/src/state/selectors.test.ts +149 -0
  182. package/src/state/selectors.ts +184 -0
  183. package/src/sync/connection.saga.test.ts +86 -0
  184. package/src/sync/connection.saga.ts +85 -0
  185. package/src/sync/live.saga.test.ts +178 -0
  186. package/src/sync/live.saga.ts +107 -0
  187. package/src/sync/policy.health.test.ts +56 -0
  188. package/src/sync/policy.test.ts +659 -0
  189. package/src/sync/policy.ts +502 -0
  190. package/src/sync/poll.saga.test.ts +51 -0
  191. package/src/sync/poll.saga.ts +36 -0
  192. package/src/sync/tabs.saga.test.ts +74 -0
  193. package/src/sync/tabs.saga.ts +93 -0
  194. package/src/testing/adapters.ts +133 -0
  195. package/src/testing/build.ts +63 -0
  196. package/src/testing/fake-services.ts +34 -0
  197. package/src/testing/run-pure.test.ts +92 -0
  198. package/src/testing/run-pure.ts +128 -0
  199. package/src/testing/services.ts +17 -0
  200. package/src/types.ts +591 -14
  201. package/src/utils/blurhash.ts +90 -0
  202. package/src/utils/error-classification.test.ts +54 -0
  203. package/src/utils/error-classification.ts +25 -0
  204. package/src/utils/index.ts +79 -13
  205. package/src/utils/parser.test.ts +49 -120
  206. package/src/utils/parser.ts +32 -2
  207. package/src/utils/semver.test.ts +32 -0
  208. package/src/utils/semver.ts +30 -0
  209. package/src/utils/surql.ts +30 -18
  210. package/src/utils/utils.test.ts +2 -1
  211. package/src/utils/withRetry.test.ts +1 -1
  212. package/tsdown.config.ts +86 -1
  213. package/vitest.config.ts +48 -0
  214. package/src/modules/cache/index.ts +0 -241
  215. package/src/modules/cache/types.ts +0 -19
  216. package/src/modules/data/data.test.ts +0 -58
  217. package/src/modules/data/index.ts +0 -879
  218. package/src/modules/sync/engine.ts +0 -173
  219. package/src/modules/sync/events/index.ts +0 -77
  220. package/src/modules/sync/index.ts +0 -3
  221. package/src/modules/sync/queue/index.ts +0 -2
  222. package/src/modules/sync/queue/queue-down.ts +0 -89
  223. package/src/modules/sync/queue/queue-up.ts +0 -223
  224. package/src/modules/sync/scheduler.ts +0 -84
  225. package/src/modules/sync/sync.ts +0 -421
  226. package/src/modules/sync/utils.test.ts +0 -311
  227. package/src/modules/sync/utils.ts +0 -167
  228. package/src/spooky.ts +0 -395
@@ -0,0 +1,158 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { RecordId } from 'surrealdb';
3
+ import { runPure } from '../testing/run-pure';
4
+ import { fakeServices } from '../testing/services';
5
+ import { buildEntry, buildOutboxItem, buildState } from '../testing/build';
6
+ import * as R from '../state/reducers';
7
+ import { defaultEnv } from '../query/env';
8
+ import { bucketSwitch, rebindQueries } from './bucket-switch.saga';
9
+
10
+ const env = defaultEnv({ tables: [] } as any);
11
+ const base = (over: Partial<ReturnType<typeof buildState>> = {}) => ({ ...buildState(), pendingBucket: 'u2', bucketId: 'u1', ...over });
12
+
13
+ describe('bucketSwitch', () => {
14
+ it('steps aside when superseded or already on target (releasing the gate)', async () => {
15
+ const released: number[] = [];
16
+ const svc = fakeServices({ 'local.currentBucketId': () => 'u1' });
17
+ await runPure(bucketSwitch(env, 'u2', () => void released.push(1)), { state: { ...base(), pendingBucket: 'u3' }, handlers: { service: svc.handler } });
18
+ await runPure(bucketSwitch(env, 'u1', () => void released.push(2)), { state: base({ pendingBucket: 'u1' }), handlers: { service: svc.handler } });
19
+ expect(released).toEqual([1, 2]);
20
+ expect(svc.names()).toEqual(['local.currentBucketId', 'local.currentBucketId']);
21
+ });
22
+ it('solo: drain, swap, provision, blobs, SSP reset, prime, token, rebind, outbox, re-register', async () => {
23
+ const svc = fakeServices({
24
+ 'local.currentBucketId': () => 'u1',
25
+ 'local.beginSwitch': () => () => undefined,
26
+ 'local.usesSurqlSchema': () => true,
27
+ 'auth.sessionAuthId': () => 'user:u2',
28
+ 'auth.access': () => 'account',
29
+ 'auth.token': () => 'jwt',
30
+ });
31
+ const s = base();
32
+ const withQ = R.compose(
33
+ R.putQuery(buildEntry({ def: { hash: 'a', viewKey: 'vk', surql: 'SELECT * FROM thing' }, lifecycle: { phase: 'live', remote: 'registered' }, remoteArray: [['t:1', 1]] })),
34
+ R.outboxReplace([buildOutboxItem()]),
35
+ R.setVersions([['t:1', 1]]),
36
+ R.markMembershipDirty(['a'])
37
+ )({ ...s, sessionId: 'sess2' });
38
+ const out = await runPure(bucketSwitch(env, 'u2'), {
39
+ state: withQ,
40
+ handlers: {
41
+ service: svc.handler,
42
+ 'local.getById': () => ({ ids: [['t:9', 1]], confirmed: true }),
43
+ 'ssp.register': () => ({ localArray: [['t:9', 1]], timings: {} }),
44
+ 'local.query': () => [],
45
+ },
46
+ });
47
+ expect(svc.names()).toEqual([
48
+ 'local.currentBucketId',
49
+ 'local.beginSwitch',
50
+ 'crdt.closeAll',
51
+ 'local.switchStore',
52
+ 'local.usesSurqlSchema',
53
+ 'migrator.provision',
54
+ 'blobs.setNamespace',
55
+ 'ssp.reset',
56
+ 'ssp.setPermissions',
57
+ 'auth.sessionAuthId',
58
+ 'auth.access',
59
+ 'ssp.setSessionAuth',
60
+ 'auth.token',
61
+ 'persistence.set',
62
+ ]);
63
+ expect(out.log.filter((e) => e.kind === 'timer.clear').map((e) => (e as any).key)).toEqual(['poll', 'outbox', 'membership', 'fetch', 'ack-prune']);
64
+ expect(out.state).toMatchObject({ bucketId: 'u2', primed: false, outbox: [] });
65
+ expect(out.state.versions.size).toBe(0);
66
+ expect(out.state.membershipDirty.size).toBe(0);
67
+ const e = out.state.queries.get('a')!;
68
+ expect(e.lifecycle).toMatchObject({ phase: 'cached', remote: 'unregistered' });
69
+ expect(e.remoteArray).toEqual([['t:9', 1]]);
70
+ expect(e.localArray).toEqual([['t:9', 1]]);
71
+ expect(String(e.def.id.table)).toBe('_00_query');
72
+ // PollTick is load-bearing: the switch cleared the poll timer, and only the
73
+ // tick re-arms it, so a sign-in without it leaves the client on LIVE alone.
74
+ expect(out.dispatched.map((d) => d.type)).toEqual(['PrimeCircuit', 'EnsureRegistered', 'LiveStart', 'PollTick', 'Drain']);
75
+ });
76
+ it('shared tabs: moves namespaces, falls back to solo on failure; blob clear on sign-out; failures are logged and the gate always reopens', async () => {
77
+ let gateReleased = false;
78
+ const moved = fakeServices({
79
+ 'local.currentBucketId': () => 'u1',
80
+ 'tabs.moveToBucket': async () => 'follower',
81
+ 'auth.sessionAuthId': () => null,
82
+ 'auth.access': () => null,
83
+ 'auth.token': () => null,
84
+ });
85
+ const out = await runPure(bucketSwitch(env, 'u2', () => void (gateReleased = true)), {
86
+ state: { ...base(), tabRole: 'leader' },
87
+ handlers: { service: moved.handler, 'local.query': () => [] },
88
+ });
89
+ expect(out.state.tabRole).toBe('follower');
90
+ expect(gateReleased).toBe(true);
91
+ expect(moved.names()).not.toContain('local.switchStore');
92
+ const failing = fakeServices({
93
+ 'local.currentBucketId': () => 'u1',
94
+ 'local.beginSwitch': () => () => undefined,
95
+ 'tabs.moveToBucket': async () => {
96
+ throw new Error('broker');
97
+ },
98
+ 'auth.sessionAuthId': () => null,
99
+ 'auth.access': () => null,
100
+ 'auth.token': () => 'jwt',
101
+ 'persistence.set': async () => {
102
+ throw new Error('kv');
103
+ },
104
+ 'blobs.setNamespace': async () => {
105
+ throw new Error('opfs');
106
+ },
107
+ });
108
+ const fb = await runPure(bucketSwitch(env, 'anon', null, { clearBlobsOnSignOut: true }), {
109
+ state: { ...base({ pendingBucket: 'anon' }), tabRole: 'leader' },
110
+ handlers: { service: failing.handler, 'local.query': () => [] },
111
+ });
112
+ expect(fb.state.tabRole).toBe('solo');
113
+ expect(failing.names()).toContain('local.beginSwitch');
114
+ expect(failing.names()).toContain('ssp.setPersistence');
115
+ expect(failing.names()).toContain('blobs.clear');
116
+ expect(fb.emitted.filter((e) => e.type === 'log')).toHaveLength(3);
117
+ });
118
+ it('a failing swap still reopens the gate and rethrows', async () => {
119
+ let released = false;
120
+ const svc = fakeServices({
121
+ 'local.currentBucketId': () => 'u1',
122
+ 'local.switchStore': async () => {
123
+ throw new Error('disk');
124
+ },
125
+ });
126
+ await expect(runPure(bucketSwitch(env, 'u2', () => void (released = true)), { state: base(), handlers: { service: svc.handler } })).rejects.toThrow('disk');
127
+ expect(released).toBe(true);
128
+ });
129
+ });
130
+
131
+ describe('rebindQueries', () => {
132
+ it('re-seeds from the new store, rebuilds the local view (tolerating failures), emits authority flips', async () => {
133
+ const s = R.compose(
134
+ R.putQuery(buildEntry({ def: { hash: 'a' }, lifecycle: { phase: 'live' } })),
135
+ R.putQuery(buildEntry({ def: { hash: 'b' }, lifecycle: { phase: 'cold' } }))
136
+ )({ ...buildState(), sessionId: 's' });
137
+ const out = await runPure(rebindQueries(), {
138
+ state: s,
139
+ handlers: {
140
+ 'local.getById': (e: any) => {
141
+ if (String((e.id as RecordId).id) === 'view-b') return { ids: [['t:1', 1]], confirmed: true };
142
+ throw new Error('missing');
143
+ },
144
+ 'ssp.register': (e: any) => {
145
+ if (e.plan.queryHash === 'a') throw new Error('wasm');
146
+ return { localArray: [['t:1', 1]], timings: {} };
147
+ },
148
+ },
149
+ });
150
+ expect(out.state.queries.get('a')!.lifecycle.phase).toBe('cold');
151
+ expect(out.state.queries.get('b')!.lifecycle.phase).toBe('cached');
152
+ expect(out.emitted.filter((e) => e.type === 'query:authority')).toEqual([
153
+ { type: 'query:authority', hash: 'a', known: false },
154
+ { type: 'query:authority', hash: 'b', known: true },
155
+ ]);
156
+ expect(out.emitted.some((e) => e.type === 'log')).toBe(true);
157
+ });
158
+ });
@@ -0,0 +1,115 @@
1
+ import { RecordId } from 'surrealdb';
2
+ import type { Saga } from '../kernel/saga';
3
+ import type { RegisterResult } from '../kernel/effects';
4
+ import { fx } from '../kernel/effects';
5
+ import type { ClientState, QueryEntry } from '../state/client-state';
6
+ import { seedLifecycle, isAuthoritative } from '../state/lifecycle';
7
+ import * as R from '../state/reducers';
8
+ import { ANON_USER_ID } from '../modules/ref-tables';
9
+ import type { SagaEnv } from '../query/env';
10
+ import { queryHashInput } from '../query/hash';
11
+ import { isResolvedBefore, parseViewRow } from '../query/membership';
12
+ import * as sql from '../query/sql';
13
+ import { loadOutbox } from '../mutation/push.saga';
14
+
15
+ export interface BucketSwitchOptions {
16
+ clearBlobsOnSignOut: boolean;
17
+ }
18
+
19
+ /**
20
+ * Move the client to another user's local store: drain, swap, rebind.
21
+ * Runs on the serial `bucket` lane; a switch that wakes up to a newer
22
+ * `pendingBucket` steps aside. Every active query keeps its hash and is
23
+ * re-seeded from the new store's `_00_view` rows, then re-registered.
24
+ */
25
+ export function* bucketSwitch(env: SagaEnv, target: string, release: (() => void) | null = null, opts: BucketSwitchOptions = { clearBlobsOnSignOut: false }): Saga<void> {
26
+ const state = (yield fx.state.read((s) => s)) as ClientState;
27
+ const current = (yield fx.service('local.currentBucketId')) as string;
28
+ if (state.pendingBucket !== target || current === target) {
29
+ release?.();
30
+ return;
31
+ }
32
+ const gate = release ?? ((yield fx.service('local.beginSwitch')) as () => void);
33
+ for (const key of ['poll', 'outbox', 'membership', 'fetch', 'ack-prune']) yield fx.timer.clear(key);
34
+ yield fx.state.update(R.clearBucketState());
35
+ yield fx.service('crdt.closeAll', false);
36
+ try {
37
+ if (state.tabRole !== 'solo') {
38
+ try {
39
+ const role = (yield fx.service('tabs.moveToBucket', target)) as ClientState['tabRole'];
40
+ yield fx.state.update(R.setTabRole(role));
41
+ } catch (error) {
42
+ yield fx.emit({ type: 'log', level: 'warn', message: 'shared-tabs bucket move failed; switching solo', data: { error } });
43
+ yield fx.state.update(R.setTabRole('solo'));
44
+ yield fx.service('ssp.setPersistence', true);
45
+ yield fx.service('local.switchStore', target);
46
+ }
47
+ } else {
48
+ yield fx.service('local.switchStore', target);
49
+ if ((yield fx.service('local.usesSurqlSchema')) as boolean) yield fx.service('migrator.provision');
50
+ }
51
+ try {
52
+ if (opts.clearBlobsOnSignOut && target === ANON_USER_ID && current !== ANON_USER_ID) yield fx.service('blobs.clear');
53
+ yield fx.service('blobs.setNamespace', target);
54
+ } catch (error) {
55
+ yield fx.emit({ type: 'log', level: 'warn', message: 'blob cache bucket switch failed', data: { error } });
56
+ }
57
+ yield fx.service('ssp.reset');
58
+ yield fx.service('ssp.setPermissions');
59
+ yield fx.service('ssp.setSessionAuth', (yield fx.service('auth.sessionAuthId')) as string | null, (yield fx.service('auth.access')) as string | null);
60
+ yield fx.state.update(R.setIdentity({ bucketId: target }));
61
+ yield fx.dispatch({ type: 'PrimeCircuit' });
62
+ } finally {
63
+ gate();
64
+ }
65
+ const token = (yield fx.service('auth.token')) as string | null;
66
+ if (token) {
67
+ try {
68
+ yield fx.service('persistence.set', 'sp00ky_auth_token', token);
69
+ } catch (error) {
70
+ yield fx.emit({ type: 'log', level: 'warn', message: 'failed to re-persist the auth token', data: { error } });
71
+ }
72
+ }
73
+ yield* rebindQueries();
74
+ yield* loadOutbox(env);
75
+ yield fx.dispatch({ type: 'EnsureRegistered' });
76
+ yield fx.dispatch({ type: 'LiveStart' });
77
+ // The switch cleared the poll timer, and only the tick itself re-arms it: a
78
+ // sign-in (auth flip -> bucket switch) otherwise left the client running on
79
+ // LIVE alone for the rest of the session, so any membership change LIVE did
80
+ // not deliver was never noticed.
81
+ yield fx.dispatch({ type: 'PollTick' });
82
+ yield fx.dispatch({ type: 'Drain' });
83
+ }
84
+
85
+ /** Re-seed every active query from the new store and rebuild its SSP view. */
86
+ export function* rebindQueries(): Saga<void> {
87
+ const [entries, sessionId] = (yield fx.state.read((s) => [[...s.queries.values()], s.sessionId])) as [QueryEntry[], string | null];
88
+ for (const entry of entries) {
89
+ let view: ReturnType<typeof parseViewRow> = null;
90
+ try {
91
+ view = parseViewRow(yield fx.local.getById(sql.VIEW_TABLE, sql.viewRecordId(entry.def.viewKey)));
92
+ } catch {
93
+ view = null;
94
+ }
95
+ const hash = (yield fx.hash(queryHashInput({ surql: entry.def.surql, params: entry.def.params as Record<string, unknown> }, sessionId))) as string;
96
+ let localArray: QueryEntry['localArray'] = [];
97
+ try {
98
+ const reg = (yield fx.ssp.register({
99
+ queryHash: entry.def.hash,
100
+ surql: entry.def.surql,
101
+ params: entry.def.params as Record<string, unknown>,
102
+ ttl: entry.def.ttl,
103
+ tableName: entry.def.tableName,
104
+ })) as RegisterResult;
105
+ localArray = reg.localArray;
106
+ } catch (error) {
107
+ yield fx.emit({ type: 'log', level: 'warn', message: 'local view rebuild failed after bucket switch', data: { hash: entry.def.hash, error } });
108
+ }
109
+ const lifecycle = seedLifecycle(isResolvedBefore(view));
110
+ yield fx.state.update(R.rebindQuery(entry.def.hash, { id: new RecordId('_00_query', hash), lifecycle, remoteArray: view?.ids ?? [], localArray }));
111
+ if (isAuthoritative(entry.lifecycle) !== isAuthoritative(lifecycle)) {
112
+ yield fx.emit({ type: 'query:authority', hash: entry.def.hash, known: isAuthoritative(lifecycle) });
113
+ }
114
+ }
115
+ }
@@ -0,0 +1,51 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { runPure, sha256Hex } from '../testing/run-pure';
3
+ import { buildEntry, buildState } from '../testing/build';
4
+ import * as R from '../state/reducers';
5
+ import { defaultEnv } from '../query/env';
6
+ import { queryHashInput } from '../query/hash';
7
+ import { preload, PreloadFailedError } from './preload.saga';
8
+
9
+ const env = defaultEnv({ tables: [{ name: 'thing', columns: {} }] } as any);
10
+ const input = { tableName: 'thing', surql: 'SELECT * FROM thing', params: {}, ttl: '10m' as const };
11
+ const sspOk = () => ({ localArray: [], timings: { parseMs: 0, planMs: 0, snapshotMs: 0, wallMs: 0 } });
12
+
13
+ describe('preload', () => {
14
+ it('resolved before: returns without waiting and with no remote effect', async () => {
15
+ const out = await runPure(preload(env, input), {
16
+ handlers: { 'local.getById': () => ({ ids: [['thing:1', 1]], confirmed: true }), 'ssp.register': sspOk },
17
+ });
18
+ expect(out.result.waited).toBe(false);
19
+ expect(out.log.filter((e) => e.kind === 'remote.query')).toHaveLength(0);
20
+ expect(out.log.filter((e) => e.kind === 'state.wait')).toHaveLength(0);
21
+ });
22
+ it('never resolved: waits for settled (membership + bodies + first render), or fails when the registration failed', async () => {
23
+ const hash = await sha256Hex(queryHashInput(input, null));
24
+ const settleIt = (ctx: any) => {
25
+ ctx.state = R.compose(
26
+ R.commitMembership(hash, [['thing:1', 1]], true),
27
+ R.setVersions([['thing:1', 1]]),
28
+ R.setRecords(hash, [{ id: 'thing:1' }], true, 1)
29
+ )(ctx.state);
30
+ };
31
+ const out = await runPure(preload(env, input), {
32
+ handlers: { 'local.getById': () => null, 'ssp.register': sspOk, 'state.wait': (_e, ctx) => settleIt(ctx) },
33
+ });
34
+ expect(out.result).toEqual({ hash, waited: true });
35
+ const failed = runPure(preload(env, input), {
36
+ handlers: {
37
+ 'local.getById': () => null,
38
+ 'ssp.register': sspOk,
39
+ 'state.wait': (_e, ctx) => void (ctx.state = R.applyLifecycle(hash, { type: 'remote-failed' })(ctx.state)),
40
+ },
41
+ });
42
+ await expect(failed).rejects.toBeInstanceOf(PreloadFailedError);
43
+ const gone = runPure(preload(env, input), {
44
+ handlers: { 'local.getById': () => null, 'ssp.register': sspOk, 'state.wait': (_e, ctx) => void (ctx.state = R.removeQuery(hash)(ctx.state)) },
45
+ });
46
+ await expect(gone).rejects.toThrow(/could not settle/);
47
+ const already = buildState([buildEntry({ def: { hash }, lifecycle: { phase: 'cached' } })]);
48
+ const cached = await runPure(preload(env, input), { state: already });
49
+ expect(cached.result.waited).toBe(false);
50
+ });
51
+ });
@@ -0,0 +1,31 @@
1
+ import type { QueryHash } from '../types';
2
+ import type { Saga } from '../kernel/saga';
3
+ import { fx } from '../kernel/effects';
4
+ import { settleFailed, settled } from '../state/selectors';
5
+ import type { SagaEnv } from '../query/env';
6
+ import type { RegisterInput } from '../query/register.saga';
7
+ import { registerLocal } from '../query/register.saga';
8
+
9
+ export class PreloadFailedError extends Error {
10
+ constructor(public readonly hash: QueryHash) {
11
+ super(`Preload could not settle: the registration of ${hash} failed`);
12
+ this.name = 'PreloadFailedError';
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Preload = a registered query nobody subscribes to. Resolved before on this
18
+ * device: returns as soon as the entry exists (its rows paint from cache).
19
+ * Never resolved: blocks until the server's membership and every body are
20
+ * local and the first materialization ran. The entry is evicted like any
21
+ * other query a ttl after it was last watched (or registered).
22
+ */
23
+ export function* preload(env: SagaEnv, input: RegisterInput): Saga<{ hash: QueryHash; waited: boolean }> {
24
+ const hash = yield* registerLocal(env, input);
25
+ const phase = (yield fx.state.read((s) => s.queries.get(hash)?.lifecycle.phase)) as string | undefined;
26
+ if (phase !== 'cold') return { hash, waited: false };
27
+ yield fx.state.wait((s) => settled(s, hash) || settleFailed(s, hash));
28
+ const failed = (yield fx.state.read((s) => settleFailed(s, hash))) as boolean;
29
+ if (failed) throw new PreloadFailedError(hash);
30
+ return { hash, waited: true };
31
+ }
@@ -0,0 +1,148 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { BucketHandle } from './sp00ky';
3
+ import type { RemoteDatabaseService } from './services/database/index';
4
+ import {
5
+ blurhashSidecarPath,
6
+ isImagePath,
7
+ encodeImageToBlurhash,
8
+ encodeBlurhash,
9
+ } from './utils/blurhash';
10
+
11
+ // A real 1x1 hash so isBlurhashValid passes in the read-path tests.
12
+ const VALID_HASH = encodeBlurhash(new Uint8ClampedArray([12, 34, 56, 255]), 1, 1, 1, 1);
13
+
14
+ function makeRemote(queries: string[]) {
15
+ return {
16
+ query: vi.fn(async (surql: string) => {
17
+ queries.push(surql);
18
+ return [null];
19
+ }),
20
+ } as unknown as RemoteDatabaseService;
21
+ }
22
+
23
+ describe('blurhash path helpers', () => {
24
+ it('appends .bh for the sidecar', () => {
25
+ expect(blurhashSidecarPath('a/b_t.webp')).toBe('a/b_t.webp.bh');
26
+ });
27
+
28
+ it('recognizes image extensions case-insensitively', () => {
29
+ expect(isImagePath('x/y.webp')).toBe(true);
30
+ expect(isImagePath('x/y.PNG')).toBe(true);
31
+ expect(isImagePath('x/y.webp.bh')).toBe(false);
32
+ expect(isImagePath('x/notes.txt')).toBe(false);
33
+ });
34
+ });
35
+
36
+ describe('encodeImageToBlurhash outside a browser', () => {
37
+ it('returns null instead of throwing (no createImageBitmap in node)', async () => {
38
+ await expect(encodeImageToBlurhash(new Uint8Array([1, 2, 3]))).resolves.toBeNull();
39
+ });
40
+ });
41
+
42
+ describe('BucketHandle.put', () => {
43
+ let queries: string[];
44
+
45
+ beforeEach(() => {
46
+ queries = [];
47
+ });
48
+
49
+ it('image put succeeds with blurhash null when encoding is unavailable', async () => {
50
+ const handle = new BucketHandle('covers', makeRemote(queries), null);
51
+ const result = await handle.put('a/b_t.webp', new Uint8Array([1]));
52
+ expect(result).toEqual({ blurhash: null });
53
+ // Only the image put went out; no sidecar for a failed/unavailable encode.
54
+ expect(queries).toHaveLength(1);
55
+ expect(queries[0]).toContain('covers:/a/b_t.webp".put');
56
+ });
57
+
58
+ it('skips hashing entirely for non-image paths and when disabled', async () => {
59
+ const handle = new BucketHandle('covers', makeRemote(queries), null, { blurhash: false });
60
+ await handle.put('a/b_t.webp', new Uint8Array([1]));
61
+ await handle.put('a/readme.txt', 'hello');
62
+ expect(queries).toHaveLength(2);
63
+ expect(queries.some((q) => q.includes('.bh'))).toBe(false);
64
+ });
65
+
66
+ it('writes the sidecar when a hash is produced', async () => {
67
+ // Simulate a browser: a createImageBitmap whose bitmap a canvas can read.
68
+ const pixels = { width: 2, height: 2 };
69
+ vi.stubGlobal(
70
+ 'createImageBitmap',
71
+ vi.fn(async () => ({ ...pixels, close: vi.fn() }))
72
+ );
73
+ vi.stubGlobal(
74
+ 'OffscreenCanvas',
75
+ class {
76
+ width: number;
77
+ height: number;
78
+ constructor(w: number, h: number) {
79
+ this.width = w;
80
+ this.height = h;
81
+ }
82
+ getContext() {
83
+ return {
84
+ drawImage: () => {},
85
+ getImageData: (_x: number, _y: number, w: number, h: number) => ({
86
+ data: new Uint8ClampedArray(w * h * 4).fill(128),
87
+ }),
88
+ };
89
+ }
90
+ }
91
+ );
92
+ try {
93
+ const handle = new BucketHandle('covers', makeRemote(queries), null);
94
+ const result = await handle.put('a/b_t.webp', new Uint8Array([1]));
95
+ expect(result.blurhash).toBeTruthy();
96
+ expect(queries).toHaveLength(2);
97
+ expect(queries[1]).toContain('covers:/a/b_t.webp.bh".put');
98
+ } finally {
99
+ vi.unstubAllGlobals();
100
+ }
101
+ });
102
+ });
103
+
104
+ describe('BucketHandle.blurhash', () => {
105
+ it('returns a valid stored hash and negative-caches misses per path', async () => {
106
+ const reads: string[] = [];
107
+ let payload: unknown = VALID_HASH;
108
+ const remote = {
109
+ query: vi.fn(async (surql: string) => {
110
+ reads.push(surql);
111
+ return [payload];
112
+ }),
113
+ } as unknown as RemoteDatabaseService;
114
+ const handle = new BucketHandle('covers', remote, null);
115
+
116
+ await expect(handle.blurhash('hit/x.webp')).resolves.toBe(VALID_HASH);
117
+
118
+ payload = null;
119
+ await expect(handle.blurhash('miss/x.webp')).resolves.toBeNull();
120
+ const readsAfterMiss = reads.length;
121
+ // The miss is remembered: no second remote read for the same path.
122
+ await expect(handle.blurhash('miss/x.webp')).resolves.toBeNull();
123
+ expect(reads).toHaveLength(readsAfterMiss);
124
+ });
125
+
126
+ it('treats invalid sidecar content as missing', async () => {
127
+ const remote = {
128
+ query: vi.fn(async () => ['not a blurhash \\ at all']),
129
+ } as unknown as RemoteDatabaseService;
130
+ const handle = new BucketHandle('covers', remote, null);
131
+ await expect(handle.blurhash('bad/x.webp')).resolves.toBeNull();
132
+ });
133
+ });
134
+
135
+ describe('BucketHandle.delete', () => {
136
+ it('also deletes the sidecar for image paths, best-effort', async () => {
137
+ const queries: string[] = [];
138
+ const handle = new BucketHandle('covers', makeRemote(queries), null);
139
+ await handle.delete('a/b_t.webp');
140
+ expect(queries).toHaveLength(2);
141
+ expect(queries[0]).toContain('covers:/a/b_t.webp".delete');
142
+ expect(queries[1]).toContain('covers:/a/b_t.webp.bh".delete');
143
+
144
+ queries.length = 0;
145
+ await handle.delete('a/notes.txt');
146
+ expect(queries).toHaveLength(1);
147
+ });
148
+ });
@@ -0,0 +1,12 @@
1
+ // Build-time string constants injected by tsdown's `define` (see
2
+ // tsdown.config.ts). They carry the real bundled frontend package versions so
3
+ // the DevTools can surface frontend/backend version drift.
4
+ //
5
+ // Typed as `string | undefined` on purpose: the substitution only happens when
6
+ // `@spooky-sync/core` is built with our tsdown plugin. A downstream app that
7
+ // bundles core from source never runs that plugin, so these identifiers must be
8
+ // guarded with `typeof` (see modules/devtools/index.ts) to avoid a runtime
9
+ // ReferenceError that would break DB initialization.
10
+ declare const __SP00KY_CORE_VERSION__: string | undefined;
11
+ declare const __SP00KY_WASM_VERSION__: string | undefined;
12
+ declare const __SP00KY_SURREAL_VERSION__: string | undefined;
@@ -0,0 +1,117 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { BucketHandle, bucketContentToBlob } from './bucket-handle';
3
+
4
+ vi.mock('../utils/blurhash', async (importOriginal) => {
5
+ const actual = await importOriginal<typeof import('../utils/blurhash')>();
6
+ return { ...actual, encodeImageToBlurhash: vi.fn(async () => 'LEHV6nWB2yk8pyo0adR*.7kCMdnj') };
7
+ });
8
+
9
+ function fakeRemote(answers: Record<string, unknown> = {}) {
10
+ const calls: Array<[string, unknown]> = [];
11
+ const remote = {
12
+ query: async (sql: string, vars?: unknown) => {
13
+ calls.push([sql, vars]);
14
+ for (const [needle, answer] of Object.entries(answers)) if (sql.includes(needle)) return [answer];
15
+ return [undefined];
16
+ },
17
+ } as any;
18
+ return { remote, calls };
19
+ }
20
+
21
+ function fakeBlobs() {
22
+ const log: string[] = [];
23
+ return {
24
+ log,
25
+ blobs: {
26
+ invalidate: async (k: { path: string }) => void log.push(`invalidate:${k.path}`),
27
+ read: async (k: { path: string }) => (k.path.endsWith('.bh') ? new Blob(['LEHV6nWB2yk8pyo0adR*.7kCMdnj']) : new Blob(['x'])),
28
+ acquireUrl: async (k: { path: string }) => ({ url: `blob:${k.path}`, release: () => undefined }),
29
+ setPinned: (k: { path: string }, pinned: boolean) => void log.push(`pin:${k.path}:${pinned}`),
30
+ prefetch: async (keys: Array<{ path: string }>) => void log.push(`prefetch:${keys.map((k) => k.path).join('+')}`),
31
+ } as any,
32
+ };
33
+ }
34
+
35
+ describe('bucketContentToBlob', () => {
36
+ it('coerces strings, buffers and views; passes blobs through; rejects the rest', async () => {
37
+ expect(bucketContentToBlob(null)).toBeNull();
38
+ expect(bucketContentToBlob(42)).toBeNull();
39
+ const b = new Blob(['a']);
40
+ expect(bucketContentToBlob(b)).toBe(b);
41
+ expect(await bucketContentToBlob('hi')!.text()).toBe('hi');
42
+ expect((await bucketContentToBlob(new ArrayBuffer(3))!.arrayBuffer()).byteLength).toBe(3);
43
+ expect((await bucketContentToBlob(new Uint8Array([1, 2]))!.arrayBuffer()).byteLength).toBe(2);
44
+ });
45
+ });
46
+
47
+ describe('BucketHandle', () => {
48
+ it('put: uploads, invalidates, writes the blurhash sidecar for images (best-effort), honours the setting', async () => {
49
+ const { remote, calls } = fakeRemote();
50
+ const { blobs, log } = fakeBlobs();
51
+ const warn = vi.fn();
52
+ const h = new BucketHandle('files', remote, blobs, { logger: { warn } });
53
+ const res = await h.put('a/pic.png', new Uint8Array([1]));
54
+ expect(res.blurhash).toBe('LEHV6nWB2yk8pyo0adR*.7kCMdnj');
55
+ expect(calls.map(([s]) => s)).toEqual(['RETURN f"files:/a/pic.png".put($content);', 'RETURN f"files:/a/pic.png.bh".put($content);']);
56
+ expect(log).toEqual(['invalidate:a/pic.png', 'invalidate:a/pic.png.bh']);
57
+ const off = new BucketHandle('files', remote, blobs, { blurhash: false });
58
+ expect((await off.put('b.png', 'x')).blurhash).toBeNull();
59
+ const perCall = new BucketHandle('files', remote, blobs, { blurhash: { componentX: 2 } });
60
+ expect((await perCall.put('c.txt', 'x', { blurhash: true })).blurhash).toBeNull();
61
+ expect((await perCall.put('c.png', 'x', { blurhash: { componentY: 3 } })).blurhash).toBeTruthy();
62
+ const failing = { query: async (sql: string) => { if (sql.includes('.bh')) throw new Error('sidecar'); return [undefined]; } } as any;
63
+ const sidecarFail = new BucketHandle('files', failing, blobs, { logger: { warn } });
64
+ expect((await sidecarFail.put('d.png', 'x')).blurhash).toBeNull();
65
+ expect(warn).toHaveBeenCalled();
66
+ const noBlobs = new BucketHandle('files', remote, null);
67
+ expect((await noBlobs.put('e.png', 'x')).blurhash).toBeTruthy();
68
+ });
69
+
70
+ it('blurhash: reads the sidecar through the cache, negative-caches misses, warns on invalid or failing reads', async () => {
71
+ const { remote } = fakeRemote();
72
+ const warn = vi.fn();
73
+ const { blobs } = fakeBlobs();
74
+ const h = new BucketHandle('bucketA', remote, blobs, { logger: { warn } });
75
+ expect(await h.blurhash('img.png')).toBe('LEHV6nWB2yk8pyo0adR*.7kCMdnj');
76
+ const missing = new BucketHandle('bucketB', remote, { ...blobs, read: async () => null } as any, { logger: { warn } });
77
+ expect(await missing.blurhash('none.png')).toBeNull();
78
+ expect(await missing.blurhash('none.png')).toBeNull();
79
+ const invalid = new BucketHandle('bucketC', remote, { ...blobs, read: async () => new Blob(['not-a-hash']) } as any, { logger: { warn } });
80
+ expect(await invalid.blurhash('bad.png')).toBeNull();
81
+ const throwing = new BucketHandle('bucketD', remote, { ...blobs, read: async () => { throw new Error('io'); } } as any, { logger: { warn } });
82
+ expect(await throwing.blurhash('err.png')).toBeNull();
83
+ expect(warn).toHaveBeenCalledTimes(2);
84
+ await new BucketHandle('bucketB', remote, blobs).put('none.png', 'x');
85
+ expect(await new BucketHandle('bucketB', remote, blobs).blurhash('none.png')).toBeTruthy();
86
+ });
87
+
88
+ it('get / read / url / pin / evict / prefetch / delete / exists / head / copy / rename / list', async () => {
89
+ const { remote, calls } = fakeRemote({ '.get()': 'content', '.exists()': true, '.head()': { size: 1 }, '.list()': ['a'] });
90
+ const { blobs, log } = fakeBlobs();
91
+ const h = new BucketHandle('files', remote, blobs);
92
+ expect(await h.get('p')).toBe('content');
93
+ expect(await (await h.read('p'))!.text()).toBe('x');
94
+ expect(await new BucketHandle('files', remote, null).read('p')).toBeInstanceOf(Blob);
95
+ expect(await h.url('p')).toEqual({ url: 'blob:p', release: expect.any(Function) });
96
+ expect(await new BucketHandle('files', remote, null).url('p')).toBeNull();
97
+ h.pin('p');
98
+ h.unpin('p');
99
+ await h.evict('p');
100
+ await h.prefetch(['a', 'b']);
101
+ await h.delete('doc.txt');
102
+ await h.delete('img.png');
103
+ const flaky = { query: async (sql: string) => { if (sql.includes('.bh".delete')) throw new Error('nope'); return [undefined]; } } as any;
104
+ await new BucketHandle('files', flaky, blobs).delete('img2.png');
105
+ expect(await h.exists('p')).toBe(true);
106
+ expect(await h.head('p')).toEqual({ size: 1 });
107
+ await h.copy('a', 'b');
108
+ await h.rename('a', 'b');
109
+ expect(await h.list()).toEqual(['a']);
110
+ expect(await h.list('pre/')).toEqual(['a']);
111
+ expect(log).toContain('pin:p:true');
112
+ expect(log).toContain('pin:p:false');
113
+ expect(log).toContain('prefetch:a+b');
114
+ expect(calls.some(([s]) => s === 'RETURN f"files:/img.png.bh".delete();')).toBe(true);
115
+ expect(calls.some(([s]) => s === 'RETURN f"files:/pre/".list();')).toBe(true);
116
+ });
117
+ });