@indigoai-us/hq-cloud 6.16.58-alpha.3 → 6.16.58-alpha.5
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-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +98 -16
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-company.test.js +621 -8
- package/dist/bin/sync-runner-company.test.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +8 -0
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +121 -1
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/push-scan-exclusions.test.js +4 -4
- package/dist/cli/push-scan-exclusions.test.js.map +1 -1
- package/dist/cli/share.d.ts +2 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +161 -46
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +480 -4
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +9 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +52 -10
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +211 -1
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/cli/tombstones.d.ts +6 -0
- package/dist/cli/tombstones.d.ts.map +1 -1
- package/dist/cli/tombstones.js +64 -6
- package/dist/cli/tombstones.js.map +1 -1
- package/dist/cli/tombstones.test.js +94 -1
- package/dist/cli/tombstones.test.js.map +1 -1
- package/dist/cognito-auth.d.ts +60 -1
- package/dist/cognito-auth.d.ts.map +1 -1
- package/dist/cognito-auth.js +162 -56
- package/dist/cognito-auth.js.map +1 -1
- package/dist/context.d.ts +12 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +102 -20
- package/dist/context.js.map +1 -1
- package/dist/context.test.js +164 -2
- package/dist/context.test.js.map +1 -1
- package/dist/ignore.d.ts +10 -0
- package/dist/ignore.d.ts.map +1 -1
- package/dist/ignore.js +47 -5
- package/dist/ignore.js.map +1 -1
- package/dist/ignore.test.js +30 -3
- package/dist/ignore.test.js.map +1 -1
- package/dist/lib/net-errors.d.ts +12 -0
- package/dist/lib/net-errors.d.ts.map +1 -1
- package/dist/lib/net-errors.js +35 -0
- package/dist/lib/net-errors.js.map +1 -1
- package/dist/lib/net-errors.test.js +19 -1
- package/dist/lib/net-errors.test.js.map +1 -1
- package/dist/machine-auth.test.js +19 -17
- package/dist/machine-auth.test.js.map +1 -1
- package/dist/machine-token-cache-isolation.test.d.ts +24 -0
- package/dist/machine-token-cache-isolation.test.d.ts.map +1 -0
- package/dist/machine-token-cache-isolation.test.js +284 -0
- package/dist/machine-token-cache-isolation.test.js.map +1 -0
- package/dist/manifest/build-manifest-resident-parity.test.js +3 -3
- package/dist/manifest/build-manifest-resident-parity.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -27,9 +27,11 @@ vi.mock("../s3.js", async (importOriginal) => {
|
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
29
|
import { executeCompanyFanout } from "./sync-runner-company.js";
|
|
30
|
+
import { clearContextCache, resolveEntityContext, setEntityFetchSleepForTest, } from "../context.js";
|
|
30
31
|
import { CognitoAuthError, CognitoRefreshError } from "../cognito-auth.js";
|
|
32
|
+
import { SESSION_LOGS_SYNC_REL } from "../personal-vault.js";
|
|
31
33
|
import { _testing as shareTesting, share, parseRegisteredCompanySkillUid, } from "../cli/share.js";
|
|
32
|
-
import { readJournal } from "../journal.js";
|
|
34
|
+
import { PERSONAL_VAULT_JOURNAL_SLUG, readJournal } from "../journal.js";
|
|
33
35
|
import { VaultConflictError } from "../vault-client.js";
|
|
34
36
|
import { headRemoteFile, uploadFile } from "../s3.js";
|
|
35
37
|
import { setBandwidthGovernorForTesting } from "../bandwidth.js";
|
|
@@ -609,6 +611,203 @@ describe("executeCompanyFanout — archived session-log skip", () => {
|
|
|
609
611
|
}
|
|
610
612
|
});
|
|
611
613
|
});
|
|
614
|
+
describe("executeCompanyFanout — diagnostic tombstone HEAD deferral", () => {
|
|
615
|
+
it("does not error the company when the only events are diagnostic tombstone deferrals", async () => {
|
|
616
|
+
// A vault 100/hr throttle during planned-deletion HEAD verify is
|
|
617
|
+
// emitted as `{ type: "error", diagnostic: true }`. The fanout must
|
|
618
|
+
// forward that marker and leave errors[] empty so the company
|
|
619
|
+
// settles `complete` and the runner keeps exit 0 (never 2).
|
|
620
|
+
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-tombstone-"));
|
|
621
|
+
try {
|
|
622
|
+
const events = [];
|
|
623
|
+
const pullResult = {
|
|
624
|
+
filesDownloaded: 0,
|
|
625
|
+
bytesDownloaded: 0,
|
|
626
|
+
filesSkipped: 0,
|
|
627
|
+
conflicts: 0,
|
|
628
|
+
conflictPaths: [],
|
|
629
|
+
aborted: false,
|
|
630
|
+
newFiles: [],
|
|
631
|
+
newFilesCount: 0,
|
|
632
|
+
filesExcludedByPolicy: 0,
|
|
633
|
+
filesTombstoned: 0,
|
|
634
|
+
filesOutOfScope: 0,
|
|
635
|
+
scopeOrphansRemoved: 0,
|
|
636
|
+
scopeOrphansBlocked: 0,
|
|
637
|
+
};
|
|
638
|
+
const syncFn = vi.fn(async (opts) => {
|
|
639
|
+
opts.onEvent?.({
|
|
640
|
+
type: "error",
|
|
641
|
+
diagnostic: true,
|
|
642
|
+
path: "skills/wbr-finalize/SKILL.md",
|
|
643
|
+
message: "tombstone HEAD verify failed (deferring): RateLimited rate limited (100/hr) — get skills/wbr-finalize/SKILL.md deferred to next sync",
|
|
644
|
+
});
|
|
645
|
+
return pullResult;
|
|
646
|
+
});
|
|
647
|
+
const result = await executeCompanyFanout({
|
|
648
|
+
plan: [{ uid: "prs_1", slug: "personal", personalMode: true }],
|
|
649
|
+
direction: "pull",
|
|
650
|
+
hqRoot,
|
|
651
|
+
onConflict: "keep",
|
|
652
|
+
client: {},
|
|
653
|
+
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
654
|
+
syncFn,
|
|
655
|
+
shareFn: vi.fn(),
|
|
656
|
+
resolveDeletePolicy: () => "all",
|
|
657
|
+
emit: (e) => events.push(e),
|
|
658
|
+
ensureCompanyDir: vi.fn(),
|
|
659
|
+
telemetryClient: null,
|
|
660
|
+
});
|
|
661
|
+
expect(events).toContainEqual({
|
|
662
|
+
type: "error",
|
|
663
|
+
diagnostic: true,
|
|
664
|
+
company: "personal",
|
|
665
|
+
path: "skills/wbr-finalize/SKILL.md",
|
|
666
|
+
message: "tombstone HEAD verify failed (deferring): RateLimited rate limited (100/hr) — get skills/wbr-finalize/SKILL.md deferred to next sync",
|
|
667
|
+
});
|
|
668
|
+
expect(result.errors).toEqual([]);
|
|
669
|
+
expect(result.companyFailures).toEqual([]);
|
|
670
|
+
expect(result.transientCompanies).toEqual([]);
|
|
671
|
+
expect(events.some((e) => e.type === "error" && e.diagnostic !== true)).toBe(false);
|
|
672
|
+
expect(result.stateByCompany.get("personal")?.status).toBe("complete");
|
|
673
|
+
}
|
|
674
|
+
finally {
|
|
675
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
describe("executeCompanyFanout — diagnostic rate-limited transfer deferral", () => {
|
|
680
|
+
it("does not error the company when the only events are diagnostic upload deferrals", async () => {
|
|
681
|
+
// A vault 100/hr throttle during a per-file PUT is emitted as
|
|
682
|
+
// `{ type: "error", diagnostic: true }`. The fanout must forward that
|
|
683
|
+
// marker and leave errors[] empty so the company settles `complete`
|
|
684
|
+
// and the runner keeps exit 0 (never 2).
|
|
685
|
+
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-put-defer-"));
|
|
686
|
+
try {
|
|
687
|
+
const events = [];
|
|
688
|
+
const shareResult = {
|
|
689
|
+
filesUploaded: 0,
|
|
690
|
+
bytesUploaded: 0,
|
|
691
|
+
filesSkipped: 1,
|
|
692
|
+
filesDeleted: 0,
|
|
693
|
+
filesTombstoned: 0,
|
|
694
|
+
filesRefusedStale: 0,
|
|
695
|
+
filesRefusedStalePaths: [],
|
|
696
|
+
filesSuppressedByTombstone: 0,
|
|
697
|
+
filesExcludedByPolicy: 0,
|
|
698
|
+
filesExcludedByScope: 0,
|
|
699
|
+
filesExcludedByIgnore: 0,
|
|
700
|
+
unreachablePaths: [],
|
|
701
|
+
linkedSubtreesNotShipped: [],
|
|
702
|
+
conflictPaths: [],
|
|
703
|
+
aborted: false,
|
|
704
|
+
};
|
|
705
|
+
const shareFn = vi.fn(async (opts) => {
|
|
706
|
+
opts.onEvent?.({
|
|
707
|
+
type: "error",
|
|
708
|
+
diagnostic: true,
|
|
709
|
+
path: "workers/concierge/output/mention-sweep-batches/1789110806_212549.json",
|
|
710
|
+
message: "RateLimited rate limited (100/hr) — put workers/concierge/output/mention-sweep-batches/1789110806_212549.json deferred to next sync",
|
|
711
|
+
});
|
|
712
|
+
return shareResult;
|
|
713
|
+
});
|
|
714
|
+
const result = await executeCompanyFanout({
|
|
715
|
+
plan: [{ uid: "prs_1", slug: "mhi-media", personalMode: true }],
|
|
716
|
+
direction: "push",
|
|
717
|
+
hqRoot,
|
|
718
|
+
onConflict: "keep",
|
|
719
|
+
client: {},
|
|
720
|
+
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
721
|
+
syncFn: vi.fn(),
|
|
722
|
+
shareFn,
|
|
723
|
+
resolveDeletePolicy: () => "all",
|
|
724
|
+
emit: (e) => events.push(e),
|
|
725
|
+
ensureCompanyDir: vi.fn(),
|
|
726
|
+
telemetryClient: null,
|
|
727
|
+
});
|
|
728
|
+
expect(events).toContainEqual({
|
|
729
|
+
type: "error",
|
|
730
|
+
diagnostic: true,
|
|
731
|
+
company: "mhi-media",
|
|
732
|
+
path: "workers/concierge/output/mention-sweep-batches/1789110806_212549.json",
|
|
733
|
+
message: "RateLimited rate limited (100/hr) — put workers/concierge/output/mention-sweep-batches/1789110806_212549.json deferred to next sync",
|
|
734
|
+
});
|
|
735
|
+
expect(result.errors).toEqual([]);
|
|
736
|
+
expect(result.companyFailures).toEqual([]);
|
|
737
|
+
expect(result.transientCompanies).toEqual([]);
|
|
738
|
+
expect(events.some((e) => e.type === "error" && e.diagnostic !== true)).toBe(false);
|
|
739
|
+
expect(result.stateByCompany.get("mhi-media")?.status).toBe("complete");
|
|
740
|
+
}
|
|
741
|
+
finally {
|
|
742
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
it("does not error the company when the only events are a breaker-tripped upload-batch deferral", async () => {
|
|
746
|
+
// throwUploadWorkerErrors collapses an all-RateLimited worker batch into
|
|
747
|
+
// one `{ type: "error", diagnostic: true, path: "(company)" }`. Same
|
|
748
|
+
// contract as the per-file PUT deferral: errors[] stays empty, the
|
|
749
|
+
// company settles `complete`, the runner keeps exit 0 (never 2).
|
|
750
|
+
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-put-batch-defer-"));
|
|
751
|
+
try {
|
|
752
|
+
const events = [];
|
|
753
|
+
const shareResult = {
|
|
754
|
+
filesUploaded: 0,
|
|
755
|
+
bytesUploaded: 0,
|
|
756
|
+
filesSkipped: 0,
|
|
757
|
+
filesDeleted: 0,
|
|
758
|
+
filesTombstoned: 0,
|
|
759
|
+
filesRefusedStale: 0,
|
|
760
|
+
filesRefusedStalePaths: [],
|
|
761
|
+
filesSuppressedByTombstone: 0,
|
|
762
|
+
filesExcludedByPolicy: 0,
|
|
763
|
+
filesExcludedByScope: 0,
|
|
764
|
+
filesExcludedByIgnore: 0,
|
|
765
|
+
unreachablePaths: [],
|
|
766
|
+
linkedSubtreesNotShipped: [],
|
|
767
|
+
conflictPaths: [],
|
|
768
|
+
aborted: false,
|
|
769
|
+
};
|
|
770
|
+
const shareFn = vi.fn(async (opts) => {
|
|
771
|
+
opts.onEvent?.({
|
|
772
|
+
type: "error",
|
|
773
|
+
diagnostic: true,
|
|
774
|
+
path: "(company)",
|
|
775
|
+
message: "RateLimited rate limited (100/hr) — get workers/concierge/output/mention-sweep-batches/1789110806_212549.json deferred to next sync (and 4915 more upload-worker errors)",
|
|
776
|
+
});
|
|
777
|
+
return shareResult;
|
|
778
|
+
});
|
|
779
|
+
const result = await executeCompanyFanout({
|
|
780
|
+
plan: [{ uid: "prs_1", slug: "brickcraft", personalMode: true }],
|
|
781
|
+
direction: "push",
|
|
782
|
+
hqRoot,
|
|
783
|
+
onConflict: "keep",
|
|
784
|
+
client: {},
|
|
785
|
+
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
786
|
+
syncFn: vi.fn(),
|
|
787
|
+
shareFn,
|
|
788
|
+
resolveDeletePolicy: () => "all",
|
|
789
|
+
emit: (e) => events.push(e),
|
|
790
|
+
ensureCompanyDir: vi.fn(),
|
|
791
|
+
telemetryClient: null,
|
|
792
|
+
});
|
|
793
|
+
expect(events).toContainEqual({
|
|
794
|
+
type: "error",
|
|
795
|
+
diagnostic: true,
|
|
796
|
+
company: "brickcraft",
|
|
797
|
+
path: "(company)",
|
|
798
|
+
message: "RateLimited rate limited (100/hr) — get workers/concierge/output/mention-sweep-batches/1789110806_212549.json deferred to next sync (and 4915 more upload-worker errors)",
|
|
799
|
+
});
|
|
800
|
+
expect(result.errors).toEqual([]);
|
|
801
|
+
expect(result.companyFailures).toEqual([]);
|
|
802
|
+
expect(result.transientCompanies).toEqual([]);
|
|
803
|
+
expect(events.some((e) => e.type === "error" && e.diagnostic !== true)).toBe(false);
|
|
804
|
+
expect(result.stateByCompany.get("brickcraft")?.status).toBe("complete");
|
|
805
|
+
}
|
|
806
|
+
finally {
|
|
807
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
});
|
|
612
811
|
describe("executeCompanyFanout — Windows rename-blocked skip (HQ-DESKTOP-54, second path)", () => {
|
|
613
812
|
it("re-emits the skip with the company label, never errors the company, and keeps it complete", async () => {
|
|
614
813
|
// A transient Windows rename refusal surfaces from the pull leg as the
|
|
@@ -787,7 +986,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
787
986
|
return entries;
|
|
788
987
|
}));
|
|
789
988
|
const shareFn = vi.fn(async (options) => {
|
|
790
|
-
shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true);
|
|
989
|
+
await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true);
|
|
791
990
|
return shareResult;
|
|
792
991
|
});
|
|
793
992
|
try {
|
|
@@ -840,7 +1039,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
840
1039
|
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
841
1040
|
syncFn: vi.fn(),
|
|
842
1041
|
shareFn: async (options) => {
|
|
843
|
-
shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true);
|
|
1042
|
+
await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true);
|
|
844
1043
|
return shareResult;
|
|
845
1044
|
},
|
|
846
1045
|
resolveDeletePolicy: () => "all",
|
|
@@ -879,7 +1078,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
879
1078
|
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
880
1079
|
syncFn: vi.fn(),
|
|
881
1080
|
shareFn: async (options) => {
|
|
882
|
-
uploadedPaths.push(...shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true)
|
|
1081
|
+
uploadedPaths.push(...(await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true))
|
|
883
1082
|
.map((entry) => entry.relativePath));
|
|
884
1083
|
return shareResult;
|
|
885
1084
|
},
|
|
@@ -930,7 +1129,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
930
1129
|
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
931
1130
|
syncFn: vi.fn(),
|
|
932
1131
|
shareFn: async (options) => {
|
|
933
|
-
uploadedPaths.push(...shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true)
|
|
1132
|
+
uploadedPaths.push(...(await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true))
|
|
934
1133
|
.map((entry) => entry.relativePath));
|
|
935
1134
|
return shareResult;
|
|
936
1135
|
},
|
|
@@ -964,7 +1163,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
964
1163
|
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
965
1164
|
syncFn: vi.fn(),
|
|
966
1165
|
shareFn: async (options) => {
|
|
967
|
-
uploadedPaths.push(...shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true)
|
|
1166
|
+
uploadedPaths.push(...(await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true))
|
|
968
1167
|
.map((entry) => entry.relativePath));
|
|
969
1168
|
return shareResult;
|
|
970
1169
|
},
|
|
@@ -996,7 +1195,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
996
1195
|
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
997
1196
|
syncFn: vi.fn(),
|
|
998
1197
|
shareFn: async (options) => {
|
|
999
|
-
uploadedPaths.push(...shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true)
|
|
1198
|
+
uploadedPaths.push(...(await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true))
|
|
1000
1199
|
.map((entry) => entry.relativePath));
|
|
1001
1200
|
return shareResult;
|
|
1002
1201
|
},
|
|
@@ -1089,7 +1288,7 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
1089
1288
|
return entries;
|
|
1090
1289
|
}));
|
|
1091
1290
|
const shareFn = vi.fn(async (options) => {
|
|
1092
|
-
shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true);
|
|
1291
|
+
await shareTesting.collectFiles(options.paths, hqRoot, hqRoot, () => true);
|
|
1093
1292
|
return shareResult;
|
|
1094
1293
|
});
|
|
1095
1294
|
try {
|
|
@@ -1163,6 +1362,104 @@ describe("executeCompanyFanout — scoped push walk roots", () => {
|
|
|
1163
1362
|
}
|
|
1164
1363
|
});
|
|
1165
1364
|
});
|
|
1365
|
+
describe("executeCompanyFanout — entity-fetch 429 (2026-09-18 Odin)", () => {
|
|
1366
|
+
const vaultConfig = {
|
|
1367
|
+
apiUrl: "https://vault-api.test",
|
|
1368
|
+
authToken: "access-token",
|
|
1369
|
+
};
|
|
1370
|
+
const entity = {
|
|
1371
|
+
uid: "cmp_01KQ2RYAHXHDPCTY9GPQPTH3DG",
|
|
1372
|
+
slug: "indigo",
|
|
1373
|
+
bucketName: "hq-vault-indigo",
|
|
1374
|
+
status: "active",
|
|
1375
|
+
};
|
|
1376
|
+
const vend = {
|
|
1377
|
+
credentials: {
|
|
1378
|
+
accessKeyId: "ASIA_TEST",
|
|
1379
|
+
secretAccessKey: "secret",
|
|
1380
|
+
sessionToken: "session",
|
|
1381
|
+
expiration: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
|
|
1382
|
+
},
|
|
1383
|
+
expiresAt: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
|
|
1384
|
+
};
|
|
1385
|
+
const runIndigoPull = async (syncFn) => {
|
|
1386
|
+
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-429-"));
|
|
1387
|
+
const events = [];
|
|
1388
|
+
try {
|
|
1389
|
+
const result = await executeCompanyFanout({
|
|
1390
|
+
plan: [{ uid: entity.uid, slug: "indigo" }],
|
|
1391
|
+
direction: "pull",
|
|
1392
|
+
hqRoot,
|
|
1393
|
+
onConflict: "keep",
|
|
1394
|
+
client: {},
|
|
1395
|
+
vaultConfig,
|
|
1396
|
+
syncFn,
|
|
1397
|
+
shareFn: vi.fn(),
|
|
1398
|
+
resolveDeletePolicy: () => "all",
|
|
1399
|
+
emit: (e) => events.push(e),
|
|
1400
|
+
ensureCompanyDir: vi.fn(),
|
|
1401
|
+
telemetryClient: null,
|
|
1402
|
+
});
|
|
1403
|
+
return { result, events };
|
|
1404
|
+
}
|
|
1405
|
+
finally {
|
|
1406
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
beforeEach(() => {
|
|
1410
|
+
clearContextCache();
|
|
1411
|
+
setEntityFetchSleepForTest(async () => undefined);
|
|
1412
|
+
});
|
|
1413
|
+
afterEach(() => {
|
|
1414
|
+
setEntityFetchSleepForTest(undefined);
|
|
1415
|
+
vi.unstubAllGlobals();
|
|
1416
|
+
});
|
|
1417
|
+
it("a 429 then success on retry yields a complete company sync", async () => {
|
|
1418
|
+
let entityCalls = 0;
|
|
1419
|
+
vi.stubGlobal("fetch", vi.fn(async (url) => {
|
|
1420
|
+
const u = String(url);
|
|
1421
|
+
if (u.includes(`/entity/${entity.uid}`)) {
|
|
1422
|
+
entityCalls += 1;
|
|
1423
|
+
if (entityCalls === 1) {
|
|
1424
|
+
return new Response(JSON.stringify({ message: "Too Many Requests" }), {
|
|
1425
|
+
status: 429,
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
return new Response(JSON.stringify({ entity }), { status: 200 });
|
|
1429
|
+
}
|
|
1430
|
+
if (u.includes("/sts/vend")) {
|
|
1431
|
+
return new Response(JSON.stringify(vend), { status: 200 });
|
|
1432
|
+
}
|
|
1433
|
+
return new Response("Not found", { status: 404 });
|
|
1434
|
+
}));
|
|
1435
|
+
const emptyPull = {
|
|
1436
|
+
filesDownloaded: 0,
|
|
1437
|
+
bytesDownloaded: 0,
|
|
1438
|
+
filesSkipped: 0,
|
|
1439
|
+
conflicts: 0,
|
|
1440
|
+
conflictPaths: [],
|
|
1441
|
+
aborted: false,
|
|
1442
|
+
newFiles: [],
|
|
1443
|
+
newFilesCount: 0,
|
|
1444
|
+
filesExcludedByPolicy: 0,
|
|
1445
|
+
filesTombstoned: 0,
|
|
1446
|
+
filesOutOfScope: 0,
|
|
1447
|
+
scopeOrphansRemoved: 0,
|
|
1448
|
+
scopeOrphansBlocked: 0,
|
|
1449
|
+
changedPaths: [],
|
|
1450
|
+
};
|
|
1451
|
+
const { result, events } = await runIndigoPull(async (opts) => {
|
|
1452
|
+
await resolveEntityContext(opts.company ?? entity.uid, opts.vaultConfig);
|
|
1453
|
+
return emptyPull;
|
|
1454
|
+
});
|
|
1455
|
+
expect(entityCalls).toBe(2);
|
|
1456
|
+
expect(result.errors).toEqual([]);
|
|
1457
|
+
expect(result.transientCompanies).toEqual([]);
|
|
1458
|
+
expect(result.stateByCompany.get("indigo")?.status).toBe("complete");
|
|
1459
|
+
expect(events.some((e) => e.type === "error")).toBe(false);
|
|
1460
|
+
expect(events.some((e) => e.type === "transient-network")).toBe(false);
|
|
1461
|
+
});
|
|
1462
|
+
});
|
|
1166
1463
|
describe("executeCompanyFanout — mid-pass identity refusal (HQ-DESKTOP-5S)", () => {
|
|
1167
1464
|
// A mid-pass Cognito refusal surfaces from the leg (share.ts/sync.ts now
|
|
1168
1465
|
// rethrow it instead of recording a per-file error). personalMode avoids the
|
|
@@ -1361,4 +1658,320 @@ describe("executeCompanyFanout — a company-skill 409 never aborts the leg (HQ-
|
|
|
1361
1658
|
expect(parseRegisteredCompanySkillUid(fs.readFileSync(skillFile, "utf8"))).toBe("skl_SOURCE1");
|
|
1362
1659
|
});
|
|
1363
1660
|
});
|
|
1661
|
+
describe("executeCompanyFanout — personal vault skips journaled company dirs", () => {
|
|
1662
|
+
const shareResult = {
|
|
1663
|
+
filesUploaded: 0,
|
|
1664
|
+
bytesUploaded: 0,
|
|
1665
|
+
filesSkipped: 0,
|
|
1666
|
+
filesDeleted: 0,
|
|
1667
|
+
filesTombstoned: 0,
|
|
1668
|
+
filesRefusedStale: 0,
|
|
1669
|
+
filesRefusedStalePaths: [],
|
|
1670
|
+
filesSuppressedByTombstone: 0,
|
|
1671
|
+
filesExcludedByPolicy: 0,
|
|
1672
|
+
filesExcludedByScope: 0,
|
|
1673
|
+
filesExcludedByIgnore: 0,
|
|
1674
|
+
unreachablePaths: [],
|
|
1675
|
+
linkedSubtreesNotShipped: [],
|
|
1676
|
+
conflictPaths: [],
|
|
1677
|
+
aborted: false,
|
|
1678
|
+
};
|
|
1679
|
+
const syncResult = {
|
|
1680
|
+
filesDownloaded: 0,
|
|
1681
|
+
bytesDownloaded: 0,
|
|
1682
|
+
filesSkipped: 0,
|
|
1683
|
+
conflicts: 0,
|
|
1684
|
+
conflictPaths: [],
|
|
1685
|
+
aborted: false,
|
|
1686
|
+
newFiles: [],
|
|
1687
|
+
newFilesCount: 0,
|
|
1688
|
+
filesExcludedByPolicy: 0,
|
|
1689
|
+
filesTombstoned: 0,
|
|
1690
|
+
filesOutOfScope: 0,
|
|
1691
|
+
scopeOrphansRemoved: 0,
|
|
1692
|
+
scopeOrphansBlocked: 0,
|
|
1693
|
+
changedPaths: [],
|
|
1694
|
+
};
|
|
1695
|
+
let hqRoot;
|
|
1696
|
+
let stateDir;
|
|
1697
|
+
let previousStateDir;
|
|
1698
|
+
beforeEach(() => {
|
|
1699
|
+
hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-journal-slugs-"));
|
|
1700
|
+
stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-journal-state-"));
|
|
1701
|
+
previousStateDir = process.env.HQ_STATE_DIR;
|
|
1702
|
+
process.env.HQ_STATE_DIR = stateDir;
|
|
1703
|
+
fs.mkdirSync(path.join(hqRoot, "personal"), { recursive: true });
|
|
1704
|
+
});
|
|
1705
|
+
afterEach(() => {
|
|
1706
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
1707
|
+
fs.rmSync(stateDir, { recursive: true, force: true });
|
|
1708
|
+
if (previousStateDir === undefined)
|
|
1709
|
+
delete process.env.HQ_STATE_DIR;
|
|
1710
|
+
else
|
|
1711
|
+
process.env.HQ_STATE_DIR = previousStateDir;
|
|
1712
|
+
});
|
|
1713
|
+
function writeCompanyDir(slug) {
|
|
1714
|
+
fs.mkdirSync(path.join(hqRoot, "companies", slug), { recursive: true });
|
|
1715
|
+
}
|
|
1716
|
+
function writeJournalLocator(slug) {
|
|
1717
|
+
fs.writeFileSync(path.join(stateDir, `sync-journal.${slug}.json`), JSON.stringify({ schema: "hq-sync-journal-locator@1" }));
|
|
1718
|
+
}
|
|
1719
|
+
function relSharePaths(shareFn) {
|
|
1720
|
+
const call = shareFn.mock.calls[0];
|
|
1721
|
+
expect(call).toBeDefined();
|
|
1722
|
+
return call[0].paths.map((p) => path.relative(hqRoot, p)).sort();
|
|
1723
|
+
}
|
|
1724
|
+
async function runPersonalBoth(shareFn = vi.fn(async (_options) => shareResult), syncFn = vi.fn(async (_options) => syncResult)) {
|
|
1725
|
+
const events = [];
|
|
1726
|
+
await executeCompanyFanout({
|
|
1727
|
+
plan: [{ uid: "prs_1", slug: "personal", personalMode: true }],
|
|
1728
|
+
direction: "both",
|
|
1729
|
+
hqRoot,
|
|
1730
|
+
onConflict: "abort",
|
|
1731
|
+
client: {},
|
|
1732
|
+
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
1733
|
+
fetchFileTombstones: async () => new Map(),
|
|
1734
|
+
syncFn,
|
|
1735
|
+
shareFn,
|
|
1736
|
+
resolveDeletePolicy: () => "all",
|
|
1737
|
+
emit: (event) => events.push(event),
|
|
1738
|
+
ensureCompanyDir: vi.fn(),
|
|
1739
|
+
telemetryClient: null,
|
|
1740
|
+
});
|
|
1741
|
+
return { events, shareFn, syncFn };
|
|
1742
|
+
}
|
|
1743
|
+
it("excludes companies/dandy from the personal push when its sync journal exists and there is no manifest", async () => {
|
|
1744
|
+
writeCompanyDir("dandy");
|
|
1745
|
+
writeJournalLocator("dandy");
|
|
1746
|
+
const { events, shareFn, syncFn } = await runPersonalBoth();
|
|
1747
|
+
const rel = relSharePaths(shareFn);
|
|
1748
|
+
expect(rel).not.toContain(path.join("companies", "dandy"));
|
|
1749
|
+
expect(rel).toContain("personal");
|
|
1750
|
+
const shareArgs = shareFn.mock.calls[0][0];
|
|
1751
|
+
expect(shareArgs.decommissionPrefixes).toEqual(["companies/dandy"]);
|
|
1752
|
+
const pullArgs = syncFn.mock.calls[0][0];
|
|
1753
|
+
expect(Array.from(pullArgs.teamSyncedSlugs ?? [])).toEqual(["dandy"]);
|
|
1754
|
+
expect(events).toContainEqual({
|
|
1755
|
+
type: "error",
|
|
1756
|
+
diagnostic: true,
|
|
1757
|
+
company: "personal",
|
|
1758
|
+
path: "(personal-vault)",
|
|
1759
|
+
message: "excluding journaled companies from personal vault: dandy",
|
|
1760
|
+
});
|
|
1761
|
+
expect(events.some((e) => e.type === "error" && e.diagnostic !== true)).toBe(false);
|
|
1762
|
+
});
|
|
1763
|
+
it("still includes a local-only company that has no journal when there is no manifest", async () => {
|
|
1764
|
+
writeCompanyDir("local-only");
|
|
1765
|
+
const { events, shareFn, syncFn } = await runPersonalBoth();
|
|
1766
|
+
const rel = relSharePaths(shareFn);
|
|
1767
|
+
expect(rel).toContain(path.join("companies", "local-only"));
|
|
1768
|
+
expect(shareFn.mock.calls[0][0]).not.toHaveProperty("decommissionPrefixes");
|
|
1769
|
+
expect(Array.from(syncFn.mock.calls[0][0].teamSyncedSlugs ?? [])).toEqual([]);
|
|
1770
|
+
expect(events.some((e) => e.type === "error")).toBe(false);
|
|
1771
|
+
});
|
|
1772
|
+
it("does not treat the personal-vault sentinel journal as a company slug", async () => {
|
|
1773
|
+
writeCompanyDir("local-only");
|
|
1774
|
+
writeJournalLocator(PERSONAL_VAULT_JOURNAL_SLUG);
|
|
1775
|
+
const { events, shareFn, syncFn } = await runPersonalBoth();
|
|
1776
|
+
const rel = relSharePaths(shareFn);
|
|
1777
|
+
expect(rel).toContain(path.join("companies", "local-only"));
|
|
1778
|
+
expect(shareFn.mock.calls[0][0]).not.toHaveProperty("decommissionPrefixes");
|
|
1779
|
+
expect(Array.from(syncFn.mock.calls[0][0].teamSyncedSlugs ?? [])).toEqual([]);
|
|
1780
|
+
expect(events.some((e) => e.type === "error")).toBe(false);
|
|
1781
|
+
});
|
|
1782
|
+
it("does not pass journal-derived teamSyncedSlugs to a company target", async () => {
|
|
1783
|
+
writeCompanyDir("dandy");
|
|
1784
|
+
writeJournalLocator("dandy");
|
|
1785
|
+
const shareFn = vi.fn(async (_options) => shareResult);
|
|
1786
|
+
const syncFn = vi.fn(async (_options) => syncResult);
|
|
1787
|
+
await executeCompanyFanout({
|
|
1788
|
+
plan: [{ uid: "cmp_dandy", slug: "dandy" }],
|
|
1789
|
+
direction: "both",
|
|
1790
|
+
hqRoot,
|
|
1791
|
+
onConflict: "abort",
|
|
1792
|
+
client: {},
|
|
1793
|
+
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
1794
|
+
fetchFileTombstones: async () => new Map(),
|
|
1795
|
+
syncFn,
|
|
1796
|
+
shareFn,
|
|
1797
|
+
resolveDeletePolicy: () => "all",
|
|
1798
|
+
emit: vi.fn(),
|
|
1799
|
+
ensureCompanyDir: vi.fn(),
|
|
1800
|
+
telemetryClient: null,
|
|
1801
|
+
});
|
|
1802
|
+
expect(shareFn.mock.calls[0][0].paths).toEqual([
|
|
1803
|
+
path.join(hqRoot, "companies", "dandy"),
|
|
1804
|
+
]);
|
|
1805
|
+
expect(shareFn.mock.calls[0][0]).not.toHaveProperty("decommissionPrefixes");
|
|
1806
|
+
expect(Object.keys(syncFn.mock.calls[0][0])).not.toContain("teamSyncedSlugs");
|
|
1807
|
+
});
|
|
1808
|
+
});
|
|
1809
|
+
describe("executeCompanyFanout work-bearing sync count telemetry", () => {
|
|
1810
|
+
function emptyShare(overrides = {}) {
|
|
1811
|
+
return {
|
|
1812
|
+
filesUploaded: 0,
|
|
1813
|
+
bytesUploaded: 0,
|
|
1814
|
+
filesSkipped: 0,
|
|
1815
|
+
filesDeleted: 0,
|
|
1816
|
+
filesTombstoned: 0,
|
|
1817
|
+
filesRefusedStale: 0,
|
|
1818
|
+
filesRefusedStalePaths: [],
|
|
1819
|
+
filesSuppressedByTombstone: 0,
|
|
1820
|
+
filesExcludedByPolicy: 0,
|
|
1821
|
+
filesExcludedByScope: 0,
|
|
1822
|
+
filesExcludedByIgnore: 0,
|
|
1823
|
+
unreachablePaths: [],
|
|
1824
|
+
linkedSubtreesNotShipped: [],
|
|
1825
|
+
conflictPaths: [],
|
|
1826
|
+
aborted: false,
|
|
1827
|
+
...overrides,
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
function emptySync(overrides = {}) {
|
|
1831
|
+
return {
|
|
1832
|
+
filesDownloaded: 0,
|
|
1833
|
+
bytesDownloaded: 0,
|
|
1834
|
+
filesSkipped: 0,
|
|
1835
|
+
conflicts: 0,
|
|
1836
|
+
conflictPaths: [],
|
|
1837
|
+
aborted: false,
|
|
1838
|
+
newFiles: [],
|
|
1839
|
+
newFilesCount: 0,
|
|
1840
|
+
filesExcludedByPolicy: 0,
|
|
1841
|
+
filesTombstoned: 0,
|
|
1842
|
+
filesOutOfScope: 0,
|
|
1843
|
+
scopeOrphansRemoved: 0,
|
|
1844
|
+
scopeOrphansBlocked: 0,
|
|
1845
|
+
changedPaths: [],
|
|
1846
|
+
...overrides,
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
async function runPersonalFanout(args) {
|
|
1850
|
+
const posts = [];
|
|
1851
|
+
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fanout-sync-counts-"));
|
|
1852
|
+
fs.mkdirSync(path.join(hqRoot, "personal"), { recursive: true });
|
|
1853
|
+
try {
|
|
1854
|
+
await executeCompanyFanout({
|
|
1855
|
+
plan: [{ uid: "prs_1", slug: "personal", personalMode: true }],
|
|
1856
|
+
direction: args.direction ?? "both",
|
|
1857
|
+
hqRoot,
|
|
1858
|
+
onConflict: "abort",
|
|
1859
|
+
client: {},
|
|
1860
|
+
vaultConfig: { apiUrl: "https://api.example", authToken: "access-token" },
|
|
1861
|
+
fetchFileTombstones: async () => new Map(),
|
|
1862
|
+
syncFn: args.syncFn ?? (async () => emptySync()),
|
|
1863
|
+
shareFn: args.shareFn,
|
|
1864
|
+
resolveDeletePolicy: () => "all",
|
|
1865
|
+
emit: vi.fn(),
|
|
1866
|
+
ensureCompanyDir: vi.fn(),
|
|
1867
|
+
telemetryClient: {
|
|
1868
|
+
postTelemetryEvents: async (batch) => {
|
|
1869
|
+
posts.push(batch);
|
|
1870
|
+
return { ok: true, written: batch.events.length, skipped: [] };
|
|
1871
|
+
},
|
|
1872
|
+
},
|
|
1873
|
+
});
|
|
1874
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1875
|
+
return posts.flatMap((post) => post.events);
|
|
1876
|
+
}
|
|
1877
|
+
finally {
|
|
1878
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
it("emits uploadedCount, downloadedCount, and sessionLogUploadedCount on a work-bearing leg", async () => {
|
|
1882
|
+
const events = await runPersonalFanout({
|
|
1883
|
+
shareFn: async () => emptyShare({ filesUploaded: 4, bytesUploaded: 400 }),
|
|
1884
|
+
syncFn: async () => emptySync({ filesDownloaded: 2, bytesDownloaded: 200 }),
|
|
1885
|
+
});
|
|
1886
|
+
const leg = events.find((event) => event.eventName === "company_sync_leg_completed");
|
|
1887
|
+
expect(leg).toMatchObject({
|
|
1888
|
+
app: "hq-cloud",
|
|
1889
|
+
source: "sync-runner",
|
|
1890
|
+
properties: {
|
|
1891
|
+
status: "complete",
|
|
1892
|
+
filesUploaded: 4,
|
|
1893
|
+
filesDownloaded: 2,
|
|
1894
|
+
uploadedCount: 4,
|
|
1895
|
+
downloadedCount: 2,
|
|
1896
|
+
sessionLogUploadedCount: 0,
|
|
1897
|
+
},
|
|
1898
|
+
});
|
|
1899
|
+
});
|
|
1900
|
+
it("counts only SESSION_LOGS_SYNC_REL uploads and never emits a path", async () => {
|
|
1901
|
+
const events = await runPersonalFanout({
|
|
1902
|
+
direction: "push",
|
|
1903
|
+
shareFn: async (options) => {
|
|
1904
|
+
options.onEvent?.({
|
|
1905
|
+
type: "progress",
|
|
1906
|
+
path: `${SESSION_LOGS_SYNC_REL}/claude/a.jsonl`,
|
|
1907
|
+
bytes: 11,
|
|
1908
|
+
});
|
|
1909
|
+
options.onEvent?.({
|
|
1910
|
+
type: "progress",
|
|
1911
|
+
path: `${SESSION_LOGS_SYNC_REL}/codex/b.jsonl`,
|
|
1912
|
+
bytes: 22,
|
|
1913
|
+
});
|
|
1914
|
+
options.onEvent?.({
|
|
1915
|
+
type: "progress",
|
|
1916
|
+
path: "personal/notes.md",
|
|
1917
|
+
bytes: 33,
|
|
1918
|
+
});
|
|
1919
|
+
options.onEvent?.({
|
|
1920
|
+
type: "progress",
|
|
1921
|
+
path: "workspace/.session-logs-old/x.jsonl",
|
|
1922
|
+
bytes: 44,
|
|
1923
|
+
});
|
|
1924
|
+
options.onEvent?.({
|
|
1925
|
+
type: "progress",
|
|
1926
|
+
path: `${SESSION_LOGS_SYNC_REL}/claude/deleted.jsonl`,
|
|
1927
|
+
bytes: 0,
|
|
1928
|
+
deleted: true,
|
|
1929
|
+
});
|
|
1930
|
+
return emptyShare({ filesUploaded: 4, bytesUploaded: 110 });
|
|
1931
|
+
},
|
|
1932
|
+
});
|
|
1933
|
+
const leg = events.find((event) => event.eventName === "company_sync_leg_completed");
|
|
1934
|
+
expect(leg?.properties).toMatchObject({
|
|
1935
|
+
uploadedCount: 4,
|
|
1936
|
+
downloadedCount: 0,
|
|
1937
|
+
sessionLogUploadedCount: 2,
|
|
1938
|
+
filesUploaded: 4,
|
|
1939
|
+
});
|
|
1940
|
+
const serialized = JSON.stringify(leg);
|
|
1941
|
+
expect(serialized).not.toContain(`${SESSION_LOGS_SYNC_REL}/`);
|
|
1942
|
+
expect(serialized).not.toContain("personal/notes.md");
|
|
1943
|
+
expect(serialized).not.toContain("session-logs-old");
|
|
1944
|
+
expect(serialized.toLowerCase()).not.toContain("filename");
|
|
1945
|
+
});
|
|
1946
|
+
it("emits no company_sync_leg_completed on an empty cycle", async () => {
|
|
1947
|
+
const events = await runPersonalFanout({
|
|
1948
|
+
shareFn: async () => emptyShare(),
|
|
1949
|
+
syncFn: async () => emptySync(),
|
|
1950
|
+
});
|
|
1951
|
+
expect(events.map((event) => event.eventName)).not.toContain("company_sync_leg_completed");
|
|
1952
|
+
});
|
|
1953
|
+
it("keeps the three count keys after emitCloudTelemetry redaction", async () => {
|
|
1954
|
+
const events = await runPersonalFanout({
|
|
1955
|
+
direction: "push",
|
|
1956
|
+
shareFn: async (options) => {
|
|
1957
|
+
options.onEvent?.({
|
|
1958
|
+
type: "progress",
|
|
1959
|
+
path: `${SESSION_LOGS_SYNC_REL}/grok/c.jsonl`,
|
|
1960
|
+
bytes: 9,
|
|
1961
|
+
});
|
|
1962
|
+
return emptyShare({ filesUploaded: 1, bytesUploaded: 9 });
|
|
1963
|
+
},
|
|
1964
|
+
});
|
|
1965
|
+
const leg = events.find((event) => event.eventName === "company_sync_leg_completed");
|
|
1966
|
+
expect(leg?.properties).toEqual(expect.objectContaining({
|
|
1967
|
+
uploadedCount: 1,
|
|
1968
|
+
downloadedCount: 0,
|
|
1969
|
+
sessionLogUploadedCount: 1,
|
|
1970
|
+
filesUploaded: 1,
|
|
1971
|
+
}));
|
|
1972
|
+
expect(leg?.properties).not.toHaveProperty("path");
|
|
1973
|
+
expect(leg?.properties).not.toHaveProperty("canonicalPath");
|
|
1974
|
+
expect(JSON.stringify(leg?.properties)).not.toContain(SESSION_LOGS_SYNC_REL);
|
|
1975
|
+
});
|
|
1976
|
+
});
|
|
1364
1977
|
//# sourceMappingURL=sync-runner-company.test.js.map
|