@indigoai-us/hq-cloud 6.16.35 → 6.16.36

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 (84) hide show
  1. package/dist/bin/sync-runner-watch-loop.test.js +1 -2
  2. package/dist/bin/sync-runner-watch-loop.test.js.map +1 -1
  3. package/dist/bin/sync-runner.test.js +6 -24
  4. package/dist/bin/sync-runner.test.js.map +1 -1
  5. package/dist/company-vault-transport.d.ts +0 -2
  6. package/dist/company-vault-transport.d.ts.map +1 -1
  7. package/dist/company-vault-transport.js +0 -2
  8. package/dist/company-vault-transport.js.map +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/journal-row-store.d.ts +44 -1
  14. package/dist/journal-row-store.d.ts.map +1 -1
  15. package/dist/journal-row-store.js +226 -3
  16. package/dist/journal-row-store.js.map +1 -1
  17. package/dist/journal-snapshot-decoder.d.ts +18 -0
  18. package/dist/journal-snapshot-decoder.d.ts.map +1 -0
  19. package/dist/journal-snapshot-decoder.js +373 -0
  20. package/dist/journal-snapshot-decoder.js.map +1 -0
  21. package/dist/journal-snapshot-memory-helpers.d.ts +30 -0
  22. package/dist/journal-snapshot-memory-helpers.d.ts.map +1 -0
  23. package/dist/journal-snapshot-memory-helpers.js +203 -0
  24. package/dist/journal-snapshot-memory-helpers.js.map +1 -0
  25. package/dist/journal-snapshot-memory.test.d.ts +2 -0
  26. package/dist/journal-snapshot-memory.test.d.ts.map +1 -0
  27. package/dist/journal-snapshot-memory.test.js +32 -0
  28. package/dist/journal-snapshot-memory.test.js.map +1 -0
  29. package/dist/journal-snapshot-v4-memory.test.d.ts +2 -0
  30. package/dist/journal-snapshot-v4-memory.test.d.ts.map +1 -0
  31. package/dist/journal-snapshot-v4-memory.test.js +24 -0
  32. package/dist/journal-snapshot-v4-memory.test.js.map +1 -0
  33. package/dist/journal-snapshot-v4.d.ts +52 -0
  34. package/dist/journal-snapshot-v4.d.ts.map +1 -0
  35. package/dist/journal-snapshot-v4.js +352 -0
  36. package/dist/journal-snapshot-v4.js.map +1 -0
  37. package/dist/journal-snapshot-v4.test.d.ts +2 -0
  38. package/dist/journal-snapshot-v4.test.d.ts.map +1 -0
  39. package/dist/journal-snapshot-v4.test.js +280 -0
  40. package/dist/journal-snapshot-v4.test.js.map +1 -0
  41. package/dist/journal-store.test.js +156 -1
  42. package/dist/journal-store.test.js.map +1 -1
  43. package/dist/journal.d.ts +4 -2
  44. package/dist/journal.d.ts.map +1 -1
  45. package/dist/journal.js +41 -1
  46. package/dist/journal.js.map +1 -1
  47. package/dist/manifest/build-manifest.bench.test.js +165 -58
  48. package/dist/manifest/build-manifest.bench.test.js.map +1 -1
  49. package/dist/skill-telemetry.d.ts +1 -2
  50. package/dist/skill-telemetry.d.ts.map +1 -1
  51. package/dist/skill-telemetry.js +1 -10
  52. package/dist/skill-telemetry.js.map +1 -1
  53. package/dist/sync/child-process-sync-worker-env.test.d.ts +2 -0
  54. package/dist/sync/child-process-sync-worker-env.test.d.ts.map +1 -0
  55. package/dist/sync/child-process-sync-worker-env.test.js +38 -0
  56. package/dist/sync/child-process-sync-worker-env.test.js.map +1 -0
  57. package/dist/sync/feature-flags.d.ts +0 -16
  58. package/dist/sync/feature-flags.d.ts.map +1 -1
  59. package/dist/sync/feature-flags.js +0 -11
  60. package/dist/sync/feature-flags.js.map +1 -1
  61. package/dist/sync/index.d.ts +2 -2
  62. package/dist/sync/index.d.ts.map +1 -1
  63. package/dist/sync/index.js +1 -1
  64. package/dist/sync/index.js.map +1 -1
  65. package/dist/sync/logger.test.js +1 -3
  66. package/dist/sync/logger.test.js.map +1 -1
  67. package/dist/sync/metrics.test.js +0 -3
  68. package/dist/sync/metrics.test.js.map +1 -1
  69. package/dist/sync/push-receiver.d.ts +0 -7
  70. package/dist/sync/push-receiver.d.ts.map +1 -1
  71. package/dist/sync/push-receiver.js.map +1 -1
  72. package/dist/sync/state-store.d.ts +23 -0
  73. package/dist/sync/state-store.d.ts.map +1 -1
  74. package/dist/sync/state-store.js +114 -39
  75. package/dist/sync/state-store.js.map +1 -1
  76. package/dist/sync/state-store.test.js +82 -0
  77. package/dist/sync/state-store.test.js.map +1 -1
  78. package/dist/watcher.test.js +7 -8
  79. package/dist/watcher.test.js.map +1 -1
  80. package/package.json +1 -1
  81. package/dist/daemon-worker.d.ts +0 -11
  82. package/dist/daemon-worker.d.ts.map +0 -1
  83. package/dist/daemon-worker.js +0 -22
  84. package/dist/daemon-worker.js.map +0 -1
