@indigoai-us/hq-cloud 6.16.87-alpha.0 → 6.16.89-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.d.ts +2 -0
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +8 -2
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.d.ts +26 -25
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +251 -183
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +22 -2
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +5 -3
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +74 -509
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts +18 -6
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +108 -97
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +4 -177
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync-scope.test.js +0 -34
- package/dist/cli/sync-scope.test.js.map +1 -1
- package/dist/cli/sync.d.ts +17 -4
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +138 -20
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +230 -1
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/lib/machine-id.d.ts +0 -7
- package/dist/lib/machine-id.d.ts.map +1 -1
- package/dist/lib/machine-id.js +7 -54
- package/dist/lib/machine-id.js.map +1 -1
- package/dist/lib/machine-id.test.js +1 -20
- package/dist/lib/machine-id.test.js.map +1 -1
- package/dist/object-io.d.ts +21 -9
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +133 -93
- package/dist/object-io.js.map +1 -1
- package/dist/object-io.test.js +140 -108
- package/dist/object-io.test.js.map +1 -1
- package/dist/prefix-coalesce.d.ts +30 -37
- package/dist/prefix-coalesce.d.ts.map +1 -1
- package/dist/prefix-coalesce.js +16 -104
- package/dist/prefix-coalesce.js.map +1 -1
- package/dist/prefix-coalesce.test.js +3 -34
- package/dist/prefix-coalesce.test.js.map +1 -1
- package/dist/remote-pull.d.ts.map +1 -1
- package/dist/remote-pull.js +8 -15
- package/dist/remote-pull.js.map +1 -1
- package/dist/remote-pull.test.js +4 -44
- package/dist/remote-pull.test.js.map +1 -1
- package/dist/s3.d.ts +8 -3
- package/dist/s3.d.ts.map +1 -1
- package/dist/s3.js +30 -7
- package/dist/s3.js.map +1 -1
- package/dist/scope-shrink.d.ts.map +1 -1
- package/dist/scope-shrink.js +1 -7
- package/dist/scope-shrink.js.map +1 -1
- package/dist/sync/event-sync.d.ts +5 -19
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +14 -150
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/event-sync.test.js +2 -386
- package/dist/sync/event-sync.test.js.map +1 -1
- package/dist/sync/inbound-event-admission.d.ts.map +1 -1
- package/dist/sync/inbound-event-admission.js +3 -0
- package/dist/sync/inbound-event-admission.js.map +1 -1
- package/dist/sync/inbound-event-admission.test.js +6 -0
- package/dist/sync/inbound-event-admission.test.js.map +1 -1
- package/dist/sync/parallel-sync-coordinator.d.ts +0 -1
- package/dist/sync/parallel-sync-coordinator.d.ts.map +1 -1
- package/dist/sync/parallel-sync-coordinator.js +8 -39
- package/dist/sync/parallel-sync-coordinator.js.map +1 -1
- package/dist/sync/parallel-sync-coordinator.test.js +1 -33
- package/dist/sync/parallel-sync-coordinator.test.js.map +1 -1
- package/dist/sync/pull-scope.d.ts +0 -2
- package/dist/sync/pull-scope.d.ts.map +1 -1
- package/dist/sync/pull-scope.js +5 -15
- package/dist/sync/pull-scope.js.map +1 -1
- package/dist/sync/push-receiver.d.ts +1 -22
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +20 -114
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +24 -398
- package/dist/sync/push-receiver.test.js.map +1 -1
- package/dist/sync/push-transport.d.ts +0 -15
- package/dist/sync/push-transport.d.ts.map +1 -1
- package/dist/sync/push-transport.js +0 -27
- package/dist/sync/push-transport.js.map +1 -1
- package/dist/sync/push-transport.test.js +1 -14
- package/dist/sync/push-transport.test.js.map +1 -1
- package/dist/sync/sync-work.d.ts +0 -5
- package/dist/sync/sync-work.d.ts.map +1 -1
- package/dist/sync/sync-work.js.map +1 -1
- package/dist/sync-core.d.ts +2 -1
- package/dist/sync-core.d.ts.map +1 -1
- package/dist/sync-core.js +5 -10
- package/dist/sync-core.js.map +1 -1
- package/dist/sync-core.test.js +16 -0
- package/dist/sync-core.test.js.map +1 -1
- package/dist/watcher.d.ts +0 -4
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +4 -16
- package/dist/watcher.js.map +1 -1
- package/dist/watcher.test.js +3 -50
- package/dist/watcher.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
|
16
16
|
import { runRunner, runRunnerWithLoop, resolveDeletePolicy, resolveSkipPersonal, resolveSkipCompanies, selectObjectIOFactory, routeChangeToTarget, buildTargetedPushArgv, resolvePullScope, readPinnedPrefixes, SESSIONS_SCOPE_PREFIX, defaultCollectTelemetry, AUTH_REQUIRED_PASS_EXIT, } from "./sync-runner.js";
|
|
17
17
|
import { SESSION_LOGS_PUSH_ONLY_PREFIX } from "../sync/pull-scope.js";
|
|
18
18
|
import { AUTH_WAIT_INITIAL_RECHECK_MS, AUTH_WAIT_RESUME_MESSAGE, AUTH_WAIT_START_MESSAGE, AUTH_WAIT_STEADY_RECHECK_MS, } from "./sync-runner-auth-wait.js";
|
|
19
|
-
import {
|
|
19
|
+
import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
|
|
20
20
|
import { setBandwidthGovernorForTesting } from "../bandwidth.js";
|
|
21
21
|
import { POST_SYNC_FLAG_KEYS, } from "./sync-runner-post-sync-flags.js";
|
|
22
22
|
import { FakeClock, TreeWatcher, } from "../watcher.js";
|
|
@@ -32,7 +32,7 @@ import { lockPathFor, OPERATION_LOCKED_EXIT } from "../operation-lock.js";
|
|
|
32
32
|
import { TRANSIENT_NETWORK_EXIT } from "../lib/net-errors.js";
|
|
33
33
|
import { getStateStoreSnapshotRecoveryCountForTest, resetStateStoreSnapshotRecoveryCountForTest, StateStoreLockError, } from "../sync/state-store.js";
|
|
34
34
|
import { PARTIAL_SYNC_EXIT, UNRESOLVED_COMPANY_EXIT, } from "../lib/exit-codes.js";
|
|
35
|
-
import { isCoveredByAny
|
|
35
|
+
import { isCoveredByAny } from "../prefix-coalesce.js";
|
|
36
36
|
import { VaultAuthError, VaultNotFoundError } from "../vault-client.js";
|
|
37
37
|
import { buildRoutePullArgv } from "./sync-runner-watch-routes.js";
|
|
38
38
|
import { CognitoAuthError, CognitoRefreshError } from "../cognito-auth.js";
|
|
@@ -565,79 +565,6 @@ describe("mid-pass identity refusal", () => {
|
|
|
565
565
|
expect(deps.stderr.events().some((e) => e.type === "auth-error")).toBe(false);
|
|
566
566
|
});
|
|
567
567
|
});
|
|
568
|
-
describe("remote failure contract", () => {
|
|
569
|
-
const person = {
|
|
570
|
-
uid: "ent_person_remote_failure_contract",
|
|
571
|
-
type: "person",
|
|
572
|
-
bucketName: "hq-vault-personal-contract",
|
|
573
|
-
status: "active",
|
|
574
|
-
};
|
|
575
|
-
it.each([
|
|
576
|
-
[
|
|
577
|
-
"terminal 403 refusal",
|
|
578
|
-
() => new CognitoRefreshError("session reauth required (403)", true, 403),
|
|
579
|
-
0,
|
|
580
|
-
"auth-error",
|
|
581
|
-
"quick refresh",
|
|
582
|
-
],
|
|
583
|
-
[
|
|
584
|
-
"404 route",
|
|
585
|
-
() => new VaultNotFoundError("remote route no longer exists (404)"),
|
|
586
|
-
PARTIAL_SYNC_EXIT,
|
|
587
|
-
"error",
|
|
588
|
-
"404",
|
|
589
|
-
],
|
|
590
|
-
[
|
|
591
|
-
"429 throttle",
|
|
592
|
-
() => Object.assign(new Error("remote throttled (429)"), { statusCode: 429 }),
|
|
593
|
-
TRANSIENT_NETWORK_EXIT,
|
|
594
|
-
"transient-network",
|
|
595
|
-
"429",
|
|
596
|
-
],
|
|
597
|
-
[
|
|
598
|
-
"503 throttle",
|
|
599
|
-
() => Object.assign(new Error("remote unavailable (503)"), { statusCode: 503 }),
|
|
600
|
-
TRANSIENT_NETWORK_EXIT,
|
|
601
|
-
"transient-network",
|
|
602
|
-
"503",
|
|
603
|
-
],
|
|
604
|
-
[
|
|
605
|
-
"Object Lock checksum refusal",
|
|
606
|
-
() => new ObjectLockChecksumRequiredError("remote.md", "checksum required"),
|
|
607
|
-
PARTIAL_SYNC_EXIT,
|
|
608
|
-
"error",
|
|
609
|
-
"ObjectLockChecksumRequired",
|
|
610
|
-
],
|
|
611
|
-
[
|
|
612
|
-
"timeout",
|
|
613
|
-
() => Object.assign(new Error("remote timed out"), { name: "TimeoutError" }),
|
|
614
|
-
TRANSIENT_NETWORK_EXIT,
|
|
615
|
-
"transient-network",
|
|
616
|
-
"timed out",
|
|
617
|
-
],
|
|
618
|
-
[
|
|
619
|
-
"abort",
|
|
620
|
-
() => Object.assign(new Error("remote aborted"), { name: "AbortError" }),
|
|
621
|
-
TRANSIENT_NETWORK_EXIT,
|
|
622
|
-
"transient-network",
|
|
623
|
-
"aborted",
|
|
624
|
-
],
|
|
625
|
-
])("keeps the journal stable and records the runner outcome for %s", async (_description, makeFailure, expectedExit, telemetryType, telemetryReason) => {
|
|
626
|
-
const before = readJournal(PERSONAL_VAULT_JOURNAL_SLUG);
|
|
627
|
-
const deps = makeDeps({
|
|
628
|
-
sync: vi.fn().mockRejectedValue(makeFailure()),
|
|
629
|
-
createVaultClient: () => makeVaultStub({ listPersons: () => Promise.resolve([person]) }),
|
|
630
|
-
});
|
|
631
|
-
expect(await runRunner(["--personal"], deps)).toBe(expectedExit);
|
|
632
|
-
expect(readJournal(PERSONAL_VAULT_JOURNAL_SLUG).files).toEqual(before.files);
|
|
633
|
-
const events = [...deps.stdout.events(), ...deps.stderr.events()];
|
|
634
|
-
expect(events.some((event) => event.type === telemetryType)).toBe(true);
|
|
635
|
-
expect(`${deps.stdout.raw()}${deps.stderr.raw()}`).toContain(telemetryReason);
|
|
636
|
-
if (telemetryType === "transient-network") {
|
|
637
|
-
expect(events.some((event) => event.type === "error")).toBe(false);
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
});
|
|
641
568
|
// ---------------------------------------------------------------------------
|
|
642
569
|
// memberships retry (3x with backoff, then abort)
|
|
643
570
|
// ---------------------------------------------------------------------------
|
|
@@ -3727,8 +3654,8 @@ describe("--direction", () => {
|
|
|
3727
3654
|
isDefault: false,
|
|
3728
3655
|
}),
|
|
3729
3656
|
listMyExplicitGrants: async () => [
|
|
3730
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
3731
|
-
{ companyUid: "cmp_a", path: "policies
|
|
3657
|
+
{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" },
|
|
3658
|
+
{ companyUid: "cmp_a", path: "policies/", permission: "read", source: "group" },
|
|
3732
3659
|
],
|
|
3733
3660
|
};
|
|
3734
3661
|
const deps = makeDeps({
|
|
@@ -3753,7 +3680,7 @@ describe("--direction", () => {
|
|
|
3753
3680
|
isDefault: false,
|
|
3754
3681
|
}),
|
|
3755
3682
|
listMyExplicitGrants: async () => [
|
|
3756
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
3683
|
+
{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" },
|
|
3757
3684
|
],
|
|
3758
3685
|
};
|
|
3759
3686
|
const deps = makeDeps({
|
|
@@ -3789,7 +3716,7 @@ describe("--direction", () => {
|
|
|
3789
3716
|
isDefault: false,
|
|
3790
3717
|
}),
|
|
3791
3718
|
listMyExplicitGrants: async () => [
|
|
3792
|
-
{ companyUid: "cmp_a", path: "policies
|
|
3719
|
+
{ companyUid: "cmp_a", path: "policies/", permission: "read", source: "person" },
|
|
3793
3720
|
],
|
|
3794
3721
|
};
|
|
3795
3722
|
const deps = makeDeps({
|
|
@@ -5087,60 +5014,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
5087
5014
|
process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
|
|
5088
5015
|
}
|
|
5089
5016
|
});
|
|
5090
|
-
it("backs off failed parallel full-reconcile completions before another chore is admitted", async () => {
|
|
5091
|
-
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5092
|
-
const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
|
|
5093
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
5094
|
-
process.env.HQ_SYNC_FULL_RECONCILE_MS = "1";
|
|
5095
|
-
const runPass = vi.fn().mockResolvedValue(1);
|
|
5096
|
-
const delays = [];
|
|
5097
|
-
const waiters = [];
|
|
5098
|
-
let now = 0;
|
|
5099
|
-
let shutdown = () => { };
|
|
5100
|
-
const sleep = (ms) => {
|
|
5101
|
-
delays.push(ms);
|
|
5102
|
-
return new Promise((resolve) => {
|
|
5103
|
-
waiters.push(resolve);
|
|
5104
|
-
});
|
|
5105
|
-
};
|
|
5106
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--poll-remote-ms", "1", "--hq-root", "/tmp/hq"], {
|
|
5107
|
-
runPass,
|
|
5108
|
-
clock: new FakeClock(),
|
|
5109
|
-
monotonicNow: () => now,
|
|
5110
|
-
sleep,
|
|
5111
|
-
onShutdownSignal: (handler) => {
|
|
5112
|
-
shutdown = handler;
|
|
5113
|
-
return () => { };
|
|
5114
|
-
},
|
|
5115
|
-
});
|
|
5116
|
-
try {
|
|
5117
|
-
for (let attempt = 0; attempt < 50 && runPass.mock.calls.length < 3; attempt += 1) {
|
|
5118
|
-
const resolve = waiters.shift();
|
|
5119
|
-
if (resolve) {
|
|
5120
|
-
now += 1;
|
|
5121
|
-
resolve();
|
|
5122
|
-
await flushLoopMicrotasks(30);
|
|
5123
|
-
}
|
|
5124
|
-
else {
|
|
5125
|
-
await new Promise((resolveNext) => setImmediate(resolveNext));
|
|
5126
|
-
}
|
|
5127
|
-
}
|
|
5128
|
-
expect(runPass).toHaveBeenCalledTimes(3);
|
|
5129
|
-
expect(delays).toContain(60_000);
|
|
5130
|
-
}
|
|
5131
|
-
finally {
|
|
5132
|
-
shutdown();
|
|
5133
|
-
await expect(loop).resolves.toBe(0);
|
|
5134
|
-
if (previousCoordinator === undefined)
|
|
5135
|
-
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5136
|
-
else
|
|
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;
|
|
5142
|
-
}
|
|
5143
|
-
});
|
|
5144
5017
|
it("parallel coordinator keeps event surfaces off for an auth-required full reconcile", async () => {
|
|
5145
5018
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
5146
5019
|
const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
|
|
@@ -6225,7 +6098,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6225
6098
|
}],
|
|
6226
6099
|
signal: new AbortController().signal,
|
|
6227
6100
|
});
|
|
6228
|
-
const firstReplacementFailure = expect(firstReplacement).rejects.toThrow("targeted pull failed");
|
|
6229
6101
|
await flushLoopMicrotasks(30); // queues the warm-up pull behind held work
|
|
6230
6102
|
const secondReplacement = receiverSync({
|
|
6231
6103
|
events: [{
|
|
@@ -6240,32 +6112,18 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6240
6112
|
}],
|
|
6241
6113
|
signal: new AbortController().signal,
|
|
6242
6114
|
});
|
|
6243
|
-
|
|
6244
|
-
await firstReplacementFailure;
|
|
6115
|
+
await firstReplacement;
|
|
6245
6116
|
await flushLoopMicrotasks(30);
|
|
6246
|
-
//
|
|
6247
|
-
//
|
|
6248
|
-
//
|
|
6117
|
+
// Both warm-up passes were superseded while queued behind held realtime
|
|
6118
|
+
// work, so the coordinator never dispatched their executor. They remain
|
|
6119
|
+
// terminal no-ops rather than fabricated exit-1 runner failures.
|
|
6249
6120
|
expect(runPass.mock.calls.filter(([argv]) => argv.includes("warmup-superseded.md"))).toHaveLength(0);
|
|
6250
6121
|
expect(settled).toBeUndefined();
|
|
6251
6122
|
await Promise.resolve();
|
|
6252
6123
|
expect(settled).toBeUndefined();
|
|
6253
6124
|
releaseHeld();
|
|
6254
6125
|
await heldReceiverWork;
|
|
6255
|
-
await
|
|
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
|
-
});
|
|
6126
|
+
await secondReplacement;
|
|
6269
6127
|
}
|
|
6270
6128
|
finally {
|
|
6271
6129
|
releaseHeld();
|
|
@@ -6277,7 +6135,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6277
6135
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6278
6136
|
}
|
|
6279
6137
|
});
|
|
6280
|
-
it("
|
|
6138
|
+
it("acknowledges superseded receiver work and records refused telemetry", async () => {
|
|
6281
6139
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6282
6140
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6283
6141
|
const watcher = makeBatchWatcherStub();
|
|
@@ -6304,14 +6162,14 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6304
6162
|
},
|
|
6305
6163
|
});
|
|
6306
6164
|
const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
|
6307
|
-
const event = (relativePath
|
|
6165
|
+
const event = (relativePath) => ({
|
|
6308
6166
|
kind: "upsert",
|
|
6309
6167
|
relativePath,
|
|
6310
6168
|
contentHash: "sha256:remote",
|
|
6311
6169
|
mtime: "2026-08-28T01:22:30.000Z",
|
|
6312
6170
|
originDeviceId: "peer-device",
|
|
6313
6171
|
originTenantId: "tenant-indigo",
|
|
6314
|
-
sequenceNumber,
|
|
6172
|
+
sequenceNumber: 1,
|
|
6315
6173
|
eventTimestamp: "2026-08-28T01:22:30.000Z",
|
|
6316
6174
|
});
|
|
6317
6175
|
try {
|
|
@@ -6328,10 +6186,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6328
6186
|
});
|
|
6329
6187
|
await flushLoopMicrotasks();
|
|
6330
6188
|
const replacement = receiverSync({
|
|
6331
|
-
events: [event("companies/indigo/superseded.md"
|
|
6189
|
+
events: [event("companies/indigo/superseded.md")],
|
|
6332
6190
|
signal: new AbortController().signal,
|
|
6333
6191
|
});
|
|
6334
|
-
await expect(superseded).
|
|
6192
|
+
await expect(superseded).resolves.toBeUndefined();
|
|
6335
6193
|
expect(runPass.mock.calls.filter(([argv]) => argv.includes("superseded.md"))).toHaveLength(0);
|
|
6336
6194
|
expect(stderr.mock.calls.map(([chunk]) => String(chunk)).join("")).toContain('"event":"sync.realtime.timing","schemaVersion":3,"source":"receiver","direction":"pull","outcome":"refused"');
|
|
6337
6195
|
releaseHeld();
|
|
@@ -6349,197 +6207,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
6349
6207
|
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6350
6208
|
}
|
|
6351
6209
|
});
|
|
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
|
-
});
|
|
6425
|
-
it("measures a queued realtime pass at the operation gate and marks append lock only after admission", async () => {
|
|
6426
|
-
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6427
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
|
|
6428
|
-
const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-telemetry-operation-gate-"));
|
|
6429
|
-
const watcher = makeBatchWatcherStub();
|
|
6430
|
-
let receiverSync;
|
|
6431
|
-
let shutdown = () => { };
|
|
6432
|
-
let releaseGuard = () => { };
|
|
6433
|
-
const guard = new Promise((resolve) => { releaseGuard = resolve; });
|
|
6434
|
-
let markGuardStarted = () => { };
|
|
6435
|
-
const guardStarted = new Promise((resolve) => { markGuardStarted = resolve; });
|
|
6436
|
-
let markTargetStarted = () => { };
|
|
6437
|
-
const targetStarted = new Promise((resolve) => { markTargetStarted = resolve; });
|
|
6438
|
-
let monotonicMs = 0;
|
|
6439
|
-
let guardReleased = false;
|
|
6440
|
-
let targetStartedAt;
|
|
6441
|
-
const timings = [];
|
|
6442
|
-
const stderr = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
|
|
6443
|
-
if (typeof chunk === "string" && chunk.startsWith("{")) {
|
|
6444
|
-
try {
|
|
6445
|
-
const record = JSON.parse(chunk);
|
|
6446
|
-
if (typeof record === "object" &&
|
|
6447
|
-
record !== null &&
|
|
6448
|
-
record.event === "sync.realtime.timing")
|
|
6449
|
-
timings.push(record);
|
|
6450
|
-
}
|
|
6451
|
-
catch {
|
|
6452
|
-
// Non-telemetry diagnostics are outside this assertion.
|
|
6453
|
-
}
|
|
6454
|
-
}
|
|
6455
|
-
return true;
|
|
6456
|
-
});
|
|
6457
|
-
const includesScope = (argv, basename) => argv.some((argument) => argument === basename || argument.endsWith(`/${basename}`));
|
|
6458
|
-
const runPass = vi.fn(async (argv) => {
|
|
6459
|
-
if (includesScope(argv, "guard.md")) {
|
|
6460
|
-
markGuardStarted();
|
|
6461
|
-
await guard;
|
|
6462
|
-
return completedPassOutcome();
|
|
6463
|
-
}
|
|
6464
|
-
if (includesScope(argv, "target.md")) {
|
|
6465
|
-
expect(guardReleased).toBe(true);
|
|
6466
|
-
targetStartedAt = monotonicMs;
|
|
6467
|
-
markTargetStarted();
|
|
6468
|
-
monotonicMs += 1;
|
|
6469
|
-
}
|
|
6470
|
-
return completedPassOutcome();
|
|
6471
|
-
});
|
|
6472
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--direction", "push", "--hq-root", hqRoot], {
|
|
6473
|
-
runPass,
|
|
6474
|
-
createWatcher: () => watcher,
|
|
6475
|
-
createReceiver: ({ syncBatchFn }) => {
|
|
6476
|
-
receiverSync = syncBatchFn;
|
|
6477
|
-
return { connected: true, start: async () => { }, dispose: async () => { } };
|
|
6478
|
-
},
|
|
6479
|
-
monotonicNow: () => monotonicMs,
|
|
6480
|
-
sleep: () => new Promise(() => { }),
|
|
6481
|
-
onShutdownSignal: (handler) => {
|
|
6482
|
-
shutdown = handler;
|
|
6483
|
-
return () => { };
|
|
6484
|
-
},
|
|
6485
|
-
});
|
|
6486
|
-
const event = (relativePath) => ({
|
|
6487
|
-
kind: "upsert",
|
|
6488
|
-
relativePath,
|
|
6489
|
-
contentHash: "sha256:remote",
|
|
6490
|
-
mtime: "2026-09-23T00:00:00.000Z",
|
|
6491
|
-
originDeviceId: "peer-device",
|
|
6492
|
-
originTenantId: "tenant-indigo",
|
|
6493
|
-
sequenceNumber: 1,
|
|
6494
|
-
eventTimestamp: "2026-09-23T00:00:00.000Z",
|
|
6495
|
-
});
|
|
6496
|
-
try {
|
|
6497
|
-
await flushLoopMicrotasks(30);
|
|
6498
|
-
runPass.mockClear();
|
|
6499
|
-
const guardedPass = receiverSync({
|
|
6500
|
-
events: [event("companies/alpha/guard.md")],
|
|
6501
|
-
signal: new AbortController().signal,
|
|
6502
|
-
});
|
|
6503
|
-
await guardStarted;
|
|
6504
|
-
const targetAbsolutePath = path.join(hqRoot, "companies", "beta", "target.md");
|
|
6505
|
-
fs.mkdirSync(path.dirname(targetAbsolutePath), { recursive: true });
|
|
6506
|
-
fs.writeFileSync(targetAbsolutePath, "x");
|
|
6507
|
-
watcher.emit("companies/beta/target.md", {
|
|
6508
|
-
paths: new Map([
|
|
6509
|
-
[targetAbsolutePath, "companies/beta/target.md"],
|
|
6510
|
-
]),
|
|
6511
|
-
changes: new Map(),
|
|
6512
|
-
});
|
|
6513
|
-
await flushLoopMicrotasks(30);
|
|
6514
|
-
expect(targetStartedAt).toBeUndefined();
|
|
6515
|
-
monotonicMs += 25;
|
|
6516
|
-
guardReleased = true;
|
|
6517
|
-
releaseGuard();
|
|
6518
|
-
await guardedPass;
|
|
6519
|
-
await targetStarted;
|
|
6520
|
-
await flushLoopMicrotasks(30);
|
|
6521
|
-
expect(targetStartedAt).toBe(25);
|
|
6522
|
-
expect(timings).toHaveLength(2);
|
|
6523
|
-
const targetTiming = timings.find((record) => record.source === "watcher" &&
|
|
6524
|
-
record.direction === "push" &&
|
|
6525
|
-
record.outcome === "durable");
|
|
6526
|
-
expect(targetTiming).toBeDefined();
|
|
6527
|
-
expect(targetTiming?.timingMs?.operationGate).toBe(25);
|
|
6528
|
-
expect(targetTiming?.timingMs?.appendLock).toBe(0);
|
|
6529
|
-
}
|
|
6530
|
-
finally {
|
|
6531
|
-
guardReleased = true;
|
|
6532
|
-
releaseGuard();
|
|
6533
|
-
shutdown();
|
|
6534
|
-
await loop;
|
|
6535
|
-
stderr.mockRestore();
|
|
6536
|
-
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
6537
|
-
if (previousCoordinator === undefined)
|
|
6538
|
-
delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6539
|
-
else
|
|
6540
|
-
process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
|
|
6541
|
-
}
|
|
6542
|
-
});
|
|
6543
6210
|
it("REGRESSION: a fast receiver pull overtakes a slow watcher push and records admitted occupancy", async () => {
|
|
6544
6211
|
const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
|
|
6545
6212
|
const previousAreaStorage = process.env.HQ_SYNC_AREA_STORAGE;
|
|
@@ -9231,137 +8898,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
|
|
|
9231
8898
|
await expect(loop).resolves.toBe(0);
|
|
9232
8899
|
expect(watcher.disposed).toBe(false);
|
|
9233
8900
|
});
|
|
9234
|
-
it("bounds repeated watch-pass exits with a fake-clock retry budget while keeping the runner alive", async () => {
|
|
9235
|
-
const watcher = makeWatcherStub();
|
|
9236
|
-
const runPass = vi.fn().mockResolvedValue(1);
|
|
9237
|
-
const delays = [];
|
|
9238
|
-
const waiters = [];
|
|
9239
|
-
let now = 0;
|
|
9240
|
-
let shutdown = () => { };
|
|
9241
|
-
let settled;
|
|
9242
|
-
const sleep = (ms) => {
|
|
9243
|
-
delays.push(ms);
|
|
9244
|
-
return new Promise((resolve) => {
|
|
9245
|
-
waiters.push(resolve);
|
|
9246
|
-
});
|
|
9247
|
-
};
|
|
9248
|
-
const tick = async (advanceMs) => {
|
|
9249
|
-
now += advanceMs;
|
|
9250
|
-
const resolve = waiters.shift();
|
|
9251
|
-
if (!resolve)
|
|
9252
|
-
throw new Error("retry sleep was not pending");
|
|
9253
|
-
resolve();
|
|
9254
|
-
await flushLoopMicrotasks();
|
|
9255
|
-
};
|
|
9256
|
-
const waitForRetrySleep = async () => {
|
|
9257
|
-
for (let attempt = 0; attempt < 200; attempt += 1) {
|
|
9258
|
-
if (waiters.length > 0)
|
|
9259
|
-
return;
|
|
9260
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
9261
|
-
}
|
|
9262
|
-
throw new Error("timed out waiting for retry sleep");
|
|
9263
|
-
};
|
|
9264
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--poll-remote-ms", "1", "--hq-root", "/tmp/hq"], {
|
|
9265
|
-
runPass,
|
|
9266
|
-
clock: new FakeClock(),
|
|
9267
|
-
createWatcher: () => watcher,
|
|
9268
|
-
monotonicNow: () => now,
|
|
9269
|
-
sleep,
|
|
9270
|
-
onShutdownSignal: (handler) => {
|
|
9271
|
-
shutdown = handler;
|
|
9272
|
-
return () => { };
|
|
9273
|
-
},
|
|
9274
|
-
}).then((code) => {
|
|
9275
|
-
settled = code;
|
|
9276
|
-
return code;
|
|
9277
|
-
});
|
|
9278
|
-
try {
|
|
9279
|
-
await waitForRetrySleep();
|
|
9280
|
-
expect(runPass).toHaveBeenCalledTimes(1);
|
|
9281
|
-
expect(delays).toEqual([1]);
|
|
9282
|
-
await tick(1_000);
|
|
9283
|
-
expect(runPass).toHaveBeenCalledTimes(2);
|
|
9284
|
-
expect(delays).toEqual([1, 1]);
|
|
9285
|
-
await tick(1_000);
|
|
9286
|
-
expect(runPass).toHaveBeenCalledTimes(3);
|
|
9287
|
-
expect(delays).toEqual([1, 1, 60_000]);
|
|
9288
|
-
await tick(60_000);
|
|
9289
|
-
await tick(120_000);
|
|
9290
|
-
await tick(240_000);
|
|
9291
|
-
await tick(480_000);
|
|
9292
|
-
expect(runPass).toHaveBeenCalledTimes(7);
|
|
9293
|
-
expect(delays).toEqual([
|
|
9294
|
-
1,
|
|
9295
|
-
1,
|
|
9296
|
-
60_000,
|
|
9297
|
-
120_000,
|
|
9298
|
-
240_000,
|
|
9299
|
-
480_000,
|
|
9300
|
-
600_000,
|
|
9301
|
-
]);
|
|
9302
|
-
// The retry window is quiet-time based, not anchored to the first
|
|
9303
|
-
// failure. Continuing failures after thirty minutes must remain capped.
|
|
9304
|
-
await tick(600_000);
|
|
9305
|
-
await tick(600_000);
|
|
9306
|
-
expect(runPass).toHaveBeenCalledTimes(9);
|
|
9307
|
-
expect(delays.slice(-2)).toEqual([600_000, 600_000]);
|
|
9308
|
-
expect(settled).toBeUndefined();
|
|
9309
|
-
expect(watcher.disposed).toBe(false);
|
|
9310
|
-
}
|
|
9311
|
-
finally {
|
|
9312
|
-
shutdown();
|
|
9313
|
-
await expect(loop).resolves.toBe(0);
|
|
9314
|
-
}
|
|
9315
|
-
});
|
|
9316
|
-
it("does not let a watcher interrupt bypass a failed-pass retry deadline", async () => {
|
|
9317
|
-
const watcher = makeWatcherStub();
|
|
9318
|
-
let passes = 0;
|
|
9319
|
-
const runPass = vi.fn().mockImplementation(async () => {
|
|
9320
|
-
passes += 1;
|
|
9321
|
-
return passes === 1 ? 0 : 1;
|
|
9322
|
-
});
|
|
9323
|
-
const waiters = [];
|
|
9324
|
-
const now = 0;
|
|
9325
|
-
let shutdown = () => { };
|
|
9326
|
-
const sleep = vi.fn(() => new Promise((resolve) => {
|
|
9327
|
-
waiters.push(resolve);
|
|
9328
|
-
}));
|
|
9329
|
-
const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--poll-remote-ms", "1", "--hq-root", "/tmp/hq"], {
|
|
9330
|
-
runPass,
|
|
9331
|
-
clock: new FakeClock(),
|
|
9332
|
-
createWatcher: () => watcher,
|
|
9333
|
-
monotonicNow: () => now,
|
|
9334
|
-
sleep,
|
|
9335
|
-
onShutdownSignal: (handler) => {
|
|
9336
|
-
shutdown = handler;
|
|
9337
|
-
return () => { };
|
|
9338
|
-
},
|
|
9339
|
-
});
|
|
9340
|
-
try {
|
|
9341
|
-
await waitForPollSleep({
|
|
9342
|
-
pendingCount: () => waiters.length,
|
|
9343
|
-
});
|
|
9344
|
-
expect(runPass).toHaveBeenCalledTimes(1);
|
|
9345
|
-
watcher.emit();
|
|
9346
|
-
await flushLoopMicrotasks(30);
|
|
9347
|
-
expect(runPass).toHaveBeenCalledTimes(2);
|
|
9348
|
-
watcher.emit();
|
|
9349
|
-
await flushLoopMicrotasks(30);
|
|
9350
|
-
expect(runPass).toHaveBeenCalledTimes(3);
|
|
9351
|
-
watcher.emit();
|
|
9352
|
-
await flushLoopMicrotasks(30);
|
|
9353
|
-
expect(runPass).toHaveBeenCalledTimes(4);
|
|
9354
|
-
expect(sleep).toHaveBeenLastCalledWith(60_000);
|
|
9355
|
-
watcher.emit();
|
|
9356
|
-
await flushLoopMicrotasks(30);
|
|
9357
|
-
expect(runPass).toHaveBeenCalledTimes(4);
|
|
9358
|
-
expect(sleep).toHaveBeenLastCalledWith(60_000);
|
|
9359
|
-
}
|
|
9360
|
-
finally {
|
|
9361
|
-
shutdown();
|
|
9362
|
-
await expect(loop).resolves.toBe(0);
|
|
9363
|
-
}
|
|
9364
|
-
});
|
|
9365
8901
|
it("alerts when a partial pass failed before a company's download leg", async () => {
|
|
9366
8902
|
const watcher = makeWatcherStub();
|
|
9367
8903
|
const stderrWrite = vi
|
|
@@ -9792,6 +9328,56 @@ describe("runRunnerWithLoop — U58 realtime scheduler guard", () => {
|
|
|
9792
9328
|
});
|
|
9793
9329
|
});
|
|
9794
9330
|
describe("CooperativePassScheduler", () => {
|
|
9331
|
+
it("admits realtime during payload I/O and fences the next chore transfer until the result is committed", async () => {
|
|
9332
|
+
const scheduler = new CooperativePassScheduler(() => 0);
|
|
9333
|
+
const order = [];
|
|
9334
|
+
let markNetworkStarted = () => { };
|
|
9335
|
+
const networkStarted = new Promise((resolve) => {
|
|
9336
|
+
markNetworkStarted = resolve;
|
|
9337
|
+
});
|
|
9338
|
+
let releaseNetwork = () => { };
|
|
9339
|
+
const networkGate = new Promise((resolve) => {
|
|
9340
|
+
releaseNetwork = resolve;
|
|
9341
|
+
});
|
|
9342
|
+
const chore = scheduler.submit(async ({ checkpoint }) => {
|
|
9343
|
+
const first = await checkpoint.runChoreNetworkTransfer(async () => {
|
|
9344
|
+
order.push("network-1-start");
|
|
9345
|
+
markNetworkStarted();
|
|
9346
|
+
await networkGate;
|
|
9347
|
+
order.push("network-1-done");
|
|
9348
|
+
return "first";
|
|
9349
|
+
});
|
|
9350
|
+
order.push(`commit-${first.value}`);
|
|
9351
|
+
const secondPromise = checkpoint.runChoreNetworkTransfer(async () => {
|
|
9352
|
+
order.push("network-2-start");
|
|
9353
|
+
return "second";
|
|
9354
|
+
});
|
|
9355
|
+
await Promise.resolve();
|
|
9356
|
+
expect(order).not.toContain("network-2-start");
|
|
9357
|
+
order.push("commit-first-done");
|
|
9358
|
+
first.complete();
|
|
9359
|
+
const second = await secondPromise;
|
|
9360
|
+
order.push(`commit-${second.value}`);
|
|
9361
|
+
second.complete();
|
|
9362
|
+
return 0;
|
|
9363
|
+
}, "chore");
|
|
9364
|
+
await networkStarted;
|
|
9365
|
+
const realtime = scheduler.submit(async () => {
|
|
9366
|
+
order.push("realtime");
|
|
9367
|
+
return 0;
|
|
9368
|
+
}, "realtime");
|
|
9369
|
+
releaseNetwork();
|
|
9370
|
+
await Promise.all([chore, realtime]);
|
|
9371
|
+
expect(order).toEqual([
|
|
9372
|
+
"network-1-start",
|
|
9373
|
+
"realtime",
|
|
9374
|
+
"network-1-done",
|
|
9375
|
+
"commit-first",
|
|
9376
|
+
"commit-first-done",
|
|
9377
|
+
"network-2-start",
|
|
9378
|
+
"commit-second",
|
|
9379
|
+
]);
|
|
9380
|
+
});
|
|
9795
9381
|
it("admits an explicitly safe fast realtime pass while a slow scoped realtime pass remains in flight", async () => {
|
|
9796
9382
|
const scheduler = new CooperativePassScheduler(() => 0);
|
|
9797
9383
|
const order = [];
|
|
@@ -12340,7 +11926,7 @@ describe("resolvePullScope", () => {
|
|
|
12340
11926
|
isDefault: false,
|
|
12341
11927
|
}),
|
|
12342
11928
|
listMyExplicitGrants: async () => [
|
|
12343
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
11929
|
+
{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" },
|
|
12344
11930
|
],
|
|
12345
11931
|
}), "cmp_a", "acme"),
|
|
12346
11932
|
// custom
|
|
@@ -12414,7 +12000,7 @@ describe("resolvePullScope", () => {
|
|
|
12414
12000
|
isDefault: false,
|
|
12415
12001
|
}),
|
|
12416
12002
|
listMyExplicitGrants: async () => [
|
|
12417
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
12003
|
+
{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" },
|
|
12418
12004
|
],
|
|
12419
12005
|
}), "cmp_a", "acme");
|
|
12420
12006
|
expect(scope).toEqual({ syncMode: "shared", prefixSet: ["knowledge/"], excludePrefixes: [SESSIONS_SCOPE_PREFIX] });
|
|
@@ -12458,36 +12044,15 @@ describe("resolvePullScope", () => {
|
|
|
12458
12044
|
isDefault: false,
|
|
12459
12045
|
}),
|
|
12460
12046
|
listMyExplicitGrants: async () => [
|
|
12461
|
-
{ companyUid: "cmp_a", path: "knowledge
|
|
12462
|
-
{ companyUid: "cmp_a", path: "knowledge/sub
|
|
12463
|
-
{ companyUid: "cmp_a", path: "shared
|
|
12047
|
+
{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" },
|
|
12048
|
+
{ companyUid: "cmp_a", path: "knowledge/sub/", permission: "read", source: "group" },
|
|
12049
|
+
{ companyUid: "cmp_a", path: "shared/", permission: "read", source: "open" },
|
|
12464
12050
|
],
|
|
12465
12051
|
}), "cmp_a", "acme");
|
|
12466
12052
|
// knowledge/sub/ is covered by knowledge/ → coalesced away.
|
|
12467
12053
|
expect(scope.syncMode).toBe("shared");
|
|
12468
12054
|
expect(scope.prefixSet).toEqual(["knowledge/", "shared/"]);
|
|
12469
12055
|
});
|
|
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
|
-
});
|
|
12491
12056
|
// Regression lock-in (Michal / ridge report): a non-owner member whose
|
|
12492
12057
|
// ONLY grant is a COMPANY-WIDE write grant (surfaced by the server as
|
|
12493
12058
|
// `source: "open"`) on a projects prefix — and who has NO direct
|
|
@@ -12510,7 +12075,7 @@ describe("resolvePullScope", () => {
|
|
|
12510
12075
|
listMyExplicitGrants: async () => [
|
|
12511
12076
|
{
|
|
12512
12077
|
companyUid: "cmp_a",
|
|
12513
|
-
path: "projects/alpha
|
|
12078
|
+
path: "projects/alpha/",
|
|
12514
12079
|
permission: "write",
|
|
12515
12080
|
source: "open",
|
|
12516
12081
|
},
|
|
@@ -12635,7 +12200,7 @@ describe("resolvePullScope", () => {
|
|
|
12635
12200
|
syncMode: "shared",
|
|
12636
12201
|
isDefault: false,
|
|
12637
12202
|
}),
|
|
12638
|
-
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge
|
|
12203
|
+
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" }],
|
|
12639
12204
|
}), "cmp_a", "acme", root);
|
|
12640
12205
|
expect(scope.syncMode).toBe("shared");
|
|
12641
12206
|
// Grant prefix + pinned prefix, coalesced + sorted.
|
|
@@ -12678,7 +12243,7 @@ describe("resolvePullScope", () => {
|
|
|
12678
12243
|
syncMode: "shared",
|
|
12679
12244
|
isDefault: false,
|
|
12680
12245
|
}),
|
|
12681
|
-
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge
|
|
12246
|
+
listMyExplicitGrants: async () => [{ companyUid: "cmp_a", path: "knowledge/", permission: "read", source: "person" }],
|
|
12682
12247
|
}), "cmp_a", "acme", root);
|
|
12683
12248
|
// beta's pin must not leak into acme's scope.
|
|
12684
12249
|
expect(scope.prefixSet).toEqual(["knowledge/"]);
|