@indigoai-us/hq-cloud 6.18.9 → 6.18.10-alpha.0
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.
- package/dist/bin/sync-runner-args.test.d.ts +2 -0
- package/dist/bin/sync-runner-args.test.d.ts.map +1 -0
- package/dist/bin/sync-runner-args.test.js +82 -0
- package/dist/bin/sync-runner-args.test.js.map +1 -0
- package/dist/bin/sync-runner-company.d.ts +1 -0
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +3 -0
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-company.test.js +31 -0
- package/dist/bin/sync-runner-company.test.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +58 -12
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.test.js +71 -0
- package/dist/bin/sync-runner-watch-loop.test.js.map +1 -1
- package/dist/bin/sync-runner-watch-routes.d.ts +2 -1
- package/dist/bin/sync-runner-watch-routes.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-routes.js +14 -3
- package/dist/bin/sync-runner-watch-routes.js.map +1 -1
- package/dist/bin/sync-runner-watch-routes.test.js +15 -0
- package/dist/bin/sync-runner-watch-routes.test.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +67 -0
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +52 -1
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +23 -3
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +2 -0
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +76 -0
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +13 -2
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +81 -4
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +228 -0
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/journal.d.ts +9 -0
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +21 -2
- package/dist/journal.js.map +1 -1
- package/dist/journal.test.js +16 -1
- package/dist/journal.test.js.map +1 -1
- package/dist/sync/content-hash.d.ts +4 -0
- package/dist/sync/content-hash.d.ts.map +1 -0
- package/dist/sync/content-hash.js +11 -0
- package/dist/sync/content-hash.js.map +1 -0
- package/dist/sync/content-hash.test.d.ts +2 -0
- package/dist/sync/content-hash.test.d.ts.map +1 -0
- package/dist/sync/content-hash.test.js +16 -0
- package/dist/sync/content-hash.test.js.map +1 -0
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +58 -1
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/event-sync.test.js +46 -0
- package/dist/sync/event-sync.test.js.map +1 -1
- package/dist/sync/logger.test.js +3 -0
- package/dist/sync/logger.test.js.map +1 -1
- package/dist/sync/metrics.test.js +3 -0
- package/dist/sync/metrics.test.js.map +1 -1
- package/dist/sync/push-receiver.d.ts +52 -0
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +413 -50
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +629 -40
- package/dist/sync/push-receiver.test.js.map +1 -1
- package/dist/sync/unchanged-push-events.d.ts +16 -0
- package/dist/sync/unchanged-push-events.d.ts.map +1 -0
- package/dist/sync/unchanged-push-events.js +51 -0
- package/dist/sync/unchanged-push-events.js.map +1 -0
- package/dist/sync/unchanged-push-events.test.d.ts +2 -0
- package/dist/sync/unchanged-push-events.test.d.ts.map +1 -0
- package/dist/sync/unchanged-push-events.test.js +76 -0
- package/dist/sync/unchanged-push-events.test.js.map +1 -0
- package/package.json +1 -1
package/dist/cli/sync.test.js
CHANGED
|
@@ -1467,6 +1467,7 @@ describe("sync", () => {
|
|
|
1467
1467
|
},
|
|
1468
1468
|
deleteMessage: async ({ receiptHandle }) => { deleted.push(receiptHandle); },
|
|
1469
1469
|
changeMessageVisibility: async () => { },
|
|
1470
|
+
changeMessageVisibilityBatch: async () => ({ failedEntries: [] }),
|
|
1470
1471
|
};
|
|
1471
1472
|
const results = [];
|
|
1472
1473
|
const receiver = new SqsPushReceiver({
|
|
@@ -1523,6 +1524,7 @@ describe("sync", () => {
|
|
|
1523
1524
|
},
|
|
1524
1525
|
deleteMessage: async ({ receiptHandle }) => { deleted.push(receiptHandle); },
|
|
1525
1526
|
changeMessageVisibility: async () => { },
|
|
1527
|
+
changeMessageVisibilityBatch: async () => ({ failedEntries: [] }),
|
|
1526
1528
|
};
|
|
1527
1529
|
let attempts = 0;
|
|
1528
1530
|
const receiver = new SqsPushReceiver({
|
|
@@ -3223,6 +3225,232 @@ describe("sync", () => {
|
|
|
3223
3225
|
}
|
|
3224
3226
|
expect(fs.readFileSync(localPath, "utf-8")).toBe("unchanged body");
|
|
3225
3227
|
});
|
|
3228
|
+
it("downloads the listed revision when an older same-size announcement arrives late", async () => {
|
|
3229
|
+
const companyDocs = path.join(tmpDir, "companies", "acme", "docs");
|
|
3230
|
+
fs.mkdirSync(companyDocs, { recursive: true });
|
|
3231
|
+
const localPath = path.join(companyDocs, "handoff.md");
|
|
3232
|
+
const revisionA = "revision A body\n";
|
|
3233
|
+
const revisionB = "revision B body\n";
|
|
3234
|
+
expect(Buffer.byteLength(revisionA)).toBe(Buffer.byteLength(revisionB));
|
|
3235
|
+
fs.writeFileSync(localPath, revisionA);
|
|
3236
|
+
const stat = fs.lstatSync(localPath);
|
|
3237
|
+
const hashA = crypto.createHash("sha256").update(revisionA).digest("hex");
|
|
3238
|
+
const hashB = crypto.createHash("sha256").update(revisionB).digest("hex");
|
|
3239
|
+
const listedRevisionB = {
|
|
3240
|
+
key: "docs/handoff.md",
|
|
3241
|
+
size: Buffer.byteLength(revisionB),
|
|
3242
|
+
lastModified: new Date(),
|
|
3243
|
+
etag: '"revision-b-etag"',
|
|
3244
|
+
};
|
|
3245
|
+
writeJournal("acme", {
|
|
3246
|
+
version: "2",
|
|
3247
|
+
lastSync: new Date().toISOString(),
|
|
3248
|
+
pulls: [],
|
|
3249
|
+
files: {
|
|
3250
|
+
"docs/handoff.md": {
|
|
3251
|
+
hash: hashA,
|
|
3252
|
+
size: stat.size,
|
|
3253
|
+
mtimeMs: stat.mtimeMs,
|
|
3254
|
+
ctimeMs: stat.ctimeMs,
|
|
3255
|
+
remoteEtag: "revision-a-etag",
|
|
3256
|
+
syncedAt: new Date(Date.now() - 3600000).toISOString(),
|
|
3257
|
+
direction: "down",
|
|
3258
|
+
kind: "file",
|
|
3259
|
+
},
|
|
3260
|
+
},
|
|
3261
|
+
});
|
|
3262
|
+
const listRemoteFiles = vi.mocked(s3Module.listRemoteFiles);
|
|
3263
|
+
const originalListImplementation = listRemoteFiles.getMockImplementation();
|
|
3264
|
+
listRemoteFiles.mockResolvedValue([listedRevisionB]);
|
|
3265
|
+
vi.mocked(s3Module.headRemoteFile).mockResolvedValueOnce({
|
|
3266
|
+
etag: '"revision-b-etag"',
|
|
3267
|
+
size: Buffer.byteLength(revisionB),
|
|
3268
|
+
lastModified: new Date(),
|
|
3269
|
+
metadata: { [s3Module.FILE_CONTENT_SHA256_META_KEY]: hashB },
|
|
3270
|
+
});
|
|
3271
|
+
vi.mocked(s3Module.downloadFile).mockImplementationOnce(async (_ctx, _key, stagedPath, options) => {
|
|
3272
|
+
fs.mkdirSync(path.dirname(stagedPath), { recursive: true });
|
|
3273
|
+
options?.beforeReplace?.();
|
|
3274
|
+
fs.writeFileSync(stagedPath, revisionB);
|
|
3275
|
+
return {
|
|
3276
|
+
metadata: { [s3Module.FILE_CONTENT_SHA256_META_KEY]: hashB },
|
|
3277
|
+
contentHash: hashB,
|
|
3278
|
+
contentSize: Buffer.byteLength(revisionB),
|
|
3279
|
+
};
|
|
3280
|
+
});
|
|
3281
|
+
try {
|
|
3282
|
+
await sync({
|
|
3283
|
+
company: "acme",
|
|
3284
|
+
onConflict: "keep",
|
|
3285
|
+
vaultConfig: mockConfig,
|
|
3286
|
+
hqRoot: tmpDir,
|
|
3287
|
+
pullPrefixes: ["docs/handoff.md"],
|
|
3288
|
+
// This delayed event describes A, while LIST and HEAD describe B.
|
|
3289
|
+
pullContentHashes: { "docs/handoff.md": `sha256:${hashA}` },
|
|
3290
|
+
skipReindex: true,
|
|
3291
|
+
});
|
|
3292
|
+
expect(vi.mocked(s3Module.downloadFile)).toHaveBeenCalledTimes(1);
|
|
3293
|
+
expect(fs.readFileSync(localPath, "utf8")).toBe(revisionB);
|
|
3294
|
+
expect(readJournal("acme").files["docs/handoff.md"]).toMatchObject({
|
|
3295
|
+
hash: hashB,
|
|
3296
|
+
remoteEtag: "revision-b-etag",
|
|
3297
|
+
});
|
|
3298
|
+
// B's later announcement sees B's bytes and ETag already committed.
|
|
3299
|
+
await sync({
|
|
3300
|
+
company: "acme",
|
|
3301
|
+
onConflict: "keep",
|
|
3302
|
+
vaultConfig: mockConfig,
|
|
3303
|
+
hqRoot: tmpDir,
|
|
3304
|
+
pullPrefixes: ["docs/handoff.md"],
|
|
3305
|
+
pullContentHashes: { "docs/handoff.md": `sha256:${hashB}` },
|
|
3306
|
+
skipReindex: true,
|
|
3307
|
+
});
|
|
3308
|
+
expect(vi.mocked(s3Module.downloadFile)).toHaveBeenCalledTimes(1);
|
|
3309
|
+
expect(fs.readFileSync(localPath, "utf8")).toBe(revisionB);
|
|
3310
|
+
}
|
|
3311
|
+
finally {
|
|
3312
|
+
if (originalListImplementation) {
|
|
3313
|
+
listRemoteFiles.mockImplementation(originalListImplementation);
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
});
|
|
3317
|
+
it("updates the remote ETag without downloading when a targeted event matches clean journal bytes", async () => {
|
|
3318
|
+
const companyDocs = path.join(tmpDir, "companies", "acme", "docs");
|
|
3319
|
+
fs.mkdirSync(companyDocs, { recursive: true });
|
|
3320
|
+
const localPath = path.join(companyDocs, "handoff.md");
|
|
3321
|
+
const localContent = "unchanged body";
|
|
3322
|
+
fs.writeFileSync(localPath, localContent);
|
|
3323
|
+
const stat = fs.lstatSync(localPath);
|
|
3324
|
+
const hash = crypto.createHash("sha256").update(localContent).digest("hex");
|
|
3325
|
+
writeJournal("acme", {
|
|
3326
|
+
version: "2",
|
|
3327
|
+
lastSync: new Date().toISOString(),
|
|
3328
|
+
pulls: [],
|
|
3329
|
+
files: {
|
|
3330
|
+
"docs/handoff.md": {
|
|
3331
|
+
hash,
|
|
3332
|
+
size: stat.size,
|
|
3333
|
+
mtimeMs: stat.mtimeMs,
|
|
3334
|
+
ctimeMs: stat.ctimeMs,
|
|
3335
|
+
remoteEtag: "old-etag",
|
|
3336
|
+
syncedAt: new Date(Date.now() - 3600000).toISOString(),
|
|
3337
|
+
direction: "down",
|
|
3338
|
+
kind: "file",
|
|
3339
|
+
},
|
|
3340
|
+
},
|
|
3341
|
+
});
|
|
3342
|
+
vi.mocked(s3Module.listRemoteFiles).mockResolvedValueOnce([
|
|
3343
|
+
{ key: "docs/handoff.md", size: stat.size, lastModified: new Date(), etag: '"new-etag"' },
|
|
3344
|
+
]);
|
|
3345
|
+
vi.mocked(s3Module.headRemoteFile).mockResolvedValueOnce({
|
|
3346
|
+
etag: '"new-etag"',
|
|
3347
|
+
size: stat.size,
|
|
3348
|
+
lastModified: new Date(),
|
|
3349
|
+
metadata: { [s3Module.FILE_CONTENT_SHA256_META_KEY]: hash },
|
|
3350
|
+
});
|
|
3351
|
+
const result = await sync({
|
|
3352
|
+
company: "acme",
|
|
3353
|
+
onConflict: "keep",
|
|
3354
|
+
vaultConfig: mockConfig,
|
|
3355
|
+
hqRoot: tmpDir,
|
|
3356
|
+
pullPrefixes: ["docs/handoff.md"],
|
|
3357
|
+
pullContentHashes: { "docs/handoff.md": `sha256:${hash}` },
|
|
3358
|
+
skipReindex: true,
|
|
3359
|
+
});
|
|
3360
|
+
expect(vi.mocked(s3Module.downloadFile)).not.toHaveBeenCalled();
|
|
3361
|
+
expect(result.filesDownloaded).toBe(0);
|
|
3362
|
+
expect(readJournal("acme").files["docs/handoff.md"]?.remoteEtag).toBe("new-etag");
|
|
3363
|
+
expect(fs.readFileSync(localPath, "utf8")).toBe(localContent);
|
|
3364
|
+
});
|
|
3365
|
+
it.each([
|
|
3366
|
+
"changed remote content hash",
|
|
3367
|
+
"locally modified file",
|
|
3368
|
+
"missing local file",
|
|
3369
|
+
"missing journal row",
|
|
3370
|
+
])("still GETs through the normal pull path for a %s", async (caseName) => {
|
|
3371
|
+
const companyDocs = path.join(tmpDir, "companies", "acme", "docs");
|
|
3372
|
+
fs.mkdirSync(companyDocs, { recursive: true });
|
|
3373
|
+
const localPath = path.join(companyDocs, "handoff.md");
|
|
3374
|
+
const baseline = "unchanged body";
|
|
3375
|
+
fs.writeFileSync(localPath, baseline);
|
|
3376
|
+
const stat = fs.lstatSync(localPath);
|
|
3377
|
+
const baselineHash = crypto.createHash("sha256").update(baseline).digest("hex");
|
|
3378
|
+
const announcedBody = caseName === "changed remote content hash"
|
|
3379
|
+
? "changed body!!"
|
|
3380
|
+
: baseline;
|
|
3381
|
+
const announcedHash = crypto.createHash("sha256").update(announcedBody).digest("hex");
|
|
3382
|
+
if (caseName !== "missing journal row") {
|
|
3383
|
+
writeJournal("acme", {
|
|
3384
|
+
version: "2",
|
|
3385
|
+
lastSync: new Date().toISOString(),
|
|
3386
|
+
pulls: [],
|
|
3387
|
+
files: {
|
|
3388
|
+
"docs/handoff.md": {
|
|
3389
|
+
hash: baselineHash,
|
|
3390
|
+
size: stat.size,
|
|
3391
|
+
mtimeMs: stat.mtimeMs,
|
|
3392
|
+
ctimeMs: stat.ctimeMs,
|
|
3393
|
+
remoteEtag: "old-etag",
|
|
3394
|
+
syncedAt: new Date(Date.now() - 3600000).toISOString(),
|
|
3395
|
+
direction: "down",
|
|
3396
|
+
kind: "file",
|
|
3397
|
+
},
|
|
3398
|
+
},
|
|
3399
|
+
});
|
|
3400
|
+
}
|
|
3401
|
+
if (caseName === "locally modified file") {
|
|
3402
|
+
fs.writeFileSync(localPath, "changed body!!");
|
|
3403
|
+
}
|
|
3404
|
+
else if (caseName === "missing local file") {
|
|
3405
|
+
fs.unlinkSync(localPath);
|
|
3406
|
+
}
|
|
3407
|
+
vi.mocked(s3Module.listRemoteFiles).mockResolvedValueOnce([
|
|
3408
|
+
{ key: "docs/handoff.md", size: stat.size, lastModified: new Date(), etag: '"new-etag"' },
|
|
3409
|
+
]);
|
|
3410
|
+
await sync({
|
|
3411
|
+
company: "acme",
|
|
3412
|
+
onConflict: "keep",
|
|
3413
|
+
vaultConfig: mockConfig,
|
|
3414
|
+
hqRoot: tmpDir,
|
|
3415
|
+
pullPrefixes: ["docs/handoff.md"],
|
|
3416
|
+
pullContentHashes: { "docs/handoff.md": `sha256:${announcedHash}` },
|
|
3417
|
+
skipReindex: true,
|
|
3418
|
+
});
|
|
3419
|
+
expect(vi.mocked(s3Module.downloadFile)).toHaveBeenCalled();
|
|
3420
|
+
});
|
|
3421
|
+
it("keeps local bytes in place when an unjournaled file already matches the announced content", async () => {
|
|
3422
|
+
const companyDocs = path.join(tmpDir, "companies", "acme", "docs");
|
|
3423
|
+
fs.mkdirSync(companyDocs, { recursive: true });
|
|
3424
|
+
const localPath = path.join(companyDocs, "handoff.md");
|
|
3425
|
+
const content = "already has incoming bytes";
|
|
3426
|
+
fs.writeFileSync(localPath, content);
|
|
3427
|
+
const before = fs.lstatSync(localPath);
|
|
3428
|
+
const hash = crypto.createHash("sha256").update(content).digest("hex");
|
|
3429
|
+
vi.mocked(s3Module.listRemoteFiles).mockResolvedValueOnce([
|
|
3430
|
+
{ key: "docs/handoff.md", size: before.size, lastModified: new Date(), etag: '"incoming-etag"' },
|
|
3431
|
+
]);
|
|
3432
|
+
vi.mocked(s3Module.downloadFile).mockImplementationOnce(async (_ctx, _key, probePath, options) => {
|
|
3433
|
+
fs.mkdirSync(path.dirname(probePath), { recursive: true });
|
|
3434
|
+
options?.beforeReplace?.();
|
|
3435
|
+
fs.writeFileSync(probePath, content);
|
|
3436
|
+
return { metadata: {} };
|
|
3437
|
+
});
|
|
3438
|
+
const result = await sync({
|
|
3439
|
+
company: "acme",
|
|
3440
|
+
onConflict: "keep",
|
|
3441
|
+
vaultConfig: mockConfig,
|
|
3442
|
+
hqRoot: tmpDir,
|
|
3443
|
+
pullPrefixes: ["docs/handoff.md"],
|
|
3444
|
+
pullContentHashes: { "docs/handoff.md": `sha256:${hash}` },
|
|
3445
|
+
skipReindex: true,
|
|
3446
|
+
});
|
|
3447
|
+
const after = fs.lstatSync(localPath);
|
|
3448
|
+
expect(vi.mocked(s3Module.downloadFile)).toHaveBeenCalledTimes(1);
|
|
3449
|
+
expect(fs.readFileSync(localPath, "utf8")).toBe(content);
|
|
3450
|
+
expect(after.ctimeMs).toBe(before.ctimeMs);
|
|
3451
|
+
expect(result.filesDownloaded).toBe(0);
|
|
3452
|
+
expect(result.conflicts).toBe(0);
|
|
3453
|
+
});
|
|
3226
3454
|
it("anti-rollback guard is direction-gated: a SMALLER remote on a clean CONSUMER copy (direction=down) downloads, not conflict", async () => {
|
|
3227
3455
|
// The device only ever PULLED this file (direction: "down") — a consumer
|
|
3228
3456
|
// copy with no local authorship to protect. The gardener legitimately
|