@@ -0,0 +1,352 @@
1
+ import * as crypto from "node:crypto";
2
+ import { createJournalRecordProxy } from "./journal-record-proxy.js";
3
+ import { JournalRowStore } from "./journal-row-store.js";
4
+ import { SNAPSHOT_V4_MAGIC } from "./sync/state-store.js";
5
+ export const JOURNAL_SNAPSHOT_V4_MAGIC = SNAPSHOT_V4_MAGIC;
6
+ const SNAPSHOT_FIXED_HEADER_BYTES = 52;
7
+ const SECTION_ALIGNMENT_BYTES = 8;
8
+ const decodedRows = new WeakMap();
9
+ let decodeMemorySampleHookForTest;
10
+ /** Return the packed views installed while decoding an HQSNAP4 payload, if any. */
11
+ export function decodedV4JournalRows(journal) {
12
+ return decodedRows.get(journal);
13
+ }
14
+ /** Test-only seam after v4 chunks become one contiguous decoder payload. */
15
+ export function setV4JournalSnapshotDecodeMemorySampleHookForTest(hook) {
16
+ decodeMemorySampleHookForTest = hook;
17
+ }
18
+ /**
19
+ * HQSNAP4 payload, frozen for the reader-before-writer release.
20
+ *
21
+ * The outer 52-byte StateStore header is unchanged: bytes 0..7 are ASCII
22
+ * `HQSNAP4\\0`; bytes 8..15 are the unsigned generation (big-endian); bytes
23
+ * 16..19 are the unsigned payload length (big-endian); bytes 20..51 are the
24
+ * 32-byte scope digest. A trailing SHA-256 covers that header and every payload
25
+ * byte. The payload is the following ordered sequence of sections. Each section
26
+ * is `u32be byteLength`, exact bytes, then zero padding until the next section's
27
+ * data starts on an eight-byte boundary. There is no implicit or optional
28
+ * section, and padding bytes must be zero.
29
+ *
30
+ * 1. metadata JSON: `{lastRecordSequence,state:{journal:{version,lastSync,pulls}},rowCount}`;
31
+ * it deliberately omits `journal.files`.
32
+ * 2. directories JSON string table (id 0 is `""`).
33
+ * 3. leafBlob raw bytes; every leaf is the row-store's `u32le UTF-8 length`
34
+ * followed by its UTF-8 bytes.
35
+ * 4. hashes: `rowCount * 32` raw bytes.
36
+ * 5. remoteEtags: `rowCount * 16` raw bytes.
37
+ * 6. sizes, mtimes, ctimes, syncedAts: each `rowCount` IEEE-754 binary64 LE.
38
+ * 7. flags: `rowCount` unsigned 16-bit LE values.
39
+ * 8. createdBySubs, dirIds, leaves: each `rowCount` unsigned 32-bit LE values.
40
+ * 9. propertyOrderIds: `rowCount` unsigned 16-bit LE values.
41
+ * 10. iterationNext and iterationPrevious: each `rowCount` signed 32-bit LE values.
42
+ * 11. buckets: unsigned 32-bit LE values; its power-of-two length is encoded by
43
+ * this section's byte length.
44
+ * 12. hashFallbacks, etagFallbacks, syncedAtFallbacks, leafFallbacks, removedAts,
45
+ * removedReasons, localDeleteIntents, authors, and propertyOrders: one JSON
46
+ * section each, in exactly that order. Map sections are sorted `[rowId,value]`
47
+ * pairs; `authors` id 0 is `""`; property orders are string-key arrays.
48
+ *
49
+ * The raw typed-array sections are little-endian. Node deployments are
50
+ * little-endian; a big-endian host rejects HQSNAP4 rather than writing or
51
+ * interpreting a different byte format.
52
+ */
53
+ export function encodeV4JournalSnapshot(generation, scopeDigest, payload) {
54
+ assertLittleEndian();
55
+ if (!Number.isSafeInteger(generation) || generation < 0)
56
+ throw new Error("HQSNAP4 requires a safe nonnegative generation");
57
+ if (scopeDigest.length !== 32)
58
+ throw new Error("HQSNAP4 requires a 32-byte scope digest");
59
+ validatePayload(payload);
60
+ const rows = new JournalRowStore(Object.keys(payload.state.journal.files).length, { trackChanges: false });
61
+ for (const [entryPath, entry] of Object.entries(payload.state.journal.files))
62
+ rows.set(entryPath, entry);
63
+ const snapshot = rows.toSnapshot();
64
+ const metadata = {
65
+ lastRecordSequence: payload.lastRecordSequence,
66
+ state: {
67
+ journal: {
68
+ version: payload.state.journal.version,
69
+ lastSync: payload.state.journal.lastSync,
70
+ ...(payload.state.journal.pulls === undefined ? {} : { pulls: payload.state.journal.pulls }),
71
+ },
72
+ },
73
+ rowCount: snapshot.rowCount,
74
+ };
75
+ const sections = new V4SectionWriter();
76
+ sections.json(metadata);
77
+ sections.json(snapshot.directories);
78
+ sections.raw(snapshot.leafBlob);
79
+ sections.raw(snapshot.hashes);
80
+ sections.raw(snapshot.remoteEtags);
81
+ sections.raw(snapshot.sizes);
82
+ sections.raw(snapshot.mtimes);
83
+ sections.raw(snapshot.ctimes);
84
+ sections.raw(snapshot.syncedAts);
85
+ sections.raw(snapshot.flags);
86
+ sections.raw(snapshot.createdBySubs);
87
+ sections.raw(snapshot.dirIds);
88
+ sections.raw(snapshot.leaves);
89
+ sections.raw(snapshot.propertyOrderIds);
90
+ sections.raw(snapshot.iterationNext);
91
+ sections.raw(snapshot.iterationPrevious);
92
+ sections.raw(snapshot.buckets);
93
+ sections.json(snapshot.hashFallbacks);
94
+ sections.json(snapshot.etagFallbacks);
95
+ sections.json(snapshot.syncedAtFallbacks);
96
+ sections.json(snapshot.leafFallbacks);
97
+ sections.json(snapshot.removedAts);
98
+ sections.json(snapshot.removedReasons);
99
+ sections.json(snapshot.localDeleteIntents);
100
+ sections.json(snapshot.authors);
101
+ sections.json(snapshot.propertyOrders);
102
+ const body = sections.finish();
103
+ const header = Buffer.alloc(SNAPSHOT_FIXED_HEADER_BYTES);
104
+ JOURNAL_SNAPSHOT_V4_MAGIC.copy(header, 0);
105
+ header.writeBigUInt64BE(BigInt(generation), 8);
106
+ header.writeUInt32BE(body.length, 16);
107
+ scopeDigest.copy(header, 20);
108
+ const checksum = crypto.createHash("sha256").update(header).update(body).digest();
109
+ return Buffer.concat([header, body, checksum]);
110
+ }
111
+ /** Decode an authenticated HQSNAP4 payload into row-store views, never JSON rows. */
112
+ export function decodeV4JournalSnapshot(chunks) {
113
+ assertLittleEndian();
114
+ const body = Buffer.allocUnsafe(chunks.byteLength);
115
+ let offset = 0;
116
+ for (const chunk of chunks) {
117
+ if (chunk.length > body.length - offset)
118
+ throw new Error("HQSNAP4 payload has an invalid byte length");
119
+ chunk.copy(body, offset);
120
+ offset += chunk.length;
121
+ }
122
+ if (offset !== body.length)
123
+ throw new Error("HQSNAP4 payload has an invalid byte length");
124
+ decodeMemorySampleHookForTest?.();
125
+ const sections = new V4SectionReader(body);
126
+ const metadata = decodeMetadata(sections.json("metadata"));
127
+ const snapshot = {
128
+ rowCount: metadata.rowCount,
129
+ directories: decodeStrings(sections.json("directories"), "directory"),
130
+ leafBlob: sections.uint8("leaf blob"),
131
+ hashes: sections.uint8("hashes"),
132
+ remoteEtags: sections.uint8("remote etags"),
133
+ sizes: sections.float64("sizes"),
134
+ mtimes: sections.float64("mtimes"),
135
+ ctimes: sections.float64("ctimes"),
136
+ syncedAts: sections.float64("synced ats"),
137
+ flags: sections.uint16("flags"),
138
+ createdBySubs: sections.uint32("created-by subs"),
139
+ dirIds: sections.uint32("directory ids"),
140
+ leaves: sections.uint32("leaves"),
141
+ propertyOrderIds: sections.uint16("property order ids"),
142
+ iterationNext: sections.int32("iteration next"),
143
+ iterationPrevious: sections.int32("iteration previous"),
144
+ buckets: sections.uint32("buckets"),
145
+ hashFallbacks: decodeStringEntries(sections.json("hash fallbacks"), "hash fallback"),
146
+ etagFallbacks: decodeStringEntries(sections.json("etag fallbacks"), "etag fallback"),
147
+ syncedAtFallbacks: decodeStringEntries(sections.json("synced-at fallbacks"), "synced-at fallback"),
148
+ leafFallbacks: decodeStringEntries(sections.json("leaf fallbacks"), "leaf fallback"),
149
+ removedAts: decodeStringEntries(sections.json("removed ats"), "removed-at"),
150
+ removedReasons: decodeRemovedReasons(sections.json("removed reasons")),
151
+ localDeleteIntents: decodeLocalDeleteIntents(sections.json("local delete intents")),
152
+ authors: decodeStrings(sections.json("authors"), "author"),
153
+ propertyOrders: decodePropertyOrders(sections.json("property orders")),
154
+ };
155
+ sections.finish();
156
+ const rows = JournalRowStore.fromSnapshot(snapshot);
157
+ const journal = {
158
+ files: createJournalRecordProxy(rows),
159
+ version: metadata.version,
160
+ lastSync: metadata.lastSync,
161
+ ...(metadata.pulls === undefined ? {} : { pulls: metadata.pulls }),
162
+ };
163
+ decodedRows.set(journal, rows);
164
+ return { lastRecordSequence: metadata.lastRecordSequence, state: { journal } };
165
+ }
166
+ class V4SectionWriter {
167
+ chunks = [];
168
+ length = 0;
169
+ json(value) {
170
+ this.raw(Buffer.from(JSON.stringify(value), "utf8"));
171
+ }
172
+ raw(values) {
173
+ const bytes = Buffer.from(values.buffer, values.byteOffset, values.byteLength);
174
+ const length = Buffer.alloc(4);
175
+ length.writeUInt32BE(bytes.length);
176
+ this.chunks.push(length, bytes);
177
+ this.length += length.length + bytes.length;
178
+ const padding = paddingAfterSection(this.length);
179
+ if (padding !== 0) {
180
+ this.chunks.push(Buffer.alloc(padding));
181
+ this.length += padding;
182
+ }
183
+ }
184
+ finish() {
185
+ return Buffer.concat(this.chunks, this.length);
186
+ }
187
+ }
188
+ class V4SectionReader {
189
+ body;
190
+ offset = 0;
191
+ constructor(body) {
192
+ this.body = body;
193
+ }
194
+ json(label) {
195
+ const bytes = this.section(label);
196
+ try {
197
+ return JSON.parse(bytes.toString("utf8"));
198
+ }
199
+ catch (error) {
200
+ throw new Error(`HQSNAP4 has invalid ${label} JSON`, { cause: error });
201
+ }
202
+ }
203
+ uint8(label) {
204
+ return this.section(label);
205
+ }
206
+ uint16(label) {
207
+ return this.typed(label, Uint16Array);
208
+ }
209
+ uint32(label) {
210
+ return this.typed(label, Uint32Array);
211
+ }
212
+ int32(label) {
213
+ return this.typed(label, Int32Array);
214
+ }
215
+ float64(label) {
216
+ return this.typed(label, Float64Array);
217
+ }
218
+ finish() {
219
+ if (this.offset !== this.body.length)
220
+ throw new Error("HQSNAP4 has trailing bytes");
221
+ }
222
+ section(label) {
223
+ if (this.offset + 4 > this.body.length)
224
+ throw new Error(`HQSNAP4 has a truncated ${label} length`);
225
+ const length = this.body.readUInt32BE(this.offset);
226
+ const start = this.offset + 4;
227
+ const end = start + length;
228
+ if (end > this.body.length || end < start)
229
+ throw new Error(`HQSNAP4 has a truncated ${label}`);
230
+ this.offset = end;
231
+ const padding = paddingAfterSection(this.offset);
232
+ if (this.offset + padding > this.body.length)
233
+ throw new Error(`HQSNAP4 has truncated ${label} padding`);
234
+ for (let index = 0; index < padding; index += 1) {
235
+ if (this.body[this.offset + index] !== 0)
236
+ throw new Error(`HQSNAP4 has nonzero ${label} padding`);
237
+ }
238
+ this.offset += padding;
239
+ return this.body.subarray(start, end);
240
+ }
241
+ typed(label, Type) {
242
+ const bytes = this.section(label);
243
+ if (bytes.byteLength % Type.BYTES_PER_ELEMENT !== 0 || bytes.byteOffset % Type.BYTES_PER_ELEMENT !== 0) {
244
+ throw new Error(`HQSNAP4 has an unaligned ${label} section`);
245
+ }
246
+ return new Type(bytes.buffer, bytes.byteOffset, bytes.byteLength / Type.BYTES_PER_ELEMENT);
247
+ }
248
+ }
249
+ function paddingAfterSection(offset) {
250
+ return (SECTION_ALIGNMENT_BYTES + 4 - (offset % SECTION_ALIGNMENT_BYTES)) % SECTION_ALIGNMENT_BYTES;
251
+ }
252
+ function decodeMetadata(value) {
253
+ if (!isRecord(value))
254
+ throw new Error("HQSNAP4 has invalid metadata");
255
+ const lastRecordSequence = value.lastRecordSequence;
256
+ const rowCount = value.rowCount;
257
+ const state = value.state;
258
+ if (typeof lastRecordSequence !== "number" || !Number.isSafeInteger(lastRecordSequence) || lastRecordSequence < 0
259
+ || typeof rowCount !== "number" || !Number.isSafeInteger(rowCount) || rowCount < 0 || !isRecord(state)
260
+ || !isRecord(state.journal))
261
+ throw new Error("HQSNAP4 has invalid metadata");
262
+ const journal = state.journal;
263
+ if ((journal.version !== "1" && journal.version !== "2") || typeof journal.lastSync !== "string"
264
+ || (journal.pulls !== undefined && !Array.isArray(journal.pulls)))
265
+ throw new Error("HQSNAP4 has invalid journal metadata");
266
+ return {
267
+ lastRecordSequence,
268
+ rowCount,
269
+ version: journal.version,
270
+ lastSync: journal.lastSync,
271
+ ...(journal.pulls === undefined ? {} : { pulls: journal.pulls }),
272
+ };
273
+ }
274
+ function decodeStrings(value, label) {
275
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
276
+ throw new Error(`HQSNAP4 has an invalid ${label} table`);
277
+ }
278
+ return value;
279
+ }
280
+ function decodeStringEntries(value, label) {
281
+ if (!Array.isArray(value))
282
+ throw new Error(`HQSNAP4 has invalid ${label} entries`);
283
+ return value.map((item) => {
284
+ if (!Array.isArray(item) || item.length !== 2 || !Number.isInteger(item[0]) || typeof item[1] !== "string") {
285
+ throw new Error(`HQSNAP4 has an invalid ${label} entry`);
286
+ }
287
+ return [item[0], item[1]];
288
+ });
289
+ }
290
+ function decodeRemovedReasons(value) {
291
+ const validReasons = new Set(["scope_shrink", "narrow_apply", "manual", "local-delete"]);
292
+ const entries = decodeStringEntries(value, "removed-reason");
293
+ if (entries.some(([, reason]) => !validReasons.has(reason)))
294
+ throw new Error("HQSNAP4 has an invalid removed reason");
295
+ return entries;
296
+ }
297
+ function decodeLocalDeleteIntents(value) {
298
+ if (!Array.isArray(value))
299
+ throw new Error("HQSNAP4 has invalid local delete intents");
300
+ return value.map((item) => {
301
+ if (!Array.isArray(item) || item.length !== 2 || !Number.isInteger(item[0]) || !isRecord(item[1])) {
302
+ throw new Error("HQSNAP4 has an invalid local delete intent");
303
+ }
304
+ const intent = item[1];
305
+ if (intent.version !== 1 || typeof intent.remoteEtag !== "string" || typeof intent.localHash !== "string"
306
+ || (intent.localKind !== "file" && intent.localKind !== "symlink")) {
307
+ throw new Error("HQSNAP4 has an invalid local delete intent");
308
+ }
309
+ return [item[0], {
310
+ version: 1,
311
+ remoteEtag: intent.remoteEtag,
312
+ localHash: intent.localHash,
313
+ localKind: intent.localKind,
314
+ }];
315
+ });
316
+ }
317
+ function decodePropertyOrders(value) {
318
+ if (!Array.isArray(value) || value.some((order) => !Array.isArray(order) || order.some((key) => typeof key !== "string"))) {
319
+ throw new Error("HQSNAP4 has invalid property orders");
320
+ }
321
+ return value;
322
+ }
323
+ function validatePayload(payload) {
324
+ if (!Number.isSafeInteger(payload.lastRecordSequence) || payload.lastRecordSequence < 0
325
+ || !isRecord(payload.state) || !isJournal(payload.state.journal)) {
326
+ throw new Error("HQSNAP4 has an invalid journal payload");
327
+ }
328
+ }
329
+ function isJournal(value) {
330
+ if (!isRecord(value) || (value.version !== "1" && value.version !== "2") || typeof value.lastSync !== "string" || !isRecord(value.files)) {
331
+ return false;
332
+ }
333
+ if (value.pulls !== undefined && !Array.isArray(value.pulls))
334
+ return false;
335
+ return Object.values(value.files).every(isJournalEntry);
336
+ }
337
+ function isJournalEntry(value) {
338
+ if (!isRecord(value) || typeof value.hash !== "string" || typeof value.size !== "number"
339
+ || !Number.isFinite(value.size) || typeof value.syncedAt !== "string"
340
+ || (value.direction !== "up" && value.direction !== "down"))
341
+ return false;
342
+ return true;
343
+ }
344
+ function isRecord(value) {
345
+ return typeof value === "object" && value !== null && !Array.isArray(value);
346
+ }
347
+ function assertLittleEndian() {
348
+ const probe = new Uint16Array([1]);
349
+ if (new Uint8Array(probe.buffer)[0] !== 1)
350
+ throw new Error("HQSNAP4 requires a little-endian host");
351
+ }
352
+ //# sourceMappingURL=journal-snapshot-v4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-snapshot-v4.js","sourceRoot":"","sources":["../src/journal-snapshot-v4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAgC,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAiC,MA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MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;WACnF,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ;WAClE,CAAC,KAAK,CAAC,SAAS,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,KAAK,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,kBAAkB;IACzB,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;AACtG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=journal-snapshot-v4.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-snapshot-v4.test.d.ts","sourceRoot":"","sources":["../src/journal-snapshot-v4.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,280 @@
1
+ import * as crypto from "node:crypto";
2
+ import * as fs from "node:fs";
3
+ import * as os from "node:os";
4
+ import * as path from "node:path";
5
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
6
+ import { readJournal, openJournalStateStoreForMigration, writeJournal } from "./journal.js";
7
+ import { JournalRowStore } from "./journal-row-store.js";
8
+ import { decodeV3JournalSnapshot } from "./journal-snapshot-decoder.js";
9
+ import { decodeV4JournalSnapshot, decodedV4JournalRows, encodeV4JournalSnapshot, JOURNAL_SNAPSHOT_V4_MAGIC, } from "./journal-snapshot-v4.js";
10
+ const FIXTURE_PATH = new URL("../test/fixtures/hqsnap4-golden.bin", import.meta.url);
11
+ const GOLDEN_FIXTURE_BYTES = 9512;
12
+ const GOLDEN_FIXTURE_SHA256 = "74f43775d7929f9fc23f103fcb1cd335076119feb787e0855a4dbf313b27f318";
13
+ let stateDir = "";
14
+ function leafStorage(store) {
15
+ return store;
16
+ }
17
+ function snapshotChunks(bytes) {
18
+ return Object.assign([bytes], { byteLength: bytes.length });
19
+ }
20
+ /**
21
+ * This fixture covers the v4 round trip, not storage-schema completeness.
22
+ * `JOURNAL_ENTRY_STORAGE` at `src/journal-row-store.ts:20` is the real guard:
23
+ * its `Record<keyof JournalEntry, "column" | "side-table">` constraint runs
24
+ * during typecheck and rejects an unmapped JournalEntry field.
25
+ */
26
+ function allJournalEntryFields() {
27
+ return {
28
+ hash: "a".repeat(64),
29
+ size: 1,
30
+ syncedAt: "2026-09-11T00:00:00.000Z",
31
+ direction: "up",
32
+ kind: "file",
33
+ createdBySub: "author",
34
+ remoteEtag: "b".repeat(32),
35
+ mtimeMs: 1,
36
+ ctimeMs: 2,
37
+ removedAt: "2026-09-11T00:00:01.000Z",
38
+ removedReason: "manual",
39
+ localDeleteIntent: {
40
+ version: 1,
41
+ remoteEtag: "c".repeat(32),
42
+ localHash: "d".repeat(64),
43
+ localKind: "symlink",
44
+ },
45
+ outOfScopeProtected: true,
46
+ skillMetadataPending: false,
47
+ localDiverges: true,
48
+ };
49
+ }
50
+ function fixtureJournal() {
51
+ const files = {};
52
+ for (let index = 0; index < 36; index += 1) {
53
+ const entry = {
54
+ hash: index % 2 === 0 ? index.toString(16).padStart(64, "0") : `short-hash-${index}`,
55
+ size: index + 0.25,
56
+ syncedAt: index % 3 === 0 ? `not-an-iso-${index}` : new Date(1_700_000_000_000 + index).toISOString(),
57
+ direction: index % 2 === 0 ? "up" : "down",
58
+ };
59
+ if (index % 2 === 0)
60
+ entry.kind = index % 4 === 0 ? "symlink" : "file";
61
+ if (index % 3 === 0)
62
+ entry.createdBySub = `author-${index % 5}`;
63
+ if (index % 4 === 0)
64
+ entry.remoteEtag = index % 8 === 0 ? `${index}`.padStart(32, "a") : `multipart-etag-${index}-4`;
65
+ if (index % 5 === 0)
66
+ entry.mtimeMs = 1_700_000_100_000 + index;
67
+ if (index % 6 === 0)
68
+ entry.ctimeMs = 1_700_000_200_000 + index;
69
+ if (index % 7 === 0) {
70
+ entry.removedAt = new Date(1_700_000_300_000 + index).toISOString();
71
+ entry.removedReason = index % 14 === 0 ? "local-delete" : "scope_shrink";
72
+ }
73
+ if (index % 8 === 0) {
74
+ entry.localDeleteIntent = {
75
+ version: 1,
76
+ remoteEtag: "e".repeat(32),
77
+ localHash: `${index}`.padStart(64, "f"),
78
+ localKind: index % 16 === 0 ? "symlink" : "file",
79
+ };
80
+ }
81
+ if (index % 9 === 0)
82
+ entry.outOfScopeProtected = index % 18 === 0;
83
+ if (index % 10 === 0)
84
+ entry.skillMetadataPending = index % 20 === 0;
85
+ if (index % 11 === 0)
86
+ entry.localDiverges = index % 22 === 0;
87
+ const leaf = index === 35 ? "ill-\ud800.md" : `entry-${index}.md`;
88
+ files[`directory-${index % 4}/nested-${index % 3}/${leaf}`] = entry;
89
+ }
90
+ return {
91
+ version: "2",
92
+ lastSync: "fixture-last-sync",
93
+ files,
94
+ pulls: [{
95
+ pullId: "01J7QW3TR3K0V2R2Y7JCF0XQ4R",
96
+ companyUid: "fixture-company",
97
+ startedAt: "2026-09-11T00:00:00.000Z",
98
+ completedAt: "2026-09-11T00:01:00.000Z",
99
+ syncMode: "custom",
100
+ prefixSet: ["directory-0", "directory-1"],
101
+ scopeChangeDetected: true,
102
+ orphansRemoved: 3,
103
+ orphansBlocked: 4,
104
+ }],
105
+ };
106
+ }
107
+ function payload(journal, lastRecordSequence = 17) {
108
+ return { lastRecordSequence, state: { journal } };
109
+ }
110
+ function emptyJournal() {
111
+ return { version: "2", lastSync: "", files: {}, pulls: [] };
112
+ }
113
+ function threeRowJournal() {
114
+ const files = {};
115
+ for (const leaf of ["first.md", "second.md", "third.md"])
116
+ files[`cyclic/${leaf}`] = allJournalEntryFields();
117
+ return { version: "2", lastSync: "three-row-journal", files, pulls: [] };
118
+ }
119
+ function withCyclicIterationChain(bytes) {
120
+ const malformed = Buffer.from(bytes);
121
+ const body = malformed.subarray(52, -32);
122
+ let offset = 0;
123
+ const section = (index) => {
124
+ const length = body.readUInt32BE(offset);
125
+ const start = offset + 4;
126
+ const end = start + length;
127
+ offset = end + ((8 + 4 - (end % 8)) % 8);
128
+ if (index !== 14 && index !== 15)
129
+ return Buffer.alloc(0);
130
+ return body.subarray(start, end);
131
+ };
132
+ let iterationNext;
133
+ let iterationPrevious;
134
+ for (let index = 0; index <= 15; index += 1) {
135
+ const current = section(index);
136
+ if (index === 14)
137
+ iterationNext = current;
138
+ if (index === 15)
139
+ iterationPrevious = current;
140
+ }
141
+ if (iterationNext === undefined || iterationPrevious === undefined
142
+ || iterationNext.length !== 12 || iterationPrevious.length !== 12) {
143
+ throw new Error("test setup did not locate the three-row iteration sections");
144
+ }
145
+ for (const [index, value] of [1, 0, -1].entries())
146
+ iterationNext.writeInt32LE(value, index * 4);
147
+ for (const [index, value] of [-1, 0, 1].entries())
148
+ iterationPrevious.writeInt32LE(value, index * 4);
149
+ crypto.createHash("sha256").update(malformed.subarray(0, -32)).digest().copy(malformed, malformed.length - 32);
150
+ return malformed;
151
+ }
152
+ function normalised(value) {
153
+ return JSON.parse(JSON.stringify(value));
154
+ }
155
+ beforeEach(() => {
156
+ stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-hqsnap4-"));
157
+ process.env.HQ_STATE_DIR = stateDir;
158
+ });
159
+ afterEach(() => {
160
+ delete process.env.HQ_STATE_DIR;
161
+ fs.rmSync(stateDir, { recursive: true, force: true });
162
+ });
163
+ describe("HQSNAP4 reader contract", () => {
164
+ it("round-trips every JournalEntry field and journal metadata without JSON row parsing", () => {
165
+ const expected = payload(fixtureJournal());
166
+ const bytes = encodeV4JournalSnapshot(9, crypto.createHash("sha256").update("fixture-scope").digest(), expected);
167
+ expect(bytes.subarray(0, 8)).toEqual(JOURNAL_SNAPSHOT_V4_MAGIC);
168
+ expect(normalised(decodeV4JournalSnapshot(snapshotChunks(bytes.subarray(52, -32))))).toEqual(expected);
169
+ });
170
+ it("decodes v3 and v4 representations of the same logical journal identically", () => {
171
+ const expected = payload(fixtureJournal());
172
+ const v3 = Buffer.from(JSON.stringify(expected), "utf8");
173
+ const v4 = encodeV4JournalSnapshot(3, crypto.createHash("sha256").update("equivalence").digest(), expected);
174
+ expect(normalised(decodeV4JournalSnapshot(snapshotChunks(v4.subarray(52, -32))))).toEqual(normalised(decodeV3JournalSnapshot(snapshotChunks(v3))));
175
+ });
176
+ it("decodes the immutable golden fixture with its exact bytes and checksum", () => {
177
+ const bytes = fs.readFileSync(FIXTURE_PATH);
178
+ expect(bytes.subarray(0, 8)).toEqual(JOURNAL_SNAPSHOT_V4_MAGIC);
179
+ expect(bytes).toHaveLength(GOLDEN_FIXTURE_BYTES);
180
+ expect(crypto.createHash("sha256").update(bytes).digest("hex")).toBe(GOLDEN_FIXTURE_SHA256);
181
+ expect(normalised(decodeV4JournalSnapshot(snapshotChunks(bytes.subarray(52, -32))))).toEqual(payload(fixtureJournal()));
182
+ });
183
+ it.each([
184
+ ["truncated", (bytes) => bytes.subarray(0, bytes.length - 5)],
185
+ ["checksum-mismatched", (bytes) => {
186
+ const corrupt = Buffer.from(bytes);
187
+ corrupt[corrupt.length - 1] ^= 0xff;
188
+ return corrupt;
189
+ }],
190
+ ])("uses the existing recovery ladder when the newest v4 generation is %s", (_name, corrupt) => {
191
+ const slug = "hqsnap4-recovery";
192
+ const prior = fixtureJournal();
193
+ const latest = fixtureJournal();
194
+ latest.files["directory-0/nested-0/latest.md"] = allJournalEntryFields();
195
+ writeJournal(slug, prior);
196
+ const store = openJournalStateStoreForMigration(slug);
197
+ store.replaceState(payload(latest, 7).state);
198
+ const snapshotPath = path.join(store.stateDir, `snapshot-${store.getGeneration()}.bin`);
199
+ const existing = fs.readFileSync(snapshotPath);
200
+ const v4 = encodeV4JournalSnapshot(store.getGeneration(), existing.subarray(20, 52), payload(latest, 7));
201
+ fs.writeFileSync(snapshotPath, corrupt(v4));
202
+ expect(normalised(readJournal(slug))).toEqual(normalised(prior));
203
+ });
204
+ it("floors a zero-row v4 snapshot leaf capacity to the constructor minimum", () => {
205
+ const bytes = encodeV4JournalSnapshot(1, crypto.createHash("sha256").update("zero-row-capacity").digest(), payload(emptyJournal()));
206
+ const decoded = decodeV4JournalSnapshot(snapshotChunks(bytes.subarray(52, -32)));
207
+ const rows = decodedV4JournalRows(decoded.state.journal);
208
+ expect(rows).toBeDefined();
209
+ expect(leafStorage(rows).leafBlob.length).toBeGreaterThanOrEqual(leafStorage(new JournalRowStore()).leafBlob.length);
210
+ });
211
+ it("grows a zero-length leaf blob within two doublings", () => {
212
+ const store = new JournalRowStore();
213
+ const storage = leafStorage(store);
214
+ const initialCapacity = storage.leafBlob.length;
215
+ const maximumDoublings = 2;
216
+ const leaf = new Uint8Array(initialCapacity * 3);
217
+ const requiredCapacity = leaf.length + 4;
218
+ storage.leafBlob = new Uint8Array(0);
219
+ storage.leafLength = 0;
220
+ expect(storage.appendLeaf(leaf)).toBe(0);
221
+ expect(storage.leafLength).toBe(requiredCapacity);
222
+ expect(storage.leafBlob.length).toBeGreaterThanOrEqual(requiredCapacity);
223
+ expect(storage.leafBlob.length).toBeLessThanOrEqual(initialCapacity * 2 ** maximumDoublings);
224
+ });
225
+ it("grows a zero-length leaf blob far beyond its initial capacity", () => {
226
+ const store = new JournalRowStore();
227
+ const storage = leafStorage(store);
228
+ const leaf = new Uint8Array(storage.leafBlob.length * 64);
229
+ const requiredCapacity = leaf.length + 4;
230
+ storage.leafBlob = new Uint8Array(0);
231
+ storage.leafLength = 0;
232
+ expect(storage.appendLeaf(leaf)).toBe(0);
233
+ expect(storage.leafLength).toBe(requiredCapacity);
234
+ expect(storage.leafBlob.length).toBeGreaterThanOrEqual(requiredCapacity);
235
+ expect(storage.leafBlob.length).toBeLessThan(requiredCapacity * 2);
236
+ });
237
+ it("rejects a cyclic v4 iteration chain and recovers the previous generation", () => {
238
+ const slug = "hqsnap4-cyclic-iteration";
239
+ const prior = fixtureJournal();
240
+ const latest = threeRowJournal();
241
+ writeJournal(slug, prior);
242
+ const store = openJournalStateStoreForMigration(slug);
243
+ const priorGeneration = store.getGeneration();
244
+ store.replaceState(payload(latest, store.getLastRecordSequence()).state);
245
+ const snapshotPath = path.join(store.stateDir, `snapshot-${store.getGeneration()}.bin`);
246
+ const existing = fs.readFileSync(snapshotPath);
247
+ const v4 = encodeV4JournalSnapshot(store.getGeneration(), existing.subarray(20, 52), payload(store.getState().journal, store.getLastRecordSequence()));
248
+ fs.writeFileSync(snapshotPath, withCyclicIterationChain(v4));
249
+ const recovered = openJournalStateStoreForMigration(slug);
250
+ expect(recovered.getGeneration()).toBe(priorGeneration);
251
+ expect(normalised(recovered.getState().journal)).toEqual(normalised(prior));
252
+ }, 1_000);
253
+ it("replays WAL frames after a nonzero v4 snapshot and appends after an empty v4 WAL", () => {
254
+ const slug = "hqsnap4-wal";
255
+ const initial = fixtureJournal();
256
+ writeJournal(slug, initial);
257
+ const store = openJournalStateStoreForMigration(slug);
258
+ const sequenceOne = store.append(2, {
259
+ version: "2",
260
+ lastSync: initial.lastSync,
261
+ deletes: [],
262
+ upserts: { "directory-0/nested-0/wal-one.md": allJournalEntryFields() },
263
+ });
264
+ store.compact();
265
+ const snapshotPath = path.join(store.stateDir, `snapshot-${store.getGeneration()}.bin`);
266
+ const existing = fs.readFileSync(snapshotPath);
267
+ const compacted = store.getState();
268
+ fs.writeFileSync(snapshotPath, encodeV4JournalSnapshot(store.getGeneration(), existing.subarray(20, 52), payload(compacted.journal, sequenceOne.sequence)));
269
+ const recovered = openJournalStateStoreForMigration(slug);
270
+ const sequenceTwo = recovered.append(2, {
271
+ version: "2",
272
+ lastSync: initial.lastSync,
273
+ deletes: [],
274
+ upserts: { "directory-0/nested-0/wal-two.md": allJournalEntryFields() },
275
+ });
276
+ expect(normalised(readJournal(slug).files["directory-0/nested-0/wal-two.md"])).toEqual(allJournalEntryFields());
277
+ expect(sequenceTwo.sequence).toBe(sequenceOne.sequence + 1);
278
+ });
279
+ });
280
+ //# sourceMappingURL=journal-snapshot-v4.test.js.map