@indigoai-us/hq-cloud 6.16.52-alpha.0 → 6.16.52
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/backup-prune.d.ts +23 -1
- package/dist/backup-prune.d.ts.map +1 -1
- package/dist/backup-prune.js +92 -8
- package/dist/backup-prune.js.map +1 -1
- package/dist/backup-prune.test.js +36 -0
- package/dist/backup-prune.test.js.map +1 -1
- package/dist/bin/rescue-runner.js +2 -1
- package/dist/bin/rescue-runner.js.map +1 -1
- package/dist/bin/sync-runner-company.d.ts +0 -6
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +1 -30
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-company.test.js +0 -55
- package/dist/bin/sync-runner-company.test.js.map +1 -1
- package/dist/bin/sync-runner-planning.d.ts +3 -12
- package/dist/bin/sync-runner-planning.d.ts.map +1 -1
- package/dist/bin/sync-runner-planning.js +3 -65
- package/dist/bin/sync-runner-planning.js.map +1 -1
- package/dist/bin/sync-runner-planning.test.js +1 -108
- package/dist/bin/sync-runner-planning.test.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.d.ts +2 -48
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +116 -311
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +5 -33
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +4 -34
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +79 -802
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/rescue-breaker.test.d.ts +2 -0
- package/dist/cli/rescue-breaker.test.d.ts.map +1 -0
- package/dist/cli/rescue-breaker.test.js +334 -0
- package/dist/cli/rescue-breaker.test.js.map +1 -0
- package/dist/cli/rescue-core.d.ts +40 -0
- package/dist/cli/rescue-core.d.ts.map +1 -1
- package/dist/cli/rescue-core.js +1454 -162
- package/dist/cli/rescue-core.js.map +1 -1
- package/dist/cli/rescue-realpath.test.d.ts +2 -0
- package/dist/cli/rescue-realpath.test.d.ts.map +1 -0
- package/dist/cli/rescue-realpath.test.js +109 -0
- package/dist/cli/rescue-realpath.test.js.map +1 -0
- package/dist/cli/rescue-rsync-preflight.test.js +256 -4
- package/dist/cli/rescue-rsync-preflight.test.js.map +1 -1
- package/dist/cli/rescue-snapshot-copy.test.d.ts +2 -0
- package/dist/cli/rescue-snapshot-copy.test.d.ts.map +1 -0
- package/dist/cli/rescue-snapshot-copy.test.js +627 -0
- package/dist/cli/rescue-snapshot-copy.test.js.map +1 -0
- package/dist/cli/rescue-snapshot-recovery.test.d.ts +2 -0
- package/dist/cli/rescue-snapshot-recovery.test.d.ts.map +1 -0
- package/dist/cli/rescue-snapshot-recovery.test.js +260 -0
- package/dist/cli/rescue-snapshot-recovery.test.js.map +1 -0
- package/dist/cli/rescue-source-switch-floor.test.d.ts +2 -0
- package/dist/cli/rescue-source-switch-floor.test.d.ts.map +1 -0
- package/dist/cli/rescue-source-switch-floor.test.js +210 -0
- package/dist/cli/rescue-source-switch-floor.test.js.map +1 -0
- package/dist/cli/rescue.d.ts +4 -0
- package/dist/cli/rescue.d.ts.map +1 -1
- package/dist/cli/rescue.js +20 -1
- package/dist/cli/rescue.js.map +1 -1
- package/dist/cli/rescue.test.js +16 -1
- package/dist/cli/rescue.test.js.map +1 -1
- package/dist/cli/share-presign-transport.test.js +2 -0
- package/dist/cli/share-presign-transport.test.js.map +1 -1
- package/dist/cli/share.d.ts +0 -19
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +37 -57
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +93 -87
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync-scope.test.js +0 -8
- package/dist/cli/sync-scope.test.js.map +1 -1
- package/dist/cli/sync.d.ts +0 -12
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +118 -226
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +2 -215
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/cli/watch-event-push-conflict.test.js +2 -0
- package/dist/cli/watch-event-push-conflict.test.js.map +1 -1
- package/dist/cognito-auth.d.ts +30 -0
- package/dist/cognito-auth.d.ts.map +1 -1
- package/dist/cognito-auth.js +175 -0
- package/dist/cognito-auth.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/journal-row-store.d.ts +5 -9
- package/dist/journal-row-store.d.ts.map +1 -1
- package/dist/journal-row-store.js +10 -70
- package/dist/journal-row-store.js.map +1 -1
- package/dist/journal-snapshot-v4.d.ts.map +1 -1
- package/dist/journal-snapshot-v4.js +6 -11
- package/dist/journal-snapshot-v4.js.map +1 -1
- package/dist/journal-store.test.js +7 -259
- package/dist/journal-store.test.js.map +1 -1
- package/dist/journal.d.ts +12 -37
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +76 -291
- package/dist/journal.js.map +1 -1
- package/dist/lib/exit-codes.d.ts +0 -15
- package/dist/lib/exit-codes.d.ts.map +1 -1
- package/dist/lib/exit-codes.js +0 -15
- package/dist/lib/exit-codes.js.map +1 -1
- package/dist/machine-auth.test.js +295 -0
- package/dist/machine-auth.test.js.map +1 -1
- package/dist/object-io.d.ts +2 -2
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +18 -3
- package/dist/object-io.js.map +1 -1
- package/dist/personal-vault.d.ts.map +1 -1
- package/dist/personal-vault.js +3 -10
- package/dist/personal-vault.js.map +1 -1
- package/dist/personal-vault.test.js +0 -35
- package/dist/personal-vault.test.js.map +1 -1
- package/dist/remote-pull.d.ts.map +1 -1
- package/dist/remote-pull.js +2 -9
- package/dist/remote-pull.js.map +1 -1
- package/dist/remote-pull.test.js +2 -59
- package/dist/remote-pull.test.js.map +1 -1
- package/dist/s3.d.ts +18 -1
- package/dist/s3.d.ts.map +1 -1
- package/dist/s3.js +47 -24
- package/dist/s3.js.map +1 -1
- package/dist/s3.test.js +27 -1
- package/dist/s3.test.js.map +1 -1
- package/dist/sync/area-ledger.js +4 -4
- package/dist/sync/area-ledger.js.map +1 -1
- package/dist/sync/parallel-sync-coordinator.test.js +0 -29
- package/dist/sync/parallel-sync-coordinator.test.js.map +1 -1
- package/dist/sync/realtime-telemetry.d.ts +1 -1
- package/dist/sync/realtime-telemetry.d.ts.map +1 -1
- package/dist/sync/realtime-telemetry.js +6 -14
- package/dist/sync/realtime-telemetry.js.map +1 -1
- package/dist/sync/realtime-telemetry.test.js +16 -136
- package/dist/sync/realtime-telemetry.test.js.map +1 -1
- package/dist/sync-core.d.ts +6 -4
- package/dist/sync-core.d.ts.map +1 -1
- package/dist/sync-core.js +10 -4
- package/dist/sync-core.js.map +1 -1
- package/dist/sync-core.test.js +25 -1
- package/dist/sync-core.test.js.map +1 -1
- package/package.json +1 -2
- package/dist/cli/onepass-pull-planner-regressions.test.d.ts +0 -2
- package/dist/cli/onepass-pull-planner-regressions.test.d.ts.map +0 -1
- package/dist/cli/onepass-pull-planner-regressions.test.js +0 -300
- package/dist/cli/onepass-pull-planner-regressions.test.js.map +0 -1
- package/dist/cli/onepass-pull-planner.test.d.ts +0 -2
- package/dist/cli/onepass-pull-planner.test.d.ts.map +0 -1
- package/dist/cli/onepass-pull-planner.test.js +0 -266
- package/dist/cli/onepass-pull-planner.test.js.map +0 -1
- package/dist/cli/streaming-pull-planner.bench.test.d.ts +0 -15
- package/dist/cli/streaming-pull-planner.bench.test.d.ts.map +0 -1
- package/dist/cli/streaming-pull-planner.bench.test.js +0 -273
- package/dist/cli/streaming-pull-planner.bench.test.js.map +0 -1
- package/dist/s3.list-cost.test.d.ts +0 -2
- package/dist/s3.list-cost.test.d.ts.map +0 -1
- package/dist/s3.list-cost.test.js +0 -51
- package/dist/s3.list-cost.test.js.map +0 -1
- package/dist/sync/remote-file-spool.d.ts +0 -16
- package/dist/sync/remote-file-spool.d.ts.map +0 -1
- package/dist/sync/remote-file-spool.js +0 -91
- package/dist/sync/remote-file-spool.js.map +0 -1
- package/dist/sync/remote-file-spool.test.d.ts +0 -2
- package/dist/sync/remote-file-spool.test.d.ts.map +0 -1
- package/dist/sync/remote-file-spool.test.js +0 -77
- package/dist/sync/remote-file-spool.test.js.map +0 -1
|
@@ -10,7 +10,6 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
|
10
10
|
import * as fs from "fs";
|
|
11
11
|
import * as os from "os";
|
|
12
12
|
import * as path from "path";
|
|
13
|
-
import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
14
13
|
import { runRunner, runRunnerWithLoop, resolveDeletePolicy, resolveSkipPersonal, resolveSkipCompanies, selectObjectIOFactory, routeChangeToTarget, buildTargetedPushArgv, resolvePullScope, readPinnedPrefixes, SESSIONS_SCOPE_PREFIX, defaultCollectTelemetry, AUTH_REQUIRED_PASS_EXIT, } from "./sync-runner.js";
|
|
15
14
|
import { SESSION_LOGS_PUSH_ONLY_PREFIX } from "../sync/pull-scope.js";
|
|
16
15
|
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";
|
|
@@ -18,18 +17,17 @@ import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
|
|
|
18
17
|
import { setBandwidthGovernorForTesting } from "../bandwidth.js";
|
|
19
18
|
import { POST_SYNC_FLAG_KEYS, } from "./sync-runner-post-sync-flags.js";
|
|
20
19
|
import { FakeClock, TreeWatcher, } from "../watcher.js";
|
|
21
|
-
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,
|
|
22
|
-
import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal,
|
|
20
|
+
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, normalizeCoordinatorPaths, shouldQuarantineWatcherDeleteIntents, shouldUseAreaStorage, WATCHER_REDISCOVERY_RETRY_MS, WATCHER_REDISCOVERY_RETRY_MAX_MS, } from "./sync-runner-watch-loop.js";
|
|
21
|
+
import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, writeJournal, } from "../journal.js";
|
|
23
22
|
import { AreaResolver } from "../sync/area-resolver.js";
|
|
24
23
|
import { AreaMaintenanceCursorStore } from "../sync/per-area-maintenance.js";
|
|
25
24
|
import { HQ_CLOUD_VERSION } from "../version.js";
|
|
26
25
|
import { lockPathFor, OPERATION_LOCKED_EXIT } from "../operation-lock.js";
|
|
27
26
|
import { TRANSIENT_NETWORK_EXIT } from "../lib/net-errors.js";
|
|
28
27
|
import { getStateStoreSnapshotRecoveryCountForTest, resetStateStoreSnapshotRecoveryCountForTest, StateStoreLockError, } from "../sync/state-store.js";
|
|
29
|
-
import { PARTIAL_SYNC_EXIT
|
|
28
|
+
import { PARTIAL_SYNC_EXIT } from "../lib/exit-codes.js";
|
|
30
29
|
import { isCoveredByAny } from "../prefix-coalesce.js";
|
|
31
30
|
import { VaultAuthError, VaultNotFoundError } from "../vault-client.js";
|
|
32
|
-
import { buildRoutePullArgv } from "./sync-runner-watch-routes.js";
|
|
33
31
|
import { CognitoAuthError, CognitoRefreshError } from "../cognito-auth.js";
|
|
34
32
|
import { reconcileCompanyManifest, } from "../manifest-reconcile.js";
|
|
35
33
|
import yaml from "js-yaml";
|
|
@@ -164,7 +162,6 @@ function makeVaultStub(opts = {}) {
|
|
|
164
162
|
bucketName: `bucket-${uid}`,
|
|
165
163
|
status: "active",
|
|
166
164
|
})),
|
|
167
|
-
findInMyNamespace: opts.findInMyNamespace ?? (() => Promise.resolve(null)),
|
|
168
165
|
listByType: opts.listPersons ??
|
|
169
166
|
(() => Promise.resolve([])),
|
|
170
167
|
},
|
|
@@ -957,164 +954,6 @@ describe("target resolution", () => {
|
|
|
957
954
|
const call = deps.sync.mock.calls[0][0];
|
|
958
955
|
expect(call.company).toBe("cmp_abc");
|
|
959
956
|
});
|
|
960
|
-
it("returns the unresolved-company exit for an empty single-company plan instead of emitting a clean all-complete", async () => {
|
|
961
|
-
const deps = makeDeps({
|
|
962
|
-
createVaultClient: () => makeVaultStub({
|
|
963
|
-
entityGet: () => Promise.resolve(undefined),
|
|
964
|
-
}),
|
|
965
|
-
});
|
|
966
|
-
expect(await runRunner(["--company", "cmp_missing"], deps)).toBe(UNRESOLVED_COMPANY_EXIT);
|
|
967
|
-
expect(deps.stderr.events()).toContainEqual({
|
|
968
|
-
type: "error",
|
|
969
|
-
company: "cmp_missing",
|
|
970
|
-
path: "(company-resolution)",
|
|
971
|
-
message: "company entity lookup returned no entity",
|
|
972
|
-
});
|
|
973
|
-
expect(deps.stdout.events().some((event) => event.type === "all-complete")).toBe(false);
|
|
974
|
-
expect(deps.sync).not.toHaveBeenCalled();
|
|
975
|
-
});
|
|
976
|
-
it("returns the unresolved-company exit when a cmp-prefixed route gets a 404", async () => {
|
|
977
|
-
const client = makeVaultStub({
|
|
978
|
-
entityGet: () => Promise.reject(new VaultNotFoundError("company deleted")),
|
|
979
|
-
});
|
|
980
|
-
const findInMyNamespace = vi.fn().mockResolvedValue(null);
|
|
981
|
-
client.entity.findInMyNamespace = findInMyNamespace;
|
|
982
|
-
const deps = makeDeps({
|
|
983
|
-
createVaultClient: () => client,
|
|
984
|
-
});
|
|
985
|
-
expect(await runRunner(["--company", "cmp_ghost"], deps)).toBe(UNRESOLVED_COMPANY_EXIT);
|
|
986
|
-
expect(findInMyNamespace).toHaveBeenCalledWith("company", "cmp_ghost");
|
|
987
|
-
expect(deps.stderr.events()).toContainEqual({
|
|
988
|
-
type: "error",
|
|
989
|
-
company: "cmp_ghost",
|
|
990
|
-
path: "(company-resolution)",
|
|
991
|
-
message: "company entity lookup returned 404",
|
|
992
|
-
});
|
|
993
|
-
expect(deps.stdout.events().some((event) => event.type === "all-complete")).toBe(false);
|
|
994
|
-
});
|
|
995
|
-
it("reports an intentional skipCompanies skip without treating it as a failed pass", async () => {
|
|
996
|
-
const previous = process.env.HQ_SYNC_SKIP_COMPANIES;
|
|
997
|
-
process.env.HQ_SYNC_SKIP_COMPANIES = "paused";
|
|
998
|
-
try {
|
|
999
|
-
const deps = makeDeps({
|
|
1000
|
-
createVaultClient: () => makeVaultStub({
|
|
1001
|
-
entityGet: (uid) => Promise.resolve({
|
|
1002
|
-
uid,
|
|
1003
|
-
slug: "paused",
|
|
1004
|
-
type: "company",
|
|
1005
|
-
status: "active",
|
|
1006
|
-
}),
|
|
1007
|
-
}),
|
|
1008
|
-
});
|
|
1009
|
-
expect(await runRunner(["--company", "cmp_paused"], deps)).toBe(0);
|
|
1010
|
-
expect(deps.stdout.events()).toContainEqual({
|
|
1011
|
-
type: "company-skipped",
|
|
1012
|
-
company: "paused",
|
|
1013
|
-
reason: "skip-companies",
|
|
1014
|
-
});
|
|
1015
|
-
expect(deps.stderr.events().some((event) => event.type === "error")).toBe(false);
|
|
1016
|
-
expect(deps.stdout.events().some((event) => event.type === "all-complete")).toBe(false);
|
|
1017
|
-
expect(deps.sync).not.toHaveBeenCalled();
|
|
1018
|
-
}
|
|
1019
|
-
finally {
|
|
1020
|
-
if (previous === undefined)
|
|
1021
|
-
delete process.env.HQ_SYNC_SKIP_COMPANIES;
|
|
1022
|
-
else
|
|
1023
|
-
process.env.HQ_SYNC_SKIP_COMPANIES = previous;
|
|
1024
|
-
}
|
|
1025
|
-
});
|
|
1026
|
-
it("resolves a slug emitted by the company watch route to its namespace UID", async () => {
|
|
1027
|
-
const company = {
|
|
1028
|
-
uid: "cmp_indigo",
|
|
1029
|
-
slug: "indigo",
|
|
1030
|
-
type: "company",
|
|
1031
|
-
status: "active",
|
|
1032
|
-
bucketName: "bucket-cmp_indigo",
|
|
1033
|
-
};
|
|
1034
|
-
const client = makeVaultStub({
|
|
1035
|
-
entityGet: (uid) => Promise.resolve(uid === company.uid ? company : undefined),
|
|
1036
|
-
});
|
|
1037
|
-
const findInMyNamespace = vi.fn().mockResolvedValue(company);
|
|
1038
|
-
client.entity.findInMyNamespace = findInMyNamespace;
|
|
1039
|
-
const deps = makeDeps({ createVaultClient: () => client });
|
|
1040
|
-
const argv = buildRoutePullArgv({ kind: "company", slug: "indigo" }, ["--companies", "--watch", "--hq-root", "/tmp/hq"]);
|
|
1041
|
-
expect(argv).toEqual([
|
|
1042
|
-
"--company",
|
|
1043
|
-
"indigo",
|
|
1044
|
-
"--direction",
|
|
1045
|
-
"pull",
|
|
1046
|
-
"--hq-root",
|
|
1047
|
-
"/tmp/hq",
|
|
1048
|
-
]);
|
|
1049
|
-
expect(await runRunner(argv, deps)).toBe(0);
|
|
1050
|
-
expect(findInMyNamespace).toHaveBeenCalledWith("company", "indigo");
|
|
1051
|
-
expect(deps.sync).toHaveBeenCalledWith(expect.objectContaining({ company: "cmp_indigo" }));
|
|
1052
|
-
expect(deps.stdout.events()).toContainEqual({
|
|
1053
|
-
type: "fanout-plan",
|
|
1054
|
-
companies: [
|
|
1055
|
-
expect.objectContaining({ uid: "cmp_indigo", slug: "indigo" }),
|
|
1056
|
-
],
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
it("resolves a cmp-prefixed directory slug in the caller namespace before treating it as a UID", async () => {
|
|
1060
|
-
const company = {
|
|
1061
|
-
uid: "cmp_01JTEAM000000000000000000",
|
|
1062
|
-
slug: "cmp_team",
|
|
1063
|
-
type: "company",
|
|
1064
|
-
status: "active",
|
|
1065
|
-
bucketName: "bucket-cmp-team",
|
|
1066
|
-
};
|
|
1067
|
-
const get = vi.fn().mockImplementation((uid) => Promise.resolve(uid === company.uid ? company : undefined));
|
|
1068
|
-
const client = makeVaultStub({ entityGet: get });
|
|
1069
|
-
const findInMyNamespace = vi.fn().mockResolvedValue(company);
|
|
1070
|
-
client.entity.findInMyNamespace = findInMyNamespace;
|
|
1071
|
-
const deps = makeDeps({ createVaultClient: () => client });
|
|
1072
|
-
const argv = buildRoutePullArgv({ kind: "company", slug: "cmp_team" }, ["--companies", "--watch", "--hq-root", "/tmp/hq"]);
|
|
1073
|
-
expect(await runRunner(argv, deps)).toBe(0);
|
|
1074
|
-
expect(findInMyNamespace).toHaveBeenCalledWith("company", "cmp_team");
|
|
1075
|
-
expect(get).toHaveBeenCalledWith(company.uid);
|
|
1076
|
-
expect(deps.sync).toHaveBeenCalledWith(expect.objectContaining({ company: company.uid }));
|
|
1077
|
-
expect(deps.stdout.events()).toContainEqual({
|
|
1078
|
-
type: "fanout-plan",
|
|
1079
|
-
companies: [expect.objectContaining({ uid: company.uid, slug: "cmp_team" })],
|
|
1080
|
-
});
|
|
1081
|
-
});
|
|
1082
|
-
it("falls back to a literal company UID after caller-namespace slug resolution misses", async () => {
|
|
1083
|
-
const uid = "cmp_01JUID0000000000000000000";
|
|
1084
|
-
const company = {
|
|
1085
|
-
uid,
|
|
1086
|
-
slug: "operator-company",
|
|
1087
|
-
type: "company",
|
|
1088
|
-
status: "active",
|
|
1089
|
-
bucketName: "bucket-operator-company",
|
|
1090
|
-
};
|
|
1091
|
-
const get = vi.fn().mockResolvedValue(company);
|
|
1092
|
-
const client = makeVaultStub({ entityGet: get });
|
|
1093
|
-
const findInMyNamespace = vi.fn().mockResolvedValue(null);
|
|
1094
|
-
client.entity.findInMyNamespace = findInMyNamespace;
|
|
1095
|
-
const deps = makeDeps({ createVaultClient: () => client });
|
|
1096
|
-
expect(await runRunner(["--company", uid], deps)).toBe(0);
|
|
1097
|
-
expect(findInMyNamespace).toHaveBeenCalledWith("company", uid);
|
|
1098
|
-
expect(get).toHaveBeenCalledWith(uid);
|
|
1099
|
-
expect(deps.sync).toHaveBeenCalledWith(expect.objectContaining({ company: uid }));
|
|
1100
|
-
});
|
|
1101
|
-
it("reports a foreign company slug when the literal UID fallback finds nothing", async () => {
|
|
1102
|
-
const get = vi.fn().mockRejectedValue(new VaultNotFoundError("company not found"));
|
|
1103
|
-
const client = makeVaultStub({ entityGet: get });
|
|
1104
|
-
const findInMyNamespace = vi.fn().mockResolvedValue(null);
|
|
1105
|
-
client.entity.findInMyNamespace = findInMyNamespace;
|
|
1106
|
-
const deps = makeDeps({ createVaultClient: () => client });
|
|
1107
|
-
expect(await runRunner(["--company", "indigo"], deps)).toBe(UNRESOLVED_COMPANY_EXIT);
|
|
1108
|
-
expect(findInMyNamespace).toHaveBeenCalledWith("company", "indigo");
|
|
1109
|
-
expect(get).toHaveBeenCalledWith("indigo");
|
|
1110
|
-
expect(deps.sync).not.toHaveBeenCalled();
|
|
1111
|
-
expect(deps.stderr.events()).toContainEqual({
|
|
1112
|
-
type: "error",
|
|
1113
|
-
company: "indigo",
|
|
1114
|
-
path: "(company-resolution)",
|
|
1115
|
-
message: "company entity lookup returned 404",
|
|
1116
|
-
});
|
|
1117
|
-
});
|
|
1118
957
|
});
|
|
1119
958
|
// ---------------------------------------------------------------------------
|
|
1120
959
|
// --personal mode (personal-vault-only, skip company fanout)
|
|
@@ -5747,7 +5586,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5747
5586
|
});
|
|
5748
5587
|
await expect(superseded).resolves.toBeUndefined();
|
|
5749
5588
|
expect(runPass.mock.calls.filter(([argv]) => argv.includes("superseded.md"))).toHaveLength(0);
|
|
5750
|
-
expect(stderr.mock.calls.map(([chunk]) => String(chunk)).join("")).toContain('"event":"sync.realtime.timing","schemaVersion":
|
|
5589
|
+
expect(stderr.mock.calls.map(([chunk]) => String(chunk)).join("")).toContain('"event":"sync.realtime.timing","schemaVersion":1,"source":"receiver","direction":"pull","outcome":"refused"');
|
|
5751
5590
|
releaseHeld();
|
|
5752
5591
|
await heldReceiverWork;
|
|
5753
5592
|
await replacement;
|
|
@@ -6060,7 +5899,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6060
5899
|
triggerShutdown();
|
|
6061
5900
|
await loop;
|
|
6062
5901
|
});
|
|
6063
|
-
it("fast lane: a small watcher batch
|
|
5902
|
+
it("fast lane: a small watcher batch dispatches during a slow bulk pass", async () => {
|
|
6064
5903
|
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fast-lane-watch-"));
|
|
6065
5904
|
const relativePath = "companies/indigo/realtime.md";
|
|
6066
5905
|
const absolutePath = path.join(hqRoot, relativePath);
|
|
@@ -6100,17 +5939,15 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6100
5939
|
expect(order).toEqual(["bulk"]);
|
|
6101
5940
|
watcher.emit(relativePath, { paths: new Map([[absolutePath, relativePath]]) });
|
|
6102
5941
|
await flushLoopMicrotasks(30);
|
|
6103
|
-
//
|
|
6104
|
-
// owner. Realtime is promoted at the checkpoint, never run concurrently.
|
|
6105
|
-
expect(order).toEqual(["bulk"]);
|
|
6106
|
-
releaseBulk();
|
|
6107
|
-
await flushLoopMicrotasks(30);
|
|
5942
|
+
// Regression: origin/main leaves this as ["bulk"] until releaseBulk().
|
|
6108
5943
|
expect(order).toEqual(["bulk", "fast", "fast"]);
|
|
5944
|
+
releaseBulk();
|
|
5945
|
+
await flushLoopMicrotasks();
|
|
6109
5946
|
triggerShutdown();
|
|
6110
5947
|
await loop;
|
|
6111
5948
|
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6112
5949
|
});
|
|
6113
|
-
it("parallel coordinator: a watcher push
|
|
5950
|
+
it("parallel coordinator: a watcher push starts while a full chore is blocked", async () => {
|
|
6114
5951
|
const previous = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6115
5952
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6116
5953
|
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-parallel-watch-"));
|
|
@@ -6153,10 +5990,9 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6153
5990
|
expect(order).toEqual(["chore"]);
|
|
6154
5991
|
watcher.emit(relativePath, { paths: new Map([[absolutePath, relativePath]]) });
|
|
6155
5992
|
await flushLoopMicrotasks(30);
|
|
6156
|
-
expect(order).toEqual(["chore"]);
|
|
6157
|
-
releaseBulk();
|
|
6158
|
-
await flushLoopMicrotasks(30);
|
|
6159
5993
|
expect(order).toEqual(["chore", "realtime"]);
|
|
5994
|
+
releaseBulk();
|
|
5995
|
+
await flushLoopMicrotasks();
|
|
6160
5996
|
triggerShutdown();
|
|
6161
5997
|
await loop;
|
|
6162
5998
|
}
|
|
@@ -6241,7 +6077,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6241
6077
|
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6242
6078
|
}
|
|
6243
6079
|
});
|
|
6244
|
-
it("parallel coordinator partitions receiver events into fast and slow realtime lanes
|
|
6080
|
+
it("parallel coordinator partitions receiver events into fast and slow realtime lanes", async () => {
|
|
6245
6081
|
const previous = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6246
6082
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6247
6083
|
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-parallel-receiver-lanes-"));
|
|
@@ -6312,7 +6148,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6312
6148
|
signal: new AbortController().signal,
|
|
6313
6149
|
});
|
|
6314
6150
|
await flushLoopMicrotasks(20);
|
|
6315
|
-
expect(order).toEqual(["slow-held"]);
|
|
6151
|
+
expect(order).toEqual(["slow-held", "fast-small"]);
|
|
6316
6152
|
releaseSlow();
|
|
6317
6153
|
await held;
|
|
6318
6154
|
await partitioned;
|
|
@@ -6478,251 +6314,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6478
6314
|
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6479
6315
|
}
|
|
6480
6316
|
});
|
|
6481
|
-
it("bounds a 32-path realtime personal commit on a 700k-row journal and 50k-path tree", async () => {
|
|
6482
|
-
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6483
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6484
|
-
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-production-scale-watch-"));
|
|
6485
|
-
const watchedRoot = path.join(hqRoot, "personal", "watch-load");
|
|
6486
|
-
const targetPaths = Array.from({ length: 32 }, (_, index) => `personal/watch-load/${String(index).padStart(5, "0")}/target.md`);
|
|
6487
|
-
const files = {};
|
|
6488
|
-
for (let index = 0; index < 700_000; index += 1) {
|
|
6489
|
-
files[`personal/history/${String(index % 50_000).padStart(5, "0")}/entry-${index}.md`] = {
|
|
6490
|
-
hash: `sha256:history-${index}`,
|
|
6491
|
-
size: index % 4096,
|
|
6492
|
-
syncedAt: "2026-09-16T21:30:00.000Z",
|
|
6493
|
-
direction: "up",
|
|
6494
|
-
};
|
|
6495
|
-
}
|
|
6496
|
-
for (const target of targetPaths) {
|
|
6497
|
-
files[target] = {
|
|
6498
|
-
hash: `sha256:${target}`,
|
|
6499
|
-
size: 1,
|
|
6500
|
-
syncedAt: "2026-09-16T21:30:00.000Z",
|
|
6501
|
-
direction: "up",
|
|
6502
|
-
};
|
|
6503
|
-
}
|
|
6504
|
-
writeJournal(PERSONAL_VAULT_JOURNAL_SLUG, {
|
|
6505
|
-
version: "2",
|
|
6506
|
-
lastSync: "2026-09-16T21:30:00.000Z",
|
|
6507
|
-
pulls: [],
|
|
6508
|
-
files,
|
|
6509
|
-
});
|
|
6510
|
-
for (let index = 0; index < 50_000; index += 1) {
|
|
6511
|
-
const directory = path.join(watchedRoot, String(index).padStart(5, "0"));
|
|
6512
|
-
fs.mkdirSync(directory, { recursive: true });
|
|
6513
|
-
fs.writeFileSync(path.join(directory, "seed.md"), "seed");
|
|
6514
|
-
}
|
|
6515
|
-
const watcher = makeBatchWatcherStub();
|
|
6516
|
-
let shutdown = () => { };
|
|
6517
|
-
let committedAt;
|
|
6518
|
-
const runPass = vi.fn(async (argv) => {
|
|
6519
|
-
if (!argv.includes("--scope-path")) {
|
|
6520
|
-
// Production opens the packed journal during the initial full pass,
|
|
6521
|
-
// before the watcher accepts realtime work. That recovered projection
|
|
6522
|
-
// is the one a scoped commit must reuse.
|
|
6523
|
-
readJournal(PERSONAL_VAULT_JOURNAL_SLUG);
|
|
6524
|
-
}
|
|
6525
|
-
if (argv.includes("--scope-path") && argv.includes("push")) {
|
|
6526
|
-
const scoped = readJournalScoped(PERSONAL_VAULT_JOURNAL_SLUG, targetPaths);
|
|
6527
|
-
const target = targetPaths[0];
|
|
6528
|
-
scoped.files[target] = {
|
|
6529
|
-
...scoped.files[target],
|
|
6530
|
-
syncedAt: "2026-09-16T21:38:18.000Z",
|
|
6531
|
-
};
|
|
6532
|
-
writeJournal(PERSONAL_VAULT_JOURNAL_SLUG, scoped);
|
|
6533
|
-
committedAt = performance.now();
|
|
6534
|
-
}
|
|
6535
|
-
return completedPassOutcome();
|
|
6536
|
-
});
|
|
6537
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--direction", "push", "--hq-root", hqRoot], {
|
|
6538
|
-
runPass,
|
|
6539
|
-
createWatcher: () => watcher,
|
|
6540
|
-
sleep: () => new Promise(() => { }),
|
|
6541
|
-
onShutdownSignal: (handler) => {
|
|
6542
|
-
shutdown = handler;
|
|
6543
|
-
return () => { };
|
|
6544
|
-
},
|
|
6545
|
-
});
|
|
6546
|
-
try {
|
|
6547
|
-
await flushLoopMicrotasks(30);
|
|
6548
|
-
runPass.mockClear();
|
|
6549
|
-
resetStateStoreSnapshotRecoveryCountForTest();
|
|
6550
|
-
const eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
|
|
6551
|
-
eventLoopDelay.enable();
|
|
6552
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
6553
|
-
const submittedAt = performance.now();
|
|
6554
|
-
let timerDelayMs;
|
|
6555
|
-
const eventLoopTurn = new Promise((resolve) => {
|
|
6556
|
-
setTimeout(() => {
|
|
6557
|
-
timerDelayMs = performance.now() - submittedAt;
|
|
6558
|
-
resolve();
|
|
6559
|
-
}, 0);
|
|
6560
|
-
});
|
|
6561
|
-
const batch = {
|
|
6562
|
-
paths: new Map(targetPaths.map((relativePath) => [path.join(hqRoot, relativePath), relativePath])),
|
|
6563
|
-
changes: new Map(targetPaths.map((relativePath) => [
|
|
6564
|
-
path.join(hqRoot, relativePath),
|
|
6565
|
-
{ kind: "change" },
|
|
6566
|
-
])),
|
|
6567
|
-
};
|
|
6568
|
-
watcher.emit(targetPaths[0], batch);
|
|
6569
|
-
await vi.waitFor(() => expect(committedAt).toBeDefined(), { timeout: 30_000, interval: 10 });
|
|
6570
|
-
await eventLoopTurn;
|
|
6571
|
-
eventLoopDelay.disable();
|
|
6572
|
-
expect(committedAt - submittedAt).toBeLessThan(1_000);
|
|
6573
|
-
expect(Number(eventLoopDelay.max) / 1_000_000).toBeLessThan(100);
|
|
6574
|
-
expect(timerDelayMs).toBeLessThan(100);
|
|
6575
|
-
expect(getStateStoreSnapshotRecoveryCountForTest()).toBe(0);
|
|
6576
|
-
expect(runPass.mock.calls.filter(([argv]) => argv.includes("--scope-path"))).toHaveLength(1);
|
|
6577
|
-
}
|
|
6578
|
-
finally {
|
|
6579
|
-
shutdown();
|
|
6580
|
-
await loop;
|
|
6581
|
-
if (previousCoordinator === undefined)
|
|
6582
|
-
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6583
|
-
else
|
|
6584
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6585
|
-
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6586
|
-
}
|
|
6587
|
-
}, 180_000);
|
|
6588
|
-
it("keeps warmed personal and company journals hot across alternating realtime batches", async () => {
|
|
6589
|
-
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6590
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6591
|
-
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-multi-journal-watch-"));
|
|
6592
|
-
const watchedRoot = path.join(hqRoot, "personal", "watch-load");
|
|
6593
|
-
const personalPath = "personal/watch-load/00000/target.md";
|
|
6594
|
-
const companyPath = "companies/indigo/watch-load/00000/target.md";
|
|
6595
|
-
const companyKey = "watch-load/00000/target.md";
|
|
6596
|
-
const personalFiles = {};
|
|
6597
|
-
for (let index = 0; index < 700_000; index += 1) {
|
|
6598
|
-
personalFiles[`personal/history/${String(index % 50_000).padStart(5, "0")}/entry-${index}.md`] = {
|
|
6599
|
-
hash: `sha256:history-${index}`,
|
|
6600
|
-
size: index % 4096,
|
|
6601
|
-
syncedAt: "2026-09-16T21:30:00.000Z",
|
|
6602
|
-
direction: "up",
|
|
6603
|
-
};
|
|
6604
|
-
}
|
|
6605
|
-
personalFiles[personalPath] = {
|
|
6606
|
-
hash: "sha256:personal-target",
|
|
6607
|
-
size: 1,
|
|
6608
|
-
syncedAt: "2026-09-16T21:30:00.000Z",
|
|
6609
|
-
direction: "up",
|
|
6610
|
-
};
|
|
6611
|
-
writeJournal(PERSONAL_VAULT_JOURNAL_SLUG, {
|
|
6612
|
-
version: "2",
|
|
6613
|
-
lastSync: "2026-09-16T21:30:00.000Z",
|
|
6614
|
-
pulls: [],
|
|
6615
|
-
files: personalFiles,
|
|
6616
|
-
});
|
|
6617
|
-
writeJournal("indigo", {
|
|
6618
|
-
version: "2",
|
|
6619
|
-
lastSync: "2026-09-16T21:30:00.000Z",
|
|
6620
|
-
pulls: [],
|
|
6621
|
-
files: {
|
|
6622
|
-
[companyKey]: {
|
|
6623
|
-
hash: "sha256:company-target",
|
|
6624
|
-
size: 1,
|
|
6625
|
-
syncedAt: "2026-09-16T21:30:00.000Z",
|
|
6626
|
-
direction: "up",
|
|
6627
|
-
},
|
|
6628
|
-
},
|
|
6629
|
-
});
|
|
6630
|
-
for (let index = 0; index < 50_000; index += 1) {
|
|
6631
|
-
const directory = path.join(watchedRoot, String(index).padStart(5, "0"));
|
|
6632
|
-
fs.mkdirSync(directory, { recursive: true });
|
|
6633
|
-
fs.writeFileSync(path.join(directory, "seed.md"), "seed");
|
|
6634
|
-
}
|
|
6635
|
-
fs.mkdirSync(path.dirname(path.join(hqRoot, personalPath)), { recursive: true });
|
|
6636
|
-
fs.writeFileSync(path.join(hqRoot, personalPath), "personal");
|
|
6637
|
-
fs.mkdirSync(path.dirname(path.join(hqRoot, companyPath)), { recursive: true });
|
|
6638
|
-
fs.writeFileSync(path.join(hqRoot, companyPath), "company");
|
|
6639
|
-
const watcher = makeBatchWatcherStub();
|
|
6640
|
-
let shutdown = () => { };
|
|
6641
|
-
const commits = [];
|
|
6642
|
-
let submittedAt = 0;
|
|
6643
|
-
const runPass = vi.fn(async (argv) => {
|
|
6644
|
-
if (!argv.includes("--scope-path")) {
|
|
6645
|
-
readJournal(PERSONAL_VAULT_JOURNAL_SLUG);
|
|
6646
|
-
readJournal("indigo");
|
|
6647
|
-
}
|
|
6648
|
-
if (argv.includes("--scope-path") && argv.includes("push")) {
|
|
6649
|
-
const slug = argv.includes("--company") ? "indigo" : PERSONAL_VAULT_JOURNAL_SLUG;
|
|
6650
|
-
const key = slug === "indigo" ? companyKey : personalPath;
|
|
6651
|
-
const scoped = readJournalScoped(slug, [key]);
|
|
6652
|
-
scoped.files[key] = {
|
|
6653
|
-
...scoped.files[key],
|
|
6654
|
-
syncedAt: "2026-09-16T21:38:18.000Z",
|
|
6655
|
-
};
|
|
6656
|
-
writeJournal(slug, scoped);
|
|
6657
|
-
commits.push({ slug, elapsedMs: performance.now() - submittedAt });
|
|
6658
|
-
}
|
|
6659
|
-
return completedPassOutcome();
|
|
6660
|
-
});
|
|
6661
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--direction", "push", "--hq-root", hqRoot], {
|
|
6662
|
-
runPass,
|
|
6663
|
-
createWatcher: () => watcher,
|
|
6664
|
-
sleep: () => new Promise(() => { }),
|
|
6665
|
-
onShutdownSignal: (handler) => {
|
|
6666
|
-
shutdown = handler;
|
|
6667
|
-
return () => { };
|
|
6668
|
-
},
|
|
6669
|
-
});
|
|
6670
|
-
const emitAndWait = async (relativePaths) => {
|
|
6671
|
-
const before = commits.length;
|
|
6672
|
-
submittedAt = performance.now();
|
|
6673
|
-
const batch = {
|
|
6674
|
-
paths: new Map(relativePaths.map((relativePath) => [path.join(hqRoot, relativePath), relativePath])),
|
|
6675
|
-
changes: new Map(relativePaths.map((relativePath) => [
|
|
6676
|
-
path.join(hqRoot, relativePath),
|
|
6677
|
-
{ kind: "change" },
|
|
6678
|
-
])),
|
|
6679
|
-
};
|
|
6680
|
-
watcher.emit(relativePaths[0], batch);
|
|
6681
|
-
await vi.waitFor(() => expect(commits.length).toBe(before + relativePaths.length), {
|
|
6682
|
-
timeout: 30_000,
|
|
6683
|
-
interval: 10,
|
|
6684
|
-
});
|
|
6685
|
-
};
|
|
6686
|
-
try {
|
|
6687
|
-
await flushLoopMicrotasks(30);
|
|
6688
|
-
runPass.mockClear();
|
|
6689
|
-
resetStateStoreSnapshotRecoveryCountForTest();
|
|
6690
|
-
const eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
|
|
6691
|
-
eventLoopDelay.enable();
|
|
6692
|
-
await emitAndWait([personalPath, companyPath]);
|
|
6693
|
-
for (let round = 0; round < 3; round += 1) {
|
|
6694
|
-
await emitAndWait([personalPath]);
|
|
6695
|
-
await emitAndWait([companyPath]);
|
|
6696
|
-
}
|
|
6697
|
-
eventLoopDelay.disable();
|
|
6698
|
-
const recoveryCount = getStateStoreSnapshotRecoveryCountForTest();
|
|
6699
|
-
const maxDelayMs = Number(eventLoopDelay.max) / 1_000_000;
|
|
6700
|
-
const maxCommitMs = Math.max(...commits.map((commit) => commit.elapsedMs));
|
|
6701
|
-
console.info({ recoveryCount, maxDelayMs, maxCommitMs, commits: commits.length });
|
|
6702
|
-
expect.soft(recoveryCount).toBe(0);
|
|
6703
|
-
expect.soft(maxDelayMs).toBeLessThan(100);
|
|
6704
|
-
expect.soft(maxCommitMs).toBeLessThan(1_000);
|
|
6705
|
-
expect(commits.map((commit) => commit.slug)).toEqual([
|
|
6706
|
-
PERSONAL_VAULT_JOURNAL_SLUG,
|
|
6707
|
-
"indigo",
|
|
6708
|
-
PERSONAL_VAULT_JOURNAL_SLUG,
|
|
6709
|
-
"indigo",
|
|
6710
|
-
PERSONAL_VAULT_JOURNAL_SLUG,
|
|
6711
|
-
"indigo",
|
|
6712
|
-
PERSONAL_VAULT_JOURNAL_SLUG,
|
|
6713
|
-
"indigo",
|
|
6714
|
-
]);
|
|
6715
|
-
}
|
|
6716
|
-
finally {
|
|
6717
|
-
shutdown();
|
|
6718
|
-
await loop;
|
|
6719
|
-
if (previousCoordinator === undefined)
|
|
6720
|
-
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6721
|
-
else
|
|
6722
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6723
|
-
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6724
|
-
}
|
|
6725
|
-
}, 180_000);
|
|
6726
6317
|
it("fast lane: prefers declared receiver sizes and falls back to the journal", async () => {
|
|
6727
6318
|
const previous = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6728
6319
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
@@ -6898,19 +6489,19 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6898
6489
|
]),
|
|
6899
6490
|
});
|
|
6900
6491
|
await flushLoopMicrotasks(30);
|
|
6901
|
-
//
|
|
6902
|
-
//
|
|
6903
|
-
expect(calls.filter((argv) => argv.includes("--scope-path"))).toHaveLength(
|
|
6492
|
+
// origin/main failure: expected a scoped tiny path while the bulk pass is
|
|
6493
|
+
// held, but #408 kept all four paths in the slow lane.
|
|
6494
|
+
expect(calls.filter((argv) => argv.includes("--scope-path"))).toHaveLength(1);
|
|
6495
|
+
expect(calls.flat().join(" ")).toContain("realtime.md");
|
|
6904
6496
|
releaseBulk();
|
|
6905
6497
|
await flushLoopMicrotasks(30);
|
|
6906
6498
|
expect(calls.filter((argv) => argv.includes("--scope-path"))).toHaveLength(2);
|
|
6907
|
-
expect(calls.flat().join(" ")).toContain("realtime.md");
|
|
6908
6499
|
expect(calls.flat().join(" ")).toContain("session-0.log");
|
|
6909
6500
|
triggerShutdown();
|
|
6910
6501
|
await loop;
|
|
6911
6502
|
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6912
6503
|
});
|
|
6913
|
-
it("fast lane: a small receiver pull
|
|
6504
|
+
it("fast lane: a small receiver pull dispatches during a slow bulk pass", async () => {
|
|
6914
6505
|
const watcher = makeWatcherStub();
|
|
6915
6506
|
let triggerShutdown = () => { };
|
|
6916
6507
|
let receiverSync;
|
|
@@ -6955,7 +6546,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6955
6546
|
watcher.emit();
|
|
6956
6547
|
await flushLoopMicrotasks();
|
|
6957
6548
|
expect(order).toEqual(["bulk"]);
|
|
6958
|
-
|
|
6549
|
+
await receiverSync({
|
|
6959
6550
|
events: [{
|
|
6960
6551
|
kind: "upsert", relativePath: "companies/acme/realtime.md", contentHash: "sha256:x",
|
|
6961
6552
|
mtime: "2026-08-26T00:00:00.000Z", originDeviceId: "peer", originTenantId: "acme",
|
|
@@ -6963,11 +6554,8 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6963
6554
|
}],
|
|
6964
6555
|
signal: new AbortController().signal,
|
|
6965
6556
|
});
|
|
6966
|
-
await flushLoopMicrotasks(20);
|
|
6967
|
-
expect(order).toEqual(["bulk"]);
|
|
6968
|
-
releaseBulk();
|
|
6969
|
-
await receiverPull;
|
|
6970
6557
|
expect(order).toEqual(["bulk", "fast-pull"]);
|
|
6558
|
+
releaseBulk();
|
|
6971
6559
|
await flushLoopMicrotasks();
|
|
6972
6560
|
triggerShutdown();
|
|
6973
6561
|
await loop;
|
|
@@ -7011,14 +6599,12 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
7011
6599
|
await flushLoopMicrotasks();
|
|
7012
6600
|
watcher.emit();
|
|
7013
6601
|
await flushLoopMicrotasks();
|
|
7014
|
-
releaseBulk();
|
|
7015
|
-
// The full chore has no explicit safe checkpoint in this stub, so the
|
|
7016
|
-
// realtime pass begins only after the chore has released ownership.
|
|
7017
6602
|
watcher.emit(relativePath, { paths: new Map([[absolutePath, relativePath]]) });
|
|
7018
6603
|
await fastStarted;
|
|
6604
|
+
releaseBulk();
|
|
7019
6605
|
await flushLoopMicrotasks(20);
|
|
7020
|
-
// The
|
|
7021
|
-
//
|
|
6606
|
+
// The slow pass has finished, but its fast bypass still mutates. A second
|
|
6607
|
+
// sync/rescue must not acquire the root operation lock in this interval.
|
|
7022
6608
|
expect(fs.existsSync(lockPathFor(hqRoot))).toBe(true);
|
|
7023
6609
|
releaseFast();
|
|
7024
6610
|
await flushLoopMicrotasks(20);
|
|
@@ -7193,68 +6779,59 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
7193
6779
|
return () => { };
|
|
7194
6780
|
},
|
|
7195
6781
|
});
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
};
|
|
7232
|
-
}
|
|
7233
|
-
writeJournal(slug, journal);
|
|
6782
|
+
await flushLoopMicrotasks();
|
|
6783
|
+
watcher.emit();
|
|
6784
|
+
await flushLoopMicrotasks();
|
|
6785
|
+
runPass.mockClear();
|
|
6786
|
+
const events = [
|
|
6787
|
+
...Array.from({ length: 17 }, (_, index) => ({
|
|
6788
|
+
kind: "upsert",
|
|
6789
|
+
relativePath: `companies/acme/a-${index}.md`,
|
|
6790
|
+
contentHash: "sha256:x",
|
|
6791
|
+
mtime: "2026-08-26T00:00:00.000Z",
|
|
6792
|
+
originDeviceId: "peer",
|
|
6793
|
+
originTenantId: "acme",
|
|
6794
|
+
sequenceNumber: index,
|
|
6795
|
+
eventTimestamp: "2026-08-26T00:00:00.000Z",
|
|
6796
|
+
})),
|
|
6797
|
+
...Array.from({ length: 16 }, (_, index) => ({
|
|
6798
|
+
kind: "upsert",
|
|
6799
|
+
relativePath: `companies/beta/b-${index}.md`,
|
|
6800
|
+
contentHash: "sha256:x",
|
|
6801
|
+
mtime: "2026-08-26T00:00:00.000Z",
|
|
6802
|
+
originDeviceId: "peer",
|
|
6803
|
+
originTenantId: "beta",
|
|
6804
|
+
sequenceNumber: index + 17,
|
|
6805
|
+
eventTimestamp: "2026-08-26T00:00:00.000Z",
|
|
6806
|
+
})),
|
|
6807
|
+
];
|
|
6808
|
+
for (const [slug, prefix, count] of [["acme", "a", 17], ["beta", "b", 16]]) {
|
|
6809
|
+
const journal = readJournal(slug);
|
|
6810
|
+
for (let index = 0; index < count; index++) {
|
|
6811
|
+
journal.files[`${prefix}-${index}.md`] = {
|
|
6812
|
+
hash: "sha256:x",
|
|
6813
|
+
size: 16,
|
|
6814
|
+
syncedAt: "2026-08-26T00:00:00.000Z",
|
|
6815
|
+
direction: "down",
|
|
6816
|
+
};
|
|
7234
6817
|
}
|
|
7235
|
-
|
|
7236
|
-
events,
|
|
7237
|
-
signal: new AbortController().signal,
|
|
7238
|
-
});
|
|
7239
|
-
await flushLoopMicrotasks(20);
|
|
7240
|
-
// The running full chore has not yet yielded a durable hand-off, so no
|
|
7241
|
-
// receiver work may overlap it. Once it releases ownership, the
|
|
7242
|
-
// scheduler admits each route's bounded work before the residual slow
|
|
7243
|
-
// beta batch (acme fast, beta fast, then beta slow).
|
|
7244
|
-
expect(runPass).not.toHaveBeenCalled();
|
|
7245
|
-
releaseBulk();
|
|
7246
|
-
await receiverDrain;
|
|
7247
|
-
const scopedCalls = runPass.mock.calls.filter(([argv]) => argv.includes("--scope-path"));
|
|
7248
|
-
expect(scopedCalls).toHaveLength(3);
|
|
7249
|
-
expect(scopedCalls.flat().join(" ")).toContain("a-16.md");
|
|
7250
|
-
expect(scopedCalls.flat().join(" ")).toContain("b-14.md");
|
|
7251
|
-
}
|
|
7252
|
-
finally {
|
|
7253
|
-
releaseBulk();
|
|
7254
|
-
triggerShutdown();
|
|
7255
|
-
await loop;
|
|
7256
|
-
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6818
|
+
writeJournal(slug, journal);
|
|
7257
6819
|
}
|
|
6820
|
+
const receiverDrain = receiverSync({
|
|
6821
|
+
events,
|
|
6822
|
+
signal: new AbortController().signal,
|
|
6823
|
+
});
|
|
6824
|
+
await flushLoopMicrotasks(20);
|
|
6825
|
+
// The 33-event mixed delivery peels its first 32 bounded paths into the
|
|
6826
|
+
// fast lane (17 acme + 15 beta); the final beta event remains slow.
|
|
6827
|
+
expect(runPass).toHaveBeenCalledTimes(2);
|
|
6828
|
+
expect(runPass.mock.calls.flat().join(" ")).toContain("a-16.md");
|
|
6829
|
+
expect(runPass.mock.calls.flat().join(" ")).toContain("b-14.md");
|
|
6830
|
+
releaseBulk();
|
|
6831
|
+
await receiverDrain;
|
|
6832
|
+
triggerShutdown();
|
|
6833
|
+
await loop;
|
|
6834
|
+
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
7258
6835
|
});
|
|
7259
6836
|
it("fast lane: queues slow work behind a receiver pass that owns the root lock", async () => {
|
|
7260
6837
|
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-fast-lane-slow-queue-"));
|
|
@@ -7426,12 +7003,9 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
7426
7003
|
await flushLoopMicrotasks();
|
|
7427
7004
|
watcher.emit(paths[0][1], { paths: new Map(paths) });
|
|
7428
7005
|
await flushLoopMicrotasks(30);
|
|
7429
|
-
|
|
7430
|
-
// only journal writer. The scoped realtime pass is admitted immediately
|
|
7431
|
-
// after this safe hand-off, preserving both sets of rows.
|
|
7432
|
-
expect(Object.keys(readJournal("indigo").files)).toHaveLength(0);
|
|
7006
|
+
expect(Object.keys(readJournal("indigo").files)).toHaveLength(paths.length);
|
|
7433
7007
|
releaseBulk();
|
|
7434
|
-
await flushLoopMicrotasks(
|
|
7008
|
+
await flushLoopMicrotasks();
|
|
7435
7009
|
const journal = readJournal("indigo").files;
|
|
7436
7010
|
expect(Object.keys(journal)).toHaveLength(paths.length * 2);
|
|
7437
7011
|
for (let index = 0; index < paths.length; index++) {
|
|
@@ -7483,12 +7057,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
7483
7057
|
watcher.emit(relativePath, { paths: new Map([[absolutePath, relativePath]]) });
|
|
7484
7058
|
}
|
|
7485
7059
|
await flushLoopMicrotasks(60);
|
|
7486
|
-
|
|
7487
|
-
// The queued realtime batches run immediately after it completes.
|
|
7488
|
-
expect(completed).toEqual([]);
|
|
7060
|
+
expect(completed).toEqual(["fast", "fast", "fast", "fast", "fast"]);
|
|
7489
7061
|
releaseBulk();
|
|
7490
|
-
await flushLoopMicrotasks(
|
|
7491
|
-
expect(completed).
|
|
7062
|
+
await flushLoopMicrotasks();
|
|
7063
|
+
expect(completed).toContain("bulk");
|
|
7492
7064
|
triggerShutdown();
|
|
7493
7065
|
await loop;
|
|
7494
7066
|
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
@@ -7806,55 +7378,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
7806
7378
|
expect(code).not.toBe(TRANSIENT_NETWORK_EXIT);
|
|
7807
7379
|
expect(watcher.disposed).toBe(false);
|
|
7808
7380
|
});
|
|
7809
|
-
it("keeps the watcher alive for an unresolved company watch route (HQ-SYNC-COMPANY-ROUTE-UID)", async () => {
|
|
7810
|
-
const watcher = makeWatcherStub();
|
|
7811
|
-
const client = makeVaultStub({
|
|
7812
|
-
entityGet: () => Promise.reject(new VaultNotFoundError("company deleted")),
|
|
7813
|
-
});
|
|
7814
|
-
const findInMyNamespace = vi.fn().mockResolvedValue(null);
|
|
7815
|
-
client.entity.findInMyNamespace = findInMyNamespace;
|
|
7816
|
-
const routedPass = makeDeps({ createVaultClient: () => client });
|
|
7817
|
-
const routedArgv = buildRoutePullArgv({ kind: "company", slug: "cmp_ghost" }, ["--companies", "--watch", "--hq-root", "/tmp/hq"]);
|
|
7818
|
-
let attempts = 0;
|
|
7819
|
-
let routedExit;
|
|
7820
|
-
const runPass = vi.fn().mockImplementation(async () => {
|
|
7821
|
-
attempts += 1;
|
|
7822
|
-
if (attempts === 1) {
|
|
7823
|
-
routedExit = await runRunner(routedArgv, routedPass);
|
|
7824
|
-
return routedExit;
|
|
7825
|
-
}
|
|
7826
|
-
// Terminate the otherwise-open loop only after it proves the unresolved
|
|
7827
|
-
// route did not make the watcher exit.
|
|
7828
|
-
return 1;
|
|
7829
|
-
});
|
|
7830
|
-
const code = await runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
|
|
7831
|
-
runPass,
|
|
7832
|
-
clock: new FakeClock(),
|
|
7833
|
-
createWatcher: () => watcher,
|
|
7834
|
-
sleep: () => Promise.resolve(),
|
|
7835
|
-
onShutdownSignal: () => () => { },
|
|
7836
|
-
});
|
|
7837
|
-
expect(routedArgv).toEqual([
|
|
7838
|
-
"--company",
|
|
7839
|
-
"cmp_ghost",
|
|
7840
|
-
"--direction",
|
|
7841
|
-
"pull",
|
|
7842
|
-
"--hq-root",
|
|
7843
|
-
"/tmp/hq",
|
|
7844
|
-
]);
|
|
7845
|
-
expect(routedExit).toBe(UNRESOLVED_COMPANY_EXIT);
|
|
7846
|
-
expect(runPass).toHaveBeenCalledTimes(2);
|
|
7847
|
-
expect(code).toBe(1);
|
|
7848
|
-
expect(code).not.toBe(UNRESOLVED_COMPANY_EXIT);
|
|
7849
|
-
expect(watcher.disposed).toBe(false);
|
|
7850
|
-
expect(findInMyNamespace).toHaveBeenCalledWith("company", "cmp_ghost");
|
|
7851
|
-
expect(routedPass.stderr.events()).toContainEqual({
|
|
7852
|
-
type: "error",
|
|
7853
|
-
company: "cmp_ghost",
|
|
7854
|
-
path: "(company-resolution)",
|
|
7855
|
-
message: "company entity lookup returned 404",
|
|
7856
|
-
});
|
|
7857
|
-
});
|
|
7858
7381
|
it("keeps the watch loop alive when a company leg returns transient exit 75 (HQ-SYNC-X)", async () => {
|
|
7859
7382
|
const watcher = makeWatcherStub();
|
|
7860
7383
|
const dnsError = Object.assign(new Error("getaddrinfo ENOTFOUND vault"), {
|
|
@@ -8148,85 +7671,6 @@ describe("runRunnerWithLoop — watch-mode auth-wait", () => {
|
|
|
8148
7671
|
});
|
|
8149
7672
|
});
|
|
8150
7673
|
describe("runRunnerWithLoop — U58 realtime scheduler guard", () => {
|
|
8151
|
-
it("hands a wake realtime drain to the guard before a long-running full chore completes", async () => {
|
|
8152
|
-
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
8153
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
8154
|
-
const watcher = makeWatcherStub();
|
|
8155
|
-
let triggerShutdown = () => { };
|
|
8156
|
-
let releaseCheckpoint = () => { };
|
|
8157
|
-
const checkpointGate = new Promise((resolve) => { releaseCheckpoint = resolve; });
|
|
8158
|
-
let releaseRealtime = () => { };
|
|
8159
|
-
const realtimeGate = new Promise((resolve) => { releaseRealtime = resolve; });
|
|
8160
|
-
const order = [];
|
|
8161
|
-
let passes = 0;
|
|
8162
|
-
let runRealtime = null;
|
|
8163
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
|
|
8164
|
-
runPass: vi.fn().mockImplementation(async (_argv, checkpoint) => {
|
|
8165
|
-
passes += 1;
|
|
8166
|
-
if (passes === 2) {
|
|
8167
|
-
order.push("chore");
|
|
8168
|
-
// The fake pass has completed its current durable unit and is now
|
|
8169
|
-
// at the same explicit hand-off seam production uses between
|
|
8170
|
-
// fully-settled fanout targets.
|
|
8171
|
-
await checkpointGate;
|
|
8172
|
-
await checkpoint?.();
|
|
8173
|
-
order.push("chore-complete");
|
|
8174
|
-
}
|
|
8175
|
-
return completedPassOutcome();
|
|
8176
|
-
}),
|
|
8177
|
-
runPassSupportsCooperativeCheckpoint: true,
|
|
8178
|
-
clock: new FakeClock(),
|
|
8179
|
-
createWatcher: () => watcher,
|
|
8180
|
-
sleep: makeSteppableSleep().sleep,
|
|
8181
|
-
onShutdownSignal: (handler) => {
|
|
8182
|
-
triggerShutdown = handler;
|
|
8183
|
-
return () => { };
|
|
8184
|
-
},
|
|
8185
|
-
startRealtimeScheduler: async (opts) => {
|
|
8186
|
-
// This is the same wake path used by the realtime scheduler: it
|
|
8187
|
-
// enters runGuardedTask behind the coordinator worker.
|
|
8188
|
-
runRealtime = () => opts.runGuarded(async () => {
|
|
8189
|
-
order.push("realtime");
|
|
8190
|
-
await realtimeGate;
|
|
8191
|
-
order.push("realtime-complete");
|
|
8192
|
-
});
|
|
8193
|
-
return {
|
|
8194
|
-
signal: () => undefined,
|
|
8195
|
-
checkHighWater: async () => undefined,
|
|
8196
|
-
dispose: async () => undefined,
|
|
8197
|
-
};
|
|
8198
|
-
},
|
|
8199
|
-
});
|
|
8200
|
-
try {
|
|
8201
|
-
await flushLoopMicrotasks(30);
|
|
8202
|
-
watcher.emit();
|
|
8203
|
-
await flushLoopMicrotasks(20);
|
|
8204
|
-
expect(order).toEqual(["chore"]);
|
|
8205
|
-
const realtime = runRealtime();
|
|
8206
|
-
releaseCheckpoint();
|
|
8207
|
-
await flushLoopMicrotasks(30);
|
|
8208
|
-
expect(order).toEqual(["chore", "realtime"]);
|
|
8209
|
-
releaseRealtime();
|
|
8210
|
-
await realtime;
|
|
8211
|
-
await flushLoopMicrotasks(20);
|
|
8212
|
-
expect(order).toEqual([
|
|
8213
|
-
"chore",
|
|
8214
|
-
"realtime",
|
|
8215
|
-
"realtime-complete",
|
|
8216
|
-
"chore-complete",
|
|
8217
|
-
]);
|
|
8218
|
-
}
|
|
8219
|
-
finally {
|
|
8220
|
-
releaseCheckpoint();
|
|
8221
|
-
releaseRealtime();
|
|
8222
|
-
triggerShutdown();
|
|
8223
|
-
await loop;
|
|
8224
|
-
if (previousCoordinator === undefined)
|
|
8225
|
-
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
8226
|
-
else
|
|
8227
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
8228
|
-
}
|
|
8229
|
-
});
|
|
8230
7674
|
it("feeds a watcher-originated V2 drain through the same single-flight guard as the poll", async () => {
|
|
8231
7675
|
const watcher = makeWatcherStub();
|
|
8232
7676
|
let triggerShutdown = () => { };
|
|
@@ -8339,173 +7783,6 @@ describe("runRunnerWithLoop — U58 realtime scheduler guard", () => {
|
|
|
8339
7783
|
await loop;
|
|
8340
7784
|
});
|
|
8341
7785
|
});
|
|
8342
|
-
describe("CooperativePassScheduler", () => {
|
|
8343
|
-
it("admits an explicitly safe fast realtime pass while a slow scoped realtime pass remains in flight", async () => {
|
|
8344
|
-
const scheduler = new CooperativePassScheduler(() => 0);
|
|
8345
|
-
const order = [];
|
|
8346
|
-
let releaseSlow = () => { };
|
|
8347
|
-
const slowGate = new Promise((resolve) => { releaseSlow = resolve; });
|
|
8348
|
-
let markSlowStarted = () => { };
|
|
8349
|
-
const slowStarted = new Promise((resolve) => { markSlowStarted = resolve; });
|
|
8350
|
-
const slow = scheduler.submit(async () => {
|
|
8351
|
-
order.push("slow-start");
|
|
8352
|
-
markSlowStarted();
|
|
8353
|
-
await slowGate;
|
|
8354
|
-
order.push("slow-complete");
|
|
8355
|
-
return 0;
|
|
8356
|
-
}, "realtime", "slow");
|
|
8357
|
-
await slowStarted;
|
|
8358
|
-
const fast = scheduler.submit(async () => {
|
|
8359
|
-
order.push("fast");
|
|
8360
|
-
return 0;
|
|
8361
|
-
}, "realtime", "fast", true);
|
|
8362
|
-
try {
|
|
8363
|
-
await Promise.resolve();
|
|
8364
|
-
await Promise.resolve();
|
|
8365
|
-
expect([...order]).toEqual(["slow-start", "fast"]);
|
|
8366
|
-
}
|
|
8367
|
-
finally {
|
|
8368
|
-
releaseSlow();
|
|
8369
|
-
await Promise.all([slow, fast]);
|
|
8370
|
-
}
|
|
8371
|
-
});
|
|
8372
|
-
it("preserves journal order and resumes full work across repeated randomized hand-offs", async () => {
|
|
8373
|
-
// These deterministic seeds deliberately vary the number and enqueue
|
|
8374
|
-
// ordering of realtime tasks. Every append asserts one durable-state owner
|
|
8375
|
-
// at a time; the full continuation must resume after every realtime burst.
|
|
8376
|
-
for (let seed = 1; seed <= 32; seed += 1) {
|
|
8377
|
-
let now = 0;
|
|
8378
|
-
const scheduler = new CooperativePassScheduler(() => now);
|
|
8379
|
-
const journal = [];
|
|
8380
|
-
const expected = new Set();
|
|
8381
|
-
let writer = null;
|
|
8382
|
-
let maximumWriters = 0;
|
|
8383
|
-
const append = async (entry) => {
|
|
8384
|
-
expect(writer).toBeNull();
|
|
8385
|
-
writer = entry;
|
|
8386
|
-
maximumWriters = Math.max(maximumWriters, 1);
|
|
8387
|
-
// A journal append crosses an async durable-write boundary. If the
|
|
8388
|
-
// scheduler admitted another pass here, its ownership assertion would
|
|
8389
|
-
// fail rather than merely observing JavaScript's synchronous turn.
|
|
8390
|
-
await Promise.resolve();
|
|
8391
|
-
expect(writer).toBe(entry);
|
|
8392
|
-
journal.push(entry);
|
|
8393
|
-
writer = null;
|
|
8394
|
-
};
|
|
8395
|
-
let releaseCheckpoint = () => { };
|
|
8396
|
-
const checkpointReady = new Promise((resolve) => { releaseCheckpoint = resolve; });
|
|
8397
|
-
const chore = scheduler.submit(async ({ checkpoint }) => {
|
|
8398
|
-
expected.add(`chore-${seed}-before`);
|
|
8399
|
-
await append(`chore-${seed}-before`);
|
|
8400
|
-
await checkpointReady;
|
|
8401
|
-
await checkpoint();
|
|
8402
|
-
expected.add(`chore-${seed}-after`);
|
|
8403
|
-
await append(`chore-${seed}-after`);
|
|
8404
|
-
return 0;
|
|
8405
|
-
}, "chore");
|
|
8406
|
-
await Promise.resolve();
|
|
8407
|
-
const realtimeCount = (seed % 7) + 1;
|
|
8408
|
-
const shuffledIndexes = Array.from({ length: realtimeCount }, (_, index) => index);
|
|
8409
|
-
let randomState = seed;
|
|
8410
|
-
for (let index = shuffledIndexes.length - 1; index > 0; index -= 1) {
|
|
8411
|
-
randomState = (randomState * 1_664_525 + 1_013_904_223) >>> 0;
|
|
8412
|
-
const swapIndex = randomState % (index + 1);
|
|
8413
|
-
[shuffledIndexes[index], shuffledIndexes[swapIndex]] = [
|
|
8414
|
-
shuffledIndexes[swapIndex],
|
|
8415
|
-
shuffledIndexes[index],
|
|
8416
|
-
];
|
|
8417
|
-
}
|
|
8418
|
-
const realtime = shuffledIndexes.map((index) => {
|
|
8419
|
-
const entry = `realtime-${seed}-${(index * 17 + seed) % realtimeCount}`;
|
|
8420
|
-
expected.add(entry);
|
|
8421
|
-
return scheduler.submit(async () => {
|
|
8422
|
-
// Shuffle the microtask timing without ever allowing a second writer.
|
|
8423
|
-
if ((seed + index) % 3 === 0)
|
|
8424
|
-
await Promise.resolve();
|
|
8425
|
-
await append(entry);
|
|
8426
|
-
now += 1;
|
|
8427
|
-
return 0;
|
|
8428
|
-
}, "realtime");
|
|
8429
|
-
});
|
|
8430
|
-
releaseCheckpoint();
|
|
8431
|
-
await Promise.all([chore, ...realtime]);
|
|
8432
|
-
expect(maximumWriters).toBe(1);
|
|
8433
|
-
expect(new Set(journal)).toEqual(expected);
|
|
8434
|
-
expect(journal).toHaveLength(expected.size);
|
|
8435
|
-
expect(journal[0]).toBe(`chore-${seed}-before`);
|
|
8436
|
-
expect(journal.at(-1)).toBe(`chore-${seed}-after`);
|
|
8437
|
-
}
|
|
8438
|
-
});
|
|
8439
|
-
it("lets realtime win at 15 minutes minus one millisecond, then gives the chore the exact-boundary admission", async () => {
|
|
8440
|
-
const runCase = async (elapsedMs) => {
|
|
8441
|
-
let now = 0;
|
|
8442
|
-
const scheduler = new CooperativePassScheduler(() => now);
|
|
8443
|
-
const order = [];
|
|
8444
|
-
let releaseActive = () => { };
|
|
8445
|
-
const activeGate = new Promise((resolve) => { releaseActive = resolve; });
|
|
8446
|
-
const activeRealtime = scheduler.submit(async () => {
|
|
8447
|
-
order.push("active-realtime");
|
|
8448
|
-
await activeGate;
|
|
8449
|
-
return 0;
|
|
8450
|
-
}, "realtime");
|
|
8451
|
-
await Promise.resolve();
|
|
8452
|
-
const chore = scheduler.submit(async () => {
|
|
8453
|
-
order.push("chore");
|
|
8454
|
-
return 0;
|
|
8455
|
-
}, "chore");
|
|
8456
|
-
const queuedRealtime = scheduler.submit(async () => {
|
|
8457
|
-
order.push("queued-realtime");
|
|
8458
|
-
return 0;
|
|
8459
|
-
}, "realtime");
|
|
8460
|
-
now = elapsedMs;
|
|
8461
|
-
releaseActive();
|
|
8462
|
-
await Promise.all([activeRealtime, chore, queuedRealtime]);
|
|
8463
|
-
return order;
|
|
8464
|
-
};
|
|
8465
|
-
await expect(runCase(CHORE_STARVATION_CAP_MS - 1)).resolves.toEqual([
|
|
8466
|
-
"active-realtime",
|
|
8467
|
-
"queued-realtime",
|
|
8468
|
-
"chore",
|
|
8469
|
-
]);
|
|
8470
|
-
await expect(runCase(CHORE_STARVATION_CAP_MS)).resolves.toEqual([
|
|
8471
|
-
"active-realtime",
|
|
8472
|
-
"chore",
|
|
8473
|
-
"queued-realtime",
|
|
8474
|
-
]);
|
|
8475
|
-
});
|
|
8476
|
-
it("resumes a handed-off chore when a continuous realtime burst reaches the 15-minute cap", async () => {
|
|
8477
|
-
let now = 0;
|
|
8478
|
-
const scheduler = new CooperativePassScheduler(() => now);
|
|
8479
|
-
const order = [];
|
|
8480
|
-
let releaseCheckpoint = () => { };
|
|
8481
|
-
const checkpointReady = new Promise((resolve) => { releaseCheckpoint = resolve; });
|
|
8482
|
-
const chore = scheduler.submit(async ({ checkpoint }) => {
|
|
8483
|
-
order.push("chore-before");
|
|
8484
|
-
await checkpointReady;
|
|
8485
|
-
await checkpoint();
|
|
8486
|
-
order.push("chore-after");
|
|
8487
|
-
return 0;
|
|
8488
|
-
}, "chore");
|
|
8489
|
-
await Promise.resolve();
|
|
8490
|
-
const firstRealtime = scheduler.submit(async () => {
|
|
8491
|
-
order.push("realtime-before-cap");
|
|
8492
|
-
now = CHORE_STARVATION_CAP_MS;
|
|
8493
|
-
return 0;
|
|
8494
|
-
}, "realtime");
|
|
8495
|
-
const laterRealtime = scheduler.submit(async () => {
|
|
8496
|
-
order.push("realtime-after-cap");
|
|
8497
|
-
return 0;
|
|
8498
|
-
}, "realtime");
|
|
8499
|
-
releaseCheckpoint();
|
|
8500
|
-
await Promise.all([chore, firstRealtime, laterRealtime]);
|
|
8501
|
-
expect(order).toEqual([
|
|
8502
|
-
"chore-before",
|
|
8503
|
-
"realtime-before-cap",
|
|
8504
|
-
"chore-after",
|
|
8505
|
-
"realtime-after-cap",
|
|
8506
|
-
]);
|
|
8507
|
-
});
|
|
8508
|
-
});
|
|
8509
7786
|
describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
|
|
8510
7787
|
const watchArgv = [
|
|
8511
7788
|
"--companies",
|