gentle-pi 5.0.0 → 5.1.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/README.md +1 -1
- package/assets/agents/gentle-ai-explore.md +3 -6
- package/assets/agents/gentle-ai-verify.md +1 -1
- package/assets/agents/gentle-ai-worker.md +9 -9
- package/assets/agents/jd-fix-agent.md +1 -1
- package/assets/agents/jd-judge-a.md +0 -1
- package/assets/agents/jd-judge-b.md +0 -1
- package/assets/migrations/agent-body-history.json +6 -0
- package/assets/orchestrator-full-delegation.md +1 -1
- package/assets/orchestrator-maintenance.md +11 -0
- package/assets/orchestrator-quota-recovery.md +1 -1
- package/assets/orchestrator-skills.md +10 -0
- package/assets/orchestrator-verification.md +9 -7
- package/assets/orchestrator.md +1 -1
- package/bin/gentle-shell.mjs +67 -15
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +10 -10
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/manifest.json +5 -5
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/orchestration/pi.md +5 -3
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/routing/pi.md +1 -1
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/lens.schema.json +3 -3
- package/contracts/review-provider-contract-mirror/v1.7.0/bundle/vectors/lens.json +1 -0
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-roles.baseline.json +3 -3
- package/docs/bundled-install.md +2 -2
- package/docs/delegated-verification.md +8 -4
- package/docs/desktop-feed.md +15 -6
- package/docs/desktop-rpc.md +44 -20
- package/docs/gentle-shell-desktop.md +10 -3
- package/docs/gentle-shell.md +17 -13
- package/docs/install-wizard.md +2 -2
- package/docs/odd-preparation-continuity.md +2 -2
- package/docs/permission-modes.md +10 -2
- package/docs/readme-reference.md +46 -11
- package/docs/session-profile-format.md +33 -7
- package/docs/work-continuity.md +7 -7
- package/docs/yolo-mode.md +1 -1
- package/extensions/child-context.ts +2 -11
- package/extensions/gentle-agents.ts +47 -28
- package/extensions/gentle-ai.ts +573 -353
- package/extensions/gentle-desktop-feed.ts +13 -3
- package/extensions/gentle-fast.ts +9 -2
- package/extensions/gentle-shell.ts +142 -55
- package/extensions/gentle-tps.ts +5 -0
- package/extensions/quiet-tools.ts +13 -22
- package/extensions/skill-registry.ts +9 -1
- package/herdr/mods/gentle-agents/snapshot.js +30 -23
- package/herdr/mods/gentle-chat/feed.js +6 -0
- package/herdr/mods/gentle-chat/main.js +76 -16
- package/herdr/mods/gentle-chat/session.js +13 -5
- package/herdr/mods/gentle-chat/snapshot.js +30 -23
- package/herdr/mods/gentle-chat/ui.js +7 -1
- package/herdr/mods/gentle-inspector/main.js +2 -0
- package/herdr/mods/gentle-inspector/snapshot.js +30 -23
- package/herdr/mods/gentle-palette/main.js +1 -1
- package/herdr/mods/gentle-palette/snapshot.js +30 -23
- package/herdr/mods/gentle-pane/snapshot.js +30 -23
- package/herdr/mods/gentle-sidebar/snapshot.js +30 -23
- package/herdr/mods/gentle-spaces/snapshot.js +30 -23
- package/herdr/mods/gentle-status/snapshot.js +30 -23
- package/herdr/mods/gentle-tabs/main.js +3 -2
- package/herdr/mods/gentle-tabs/new-tab.js +9 -0
- package/herdr/mods/gentle-tabs/snapshot.js +30 -23
- package/herdr/mods/gentle-tokens/snapshot.js +30 -23
- package/lib/agent-profiles.ts +50 -10
- package/lib/agents-config.ts +59 -4
- package/lib/agents-runner.ts +34 -1
- package/lib/auto-permission-runtime.ts +2 -1
- package/lib/background-jobs-tools.ts +24 -16
- package/lib/claude-bridge-config.ts +41 -0
- package/lib/desktop-agent-definitions-service.ts +10 -6
- package/lib/desktop-command-rpc.ts +71 -0
- package/lib/desktop-feed-sources.ts +44 -1
- package/lib/desktop-feed.ts +41 -29
- package/lib/desktop-rpc-agent-definitions.ts +7 -3
- package/lib/desktop-rpc-changes.ts +13 -4
- package/lib/desktop-rpc-config.ts +106 -3
- package/lib/exploration-budget.ts +3 -7
- package/lib/gentle-design.ts +23 -4
- package/lib/gentle-shell-desktop.ts +85 -0
- package/lib/gentle-shell-launcher.ts +106 -3
- package/lib/mcp-config.ts +214 -0
- package/lib/native-review-cli.ts +78 -34
- package/lib/odd-phase-inference.ts +1 -1
- package/lib/orchestrator-mode-policy.ts +25 -12
- package/lib/path-consent-fence.ts +113 -0
- package/lib/pi-settings.ts +157 -0
- package/lib/review-continuation-registry.ts +7 -20
- package/lib/review-coordinator.ts +5 -0
- package/lib/review-host-relay.ts +2 -35
- package/lib/review-integration-v2.ts +31 -12
- package/lib/sensitive-paths.ts +22 -2
- package/lib/session-profile-freeze.ts +11 -4
- package/lib/session-worktree-registry.ts +11 -5
- package/lib/shell-card.ts +27 -1
- package/lib/shell-changes-view.ts +6 -2
- package/lib/shell-changes.ts +94 -37
- package/lib/shell-git-worker.ts +158 -0
- package/lib/shell-idle-changes.ts +88 -0
- package/lib/shell-untracked-cache.ts +142 -0
- package/lib/shell-untracked-lines.ts +178 -0
- package/lib/tps-policy.ts +85 -0
- package/lib/vim-editor-adapter.ts +3 -2
- package/lib/voice-artifacts.ts +8 -1
- package/lib/voice-install.ts +7 -3
- package/lib/yolo-session-policy.ts +2 -2
- package/package.json +1 -1
- package/runtime/gentle-shell-desktop.mjs +85 -0
- package/runtime/gentle-shell-launcher.mjs +106 -3
- package/runtime/native-review-cli.mjs +77 -33
- package/runtime/review-integration-v2.mjs +31 -12
- package/runtime/sensitive-paths.mjs +22 -2
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/main-channel.mjs +27 -7
- package/scripts/verify-package-files.mjs +13 -12
- package/skills/rdd-defect-workflow/SKILL.md +2 -2
- package/tests/agent-profiles-workflow.test.ts +102 -0
- package/tests/agents-config.test.ts +1 -2
- package/tests/agents-protocol.test.ts +1 -1
- package/tests/agents-runner.test.ts +94 -2
- package/tests/append-system-prompt-route.test.ts +16 -11
- package/tests/auto-permission-runtime.test.ts +4 -4
- package/tests/bounded-stop-contract.test.ts +50 -62
- package/tests/child-context-files.test.ts +6 -6
- package/tests/child-web-package.test.ts +1 -1
- package/tests/controlled-engineering-editor.test.ts +192 -0
- package/tests/controlled-engineering-launch.test.ts +136 -0
- package/tests/controlled-engineering.test.ts +244 -0
- package/tests/delivery-b-rendered-surfaces.test.ts +1 -1
- package/tests/desktop-feed-tool-summaries.test.ts +1 -1
- package/tests/desktop-feed-transcript.test.ts +17 -0
- package/tests/desktop-feed.test.ts +141 -7
- package/tests/desktop-liveness.test.ts +125 -0
- package/tests/desktop-persona.test.ts +17 -0
- package/tests/desktop-rpc-agent-definitions.test.ts +23 -2
- package/tests/desktop-rpc-changes.test.ts +80 -3
- package/tests/desktop-rpc-config-mcp-fidelity.test.ts +106 -0
- package/tests/desktop-rpc-config-readonly-stores.test.ts +458 -0
- package/tests/desktop-rpc-config.test.ts +5 -2
- package/tests/desktop-rpc-design.test.ts +21 -0
- package/tests/desktop-rpc-session-snapshot-commands.test.ts +50 -0
- package/tests/desktop-session-switch.test.ts +237 -0
- package/tests/desktop-target-session.test.ts +104 -0
- package/tests/destructive-command-guard.test.ts +187 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +73 -9
- package/tests/exploration-budget.test.ts +2 -26
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +14 -10
- package/tests/full-delegation-closure.test.ts +19 -9
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agents.test.ts +214 -9
- package/tests/gentle-ai-exploration-budget.test.ts +3 -2
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai.test.ts +29 -5
- package/tests/gentle-chat-read-failure.test.ts +74 -0
- package/tests/gentle-chat-session-read.test.ts +127 -0
- package/tests/gentle-design.test.ts +39 -0
- package/tests/gentle-shell-desktop.test.ts +108 -0
- package/tests/gentle-shell-launcher-auto-provision.test.ts +152 -0
- package/tests/gentle-shell-launcher-machine-output.test.ts +356 -0
- package/tests/gentle-shell.test.ts +93 -12
- package/tests/gentle-tps.test.ts +57 -0
- package/tests/independent-recovery-delivery.test.ts +15 -13
- package/tests/installer-preflight.test.ts +3 -2
- package/tests/job-turn-end-texts.test.ts +57 -0
- package/tests/lazy-module-contradictions-contract.test.ts +1 -2
- package/tests/main-channel.test.ts +12 -1
- package/tests/maintainer/desktop-rpc.maintest.ts +2 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +113 -1
- package/tests/no-self-pause-contract.test.ts +8 -7
- package/tests/odd-phase-inference.test.ts +2 -2
- package/tests/odd-routing-canonical-ratchet.test.ts +1 -1
- package/tests/odd-routing-contract.test.ts +1 -1
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +5 -5
- package/tests/orchestrator-skills-inline-contract.test.ts +26 -0
- package/tests/package-manifest.test.ts +11 -16
- package/tests/packaged-agent-codemode.test.ts +79 -0
- package/tests/path-consent-fence.test.ts +326 -0
- package/tests/pi-update-launcher.test.ts +1 -1
- package/tests/primary-session-prompt.test.ts +9 -7
- package/tests/profile-fast-tier.test.ts +79 -4
- package/tests/progress-rule-contract.test.ts +54 -0
- package/tests/rdd-delivery-warning.test.ts +42 -4
- package/tests/review-actor-tool-deny.test.ts +1 -2
- package/tests/review-continuation-registry.test.ts +17 -17
- package/tests/review-controller-native-recovery.test.ts +100 -0
- package/tests/review-controller-native-routing.test.ts +129 -24
- package/tests/review-coordinator.test.ts +14 -0
- package/tests/review-host-relay-restart-parity.test.ts +2 -52
- package/tests/review-host-relay-routing.test.ts +57 -297
- package/tests/review-host-relay.test.ts +0 -46
- package/tests/review-integration-v2-forward.test.ts +39 -2
- package/tests/review-json-arguments.test.ts +30 -9
- package/tests/review-one-call-findings.test.ts +1 -0
- package/tests/review-untracked-inventory-replay.test.ts +181 -0
- package/tests/runtime-harness.mjs +27 -1
- package/tests/sensitive-path-tools.test.ts +155 -4
- package/tests/session-profile-extension.test.ts +90 -11
- package/tests/session-profile-freeze.test.ts +49 -2
- package/tests/session-profile-v1-compat.test.ts +11 -3
- package/tests/session-worktree-registry.test.ts +23 -0
- package/tests/shell-changes-idle-start.test.ts +510 -0
- package/tests/shell-changes-untracked-bound.test.ts +230 -0
- package/tests/shell-changes-view.test.ts +8 -2
- package/tests/shell-changes.test.ts +134 -0
- package/tests/shell-git-runner-stall.test.ts +74 -0
- package/tests/shell-git-worker-fallback.test.ts +140 -0
- package/tests/shell-git-worker-lifetime.test.ts +91 -0
- package/tests/shell-render-cache-runtime.test.ts +256 -3
- package/tests/shell-untracked-cache.test.ts +213 -0
- package/tests/short-check-routing-contract.test.ts +11 -7
- package/tests/skill-registry.test.ts +3 -3
- package/tests/support/chat-ui.ts +39 -0
- package/tests/t7-recovery-preservation.test.ts +68 -0
- package/tests/tps-policy.test.ts +96 -0
- package/tests/turn-end-rule-contract.test.ts +155 -0
- package/tests/turn-end-scope.test.ts +39 -0
- package/tests/verification-scoped-stop-contract.test.ts +1 -1
- package/tests/verification-tiers-contract.test.ts +4 -3
- package/tests/verify-first-launch-contract.test.ts +19 -7
- package/tests/vim-editor-adapter.test.ts +4 -4
- package/tests/voice-install.test.ts +97 -11
- package/tests/windows-hidden-processes.test.ts +11 -44
- package/tests/work-continuity-contract.test.ts +48 -55
- package/tests/yolo-session-policy.test.ts +2 -0
- package/contracts/review-provider-contract-mirror/v1.6.0/bundle/vectors/lens.json +0 -1
- package/extensions/codegraph-tools.ts +0 -437
- package/tests/child-codegraph-bootstrap.test.ts +0 -74
- package/tests/codegraph-tools.test.ts +0 -554
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -466,16 +466,63 @@ test("a startup-none record resolves no session profile without freezing the cur
|
|
|
466
466
|
assert.deepEqual(sessionProfileRoutingAt(resolution, target), LOCAL, "a foreign repository uses its own pins");
|
|
467
467
|
});
|
|
468
468
|
|
|
469
|
-
|
|
469
|
+
// A3 S4 (gentle-shell#1064), changed on purpose: follow ignores a recorded
|
|
470
|
+
// startup profile and resolves the current defaults; a startup-none record
|
|
471
|
+
// resolves those same defaults.
|
|
472
|
+
test("follow mode ignores a recorded startup profile and resolves the current defaults after a startup-none record", () => {
|
|
470
473
|
const f = fixture();
|
|
471
474
|
const env = { [PROFILE_FOLLOW_ENV]: "1" };
|
|
472
475
|
f.pinLocal("frontier");
|
|
473
476
|
bindSessionProfile("s-bind", "team", TEAM, { origin: "global" });
|
|
474
|
-
assert.deepEqual(
|
|
477
|
+
assert.deepEqual(resolveSessionProfile(options(f, "s-bind", env)), { kind: "follow", profile: { name: "frontier", origin: "local", modelProfiles: FRONTIER } }, "follow never reads the startup bind");
|
|
475
478
|
recordSessionProfileStartupNone("s-none");
|
|
476
479
|
assert.deepEqual(resolveSessionProfile(options(f, "s-none", env)), { kind: "follow", profile: { name: "frontier", origin: "local", modelProfiles: FRONTIER } });
|
|
477
480
|
});
|
|
478
481
|
|
|
482
|
+
// A3 S4 (gentle-shell#1064): reading side. A `follow` session ignores a startup
|
|
483
|
+
// bind from the record, from any origin, and resolves the current defaults; it
|
|
484
|
+
// never freezes and the inherited drift notice never applies.
|
|
485
|
+
test("follow mode ignores a recorded startup profile from every origin and routes the current defaults", () => {
|
|
486
|
+
const f = fixture();
|
|
487
|
+
const env = { [PROFILE_FOLLOW_ENV]: "1" };
|
|
488
|
+
f.pinLocal("frontier");
|
|
489
|
+
for (const origin of ["local", "repo", "global"] as const) {
|
|
490
|
+
const id = `s-${origin}`;
|
|
491
|
+
bindSessionProfile(id, "team", TEAM, { origin });
|
|
492
|
+
const resolution = resolveSessionProfile(options(f, id, env));
|
|
493
|
+
assert.deepEqual(resolution, { kind: "follow", profile: { name: "frontier", origin: "local", modelProfiles: FRONTIER } }, `a ${origin} startup bind does not outrank the current defaults`);
|
|
494
|
+
assert.deepEqual(sessionProfileRoutingAt(resolution, options(f, id)), FRONTIER, "a launch reads the current defaults too");
|
|
495
|
+
assert.equal(readFrozenInheritedProfile(id), undefined, "follow never freezes");
|
|
496
|
+
assert.equal(inheritedProfileDriftNotice(options(f, id, env)), undefined, "follow sessions are never compared");
|
|
497
|
+
}
|
|
498
|
+
const foreign = fixture();
|
|
499
|
+
foreign.declareRepo("team");
|
|
500
|
+
foreign.setActive("local");
|
|
501
|
+
const target = { cwd: foreign.cwd, configHome: foreign.configHome, resolveWorktree: foreign.resolveWorktree, foreignRepository: true };
|
|
502
|
+
assert.deepEqual(
|
|
503
|
+
JSON.parse(JSON.stringify(sessionProfileRoutingAt(resolveSessionProfile(options(f, "s-global", env)), target))),
|
|
504
|
+
{ worker: TEAM.worker },
|
|
505
|
+
"a foreign launch reads that repository's own defaults",
|
|
506
|
+
);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// A3 S4 (gentle-shell#1064): the explicit choice still wins over follow, with or
|
|
510
|
+
// without the startup state its record carries.
|
|
511
|
+
test("follow mode keeps an explicit choice that carried a startup state", () => {
|
|
512
|
+
const f = fixture();
|
|
513
|
+
const env = { [PROFILE_FOLLOW_ENV]: "1" };
|
|
514
|
+
f.pinLocal("frontier");
|
|
515
|
+
bindSessionProfile("s-known", "local", LOCAL, { startup: { origin: "global", name: "team", modelProfiles: TEAM } });
|
|
516
|
+
bindSessionProfile("s-none", "local", LOCAL, { startup: "none" });
|
|
517
|
+
for (const id of ["s-known", "s-none"]) {
|
|
518
|
+
const resolution = resolveSessionProfile(options(f, id, env));
|
|
519
|
+
assert.deepEqual(resolution, { kind: "explicit", name: "local", modelProfiles: LOCAL }, `${id} keeps its explicit choice`);
|
|
520
|
+
assert.equal(sessionProfileLabel(resolution), "local (session)");
|
|
521
|
+
}
|
|
522
|
+
f.pinLocal("team");
|
|
523
|
+
assert.deepEqual(sessionProfileModelProfiles(resolveSessionProfile(options(f, "s-known", env))), LOCAL, "later defaults never move an explicit choice");
|
|
524
|
+
});
|
|
525
|
+
|
|
479
526
|
// A2 (gentle-shell#2742, section 3): only a freeze at the session's own start
|
|
480
527
|
// knows the startup state, with the profile's full definition.
|
|
481
528
|
test("own start captures the startup profile with its full definition, orchestrator included", () => {
|
|
@@ -154,10 +154,18 @@ for (const [origin, defaults] of Object.entries(startupDefaults) as Array<[keyof
|
|
|
154
154
|
assert.ok(notice?.includes(`this session keeps "${name}" (${origin})`), "the inherited drift notice");
|
|
155
155
|
assert.equal(replay("v1", transcript).notice, undefined, "v1 finds no definition drift");
|
|
156
156
|
});
|
|
157
|
-
|
|
157
|
+
// A3 S4 (gentle-shell#1064), changed on purpose: the documented follow
|
|
158
|
+
// divergence. Follow ignores the startup bind and resolves the current
|
|
159
|
+
// defaults; v1 routes the recorded bind.
|
|
160
|
+
test(`follow mode ignores a ${origin} startup bind and resolves the current defaults, diverging from v1`, () => {
|
|
158
161
|
const transcript = { records: [record], defaults: { profiles, active: "local", foreignPin: "frontier" }, env: { GENTLE_PI_PROFILE_FOLLOW: "1" } };
|
|
159
|
-
|
|
160
|
-
assert.
|
|
162
|
+
const current = replay("current", transcript), v1 = launchRouting("v1", transcript);
|
|
163
|
+
assert.equal(current.kind, "follow");
|
|
164
|
+
assert.equal(current.notice, undefined, "follow sessions are never compared");
|
|
165
|
+
assert.deepEqual(launchRouting("current", transcript).routing, roles(LOCAL), "the current defaults outrank the startup bind");
|
|
166
|
+
assert.deepEqual(launchRouting("current", transcript).foreignRouting, roles(FRONTIER), "a foreign launch reads that repository's own pin");
|
|
167
|
+
assert.deepEqual(v1.routing, roles(profiles[name]), "v1 still routes the recorded startup bind");
|
|
168
|
+
assert.deepEqual(v1.foreignRouting, roles(profiles[name]));
|
|
161
169
|
});
|
|
162
170
|
}
|
|
163
171
|
|
|
@@ -56,6 +56,29 @@ test("canonical roots include cwd, dedupe aliases immediately and reject unrelat
|
|
|
56
56
|
assert.equal(resolveSessionWorktree(f.alias, f.main)?.root, f.linked);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
test("startup registers a cwd whose clone sets core.worktree outside the cwd", (t) => {
|
|
60
|
+
// A stray `D:\.git` with `core.worktree = E:/`: Git answers the cwd with a
|
|
61
|
+
// root it cannot rediscover from, which must not fail session startup.
|
|
62
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), "session-worktrees-")));
|
|
63
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
64
|
+
const outer = join(dir, "outer");
|
|
65
|
+
const elsewhere = join(dir, "elsewhere");
|
|
66
|
+
const cwd = join(outer, "project");
|
|
67
|
+
mkdirSync(elsewhere);
|
|
68
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("GIT_")));
|
|
69
|
+
Object.assign(env, { GIT_CONFIG_GLOBAL: join(elsewhere, "config"), GIT_CONFIG_NOSYSTEM: "1" });
|
|
70
|
+
writeFileSync(join(elsewhere, "config"), "");
|
|
71
|
+
execFileSync("git", ["init", outer], { env, stdio: ["ignore", "pipe", "pipe"] });
|
|
72
|
+
execFileSync("git", ["-C", outer, "config", "core.worktree", elsewhere], { env, stdio: ["ignore", "pipe", "pipe"] });
|
|
73
|
+
mkdirSync(cwd);
|
|
74
|
+
const h = host(cwd);
|
|
75
|
+
const registry = h.registry();
|
|
76
|
+
registry.start();
|
|
77
|
+
const entries = h.session.getEntries().filter((entry) => entry.type === "custom" && entry.customType === SESSION_WORKTREE_ENTRY);
|
|
78
|
+
assert.deepEqual(entries.map((entry) => (entry as { data?: unknown }).data), [{ sessionId: h.session.getSessionId(), root: elsewhere, evidence: "session:cwd" }]);
|
|
79
|
+
assert.throws(() => registry.register(elsewhere, "explicit"), /same Git clone/);
|
|
80
|
+
});
|
|
81
|
+
|
|
59
82
|
test("a registry constructed before Git init adopts only its original cwd in the same session", (t) => {
|
|
60
83
|
const f = fixture(t);
|
|
61
84
|
const cwd = join(f.dir, "bootstrap");
|
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test, { type TestContext } from "node:test";
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import shell, { backgroundChangeRefreshesSettled, shellUntrackedLines } from "../extensions/gentle-shell.ts";
|
|
8
|
+
import { createIdleChanges } from "../lib/shell-idle-changes.ts";
|
|
9
|
+
|
|
10
|
+
const quiet = 250;
|
|
11
|
+
const oneScan = ["worktree", "rev-parse", "diff", "status"];
|
|
12
|
+
const changed = "✎ 1 file · +2 −1 · hello.ts";
|
|
13
|
+
const theme = { fg: (_color: string, value: string) => value };
|
|
14
|
+
const tui = { requestRender() {} };
|
|
15
|
+
const footerData = { getGitBranch: () => "main", getExtensionStatuses: () => new Map(), getAvailableProviderCount: () => 1, onBranchChange: () => () => {} };
|
|
16
|
+
type Row = { render(width: number): string[] };
|
|
17
|
+
type Widget = (host: typeof tui, colors: typeof theme) => Row;
|
|
18
|
+
|
|
19
|
+
function fixture(t: TestContext, deferredCounts = false, budget = 2, statusFails = (_attempt: number) => false) {
|
|
20
|
+
const config = mkdtempSync(join(tmpdir(), "gentle-changes-idle-"));
|
|
21
|
+
t.after(() => rmSync(config, { recursive: true, force: true }));
|
|
22
|
+
const handlers = new Map<string, Array<(event: unknown, ctx: ExtensionContext) => unknown>>();
|
|
23
|
+
let entries: unknown[];
|
|
24
|
+
const calls: string[] = [], lookups: string[][] = [];
|
|
25
|
+
let now = 0, statuses = 0;
|
|
26
|
+
let gate: Promise<void> | undefined;
|
|
27
|
+
const timers = new Map<() => void, { at: number; unrefed: boolean }>();
|
|
28
|
+
const pi = {
|
|
29
|
+
on: (key: string, fn: (event: unknown, ctx: ExtensionContext) => unknown) => handlers.set(key, [...(handlers.get(key) ?? []), fn]),
|
|
30
|
+
events: { on: () => () => {}, emit() {} },
|
|
31
|
+
appendEntry: (customType: string, data: unknown) => entries.push({ type: "custom", customType, data }),
|
|
32
|
+
registerCommand() {}, registerTool() {}, registerShortcut() {}, registerMessageRenderer() {}, getThinkingLevel: () => "off",
|
|
33
|
+
} as unknown as ExtensionAPI;
|
|
34
|
+
shell(pi, { GENTLE_PI_CONFIG_HOME: config }, {
|
|
35
|
+
devBinary: () => undefined, resolveWorktree: (path, cwd) => {
|
|
36
|
+
lookups.push([path, cwd]);
|
|
37
|
+
return { root: "/repo", commonDir: "/repo/.git" };
|
|
38
|
+
}, rootExists: () => true,
|
|
39
|
+
gitRunner: () => async ([cmd]) => {
|
|
40
|
+
calls.push(cmd);
|
|
41
|
+
if (cmd === "worktree") await gate;
|
|
42
|
+
if (cmd === "status" && statusFails(++statuses)) return { code: 1, stdout: "", timedOut: true };
|
|
43
|
+
return { code: 0, stdout: cmd === "worktree" ? "worktree /repo\0branch refs/heads/main\0\0" : cmd === "status" ? (deferredCounts ? "?? a\0?? b\0?? c\0" : " M hello.ts\0") : cmd === "diff" ? "2\t1\thello.ts\n" : "" };
|
|
44
|
+
},
|
|
45
|
+
...(deferredCounts ? { changesLineCache: () => shellUntrackedLines({
|
|
46
|
+
lstat: async () => ({ isFile: () => true, size: 2, mtimeMs: 1 }), read: async () => Buffer.from("x\n"),
|
|
47
|
+
}, budget) } : {}),
|
|
48
|
+
now: () => now,
|
|
49
|
+
scheduleChangesIdle: (tick: () => void, delay: number) => {
|
|
50
|
+
const timer = { at: now + delay, unrefed: false };
|
|
51
|
+
timers.set(tick, timer);
|
|
52
|
+
return { cancel: () => { timers.delete(tick); }, unref: () => { timer.unrefed = true; } };
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const advance = (ms: number) => {
|
|
56
|
+
now += ms;
|
|
57
|
+
for (const [tick, timer] of [...timers]) if (timer.at <= now && timers.delete(tick)) tick();
|
|
58
|
+
};
|
|
59
|
+
function session(id: string) {
|
|
60
|
+
const sessionEntries: unknown[] = [];
|
|
61
|
+
const widgets = new Map<string, Widget>();
|
|
62
|
+
let footerFactory: (host: typeof tui, colors: typeof theme, data: typeof footerData) => Row;
|
|
63
|
+
let terminalInput: ((data: string) => unknown) | undefined;
|
|
64
|
+
let idle = true;
|
|
65
|
+
// The gentle-shell.test.ts fakeContext shape: the real footer reads
|
|
66
|
+
// context usage, session cwd and name, even before Git has run.
|
|
67
|
+
const ctx = {
|
|
68
|
+
hasUI: true, mode: "tui", cwd: "/repo", isIdle: () => idle, hasPendingMessages: () => false,
|
|
69
|
+
getContextUsage: () => ({ tokens: 0, contextWindow: 272_000, percent: 0 }),
|
|
70
|
+
sessionManager: { getCwd: () => "/repo", getSessionName: () => undefined, getSessionId: () => id, getEntries: () => sessionEntries },
|
|
71
|
+
ui: { theme, setFooter: (factory: typeof footerFactory) => { footerFactory = factory; }, getEditorComponent: () => ({}), setWorkingVisible() {},
|
|
72
|
+
setWidget: (key: string, value: Widget | undefined) => value === undefined ? widgets.delete(key) : widgets.set(key, value),
|
|
73
|
+
onTerminalInput: (listener: typeof terminalInput) => { terminalInput = listener; return () => { terminalInput = undefined; }; } },
|
|
74
|
+
} as unknown as ExtensionContext;
|
|
75
|
+
const fire = async (key: string) => { entries = sessionEntries; for (const fn of handlers.get(key) ?? []) await fn({}, ctx); };
|
|
76
|
+
const widget = () => widgets.get("gentle-shell-changes")?.(tui, theme).render(160)[0]?.replace(/\s+\/gentle:changes$/, "");
|
|
77
|
+
return { fire, footer: () => footerFactory(tui, theme, footerData), widget, setIdle: (next: boolean) => { idle = next; },
|
|
78
|
+
input: () => terminalInput?.("x"), observing: () => Boolean(terminalInput) };
|
|
79
|
+
}
|
|
80
|
+
return { session, calls, lookups, timers, advance, holdGit: () => { const held = Promise.withResolvers<void>(); gate = held.promise; return held.resolve; } };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
test("session_start finishes with only existing worktree identity lookups, even when inventory Git would block", async (t) => {
|
|
84
|
+
const f = fixture(t);
|
|
85
|
+
const s = f.session("startup");
|
|
86
|
+
t.after(() => s.fire("session_shutdown"));
|
|
87
|
+
const release = f.holdGit();
|
|
88
|
+
try {
|
|
89
|
+
const started = s.fire("session_start");
|
|
90
|
+
assert.equal(await Promise.race([started.then(() => "started"), new Promise((resolve) => setImmediate(resolve, "blocked"))]), "started");
|
|
91
|
+
assert.deepEqual(f.lookups, Array.from({ length: 4 }, () => ["/repo", "/repo"]));
|
|
92
|
+
assert.deepEqual(f.calls, []);
|
|
93
|
+
assert.equal(f.timers.size, 0);
|
|
94
|
+
assert.equal(s.widget(), undefined);
|
|
95
|
+
} finally { release(); }
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("after first paint the first quiet, idle shell loads Changes exactly once", async (t) => {
|
|
99
|
+
const f = fixture(t);
|
|
100
|
+
const s = f.session("paint");
|
|
101
|
+
t.after(() => s.fire("session_shutdown"));
|
|
102
|
+
await s.fire("session_start");
|
|
103
|
+
const footer = s.footer();
|
|
104
|
+
f.advance(4 * quiet);
|
|
105
|
+
assert.deepEqual(f.calls, [], "creating the footer is not a paint");
|
|
106
|
+
assert.equal(s.widget(), undefined);
|
|
107
|
+
footer.render(160);
|
|
108
|
+
assert.deepEqual(f.calls, [], "the first paint itself does not run Git");
|
|
109
|
+
s.setIdle(false);
|
|
110
|
+
f.advance(quiet);
|
|
111
|
+
assert.deepEqual(f.calls, [], "the shell must also be idle");
|
|
112
|
+
s.setIdle(true);
|
|
113
|
+
f.advance(quiet - 1);
|
|
114
|
+
assert.deepEqual(f.calls, []);
|
|
115
|
+
f.advance(1);
|
|
116
|
+
await backgroundChangeRefreshesSettled();
|
|
117
|
+
assert.deepEqual(f.calls, oneScan);
|
|
118
|
+
assert.equal(s.widget(), changed);
|
|
119
|
+
footer.render(160);
|
|
120
|
+
f.advance(4 * quiet);
|
|
121
|
+
assert.equal(f.timers.size, 0);
|
|
122
|
+
assert.deepEqual(f.calls, oneScan);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("typing restarts the quiet period and a turn start cancels the pending startup scan; agent_end still refreshes", async (t) => {
|
|
126
|
+
const f = fixture(t);
|
|
127
|
+
const s = f.session("turn");
|
|
128
|
+
t.after(() => s.fire("session_shutdown"));
|
|
129
|
+
await s.fire("session_start");
|
|
130
|
+
s.footer().render(160);
|
|
131
|
+
assert.equal(f.timers.size, 1);
|
|
132
|
+
f.advance(quiet - 1);
|
|
133
|
+
assert.equal(s.input(), undefined, "watching keys does not consume them");
|
|
134
|
+
f.advance(quiet - 1);
|
|
135
|
+
assert.deepEqual(f.calls, [], "a keystroke restarts the full quiet delay");
|
|
136
|
+
await s.fire("agent_start");
|
|
137
|
+
assert.equal(f.timers.size, 0);
|
|
138
|
+
f.advance(4 * quiet);
|
|
139
|
+
assert.deepEqual(f.calls, []);
|
|
140
|
+
assert.equal(s.widget(), undefined);
|
|
141
|
+
await s.fire("agent_end");
|
|
142
|
+
await backgroundChangeRefreshesSettled();
|
|
143
|
+
assert.deepEqual(f.calls, oneScan);
|
|
144
|
+
assert.equal(s.widget(), changed);
|
|
145
|
+
f.advance(4 * quiet);
|
|
146
|
+
assert.deepEqual(f.calls, oneScan);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("session replacement and shutdown cancel unrefed scans and remove their input observers", async (t) => {
|
|
150
|
+
const f = fixture(t);
|
|
151
|
+
const old = f.session("old");
|
|
152
|
+
await old.fire("session_start");
|
|
153
|
+
const oldFooter = old.footer();
|
|
154
|
+
oldFooter.render(160);
|
|
155
|
+
assert.deepEqual([...f.timers.values()].map(({ unrefed }) => unrefed), [true]);
|
|
156
|
+
assert.equal(old.observing(), true);
|
|
157
|
+
const next = f.session("next");
|
|
158
|
+
await next.fire("session_start");
|
|
159
|
+
assert.equal(f.timers.size, 0);
|
|
160
|
+
assert.equal(old.observing(), false);
|
|
161
|
+
oldFooter.render(160);
|
|
162
|
+
f.advance(4 * quiet);
|
|
163
|
+
assert.deepEqual(f.calls, []);
|
|
164
|
+
assert.equal(old.widget(), undefined);
|
|
165
|
+
next.footer().render(160);
|
|
166
|
+
assert.deepEqual([...f.timers.values()].map(({ unrefed }) => unrefed), [true]);
|
|
167
|
+
assert.equal(next.observing(), true);
|
|
168
|
+
await next.fire("session_shutdown");
|
|
169
|
+
assert.equal(f.timers.size, 0);
|
|
170
|
+
assert.equal(next.observing(), false);
|
|
171
|
+
f.advance(4 * quiet);
|
|
172
|
+
assert.deepEqual(f.calls, []);
|
|
173
|
+
assert.equal(next.widget(), undefined);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const backoff = [1_000, 3_000, 10_000];
|
|
177
|
+
|
|
178
|
+
async function startFailingIdle(t: TestContext, fails: (attempt: number) => boolean, deferredCounts = false) {
|
|
179
|
+
const f = fixture(t, deferredCounts, 2, fails);
|
|
180
|
+
const s = f.session("retry");
|
|
181
|
+
await s.fire("session_start");
|
|
182
|
+
s.footer().render(160);
|
|
183
|
+
f.advance(quiet);
|
|
184
|
+
await backgroundChangeRefreshesSettled();
|
|
185
|
+
assert.deepEqual(f.calls, oneScan);
|
|
186
|
+
assert.equal(s.widget(), undefined);
|
|
187
|
+
return { f, s };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const scans = (count: number) => Array.from({ length: count }, () => oneScan).flat();
|
|
191
|
+
|
|
192
|
+
test("a failed first idle scan recovers on its first retry without an agent turn", async (t) => {
|
|
193
|
+
const { f, s } = await startFailingIdle(t, (attempt) => attempt === 1);
|
|
194
|
+
t.after(() => s.fire("session_shutdown"));
|
|
195
|
+
assert.deepEqual([...f.timers.values()].map(({ unrefed }) => unrefed), [true]);
|
|
196
|
+
f.advance(backoff[0] - 1);
|
|
197
|
+
assert.deepEqual(f.calls, oneScan);
|
|
198
|
+
assert.equal(s.widget(), undefined);
|
|
199
|
+
f.advance(1);
|
|
200
|
+
await backgroundChangeRefreshesSettled();
|
|
201
|
+
assert.deepEqual(f.calls, scans(2));
|
|
202
|
+
assert.equal(s.widget(), changed);
|
|
203
|
+
assert.equal(f.timers.size, 0);
|
|
204
|
+
assert.equal(s.observing(), false);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("a repeatedly failing root stops after bounded idle retries; turn end can still refresh", async (t) => {
|
|
208
|
+
let failing = true;
|
|
209
|
+
const { f, s } = await startFailingIdle(t, () => failing);
|
|
210
|
+
t.after(() => s.fire("session_shutdown"));
|
|
211
|
+
for (const [index, delay] of backoff.entries()) {
|
|
212
|
+
f.advance(delay - 1);
|
|
213
|
+
assert.deepEqual(f.calls, scans(index + 1));
|
|
214
|
+
f.advance(1);
|
|
215
|
+
await backgroundChangeRefreshesSettled();
|
|
216
|
+
assert.deepEqual(f.calls, scans(index + 2));
|
|
217
|
+
assert.equal(s.widget(), undefined);
|
|
218
|
+
}
|
|
219
|
+
assert.equal(f.timers.size, 0);
|
|
220
|
+
assert.equal(s.observing(), false);
|
|
221
|
+
f.advance(60_000);
|
|
222
|
+
assert.deepEqual(f.calls, scans(4));
|
|
223
|
+
failing = false;
|
|
224
|
+
await s.fire("agent_end");
|
|
225
|
+
await backgroundChangeRefreshesSettled();
|
|
226
|
+
assert.deepEqual(f.calls, scans(5));
|
|
227
|
+
assert.equal(s.widget(), changed);
|
|
228
|
+
assert.equal(f.timers.size, 0);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("a turn start cancels a waiting failure retry", async (t) => {
|
|
232
|
+
const { f, s } = await startFailingIdle(t, () => true);
|
|
233
|
+
t.after(() => s.fire("session_shutdown"));
|
|
234
|
+
assert.equal(f.timers.size, 1);
|
|
235
|
+
f.advance(backoff[0] - 1);
|
|
236
|
+
await s.fire("agent_start");
|
|
237
|
+
assert.equal(f.timers.size, 0);
|
|
238
|
+
assert.equal(s.observing(), false);
|
|
239
|
+
f.advance(60_000);
|
|
240
|
+
assert.deepEqual(f.calls, oneScan);
|
|
241
|
+
assert.equal(s.widget(), undefined);
|
|
242
|
+
await s.fire("agent_end");
|
|
243
|
+
await backgroundChangeRefreshesSettled();
|
|
244
|
+
assert.deepEqual(f.calls, scans(2), "a turn end still runs its ordinary refresh");
|
|
245
|
+
assert.equal(f.timers.size, 0, "a failed ordinary refresh does not start an idle retry chain");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("shutdown cancels a waiting failure retry", async (t) => {
|
|
249
|
+
const { f, s } = await startFailingIdle(t, () => true);
|
|
250
|
+
assert.equal(f.timers.size, 1);
|
|
251
|
+
await s.fire("session_shutdown");
|
|
252
|
+
assert.equal(f.timers.size, 0);
|
|
253
|
+
assert.equal(s.observing(), false);
|
|
254
|
+
f.advance(60_000);
|
|
255
|
+
assert.deepEqual(f.calls, oneScan);
|
|
256
|
+
assert.equal(s.widget(), undefined);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("typing postpones a waiting failure retry without consuming it or the key", async (t) => {
|
|
260
|
+
const { f, s } = await startFailingIdle(t, (attempt) => attempt === 1);
|
|
261
|
+
t.after(() => s.fire("session_shutdown"));
|
|
262
|
+
assert.equal(s.observing(), true);
|
|
263
|
+
f.advance(backoff[0] - 1);
|
|
264
|
+
assert.equal(s.input(), undefined);
|
|
265
|
+
f.advance(backoff[0] - 1);
|
|
266
|
+
assert.deepEqual(f.calls, oneScan);
|
|
267
|
+
assert.equal(s.widget(), undefined);
|
|
268
|
+
f.advance(1);
|
|
269
|
+
await backgroundChangeRefreshesSettled();
|
|
270
|
+
assert.deepEqual(f.calls, scans(2));
|
|
271
|
+
assert.equal(s.widget(), changed);
|
|
272
|
+
assert.equal(f.timers.size, 0);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("a successful retry resets backoff for a later failed idle count continuation", async (t) => {
|
|
276
|
+
const { f, s } = await startFailingIdle(t, (attempt) => attempt === 1 || attempt === 3, true);
|
|
277
|
+
t.after(() => s.fire("session_shutdown"));
|
|
278
|
+
f.advance(backoff[0]);
|
|
279
|
+
await backgroundChangeRefreshesSettled();
|
|
280
|
+
assert.deepEqual(f.calls, scans(2));
|
|
281
|
+
assert.equal(s.widget(), "✎ 3 files · +1 −0 · partial counts · a · b · c");
|
|
282
|
+
f.advance(quiet);
|
|
283
|
+
await backgroundChangeRefreshesSettled();
|
|
284
|
+
assert.deepEqual(f.calls, scans(3));
|
|
285
|
+
f.advance(backoff[0] - 1);
|
|
286
|
+
assert.deepEqual(f.calls, scans(3));
|
|
287
|
+
f.advance(1);
|
|
288
|
+
await backgroundChangeRefreshesSettled();
|
|
289
|
+
assert.deepEqual(f.calls, scans(4));
|
|
290
|
+
assert.equal(s.widget(), "✎ 3 files · +2 −0 · partial counts · a · b · c");
|
|
291
|
+
f.advance(quiet);
|
|
292
|
+
await backgroundChangeRefreshesSettled();
|
|
293
|
+
assert.deepEqual(f.calls, scans(5));
|
|
294
|
+
assert.equal(s.widget(), "✎ 3 files · +3 −0 · a · b · c");
|
|
295
|
+
assert.equal(f.timers.size, 0);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("pending counts resume after typing and a turn, coalesce in-flight scans, and stop at complete counts", async (t) => {
|
|
299
|
+
const f = fixture(t, true);
|
|
300
|
+
const s = f.session("counts");
|
|
301
|
+
t.after(() => s.fire("session_shutdown"));
|
|
302
|
+
await s.fire("session_start");
|
|
303
|
+
s.footer().render(160);
|
|
304
|
+
f.advance(quiet);
|
|
305
|
+
await backgroundChangeRefreshesSettled();
|
|
306
|
+
assert.deepEqual(f.calls, oneScan);
|
|
307
|
+
assert.equal(s.widget(), "✎ 3 files · +1 −0 · partial counts · a · b · c");
|
|
308
|
+
f.advance(quiet - 1);
|
|
309
|
+
s.input();
|
|
310
|
+
f.advance(quiet - 1);
|
|
311
|
+
assert.deepEqual(f.calls, oneScan);
|
|
312
|
+
const release = f.holdGit();
|
|
313
|
+
try {
|
|
314
|
+
f.advance(1);
|
|
315
|
+
assert.deepEqual(f.calls, [...oneScan, "worktree"]);
|
|
316
|
+
s.setIdle(false);
|
|
317
|
+
await s.fire("agent_start");
|
|
318
|
+
await s.fire("agent_end");
|
|
319
|
+
f.advance(4 * quiet);
|
|
320
|
+
assert.deepEqual(f.calls, [...oneScan, "worktree"], "turn-end refresh shares the in-flight scan");
|
|
321
|
+
} finally { release(); }
|
|
322
|
+
await backgroundChangeRefreshesSettled();
|
|
323
|
+
assert.deepEqual(f.calls, [...oneScan, ...oneScan]);
|
|
324
|
+
assert.equal(s.widget(), "✎ 3 files · +2 −0 · partial counts · a · b · c");
|
|
325
|
+
f.advance(quiet);
|
|
326
|
+
assert.deepEqual(f.calls, [...oneScan, ...oneScan], "post-run work is still busy");
|
|
327
|
+
s.setIdle(true);
|
|
328
|
+
f.advance(quiet);
|
|
329
|
+
await backgroundChangeRefreshesSettled();
|
|
330
|
+
assert.deepEqual(f.calls, [...oneScan, ...oneScan, ...oneScan]);
|
|
331
|
+
assert.equal(s.widget(), "✎ 3 files · +3 −0 · a · b · c");
|
|
332
|
+
f.advance(4 * quiet);
|
|
333
|
+
assert.equal(f.timers.size, 0);
|
|
334
|
+
assert.deepEqual(f.calls, [...oneScan, ...oneScan, ...oneScan]);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// Counts that stay pending without progress (here: a budget no file fits in)
|
|
338
|
+
// must not keep the shell scanning forever while idle.
|
|
339
|
+
test("idle continuation stops after a pass that made no progress", async (t) => {
|
|
340
|
+
const f = fixture(t, true, 1);
|
|
341
|
+
const s = f.session("stuck");
|
|
342
|
+
t.after(() => s.fire("session_shutdown"));
|
|
343
|
+
await s.fire("session_start");
|
|
344
|
+
s.footer().render(160);
|
|
345
|
+
for (let tick = 0; tick < 12; tick++) {
|
|
346
|
+
f.advance(quiet);
|
|
347
|
+
await backgroundChangeRefreshesSettled();
|
|
348
|
+
}
|
|
349
|
+
assert.equal(f.calls.filter((cmd) => cmd === "status").length, 2, "the first pass, then one pass that confirms nothing moved");
|
|
350
|
+
assert.equal(f.timers.size, 0, "no idle timer is left armed");
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("unchanged pending counts do not keep the idle scan armed forever", () => {
|
|
354
|
+
const ticks = new Set<() => void>();
|
|
355
|
+
let scans = 0;
|
|
356
|
+
const idle = createIdleChanges({
|
|
357
|
+
isIdle: () => true,
|
|
358
|
+
refresh() {
|
|
359
|
+
scans++;
|
|
360
|
+
idle.scanStarted();
|
|
361
|
+
idle.scanFinished(3, {});
|
|
362
|
+
},
|
|
363
|
+
observeInput: () => undefined,
|
|
364
|
+
schedule(tick) {
|
|
365
|
+
ticks.add(tick);
|
|
366
|
+
return { cancel: () => { ticks.delete(tick); }, unref() {} };
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
const advance = () => { for (const tick of [...ticks]) if (ticks.delete(tick)) tick(); };
|
|
370
|
+
idle.started();
|
|
371
|
+
idle.firstPaint();
|
|
372
|
+
for (let i = 0; i < 60; i++) advance();
|
|
373
|
+
const before = scans;
|
|
374
|
+
for (let i = 0; i < 60; i++) advance();
|
|
375
|
+
assert.equal(before, 2, "the first pass and the one that saw no progress");
|
|
376
|
+
assert.equal(scans, before);
|
|
377
|
+
assert.equal(ticks.size, 0);
|
|
378
|
+
idle.dispose();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Found by the independent verify: once the failure retries run out, counts
|
|
382
|
+
// that still progress on a healthy root must keep continuing while idle.
|
|
383
|
+
test("pending counts keep progressing after the failure retries run out", () => {
|
|
384
|
+
const ticks = new Set<() => void>();
|
|
385
|
+
let scans = 0, pending = 10;
|
|
386
|
+
const idle = createIdleChanges({
|
|
387
|
+
isIdle: () => true,
|
|
388
|
+
refresh() {
|
|
389
|
+
scans++;
|
|
390
|
+
const turn = idle.scanStarted();
|
|
391
|
+
pending = Math.max(0, pending - 1);
|
|
392
|
+
idle.scanFinished(pending, {}, 1, turn);
|
|
393
|
+
},
|
|
394
|
+
observeInput: () => undefined,
|
|
395
|
+
schedule(tick) {
|
|
396
|
+
ticks.add(tick);
|
|
397
|
+
return { cancel: () => { ticks.delete(tick); }, unref() {} };
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
const advance = () => { for (const tick of [...ticks]) if (ticks.delete(tick)) tick(); };
|
|
401
|
+
idle.started();
|
|
402
|
+
idle.firstPaint();
|
|
403
|
+
for (let i = 0; i < 40; i++) advance();
|
|
404
|
+
assert.equal(pending, 0, "every count finished");
|
|
405
|
+
assert.equal(scans, 10);
|
|
406
|
+
assert.equal(ticks.size, 0, "nothing stays armed once counts are complete");
|
|
407
|
+
idle.dispose();
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test("progressing line counts outlive the idle failure retry budget", () => {
|
|
411
|
+
const ticks = new Set<() => void>();
|
|
412
|
+
let pending = 6;
|
|
413
|
+
const idle = createIdleChanges({
|
|
414
|
+
isIdle: () => true,
|
|
415
|
+
refresh() {
|
|
416
|
+
const turn = idle.scanStarted();
|
|
417
|
+
pending = Math.max(0, pending - 1);
|
|
418
|
+
idle.scanFinished(pending, {}, 1, turn);
|
|
419
|
+
},
|
|
420
|
+
observeInput: () => undefined,
|
|
421
|
+
schedule(tick) {
|
|
422
|
+
ticks.add(tick);
|
|
423
|
+
return { cancel: () => { ticks.delete(tick); }, unref() {} };
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
idle.started();
|
|
427
|
+
idle.firstPaint();
|
|
428
|
+
for (let i = 0; i < 12 && ticks.size; i++) {
|
|
429
|
+
for (const tick of [...ticks]) if (ticks.delete(tick)) tick();
|
|
430
|
+
}
|
|
431
|
+
assert.equal(pending, 0);
|
|
432
|
+
assert.equal(ticks.size, 0);
|
|
433
|
+
idle.dispose();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// A pending count that moves without going down (a file rewritten while it is
|
|
437
|
+
// counted) must not keep the idle continuation alive: it continues only while
|
|
438
|
+
// the count reaches a new low.
|
|
439
|
+
test("idle continuation stops when pending counts oscillate without a new low", () => {
|
|
440
|
+
const ticks = new Set<() => void>();
|
|
441
|
+
const counts = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6];
|
|
442
|
+
let scans = 0;
|
|
443
|
+
const idle = createIdleChanges({
|
|
444
|
+
isIdle: () => true,
|
|
445
|
+
refresh() {
|
|
446
|
+
const turn = idle.scanStarted();
|
|
447
|
+
idle.scanFinished(counts[Math.min(scans++, counts.length - 1)], {}, 0, turn);
|
|
448
|
+
},
|
|
449
|
+
observeInput: () => undefined,
|
|
450
|
+
schedule(tick) {
|
|
451
|
+
ticks.add(tick);
|
|
452
|
+
return { cancel: () => { ticks.delete(tick); }, unref() {} };
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
idle.started();
|
|
456
|
+
idle.firstPaint();
|
|
457
|
+
for (let i = 0; i < 40 && ticks.size; i++) for (const tick of [...ticks]) if (ticks.delete(tick)) tick();
|
|
458
|
+
assert.equal(scans, 2, "the first pass, then the one that did not reach a new low");
|
|
459
|
+
assert.equal(ticks.size, 0);
|
|
460
|
+
idle.dispose();
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// Found by the independent verify: a root that keeps failing must not turn an
|
|
464
|
+
// unchanged pending count into endless 250 ms idle rescans.
|
|
465
|
+
test("unchanged pending counts next to a failing root stop once the retries run out", () => {
|
|
466
|
+
const ticks = new Set<() => void>();
|
|
467
|
+
let scans = 0;
|
|
468
|
+
const idle = createIdleChanges({
|
|
469
|
+
isIdle: () => true,
|
|
470
|
+
refresh() {
|
|
471
|
+
scans++;
|
|
472
|
+
const turn = idle.scanStarted();
|
|
473
|
+
idle.scanFinished(5, {}, 1, turn);
|
|
474
|
+
},
|
|
475
|
+
observeInput: () => undefined,
|
|
476
|
+
schedule(tick) {
|
|
477
|
+
ticks.add(tick);
|
|
478
|
+
return { cancel: () => { ticks.delete(tick); }, unref() {} };
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
idle.started();
|
|
482
|
+
idle.firstPaint();
|
|
483
|
+
for (let i = 0; i < 40 && ticks.size; i++) for (const tick of [...ticks]) if (ticks.delete(tick)) tick();
|
|
484
|
+
assert.ok(scans <= 5, `the first pass, the three retries, at most one pass without progress (saw ${scans})`);
|
|
485
|
+
assert.equal(ticks.size, 0);
|
|
486
|
+
idle.dispose();
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test("oscillating pending counts next to a failing root stop once the retries run out", () => {
|
|
490
|
+
const ticks = new Set<() => void>();
|
|
491
|
+
let scans = 0;
|
|
492
|
+
const idle = createIdleChanges({
|
|
493
|
+
isIdle: () => true,
|
|
494
|
+
refresh() {
|
|
495
|
+
const turn = idle.scanStarted();
|
|
496
|
+
idle.scanFinished(scans++ % 2 ? 6 : 5, {}, 1, turn);
|
|
497
|
+
},
|
|
498
|
+
observeInput: () => undefined,
|
|
499
|
+
schedule(tick) {
|
|
500
|
+
ticks.add(tick);
|
|
501
|
+
return { cancel: () => { ticks.delete(tick); }, unref() {} };
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
idle.started();
|
|
505
|
+
idle.firstPaint();
|
|
506
|
+
for (let i = 0; i < 60 && ticks.size; i++) for (const tick of [...ticks]) if (ticks.delete(tick)) tick();
|
|
507
|
+
assert.ok(scans <= 6, `bounded (saw ${scans})`);
|
|
508
|
+
assert.equal(ticks.size, 0);
|
|
509
|
+
idle.dispose();
|
|
510
|
+
});
|