@indigoai-us/hq-cloud 6.18.5 → 6.18.7

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 (78) hide show
  1. package/dist/bin/sync-runner-company.d.ts +2 -0
  2. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  3. package/dist/bin/sync-runner-company.js +7 -0
  4. package/dist/bin/sync-runner-company.js.map +1 -1
  5. package/dist/bin/sync-runner-publish-expansion.test.d.ts +2 -0
  6. package/dist/bin/sync-runner-publish-expansion.test.d.ts.map +1 -0
  7. package/dist/bin/sync-runner-publish-expansion.test.js +54 -0
  8. package/dist/bin/sync-runner-publish-expansion.test.js.map +1 -0
  9. package/dist/bin/sync-runner-watch-loop.d.ts +11 -0
  10. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  11. package/dist/bin/sync-runner-watch-loop.js +58 -1
  12. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  13. package/dist/bin/sync-runner.d.ts +2 -0
  14. package/dist/bin/sync-runner.d.ts.map +1 -1
  15. package/dist/bin/sync-runner.js +1 -0
  16. package/dist/bin/sync-runner.js.map +1 -1
  17. package/dist/cli/share.d.ts +24 -2
  18. package/dist/cli/share.d.ts.map +1 -1
  19. package/dist/cli/share.js +56 -12
  20. package/dist/cli/share.js.map +1 -1
  21. package/dist/cli/share.test.js +194 -0
  22. package/dist/cli/share.test.js.map +1 -1
  23. package/dist/lib/ontology-entity-meta.d.ts +21 -0
  24. package/dist/lib/ontology-entity-meta.d.ts.map +1 -0
  25. package/dist/lib/ontology-entity-meta.js +51 -0
  26. package/dist/lib/ontology-entity-meta.js.map +1 -0
  27. package/dist/lib/ontology-entity-meta.test.d.ts +2 -0
  28. package/dist/lib/ontology-entity-meta.test.d.ts.map +1 -0
  29. package/dist/lib/ontology-entity-meta.test.js +79 -0
  30. package/dist/lib/ontology-entity-meta.test.js.map +1 -0
  31. package/dist/lib/ontology-entity-push.d.ts +9 -4
  32. package/dist/lib/ontology-entity-push.d.ts.map +1 -1
  33. package/dist/lib/ontology-entity-push.js +19 -20
  34. package/dist/lib/ontology-entity-push.js.map +1 -1
  35. package/dist/lib/ontology-entity-push.test.js +7 -0
  36. package/dist/lib/ontology-entity-push.test.js.map +1 -1
  37. package/dist/lib/ontology-outbox.d.ts +52 -0
  38. package/dist/lib/ontology-outbox.d.ts.map +1 -0
  39. package/dist/lib/ontology-outbox.js +118 -0
  40. package/dist/lib/ontology-outbox.js.map +1 -0
  41. package/dist/outposts/client.d.ts +2 -0
  42. package/dist/outposts/client.d.ts.map +1 -1
  43. package/dist/outposts/client.js +60 -14
  44. package/dist/outposts/client.js.map +1 -1
  45. package/dist/outposts/client.test.js +73 -8
  46. package/dist/outposts/client.test.js.map +1 -1
  47. package/dist/outposts/command.d.ts.map +1 -1
  48. package/dist/outposts/command.js +87 -71
  49. package/dist/outposts/command.js.map +1 -1
  50. package/dist/outposts/command.test.js +187 -65
  51. package/dist/outposts/command.test.js.map +1 -1
  52. package/dist/outposts/errors.d.ts +6 -0
  53. package/dist/outposts/errors.d.ts.map +1 -1
  54. package/dist/outposts/errors.js +11 -0
  55. package/dist/outposts/errors.js.map +1 -1
  56. package/dist/outposts/index.d.ts +1 -1
  57. package/dist/outposts/index.d.ts.map +1 -1
  58. package/dist/outposts/index.js +1 -1
  59. package/dist/outposts/index.js.map +1 -1
  60. package/dist/private-folder-transport.d.ts.map +1 -1
  61. package/dist/private-folder-transport.js +16 -1
  62. package/dist/private-folder-transport.js.map +1 -1
  63. package/dist/private-folder-transport.test.d.ts +2 -0
  64. package/dist/private-folder-transport.test.d.ts.map +1 -0
  65. package/dist/private-folder-transport.test.js +33 -0
  66. package/dist/private-folder-transport.test.js.map +1 -0
  67. package/dist/s3.d.ts.map +1 -1
  68. package/dist/s3.js +29 -0
  69. package/dist/s3.js.map +1 -1
  70. package/dist/s3.test.js +44 -0
  71. package/dist/s3.test.js.map +1 -1
  72. package/dist/session-log-capture.d.ts +2 -0
  73. package/dist/session-log-capture.d.ts.map +1 -1
  74. package/dist/session-log-capture.js +127 -4
  75. package/dist/session-log-capture.js.map +1 -1
  76. package/dist/session-log-capture.test.js +119 -0
  77. package/dist/session-log-capture.test.js.map +1 -1
  78. package/package.json +2 -1
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Unit tests for hq share command (VLT-5 US-002).
3
3
  */
