@indigoai-us/hq-cloud 6.16.84-alpha.0 → 6.16.86-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-company.js +2 -2
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.d.ts +21 -0
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +68 -27
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +0 -2
- 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 +384 -158
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +7 -14
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +22 -72
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync-scope.test.js +34 -0
- package/dist/cli/sync-scope.test.js.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -2
- package/dist/cli/sync.js.map +1 -1
- package/dist/prefix-coalesce.d.ts +37 -30
- package/dist/prefix-coalesce.d.ts.map +1 -1
- package/dist/prefix-coalesce.js +104 -16
- package/dist/prefix-coalesce.js.map +1 -1
- package/dist/prefix-coalesce.test.js +34 -3
- package/dist/prefix-coalesce.test.js.map +1 -1
- package/dist/remote-pull.d.ts.map +1 -1
- package/dist/remote-pull.js +15 -8
- package/dist/remote-pull.js.map +1 -1
- package/dist/remote-pull.test.js +44 -4
- package/dist/remote-pull.test.js.map +1 -1
- package/dist/scope-shrink.d.ts.map +1 -1
- package/dist/scope-shrink.js +7 -1
- package/dist/scope-shrink.js.map +1 -1
- package/dist/sync/event-sync.d.ts +3 -1
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +2 -4
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/event-sync.test.js +2 -2
- package/dist/sync/event-sync.test.js.map +1 -1
- 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/pull-scope.d.ts.map +1 -1
- package/dist/sync/pull-scope.js +5 -5
- package/dist/sync/pull-scope.js.map +1 -1
- package/dist/sync/push-receiver.d.ts +17 -1
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +89 -16
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +241 -7
- package/dist/sync/push-receiver.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
- package/dist/sync/full-pass-interval.d.ts +0 -25
- package/dist/sync/full-pass-interval.d.ts.map +0 -1
- package/dist/sync/full-pass-interval.js +0 -53
- package/dist/sync/full-pass-interval.js.map +0 -1
- package/dist/sync/full-pass-interval.test.d.ts +0 -2
- package/dist/sync/full-pass-interval.test.d.ts.map +0 -1
- package/dist/sync/full-pass-interval.test.js +0 -21
- package/dist/sync/full-pass-interval.test.js.map +0 -1
|
@@ -20,8 +20,7 @@ import { ObjectLockChecksumRequiredError, PresignObjectIO, S3SdkObjectIO, } from
|
|
|
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, 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";
|
|
23
|
+
import { adaptivePollMs, advanceMonotonicDeadline, DEFAULT_EVENT_BATCH_LIMIT, DEFAULT_FAST_LANE_MAX_BYTES, DEFAULT_FAST_LANE_MAX_FILE_BYTES, DEFAULT_FAST_LANE_MAX_FILES, DEFAULT_FULL_RECONCILE_MS, EVENT_BATCH_LIMIT_ENV, FAST_LANE_MAX_BYTES_ENV, FAST_LANE_MAX_FILES_ENV, FULL_RECONCILE_MS_ENV, isFastLocalBatch, isFastReceiverBatch, partitionLocalBatch, journalEntriesForWatcherDelete, resolveEventBatchLimit, resolveFullReconcileMs, 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";
|
|
25
24
|
import { FullPassCapController, resetFullPassCapLogForTest, } from "../sync/full-pass-caps.js";
|
|
26
25
|
import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, readJournalScoped, writeJournal, } from "../journal.js";
|
|
27
26
|
import { AreaLedger } from "../sync/area-ledger.js";
|
|
@@ -33,7 +32,7 @@ import { lockPathFor, OPERATION_LOCKED_EXIT } from "../operation-lock.js";
|
|
|
33
32
|
import { TRANSIENT_NETWORK_EXIT } from "../lib/net-errors.js";
|
|
34
33
|
import { getStateStoreSnapshotRecoveryCountForTest, resetStateStoreSnapshotRecoveryCountForTest, StateStoreLockError, } from "../sync/state-store.js";
|
|
35
34
|
import { PARTIAL_SYNC_EXIT, UNRESOLVED_COMPANY_EXIT, } from "../lib/exit-codes.js";
|
|
36
|
-
import { isCoveredByAny } from "../prefix-coalesce.js";
|
|
35
|
+
import { isCoveredByAny, toScopePrefixEntries } from "../prefix-coalesce.js";
|
|
37
36
|
import { VaultAuthError, VaultNotFoundError } from "../vault-client.js";
|
|
38
37
|
import { buildRoutePullArgv } from "./sync-runner-watch-routes.js";
|
|
39
38
|
import { CognitoAuthError, CognitoRefreshError } from "../cognito-auth.js";
|
|
@@ -3728,8 +3727,8 @@ describe("--direction", () => {
|
|
|
3728
3727
|
isDefault: false,
|
|
3729
3728
|
}),
|
|
3730
3729
|
listMyExplicitGrants: async () => [
|
|
3731
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
3732
|
-
{ companyUid: "cmp_a", path: "policies
|
|
3730
|
+
{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" },
|
|
3731
|
+
{ companyUid: "cmp_a", path: "policies/*", permission: "read", source: "group" },
|
|
3733
3732
|
],
|
|
3734
3733
|
};
|
|
3735
3734
|
const deps = makeDeps({
|
|
@@ -3754,7 +3753,7 @@ describe("--direction", () => {
|
|
|
3754
3753
|
isDefault: false,
|
|
3755
3754
|
}),
|
|
3756
3755
|
listMyExplicitGrants: async () => [
|
|
3757
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
3756
|
+
{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" },
|
|
3758
3757
|
],
|
|
3759
3758
|
};
|
|
3760
3759
|
const deps = makeDeps({
|
|
@@ -3790,7 +3789,7 @@ describe("--direction", () => {
|
|
|
3790
3789
|
isDefault: false,
|
|
3791
3790
|
}),
|
|
3792
3791
|
listMyExplicitGrants: async () => [
|
|
3793
|
-
{ companyUid: "cmp_a", path: "policies
|
|
3792
|
+
{ companyUid: "cmp_a", path: "policies/*", permission: "read", source: "person" },
|
|
3794
3793
|
],
|
|
3795
3794
|
};
|
|
3796
3795
|
const deps = makeDeps({
|
|
@@ -4710,13 +4709,28 @@ describe("advanceMonotonicDeadline", () => {
|
|
|
4710
4709
|
});
|
|
4711
4710
|
});
|
|
4712
4711
|
});
|
|
4713
|
-
describe("watch-loop reconcile
|
|
4712
|
+
describe("watch-loop reconcile environment resolvers", () => {
|
|
4714
4713
|
it("uses the shipped 10,000 event-batch default while allowing smaller and larger overrides", () => {
|
|
4715
4714
|
expect(DEFAULT_EVENT_BATCH_LIMIT).toBe(10_000);
|
|
4716
4715
|
expect(resolveEventBatchLimit({})).toBe(10_000);
|
|
4717
4716
|
expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
|
|
4718
4717
|
expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
|
|
4719
4718
|
});
|
|
4719
|
+
it("defaults the full-reconcile cadence to one elapsed hour for an unset or invalid interval", () => {
|
|
4720
|
+
// The legacy default was "every tenth tick" with no elapsed-time floor.
|
|
4721
|
+
// Ticks fire on every watcher batch, not just polls, so on an active
|
|
4722
|
+
// vault that meant a full pass every 4-8 minutes — and each pass on a
|
|
4723
|
+
// real install lasts ~10 minutes. Full reconcile is the correctness
|
|
4724
|
+
// backstop behind event-push, so elapsed time is the right clock.
|
|
4725
|
+
expect(DEFAULT_FULL_RECONCILE_MS).toBe(3_600_000);
|
|
4726
|
+
expect(resolveFullReconcileMs({})).toBe(DEFAULT_FULL_RECONCILE_MS);
|
|
4727
|
+
for (const raw of ["", "0", "0.5", "-1", "NaN", "not-a-number", "Infinity"]) {
|
|
4728
|
+
expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: raw })).toBe(DEFAULT_FULL_RECONCILE_MS);
|
|
4729
|
+
}
|
|
4730
|
+
});
|
|
4731
|
+
it("accepts a positive millisecond full-reconcile interval", () => {
|
|
4732
|
+
expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: "10800000" })).toBe(10_800_000);
|
|
4733
|
+
});
|
|
4720
4734
|
});
|
|
4721
4735
|
describe("runRunnerWithLoop — adaptive poll interval (no --poll-remote-ms)", () => {
|
|
4722
4736
|
// Capture the ms handed to sleep on the FIRST poll, then hang so the loop
|
|
@@ -4932,8 +4946,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
4932
4946
|
it("parallel coordinator activates every event surface after a partial completed full reconcile", async () => {
|
|
4933
4947
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
4934
4948
|
const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
|
|
4949
|
+
const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
4935
4950
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
4936
4951
|
process.env.HQ_SYNC_EVENT_SYNC = "1";
|
|
4952
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
|
|
4937
4953
|
const watcher = makeWatcherStub();
|
|
4938
4954
|
const receiver = {
|
|
4939
4955
|
connected: false,
|
|
@@ -4993,13 +5009,19 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
4993
5009
|
delete process.env.HQ_SYNC_EVENT_SYNC;
|
|
4994
5010
|
else
|
|
4995
5011
|
process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
|
|
5012
|
+
if (previousFullReconcileMs === undefined)
|
|
5013
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
5014
|
+
else
|
|
5015
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
|
|
4996
5016
|
}
|
|
4997
5017
|
});
|
|
4998
5018
|
it("parallel coordinator activates event surfaces and advances cadence after a numeric-zero full reconcile", async () => {
|
|
4999
5019
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5000
5020
|
const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
|
|
5021
|
+
const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
5001
5022
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
5002
5023
|
process.env.HQ_SYNC_EVENT_SYNC = "1";
|
|
5024
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
|
|
5003
5025
|
const watcher = makeWatcherStub();
|
|
5004
5026
|
const receiver = {
|
|
5005
5027
|
connected: false,
|
|
@@ -5059,11 +5081,17 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5059
5081
|
delete process.env.HQ_SYNC_EVENT_SYNC;
|
|
5060
5082
|
else
|
|
5061
5083
|
process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
|
|
5084
|
+
if (previousFullReconcileMs === undefined)
|
|
5085
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
5086
|
+
else
|
|
5087
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
|
|
5062
5088
|
}
|
|
5063
5089
|
});
|
|
5064
5090
|
it("backs off failed parallel full-reconcile completions before another chore is admitted", async () => {
|
|
5065
5091
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5092
|
+
const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
5066
5093
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
5094
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1";
|
|
5067
5095
|
const runPass = vi.fn().mockResolvedValue(1);
|
|
5068
5096
|
const delays = [];
|
|
5069
5097
|
const waiters = [];
|
|
@@ -5080,7 +5108,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5080
5108
|
clock: new FakeClock(),
|
|
5081
5109
|
monotonicNow: () => now,
|
|
5082
5110
|
sleep,
|
|
5083
|
-
fullPassIntervalSource: { read: () => 1 },
|
|
5084
5111
|
onShutdownSignal: (handler) => {
|
|
5085
5112
|
shutdown = handler;
|
|
5086
5113
|
return () => { };
|
|
@@ -5108,6 +5135,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5108
5135
|
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5109
5136
|
else
|
|
5110
5137
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
5138
|
+
if (previousFullReconcileMs === undefined)
|
|
5139
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
5140
|
+
else
|
|
5141
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
|
|
5111
5142
|
}
|
|
5112
5143
|
});
|
|
5113
5144
|
it("parallel coordinator keeps event surfaces off for an auth-required full reconcile", async () => {
|
|
@@ -5240,7 +5271,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5240
5271
|
sleep.tick();
|
|
5241
5272
|
await flushLoopMicrotasks();
|
|
5242
5273
|
}
|
|
5243
|
-
clockState.now =
|
|
5274
|
+
clockState.now = DEFAULT_FULL_RECONCILE_MS;
|
|
5244
5275
|
sleep.tick();
|
|
5245
5276
|
await flushLoopMicrotasks();
|
|
5246
5277
|
// Tick 1 and the first tick after an hour has elapsed are full
|
|
@@ -5308,7 +5339,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5308
5339
|
}
|
|
5309
5340
|
expect(runPass).toHaveBeenCalledTimes(1);
|
|
5310
5341
|
// The hourly cadence, not a tick count, schedules the next full pass.
|
|
5311
|
-
clockState.now =
|
|
5342
|
+
clockState.now = DEFAULT_FULL_RECONCILE_MS;
|
|
5312
5343
|
sleep.tick();
|
|
5313
5344
|
await flushLoopMicrotasks(30);
|
|
5314
5345
|
expect(runPass).toHaveBeenCalledTimes(2);
|
|
@@ -6194,6 +6225,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6194
6225
|
}],
|
|
6195
6226
|
signal: new AbortController().signal,
|
|
6196
6227
|
});
|
|
6228
|
+
const firstReplacementFailure = expect(firstReplacement).rejects.toThrow("targeted pull failed");
|
|
6197
6229
|
await flushLoopMicrotasks(30); // queues the warm-up pull behind held work
|
|
6198
6230
|
const secondReplacement = receiverSync({
|
|
6199
6231
|
events: [{
|
|
@@ -6208,18 +6240,32 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6208
6240
|
}],
|
|
6209
6241
|
signal: new AbortController().signal,
|
|
6210
6242
|
});
|
|
6211
|
-
|
|
6243
|
+
const secondReplacementFailure = expect(secondReplacement).rejects.toThrow("targeted pull failed");
|
|
6244
|
+
await firstReplacementFailure;
|
|
6212
6245
|
await flushLoopMicrotasks(30);
|
|
6213
|
-
//
|
|
6214
|
-
//
|
|
6215
|
-
//
|
|
6246
|
+
// The queued first replacement is superseded, and the second may be
|
|
6247
|
+
// refused by the warm-up pull. Both stay retryable so SQS can redeliver
|
|
6248
|
+
// after the durable replacement instead of acknowledging a lost pull.
|
|
6216
6249
|
expect(runPass.mock.calls.filter(([argv]) => argv.includes("warmup-superseded.md"))).toHaveLength(0);
|
|
6217
6250
|
expect(settled).toBeUndefined();
|
|
6218
6251
|
await Promise.resolve();
|
|
6219
6252
|
expect(settled).toBeUndefined();
|
|
6220
6253
|
releaseHeld();
|
|
6221
6254
|
await heldReceiverWork;
|
|
6222
|
-
await
|
|
6255
|
+
await secondReplacementFailure;
|
|
6256
|
+
await receiverSync({
|
|
6257
|
+
events: [{
|
|
6258
|
+
kind: "upsert",
|
|
6259
|
+
relativePath: "companies/indigo/warmup-superseded.md",
|
|
6260
|
+
contentHash: "sha256:remote",
|
|
6261
|
+
mtime: "2026-08-28T01:22:33.000Z",
|
|
6262
|
+
originDeviceId: "peer-device",
|
|
6263
|
+
originTenantId: "tenant-indigo",
|
|
6264
|
+
sequenceNumber: 4,
|
|
6265
|
+
eventTimestamp: "2026-08-28T01:22:33.000Z",
|
|
6266
|
+
}],
|
|
6267
|
+
signal: new AbortController().signal,
|
|
6268
|
+
});
|
|
6223
6269
|
}
|
|
6224
6270
|
finally {
|
|
6225
6271
|
releaseHeld();
|
|
@@ -6231,7 +6277,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6231
6277
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6232
6278
|
}
|
|
6233
6279
|
});
|
|
6234
|
-
it("
|
|
6280
|
+
it("keeps all-refused receiver work retryable until its replacement pull is durable", async () => {
|
|
6235
6281
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6236
6282
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6237
6283
|
const watcher = makeBatchWatcherStub();
|
|
@@ -6258,14 +6304,14 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6258
6304
|
},
|
|
6259
6305
|
});
|
|
6260
6306
|
const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
|
6261
|
-
const event = (relativePath) => ({
|
|
6307
|
+
const event = (relativePath, sequenceNumber = 1) => ({
|
|
6262
6308
|
kind: "upsert",
|
|
6263
6309
|
relativePath,
|
|
6264
6310
|
contentHash: "sha256:remote",
|
|
6265
6311
|
mtime: "2026-08-28T01:22:30.000Z",
|
|
6266
6312
|
originDeviceId: "peer-device",
|
|
6267
6313
|
originTenantId: "tenant-indigo",
|
|
6268
|
-
sequenceNumber
|
|
6314
|
+
sequenceNumber,
|
|
6269
6315
|
eventTimestamp: "2026-08-28T01:22:30.000Z",
|
|
6270
6316
|
});
|
|
6271
6317
|
try {
|
|
@@ -6282,10 +6328,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6282
6328
|
});
|
|
6283
6329
|
await flushLoopMicrotasks();
|
|
6284
6330
|
const replacement = receiverSync({
|
|
6285
|
-
events: [event("companies/indigo/superseded.md")],
|
|
6331
|
+
events: [event("companies/indigo/superseded.md", 2)],
|
|
6286
6332
|
signal: new AbortController().signal,
|
|
6287
6333
|
});
|
|
6288
|
-
await expect(superseded).
|
|
6334
|
+
await expect(superseded).rejects.toThrow("targeted pull failed");
|
|
6289
6335
|
expect(runPass.mock.calls.filter(([argv]) => argv.includes("superseded.md"))).toHaveLength(0);
|
|
6290
6336
|
expect(stderr.mock.calls.map(([chunk]) => String(chunk)).join("")).toContain('"event":"sync.realtime.timing","schemaVersion":3,"source":"receiver","direction":"pull","outcome":"refused"');
|
|
6291
6337
|
releaseHeld();
|
|
@@ -6303,6 +6349,79 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6303
6349
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6304
6350
|
}
|
|
6305
6351
|
});
|
|
6352
|
+
it("keeps mixed durable and refused receiver paths retryable until the replacement completes", async () => {
|
|
6353
|
+
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6354
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6355
|
+
const watcher = makeBatchWatcherStub();
|
|
6356
|
+
let receiverSync;
|
|
6357
|
+
let shutdown = () => { };
|
|
6358
|
+
let releaseHeld = () => { };
|
|
6359
|
+
const held = new Promise((resolve) => { releaseHeld = resolve; });
|
|
6360
|
+
const runPass = vi.fn(async (argv) => {
|
|
6361
|
+
if (argv.includes("held.md"))
|
|
6362
|
+
await held;
|
|
6363
|
+
return completedPassOutcome();
|
|
6364
|
+
});
|
|
6365
|
+
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
|
|
6366
|
+
runPass,
|
|
6367
|
+
createWatcher: () => watcher,
|
|
6368
|
+
createReceiver: ({ syncBatchFn }) => {
|
|
6369
|
+
receiverSync = syncBatchFn;
|
|
6370
|
+
return { connected: true, start: async () => { }, dispose: async () => { } };
|
|
6371
|
+
},
|
|
6372
|
+
sleep: () => new Promise(() => { }),
|
|
6373
|
+
onShutdownSignal: (handler) => {
|
|
6374
|
+
shutdown = handler;
|
|
6375
|
+
return () => { };
|
|
6376
|
+
},
|
|
6377
|
+
});
|
|
6378
|
+
const event = (relativePath, sequenceNumber) => ({
|
|
6379
|
+
kind: "upsert",
|
|
6380
|
+
relativePath,
|
|
6381
|
+
contentHash: "sha256:remote",
|
|
6382
|
+
mtime: "2026-08-28T01:22:30.000Z",
|
|
6383
|
+
originDeviceId: "peer-device",
|
|
6384
|
+
originTenantId: "tenant-indigo",
|
|
6385
|
+
sequenceNumber,
|
|
6386
|
+
eventTimestamp: "2026-08-28T01:22:30.000Z",
|
|
6387
|
+
});
|
|
6388
|
+
try {
|
|
6389
|
+
await flushLoopMicrotasks(30);
|
|
6390
|
+
runPass.mockClear();
|
|
6391
|
+
const blocking = receiverSync({
|
|
6392
|
+
events: [event("companies/indigo/held.md", 1)],
|
|
6393
|
+
signal: new AbortController().signal,
|
|
6394
|
+
});
|
|
6395
|
+
await flushLoopMicrotasks();
|
|
6396
|
+
const mixed = receiverSync({
|
|
6397
|
+
events: [
|
|
6398
|
+
event("companies/indigo/durable.md", 1),
|
|
6399
|
+
event("companies/indigo/shared.md", 2),
|
|
6400
|
+
],
|
|
6401
|
+
signal: new AbortController().signal,
|
|
6402
|
+
});
|
|
6403
|
+
const mixedFailure = expect(mixed).rejects.toThrow("targeted pull failed");
|
|
6404
|
+
await flushLoopMicrotasks();
|
|
6405
|
+
const replacement = receiverSync({
|
|
6406
|
+
events: [event("companies/indigo/shared.md", 3)],
|
|
6407
|
+
signal: new AbortController().signal,
|
|
6408
|
+
});
|
|
6409
|
+
releaseHeld();
|
|
6410
|
+
await blocking;
|
|
6411
|
+
await mixedFailure;
|
|
6412
|
+
await replacement;
|
|
6413
|
+
expect(runPass.mock.calls.filter(([argv]) => argv.includes("durable.md"))).toHaveLength(1);
|
|
6414
|
+
}
|
|
6415
|
+
finally {
|
|
6416
|
+
releaseHeld();
|
|
6417
|
+
shutdown();
|
|
6418
|
+
await loop;
|
|
6419
|
+
if (previousCoordinator === undefined)
|
|
6420
|
+
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6421
|
+
else
|
|
6422
|
+
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6423
|
+
}
|
|
6424
|
+
});
|
|
6306
6425
|
it("measures a queued realtime pass at the operation gate and marks append lock only after admission", async () => {
|
|
6307
6426
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6308
6427
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
@@ -9277,7 +9396,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
9277
9396
|
runPass,
|
|
9278
9397
|
clock: new FakeClock(),
|
|
9279
9398
|
createWatcher: () => watcher,
|
|
9280
|
-
monotonicNow: () => (monotonic +=
|
|
9399
|
+
monotonicNow: () => (monotonic += DEFAULT_FULL_RECONCILE_MS),
|
|
9281
9400
|
sleep: sleep.sleep,
|
|
9282
9401
|
onShutdownSignal: (handler) => {
|
|
9283
9402
|
triggerShutdown = handler;
|
|
@@ -10259,7 +10378,9 @@ describe("CooperativePassScheduler", () => {
|
|
|
10259
10378
|
describe("first-tick realtime yield", () => {
|
|
10260
10379
|
it("commits a watcher push at the first chore checkpoint without a wall-clock wait", async () => {
|
|
10261
10380
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10381
|
+
const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10262
10382
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
10383
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10263
10384
|
const timings = [];
|
|
10264
10385
|
const spy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
|
|
10265
10386
|
const text = String(chunk);
|
|
@@ -10358,6 +10479,10 @@ describe("first-tick realtime yield", () => {
|
|
|
10358
10479
|
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10359
10480
|
else
|
|
10360
10481
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
10482
|
+
if (previousInterval === undefined)
|
|
10483
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10484
|
+
else
|
|
10485
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
|
|
10361
10486
|
}
|
|
10362
10487
|
});
|
|
10363
10488
|
});
|
|
@@ -10652,6 +10777,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10652
10777
|
capture.restore();
|
|
10653
10778
|
});
|
|
10654
10779
|
it("logs event-push-surfaces-inactive without silently attributing the first tick", async () => {
|
|
10780
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10781
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10655
10782
|
const capture = captureFullReconcileDecisions();
|
|
10656
10783
|
try {
|
|
10657
10784
|
const sleep = makeSteppableSleep();
|
|
@@ -10680,6 +10807,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10680
10807
|
}
|
|
10681
10808
|
finally {
|
|
10682
10809
|
capture.restore();
|
|
10810
|
+
if (saved === undefined)
|
|
10811
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10812
|
+
else
|
|
10813
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
10683
10814
|
}
|
|
10684
10815
|
});
|
|
10685
10816
|
it("reports every matching trigger instead of short-circuiting at the first", async () => {
|
|
@@ -10734,7 +10865,9 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10734
10865
|
});
|
|
10735
10866
|
it("skips a 404 company route in a mixed drain and records a completed full reconcile", async () => {
|
|
10736
10867
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10868
|
+
const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10737
10869
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
10870
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10738
10871
|
const failedLines = [];
|
|
10739
10872
|
const decisions = [];
|
|
10740
10873
|
const timingRecords = [];
|
|
@@ -10834,11 +10967,17 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10834
10967
|
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
10835
10968
|
else
|
|
10836
10969
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
10970
|
+
if (previousInterval === undefined)
|
|
10971
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10972
|
+
else
|
|
10973
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
|
|
10837
10974
|
}
|
|
10838
10975
|
});
|
|
10839
10976
|
it("does not escalate a fully-enumerated over-limit batch to a full reconcile", async () => {
|
|
10840
10977
|
const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10978
|
+
const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10841
10979
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
|
|
10980
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10842
10981
|
const journal = captureWatchLoopJournal();
|
|
10843
10982
|
try {
|
|
10844
10983
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
@@ -10878,11 +11017,17 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10878
11017
|
delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10879
11018
|
else
|
|
10880
11019
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
|
|
11020
|
+
if (savedInterval === undefined)
|
|
11021
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11022
|
+
else
|
|
11023
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
|
|
10881
11024
|
}
|
|
10882
11025
|
});
|
|
10883
11026
|
it("still escalates an overflowed batch with unknown routes to a full reconcile", async () => {
|
|
10884
11027
|
const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
11028
|
+
const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10885
11029
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
|
|
11030
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
10886
11031
|
const journal = captureWatchLoopJournal();
|
|
10887
11032
|
try {
|
|
10888
11033
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
@@ -10914,9 +11059,15 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10914
11059
|
delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
|
|
10915
11060
|
else
|
|
10916
11061
|
process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
|
|
11062
|
+
if (savedInterval === undefined)
|
|
11063
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11064
|
+
else
|
|
11065
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
|
|
10917
11066
|
}
|
|
10918
11067
|
});
|
|
10919
|
-
it("logs scheduled-interval as the sole full-reconcile trigger on the
|
|
11068
|
+
it("logs scheduled-interval as the sole full-reconcile trigger on the default hourly cadence", async () => {
|
|
11069
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11070
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
10920
11071
|
const capture = captureFullReconcileDecisions();
|
|
10921
11072
|
try {
|
|
10922
11073
|
const clockState = { now: 0 };
|
|
@@ -10942,11 +11093,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10942
11093
|
sleep.tick();
|
|
10943
11094
|
await flushLoopMicrotasks();
|
|
10944
11095
|
}
|
|
10945
|
-
// A dozen ticks inside the
|
|
11096
|
+
// A dozen ticks inside the hour: never a scheduled full pass.
|
|
10946
11097
|
expect(runPass).not.toHaveBeenCalled();
|
|
10947
11098
|
capture.clear();
|
|
10948
11099
|
runPass.mockClear();
|
|
10949
|
-
clockState.now =
|
|
11100
|
+
clockState.now = DEFAULT_FULL_RECONCILE_MS;
|
|
10950
11101
|
sleep.tick();
|
|
10951
11102
|
await flushLoopMicrotasks();
|
|
10952
11103
|
expectFullReconcileDecision(capture.records[0], "full", [
|
|
@@ -10958,6 +11109,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10958
11109
|
}
|
|
10959
11110
|
finally {
|
|
10960
11111
|
capture.restore();
|
|
11112
|
+
if (saved === undefined)
|
|
11113
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11114
|
+
else
|
|
11115
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
10961
11116
|
}
|
|
10962
11117
|
});
|
|
10963
11118
|
it("logs scoped passes with their batch path count and preserves the scoped route", async () => {
|
|
@@ -10978,6 +11133,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10978
11133
|
capture.restore();
|
|
10979
11134
|
});
|
|
10980
11135
|
it("reports interval diagnostics while the configured interval has not elapsed", async () => {
|
|
11136
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11137
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
|
|
10981
11138
|
const capture = captureFullReconcileDecisions();
|
|
10982
11139
|
try {
|
|
10983
11140
|
const clockState = { now: 0 };
|
|
@@ -10986,7 +11143,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
10986
11143
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
10987
11144
|
const loop = runRunnerWithLoop(watchArgv, {
|
|
10988
11145
|
runPass,
|
|
10989
|
-
fullPassIntervalSource: { read: () => 1_000 },
|
|
10990
11146
|
monotonicNow: () => clockState.now,
|
|
10991
11147
|
createWatcher: () => makeBatchWatcherStub(),
|
|
10992
11148
|
sleep: sleep.sleep,
|
|
@@ -11022,6 +11178,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11022
11178
|
}
|
|
11023
11179
|
finally {
|
|
11024
11180
|
capture.restore();
|
|
11181
|
+
if (saved === undefined)
|
|
11182
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11183
|
+
else
|
|
11184
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11025
11185
|
}
|
|
11026
11186
|
});
|
|
11027
11187
|
it("startup runs one full reconcile, then watcher edits interrupt the pending wait", async () => {
|
|
@@ -11327,6 +11487,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11327
11487
|
await loop;
|
|
11328
11488
|
});
|
|
11329
11489
|
it("drops an unroutable batch and leaves the next unexpired poll idle", async () => {
|
|
11490
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11491
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
|
|
11330
11492
|
const capture = captureFullReconcileDecisions();
|
|
11331
11493
|
try {
|
|
11332
11494
|
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
@@ -11352,6 +11514,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11352
11514
|
}
|
|
11353
11515
|
finally {
|
|
11354
11516
|
capture.restore();
|
|
11517
|
+
if (saved === undefined)
|
|
11518
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11519
|
+
else
|
|
11520
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11355
11521
|
}
|
|
11356
11522
|
});
|
|
11357
11523
|
it("personal scoped ticks preserve personal mode for the pull leg", async () => {
|
|
@@ -11510,7 +11676,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11510
11676
|
}
|
|
11511
11677
|
expect(runPass).not.toHaveBeenCalled();
|
|
11512
11678
|
runPass.mockClear();
|
|
11513
|
-
clockState.now =
|
|
11679
|
+
clockState.now = DEFAULT_FULL_RECONCILE_MS;
|
|
11514
11680
|
sleep.tick();
|
|
11515
11681
|
await flushLoopMicrotasks();
|
|
11516
11682
|
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
@@ -11518,105 +11684,134 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11518
11684
|
sleep.tick();
|
|
11519
11685
|
await loop;
|
|
11520
11686
|
});
|
|
11521
|
-
it("schedules the full reconcile by elapsed time, not tick count,
|
|
11687
|
+
it("schedules the full reconcile by elapsed time, not tick count, when the interval env is unset", async () => {
|
|
11522
11688
|
// Pre-fix the unset default was every tenth tick. Ticks fire on every
|
|
11523
11689
|
// watcher batch, so an active vault ran a ~10-minute full pass every
|
|
11524
11690
|
// 4-8 minutes — nearly continuous, and the runner's dominant CPU cost
|
|
11525
11691
|
// once per-pass hashing was fixed.
|
|
11526
|
-
const
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11692
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11693
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11694
|
+
try {
|
|
11695
|
+
const clockState = { now: 0 };
|
|
11696
|
+
const watcher = makeBatchWatcherStub();
|
|
11697
|
+
const sleep = makeSteppableSleep();
|
|
11698
|
+
let triggerShutdown = () => { };
|
|
11699
|
+
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
11700
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11701
|
+
runPass,
|
|
11702
|
+
clock: new FakeClock(),
|
|
11703
|
+
monotonicNow: () => clockState.now,
|
|
11704
|
+
createWatcher: () => watcher,
|
|
11705
|
+
sleep: sleep.sleep,
|
|
11706
|
+
onShutdownSignal: (handler) => {
|
|
11707
|
+
triggerShutdown = handler;
|
|
11708
|
+
return () => { };
|
|
11709
|
+
},
|
|
11710
|
+
});
|
|
11711
|
+
await flushLoopMicrotasks();
|
|
11712
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11713
|
+
runPass.mockClear();
|
|
11714
|
+
// Twenty ticks in fifty-nine minutes: the old cadence would have run
|
|
11715
|
+
// two full passes here.
|
|
11716
|
+
for (let tick = 0; tick < 20; tick++) {
|
|
11717
|
+
clockState.now += 177_000;
|
|
11718
|
+
sleep.tick();
|
|
11719
|
+
await flushLoopMicrotasks();
|
|
11720
|
+
}
|
|
11721
|
+
expect(runPass).not.toHaveBeenCalled();
|
|
11722
|
+
runPass.mockClear();
|
|
11723
|
+
clockState.now = DEFAULT_FULL_RECONCILE_MS;
|
|
11549
11724
|
sleep.tick();
|
|
11550
11725
|
await flushLoopMicrotasks();
|
|
11726
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11727
|
+
triggerShutdown();
|
|
11728
|
+
await loop;
|
|
11729
|
+
}
|
|
11730
|
+
finally {
|
|
11731
|
+
if (saved === undefined)
|
|
11732
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11733
|
+
else
|
|
11734
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11551
11735
|
}
|
|
11552
|
-
expect(runPass).not.toHaveBeenCalled();
|
|
11553
|
-
runPass.mockClear();
|
|
11554
|
-
clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
|
|
11555
|
-
sleep.tick();
|
|
11556
|
-
await flushLoopMicrotasks();
|
|
11557
|
-
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11558
|
-
triggerShutdown();
|
|
11559
|
-
await loop;
|
|
11560
11736
|
});
|
|
11561
|
-
it("uses the
|
|
11562
|
-
const
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
|
|
11737
|
+
it("uses the configured elapsed-time interval instead of the tick count", async () => {
|
|
11738
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11739
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
|
|
11740
|
+
try {
|
|
11741
|
+
const clockState = { now: 0 };
|
|
11742
|
+
const watcher = makeBatchWatcherStub();
|
|
11743
|
+
const sleep = makeSteppableSleep();
|
|
11744
|
+
let triggerShutdown = () => { };
|
|
11745
|
+
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
11746
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11747
|
+
runPass,
|
|
11748
|
+
clock: new FakeClock(),
|
|
11749
|
+
monotonicNow: () => clockState.now,
|
|
11750
|
+
createWatcher: () => watcher,
|
|
11751
|
+
sleep: sleep.sleep,
|
|
11752
|
+
onShutdownSignal: (handler) => {
|
|
11753
|
+
triggerShutdown = handler;
|
|
11754
|
+
return () => { };
|
|
11755
|
+
},
|
|
11756
|
+
});
|
|
11757
|
+
await flushLoopMicrotasks();
|
|
11758
|
+
// Startup always forces the first full reconcile, and starts the interval.
|
|
11759
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11760
|
+
runPass.mockClear();
|
|
11761
|
+
clockState.now = 999;
|
|
11762
|
+
sleep.tick();
|
|
11763
|
+
await flushLoopMicrotasks();
|
|
11764
|
+
expect(runPass).not.toHaveBeenCalled();
|
|
11765
|
+
runPass.mockClear();
|
|
11766
|
+
clockState.now = 1_000;
|
|
11767
|
+
sleep.tick();
|
|
11768
|
+
await flushLoopMicrotasks();
|
|
11769
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11770
|
+
triggerShutdown();
|
|
11771
|
+
await loop;
|
|
11772
|
+
}
|
|
11773
|
+
finally {
|
|
11774
|
+
if (saved === undefined)
|
|
11775
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11776
|
+
else
|
|
11777
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11778
|
+
}
|
|
11594
11779
|
});
|
|
11595
11780
|
it("does not let a full-reconcile interval suppress event-push activation", async () => {
|
|
11596
|
-
const
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11781
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11782
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
11783
|
+
try {
|
|
11784
|
+
const watcher = makeBatchWatcherStub();
|
|
11785
|
+
const sleep = makeSteppableSleep();
|
|
11786
|
+
let triggerShutdown = () => { };
|
|
11787
|
+
// A numeric partial result does not activate event-push surfaces, so the
|
|
11788
|
+
// next tick must force another full pass even though three hours have not elapsed.
|
|
11789
|
+
const runPass = vi.fn().mockResolvedValue(PARTIAL_SYNC_EXIT);
|
|
11790
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11791
|
+
runPass,
|
|
11792
|
+
clock: new FakeClock(),
|
|
11793
|
+
monotonicNow: () => 0,
|
|
11794
|
+
createWatcher: () => watcher,
|
|
11795
|
+
sleep: sleep.sleep,
|
|
11796
|
+
onShutdownSignal: (handler) => {
|
|
11797
|
+
triggerShutdown = handler;
|
|
11798
|
+
return () => { };
|
|
11799
|
+
},
|
|
11800
|
+
});
|
|
11801
|
+
await flushLoopMicrotasks();
|
|
11802
|
+
runPass.mockClear();
|
|
11803
|
+
sleep.tick();
|
|
11804
|
+
await flushLoopMicrotasks();
|
|
11805
|
+
expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
|
|
11806
|
+
triggerShutdown();
|
|
11807
|
+
await loop;
|
|
11808
|
+
}
|
|
11809
|
+
finally {
|
|
11810
|
+
if (saved === undefined)
|
|
11811
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11812
|
+
else
|
|
11813
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11814
|
+
}
|
|
11620
11815
|
});
|
|
11621
11816
|
it("overflow with known dropped-route hints fans out per touched route instead of a full reconcile", async () => {
|
|
11622
11817
|
const capture = captureFullReconcileDecisions();
|
|
@@ -11751,40 +11946,50 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
|
11751
11946
|
await loop;
|
|
11752
11947
|
});
|
|
11753
11948
|
it("a batch above the shipped 10,000-path default stays on chunked targeted passes before the interval", async () => {
|
|
11754
|
-
const
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
|
|
11763
|
-
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
.
|
|
11783
|
-
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11787
|
-
|
|
11949
|
+
const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11950
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
|
|
11951
|
+
try {
|
|
11952
|
+
const watcher = makeBatchWatcherStub();
|
|
11953
|
+
const sleep = makeSteppableSleep();
|
|
11954
|
+
let triggerShutdown = () => { };
|
|
11955
|
+
const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
|
|
11956
|
+
const loop = runRunnerWithLoop(watchArgv, {
|
|
11957
|
+
runPass,
|
|
11958
|
+
clock: new FakeClock(),
|
|
11959
|
+
monotonicNow: () => 0,
|
|
11960
|
+
createWatcher: () => watcher,
|
|
11961
|
+
sleep: sleep.sleep,
|
|
11962
|
+
onShutdownSignal: (handler) => {
|
|
11963
|
+
triggerShutdown = handler;
|
|
11964
|
+
return () => { };
|
|
11965
|
+
},
|
|
11966
|
+
});
|
|
11967
|
+
await flushLoopMicrotasks();
|
|
11968
|
+
runPass.mockClear();
|
|
11969
|
+
watcher.emit("companies/indigo/a.md", {
|
|
11970
|
+
paths: new Map(Array.from({ length: 10_001 }, (_, index) => [
|
|
11971
|
+
`/tmp/hq/companies/indigo/${index}.md`,
|
|
11972
|
+
`companies/indigo/${index}.md`,
|
|
11973
|
+
])),
|
|
11974
|
+
});
|
|
11975
|
+
sleep.tick();
|
|
11976
|
+
await flushLoopMicrotasks(40);
|
|
11977
|
+
const calls = runPass.mock.calls.map((call) => call[0]);
|
|
11978
|
+
expect(calls).not.toContainEqual(fullArgv);
|
|
11979
|
+
const pushScopeCounts = calls
|
|
11980
|
+
.filter((argv) => argv.includes("push"))
|
|
11981
|
+
.map((argv) => scopePathsFromArgv(argv).length);
|
|
11982
|
+
expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
|
|
11983
|
+
expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
|
|
11984
|
+
triggerShutdown();
|
|
11985
|
+
await loop;
|
|
11986
|
+
}
|
|
11987
|
+
finally {
|
|
11988
|
+
if (saved === undefined)
|
|
11989
|
+
delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
11990
|
+
else
|
|
11991
|
+
process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
|
|
11992
|
+
}
|
|
11788
11993
|
});
|
|
11789
11994
|
it("a throwing targeted pass falls back to one full reconcile instead of dropping the change", async () => {
|
|
11790
11995
|
const capture = captureFullReconcileDecisions();
|
|
@@ -12135,7 +12340,7 @@ describe("resolvePullScope", () => {
|
|
|
12135
12340
|
isDefault: false,
|
|
12136
12341
|
}),
|
|
12137
12342
|
listMyExplicitGrants: async () => [
|
|
12138
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
12343
|
+
{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" },
|
|
12139
12344
|
],
|
|
12140
12345
|
}), "cmp_a", "acme"),
|
|
12141
12346
|
// custom
|
|
@@ -12209,7 +12414,7 @@ describe("resolvePullScope", () => {
|
|
|
12209
12414
|
isDefault: false,
|
|
12210
12415
|
}),
|
|
12211
12416
|
listMyExplicitGrants: async () => [
|
|
12212
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
12417
|
+
{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" },
|
|
12213
12418
|
],
|
|
12214
12419
|
}), "cmp_a", "acme");
|
|
12215
12420
|
expect(scope).toEqual({ syncMode: "shared", prefixSet: ["knowledge/"], excludePrefixes: [SESSIONS_SCOPE_PREFIX] });
|
|
@@ -12253,15 +12458,36 @@ describe("resolvePullScope", () => {
|
|
|
12253
12458
|
isDefault: false,
|
|
12254
12459
|
}),
|
|
12255
12460
|
listMyExplicitGrants: async () => [
|
|
12256
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
12257
|
-
{ companyUid: "cmp_a", path: "knowledge/sub
|
|
12258
|
-
{ companyUid: "cmp_a", path: "shared
|
|
12461
|
+
{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" },
|
|
12462
|
+
{ companyUid: "cmp_a", path: "knowledge/sub/*", permission: "read", source: "group" },
|
|
12463
|
+
{ companyUid: "cmp_a", path: "shared/*", permission: "read", source: "open" },
|
|
12259
12464
|
],
|
|
12260
12465
|
}), "cmp_a", "acme");
|
|
12261
12466
|
// knowledge/sub/ is covered by knowledge/ → coalesced away.
|
|
12262
12467
|
expect(scope.syncMode).toBe("shared");
|
|
12263
12468
|
expect(scope.prefixSet).toEqual(["knowledge/", "shared/"]);
|
|
12264
12469
|
});
|
|
12470
|
+
it.each(["read", "write"])("keeps a private foo/ %s grant distinct while retaining its minted child rows", async (permission) => {
|
|
12471
|
+
const scope = await resolvePullScope(stubClient({
|
|
12472
|
+
listMyMemberships: async () => [membership("cmp_a", "mk_a")],
|
|
12473
|
+
getMembershipSyncConfig: async () => ({
|
|
12474
|
+
membershipId: "mk_a",
|
|
12475
|
+
syncMode: "shared",
|
|
12476
|
+
isDefault: false,
|
|
12477
|
+
}),
|
|
12478
|
+
listMyExplicitGrants: async () => [
|
|
12479
|
+
{ companyUid: "cmp_a", path: "foo/", permission, source: "open" },
|
|
12480
|
+
{ companyUid: "cmp_a", path: "foo/new-folder/*", permission: "admin", source: "creator" },
|
|
12481
|
+
{ companyUid: "cmp_a", path: "foo/brief.md", permission: "admin", source: "creator" },
|
|
12482
|
+
],
|
|
12483
|
+
}), "cmp_a", "acme");
|
|
12484
|
+
expect(scope.syncMode).toBe("shared");
|
|
12485
|
+
expect(toScopePrefixEntries(scope.prefixSet ?? [])).toEqual([
|
|
12486
|
+
{ prefix: "foo/", match: "private" },
|
|
12487
|
+
{ prefix: "foo/brief.md", match: "exact" },
|
|
12488
|
+
{ prefix: "foo/new-folder/", match: "prefix" },
|
|
12489
|
+
]);
|
|
12490
|
+
});
|
|
12265
12491
|
// Regression lock-in (Michal / ridge report): a non-owner member whose
|
|
12266
12492
|
// ONLY grant is a COMPANY-WIDE write grant (surfaced by the server as
|
|
12267
12493
|
// `source: "open"`) on a projects prefix — and who has NO direct
|
|
@@ -12284,7 +12510,7 @@ describe("resolvePullScope", () => {
|
|
|
12284
12510
|
listMyExplicitGrants: async () => [
|
|
12285
12511
|
{
|
|
12286
12512
|
companyUid: "cmp_a",
|
|
12287
|
-
path: "projects/alpha
|
|
12513
|
+
path: "projects/alpha/*",
|
|
12288
12514
|
permission: "write",
|
|
12289
12515
|
source: "open",
|
|
12290
12516
|
},
|
|
@@ -12409,7 +12635,7 @@ describe("resolvePullScope", () => {
|
|
|
12409
12635
|
syncMode: "shared",
|
|
12410
12636
|
isDefault: false,
|
|
12411
12637
|
}),
|
|
12412
|
-
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge
|
|
12638
|
+
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" }],
|
|
12413
12639
|
}), "cmp_a", "acme", root);
|
|
12414
12640
|
expect(scope.syncMode).toBe("shared");
|
|
12415
12641
|
// Grant prefix + pinned prefix, coalesced + sorted.
|
|
@@ -12452,7 +12678,7 @@ describe("resolvePullScope", () => {
|
|
|
12452
12678
|
syncMode: "shared",
|
|
12453
12679
|
isDefault: false,
|
|
12454
12680
|
}),
|
|
12455
|
-
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge
|
|
12681
|
+
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge/*", permission: "read", source: "person" }],
|
|
12456
12682
|
}), "cmp_a", "acme", root);
|
|
12457
12683
|
// beta's pin must not leak into acme's scope.
|
|
12458
12684
|
expect(scope.prefixSet).toEqual(["knowledge/"]);
|