@indigoai-us/hq-cloud 6.16.83-alpha.0 → 6.16.85-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-watch-loop.d.ts +22 -19
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +127 -61
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +2 -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 +641 -296
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +50 -9
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +224 -1
- package/dist/cli/share.test.js.map +1 -1
- package/dist/lib/machine-id.d.ts +7 -0
- package/dist/lib/machine-id.d.ts.map +1 -1
- package/dist/lib/machine-id.js +54 -7
- package/dist/lib/machine-id.js.map +1 -1
- package/dist/lib/machine-id.test.js +20 -1
- package/dist/lib/machine-id.test.js.map +1 -1
- package/dist/object-io.d.ts +2 -0
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +78 -27
- package/dist/object-io.js.map +1 -1
- package/dist/object-io.test.js +107 -2
- package/dist/object-io.test.js.map +1 -1
- package/dist/sync/event-sync.d.ts +14 -4
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +148 -14
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/event-sync.test.js +321 -2
- package/dist/sync/event-sync.test.js.map +1 -1
- package/dist/sync/full-pass-interval.d.ts +25 -0
- package/dist/sync/full-pass-interval.d.ts.map +1 -0
- package/dist/sync/full-pass-interval.js +53 -0
- package/dist/sync/full-pass-interval.js.map +1 -0
- package/dist/sync/full-pass-interval.test.d.ts +2 -0
- package/dist/sync/full-pass-interval.test.d.ts.map +1 -0
- package/dist/sync/full-pass-interval.test.js +21 -0
- package/dist/sync/full-pass-interval.test.js.map +1 -0
- package/dist/sync/parallel-sync-coordinator.d.ts +1 -0
- package/dist/sync/parallel-sync-coordinator.d.ts.map +1 -1
- package/dist/sync/parallel-sync-coordinator.js +39 -8
- package/dist/sync/parallel-sync-coordinator.js.map +1 -1
- package/dist/sync/parallel-sync-coordinator.test.js +33 -1
- package/dist/sync/parallel-sync-coordinator.test.js.map +1 -1
- package/dist/sync/push-receiver.d.ts +3 -1
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +45 -9
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +70 -0
- package/dist/sync/push-receiver.test.js.map +1 -1
- package/dist/sync/push-transport.d.ts +15 -0
- package/dist/sync/push-transport.d.ts.map +1 -1
- package/dist/sync/push-transport.js +27 -0
- package/dist/sync/push-transport.js.map +1 -1
- package/dist/sync/push-transport.test.js +14 -1
- package/dist/sync/push-transport.test.js.map +1 -1
- package/dist/sync/sync-work.d.ts +5 -0
- package/dist/sync/sync-work.d.ts.map +1 -1
- package/dist/sync/sync-work.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,11 +16,12 @@ import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
|
16
16
|
import { runRunner, runRunnerWithLoop, resolveDeletePolicy, resolveSkipPersonal, resolveSkipCompanies, selectObjectIOFactory, routeChangeToTarget, buildTargetedPushArgv, resolvePullScope, readPinnedPrefixes, SESSIONS_SCOPE_PREFIX, defaultCollectTelemetry, AUTH_REQUIRED_PASS_EXIT, } from "./sync-runner.js";
|
|
17
17
|
import { SESSION_LOGS_PUSH_ONLY_PREFIX } from "../sync/pull-scope.js";
|
|
18
18
|
import { AUTH_WAIT_INITIAL_RECHECK_MS, AUTH_WAIT_RESUME_MESSAGE, AUTH_WAIT_START_MESSAGE, AUTH_WAIT_STEADY_RECHECK_MS, } from "./sync-runner-auth-wait.js";
|
|
19
|
-
import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
|
|
19
|
+
import { ObjectLockChecksumRequiredError, PresignObjectIO, S3SdkObjectIO, } from "../object-io.js";
|
|
20
20
|
import { setBandwidthGovernorForTesting } from "../bandwidth.js";
|
|
21
21
|
import { POST_SYNC_FLAG_KEYS, } from "./sync-runner-post-sync-flags.js";
|
|
22
22
|
import { FakeClock, TreeWatcher, } from "../watcher.js";
|
|
23
|
-
import { adaptivePollMs, advanceMonotonicDeadline, DEFAULT_EVENT_BATCH_LIMIT, DEFAULT_FAST_LANE_MAX_BYTES, DEFAULT_FAST_LANE_MAX_FILE_BYTES, DEFAULT_FAST_LANE_MAX_FILES,
|
|
23
|
+
import { adaptivePollMs, advanceMonotonicDeadline, DEFAULT_EVENT_BATCH_LIMIT, DEFAULT_FAST_LANE_MAX_BYTES, DEFAULT_FAST_LANE_MAX_FILE_BYTES, DEFAULT_FAST_LANE_MAX_FILES, EVENT_BATCH_LIMIT_ENV, FAST_LANE_MAX_BYTES_ENV, FAST_LANE_MAX_FILES_ENV, isFastLocalBatch, isFastReceiverBatch, partitionLocalBatch, journalEntriesForWatcherDelete, resolveEventBatchLimit, resolveWatchPollMs, CHORE_STARVATION_CAP_MS, CooperativePassScheduler, REALTIME_ADMISSION_DEADLINE_MS, REALTIME_DRAIN_BURST_MS, REALTIME_WORKER_OCCUPANCY_CAP, RealtimeAdmissionTimeoutError, setRealtimeAdmissionDeadlineMsForTesting, setRealtimeDrainBurstMsForTesting, normalizeCoordinatorPaths, shouldQuarantineWatcherDeleteIntents, shouldUseAreaStorage, WATCHER_REDISCOVERY_RETRY_MS, WATCHER_REDISCOVERY_RETRY_MAX_MS, } from "./sync-runner-watch-loop.js";
|
|
24
|
+
import { DEFAULT_FULL_PASS_INTERVAL_MS } from "../sync/full-pass-interval.js";
|
|
24
25
|
import { FullPassCapController, resetFullPassCapLogForTest, } from "../sync/full-pass-caps.js";
|
|
25
26
|
import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, readJournalScoped, writeJournal, } from "../journal.js";
|
|
26
27
|
import { AreaLedger } from "../sync/area-ledger.js";
|
|
@@ -565,6 +566,79 @@ describe("mid-pass identity refusal", () => {
|
|
|
565
566
|
expect(deps.stderr.events().some((e) => e.type === "auth-error")).toBe(false);
|
|
566
567
|
});
|
|
567
568
|
});
|
|
569
|
+
describe("remote failure contract", () => {
|
|
570
|
+
const person = {
|
|
571
|
+
uid: "ent_person_remote_failure_contract",
|
|
572
|
+
type: "person",
|
|
573
|
+
bucketName: "hq-vault-personal-contract",
|
|
574
|
+
status: "active",
|
|
575
|
+
};
|
|
576
|
+
it.each([
|
|
577
|
+
[
|
|
578
|
+
"terminal 403 refusal",
|
|
579
|
+
() => new CognitoRefreshError("session reauth required (403)", true, 403),
|
|
580
|
+
0,
|
|
581
|
+
"auth-error",
|
|
582
|
+
"quick refresh",
|
|
583
|
+
],
|
|
584
|
+
[
|
|
585
|
+
"404 route",
|
|
586
|
+
() => new VaultNotFoundError("remote route no longer exists (404)"),
|
|
587
|
+
PARTIAL_SYNC_EXIT,
|
|
588
|
+
"error",
|
|
589
|
+
"404",
|
|
590
|
+
],
|
|
591
|
+
[
|
|
592
|
+
"429 throttle",
|
|
593
|
+
() => Object.assign(new Error("remote throttled (429)"), { statusCode: 429 }),
|
|
594
|
+
TRANSIENT_NETWORK_EXIT,
|
|
595
|
+
"transient-network",
|
|
596
|
+
"429",
|
|
597
|
+
],
|
|
598
|
+
[
|
|
599
|
+
"503 throttle",
|
|
600
|
+
() => Object.assign(new Error("remote unavailable (503)"), { statusCode: 503 }),
|
|
601
|
+
TRANSIENT_NETWORK_EXIT,
|
|
602
|
+
"transient-network",
|
|
603
|
+
"503",
|
|
604
|
+
],
|
|
605
|
+
[
|
|
606
|
+
"Object Lock checksum refusal",
|
|
607
|
+
() => new ObjectLockChecksumRequiredError("remote.md", "checksum required"),
|
|
608
|
+
PARTIAL_SYNC_EXIT,
|
|
609
|
+
"error",
|
|
610
|
+
"ObjectLockChecksumRequired",
|
|
611
|
+
],
|
|
612
|
+
[
|
|
613
|
+
"timeout",
|
|
614
|
+
() => Object.assign(new Error("remote timed out"), { name: "TimeoutError" }),
|
|
615
|
+
TRANSIENT_NETWORK_EXIT,
|
|
616
|
+
"transient-network",
|
|
617
|
+
"timed out",
|
|
618
|
+
],
|
|
619
|
+
[
|
|
620
|
+
"abort",
|
|
621
|
+
() => Object.assign(new Error("remote aborted"), { name: "AbortError" }),
|
|
622
|
+
TRANSIENT_NETWORK_EXIT,
|
|
623
|
+
"transient-network",
|
|
624
|
+
"aborted",
|
|
625
|
+
],
|
|
626
|
+
])("keeps the journal stable and records the runner outcome for %s", async (_description, makeFailure, expectedExit, telemetryType, telemetryReason) => {
|
|
627
|
+
const before = readJournal(PERSONAL_VAULT_JOURNAL_SLUG);
|
|
628
|
+
const deps = makeDeps({
|
|
629
|
+
sync: vi.fn().mockRejectedValue(makeFailure()),
|
|
630
|
+
createVaultClient: () => makeVaultStub({ listPersons: () => Promise.resolve([person]) }),
|
|
631
|
+
});
|
|
632
|
+
expect(await runRunner(["--personal"], deps)).toBe(expectedExit);
|
|
633
|
+
expect(readJournal(PERSONAL_VAULT_JOURNAL_SLUG).files).toEqual(before.files);
|
|
634
|
+
const events = [...deps.stdout.events(), ...deps.stderr.events()];
|
|
635
|
+
expect(events.some((event) => event.type === telemetryType)).toBe(true);
|
|
636
|
+
expect(`${deps.stdout.raw()}${deps.stderr.raw()}`).toContain(telemetryReason);
|
|
637
|
+
if (telemetryType === "transient-network") {
|
|
638
|
+
expect(events.some((event) => event.type === "error")).toBe(false);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
});
|
|
568
642
|
// ---------------------------------------------------------------------------
|
|
569
643
|
// memberships retry (3x with backoff, then abort)
|
|
570
644
|
// ---------------------------------------------------------------------------
|
|
@@ -4636,28 +4710,13 @@ describe("advanceMonotonicDeadline", () => {
|
|
|
4636
4710
|
});
|
|
4637
4711
|
});
|
|
4638
4712
|
});
|
|
4639
|
-
describe("watch-loop reconcile
|
|
4713
|
+
describe("watch-loop reconcile configuration", () => {
|
|
4640
4714
|
it("uses the shipped 10,000 event-batch default while allowing smaller and larger overrides", () => {
|
|
4641
4715
|
expect(DEFAULT_EVENT_BATCH_LIMIT).toBe(10_000);
|
|
4642
4716
|
expect(resolveEventBatchLimit({})).toBe(10_000);
|
|
4643
4717
|
expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
|
|
4644
4718
|
expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
|
|
4645
4719
|
});
|
|
4646
|
-
it("defaults the full-reconcile cadence to one elapsed hour for an unset or invalid interval", () => {
|
|
4647
|
-
// The legacy default was "every tenth tick" with no elapsed-time floor.
|
|
4648
|
-
// Ticks fire on every watcher batch, not just polls, so on an active
|
|
4649
|
-
// vault that meant a full pass every 4-8 minutes — and each pass on a
|
|
4650
|
-
// real install lasts ~10 minutes. Full reconcile is the correctness
|
|
4651
|
-
// backstop behind event-push, so elapsed time is the right clock.
|
|
4652
|
-
expect(DEFAULT_FULL_RECONCILE_MS).toBe(3_600_000);
|
|
4653
|
-
expect(resolveFullReconcileMs({})).toBe(DEFAULT_FULL_RECONCILE_MS);
|
|
4654
|
-
for (const raw of ["", "0", "0.5", "-1", "NaN", "not-a-number", "Infinity"]) {
|
|
4655
|
-
expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: raw })).toBe(DEFAULT_FULL_RECONCILE_MS);
|
|
4656
|
-
}
|
|
4657
|
-
});
|
|
4658
|
-
it("accepts a positive millisecond full-reconcile interval", () => {
|
|
4659
|
-
expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: "10800000" })).toBe(10_800_000);
|
|
4660
|
-
});
|
|
4661
4720
|
});
|
|
4662
4721
|
describe("runRunnerWithLoop — adaptive poll interval (no --poll-remote-ms)", () => {
|
|
4663
4722
|
// Capture the ms handed to sleep on the FIRST poll, then hang so the loop
|
|
@@ -4873,10 +4932,8 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
4873
4932
|
it("parallel coordinator activates every event surface after a partial completed full reconcile", async () => {
|
|
4874
4933
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
4875
4934
|
const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
|
|
4876
|
-
const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
4877
4935
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
4878
4936
|
process.env.HQ_SYNC_EVENT_SYNC = "1";
|
|
4879
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
|
|
4880
4937
|
const watcher = makeWatcherStub();
|
|
4881
4938
|
const receiver = {
|
|
4882
4939
|
connected: false,
|
|
@@ -4936,19 +4993,13 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
4936
4993
|
delete process.env.HQ_SYNC_EVENT_SYNC;
|
|
4937
4994
|
else
|
|
4938
4995
|
process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
|
|
4939
|
-
if (previousFullReconcileMs === undefined)
|
|
4940
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
4941
|
-
else
|
|
4942
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
|
|
4943
4996
|
}
|
|
4944
4997
|
});
|
|
4945
4998
|
it("parallel coordinator activates event surfaces and advances cadence after a numeric-zero full reconcile", async () => {
|
|
4946
4999
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
4947
5000
|
const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
|
|
4948
|
-
const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
4949
5001
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
4950
5002
|
process.env.HQ_SYNC_EVENT_SYNC = "1";
|
|
4951
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
|
|
4952
5003
|
const watcher = makeWatcherStub();
|
|
4953
5004
|
const receiver = {
|
|
4954
5005
|
connected: false,
|
|
@@ -5008,10 +5059,55 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5008
5059
|
delete process.env.HQ_SYNC_EVENT_SYNC;
|
|
5009
5060
|
else
|
|
5010
5061
|
process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
|
|
5011
|
-
|
|
5012
|
-
|
|
5062
|
+
}
|
|
5063
|
+
});
|
|
5064
|
+
it("backs off failed parallel full-reconcile completions before another chore is admitted", async () => {
|
|
5065
|
+
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5066
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
5067
|
+
const runPass = vi.fn().mockResolvedValue(1);
|
|
5068
|
+
const delays = [];
|
|
5069
|
+
const waiters = [];
|
|
5070
|
+
let now = 0;
|
|
5071
|
+
let shutdown = () => { };
|
|
5072
|
+
const sleep = (ms) => {
|
|
5073
|
+
delays.push(ms);
|
|
5074
|
+
return new Promise((resolve) => {
|
|
5075
|
+
waiters.push(resolve);
|
|
5076
|
+
});
|
|
5077
|
+
};
|
|
5078
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--poll-remote-ms", "1", "--hq-root", "/tmp/hq"], {
|
|
5079
|
+
runPass,
|
|
5080
|
+
clock: new FakeClock(),
|
|
5081
|
+
monotonicNow: () => now,
|
|
5082
|
+
sleep,
|
|
5083
|
+
fullPassIntervalSource: { read: () => 1 },
|
|
5084
|
+
onShutdownSignal: (handler) => {
|
|
5085
|
+
shutdown = handler;
|
|
5086
|
+
return () => { };
|
|
5087
|
+
},
|
|
5088
|
+
});
|
|
5089
|
+
try {
|
|
5090
|
+
for (let attempt = 0; attempt < 50 && runPass.mock.calls.length < 3; attempt += 1) {
|
|
5091
|
+
const resolve = waiters.shift();
|
|
5092
|
+
if (resolve) {
|
|
5093
|
+
now += 1;
|
|
5094
|
+
resolve();
|
|
5095
|
+
await flushLoopMicrotasks(30);
|
|
5096
|
+
}
|
|
5097
|
+
else {
|
|
5098
|
+
await new Promise((resolveNext) => setImmediate(resolveNext));
|
|
5099
|
+
}
|
|
5100
|
+
}
|
|
5101
|
+
expect(runPass).toHaveBeenCalledTimes(3);
|
|
5102
|
+
expect(delays).toContain(60_000);
|
|
5103
|
+
}
|
|
5104
|
+
finally {
|
|
5105
|
+
shutdown();
|
|
5106
|
+
await expect(loop).resolves.toBe(0);
|
|
5107
|
+
if (previousCoordinator === undefined)
|
|
5108
|
+
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5013
5109
|
else
|
|
5014
|
-
process.env.
|
|
5110
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
5015
5111
|
}
|
|
5016
5112
|
});
|
|
5017
5113
|
it("parallel coordinator keeps event surfaces off for an auth-required full reconcile", async () => {
|
|
@@ -5144,7 +5240,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5144
5240
|
sleep.tick();
|
|
5145
5241
|
await flushLoopMicrotasks();
|
|
5146
5242
|
}
|
|
5147
|
-
clockState.now =
|
|
5243
|
+
clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
|
|
5148
5244
|
sleep.tick();
|
|
5149
5245
|
await flushLoopMicrotasks();
|
|
5150
5246
|
// Tick 1 and the first tick after an hour has elapsed are full
|
|
@@ -5212,7 +5308,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5212
5308
|
}
|
|
5213
5309
|
expect(runPass).toHaveBeenCalledTimes(1);
|
|
5214
5310
|
// The hourly cadence, not a tick count, schedules the next full pass.
|
|
5215
|
-
clockState.now =
|
|
5311
|
+
clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
|
|
5216
5312
|
sleep.tick();
|
|
5217
5313
|
await flushLoopMicrotasks(30);
|
|
5218
5314
|
expect(runPass).toHaveBeenCalledTimes(2);
|
|
@@ -6113,19 +6209,32 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6113
6209
|
}],
|
|
6114
6210
|
signal: new AbortController().signal,
|
|
6115
6211
|
});
|
|
6212
|
+
const secondReplacementFailure = expect(secondReplacement).rejects.toThrow("targeted pull failed");
|
|
6116
6213
|
await firstReplacementFailure;
|
|
6117
6214
|
await flushLoopMicrotasks(30);
|
|
6118
|
-
//
|
|
6119
|
-
//
|
|
6120
|
-
//
|
|
6121
|
-
// their receipts before a targeted pull becomes durable.
|
|
6215
|
+
// The queued first replacement is superseded, and the second may be
|
|
6216
|
+
// refused by the warm-up pull. Both stay retryable so SQS can redeliver
|
|
6217
|
+
// after the durable replacement instead of acknowledging a lost pull.
|
|
6122
6218
|
expect(runPass.mock.calls.filter(([argv]) => argv.includes("warmup-superseded.md"))).toHaveLength(0);
|
|
6123
6219
|
expect(settled).toBeUndefined();
|
|
6124
6220
|
await Promise.resolve();
|
|
6125
6221
|
expect(settled).toBeUndefined();
|
|
6126
6222
|
releaseHeld();
|
|
6127
6223
|
await heldReceiverWork;
|
|
6128
|
-
await
|
|
6224
|
+
await secondReplacementFailure;
|
|
6225
|
+
await receiverSync({
|
|
6226
|
+
events: [{
|
|
6227
|
+
kind: "upsert",
|
|
6228
|
+
relativePath: "companies/indigo/warmup-superseded.md",
|
|
6229
|
+
contentHash: "sha256:remote",
|
|
6230
|
+
mtime: "2026-08-28T01:22:33.000Z",
|
|
6231
|
+
originDeviceId: "peer-device",
|
|
6232
|
+
originTenantId: "tenant-indigo",
|
|
6233
|
+
sequenceNumber: 4,
|
|
6234
|
+
eventTimestamp: "2026-08-28T01:22:33.000Z",
|
|
6235
|
+
}],
|
|
6236
|
+
signal: new AbortController().signal,
|
|
6237
|
+
});
|
|
6129
6238
|
}
|
|
6130
6239
|
finally {
|
|
6131
6240
|
releaseHeld();
|
|
@@ -6164,14 +6273,14 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6164
6273
|
},
|
|
6165
6274
|
});
|
|
6166
6275
|
const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
|
6167
|
-
const event = (relativePath) => ({
|
|
6276
|
+
const event = (relativePath, sequenceNumber = 1) => ({
|
|
6168
6277
|
kind: "upsert",
|
|
6169
6278
|
relativePath,
|
|
6170
6279
|
contentHash: "sha256:remote",
|
|
6171
6280
|
mtime: "2026-08-28T01:22:30.000Z",
|
|
6172
6281
|
originDeviceId: "peer-device",
|
|
6173
6282
|
originTenantId: "tenant-indigo",
|
|
6174
|
-
sequenceNumber
|
|
6283
|
+
sequenceNumber,
|
|
6175
6284
|
eventTimestamp: "2026-08-28T01:22:30.000Z",
|
|
6176
6285
|
});
|
|
6177
6286
|
try {
|
|
@@ -6188,7 +6297,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6188
6297
|
});
|
|
6189
6298
|
await flushLoopMicrotasks();
|
|
6190
6299
|
const replacement = receiverSync({
|
|
6191
|
-
events: [event("companies/indigo/superseded.md")],
|
|
6300
|
+
events: [event("companies/indigo/superseded.md", 2)],
|
|
6192
6301
|
signal: new AbortController().signal,
|
|
6193
6302
|
});
|
|
6194
6303
|
await expect(superseded).rejects.toThrow("targeted pull failed");
|
|
@@ -6209,6 +6318,197 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6209
6318
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6210
6319
|
}
|
|
6211
6320
|
});
|
|
6321
|
+
it("keeps mixed durable and refused receiver paths retryable until the replacement completes", async () => {
|
|
6322
|
+
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6323
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6324
|
+
const watcher = makeBatchWatcherStub();
|
|
6325
|
+
let receiverSync;
|
|
6326
|
+
let shutdown = () => { };
|
|
6327
|
+
let releaseHeld = () => { };
|
|
6328
|
+
const held = new Promise((resolve) => { releaseHeld = resolve; });
|
|
6329
|
+
const runPass = vi.fn(async (argv) => {
|
|
6330
|
+
if (argv.includes("held.md"))
|
|
6331
|
+
await held;
|
|
6332
|
+
return completedPassOutcome();
|
|
6333
|
+
});
|
|
6334
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
|
|
6335
|
+
runPass,
|
|
6336
|
+
createWatcher: () => watcher,
|
|
6337
|
+
createReceiver: ({ syncBatchFn }) => {
|
|
6338
|
+
receiverSync = syncBatchFn;
|
|
6339
|
+
return { connected: true, start: async () => { }, dispose: async () => { } };
|
|
6340
|
+
},
|
|
6341
|
+
sleep: () => new Promise(() => { }),
|
|
6342
|
+
onShutdownSignal: (handler) => {
|
|
6343
|
+
shutdown = handler;
|
|
6344
|
+
return () => { };
|
|
6345
|
+
},
|
|
6346
|
+
});
|
|
6347
|
+
const event = (relativePath, sequenceNumber) => ({
|
|
6348
|
+
kind: "upsert",
|
|
6349
|
+
relativePath,
|
|
6350
|
+
contentHash: "sha256:remote",
|
|
6351
|
+
mtime: "2026-08-28T01:22:30.000Z",
|
|
6352
|
+
originDeviceId: "peer-device",
|
|
6353
|
+
originTenantId: "tenant-indigo",
|
|
6354
|
+
sequenceNumber,
|
|
6355
|
+
eventTimestamp: "2026-08-28T01:22:30.000Z",
|
|
6356
|
+
});
|
|
6357
|
+
try {
|
|
6358
|
+
await flushLoopMicrotasks(30);
|
|
6359
|
+
runPass.mockClear();
|
|
6360
|
+
const blocking = receiverSync({
|
|
6361
|
+
events: [event("companies/indigo/held.md", 1)],
|
|
6362
|
+
signal: new AbortController().signal,
|
|
6363
|
+
});
|
|
6364
|
+
await flushLoopMicrotasks();
|
|
6365
|
+
const mixed = receiverSync({
|
|
6366
|
+
events: [
|
|
6367
|
+
event("companies/indigo/durable.md", 1),
|
|
6368
|
+
event("companies/indigo/shared.md", 2),
|
|
6369
|
+
],
|
|
6370
|
+
signal: new AbortController().signal,
|
|
6371
|
+
});
|
|
6372
|
+
const mixedFailure = expect(mixed).rejects.toThrow("targeted pull failed");
|
|
6373
|
+
await flushLoopMicrotasks();
|
|
6374
|
+
const replacement = receiverSync({
|
|
6375
|
+
events: [event("companies/indigo/shared.md", 3)],
|
|
6376
|
+
signal: new AbortController().signal,
|
|
6377
|
+
});
|
|
6378
|
+
releaseHeld();
|
|
6379
|
+
await blocking;
|
|
6380
|
+
await mixedFailure;
|
|
6381
|
+
await replacement;
|
|
6382
|
+
expect(runPass.mock.calls.filter(([argv]) => argv.includes("durable.md"))).toHaveLength(1);
|
|
6383
|
+
}
|
|
6384
|
+
finally {
|
|
6385
|
+
releaseHeld();
|
|
6386
|
+
shutdown();
|
|
6387
|
+
await loop;
|
|
6388
|
+
if (previousCoordinator === undefined)
|
|
6389
|
+
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6390
|
+
else
|
|
6391
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6392
|
+
}
|
|
6393
|
+
});
|
|
6394
|
+
it("measures a queued realtime pass at the operation gate and marks append lock only after admission", async () => {
|
|
6395
|
+
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6396
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6397
|
+
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-telemetry-operation-gate-"));
|
|
6398
|
+
const watcher = makeBatchWatcherStub();
|
|
6399
|
+
let receiverSync;
|
|
6400
|
+
let shutdown = () => { };
|
|
6401
|
+
let releaseGuard = () => { };
|
|
6402
|
+
const guard = new Promise((resolve) => { releaseGuard = resolve; });
|
|
6403
|
+
let markGuardStarted = () => { };
|
|
6404
|
+
const guardStarted = new Promise((resolve) => { markGuardStarted = resolve; });
|
|
6405
|
+
let markTargetStarted = () => { };
|
|
6406
|
+
const targetStarted = new Promise((resolve) => { markTargetStarted = resolve; });
|
|
6407
|
+
let monotonicMs = 0;
|
|
6408
|
+
let guardReleased = false;
|
|
6409
|
+
let targetStartedAt;
|
|
6410
|
+
const timings = [];
|
|
6411
|
+
const stderr = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
|
|
6412
|
+
if (typeof chunk === "string" && chunk.startsWith("{")) {
|
|
6413
|
+
try {
|
|
6414
|
+
const record = JSON.parse(chunk);
|
|
6415
|
+
if (typeof record === "object" &&
|
|
6416
|
+
record !== null &&
|
|
6417
|
+
record.event === "sync.realtime.timing")
|
|
6418
|
+
timings.push(record);
|
|
6419
|
+
}
|
|
6420
|
+
catch {
|
|
6421
|
+
// Non-telemetry diagnostics are outside this assertion.
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
return true;
|
|
6425
|
+
});
|
|
6426
|
+
const includesScope = (argv, basename) => argv.some((argument) => argument === basename || argument.endsWith(`/${basename}`));
|
|
6427
|
+
const runPass = vi.fn(async (argv) => {
|
|
6428
|
+
if (includesScope(argv, "guard.md")) {
|
|
6429
|
+
markGuardStarted();
|
|
6430
|
+
await guard;
|
|
6431
|
+
return completedPassOutcome();
|
|
6432
|
+
}
|
|
6433
|
+
if (includesScope(argv, "target.md")) {
|
|
6434
|
+
expect(guardReleased).toBe(true);
|
|
6435
|
+
targetStartedAt = monotonicMs;
|
|
6436
|
+
markTargetStarted();
|
|
6437
|
+
monotonicMs += 1;
|
|
6438
|
+
}
|
|
6439
|
+
return completedPassOutcome();
|
|
6440
|
+
});
|
|
6441
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--direction", "push", "--hq-root", hqRoot], {
|
|
6442
|
+
runPass,
|
|
6443
|
+
createWatcher: () => watcher,
|
|
6444
|
+
createReceiver: ({ syncBatchFn }) => {
|
|
6445
|
+
receiverSync = syncBatchFn;
|
|
6446
|
+
return { connected: true, start: async () => { }, dispose: async () => { } };
|
|
6447
|
+
},
|
|
6448
|
+
monotonicNow: () => monotonicMs,
|
|
6449
|
+
sleep: () => new Promise(() => { }),
|
|
6450
|
+
onShutdownSignal: (handler) => {
|
|
6451
|
+
shutdown = handler;
|
|
6452
|
+
return () => { };
|
|
6453
|
+
},
|
|
6454
|
+
});
|
|
6455
|
+
const event = (relativePath) => ({
|
|
6456
|
+
kind: "upsert",
|
|
6457
|
+
relativePath,
|
|
6458
|
+
contentHash: "sha256:remote",
|
|
6459
|
+
mtime: "2026-09-23T00:00:00.000Z",
|
|
6460
|
+
originDeviceId: "peer-device",
|
|
6461
|
+
originTenantId: "tenant-indigo",
|
|
6462
|
+
sequenceNumber: 1,
|
|
6463
|
+
eventTimestamp: "2026-09-23T00:00:00.000Z",
|
|
6464
|
+
});
|
|
6465
|
+
try {
|
|
6466
|
+
await flushLoopMicrotasks(30);
|
|
6467
|
+
runPass.mockClear();
|
|
6468
|
+
const guardedPass = receiverSync({
|
|
6469
|
+
events: [event("companies/alpha/guard.md")],
|
|
6470
|
+
signal: new AbortController().signal,
|
|
6471
|
+
});
|
|
6472
|
+
await guardStarted;
|
|
6473
|
+
const targetAbsolutePath = path.join(hqRoot, "companies", "beta", "target.md");
|
|
6474
|
+
fs.mkdirSync(path.dirname(targetAbsolutePath), { recursive: true });
|
|
6475
|
+
fs.writeFileSync(targetAbsolutePath, "x");
|
|
6476
|
+
watcher.emit("companies/beta/target.md", {
|
|
6477
|
+
paths: new Map([
|
|
6478
|
+
[targetAbsolutePath, "companies/beta/target.md"],
|
|
6479
|
+
]),
|
|
6480
|
+
changes: new Map(),
|
|
6481
|
+
});
|
|
6482
|
+
await flushLoopMicrotasks(30);
|
|
6483
|
+
expect(targetStartedAt).toBeUndefined();
|
|
6484
|
+
monotonicMs += 25;
|
|
6485
|
+
guardReleased = true;
|
|
6486
|
+
releaseGuard();
|
|
6487
|
+
await guardedPass;
|
|
6488
|
+
await targetStarted;
|
|
6489
|
+
await flushLoopMicrotasks(30);
|
|
6490
|
+
expect(targetStartedAt).toBe(25);
|
|
6491
|
+
expect(timings).toHaveLength(2);
|
|
6492
|
+
const targetTiming = timings.find((record) => record.source === "watcher" &&
|
|
6493
|
+
record.direction === "push" &&
|
|
6494
|
+
record.outcome === "durable");
|
|
6495
|
+
expect(targetTiming).toBeDefined();
|
|
6496
|
+
expect(targetTiming?.timingMs?.operationGate).toBe(25);
|
|
6497
|
+
expect(targetTiming?.timingMs?.appendLock).toBe(0);
|
|
6498
|
+
}
|
|
6499
|
+
finally {
|
|
6500
|
+
guardReleased = true;
|
|
6501
|
+
releaseGuard();
|
|
6502
|
+
shutdown();
|
|
6503
|
+
await loop;
|
|
6504
|
+
stderr.mockRestore();
|
|
6505
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6506
|
+
if (previousCoordinator === undefined)
|
|
6507
|
+
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6508
|
+
else
|
|
6509
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6510
|
+
}
|
|
6511
|
+
});
|
|
6212
6512
|
it("REGRESSION: a fast receiver pull overtakes a slow watcher push and records admitted occupancy", async () => {
|
|
6213
6513
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6214
6514
|
const previousAreaStorage = process.env.HQ_SYNC_AREA_STORAGE;
|
|
@@ -8900,52 +9200,183 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
8900
9200
|
await expect(loop).resolves.toBe(0);
|
|
8901
9201
|
expect(watcher.disposed).toBe(false);
|
|
8902
9202
|
});
|
|
8903
|
-
it("
|
|
9203
|
+
it("bounds repeated watch-pass exits with a fake-clock retry budget while keeping the runner alive", async () => {
|
|
8904
9204
|
const watcher = makeWatcherStub();
|
|
8905
|
-
const
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
let
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
pushPathResults: [],
|
|
8916
|
-
companyFailures: [
|
|
8917
|
-
{
|
|
8918
|
-
company: "personal",
|
|
8919
|
-
message: "RangeError Maximum call stack size exceeded",
|
|
8920
|
-
},
|
|
8921
|
-
],
|
|
8922
|
-
},
|
|
8923
|
-
};
|
|
8924
|
-
}
|
|
8925
|
-
return 1;
|
|
8926
|
-
});
|
|
8927
|
-
// Every clock read advances a full cadence interval, so the tick after
|
|
8928
|
-
// the partial pass is a scheduled full reconcile with a generic failure.
|
|
8929
|
-
let monotonic = 0;
|
|
8930
|
-
const sleep = makeSteppableSleep();
|
|
8931
|
-
let triggerShutdown = () => { };
|
|
8932
|
-
try {
|
|
8933
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
|
|
8934
|
-
runPass,
|
|
8935
|
-
clock: new FakeClock(),
|
|
8936
|
-
createWatcher: () => watcher,
|
|
8937
|
-
monotonicNow: () => (monotonic += DEFAULT_FULL_RECONCILE_MS),
|
|
8938
|
-
sleep: sleep.sleep,
|
|
8939
|
-
onShutdownSignal: (handler) => {
|
|
8940
|
-
triggerShutdown = handler;
|
|
8941
|
-
return () => { };
|
|
8942
|
-
},
|
|
9205
|
+
const runPass = vi.fn().mockResolvedValue(1);
|
|
9206
|
+
const delays = [];
|
|
9207
|
+
const waiters = [];
|
|
9208
|
+
let now = 0;
|
|
9209
|
+
let shutdown = () => { };
|
|
9210
|
+
let settled;
|
|
9211
|
+
const sleep = (ms) => {
|
|
9212
|
+
delays.push(ms);
|
|
9213
|
+
return new Promise((resolve) => {
|
|
9214
|
+
waiters.push(resolve);
|
|
8943
9215
|
});
|
|
9216
|
+
};
|
|
9217
|
+
const tick = async (advanceMs) => {
|
|
9218
|
+
now += advanceMs;
|
|
9219
|
+
const resolve = waiters.shift();
|
|
9220
|
+
if (!resolve)
|
|
9221
|
+
throw new Error("retry sleep was not pending");
|
|
9222
|
+
resolve();
|
|
8944
9223
|
await flushLoopMicrotasks();
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
9224
|
+
};
|
|
9225
|
+
const waitForRetrySleep = async () => {
|
|
9226
|
+
for (let attempt = 0; attempt < 200; attempt += 1) {
|
|
9227
|
+
if (waiters.length > 0)
|
|
9228
|
+
return;
|
|
9229
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
9230
|
+
}
|
|
9231
|
+
throw new Error("timed out waiting for retry sleep");
|
|
9232
|
+
};
|
|
9233
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--poll-remote-ms", "1", "--hq-root", "/tmp/hq"], {
|
|
9234
|
+
runPass,
|
|
9235
|
+
clock: new FakeClock(),
|
|
9236
|
+
createWatcher: () => watcher,
|
|
9237
|
+
monotonicNow: () => now,
|
|
9238
|
+
sleep,
|
|
9239
|
+
onShutdownSignal: (handler) => {
|
|
9240
|
+
shutdown = handler;
|
|
9241
|
+
return () => { };
|
|
9242
|
+
},
|
|
9243
|
+
}).then((code) => {
|
|
9244
|
+
settled = code;
|
|
9245
|
+
return code;
|
|
9246
|
+
});
|
|
9247
|
+
try {
|
|
9248
|
+
await waitForRetrySleep();
|
|
9249
|
+
expect(runPass).toHaveBeenCalledTimes(1);
|
|
9250
|
+
expect(delays).toEqual([1]);
|
|
9251
|
+
await tick(1_000);
|
|
9252
|
+
expect(runPass).toHaveBeenCalledTimes(2);
|
|
9253
|
+
expect(delays).toEqual([1, 1]);
|
|
9254
|
+
await tick(1_000);
|
|
9255
|
+
expect(runPass).toHaveBeenCalledTimes(3);
|
|
9256
|
+
expect(delays).toEqual([1, 1, 60_000]);
|
|
9257
|
+
await tick(60_000);
|
|
9258
|
+
await tick(120_000);
|
|
9259
|
+
await tick(240_000);
|
|
9260
|
+
await tick(480_000);
|
|
9261
|
+
expect(runPass).toHaveBeenCalledTimes(7);
|
|
9262
|
+
expect(delays).toEqual([
|
|
9263
|
+
1,
|
|
9264
|
+
1,
|
|
9265
|
+
60_000,
|
|
9266
|
+
120_000,
|
|
9267
|
+
240_000,
|
|
9268
|
+
480_000,
|
|
9269
|
+
600_000,
|
|
9270
|
+
]);
|
|
9271
|
+
// The retry window is quiet-time based, not anchored to the first
|
|
9272
|
+
// failure. Continuing failures after thirty minutes must remain capped.
|
|
9273
|
+
await tick(600_000);
|
|
9274
|
+
await tick(600_000);
|
|
9275
|
+
expect(runPass).toHaveBeenCalledTimes(9);
|
|
9276
|
+
expect(delays.slice(-2)).toEqual([600_000, 600_000]);
|
|
9277
|
+
expect(settled).toBeUndefined();
|
|
9278
|
+
expect(watcher.disposed).toBe(false);
|
|
9279
|
+
}
|
|
9280
|
+
finally {
|
|
9281
|
+
shutdown();
|
|
9282
|
+
await expect(loop).resolves.toBe(0);
|
|
9283
|
+
}
|
|
9284
|
+
});
|
|
9285
|
+
it("does not let a watcher interrupt bypass a failed-pass retry deadline", async () => {
|
|
9286
|
+
const watcher = makeWatcherStub();
|
|
9287
|
+
let passes = 0;
|
|
9288
|
+
const runPass = vi.fn().mockImplementation(async () => {
|
|
9289
|
+
passes += 1;
|
|
9290
|
+
return passes === 1 ? 0 : 1;
|
|
9291
|
+
});
|
|
9292
|
+
const waiters = [];
|
|
9293
|
+
const now = 0;
|
|
9294
|
+
let shutdown = () => { };
|
|
9295
|
+
const sleep = vi.fn(() => new Promise((resolve) => {
|
|
9296
|
+
waiters.push(resolve);
|
|
9297
|
+
}));
|
|
9298
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--poll-remote-ms", "1", "--hq-root", "/tmp/hq"], {
|
|
9299
|
+
runPass,
|
|
9300
|
+
clock: new FakeClock(),
|
|
9301
|
+
createWatcher: () => watcher,
|
|
9302
|
+
monotonicNow: () => now,
|
|
9303
|
+
sleep,
|
|
9304
|
+
onShutdownSignal: (handler) => {
|
|
9305
|
+
shutdown = handler;
|
|
9306
|
+
return () => { };
|
|
9307
|
+
},
|
|
9308
|
+
});
|
|
9309
|
+
try {
|
|
9310
|
+
await waitForPollSleep({
|
|
9311
|
+
pendingCount: () => waiters.length,
|
|
9312
|
+
});
|
|
9313
|
+
expect(runPass).toHaveBeenCalledTimes(1);
|
|
9314
|
+
watcher.emit();
|
|
9315
|
+
await flushLoopMicrotasks(30);
|
|
9316
|
+
expect(runPass).toHaveBeenCalledTimes(2);
|
|
9317
|
+
watcher.emit();
|
|
9318
|
+
await flushLoopMicrotasks(30);
|
|
9319
|
+
expect(runPass).toHaveBeenCalledTimes(3);
|
|
9320
|
+
watcher.emit();
|
|
9321
|
+
await flushLoopMicrotasks(30);
|
|
9322
|
+
expect(runPass).toHaveBeenCalledTimes(4);
|
|
9323
|
+
expect(sleep).toHaveBeenLastCalledWith(60_000);
|
|
9324
|
+
watcher.emit();
|
|
9325
|
+
await flushLoopMicrotasks(30);
|
|
9326
|
+
expect(runPass).toHaveBeenCalledTimes(4);
|
|
9327
|
+
expect(sleep).toHaveBeenLastCalledWith(60_000);
|
|
9328
|
+
}
|
|
9329
|
+
finally {
|
|
9330
|
+
shutdown();
|
|
9331
|
+
await expect(loop).resolves.toBe(0);
|
|
9332
|
+
}
|
|
9333
|
+
});
|
|
9334
|
+
it("alerts when a partial pass failed before a company's download leg", async () => {
|
|
9335
|
+
const watcher = makeWatcherStub();
|
|
9336
|
+
const stderrWrite = vi
|
|
9337
|
+
.spyOn(process.stderr, "write")
|
|
9338
|
+
.mockImplementation(() => true);
|
|
9339
|
+
let passCount = 0;
|
|
9340
|
+
const runPass = vi.fn().mockImplementation(async () => {
|
|
9341
|
+
passCount++;
|
|
9342
|
+
if (passCount === 1) {
|
|
9343
|
+
return {
|
|
9344
|
+
exitCode: PARTIAL_SYNC_EXIT,
|
|
9345
|
+
result: {
|
|
9346
|
+
pushPathResults: [],
|
|
9347
|
+
companyFailures: [
|
|
9348
|
+
{
|
|
9349
|
+
company: "personal",
|
|
9350
|
+
message: "RangeError Maximum call stack size exceeded",
|
|
9351
|
+
},
|
|
9352
|
+
],
|
|
9353
|
+
},
|
|
9354
|
+
};
|
|
9355
|
+
}
|
|
9356
|
+
return 1;
|
|
9357
|
+
});
|
|
9358
|
+
// Every clock read advances a full cadence interval, so the tick after
|
|
9359
|
+
// the partial pass is a scheduled full reconcile with a generic failure.
|
|
9360
|
+
let monotonic = 0;
|
|
9361
|
+
const sleep = makeSteppableSleep();
|
|
9362
|
+
let triggerShutdown = () => { };
|
|
9363
|
+
try {
|
|
9364
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
|
|
9365
|
+
runPass,
|
|
9366
|
+
clock: new FakeClock(),
|
|
9367
|
+
createWatcher: () => watcher,
|
|
9368
|
+
monotonicNow: () => (monotonic += DEFAULT_FULL_PASS_INTERVAL_MS),
|
|
9369
|
+
sleep: sleep.sleep,
|
|
9370
|
+
onShutdownSignal: (handler) => {
|
|
9371
|
+
triggerShutdown = handler;
|
|
9372
|
+
return () => { };
|
|
9373
|
+
},
|
|
9374
|
+
});
|
|
9375
|
+
await flushLoopMicrotasks();
|
|
9376
|
+
sleep.tick();
|
|
9377
|
+
await flushLoopMicrotasks();
|
|
9378
|
+
expect(runPass).toHaveBeenCalledTimes(2);
|
|
9379
|
+
const stderr = stderrWrite.mock.calls
|
|
8949
9380
|
.map(([chunk]) => String(chunk))
|
|
8950
9381
|
.join("");
|
|
8951
9382
|
expect(stderr).toContain("hq-sync-runner: COMPANY PASS FAILED company=personal message=RangeError Maximum call stack size exceeded (downloads for this company did not run)");
|
|
@@ -9916,9 +10347,7 @@ describe("CooperativePassScheduler", () => {
|
|
|
9916
10347
|
describe("first-tick realtime yield", () => {
|
|
9917
10348
|
it("commits a watcher push at the first chore checkpoint without a wall-clock wait", async () => {
|
|
9918
10349
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
9919
|
-
const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
9920
10350
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
9921
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
9922
10351
|
const timings = [];
|
|
9923
10352
|
const spy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
|
|
9924
10353
|
const text = String(chunk);
|
|
@@ -10017,10 +10446,6 @@ describe("first-tick realtime yield", () => {
|
|
|
10017
10446
|
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10018
10447
|
else
|
|
10019
10448
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
10020
|
-
if (previousInterval === undefined)
|
|
10021
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10022
|
-
else
|
|
10023
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
|
|
10024
10449
|
}
|
|
10025
10450
|
});
|
|
10026
10451
|
});
|
|
@@ -10315,8 +10740,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10315
10740
|
capture.restore();
|
|
10316
10741
|
});
|
|
10317
10742
|
it("logs event-push-surfaces-inactive without silently attributing the first tick", async () => {
|
|
10318
|
-
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10319
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10320
10743
|
const capture = captureFullReconcileDecisions();
|
|
10321
10744
|
try {
|
|
10322
10745
|
const sleep = makeSteppableSleep();
|
|
@@ -10345,10 +10768,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10345
10768
|
}
|
|
10346
10769
|
finally {
|
|
10347
10770
|
capture.restore();
|
|
10348
|
-
if (saved === undefined)
|
|
10349
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10350
|
-
else
|
|
10351
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
10352
10771
|
}
|
|
10353
10772
|
});
|
|
10354
10773
|
it("reports every matching trigger instead of short-circuiting at the first", async () => {
|
|
@@ -10403,9 +10822,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10403
10822
|
});
|
|
10404
10823
|
it("skips a 404 company route in a mixed drain and records a completed full reconcile", async () => {
|
|
10405
10824
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10406
|
-
const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10407
10825
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
10408
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10409
10826
|
const failedLines = [];
|
|
10410
10827
|
const decisions = [];
|
|
10411
10828
|
const timingRecords = [];
|
|
@@ -10505,17 +10922,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10505
10922
|
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10506
10923
|
else
|
|
10507
10924
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
10508
|
-
if (previousInterval === undefined)
|
|
10509
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10510
|
-
else
|
|
10511
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
|
|
10512
10925
|
}
|
|
10513
10926
|
});
|
|
10514
10927
|
it("does not escalate a fully-enumerated over-limit batch to a full reconcile", async () => {
|
|
10515
10928
|
const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10516
|
-
const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10517
10929
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
|
|
10518
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10519
10930
|
const journal = captureWatchLoopJournal();
|
|
10520
10931
|
try {
|
|
10521
10932
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
@@ -10555,17 +10966,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10555
10966
|
delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10556
10967
|
else
|
|
10557
10968
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
|
|
10558
|
-
if (savedInterval === undefined)
|
|
10559
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10560
|
-
else
|
|
10561
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
|
|
10562
10969
|
}
|
|
10563
10970
|
});
|
|
10564
10971
|
it("still escalates an overflowed batch with unknown routes to a full reconcile", async () => {
|
|
10565
10972
|
const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10566
|
-
const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10567
10973
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
|
|
10568
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10569
10974
|
const journal = captureWatchLoopJournal();
|
|
10570
10975
|
try {
|
|
10571
10976
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
@@ -10597,15 +11002,9 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10597
11002
|
delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10598
11003
|
else
|
|
10599
11004
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
|
|
10600
|
-
if (savedInterval === undefined)
|
|
10601
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10602
|
-
else
|
|
10603
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
|
|
10604
11005
|
}
|
|
10605
11006
|
});
|
|
10606
|
-
it("logs scheduled-interval as the sole full-reconcile trigger on the default
|
|
10607
|
-
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10608
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11007
|
+
it("logs scheduled-interval as the sole full-reconcile trigger on the six-hour default", async () => {
|
|
10609
11008
|
const capture = captureFullReconcileDecisions();
|
|
10610
11009
|
try {
|
|
10611
11010
|
const clockState = { now: 0 };
|
|
@@ -10631,11 +11030,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10631
11030
|
sleep.tick();
|
|
10632
11031
|
await flushLoopMicrotasks();
|
|
10633
11032
|
}
|
|
10634
|
-
// A dozen ticks inside the
|
|
11033
|
+
// A dozen ticks inside the interval: never a scheduled full pass.
|
|
10635
11034
|
expect(runPass).not.toHaveBeenCalled();
|
|
10636
11035
|
capture.clear();
|
|
10637
11036
|
runPass.mockClear();
|
|
10638
|
-
clockState.now =
|
|
11037
|
+
clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
|
|
10639
11038
|
sleep.tick();
|
|
10640
11039
|
await flushLoopMicrotasks();
|
|
10641
11040
|
expectFullReconcileDecision(capture.records[0], "full", [
|
|
@@ -10647,10 +11046,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10647
11046
|
}
|
|
10648
11047
|
finally {
|
|
10649
11048
|
capture.restore();
|
|
10650
|
-
if (saved === undefined)
|
|
10651
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10652
|
-
else
|
|
10653
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
10654
11049
|
}
|
|
10655
11050
|
});
|
|
10656
11051
|
it("logs scoped passes with their batch path count and preserves the scoped route", async () => {
|
|
@@ -10671,8 +11066,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10671
11066
|
capture.restore();
|
|
10672
11067
|
});
|
|
10673
11068
|
it("reports interval diagnostics while the configured interval has not elapsed", async () => {
|
|
10674
|
-
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10675
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
|
|
10676
11069
|
const capture = captureFullReconcileDecisions();
|
|
10677
11070
|
try {
|
|
10678
11071
|
const clockState = { now: 0 };
|
|
@@ -10681,6 +11074,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10681
11074
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
10682
11075
|
const loop = runRunnerWithLoop(watchArgv, {
|
|
10683
11076
|
runPass,
|
|
11077
|
+
fullPassIntervalSource: { read: () => 1_000 },
|
|
10684
11078
|
monotonicNow: () => clockState.now,
|
|
10685
11079
|
createWatcher: () => makeBatchWatcherStub(),
|
|
10686
11080
|
sleep: sleep.sleep,
|
|
@@ -10716,10 +11110,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10716
11110
|
}
|
|
10717
11111
|
finally {
|
|
10718
11112
|
capture.restore();
|
|
10719
|
-
if (saved === undefined)
|
|
10720
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10721
|
-
else
|
|
10722
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
10723
11113
|
}
|
|
10724
11114
|
});
|
|
10725
11115
|
it("startup runs one full reconcile, then watcher edits interrupt the pending wait", async () => {
|
|
@@ -11025,8 +11415,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11025
11415
|
await loop;
|
|
11026
11416
|
});
|
|
11027
11417
|
it("drops an unroutable batch and leaves the next unexpired poll idle", async () => {
|
|
11028
|
-
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11029
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
|
|
11030
11418
|
const capture = captureFullReconcileDecisions();
|
|
11031
11419
|
try {
|
|
11032
11420
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
@@ -11052,10 +11440,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11052
11440
|
}
|
|
11053
11441
|
finally {
|
|
11054
11442
|
capture.restore();
|
|
11055
|
-
if (saved === undefined)
|
|
11056
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11057
|
-
else
|
|
11058
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11059
11443
|
}
|
|
11060
11444
|
});
|
|
11061
11445
|
it("personal scoped ticks preserve personal mode for the pull leg", async () => {
|
|
@@ -11214,7 +11598,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11214
11598
|
}
|
|
11215
11599
|
expect(runPass).not.toHaveBeenCalled();
|
|
11216
11600
|
runPass.mockClear();
|
|
11217
|
-
clockState.now =
|
|
11601
|
+
clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
|
|
11218
11602
|
sleep.tick();
|
|
11219
11603
|
await flushLoopMicrotasks();
|
|
11220
11604
|
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
@@ -11222,134 +11606,105 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11222
11606
|
sleep.tick();
|
|
11223
11607
|
await loop;
|
|
11224
11608
|
});
|
|
11225
|
-
it("schedules the full reconcile by elapsed time, not tick count,
|
|
11609
|
+
it("schedules the full reconcile by elapsed time, not tick count, at the flag fallback", async () => {
|
|
11226
11610
|
// Pre-fix the unset default was every tenth tick. Ticks fire on every
|
|
11227
11611
|
// watcher batch, so an active vault ran a ~10-minute full pass every
|
|
11228
11612
|
// 4-8 minutes — nearly continuous, and the runner's dominant CPU cost
|
|
11229
11613
|
// once per-pass hashing was fixed.
|
|
11230
|
-
const
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
|
|
11244
|
-
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11252
|
-
|
|
11253
|
-
// two full passes here.
|
|
11254
|
-
for (let tick = 0; tick < 20; tick++) {
|
|
11255
|
-
clockState.now += 177_000;
|
|
11256
|
-
sleep.tick();
|
|
11257
|
-
await flushLoopMicrotasks();
|
|
11258
|
-
}
|
|
11259
|
-
expect(runPass).not.toHaveBeenCalled();
|
|
11260
|
-
runPass.mockClear();
|
|
11261
|
-
clockState.now = DEFAULT_FULL_RECONCILE_MS;
|
|
11614
|
+
const clockState = { now: 0 };
|
|
11615
|
+
const watcher = makeBatchWatcherStub();
|
|
11616
|
+
const sleep = makeSteppableSleep();
|
|
11617
|
+
let triggerShutdown = () => { };
|
|
11618
|
+
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
11619
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11620
|
+
runPass,
|
|
11621
|
+
clock: new FakeClock(),
|
|
11622
|
+
monotonicNow: () => clockState.now,
|
|
11623
|
+
createWatcher: () => watcher,
|
|
11624
|
+
sleep: sleep.sleep,
|
|
11625
|
+
onShutdownSignal: (handler) => {
|
|
11626
|
+
triggerShutdown = handler;
|
|
11627
|
+
return () => { };
|
|
11628
|
+
},
|
|
11629
|
+
});
|
|
11630
|
+
await flushLoopMicrotasks();
|
|
11631
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11632
|
+
runPass.mockClear();
|
|
11633
|
+
// Twenty ticks in fifty-nine minutes: the old cadence would have run
|
|
11634
|
+
// two full passes here.
|
|
11635
|
+
for (let tick = 0; tick < 20; tick++) {
|
|
11636
|
+
clockState.now += 177_000;
|
|
11262
11637
|
sleep.tick();
|
|
11263
11638
|
await flushLoopMicrotasks();
|
|
11264
|
-
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11265
|
-
triggerShutdown();
|
|
11266
|
-
await loop;
|
|
11267
|
-
}
|
|
11268
|
-
finally {
|
|
11269
|
-
if (saved === undefined)
|
|
11270
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11271
|
-
else
|
|
11272
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11273
11639
|
}
|
|
11640
|
+
expect(runPass).not.toHaveBeenCalled();
|
|
11641
|
+
runPass.mockClear();
|
|
11642
|
+
clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
|
|
11643
|
+
sleep.tick();
|
|
11644
|
+
await flushLoopMicrotasks();
|
|
11645
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11646
|
+
triggerShutdown();
|
|
11647
|
+
await loop;
|
|
11274
11648
|
});
|
|
11275
|
-
it("uses the
|
|
11276
|
-
const
|
|
11277
|
-
|
|
11278
|
-
|
|
11279
|
-
|
|
11280
|
-
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
|
|
11284
|
-
|
|
11285
|
-
|
|
11286
|
-
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
|
|
11300
|
-
|
|
11301
|
-
|
|
11302
|
-
|
|
11303
|
-
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
triggerShutdown();
|
|
11309
|
-
await loop;
|
|
11310
|
-
}
|
|
11311
|
-
finally {
|
|
11312
|
-
if (saved === undefined)
|
|
11313
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11314
|
-
else
|
|
11315
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11316
|
-
}
|
|
11649
|
+
it("uses the hq-flag interval source instead of the tick count", async () => {
|
|
11650
|
+
const clockState = { now: 0 };
|
|
11651
|
+
const watcher = makeBatchWatcherStub();
|
|
11652
|
+
const sleep = makeSteppableSleep();
|
|
11653
|
+
let triggerShutdown = () => { };
|
|
11654
|
+
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
11655
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11656
|
+
runPass,
|
|
11657
|
+
fullPassIntervalSource: { read: () => 1_000 },
|
|
11658
|
+
clock: new FakeClock(),
|
|
11659
|
+
monotonicNow: () => clockState.now,
|
|
11660
|
+
createWatcher: () => watcher,
|
|
11661
|
+
sleep: sleep.sleep,
|
|
11662
|
+
onShutdownSignal: (handler) => {
|
|
11663
|
+
triggerShutdown = handler;
|
|
11664
|
+
return () => { };
|
|
11665
|
+
},
|
|
11666
|
+
});
|
|
11667
|
+
await flushLoopMicrotasks();
|
|
11668
|
+
// Startup always forces the first full reconcile, and starts the interval.
|
|
11669
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11670
|
+
runPass.mockClear();
|
|
11671
|
+
clockState.now = 999;
|
|
11672
|
+
sleep.tick();
|
|
11673
|
+
await flushLoopMicrotasks();
|
|
11674
|
+
expect(runPass).not.toHaveBeenCalled();
|
|
11675
|
+
runPass.mockClear();
|
|
11676
|
+
clockState.now = 1_000;
|
|
11677
|
+
sleep.tick();
|
|
11678
|
+
await flushLoopMicrotasks();
|
|
11679
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11680
|
+
triggerShutdown();
|
|
11681
|
+
await loop;
|
|
11317
11682
|
});
|
|
11318
11683
|
it("does not let a full-reconcile interval suppress event-push activation", async () => {
|
|
11319
|
-
const
|
|
11320
|
-
|
|
11321
|
-
|
|
11322
|
-
|
|
11323
|
-
|
|
11324
|
-
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11344
|
-
triggerShutdown();
|
|
11345
|
-
await loop;
|
|
11346
|
-
}
|
|
11347
|
-
finally {
|
|
11348
|
-
if (saved === undefined)
|
|
11349
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11350
|
-
else
|
|
11351
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11352
|
-
}
|
|
11684
|
+
const watcher = makeBatchWatcherStub();
|
|
11685
|
+
const sleep = makeSteppableSleep();
|
|
11686
|
+
let triggerShutdown = () => { };
|
|
11687
|
+
// A numeric partial result does not activate event-push surfaces, so the
|
|
11688
|
+
// next tick must force another full pass even though three hours have not elapsed.
|
|
11689
|
+
const runPass = vi.fn().mockResolvedValue(PARTIAL_SYNC_EXIT);
|
|
11690
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11691
|
+
runPass,
|
|
11692
|
+
clock: new FakeClock(),
|
|
11693
|
+
monotonicNow: () => 0,
|
|
11694
|
+
createWatcher: () => watcher,
|
|
11695
|
+
sleep: sleep.sleep,
|
|
11696
|
+
onShutdownSignal: (handler) => {
|
|
11697
|
+
triggerShutdown = handler;
|
|
11698
|
+
return () => { };
|
|
11699
|
+
},
|
|
11700
|
+
});
|
|
11701
|
+
await flushLoopMicrotasks();
|
|
11702
|
+
runPass.mockClear();
|
|
11703
|
+
sleep.tick();
|
|
11704
|
+
await flushLoopMicrotasks();
|
|
11705
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11706
|
+
triggerShutdown();
|
|
11707
|
+
await loop;
|
|
11353
11708
|
});
|
|
11354
11709
|
it("overflow with known dropped-route hints fans out per touched route instead of a full reconcile", async () => {
|
|
11355
11710
|
const capture = captureFullReconcileDecisions();
|
|
@@ -11484,50 +11839,40 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11484
11839
|
await loop;
|
|
11485
11840
|
});
|
|
11486
11841
|
it("a batch above the shipped 10,000-path default stays on chunked targeted passes before the interval", async () => {
|
|
11487
|
-
const
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
|
|
11522
|
-
triggerShutdown();
|
|
11523
|
-
await loop;
|
|
11524
|
-
}
|
|
11525
|
-
finally {
|
|
11526
|
-
if (saved === undefined)
|
|
11527
|
-
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11528
|
-
else
|
|
11529
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11530
|
-
}
|
|
11842
|
+
const watcher = makeBatchWatcherStub();
|
|
11843
|
+
const sleep = makeSteppableSleep();
|
|
11844
|
+
let triggerShutdown = () => { };
|
|
11845
|
+
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
11846
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11847
|
+
runPass,
|
|
11848
|
+
clock: new FakeClock(),
|
|
11849
|
+
monotonicNow: () => 0,
|
|
11850
|
+
createWatcher: () => watcher,
|
|
11851
|
+
sleep: sleep.sleep,
|
|
11852
|
+
onShutdownSignal: (handler) => {
|
|
11853
|
+
triggerShutdown = handler;
|
|
11854
|
+
return () => { };
|
|
11855
|
+
},
|
|
11856
|
+
});
|
|
11857
|
+
await flushLoopMicrotasks();
|
|
11858
|
+
runPass.mockClear();
|
|
11859
|
+
watcher.emit("companies/indigo/a.md", {
|
|
11860
|
+
paths: new Map(Array.from({ length: 10_001 }, (_, index) => [
|
|
11861
|
+
`/tmp/hq/companies/indigo/${index}.md`,
|
|
11862
|
+
`companies/indigo/${index}.md`,
|
|
11863
|
+
])),
|
|
11864
|
+
});
|
|
11865
|
+
sleep.tick();
|
|
11866
|
+
await flushLoopMicrotasks(40);
|
|
11867
|
+
const calls = runPass.mock.calls.map((call) => call[0]);
|
|
11868
|
+
expect(calls).not.toContainEqual(fullArgv);
|
|
11869
|
+
const pushScopeCounts = calls
|
|
11870
|
+
.filter((argv) => argv.includes("push"))
|
|
11871
|
+
.map((argv) => scopePathsFromArgv(argv).length);
|
|
11872
|
+
expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
|
|
11873
|
+
expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
|
|
11874
|
+
triggerShutdown();
|
|
11875
|
+
await loop;
|
|
11531
11876
|
});
|
|
11532
11877
|
it("a throwing targeted pass falls back to one full reconcile instead of dropping the change", async () => {
|
|
11533
11878
|
const capture = captureFullReconcileDecisions();
|