4
+ import { createHash } from "node:crypto";
4
5
  import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
5
6
  import * as fs from "fs";
6
7
  import * as path from "path";
@@ -3330,6 +3331,7 @@ describe("share", () => {
3330
3331
  vaultConfig: mockConfig,
3331
3332
  hqRoot: tmpDir,
3332
3333
  ontologyEntityPush: true,
3334
+ ontologyMultiWriter: false,
3333
3335
  });
3334
3336
  expect(result.filesUploaded).toBe(1);
3335
3337
  expect(uploadFile).toHaveBeenCalledWith(expect.anything(), file, entityRel, undefined, { ifNoneMatch: "*" });
@@ -3353,6 +3355,7 @@ describe("share", () => {
3353
3355
  vaultConfig: mockConfig,
3354
3356
  hqRoot: tmpDir,
3355
3357
  ontologyEntityPush: true,
3358
+ ontologyMultiWriter: false,
3356
3359
  })).rejects.toThrow(ServerOwnedPushPathsError);
3357
3360
  expect(uploadFile).not.toHaveBeenCalled();
3358
3361
  });
@@ -3370,6 +3373,7 @@ describe("share", () => {
3370
3373
  vaultConfig: mockConfig,
3371
3374
  hqRoot: tmpDir,
3372
3375
  ontologyEntityPush: true,
3376
+ ontologyMultiWriter: false,
3373
3377
  });
3374
3378
  expect(result.filesUploaded).toBe(1);
3375
3379
  expect(uploadFile).toHaveBeenCalledWith(expect.anything(), file, entityRel, undefined, { ifMatch: "synced-etag" });
@@ -3394,6 +3398,7 @@ describe("share", () => {
3394
3398
  hqRoot: tmpDir,
3395
3399
  onConflict: "overwrite",
3396
3400
  ontologyEntityPush: true,
3401
+ ontologyMultiWriter: false,
3397
3402
  onEvent: (e) => events.push(e),
3398
3403
  });
3399
3404
  expect(uploadFile).not.toHaveBeenCalled();
@@ -3420,6 +3425,7 @@ describe("share", () => {
3420
3425
  hqRoot: tmpDir,
3421
3426
  onConflict: "overwrite",
3422
3427
  ontologyEntityPush: true,
3428
+ ontologyMultiWriter: false,
3423
3429
  });
3424
3430
  expect(uploadFile).toHaveBeenCalledTimes(1);
3425
3431
  expect(vi.mocked(uploadFile).mock.calls[0][4]).toEqual({ ifNoneMatch: "*" });
@@ -3439,6 +3445,7 @@ describe("share", () => {
3439
3445
  hqRoot: tmpDir,
3440
3446
  onConflict: "overwrite",
3441
3447
  ontologyEntityPush: true,
3448
+ ontologyMultiWriter: false,
3442
3449
  });
3443
3450
  expect(uploadFile).not.toHaveBeenCalled();
3444
3451
  expect(result.filesUploaded).toBe(0);
