harness-everything 1.3.0 → 1.3.2
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +14 -0
- package/behavioral-evals/ledger-pairs/README.md +53 -0
- package/behavioral-evals/ledger-pairs/arm.js +359 -0
- package/behavioral-evals/ledger-pairs/fixture.js +138 -0
- package/behavioral-evals/ledger-pairs/preflight.js +96 -0
- package/behavioral-evals/ledger-pairs/score.js +155 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/README.md +108 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-result.json +28 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/receipt.jsonl +17 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-result.json +41 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/receipt.jsonl +58 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-result.json +50 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/receipt.jsonl +101 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/receipt.jsonl +29 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/receipt.jsonl +23 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-result.json +34 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/receipt.jsonl +24 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-result.json +47 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/receipt.jsonl +69 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/receipt.jsonl +65 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/run-order.sh +18 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/score.json +1032 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/README.md +50 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/collect-rerun.txt +3 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/export-report.json +22 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/host-version.txt +1 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-1.json +18 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-2.json +18 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/labels-observed-excerpt.jsonl +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/observations-index-excerpt.json +26 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/plugin-load-lines.txt +1 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/README.md +46 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/observations-index-excerpt.json +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/plugin-load-lines.txt +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/run-marks.txt +6 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-trace.jsonl +167 -0
- package/ci/archive/325-prep/README.md +9 -2
- package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
- package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
- package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
- package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
- package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
- package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
- package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
- package/ci/fixtures/stop/fail-session-writes.js +109 -0
- package/ci/fixtures/workflow-contract/cases.json +3355 -0
- package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
- package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
- package/ci/mechanism-2an-workflow-replay.test.js +324 -0
- package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
- package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
- package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
- package/ci/mechanism-325-3b-preparation.test.js +208 -49
- package/ci/mechanism-325-3b-s1-review.test.js +20 -828
- package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
- package/ci/mechanism-325-f3-derived-views.test.js +140 -0
- package/ci/mechanism-332-fable-directive.test.js +180 -0
- package/ci/mechanism-341-opencode-lane.test.js +164 -284
- package/ci/mechanism-35-verification-contract.test.js +246 -0
- package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
- package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
- package/ci/mechanism-397-opencode-observations.test.js +151 -18
- package/ci/mechanism-552-ledger-pairs.test.js +159 -0
- package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
- package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
- package/ci/mechanism-553-p3-plan-start.test.js +212 -0
- package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
- package/ci/mechanism-553-stop.test.js +427 -0
- package/ci/mechanism-553-t2a-derive.test.js +110 -0
- package/ci/mechanism-553-t2c-derive.test.js +94 -0
- package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
- package/ci/mechanism-outline-sanitizer.test.js +0 -8
- package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
- package/ci/mechanism-prb-outline-review.test.js +101 -3283
- package/ci/router-workflow-plan.test.js +61 -21
- package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
- package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
- package/docs/doc-workflow-reconciliation.md +17 -2
- package/docs/document-lifecycle.md +6 -2
- package/docs/platform-capabilities.md +63 -16
- package/docs/platform-compatibility.json +5 -5
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/routing-keywords.json +0 -2
- package/harness-everything/scripts/tier-router.js +105 -11
- package/hooks/hooks.json +0 -46
- package/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/hooks/scripts/state-persist.js +7 -95
- package/hooks/scripts/workflow-disposition.js +0 -2
- package/hooks/scripts/workflow-stop-gate.js +17 -30
- package/opencode-plugin/index.mjs +6 -70
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
- package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
- package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/rules/AGENTS.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +105 -11
- package/sbom.cdx.json +7 -7
- package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
- package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
- package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
- package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
- package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
- package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
- package/ci/lib/doc-reconciliation-file-spy.js +0 -23
- package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
- package/ci/lib/doc-reconciliation-replay.js +0 -104
- package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
- package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
- package/ci/mechanism-325-3b-s1.test.js +0 -188
- package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
- package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
- package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
- package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
- package/ci/mechanism-325-f4-invariants.test.js +0 -606
- package/ci/mechanism-325-f4-projections.test.js +0 -392
- package/ci/mechanism-325-f4-qualification.test.js +0 -228
- package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
- package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
- package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/hooks/scripts/w6-state-operations.js +0 -239
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
- package/scripts/system-one-eval-laya.js +0 -112
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
10
|
+
const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-553-p3-plan-start-'));
|
|
11
|
+
const STATE_HOME = path.join(TEMP, 'state-home');
|
|
12
|
+
const SWITCH = 'HARNESS_DOC_RECONCILIATION_PILOT';
|
|
13
|
+
const ORIGINAL_ENV = {
|
|
14
|
+
stateHome: process.env.HARNESS_STATE_HOME,
|
|
15
|
+
workspaceRoot: process.env.HARNESS_WORKSPACE_ROOT,
|
|
16
|
+
pilot: process.env[SWITCH],
|
|
17
|
+
};
|
|
18
|
+
const LEGS = [
|
|
19
|
+
{ id: 'source', hooks: path.join(ROOT, 'hooks', 'scripts') },
|
|
20
|
+
{ id: 'packaged', hooks: path.join(ROOT, 'plugins', 'harness-everything', 'hooks', 'scripts') },
|
|
21
|
+
];
|
|
22
|
+
const REQUIREMENTS = [
|
|
23
|
+
{ id: 'req-review', stepType: 'review', summary: 'Review the requested change', acceptance: 'The affected behavior was reviewed' },
|
|
24
|
+
{ id: 'req-change', stepType: 'behavior-change', summary: 'Make the requested change', acceptance: 'The requested behavior is corrected' },
|
|
25
|
+
{ id: 'req-verify', stepType: 'verification', summary: 'Verify the requested change', acceptance: 'Objective checks pass' },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
let failed = 0;
|
|
29
|
+
function check(condition, id, detail = '') {
|
|
30
|
+
if (condition) console.log(` PASS ${id}`);
|
|
31
|
+
else { console.error(` FAIL ${id}${detail ? ` — ${detail}` : ''}`); failed++; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function writeJson(file, value) {
|
|
35
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
36
|
+
fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const preload = path.join(TEMP, 'trace-e1-loads.js');
|
|
40
|
+
fs.writeFileSync(preload, [
|
|
41
|
+
"'use strict';",
|
|
42
|
+
"const fs = require('fs');",
|
|
43
|
+
"const path = require('path');",
|
|
44
|
+
"const Module = require('module');",
|
|
45
|
+
'const hooksRoot = path.resolve(process.env.HARNESS_P3_HOOKS_ROOT);',
|
|
46
|
+
'const originalLoad = Module._load;',
|
|
47
|
+
'Module._load = function (request, parent, isMain) {',
|
|
48
|
+
' const parentFile = parent?.filename ? path.resolve(parent.filename) : "";',
|
|
49
|
+
' const requestPath = String(request).replace(/\\\\/g, "/");',
|
|
50
|
+
' const inHooks = parentFile === hooksRoot || parentFile.startsWith(hooksRoot + path.sep);',
|
|
51
|
+
' if (inHooks && /(?:^|\\/)doc-reconciliation-(?:pilot|provider)$/.test(requestPath)) {',
|
|
52
|
+
' fs.appendFileSync(process.env.HARNESS_P3_E1_TRACE, `${path.relative(hooksRoot, parentFile)} -> ${requestPath}\\n`);',
|
|
53
|
+
' }',
|
|
54
|
+
' return Reflect.apply(originalLoad, this, [request, parent, isMain]);',
|
|
55
|
+
'};',
|
|
56
|
+
].join('\n') + '\n', 'utf8');
|
|
57
|
+
|
|
58
|
+
function createScenario(leg, flag, label) {
|
|
59
|
+
process.env.HARNESS_STATE_HOME = STATE_HOME;
|
|
60
|
+
process.env.HARNESS_WORKSPACE_ROOT = ROOT;
|
|
61
|
+
const sessionId = `p3-553-${leg.id}-${label}`;
|
|
62
|
+
const payload = { session_id: sessionId, cwd: ROOT };
|
|
63
|
+
const state = require(path.join(leg.hooks, 'lib', 'harness-state.js'));
|
|
64
|
+
const runtime = require(path.join(leg.hooks, 'lib', 'workflow-runtime.js'));
|
|
65
|
+
const obligations = require(path.join(leg.hooks, 'lib', 'workflow-obligations.js'));
|
|
66
|
+
const sessionDir = state.getSessionDir(ROOT, sessionId, payload);
|
|
67
|
+
const plan = { strategySelection: 'selected', tier: 'tier2', strategy: 'iterative-single' };
|
|
68
|
+
const workflow = {
|
|
69
|
+
schemaVersion: 2,
|
|
70
|
+
workflowId: `wf-${sessionId}`,
|
|
71
|
+
sessionId,
|
|
72
|
+
revision: 0,
|
|
73
|
+
state: 'pending',
|
|
74
|
+
strategy: plan.strategy,
|
|
75
|
+
tier: plan.tier,
|
|
76
|
+
strategySelection: plan.strategySelection,
|
|
77
|
+
workflowPlan: plan,
|
|
78
|
+
lastMutationAt: 1,
|
|
79
|
+
escapes: [],
|
|
80
|
+
};
|
|
81
|
+
const context = { root: ROOT, sessionId, sessionDir, file: path.join(sessionDir, 'workflow-run.json'), workflow };
|
|
82
|
+
obligations.initializePlanningContract(context, plan);
|
|
83
|
+
runtime.saveWorkflow(context);
|
|
84
|
+
|
|
85
|
+
const env = { ...process.env, HARNESS_STATE_HOME: STATE_HOME, HARNESS_WORKSPACE_ROOT: ROOT };
|
|
86
|
+
if (flag === null) delete env[SWITCH];
|
|
87
|
+
else env[SWITCH] = flag;
|
|
88
|
+
return { sessionId, sessionDir, workflowFile: context.file, plan, env, leg, flag, label };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function runCli(scenario, name, entry, args, input) {
|
|
92
|
+
const trace = path.join(TEMP, `${scenario.label}-${name}.e1-trace`);
|
|
93
|
+
const env = {
|
|
94
|
+
...scenario.env,
|
|
95
|
+
HARNESS_P3_HOOKS_ROOT: scenario.leg.hooks,
|
|
96
|
+
HARNESS_P3_E1_TRACE: trace,
|
|
97
|
+
};
|
|
98
|
+
const result = spawnSync(process.execPath, ['--require', preload, entry, ...args], {
|
|
99
|
+
cwd: ROOT, encoding: 'utf8', input, env, timeout: 20000,
|
|
100
|
+
});
|
|
101
|
+
const id = `cli.${scenario.leg.id}.${scenario.label}.${name}`;
|
|
102
|
+
check(!result.error, `${id}.launched`, result.error?.message || '');
|
|
103
|
+
check(result.status === 0, `${id}.exit-0`, result.stderr || `status ${result.status}`);
|
|
104
|
+
const e1Loads = fs.existsSync(trace) ? fs.readFileSync(trace, 'utf8').trim() : '';
|
|
105
|
+
check(e1Loads === '', `${id}.no-e1-load`, e1Loads);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseOutput(result, id) {
|
|
110
|
+
try { return JSON.parse(result.stdout); }
|
|
111
|
+
catch (error) {
|
|
112
|
+
check(false, id, `invalid JSON from CLI: ${error.message}; stdout=${result.stdout}`);
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function assertNoPins(scenario, phase) {
|
|
118
|
+
const workflow = JSON.parse(fs.readFileSync(scenario.workflowFile, 'utf8'));
|
|
119
|
+
check(!workflow.docReconciliationBaseline && !workflow.docReconciliationTask,
|
|
120
|
+
`pins.${scenario.leg.id}.${scenario.label}.${phase}.absent`,
|
|
121
|
+
JSON.stringify({ baseline: workflow.docReconciliationBaseline, task: workflow.docReconciliationTask }));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function resolveActiveBindings(scenario, activeStep, label) {
|
|
125
|
+
for (const binding of [...(activeStep?.requiredBindings || []), ...(activeStep?.optionalBindings || [])]) {
|
|
126
|
+
const disposition = binding.required === false ? 'not-needed' : 'loaded';
|
|
127
|
+
runCli(scenario, `${label}-binding-${binding.id}`, scenario.controller, [
|
|
128
|
+
'binding', '--session-id', scenario.sessionId, '--step-id', activeStep.id,
|
|
129
|
+
'--binding-id', binding.id, '--disposition', disposition, '--evidence', 'Active-step binding resolved for the real CLI path',
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function exerciseRealCli(leg, flag, label) {
|
|
135
|
+
const scenario = createScenario(leg, flag, label);
|
|
136
|
+
scenario.controller = path.join(leg.hooks, 'workflow-disposition.js');
|
|
137
|
+
const stopGate = path.join(leg.hooks, 'workflow-stop-gate.js');
|
|
138
|
+
const requirementsJson = JSON.stringify(REQUIREMENTS);
|
|
139
|
+
|
|
140
|
+
const planResult = runCli(scenario, 'plan', scenario.controller, [
|
|
141
|
+
'plan', '--session-id', scenario.sessionId, '--requirements-json', requirementsJson,
|
|
142
|
+
'--strategy', scenario.plan.strategy, '--evidence', 'The ordered review, change, and verification requirements were confirmed',
|
|
143
|
+
]);
|
|
144
|
+
const planned = parseOutput(planResult, `plan.${leg.id}.${label}.json`);
|
|
145
|
+
check(planned.requirements?.length === REQUIREMENTS.length && planned.blocked === false,
|
|
146
|
+
`plan.${leg.id}.${label}.valid-requirements`, JSON.stringify(planned));
|
|
147
|
+
const plannedSet = JSON.parse(fs.readFileSync(path.join(scenario.sessionDir, 'workflow-obligations.json'), 'utf8'));
|
|
148
|
+
check(plannedSet.phase === 'planned' && plannedSet.requirements.map(step => step.id).join(',') === 'req-review,req-change,req-verify',
|
|
149
|
+
`plan.${leg.id}.${label}.obligations-recorded`, JSON.stringify({ phase: plannedSet.phase, ids: plannedSet.requirements.map(step => step.id) }));
|
|
150
|
+
assertNoPins(scenario, 'after-plan');
|
|
151
|
+
|
|
152
|
+
const startResult = runCli(scenario, 'start', scenario.controller, ['start', '--session-id', scenario.sessionId]);
|
|
153
|
+
const started = parseOutput(startResult, `start.${leg.id}.${label}.json`);
|
|
154
|
+
check(started.state === 'running' && started.activeStep?.id === 'req-review',
|
|
155
|
+
`start.${leg.id}.${label}.active-review`, JSON.stringify(started));
|
|
156
|
+
const executionSet = JSON.parse(fs.readFileSync(path.join(scenario.sessionDir, 'workflow-obligations.json'), 'utf8'));
|
|
157
|
+
check(executionSet.phase === 'execution' && executionSet.obligations.some(item => item.id === 'execute') &&
|
|
158
|
+
executionSet.obligations.some(item => item.id === 'verify'),
|
|
159
|
+
`start.${leg.id}.${label}.valid-execution-obligations`, JSON.stringify(executionSet));
|
|
160
|
+
assertNoPins(scenario, 'after-start');
|
|
161
|
+
|
|
162
|
+
let activeStep = started.activeStep;
|
|
163
|
+
for (const [index, requirement] of REQUIREMENTS.entries()) {
|
|
164
|
+
check(activeStep?.id === requirement.id, `progress.${leg.id}.${label}.active-${requirement.id}`, JSON.stringify(activeStep));
|
|
165
|
+
resolveActiveBindings(scenario, activeStep, `step-${index}`);
|
|
166
|
+
const stepResult = runCli(scenario, `step-${requirement.id}`, scenario.controller, [
|
|
167
|
+
'step', '--session-id', scenario.sessionId, '--step-id', requirement.id,
|
|
168
|
+
'--disposition', 'pass', '--evidence', `${requirement.summary} and acceptance criteria were met`,
|
|
169
|
+
]);
|
|
170
|
+
const disposition = parseOutput(stepResult, `step.${leg.id}.${label}.${requirement.id}.json`);
|
|
171
|
+
activeStep = disposition.activeStep;
|
|
172
|
+
}
|
|
173
|
+
check(activeStep === null, `progress.${leg.id}.${label}.verification-completes-steps`, JSON.stringify(activeStep));
|
|
174
|
+
|
|
175
|
+
writeJson(path.join(scenario.sessionDir, 'handoff-state.json'), { lastEditAt: 1, lastVerifyAt: 2 });
|
|
176
|
+
const stopResult = runCli(scenario, 'stop', stopGate, [], JSON.stringify({
|
|
177
|
+
session_id: scenario.sessionId, cwd: ROOT, hook_event_name: 'Stop',
|
|
178
|
+
}));
|
|
179
|
+
const completed = JSON.parse(fs.readFileSync(scenario.workflowFile, 'utf8'));
|
|
180
|
+
check(stopResult.status === 0 && completed.state === 'satisfied' && completed.unresolved.length === 0,
|
|
181
|
+
`stop.${leg.id}.${label}.satisfied-after-review-verify`,
|
|
182
|
+
JSON.stringify({ status: stopResult.status, state: completed.state, unresolved: completed.unresolved, stderr: stopResult.stderr }));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
console.log('=== P3-553 plan/start E1 unhook ===');
|
|
186
|
+
try {
|
|
187
|
+
for (const leg of LEGS) {
|
|
188
|
+
if (!fs.existsSync(path.join(leg.hooks, 'workflow-disposition.js')) ||
|
|
189
|
+
!fs.existsSync(path.join(leg.hooks, 'workflow-stop-gate.js'))) {
|
|
190
|
+
check(false, `layout.${leg.id}.cli-present`, 'workflow-disposition.js or workflow-stop-gate.js is missing');
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
exerciseRealCli(leg, null, 'unset');
|
|
194
|
+
exerciseRealCli(leg, '1', 'on');
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error(`INFRA ${error.stack || error}`);
|
|
198
|
+
failed++;
|
|
199
|
+
} finally {
|
|
200
|
+
fs.rmSync(TEMP, { recursive: true, force: true });
|
|
201
|
+
if (ORIGINAL_ENV.stateHome === undefined) delete process.env.HARNESS_STATE_HOME;
|
|
202
|
+
else process.env.HARNESS_STATE_HOME = ORIGINAL_ENV.stateHome;
|
|
203
|
+
if (ORIGINAL_ENV.workspaceRoot === undefined) delete process.env.HARNESS_WORKSPACE_ROOT;
|
|
204
|
+
else process.env.HARNESS_WORKSPACE_ROOT = ORIGINAL_ENV.workspaceRoot;
|
|
205
|
+
if (ORIGINAL_ENV.pilot === undefined) delete process.env[SWITCH];
|
|
206
|
+
else process.env[SWITCH] = ORIGINAL_ENV.pilot;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (failed) {
|
|
210
|
+
console.error(`FAIL P3-553 plan/start E1 unhook: ${failed} assertions`);
|
|
211
|
+
process.exitCode = 1;
|
|
212
|
+
} else console.log('PASS P3-553 plan/start E1 unhook');
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// General state-persist PostToolUse compatibility controls, moved here from the
|
|
5
|
+
// S2b capture/provider suite when the E1 pilot was retired (issue #553, T2-H).
|
|
6
|
+
// These are ordinary state-persist outcomes: retired manifest callbacks stay
|
|
7
|
+
// quiet, the legacy handoff golden survives unset/0/unknown flag values, and
|
|
8
|
+
// ordinary success/failure posts do not depend on the retired pilot switch.
|
|
9
|
+
//
|
|
10
|
+
// Every assertion runs on both legs (canonical hooks/scripts and the packaged
|
|
11
|
+
// plugins/harness-everything copy) against the real state-persist.js entry.
|
|
12
|
+
// This suite does not require any E1 runtime module at load time.
|
|
13
|
+
|
|
14
|
+
const { spawnSync } = require('child_process');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const H = require('./fixtures/state-persist-post-tool-use/harness');
|
|
19
|
+
|
|
20
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
21
|
+
const PILOT_SWITCH = 'HARNESS_DOC_RECONCILIATION_PILOT';
|
|
22
|
+
|
|
23
|
+
const runner = H.createRunner('state-persist PostToolUse');
|
|
24
|
+
const GOLDEN = H.golden();
|
|
25
|
+
|
|
26
|
+
function legacyGoldenChecks(id, drive) {
|
|
27
|
+
if (drive.code !== 0) throw new Error(`state-persist exited ${drive.code}: ${(drive.stderr || drive.stdout).slice(0, 200)}`);
|
|
28
|
+
const names = Object.keys(drive.files);
|
|
29
|
+
for (const rel of names) {
|
|
30
|
+
if (!rel.endsWith('/handoff-state.json')) throw new Error(`OFF created an unexpected session file: ${rel}`);
|
|
31
|
+
}
|
|
32
|
+
const handoffRels = names.filter(rel => rel.endsWith('/handoff-state.json'));
|
|
33
|
+
if (handoffRels.length !== 1) throw new Error(`OFF expected exactly one handoff-state.json, got ${handoffRels.length}`);
|
|
34
|
+
const state = JSON.parse(drive.files[handoffRels[0]]);
|
|
35
|
+
const keys = Object.keys(state).sort();
|
|
36
|
+
if (JSON.stringify(keys) !== JSON.stringify([...GOLDEN.keys].sort())) {
|
|
37
|
+
throw new Error(`legacy handoff keyset changed: got ${JSON.stringify(keys)} expected ${JSON.stringify(GOLDEN.keys)}`);
|
|
38
|
+
}
|
|
39
|
+
for (const [key, expected] of Object.entries(GOLDEN.values)) {
|
|
40
|
+
if (state[key] !== expected) throw new Error(`legacy handoff ${key} changed: got ${state[key]} expected ${expected}`);
|
|
41
|
+
}
|
|
42
|
+
const captures = H.findCaptureRecords(drive.files);
|
|
43
|
+
if (captures.length) throw new Error(`legacy post wrote an E1 capture record: ${JSON.stringify(captures[0]).slice(0, 200)}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Old manifest callbacks are ignored regardless of the retired flag value.
|
|
47
|
+
// Drive the real source/package hook with an isolated state home and assert
|
|
48
|
+
// no E1 load, state write, output or nonzero exit.
|
|
49
|
+
const CAPTURE_ONLY_ROUTES = [
|
|
50
|
+
{ id: 'pre-bash', event: 'PreToolUse', tool: 'Bash', input: { command: 'echo f8-probe' } },
|
|
51
|
+
{ id: 'pre-powershell', event: 'PreToolUse', tool: 'PowerShell', input: { command: 'Write-Output f8-probe' } },
|
|
52
|
+
{ id: 'pre-task', event: 'PreToolUse', tool: 'Task', input: { description: 'F8 capture probe' } },
|
|
53
|
+
{ id: 'pre-agent', event: 'PreToolUse', tool: 'Agent', input: { description: 'F8 capture probe' } },
|
|
54
|
+
{ id: 'post-task', event: 'PostToolUse', tool: 'Task', input: { description: 'F8 capture probe' } },
|
|
55
|
+
{ id: 'post-agent', event: 'PostToolUse', tool: 'Agent', input: { description: 'F8 capture probe' } },
|
|
56
|
+
{ id: 'subagent-start', event: 'SubagentStart' },
|
|
57
|
+
{ id: 'subagent-stop', event: 'SubagentStop' },
|
|
58
|
+
];
|
|
59
|
+
const RETIRED_SWITCH_VALUES = [
|
|
60
|
+
{ id: 'unset' },
|
|
61
|
+
{ id: 'zero', value: '0' },
|
|
62
|
+
{ id: 'one', value: '1' },
|
|
63
|
+
{ id: 'other', value: 'true' },
|
|
64
|
+
];
|
|
65
|
+
const ORDINARY_SWITCH_VALUES = RETIRED_SWITCH_VALUES.slice(0, 3);
|
|
66
|
+
|
|
67
|
+
function snapshotTree(root) {
|
|
68
|
+
const files = {};
|
|
69
|
+
function visit(dir) {
|
|
70
|
+
if (!fs.existsSync(dir)) return;
|
|
71
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
72
|
+
const abs = path.join(dir, entry.name);
|
|
73
|
+
if (entry.isDirectory()) visit(abs);
|
|
74
|
+
else if (entry.isFile()) files[path.relative(root, abs).split(path.sep).join('/')] = fs.readFileSync(abs, 'utf8');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
visit(root);
|
|
78
|
+
return files;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function snapshotSessionTree(root, sessionId) {
|
|
82
|
+
const safeId = String(sessionId || 'default').replace(/[^A-Za-z0-9._-]+/g, '_').replace(/^\.+/, '');
|
|
83
|
+
const allFiles = snapshotTree(root);
|
|
84
|
+
return Object.fromEntries(Object.entries(allFiles)
|
|
85
|
+
.filter(([name]) => name.split('/').includes(safeId)));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function captureEventRecords(files) {
|
|
89
|
+
return Object.entries(files)
|
|
90
|
+
.filter(([name]) => /(?:^|\/)doc-reconciliation-capture\/\d{8}\.json$/.test(name))
|
|
91
|
+
.map(([, content]) => JSON.parse(content));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function driveStatePersistPayload(leg, inputPayload, switchSetting) {
|
|
95
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'f10-f8-capture-'));
|
|
96
|
+
const stateHome = path.join(temp, 'state-home');
|
|
97
|
+
const wsRoot = path.join(temp, 'workspace');
|
|
98
|
+
fs.mkdirSync(stateHome, { recursive: true });
|
|
99
|
+
fs.mkdirSync(wsRoot, { recursive: true });
|
|
100
|
+
|
|
101
|
+
const payload = JSON.parse(JSON.stringify(inputPayload));
|
|
102
|
+
payload.cwd = wsRoot;
|
|
103
|
+
const statePersist = path.join(leg.hooksScripts, 'state-persist.js');
|
|
104
|
+
const sentinel = path.join(temp, 'e1-module-loads.txt');
|
|
105
|
+
const preload = path.join(temp, 'e1-load-sentinel.js');
|
|
106
|
+
fs.writeFileSync(preload, [
|
|
107
|
+
"'use strict';",
|
|
108
|
+
"const fs = require('fs');",
|
|
109
|
+
"const path = require('path');",
|
|
110
|
+
"const Module = require('module');",
|
|
111
|
+
"const statePersist = path.resolve(process.env.HARNESS_553_STATE_PERSIST);",
|
|
112
|
+
"const sentinel = process.env.HARNESS_553_E1_SENTINEL;",
|
|
113
|
+
"const original = Module._load;",
|
|
114
|
+
"Module._load = function (request, parent, isMain) {",
|
|
115
|
+
" if (parent?.filename && path.resolve(parent.filename) === statePersist &&",
|
|
116
|
+
" (request === './lib/doc-reconciliation-pilot' || request === './lib/doc-reconciliation-provider')) {",
|
|
117
|
+
" fs.appendFileSync(sentinel, 'state-persist.js -> ' + request + '\\n');",
|
|
118
|
+
" }",
|
|
119
|
+
" return Reflect.apply(original, this, [request, parent, isMain]);",
|
|
120
|
+
"};",
|
|
121
|
+
].join('\n') + '\n', 'utf8');
|
|
122
|
+
|
|
123
|
+
const env = {
|
|
124
|
+
...process.env,
|
|
125
|
+
CLAUDE: '1',
|
|
126
|
+
HOME: temp,
|
|
127
|
+
USERPROFILE: temp,
|
|
128
|
+
HARNESS_STATE_HOME: stateHome,
|
|
129
|
+
HARNESS_WORKSPACE_ROOT: wsRoot,
|
|
130
|
+
};
|
|
131
|
+
delete env.NODE_OPTIONS;
|
|
132
|
+
if (switchSetting.value === undefined) delete env[PILOT_SWITCH];
|
|
133
|
+
else env[PILOT_SWITCH] = switchSetting.value;
|
|
134
|
+
env.HARNESS_553_STATE_PERSIST = statePersist;
|
|
135
|
+
env.HARNESS_553_E1_SENTINEL = sentinel;
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const result = spawnSync(process.execPath, ['--require', preload, statePersist], {
|
|
139
|
+
input: JSON.stringify(payload),
|
|
140
|
+
encoding: 'utf8',
|
|
141
|
+
cwd: wsRoot,
|
|
142
|
+
env,
|
|
143
|
+
timeout: 30000,
|
|
144
|
+
});
|
|
145
|
+
if (result.error) throw new H.InfraError('capture-only hook subprocess failed: ' + result.error.message);
|
|
146
|
+
return {
|
|
147
|
+
code: result.status,
|
|
148
|
+
stdout: result.stdout || '',
|
|
149
|
+
stderr: result.stderr || '',
|
|
150
|
+
files: snapshotSessionTree(stateHome, payload.session_id),
|
|
151
|
+
allFiles: snapshotTree(stateHome),
|
|
152
|
+
payload,
|
|
153
|
+
e1Loads: fs.existsSync(sentinel) ? fs.readFileSync(sentinel, 'utf8').trim().split(/\r?\n/) : [],
|
|
154
|
+
};
|
|
155
|
+
} finally {
|
|
156
|
+
fs.rmSync(temp, { recursive: true, force: true });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function driveCaptureOnlyRoute(leg, route, switchSetting) {
|
|
161
|
+
const payload = {
|
|
162
|
+
hook_event_name: route.event,
|
|
163
|
+
session_id: 'f8-' + route.id,
|
|
164
|
+
};
|
|
165
|
+
if (route.tool) {
|
|
166
|
+
payload.tool_name = route.tool;
|
|
167
|
+
payload.tool_use_id = 'toolu-' + route.id;
|
|
168
|
+
payload.tool_input = route.input;
|
|
169
|
+
if (route.event === 'PostToolUse') {
|
|
170
|
+
payload.tool_response = { agentId: 'agent-f8', interrupted: false, result: 'completed' };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (route.event === 'SubagentStart' || route.event === 'SubagentStop') {
|
|
174
|
+
payload.agent_id = 'agent-f8';
|
|
175
|
+
payload.agent_type = 'doc-reviewer';
|
|
176
|
+
}
|
|
177
|
+
if (route.event === 'SubagentStop') {
|
|
178
|
+
payload.last_assistant_message = 'Review verdict: approve. F8 capture probe.';
|
|
179
|
+
}
|
|
180
|
+
return driveStatePersistPayload(leg, payload, switchSetting);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// locks: historical — the old F8 preload-spy predicate is retired; current
|
|
184
|
+
// path checks assert callback side effects and provider non-loading directly.
|
|
185
|
+
runner.run('P2B-553-OLD-MANIFEST-CAPTURE-ONLY-QUIET', [], (_mods, leg) => {
|
|
186
|
+
const routeSwitchCases = CAPTURE_ONLY_ROUTES.length * RETIRED_SWITCH_VALUES.length;
|
|
187
|
+
let stateChangeCases = 0;
|
|
188
|
+
let outputCases = 0;
|
|
189
|
+
let captureCases = 0;
|
|
190
|
+
let badExitCases = 0;
|
|
191
|
+
let providerLoadCases = 0;
|
|
192
|
+
for (const route of CAPTURE_ONLY_ROUTES) {
|
|
193
|
+
for (const switchSetting of RETIRED_SWITCH_VALUES) {
|
|
194
|
+
const result = driveCaptureOnlyRoute(leg, route, switchSetting);
|
|
195
|
+
if (result.code !== 0) badExitCases += 1;
|
|
196
|
+
if (result.stdout || result.stderr) outputCases += 1;
|
|
197
|
+
if (Object.keys(result.allFiles).length) stateChangeCases += 1;
|
|
198
|
+
if (captureEventRecords(result.files).length) captureCases += 1;
|
|
199
|
+
if (result.e1Loads.length) providerLoadCases += 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
console.log(' SENTINEL ' + path.relative(ROOT, path.join(leg.hooksScripts, 'state-persist.js'))
|
|
203
|
+
+ ': E1 provider load in ' + providerLoadCases + '/' + routeSwitchCases + ' callback cases');
|
|
204
|
+
const failures = [];
|
|
205
|
+
if (badExitCases) failures.push('nonzero exit in ' + badExitCases + '/' + routeSwitchCases + ' retired callback cases');
|
|
206
|
+
if (outputCases) failures.push('output emitted in ' + outputCases + '/' + routeSwitchCases + ' retired callback cases');
|
|
207
|
+
if (stateChangeCases) failures.push('state changed in ' + stateChangeCases + '/' + routeSwitchCases + ' retired callback cases');
|
|
208
|
+
if (captureCases) failures.push('capture written in ' + captureCases + '/' + routeSwitchCases + ' retired callback cases');
|
|
209
|
+
if (providerLoadCases) failures.push('E1 provider loaded from state-persist in ' + providerLoadCases + '/' + routeSwitchCases + ' retired callback cases');
|
|
210
|
+
if (failures.length) failures.push(`observed side effects: state=${stateChangeCases}, capture=${captureCases}, output=${outputCases}, nonzero-exit=${badExitCases}`);
|
|
211
|
+
if (failures.length) throw new Error(failures.join('; '));
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// ---- legacy post retains the handoff golden under retired flag values ----
|
|
215
|
+
|
|
216
|
+
runner.run('P2B-553-LEGACY-GOLDEN-UNSET', [], (_mods, leg) => {
|
|
217
|
+
legacyGoldenChecks('P2B-553-LEGACY-GOLDEN-UNSET', H.driveStatePersist(leg, 'payload-post-tool-use-success.json', {}));
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
runner.run('P2B-553-LEGACY-GOLDEN-ZERO', [], (_mods, leg) => {
|
|
221
|
+
legacyGoldenChecks('P2B-553-LEGACY-GOLDEN-ZERO', H.driveStatePersist(leg, 'payload-post-tool-use-success.json', {}, { env: { [PILOT_SWITCH]: '0' } }));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
runner.run('P2B-553-LEGACY-GOLDEN-OTHER', [], (_mods, leg) => {
|
|
225
|
+
// Unknown legacy flag values are ignored too.
|
|
226
|
+
legacyGoldenChecks('P2B-553-LEGACY-GOLDEN-OTHER', H.driveStatePersist(leg, 'payload-post-tool-use-success.json', {}, { env: { [PILOT_SWITCH]: 'true' } }));
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// ---- ordinary post outcomes ignore the retired pilot switch -----------
|
|
230
|
+
|
|
231
|
+
function assertLegacyPost(drive, label, expectedStatus) {
|
|
232
|
+
if (drive.code !== 0) throw new Error(label + ': state-persist exited ' + drive.code);
|
|
233
|
+
if (drive.stdout || drive.stderr) throw new Error(label + ': hook emitted output');
|
|
234
|
+
if (drive.e1Loads.length) throw new Error(label + ': E1 provider loaded: ' + drive.e1Loads.join('; '));
|
|
235
|
+
const names = Object.keys(drive.files);
|
|
236
|
+
if (names.length !== 1 || !names[0].endsWith('/handoff-state.json')) {
|
|
237
|
+
throw new Error(label + ': unexpected state files: ' + JSON.stringify(names));
|
|
238
|
+
}
|
|
239
|
+
if (H.findCaptureRecords(drive.allFiles).length) throw new Error(label + ': E1 capture record was written');
|
|
240
|
+
if (Object.keys(drive.allFiles).some(name => /doc-reconciliation-capture/.test(name))) {
|
|
241
|
+
throw new Error(label + ': E1 journal file was written');
|
|
242
|
+
}
|
|
243
|
+
const state = JSON.parse(drive.files[names[0]]);
|
|
244
|
+
const creditKeys = Object.keys(state).filter(key => /^last(?:Doc|Generic)Verify/.test(key));
|
|
245
|
+
if (creditKeys.length) throw new Error(label + ': E1 verification fields were written: ' + creditKeys.join(','));
|
|
246
|
+
if (state.status !== expectedStatus) throw new Error(label + ': expected status ' + expectedStatus + ', got ' + state.status);
|
|
247
|
+
if (expectedStatus === 'idle' && !Number.isFinite(state.lastVerifyAt)) {
|
|
248
|
+
throw new Error(label + ': successful verification did not update generic lastVerifyAt');
|
|
249
|
+
}
|
|
250
|
+
if (expectedStatus === 'failed' && !String(state.errorSummary || '').includes('r2c1 simulated failure')) {
|
|
251
|
+
throw new Error(label + ': ordinary failure detail was lost: ' + JSON.stringify(state));
|
|
252
|
+
}
|
|
253
|
+
if (expectedStatus === 'failed' && (state.lastVerifyAt !== undefined || state.lastVerifyExitCode !== undefined)) {
|
|
254
|
+
throw new Error(label + ': failed post was recorded as successful verification');
|
|
255
|
+
}
|
|
256
|
+
return state;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function normalizeTimeFields(value) {
|
|
260
|
+
if (Array.isArray(value)) return value.map(normalizeTimeFields);
|
|
261
|
+
if (!value || typeof value !== 'object') return value;
|
|
262
|
+
const out = {};
|
|
263
|
+
for (const [key, child] of Object.entries(value)) {
|
|
264
|
+
out[key] = key === 'timestamp' || /At$/.test(key) ? '<time>' : normalizeTimeFields(child);
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function legacyPostSignature(drive, state) {
|
|
270
|
+
const files = Object.keys(drive.files).map(name => path.basename(name)).sort();
|
|
271
|
+
return JSON.stringify({ files, state: normalizeTimeFields(state) });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
runner.run('P2B-553-ORDINARY-POST-FLAG-INDEPENDENCE', [], (_mods, leg) => {
|
|
275
|
+
const cases = [
|
|
276
|
+
{ id: 'success', fixture: 'payload-post-tool-use-success.json', status: 'idle' },
|
|
277
|
+
{ id: 'failure', fixture: 'payload-post-tool-use-failure.json', status: 'failed' },
|
|
278
|
+
];
|
|
279
|
+
const failures = [];
|
|
280
|
+
for (const scenario of cases) {
|
|
281
|
+
const signatures = [];
|
|
282
|
+
for (const switchSetting of ORDINARY_SWITCH_VALUES) {
|
|
283
|
+
const label = scenario.id + '/' + switchSetting.id;
|
|
284
|
+
const drive = driveStatePersistPayload(leg, H.payload(scenario.fixture), switchSetting);
|
|
285
|
+
const state = assertLegacyPost(drive, label, scenario.status);
|
|
286
|
+
if (scenario.status === 'idle') legacyGoldenChecks(label, drive);
|
|
287
|
+
signatures.push(legacyPostSignature(drive, state));
|
|
288
|
+
}
|
|
289
|
+
if (signatures.some(signature => signature !== signatures[0])) {
|
|
290
|
+
failures.push(scenario.id + ': ordinary post result changed across unset/0/1');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
console.log(' SENTINEL ' + path.relative(ROOT, path.join(leg.hooksScripts, 'state-persist.js'))
|
|
294
|
+
+ ': no E1 provider load across success/failure at unset/0/1');
|
|
295
|
+
if (failures.length) throw new Error(failures.join('; '));
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
function finish(counts) {
|
|
299
|
+
if (counts.FAIL === 0 && counts.INFRA === 0) {
|
|
300
|
+
console.log('state-persist PostToolUse suite: all assertions PASS.');
|
|
301
|
+
process.exit(0);
|
|
302
|
+
}
|
|
303
|
+
console.log(`state-persist PostToolUse suite: FAIL/INFRA present (failed assertions: ${counts.FAIL}, infra faults: ${counts.INFRA}).`);
|
|
304
|
+
process.exit(1);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
finish(runner.summary());
|