harness-everything 1.3.0 → 1.3.1

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.
Files changed (125) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +6 -0
  4. package/ci/archive/325-prep/README.md +9 -2
  5. package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
  6. package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
  7. package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
  8. package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
  9. package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
  10. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  11. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
  12. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  13. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
  14. package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
  15. package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
  16. package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
  17. package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
  18. package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
  19. package/ci/fixtures/stop/fail-session-writes.js +109 -0
  20. package/ci/fixtures/workflow-contract/cases.json +3355 -0
  21. package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
  22. package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
  23. package/ci/mechanism-2an-workflow-replay.test.js +324 -0
  24. package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
  25. package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
  26. package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
  27. package/ci/mechanism-325-3b-preparation.test.js +208 -49
  28. package/ci/mechanism-325-3b-s1-review.test.js +20 -828
  29. package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
  30. package/ci/mechanism-325-f3-derived-views.test.js +140 -0
  31. package/ci/mechanism-341-opencode-lane.test.js +164 -284
  32. package/ci/mechanism-35-verification-contract.test.js +246 -0
  33. package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
  34. package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
  35. package/ci/mechanism-397-opencode-observations.test.js +151 -18
  36. package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
  37. package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
  38. package/ci/mechanism-553-p3-plan-start.test.js +212 -0
  39. package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
  40. package/ci/mechanism-553-stop.test.js +427 -0
  41. package/ci/mechanism-553-t2a-derive.test.js +110 -0
  42. package/ci/mechanism-553-t2c-derive.test.js +94 -0
  43. package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
  44. package/ci/mechanism-outline-sanitizer.test.js +0 -8
  45. package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
  46. package/ci/mechanism-prb-outline-review.test.js +101 -3283
  47. package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
  48. package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
  49. package/docs/doc-workflow-reconciliation.md +17 -2
  50. package/docs/document-lifecycle.md +6 -2
  51. package/docs/platform-capabilities.md +35 -5
  52. package/hooks/hooks.json +0 -46
  53. package/hooks/scripts/lib/workflow-obligations.js +0 -55
  54. package/hooks/scripts/state-persist.js +7 -95
  55. package/hooks/scripts/workflow-disposition.js +0 -2
  56. package/hooks/scripts/workflow-stop-gate.js +17 -30
  57. package/opencode-plugin/index.mjs +6 -70
  58. package/opencode-plugin/plugin.json +1 -1
  59. package/package.json +1 -1
  60. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  61. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  62. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
  63. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
  64. package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
  65. package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
  66. package/plugins/harness-everything/plugin.json +1 -1
  67. package/sbom.cdx.json +7 -7
  68. package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
  69. package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
  70. package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
  71. package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
  72. package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
  73. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
  74. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
  75. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
  76. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
  77. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
  78. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
  79. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
  80. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
  81. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
  82. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
  83. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
  84. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
  85. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
  86. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
  87. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
  88. package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
  89. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
  90. package/ci/lib/doc-reconciliation-file-spy.js +0 -23
  91. package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
  92. package/ci/lib/doc-reconciliation-replay.js +0 -104
  93. package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
  94. package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
  95. package/ci/mechanism-325-3b-s1.test.js +0 -188
  96. package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
  97. package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
  98. package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
  99. package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
  100. package/ci/mechanism-325-f4-invariants.test.js +0 -606
  101. package/ci/mechanism-325-f4-projections.test.js +0 -392
  102. package/ci/mechanism-325-f4-qualification.test.js +0 -228
  103. package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
  104. package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
  105. package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  106. package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  107. package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  108. package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  109. package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  110. package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  111. package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  112. package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  113. package/hooks/scripts/w6-state-operations.js +0 -239
  114. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  115. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  116. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  117. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  118. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  119. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  120. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  121. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  122. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
  123. package/scripts/system-one-eval-laya.js +0 -112
  124. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
  125. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
@@ -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());