@@ -3459,6 +3466,7 @@ describe("share", () => {
3459
3466
  hqRoot: tmpDir,
3460
3467
  onConflict: "overwrite",
3461
3468
  ontologyEntityPush: true,
3469
+ ontologyMultiWriter: false,
3462
3470
  onEvent: (e) => events.push(e),
3463
3471
  });
3464
3472
  expect(uploadFile).not.toHaveBeenCalled();
@@ -3474,6 +3482,7 @@ describe("share", () => {
3474
3482
  it("unset option: reads the flag, and the local override turns the push on", async () => {
3475
3483
  const file = writeEntity();
3476
3484
  process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY = "true";
3485
+ process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY_MULTI_WRITER = "false";
3477
3486
  try {
3478
3487
  const result = await share({
3479
3488
  paths: [file],
@@ -3485,6 +3494,7 @@ describe("share", () => {
3485
3494
  }
3486
3495
  finally {
3487
3496
  delete process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY;
3497
+ delete process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY_MULTI_WRITER;
3488
3498
  }
3489
3499
  });
3490
3500
  it("unset option: a personal-vault push never reads the flag or pushes entities", async () => {
@@ -3507,6 +3517,190 @@ describe("share", () => {
3507
3517
  }
3508
3518
  expect(uploadFile).not.toHaveBeenCalled();
3509
3519
  });
3520
+ describe("several writers (flag checkpoint.ontology.multi-writer)", () => {
3521
+ const sha = (body) => createHash("sha256").update(body).digest("hex");
3522
+ const bodyAt = (lastUpdated, extra = "") => `---\nid: abc\ntype: person\ncanonical_name: Maria Khan\nlast_updated: ${lastUpdated}\n${extra}---\n`;
3523
+ const freshBody = () => bodyAt(new Date(Date.now() - 60_000).toISOString());
3524
+ const outboxFile = () => path.join(tmpDir, ".hq", "ontology-outbox", "acme.json");
3525
+ function writeOutbox(entries, raw) {
3526
+ fs.mkdirSync(path.dirname(outboxFile()), { recursive: true });
3527
+ fs.writeFileSync(outboxFile(), raw ??
3528
+ JSON.stringify({
3529
+ schema: "hq-ontology-outbox.v1",
3530
+ company: "acme",
3531
+ entries: Object.fromEntries(Object.entries(entries).map(([key, hash]) => [key, { sha256: hash, written_at: new Date().toISOString() }])),
3532
+ }));
3533
+ }
3534
+ const multiWriterShare = (file, extra = {}) => share({
3535
+ paths: [file],
3536
+ company: "acme",
3537
+ vaultConfig: mockConfig,
3538
+ hqRoot: tmpDir,
3539
+ ontologyEntityPush: true,
3540
+ ontologyMultiWriter: true,
3541
+ ...extra,
3542
+ });
3543
+ it("C1: a pulled copy with no outbox entry is refused, with or without a journal row", async () => {
3544
+ const body = freshBody();
3545
+ const file = writeEntity(body);
3546
+ writeOutbox({});
3547
+ await expect(multiWriterShare(file)).rejects.toThrow(ServerOwnedPushPathsError);
3548
+ seedEntityJournal("old-etag", sha("---\nolder: body\n---\n"));
3549
+ await expect(multiWriterShare(file, { onConflict: "overwrite" })).rejects.toThrow(ServerOwnedPushPathsError);
3550
+ expect(uploadFile).not.toHaveBeenCalled();
3551
+ });
3552
+ it("C2: bytes that differ from the outbox entry are refused", async () => {
3553
+ const file = writeEntity(freshBody());
3554
+ writeOutbox({ [entityRel]: sha(bodyAt("2026-09-01T00:00:00.000Z")) });
3555
+ await expect(multiWriterShare(file)).rejects.toThrow(ServerOwnedPushPathsError);
3556
+ expect(uploadFile).not.toHaveBeenCalled();
3557
+ });
3558
+ it("an outbox'd fresh create uploads with If-None-Match:*", async () => {
3559
+ const body = freshBody();
3560
+ const file = writeEntity(body);
3561
+ writeOutbox({ [entityRel]: sha(body) });
3562
+ const result = await multiWriterShare(file);
3563
+ expect(result.filesUploaded).toBe(1);
3564
+ expect(uploadFile).toHaveBeenCalledWith(expect.anything(), file, entityRel, undefined, { ifNoneMatch: "*" });
3565
+ });
3566
+ it("an outbox'd edit over the synced remote is fenced on the journal etag", async () => {
3567
+ const body = bodyAt("2026-09-01T00:00:00.000Z");
3568
+ const file = writeEntity(body);
3569
+ writeOutbox({ [entityRel]: sha(body) });
3570
+ seedEntityJournal("synced-etag");
3571
+ vi.mocked(headRemoteFile).mockResolvedValueOnce({
3572
+ lastModified: new Date(Date.now() - 120_000),
3573
+ etag: '"synced-etag"',
3574
+ size: 10,
3575
+ });
3576
+ const result = await multiWriterShare(file);
3577
+ expect(result.filesUploaded).toBe(1);
3578
+ expect(uploadFile).toHaveBeenCalledWith(expect.anything(), file, entityRel, undefined, { ifMatch: "synced-etag" });
3579
+ });
3580
+ it("an outbox'd create older than 24 hours over an absent remote is set aside, not uploaded", async () => {
3581
+ const body = bodyAt(new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString());
3582
+ const file = writeEntity(body);
3583
+ writeOutbox({ [entityRel]: sha(body) });
3584
+ vi.mocked(headRemoteFile).mockResolvedValueOnce(null);
3585
+ const events = [];
3586
+ const result = await multiWriterShare(file, { onEvent: (e) => events.push(e) });
3587
+ expect(uploadFile).not.toHaveBeenCalled();
3588
+ expect(result.filesUploaded).toBe(0);
3589
+ expect(result.conflictPaths).toEqual([entityRel]);
3590
+ expect(fs.existsSync(file)).toBe(false);
3591
+ expect(fs.readFileSync(sidecarIn(path.dirname(file)), "utf-8")).toBe(body);
3592
+ expect(events).toContainEqual(expect.objectContaining({ type: "conflict", path: entityRel, resolution: "keep" }));
3593
+ });
3594
+ it("an outbox'd create with no readable last_updated over an absent remote is set aside", async () => {
3595
+ const file = writeEntity(entityBody);
3596
+ writeOutbox({ [entityRel]: sha(entityBody) });
3597
+ vi.mocked(headRemoteFile).mockResolvedValueOnce(null);
3598
+ const result = await multiWriterShare(file);
3599
+ expect(uploadFile).not.toHaveBeenCalled();
3600
+ expect(result.conflictPaths).toEqual([entityRel]);
3601
+ });
3602
+ it("a malformed outbox pushes nothing and says so", async () => {
3603
+ const body = freshBody();
3604
+ const file = writeEntity(body);
3605
+ writeOutbox({}, "{not json");
3606
+ const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
3607
+ try {
3608
+ await expect(multiWriterShare(file)).rejects.toThrow(ServerOwnedPushPathsError);
3609
+ expect(stderr.mock.calls.map((c) => String(c[0])).join("")).toContain("could not read the ontology outbox for acme");
3610
+ }
3611
+ finally {
3612
+ stderr.mockRestore();
3613
+ }
3614
+ expect(uploadFile).not.toHaveBeenCalled();
3615
+ });
3616
+ it("an outbox for another company does not open this one", async () => {
3617
+ const body = freshBody();
3618
+ const file = writeEntity(body);
3619
+ writeOutbox({}, JSON.stringify({
3620
+ schema: "hq-ontology-outbox.v1",
3621
+ company: "other",
3622
+ entries: { [entityRel]: { sha256: sha(body), written_at: new Date().toISOString() } },
3623
+ }));
3624
+ const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
3625
+ try {
3626
+ await expect(multiWriterShare(file)).rejects.toThrow(ServerOwnedPushPathsError);
3627
+ }
3628
+ finally {
3629
+ stderr.mockRestore();
3630
+ }
3631
+ expect(uploadFile).not.toHaveBeenCalled();
3632
+ });
3633
+ it("unset option: a failed read of the multi-writer flag keeps entities pull-only", async () => {
3634
+ const body = freshBody();
3635
+ const file = writeEntity(body);
3636
+ process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY = "true";
3637
+ const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
3638
+ const failingConfig = { ...mockConfig, apiUrl: "http://127.0.0.1:9", authToken: "t" };
3639
+ try {
3640
+ await expect(share({ paths: [file], company: "acme", vaultConfig: failingConfig, hqRoot: tmpDir })).rejects.toThrow(ServerOwnedPushPathsError);
3641
+ expect(stderr.mock.calls.map((c) => String(c[0])).join("")).toContain("could not read checkpoint.ontology.multi-writer");
3642
+ }
3643
+ finally {
3644
+ stderr.mockRestore();
3645
+ delete process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY;
3646
+ }
3647
+ expect(uploadFile).not.toHaveBeenCalled();
3648
+ });
3649
+ it("unset option: no flags endpoint for the multi-writer flag keeps entities pull-only", async () => {
3650
+ const body = freshBody();
3651
+ const file = writeEntity(body);
3652
+ writeOutbox({ [entityRel]: sha(body) });
3653
+ process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY = "true";
3654
+ const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
3655
+ const noEndpoint = { ...mockConfig, apiUrl: "", authToken: "t" };
3656
+ try {
3657
+ await expect(share({ paths: [file], company: "acme", vaultConfig: noEndpoint, hqRoot: tmpDir })).rejects.toThrow(ServerOwnedPushPathsError);
3658
+ expect(stderr.mock.calls.map((c) => String(c[0])).join("")).toContain("no flags endpoint or token");
3659
+ }
3660
+ finally {
3661
+ stderr.mockRestore();
3662
+ delete process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY;
3663
+ }
3664
+ expect(uploadFile).not.toHaveBeenCalled();
3665
+ });
3666
+ it("an outbox with one malformed entry pushes nothing", async () => {
3667
+ const body = freshBody();
3668
+ const file = writeEntity(body);
3669
+ writeOutbox({}, JSON.stringify({
3670
+ schema: "hq-ontology-outbox.v1",
3671
+ company: "acme",
3672
+ entries: {
3673
+ [entityRel]: { sha256: sha(body), written_at: new Date().toISOString() },
3674
+ "ontology/entities/person/other.md": { sha256: "not-a-hash", written_at: new Date().toISOString() },
3675
+ },
3676
+ }));
3677
+ const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
3678
+ try {
3679
+ await expect(multiWriterShare(file)).rejects.toThrow(ServerOwnedPushPathsError);
3680
+ expect(stderr.mock.calls.map((c) => String(c[0])).join("")).toContain("malformed entry");
3681
+ }
3682
+ finally {
3683
+ stderr.mockRestore();
3684
+ }
3685
+ expect(uploadFile).not.toHaveBeenCalled();
3686
+ });
3687
+ it("unset option: the multi-writer local override turns the outbox rule on", async () => {
3688
+ const body = freshBody();
3689
+ const file = writeEntity(body);
3690
+ process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY = "true";
3691
+ process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY_MULTI_WRITER = "true";
3692
+ try {
3693
+ await expect(share({ paths: [file], company: "acme", vaultConfig: mockConfig, hqRoot: tmpDir })).rejects.toThrow(ServerOwnedPushPathsError);
3694
+ writeOutbox({ [entityRel]: sha(body) });
3695
+ const result = await share({ paths: [file], company: "acme", vaultConfig: mockConfig, hqRoot: tmpDir });
3696
+ expect(result.filesUploaded).toBe(1);
3697
+ }
3698
+ finally {
3699
+ delete process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY;
3700
+ delete process.env.HQ_FLAG_CHECKPOINT_ONTOLOGY_MULTI_WRITER;
3701
+ }
3702
+ });
3703
+ });
3510
3704
  });
3511
3705
  it("watch push collapses 32k server-owned refusals to one exact-count event while board.json still uploads", async () => {
3512
3706
  const companyRoot = path.join(tmpDir, "companies", "acme");