gentle-pi 4.6.0 → 4.7.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 +10 -11
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +5 -2
- package/assets/agents/gentle-ai-worker.md +3 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +16 -1
- package/assets/orchestrator-delegation-reference.md +4 -4
- package/assets/orchestrator-delegation.md +1 -1
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +7 -5
- package/assets/orchestrator.md +3 -3
- package/bin/gentle-shell.mjs +164 -56
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/delegated-verification.md +29 -7
- package/docs/gentle-agents-activity.md +14 -0
- package/docs/gentle-shell.md +54 -16
- package/docs/install-wizard.md +1 -1
- package/docs/permission-modes.md +9 -4
- package/docs/readme-reference.md +75 -30
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +326 -34
- package/extensions/gentle-ai.ts +1496 -454
- package/extensions/gentle-shell.ts +293 -63
- package/extensions/gentle-todo.ts +18 -2
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +175 -18
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +46 -0
- package/lib/agents-history.ts +24 -5
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-runner.ts +183 -12
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/card-content-policy.ts +8 -6
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +270 -140
- package/lib/jobs-view.ts +198 -11
- package/lib/model-routing-authority.ts +22 -4
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +96 -19
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +46 -10
- package/lib/review-integration-v2.ts +7 -1
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/verifier-admission.ts +1 -1
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +40 -15
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +93 -16
- package/runtime/review-integration-v2.mjs +7 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +5 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/verify-package-files.mjs +12 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +178 -2
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +30 -5
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +3 -3
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1070 -12
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +113 -38
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +77 -10
- package/tests/gentle-shell.test.ts +899 -59
- package/tests/gentle-todo.test.ts +19 -2
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +176 -4
- package/tests/installer-posix-bootstrap.test.ts +1 -1
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/jobs-view.test.ts +260 -6
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +4 -1
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +3 -1
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +11 -9
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/pi-update-launcher.test.ts +8 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +1 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/skill-registry.test.ts +838 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +5 -3
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verify-first-launch-contract.test.ts +78 -3
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +28 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +23 -18
- package/tests/yolo-session-policy.test.ts +270 -1
|
@@ -6,6 +6,7 @@ import { __testing } from "../extensions/gentle-ai.ts";
|
|
|
6
6
|
import { reconcileUnknownReviewLastEventCapture } from "../lib/review-last-event-controller.ts";
|
|
7
7
|
import * as nativeReviewCliModule from "../lib/native-review-cli.ts";
|
|
8
8
|
import type { NativeReviewCli } from "../lib/native-review-cli.ts";
|
|
9
|
+
import { ReviewHostRelayError, REVIEW_HOST_RELAY_FAILURE } from "../lib/review-host-relay.ts";
|
|
9
10
|
import {
|
|
10
11
|
decodeReviewLastEventClosureV1,
|
|
11
12
|
decodeReviewStartV3,
|
|
@@ -17,6 +18,49 @@ const SHA = `sha256:${"a".repeat(64)}`;
|
|
|
17
18
|
const TREE = "b".repeat(40);
|
|
18
19
|
const CAPTURED_FIXTURES = join(process.cwd(), "tests", "fixtures", "devbinary");
|
|
19
20
|
|
|
21
|
+
test("host reviewer facts survive both ordinary capture and terminal closure without changing native output", async t => {
|
|
22
|
+
t.after(() => __testing.setReviewHostRelayRunnerForTesting());
|
|
23
|
+
for (const terminal of [false, true]) {
|
|
24
|
+
const lineageId = `facts-single-${terminal}`, input = materializeInput(lineageId);
|
|
25
|
+
const reviewer = { reviewerModel: "fixture/model", phase: "completion", usage: { input: 10 }, cost: { total: 0.01 } };
|
|
26
|
+
const native = { targetStatus: async () => status(lineageId, [input]) } as unknown as NativeReviewCli;
|
|
27
|
+
__testing.setReviewHostRelayRunnerForTesting(async () => ({ promptByteLength: 30, resultByteLength: 20, reviewerEvidence: reviewer,
|
|
28
|
+
submission: terminal ? JSON.stringify(closure("review/capture-result", lineageId)) : '{"admission_decision":"completed"}' }));
|
|
29
|
+
const result = await __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(input), reviewerRunAcknowledged: true }, process.cwd(), native);
|
|
30
|
+
assert.equal(result.outcome, terminal ? "native-last-event-closure" : "native-reviewer-result-captured");
|
|
31
|
+
assert.deepEqual((result.host_relay as any)?.reviewer, reviewer);
|
|
32
|
+
const before = structuredClone((result.host_relay as any).reviewer);
|
|
33
|
+
reviewer.usage.input = 999;
|
|
34
|
+
assert.deepEqual((result.host_relay as any).reviewer, before, "host facts are snapshots rather than a runner's mutable object");
|
|
35
|
+
if (terminal) assert.equal((result.closure as any).lineage_id, lineageId);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("group reviewer runs retain every prepared completion after early closure or later admission refusal", async t => {
|
|
40
|
+
t.after(() => __testing.setReviewHostRelayGroupRunnersForTesting());
|
|
41
|
+
for (const terminal of [true, false]) {
|
|
42
|
+
const lineageId = `facts-group-${terminal}`;
|
|
43
|
+
const inputs = Array.from({ length: 4 }, (_, index) => materializeInput(lineageId, String(index), `sha256:${String(index + 1).repeat(64)}`));
|
|
44
|
+
const facts = inputs.map((_, index) => ({ reviewerModel: `fixture/model-${index}`, phase: "completion", ...(index === 1 ? {} : { usage: { input: index + 1 }, cost: { total: 0.01 * (index + 1) } }) }));
|
|
45
|
+
let submitted = 0;
|
|
46
|
+
const native = { targetStatus: async () => ({ ...status(lineageId, inputs.slice(submitted)), repositoryContext: { capability: "review.opaque_repository_context", handle: `rctx1_${"c".repeat(64)}`, revision: SHA, targetIdentity: SHA } }) } as unknown as NativeReviewCli;
|
|
47
|
+
__testing.setReviewHostRelayGroupRunnersForTesting(async requests => requests.map((request, index) => ({ request, promptByteLength: 30, resultByteLength: 20, reviewerEvidence: facts[index] })), async () => {
|
|
48
|
+
if (submitted === 1) throw new ReviewHostRelayError(REVIEW_HOST_RELAY_FAILURE.SUBMISSION_REFUSED, "submit", "fixture refused", { mutationOutcome: "none", reviewerEvidence: facts[1] });
|
|
49
|
+
submitted++;
|
|
50
|
+
return { promptByteLength: 30, resultByteLength: 20, submission: terminal ? JSON.stringify(closure("review/capture-result", lineageId)) : '{"admission_decision":"completed"}' };
|
|
51
|
+
});
|
|
52
|
+
const result = await __testing.executeReviewCaptureGroupOperation({ lineageId, collectBindings: inputs, reviewerRunAcknowledged: true }, process.cwd(), native);
|
|
53
|
+
assert.equal(result.submitted_reviewers, 1, JSON.stringify(result)); assert.equal(result.prepared_reviewers, 4);
|
|
54
|
+
const diagnostics = result.host_relay as any;
|
|
55
|
+
assert.equal(diagnostics.reviewers.length, 1, "legacy reviewer diagnostics remain limited to confirmed submissions");
|
|
56
|
+
assert.equal(diagnostics.reviewer_runs.length, 4, "all prepared completions already spent their reported usage");
|
|
57
|
+
assert.deepEqual(diagnostics.reviewer_runs.map((run: any) => run.reviewer), facts);
|
|
58
|
+
assert.equal(Object.hasOwn(diagnostics.reviewer_runs[1].reviewer, "usage"), false, "missing usage remains unknown");
|
|
59
|
+
assert.equal(Object.hasOwn(diagnostics.reviewers[0], "reviewer"), false, "do not copy cost into both legacy and run diagnostics");
|
|
60
|
+
assert.equal(result.outcome, terminal ? "native-last-event-closure" : "pi-host-relay-transport-failure");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
20
64
|
function captured(name: string): unknown {
|
|
21
65
|
return JSON.parse(readFileSync(join(CAPTURED_FIXTURES, name), "utf8"));
|
|
22
66
|
}
|
|
@@ -492,6 +536,30 @@ test("refuter and validation each execute one self-contained provider vector", a
|
|
|
492
536
|
}
|
|
493
537
|
});
|
|
494
538
|
|
|
539
|
+
test("public STATUS retains only the original opaque binding projection", async () => {
|
|
540
|
+
const lineageId = "validation-projection";
|
|
541
|
+
const input = roleInput(lineageId, "review.capture-validation");
|
|
542
|
+
const native = { targetStatus: async () => status(lineageId, [input]),
|
|
543
|
+
reviewMode: async () => ({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "", effective: "on", source: "global" } }),
|
|
544
|
+
} as unknown as NativeReviewCli;
|
|
545
|
+
const result = await __testing.executeReviewControllerOperation({ operation: "status", lineageId }, process.cwd(), native);
|
|
546
|
+
const entries = result.collectBindings as Array<{ collectBinding: string }>;
|
|
547
|
+
assert.equal(entries.length, 1);
|
|
548
|
+
assert.deepEqual(Object.keys(entries[0]), ["collectBinding"]);
|
|
549
|
+
assert.deepEqual(JSON.parse(entries[0].collectBinding), input);
|
|
550
|
+
assert.equal((entries[0] as Record<string, unknown>).forecast, undefined, "legacy execute vectors keep their existing route");
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
test("public correction STATUS adds no inferred input metadata", async () => {
|
|
554
|
+
const lineageId = "authored-plan-metadata";
|
|
555
|
+
const input = correctionPlanInput(lineageId);
|
|
556
|
+
const native = { targetStatus: async () => status(lineageId, [input]) } as unknown as NativeReviewCli;
|
|
557
|
+
const result = await __testing.executeReviewControllerOperation({ operation: "status", lineageId }, process.cwd(), native);
|
|
558
|
+
const entries = result.collectBindings as Array<{ collectBinding: string }>;
|
|
559
|
+
assert.deepEqual(Object.keys(entries[0]), ["collectBinding"]);
|
|
560
|
+
assert.deepEqual(JSON.parse(entries[0].collectBinding), input);
|
|
561
|
+
});
|
|
562
|
+
|
|
495
563
|
test("terminal capture closes directly, nonterminal capture does not auto-follow, and unknown mutation reconciles once", async (t) => {
|
|
496
564
|
t.after(() => __testing.setReviewHostRelayRunnerForTesting());
|
|
497
565
|
const lineageId = "closure-behavior";
|
|
@@ -7,9 +7,8 @@ import test from "node:test";
|
|
|
7
7
|
import type { AssistantMessage, JsonObject, Tool, ToolCall } from "@earendil-works/pi-ai";
|
|
8
8
|
import type { NativeReviewCli } from "../lib/native-review-cli.ts";
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// guideline and leaves the capture, capture-group, and scope declarations out.
|
|
10
|
+
// With receipt-driven development off, the parent request does not require
|
|
11
|
+
// ASSESS and leaves the capture, capture-group, and scope declarations out.
|
|
13
12
|
// With RDD on, the request is exactly what the registered tools declare. Both
|
|
14
13
|
// paths run through a real Pi SDK session and inspect the provider request.
|
|
15
14
|
|
|
@@ -20,6 +19,7 @@ interface SessionRun {
|
|
|
20
19
|
requests: RecordedRequest[];
|
|
21
20
|
registered: Map<string, { description: string; promptGuidelines?: readonly string[] }>;
|
|
22
21
|
assessResults: Array<{ isError: boolean; details: unknown }>;
|
|
22
|
+
nativeCalls: { mode: number; assess: number; target: number };
|
|
23
23
|
errors: string[];
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -31,24 +31,29 @@ const NATIVE_CONTINUATION = {
|
|
|
31
31
|
arguments: [{ name: "--agent", value: "pi" }, { name: "--next-transition" }],
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
function nativeCli(mode: () => RddMode): NativeReviewCli {
|
|
34
|
+
function nativeCli(mode: () => RddMode, calls: SessionRun["nativeCalls"]): NativeReviewCli {
|
|
35
35
|
return {
|
|
36
36
|
reviewMode: async () => {
|
|
37
|
+
calls.mode++;
|
|
37
38
|
const effective = mode();
|
|
38
39
|
if (effective === "throws") throw new Error("native review mode is unavailable");
|
|
39
40
|
return { operation: "status", scope: "clone", status: { global: effective, cloneLocal: "", effective, source: "global" } };
|
|
40
41
|
},
|
|
41
|
-
assess: async () =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
assess: async () => {
|
|
43
|
+
calls.assess++;
|
|
44
|
+
return {
|
|
45
|
+
schema: "gentle-ai.review-assessment/v1",
|
|
46
|
+
risk: "high",
|
|
47
|
+
reviewDue: true,
|
|
48
|
+
reviewDueReason: "high_risk",
|
|
49
|
+
nextTransition: NATIVE_CONTINUATION,
|
|
50
|
+
reasons: [],
|
|
51
|
+
changedPaths: 1,
|
|
52
|
+
changedLines: 3,
|
|
53
|
+
candidate: { kind: "current-changes", baseRef: undefined },
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
targetStatus: async () => { calls.target++; return { applicability: "current_target", targetIdentity: "fixture" }; },
|
|
52
57
|
} as unknown as NativeReviewCli;
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -66,9 +71,9 @@ async function runSession(
|
|
|
66
71
|
mkdirSync(cwd);
|
|
67
72
|
const gitEnv = { PATH: process.env.PATH, HOME: root, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: join(root, "gitconfig") };
|
|
68
73
|
writeFileSync(gitEnv.GIT_CONFIG_GLOBAL, "");
|
|
74
|
+
// The stubbed review client needs a repository root, not a committed candidate.
|
|
69
75
|
execFileSync("git", ["init", "--initial-branch=fixture"], { cwd, env: gitEnv, stdio: "ignore" });
|
|
70
|
-
|
|
71
|
-
const run: SessionRun = { requests: [], registered: new Map(), assessResults: [], errors: [] };
|
|
76
|
+
const run: SessionRun = { requests: [], registered: new Map(), assessResults: [], nativeCalls: { mode: 0, assess: 0, target: 0 }, errors: [] };
|
|
72
77
|
let next: { name: string; arguments: JsonObject } | undefined;
|
|
73
78
|
let calls = 0;
|
|
74
79
|
const model = { id: "driver", name: "Local driver", provider: "loadout-fixture", api: "loadout-fixture", baseUrl: "http://invalid.local", reasoning: false, input: ["text"], contextWindow: 1_000_000, maxTokens: 1024, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } as const;
|
|
@@ -85,7 +90,7 @@ async function runSession(
|
|
|
85
90
|
return registerTool(definition as never);
|
|
86
91
|
}) as typeof pi.registerTool;
|
|
87
92
|
createGentleAiExtension({
|
|
88
|
-
nativeReviewCli: nativeCli(mode),
|
|
93
|
+
nativeReviewCli: nativeCli(mode, run.nativeCalls),
|
|
89
94
|
candidateViews: null,
|
|
90
95
|
processEnv: { ...bindings, GENTLE_AI_TELEMETRY: "0" },
|
|
91
96
|
resolveTelemetryTriggerBinary: () => { throw new Error("fixture"); },
|
|
@@ -140,7 +145,7 @@ async function runSession(
|
|
|
140
145
|
return run;
|
|
141
146
|
}
|
|
142
147
|
|
|
143
|
-
const LEAN_GUIDELINE = /
|
|
148
|
+
const LEAN_GUIDELINE = /RDD off does not require an assessment/;
|
|
144
149
|
|
|
145
150
|
function fixture(t: { after: (fn: () => void) => void }): { root: string; bindings: Record<string, string> } {
|
|
146
151
|
const root = realpathSync(mkdtempSync(join(tmpdir(), "gentle-review-loadout-")));
|
|
@@ -171,10 +176,8 @@ function registeredGuidelines(run: SessionRun): string[] {
|
|
|
171
176
|
function assertLeanRequest(request: RecordedRequest, run: SessionRun): void {
|
|
172
177
|
assert.match(request.systemPrompt, /Receipt-driven development: off /);
|
|
173
178
|
assert.match(request.systemPrompt, LEAN_GUIDELINE);
|
|
174
|
-
assert.
|
|
175
|
-
assert.match(request.systemPrompt, /
|
|
176
|
-
assert.doesNotMatch(request.systemPrompt, /relay it unchanged and follow it/);
|
|
177
|
-
assert.match(request.systemPrompt, /Continue the returned verification plan/);
|
|
179
|
+
assert.doesNotMatch(request.systemPrompt, /after an authorized implementation, delegated or inline, call it over the diff/);
|
|
180
|
+
assert.match(request.systemPrompt, /named Task Size high-risk item still requires one independent verifier/);
|
|
178
181
|
assert.match(request.systemPrompt, /tests, builds, and functional checks still run/);
|
|
179
182
|
for (const guideline of registeredGuidelines(run)) assert.equal(request.systemPrompt.includes(guideline), false, `RDD off must leave out: ${guideline.slice(0, 80)}`);
|
|
180
183
|
const names = request.tools.map((tool) => tool.name);
|
|
@@ -193,7 +196,7 @@ function assertRegisteredRequest(request: RecordedRequest, run: SessionRun): voi
|
|
|
193
196
|
}
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
test("RDD off: the parent request
|
|
199
|
+
test("RDD off: the parent request does not mandate ASSESS; RDD on keeps the registered review loadout", { timeout: 30_000 }, async (t) => {
|
|
197
200
|
const { root, bindings } = fixture(t);
|
|
198
201
|
const off = await runSession(root, "off", bindings, () => "off");
|
|
199
202
|
const on = await runSession(root, "on", bindings, () => "on");
|
|
@@ -211,9 +214,11 @@ test("RDD off: the parent request carries only the lean ASSESS loadout; RDD on:
|
|
|
211
214
|
assert.equal((off.assessResults[0].details as { schema?: string }).schema, "gentle-pi.review-assessment-plan/v1");
|
|
212
215
|
const plan = off.assessResults[0].details as Record<string, unknown>;
|
|
213
216
|
assert.equal(plan.rddLine, "off");
|
|
214
|
-
assert.equal(plan.
|
|
215
|
-
assert.equal(plan.
|
|
216
|
-
assert.
|
|
217
|
+
assert.equal(plan.nativeRisk, "unassessable");
|
|
218
|
+
assert.equal(plan.candidate, null);
|
|
219
|
+
for (const field of ["reviewDue", "reviewDueReason", "nextTransition"]) assert.equal(Object.hasOwn(plan, field), false);
|
|
220
|
+
assert.equal(off.nativeCalls.assess, 0);
|
|
221
|
+
assert.equal(off.nativeCalls.target, 0);
|
|
217
222
|
assert.equal((plan.plan as Record<string, unknown>).writerSelfVerification, true);
|
|
218
223
|
assert.equal((plan.plan as Record<string, unknown>).independentVerifier, true);
|
|
219
224
|
|
|
@@ -223,6 +228,9 @@ test("RDD off: the parent request carries only the lean ASSESS loadout; RDD on:
|
|
|
223
228
|
}
|
|
224
229
|
assert.equal(on.assessResults.length, 1);
|
|
225
230
|
assert.equal(on.assessResults[0].isError, false);
|
|
231
|
+
assert.equal(on.nativeCalls.assess, 1);
|
|
232
|
+
assert.equal(on.nativeCalls.target, 1);
|
|
233
|
+
assert.deepEqual((on.assessResults[0].details as Record<string, unknown>).nextTransition, NATIVE_CONTINUATION);
|
|
226
234
|
|
|
227
235
|
const bytes = (request: RecordedRequest) => ({
|
|
228
236
|
systemPrompt: Buffer.byteLength(request.systemPrompt),
|
|
@@ -244,15 +252,41 @@ test("an unknown RDD line keeps the registered loadout; turning RDD on mid-sessi
|
|
|
244
252
|
assert.match(request.systemPrompt, /Receipt-driven development: unknown/);
|
|
245
253
|
assertRegisteredRequest(request, unknown);
|
|
246
254
|
}
|
|
255
|
+
assert.equal(unknown.nativeCalls.assess, 1);
|
|
256
|
+
assert.equal(unknown.nativeCalls.target, 1);
|
|
247
257
|
|
|
248
258
|
let mode: RddMode = "off";
|
|
249
|
-
const flipped = await runSession(root, "flip", bindings, () => mode, () => {
|
|
250
|
-
mode = "on";
|
|
251
|
-
__testing.clearRddStatusMemoForTesting();
|
|
252
|
-
});
|
|
259
|
+
const flipped = await runSession(root, "flip", bindings, () => mode, () => { mode = "on"; });
|
|
253
260
|
assert.deepEqual(flipped.errors, []);
|
|
254
261
|
const last = flipped.requests.at(-1)!;
|
|
255
262
|
for (const request of flipped.requests.slice(0, -1)) assertLeanRequest(request, flipped);
|
|
256
263
|
assert.match(last.systemPrompt, /Receipt-driven development: on /);
|
|
257
264
|
assertRegisteredRequest(last, flipped);
|
|
265
|
+
|
|
266
|
+
mode = "off";
|
|
267
|
+
const failed = await runSession(root, "failed-after-off", bindings, () => mode, () => { mode = "throws"; });
|
|
268
|
+
assert.deepEqual(failed.errors, []);
|
|
269
|
+
assert.match(failed.requests.at(-1)!.systemPrompt, /Receipt-driven development: unknown/);
|
|
270
|
+
assertRegisteredRequest(failed.requests.at(-1)!, failed);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("malformed fresh reads restore guidance while on and unknown preserve pinning", { timeout: 30_000 }, async (t) => {
|
|
274
|
+
const { root, bindings } = fixture(t);
|
|
275
|
+
for (const [initial, next, expected] of [["off", "malformed", "unknown"], ["on", "throws", "on"], ["throws", "on", "unknown"]] as const) {
|
|
276
|
+
let mode: RddMode = initial;
|
|
277
|
+
const run = await runSession(root, `independent-${initial}`, bindings, () => mode, () => { mode = next as RddMode; });
|
|
278
|
+
assert.deepEqual(run.errors, []);
|
|
279
|
+
assert.match(run.requests.at(-1)!.systemPrompt, new RegExp(`Receipt-driven development: ${expected}`));
|
|
280
|
+
assertRegisteredRequest(run.requests.at(-1)!, run);
|
|
281
|
+
if (initial === "off") {
|
|
282
|
+
assertLeanRequest(run.requests[0], run);
|
|
283
|
+
assert.equal(run.nativeCalls.assess, 0);
|
|
284
|
+
assert.equal(run.nativeCalls.target, 0);
|
|
285
|
+
} else {
|
|
286
|
+
assert.equal(run.nativeCalls.assess, 1);
|
|
287
|
+
assert.equal(run.nativeCalls.target, 1);
|
|
288
|
+
assert.equal(new Set(run.requests.map((request) => request.systemPrompt)).size, 1);
|
|
289
|
+
}
|
|
290
|
+
t.diagnostic(JSON.stringify({ initial, next, expected, requests: run.requests.length, calls: run.nativeCalls, errors: run.errors }));
|
|
291
|
+
}
|
|
258
292
|
});
|
|
@@ -5,7 +5,7 @@ import fs from "node:fs";
|
|
|
5
5
|
import { syncBuiltinESMExports } from "node:module";
|
|
6
6
|
import { dirname, join, resolve } from "node:path";
|
|
7
7
|
import test from "node:test";
|
|
8
|
-
import { createCandidateOwner, prepareCandidateOwnerParent } from "../lib/review-candidate-view-owner.ts";
|
|
8
|
+
import { createCandidateOwner, prepareCandidateOwnerParent, WindowsOwnerValidationError } from "../lib/review-candidate-view-owner.ts";
|
|
9
9
|
|
|
10
10
|
function fixture(t: test.TestContext) {
|
|
11
11
|
fs.mkdirSync(resolve("tmp"), { recursive: true });
|
|
@@ -17,7 +17,9 @@ function fixture(t: test.TestContext) {
|
|
|
17
17
|
let user = "S-1-5-21-1-2-3-1001";
|
|
18
18
|
let identityFailure = "";
|
|
19
19
|
let replacedMarker = false;
|
|
20
|
-
|
|
20
|
+
let whoamiUser: string | undefined;
|
|
21
|
+
let foreignPath: string | undefined;
|
|
22
|
+
const probes = { user: 0, whoami: 0, administrator: 0, owner: [] as string[], dacl: [] as string[], enforce: [] as string[], sddl: [] as string[] };
|
|
21
23
|
const native = fs.realpathSync.native;
|
|
22
24
|
t.mock.method(fs.realpathSync, "native", (path: string) =>
|
|
23
25
|
path.startsWith("\\\\?\\GLOBALROOT\\SystemRoot\\System32") ? path : native(path));
|
|
@@ -25,29 +27,33 @@ function fixture(t: test.TestContext) {
|
|
|
25
27
|
const name = command.split(/[\\/]/).at(-1);
|
|
26
28
|
if (name === "whoami.exe") {
|
|
27
29
|
probes.user++;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (name === "icacls.exe") {
|
|
31
|
-
probes.dacl.push(args[0]);
|
|
32
|
-
const directory = fs.lstatSync(args[0]).isDirectory();
|
|
33
|
-
const flags = directory ? "OICI" : "ID";
|
|
34
|
-
const dacl = `D:${directory ? "P" : ""}(A;${flags};FA;;;${user})(A;${flags};FA;;;SY)(A;${flags};FA;;;BA)`;
|
|
35
|
-
fs.writeFileSync(join(options.cwd, args[2]), dacl, "utf16le");
|
|
36
|
-
return "";
|
|
30
|
+
probes.whoami++;
|
|
31
|
+
return identityFailure === "user" ? "unavailable" : whoamiUser ?? user;
|
|
37
32
|
}
|
|
38
33
|
if (name === "powershell.exe") {
|
|
39
34
|
const script = Buffer.from(args.at(-1)!, "base64").toString("utf16le");
|
|
40
|
-
if (script.includes("
|
|
35
|
+
if (script.includes("gentle-pi.windows-acl-probe/v1")) {
|
|
36
|
+
probes.user++;
|
|
37
|
+
if (identityFailure === "user") throw Object.assign(new Error("fixture user unavailable"), { code: "EACCES" });
|
|
41
38
|
probes.administrator++;
|
|
42
|
-
|
|
39
|
+
if (identityFailure === "administrator") throw Object.assign(new Error("fixture administrator unavailable"), { code: "EACCES" });
|
|
40
|
+
const requests = JSON.parse(options.input) as { path: string; kind: string }[];
|
|
41
|
+
return JSON.stringify({ schema: "gentle-pi.windows-acl-probe/v1", user, localAdministrator: "S-1-5-21-1-2-3-500", entries: requests.map((request, index) => {
|
|
42
|
+
probes.owner.push(request.path); probes.dacl.push(request.path);
|
|
43
|
+
const directory = request.kind === "directory";
|
|
44
|
+
const flags = directory ? "OICI" : "ID";
|
|
45
|
+
return { index, owner: (replacedMarker && request.path.endsWith(".owner.json")) || request.path === foreignPath ? "S-1-5-21-9-8-7-1002" : user,
|
|
46
|
+
dacl: `D:${directory ? "P" : ""}(A;${flags};FA;;;${user})(A;${flags};FA;;;SY)(A;${flags};FA;;;BA)` };
|
|
47
|
+
}) });
|
|
43
48
|
}
|
|
44
49
|
if (script.includes("SetAccessControl")) {
|
|
45
50
|
probes.enforce.push(options.env.GENTLE_PI_CANDIDATE_ACL_PATH);
|
|
51
|
+
probes.sddl.push(options.env.GENTLE_PI_CANDIDATE_ACL_SDDL);
|
|
46
52
|
return "";
|
|
47
53
|
}
|
|
48
54
|
const path = options.env.GENTLE_PI_CANDIDATE_OWNER_PATH;
|
|
49
55
|
probes.owner.push(path);
|
|
50
|
-
return replacedMarker && path.endsWith(".owner.json") ? "S-1-5-21-9-8-7-1002" : user;
|
|
56
|
+
return (replacedMarker && path.endsWith(".owner.json")) || path === foreignPath ? "S-1-5-21-9-8-7-1002" : user;
|
|
51
57
|
}
|
|
52
58
|
throw new Error(`Unexpected subprocess: ${name}`);
|
|
53
59
|
});
|
|
@@ -60,10 +66,12 @@ function fixture(t: test.TestContext) {
|
|
|
60
66
|
return { commonDir, parent, boundary, probes,
|
|
61
67
|
changeUser: () => { user = "S-1-5-21-4-5-6-1002"; },
|
|
62
68
|
failIdentity: (kind: string) => { identityFailure = kind; },
|
|
69
|
+
disagreeWhoami: () => { whoamiUser = "S-1-5-21-7-7-7-1003"; },
|
|
70
|
+
foreignOwner: (path: string) => { foreignPath = path; },
|
|
63
71
|
replaceMarker: () => { replacedMarker = true; } };
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
test("Windows creation
|
|
74
|
+
test("Windows creation refreshes identity at each boundary and preserves every filesystem probe", (t) => {
|
|
67
75
|
const f = fixture(t);
|
|
68
76
|
for (let operation = 1; operation <= 2; operation++) {
|
|
69
77
|
if (operation === 2) f.changeUser();
|
|
@@ -73,8 +81,8 @@ test("Windows creation reuses identity only within one operation and preserves e
|
|
|
73
81
|
assert.equal(owner.root, root);
|
|
74
82
|
assert.deepEqual(JSON.parse(fs.readFileSync(marker, "utf8")), owner);
|
|
75
83
|
assert.equal(fs.existsSync(root), false);
|
|
76
|
-
assert.equal(f.probes.user, operation, "
|
|
77
|
-
assert.equal(f.probes.administrator, operation, "
|
|
84
|
+
assert.equal(f.probes.user, operation * 2, "fresh user SID at the parent batch and marker boundary");
|
|
85
|
+
assert.equal(f.probes.administrator, operation * 2, "fresh administrator SID at the parent batch and marker boundary");
|
|
78
86
|
assert.deepEqual(f.probes.owner.slice((operation - 1) * 4), [...f.boundary, marker]);
|
|
79
87
|
assert.deepEqual(f.probes.dacl.slice((operation - 1) * 4), [...f.boundary, marker]);
|
|
80
88
|
assert.deepEqual(f.probes.enforce, []);
|
|
@@ -84,13 +92,41 @@ test("Windows creation reuses identity only within one operation and preserves e
|
|
|
84
92
|
test("Windows preparation retains fresh pre-write and post-write owner/DACL checks", (t) => {
|
|
85
93
|
const f = fixture(t);
|
|
86
94
|
assert.equal(prepareCandidateOwnerParent(f.commonDir, "win32"), f.parent);
|
|
87
|
-
assert.equal(f.probes.user,
|
|
88
|
-
assert.equal(f.probes.
|
|
95
|
+
assert.equal(f.probes.user, 4, "one pre-write identity batch plus one fresh read-back per directory");
|
|
96
|
+
assert.equal(f.probes.whoami, 0);
|
|
97
|
+
assert.equal(f.probes.administrator, 4);
|
|
89
98
|
assert.deepEqual(f.probes.owner, [...f.boundary, ...f.boundary.flatMap(path => [path, path])]);
|
|
90
|
-
|
|
99
|
+
// The pre-write batch observes the DACLs it is about to replace; only the
|
|
100
|
+
// read-back observations are validated as private.
|
|
101
|
+
assert.deepEqual(f.probes.dacl, [...f.boundary, ...f.boundary]);
|
|
91
102
|
assert.deepEqual(f.probes.enforce, f.boundary);
|
|
92
103
|
});
|
|
93
104
|
|
|
105
|
+
test("Windows preparation takes its identity from the probe that reads owners back", (t) => {
|
|
106
|
+
const f = fixture(t);
|
|
107
|
+
// whoami and the .NET token can only disagree in theory; preparation must
|
|
108
|
+
// not depend on a second identity source it never re-reads.
|
|
109
|
+
f.disagreeWhoami();
|
|
110
|
+
assert.equal(prepareCandidateOwnerParent(f.commonDir, "win32"), f.parent);
|
|
111
|
+
assert.equal(f.probes.whoami, 0);
|
|
112
|
+
assert.deepEqual(f.probes.enforce, f.boundary);
|
|
113
|
+
for (const sddl of f.probes.sddl) assert.match(sddl, /^D:P\(A;OICI;FA;;;S-1-5-21-1-2-3-1001\)/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
for (const index of [0, 1, 2]) test(`Windows preparation rejects a foreign owner at boundary ${index} before rewriting any DACL`, (t) => {
|
|
117
|
+
const f = fixture(t);
|
|
118
|
+
f.foreignOwner(f.boundary[index]!);
|
|
119
|
+
assert.throws(() => prepareCandidateOwnerParent(f.commonDir, "win32"), WindowsOwnerValidationError);
|
|
120
|
+
assert.deepEqual(f.probes.enforce, []);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
for (const kind of ["user", "administrator"]) test(`Windows preparation fails closed on ${kind} identity failure before rewriting any DACL`, (t) => {
|
|
124
|
+
const f = fixture(t);
|
|
125
|
+
f.failIdentity(kind);
|
|
126
|
+
assert.throws(() => prepareCandidateOwnerParent(f.commonDir, "win32"), WindowsOwnerValidationError);
|
|
127
|
+
assert.deepEqual(f.probes.enforce, []);
|
|
128
|
+
});
|
|
129
|
+
|
|
94
130
|
for (const kind of ["user", "administrator"]) test(`Windows creation fails closed on fresh ${kind} identity failure`, (t) => {
|
|
95
131
|
const f = fixture(t);
|
|
96
132
|
const first = createCandidateOwner(f.commonDir, join(f.parent, randomUUID()), "win32");
|
|
@@ -99,7 +135,7 @@ for (const kind of ["user", "administrator"]) test(`Windows creation fails close
|
|
|
99
135
|
const stored = fs.readdirSync(f.parent);
|
|
100
136
|
f.failIdentity(kind);
|
|
101
137
|
const root = join(f.parent, randomUUID());
|
|
102
|
-
assert.throws(() => createCandidateOwner(f.commonDir, root, "win32"),
|
|
138
|
+
assert.throws(() => createCandidateOwner(f.commonDir, root, "win32"), WindowsOwnerValidationError);
|
|
103
139
|
assert.equal(fs.existsSync(root), false);
|
|
104
140
|
assert.equal(fs.existsSync(`${root}.owner.json`), false);
|
|
105
141
|
assert.equal(fs.readFileSync(marker, "utf8"), before);
|
|
@@ -122,10 +158,10 @@ test("Windows creation rollback rechecks a replaced marker owner before removal"
|
|
|
122
158
|
});
|
|
123
159
|
syncBuiltinESMExports();
|
|
124
160
|
assert.throws(() => createCandidateOwner(f.commonDir, root, "win32"), /fixture write failure/);
|
|
125
|
-
assert.equal(f.probes.user,
|
|
126
|
-
assert.equal(f.probes.administrator,
|
|
161
|
+
assert.equal(f.probes.user, 3, "rollback obtains another fresh identity observation");
|
|
162
|
+
assert.equal(f.probes.administrator, 3);
|
|
127
163
|
assert.deepEqual(f.probes.owner, [...f.boundary, marker, marker]);
|
|
128
|
-
assert.deepEqual(f.probes.dacl, [...f.boundary, marker]);
|
|
164
|
+
assert.deepEqual(f.probes.dacl, [...f.boundary, marker, marker]);
|
|
129
165
|
assert.equal(fs.existsSync(marker), true, "unproven marker survives rollback");
|
|
130
166
|
assert.equal(fs.readFileSync(marker, "utf8"), "");
|
|
131
167
|
assert.equal(fs.existsSync(root), false);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import childProcess from "node:child_process";
|
|
3
|
+
import { EventEmitter } from "node:events";
|
|
4
|
+
import fsPromises from "node:fs/promises";
|
|
5
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import test from "node:test";
|
|
8
|
+
import { PassThrough } from "node:stream";
|
|
9
|
+
import { observeReviewRelayPhase, type ReviewRelayPhaseObserver, type ReviewRelayPhaseTiming } from "../lib/review-relay-phase-timing.ts";
|
|
10
|
+
import { runReviewHostRelaySlot, type ReviewHostRelayRequest, ReviewHostRelayError } from "../lib/review-host-relay.ts";
|
|
11
|
+
import type { runInProcessReviewer } from "../lib/inprocess-reviewer.ts";
|
|
12
|
+
|
|
13
|
+
test("disabled observation adds no clock reads and preserves operation settlement", async () => {
|
|
14
|
+
const value = {};
|
|
15
|
+
assert.equal(await observeReviewRelayPhase(undefined, "materialize", async () => value, undefined, () => { throw new Error("must not read clock"); }), value);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("monotonic intervals report only the minimal immutable sample", async () => {
|
|
19
|
+
const samples: ReviewRelayPhaseTiming[] = [], ticks = [12, 39];
|
|
20
|
+
const result = await observeReviewRelayPhase(sample => { samples.push(sample); }, "submit", async () => "private-output", undefined, () => ticks.shift()!);
|
|
21
|
+
assert.equal(result, "private-output");
|
|
22
|
+
assert.deepEqual(samples, [{ phase: "submit", duration_ms: 27, outcome: "success" }]);
|
|
23
|
+
assert.equal(Object.isFrozen(samples[0]), true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("throwing, rejecting and never-settling observers preserve values and original failures", async t => {
|
|
27
|
+
for (const observer of [() => { throw new Error("observer"); }, () => Promise.reject(new Error("observer")), () => new Promise(() => {})]) {
|
|
28
|
+
await t.test(String(observer), { timeout: 1000 }, async () => {
|
|
29
|
+
const value = {}, failure = new Error("primary");
|
|
30
|
+
assert.equal(await observeReviewRelayPhase(observer, "materialize", async () => value), value);
|
|
31
|
+
await assert.rejects(observeReviewRelayPhase(observer, "cleanup", async () => { throw failure; }), error => error === failure);
|
|
32
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("unavailable or backwards clocks omit samples without changing the operation", async () => {
|
|
38
|
+
for (const ticks of [[NaN, 5], [7, 3], [Infinity, 5]]) {
|
|
39
|
+
const samples: ReviewRelayPhaseTiming[] = [];
|
|
40
|
+
assert.equal(await observeReviewRelayPhase(sample => samples.push(sample), "submit", async () => 42, undefined, () => ticks.shift()!), 42);
|
|
41
|
+
assert.deepEqual(samples, []);
|
|
42
|
+
}
|
|
43
|
+
assert.equal(await observeReviewRelayPhase(() => { throw new Error("not observed"); }, "submit", async () => 42, undefined, () => { throw new Error("clock"); }), 42);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function fakeRelay(t: test.TestContext, options: { materializeFail?: boolean; submitFail?: boolean; cleanupFail?: boolean; launchFail?: boolean } = {}) {
|
|
47
|
+
const original = { spawn: childProcess.spawn, mkdtemp: fsPromises.mkdtemp, chmod: fsPromises.chmod, writeFile: fsPromises.writeFile, rm: fsPromises.rm };
|
|
48
|
+
const invocations: string[][] = [];
|
|
49
|
+
let submissions = 0, cleaned = 0, reviewerCalls = 0;
|
|
50
|
+
const bytes: Buffer[] = [];
|
|
51
|
+
childProcess.spawn = ((_file: string, argv: string[]) => {
|
|
52
|
+
invocations.push([...argv]);
|
|
53
|
+
if (options.launchFail) throw new Error("private-launch-message");
|
|
54
|
+
const child = Object.assign(new EventEmitter(), { stdout: new PassThrough(), stderr: new PassThrough(), stdin: new PassThrough(), kill: () => true });
|
|
55
|
+
queueMicrotask(() => {
|
|
56
|
+
const materialize = argv.includes("--materialize=true");
|
|
57
|
+
if (!materialize) submissions++;
|
|
58
|
+
const failed = materialize ? options.materializeFail : options.submitFail;
|
|
59
|
+
child.stdout.write(failed ? "" : materialize ? "private-prompt" : "private-admission-output");
|
|
60
|
+
if (failed) child.stderr.write("private-provider-refusal [invalid_request]");
|
|
61
|
+
child.emit("close", failed ? 1 : 0);
|
|
62
|
+
});
|
|
63
|
+
return child;
|
|
64
|
+
}) as unknown as typeof childProcess.spawn;
|
|
65
|
+
fsPromises.mkdtemp = (async () => join(process.cwd(), "private-fixture-path")) as unknown as typeof fsPromises.mkdtemp;
|
|
66
|
+
fsPromises.chmod = async () => {};
|
|
67
|
+
fsPromises.writeFile = (async (_path: unknown, data: Buffer) => { bytes.push(Buffer.from(data)); }) as unknown as typeof fsPromises.writeFile;
|
|
68
|
+
fsPromises.rm = async () => { cleaned++; if (options.cleanupFail) throw new Error("private-cleanup-message"); };
|
|
69
|
+
syncBuiltinESMExports();
|
|
70
|
+
t.after(() => { Object.assign(childProcess, { spawn: original.spawn }); Object.assign(fsPromises, { mkdtemp: original.mkdtemp, chmod: original.chmod, writeFile: original.writeFile, rm: original.rm }); syncBuiltinESMExports(); });
|
|
71
|
+
const request: ReviewHostRelayRequest = {
|
|
72
|
+
captureArgumentTokens: ["--materialize=true", "--private-binding=secret"],
|
|
73
|
+
submission: { operationToken: "capture-result", argumentTokens: ["--input={{value}}"], values: [{ slot: "reviewer_result", domain: "artifact_path_or_stdin", substitutionLocation: 0 }] },
|
|
74
|
+
gentleAiExecutable: process.execPath,
|
|
75
|
+
targetCwd: process.cwd(),
|
|
76
|
+
reviewerRegistry: {
|
|
77
|
+
find: () => ({ id: "private-model", provider: "private-provider", api: "openai-responses", reasoning: false }) as never,
|
|
78
|
+
getApiKeyAndHeaders: async () => ({ ok: true, apiKey: "private-credential" }),
|
|
79
|
+
},
|
|
80
|
+
selection: "private-provider/private-model",
|
|
81
|
+
environment: { PRIVATE_CREDENTIAL: "private-credential" },
|
|
82
|
+
};
|
|
83
|
+
const runReviewer = (async () => { reviewerCalls++; return { kind: "text", text: "private-reviewer-output", reviewerModel: "private-model" }; }) as typeof runInProcessReviewer;
|
|
84
|
+
return { run: (observePhase?: ReviewRelayPhaseObserver) => runReviewHostRelaySlot({ ...request, ...(observePhase === undefined ? {} : { observePhase }) }, runReviewer), state: () => ({ submissions, cleaned, reviewerCalls, bytes, invocations }) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
test("relay reports materialize, submit and cleanup success without exposing payload or binding data", async t => {
|
|
88
|
+
const relay = fakeRelay(t), samples: ReviewRelayPhaseTiming[] = [];
|
|
89
|
+
const result = await relay.run(sample => samples.push(sample));
|
|
90
|
+
assert.deepEqual(result, { promptByteLength: Buffer.byteLength("private-prompt"), resultByteLength: Buffer.byteLength("private-reviewer-output"), submission: "private-admission-output" });
|
|
91
|
+
assert.deepEqual(samples.map(({ phase, outcome }) => ({ phase, outcome })), ["materialize", "submit", "cleanup"].map(phase => ({ phase, outcome: "success" })));
|
|
92
|
+
for (const sample of samples) {
|
|
93
|
+
assert.deepEqual(Object.keys(sample).sort(), ["duration_ms", "outcome", "phase"]);
|
|
94
|
+
assert.ok(Number.isFinite(sample.duration_ms) && sample.duration_ms >= 0);
|
|
95
|
+
}
|
|
96
|
+
assert.doesNotMatch(JSON.stringify(samples), /private|secret|credential|binding|prompt|output/);
|
|
97
|
+
assert.equal(relay.state().submissions, 1);
|
|
98
|
+
assert.deepEqual(relay.state().bytes, [Buffer.from("private-reviewer-output")]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
for (const options of [{ materializeFail: true }, { launchFail: true }, { submitFail: true }, { cleanupFail: true }, { submitFail: true, cleanupFail: true }]) {
|
|
102
|
+
test(`relay reports phase failures and keeps original refusal/cleanup precedence: ${JSON.stringify(options)}`, async t => {
|
|
103
|
+
const relay = fakeRelay(t, options), samples: ReviewRelayPhaseTiming[] = [];
|
|
104
|
+
let caught: unknown;
|
|
105
|
+
try { await relay.run(sample => samples.push(sample)); } catch (error) { caught = error; }
|
|
106
|
+
assert.ok(caught instanceof ReviewHostRelayError);
|
|
107
|
+
const materializeFailed = options.materializeFail || options.launchFail;
|
|
108
|
+
assert.equal(caught.stage, materializeFailed ? "materialize" : "submit");
|
|
109
|
+
assert.equal(caught.mutationOutcome, options.submitFail || materializeFailed ? "none" : "unknown");
|
|
110
|
+
assert.deepEqual(samples.map(({ phase, outcome }) => ({ phase, outcome })), materializeFailed
|
|
111
|
+
? [{ phase: "materialize", outcome: "failure" }]
|
|
112
|
+
: [{ phase: "materialize", outcome: "success" }, { phase: "submit", outcome: options.submitFail ? "failure" : "success" }, { phase: "cleanup", outcome: options.cleanupFail ? "failure" : "success" }]);
|
|
113
|
+
assert.equal(relay.state().reviewerCalls, materializeFailed ? 0 : 1);
|
|
114
|
+
assert.equal(relay.state().cleaned, materializeFailed ? 0 : 1);
|
|
115
|
+
if (options.submitFail) assert.match(caught.message, /private-provider-refusal/);
|
|
116
|
+
assert.doesNotMatch(JSON.stringify(samples), /private|secret|credential|binding|prompt|output/);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
test("relay outcomes and process counts survive broken observers without awaiting promises", { timeout: 2000 }, async t => {
|
|
121
|
+
const relay = fakeRelay(t);
|
|
122
|
+
const expected = await relay.run();
|
|
123
|
+
for (const observer of [() => { throw new Error("observer"); }, () => Promise.reject(new Error("observer")), () => new Promise(() => {})]) assert.deepEqual(await relay.run(observer), expected);
|
|
124
|
+
assert.equal(relay.state().submissions, 4);
|
|
125
|
+
assert.equal(relay.state().invocations.length, 8);
|
|
126
|
+
assert.equal(relay.state().cleaned, 4);
|
|
127
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
128
|
+
});
|
|
@@ -394,8 +394,17 @@ test("public empty-output report preserves only safe in-process completion facts
|
|
|
394
394
|
});
|
|
395
395
|
const result = await runCapture(cwd, native, "safe-evidence-lineage");
|
|
396
396
|
assert.equal(result.outcome, "pi-host-relay-transport-failure");
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
const reviewer = (result.failure as { reviewer: Record<string, unknown> }).reviewer;
|
|
398
|
+
const { durationMs, authDurationMs, completionDurationMs, ...facts } = reviewer;
|
|
399
|
+
for (const [key, value] of Object.entries({ durationMs, authDurationMs, completionDurationMs })) {
|
|
400
|
+
assert.equal(typeof value, "number", key);
|
|
401
|
+
assert.ok(Number.isFinite(value) && Number(value) >= 0, key);
|
|
402
|
+
assert.equal(value, outcome.evidence?.[key], `${key} is relayed unchanged`);
|
|
403
|
+
}
|
|
404
|
+
assert.ok(Number(durationMs) >= Number(authDurationMs));
|
|
405
|
+
assert.ok(Number(durationMs) >= Number(completionDurationMs));
|
|
406
|
+
assert.deepEqual(facts, {
|
|
407
|
+
phase: "completion", provider: "nan", reviewerModel: "nan/deepseek-v4-flash", stopReason: "length", usage: { output: 64, reasoning: 64 },
|
|
399
408
|
content: { blocks: 1, textBlocks: 0, thinkingBlocks: 1, textChars: 0, thinkingChars: 16 },
|
|
400
409
|
});
|
|
401
410
|
assert.doesNotMatch(JSON.stringify(result), /PRIVATE|errorMessage|unknown|authorization/);
|
|
@@ -452,6 +461,7 @@ test("a provider that refuses the pi transport blocks immediately without an age
|
|
|
452
461
|
assert.match(transport.message, /immutable review runtimes/i);
|
|
453
462
|
assert.equal(result.status, "blocked");
|
|
454
463
|
assert.equal(result.outcome, "pi-host-relay-transport-unavailable");
|
|
464
|
+
assert.equal((result.blocker as Record<string, unknown>).category, "provider-capability");
|
|
455
465
|
assert.equal(result.mutation_performed, false);
|
|
456
466
|
assert.equal(result.mutation_outcome, "none");
|
|
457
467
|
assert.match(String(result.next_action), /support.*--agent pi/i);
|