harness-everything 1.2.2 → 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 (147) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +29 -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/468-dispatch/agy-quota-PROVENANCE.md +19 -0
  7. package/ci/fixtures/468-dispatch/agy-quota-direct-individual.stderr +2 -0
  8. package/ci/fixtures/468-dispatch/agy-quota-direct-third-party.stderr +2 -0
  9. package/ci/fixtures/468-dispatch/agy-quota-exec-individual.log +3 -0
  10. package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
  11. package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
  12. package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
  13. package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
  14. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  15. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
  16. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  17. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
  18. package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
  19. package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
  20. package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
  21. package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
  22. package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
  23. package/ci/fixtures/stop/fail-session-writes.js +109 -0
  24. package/ci/fixtures/workflow-contract/cases.json +3355 -0
  25. package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
  26. package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
  27. package/ci/mechanism-2an-workflow-replay.test.js +324 -0
  28. package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
  29. package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
  30. package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
  31. package/ci/mechanism-325-3b-preparation.test.js +208 -49
  32. package/ci/mechanism-325-3b-s1-review.test.js +20 -828
  33. package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
  34. package/ci/mechanism-325-f3-derived-views.test.js +140 -0
  35. package/ci/mechanism-341-opencode-lane.test.js +164 -284
  36. package/ci/mechanism-35-verification-contract.test.js +246 -0
  37. package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
  38. package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
  39. package/ci/mechanism-397-opencode-observations.test.js +151 -18
  40. package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
  41. package/ci/mechanism-548-bigint-identity.test.js +531 -0
  42. package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
  43. package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
  44. package/ci/mechanism-553-p3-plan-start.test.js +212 -0
  45. package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
  46. package/ci/mechanism-553-stop.test.js +427 -0
  47. package/ci/mechanism-553-t2a-derive.test.js +110 -0
  48. package/ci/mechanism-553-t2c-derive.test.js +94 -0
  49. package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
  50. package/ci/mechanism-error-ledger-oracle.test.js +786 -3
  51. package/ci/mechanism-error-ledger-scan.test.js +981 -0
  52. package/ci/mechanism-outline-sanitizer.test.js +0 -8
  53. package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
  54. package/ci/mechanism-prb-outline-review.test.js +101 -3283
  55. package/ci/mechanism-report-writer.test.js +45 -0
  56. package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
  57. package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
  58. package/docs/doc-workflow-reconciliation.md +17 -2
  59. package/docs/document-lifecycle.md +6 -2
  60. package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
  61. package/docs/platform-capabilities.md +35 -5
  62. package/error-ledger-bootstrap/SKILL.md +1 -1
  63. package/error-ledger-bootstrap/references/workflow.md +42 -7
  64. package/error-ledger-bootstrap/scripts/promote.js +8 -6
  65. package/error-ledger-bootstrap/scripts/scan.js +525 -12
  66. package/hooks/hooks.json +0 -46
  67. package/hooks/scripts/lib/workflow-obligations.js +0 -55
  68. package/hooks/scripts/state-persist.js +7 -95
  69. package/hooks/scripts/workflow-disposition.js +0 -2
  70. package/hooks/scripts/workflow-stop-gate.js +17 -30
  71. package/opencode-plugin/index.mjs +6 -70
  72. package/opencode-plugin/plugin.json +1 -1
  73. package/package.json +1 -1
  74. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  75. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  76. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
  77. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
  78. package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
  79. package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
  80. package/plugins/harness-everything/plugin.json +1 -1
  81. package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
  82. package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +42 -7
  83. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +8 -6
  84. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +525 -12
  85. package/sbom.cdx.json +7 -7
  86. package/scripts/dispatch.js +499 -87
  87. package/scripts/error-ledger-oracle.js +521 -27
  88. package/scripts/errors-sync.js +4 -3
  89. package/scripts/report-writer.js +4 -3
  90. package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
  91. package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
  92. package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
  93. package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
  94. package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
  95. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
  96. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
  97. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
  98. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
  99. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
  100. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
  101. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
  102. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
  103. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
  104. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
  105. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
  106. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
  107. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
  108. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
  109. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
  110. package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
  111. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
  112. package/ci/lib/doc-reconciliation-file-spy.js +0 -23
  113. package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
  114. package/ci/lib/doc-reconciliation-replay.js +0 -104
  115. package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
  116. package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
  117. package/ci/mechanism-325-3b-s1.test.js +0 -188
  118. package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
  119. package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
  120. package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
  121. package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
  122. package/ci/mechanism-325-f4-invariants.test.js +0 -606
  123. package/ci/mechanism-325-f4-projections.test.js +0 -392
  124. package/ci/mechanism-325-f4-qualification.test.js +0 -228
  125. package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
  126. package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
  127. package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  128. package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  129. package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  130. package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  131. package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  132. package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  133. package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  134. package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  135. package/hooks/scripts/w6-state-operations.js +0 -239
  136. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  137. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  138. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  139. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  140. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  141. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  142. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  143. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  144. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
  145. package/scripts/system-one-eval-laya.js +0 -112
  146. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
  147. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
@@ -0,0 +1,328 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // P1-553: the normal workflow credit decision and Stop recheck must not load the retired E1 pilot.
5
+ const fs = require('fs');
6
+ const Module = require('module');
7
+ const os = require('os');
8
+ const path = require('path');
9
+
10
+ const ROOT = path.resolve(__dirname, '..');
11
+ const SWITCH = 'HARNESS_DOC_RECONCILIATION_PILOT';
12
+ const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-553-e1-unhook-'));
13
+ const WORKSPACE = path.join(TEMP, 'workspace');
14
+ fs.mkdirSync(WORKSPACE, { recursive: true });
15
+ const ORIGINAL_ENV = {
16
+ stateHome: process.env.HARNESS_STATE_HOME,
17
+ workspaceRoot: process.env.HARNESS_WORKSPACE_ROOT,
18
+ pilot: process.env[SWITCH],
19
+ };
20
+ process.env.HARNESS_STATE_HOME = path.join(TEMP, 'state-home');
21
+ process.env.HARNESS_WORKSPACE_ROOT = WORKSPACE;
22
+
23
+ const LEGS = [
24
+ { id: 'source', hooks: path.join(ROOT, 'hooks', 'scripts') },
25
+ { id: 'packaged', hooks: path.join(ROOT, 'plugins', 'harness-everything', 'hooks', 'scripts') },
26
+ ];
27
+ const PLAN = { strategySelection: 'selected', tier: 'tier2', strategy: 'iterative-single' };
28
+ const REQUIREMENTS = [
29
+ { id: 'req-change', stepType: 'behavior-change', summary: 'Make the requested change', acceptance: 'The behavior is corrected' },
30
+ { id: 'req-review', stepType: 'review', summary: 'Review the change', acceptance: 'The changed scope is reviewed' },
31
+ { id: 'req-verify', stepType: 'verification', summary: 'Verify the change', acceptance: 'Objective checks pass' },
32
+ ];
33
+
34
+ let failed = 0;
35
+ function check(condition, id, detail = '') {
36
+ if (condition) console.log(` PASS ${id}`);
37
+ else { console.error(` FAIL ${id}${detail ? ` — ${detail}` : ''}`); failed++; }
38
+ }
39
+
40
+ function withFlag(value, fn) {
41
+ const previous = process.env[SWITCH];
42
+ if (value === null) delete process.env[SWITCH];
43
+ else process.env[SWITCH] = value;
44
+ try { return fn(); }
45
+ finally {
46
+ if (previous === undefined) delete process.env[SWITCH];
47
+ else process.env[SWITCH] = previous;
48
+ }
49
+ }
50
+
51
+ function withLoadSpy(leg, fn) {
52
+ const watched = new Set([
53
+ path.resolve(path.join(leg.hooks, 'lib', 'workflow-obligations.js')),
54
+ path.resolve(path.join(leg.hooks, 'workflow-stop-gate.js')),
55
+ ]);
56
+ const loads = [];
57
+ const original = Module._load;
58
+ Module._load = function (request, parent, isMain) {
59
+ const parentFile = parent?.filename ? path.resolve(parent.filename) : '';
60
+ const target = String(request).replace(/\\/g, '/').match(/(?:^|\/)doc-reconciliation-(pilot|provider)$/)?.[1];
61
+ if (watched.has(parentFile) && target) {
62
+ loads.push(`${path.relative(ROOT, parentFile)} -> doc-reconciliation-${target}`);
63
+ }
64
+ return Reflect.apply(original, this, [request, parent, isMain]);
65
+ };
66
+ try { return { value: fn(), loads }; }
67
+ finally { Module._load = original; }
68
+ }
69
+
70
+ function createScenario(leg, label, plan = PLAN, requirements = REQUIREMENTS) {
71
+ const runtime = require(path.join(leg.hooks, 'lib', 'workflow-runtime.js'));
72
+ const state = require(path.join(leg.hooks, 'lib', 'harness-state.js'));
73
+ const api = require(path.join(leg.hooks, 'lib', 'workflow-obligations.js'));
74
+ const stopGate = require(path.join(leg.hooks, 'workflow-stop-gate.js'));
75
+ const sessionId = `p1-553-${leg.id}-${label}`;
76
+ const payload = { session_id: sessionId, cwd: WORKSPACE, hook_event_name: 'Stop' };
77
+ const sessionDir = state.getSessionDir(WORKSPACE, sessionId, payload);
78
+ const workflow = {
79
+ schemaVersion: 2,
80
+ workflowId: `wf-${sessionId}`,
81
+ sessionId,
82
+ revision: 1,
83
+ state: 'running',
84
+ strategy: plan.strategy,
85
+ tier: plan.tier,
86
+ strategySelection: plan.strategySelection,
87
+ workflowPlan: plan,
88
+ lastMutationAt: 1000,
89
+ escapes: [],
90
+ };
91
+ const context = { root: WORKSPACE, sessionId, sessionDir, file: path.join(sessionDir, 'workflow-run.json'), workflow };
92
+ api.initializePlanningContract(context, plan);
93
+ api.recordPlanning(context, JSON.stringify(requirements), plan, plan.strategy, 'Requirements and workflow were confirmed');
94
+ api.materializeExecutionObligations(context, plan);
95
+ return { api, context, payload, runtime, stopGate, sessionDir };
96
+ }
97
+
98
+ function readJson(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
99
+ function writeJson(file, value) {
100
+ fs.mkdirSync(path.dirname(file), { recursive: true });
101
+ fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
102
+ }
103
+
104
+ function captureWarnings(fn) {
105
+ const output = [];
106
+ const original = console.error;
107
+ console.error = (...values) => output.push(values.join(' '));
108
+ try { fn(); }
109
+ finally { console.error = original; }
110
+ return output;
111
+ }
112
+
113
+ function completeOrdinaryWorkflow(leg, flag, label, options = {}) {
114
+ const scenario = createScenario(leg, label);
115
+ const { api, context, payload, runtime, stopGate, sessionDir } = scenario;
116
+ const { value, loads } = withLoadSpy(leg, () => withFlag(flag, () => {
117
+ const operationErrors = [];
118
+ const attempt = (id, action) => {
119
+ try { action(); }
120
+ catch (error) { operationErrors.push(`${id}: ${error.message}`); }
121
+ };
122
+ attempt('aggregate-execute', () => api.updateObligation(context, 'execute', 'pass', { evidence: 'Implementation actions completed' }));
123
+ attempt('aggregate-verify', () => api.updateObligation(context, 'verify', 'pass', { evidence: 'Independent generic test run passed' }));
124
+ attempt('change-binding', () => api.updateBinding(context, 'req-change', 'tdd', 'loaded', { evidence: 'Read the TDD binding' }));
125
+ attempt('change-step', () => api.updateStep(context, 'req-change', 'pass', { evidence: 'Behavior change implemented' }));
126
+ attempt('review-step', () => api.updateStep(context, 'req-review', 'pass', { evidence: 'Changed files reviewed' }));
127
+ attempt('verify-binding', () => api.updateBinding(context, 'req-verify', 'verification-loop', 'loaded', { evidence: 'Read the verification binding' }));
128
+ attempt('verify-step', () => api.updateStep(context, 'req-verify', 'pass', { evidence: 'Objective checks passed' }));
129
+ const unresolved = api.unresolvedObligations(context);
130
+ if (options.initialState) {
131
+ context.workflow.state = options.initialState;
132
+ context.workflow.resolvedAt = '2026-11-26T00:00:00.000Z';
133
+ }
134
+ runtime.saveWorkflow(context);
135
+ const handoffBefore = options.handoff || { lastEditAt: 1000, lastVerifyAt: 2000 };
136
+ writeJson(path.join(sessionDir, 'handoff-state.json'), handoffBefore);
137
+ const warnings = captureWarnings(() => stopGate.decide(payload));
138
+ const workflow = readJson(context.file);
139
+ const obligations = readJson(api.obligationPath(sessionDir));
140
+ return {
141
+ operationErrors,
142
+ unresolved,
143
+ workflowState: workflow.state,
144
+ workflowUnresolved: workflow.unresolved || [],
145
+ executeStatus: obligations.obligations.find(item => item.id === 'execute')?.status,
146
+ verifyStatus: obligations.obligations.find(item => item.id === 'verify')?.status,
147
+ warnings,
148
+ handoffBefore,
149
+ handoffAfter: readJson(path.join(sessionDir, 'handoff-state.json')),
150
+ };
151
+ }));
152
+ const flagName = flag === null ? 'unset' : flag;
153
+ const assertionPrefix = `credit.${leg.id}.${label}.${flagName}`;
154
+ console.log(` SENTINEL ${leg.id}/${flagName}: ${loads.length ? loads.join('; ') : 'no E1 loads'}`);
155
+ check(loads.length === 0, `${assertionPrefix}.no-e1-load`, loads.join('; '));
156
+ check(value.operationErrors.length === 0 && value.unresolved.length === 0,
157
+ `${assertionPrefix}.typed-and-aggregate-complete`, JSON.stringify({ errors: value.operationErrors, unresolved: value.unresolved }));
158
+ const expectedState = options.expectedState || 'satisfied';
159
+ check(value.workflowState === expectedState &&
160
+ (expectedState === 'running'
161
+ ? value.workflowUnresolved.includes('verification-after-edit-missing')
162
+ : value.workflowUnresolved.length === 0),
163
+ `${assertionPrefix}.stop-${expectedState}`, JSON.stringify(value));
164
+ check(value.executeStatus === 'pass' && value.verifyStatus === 'pass',
165
+ `${assertionPrefix}.aggregate-pass`, `${value.executeStatus}/${value.verifyStatus}`);
166
+ check(JSON.stringify(value.handoffAfter) === JSON.stringify(value.handoffBefore),
167
+ `${assertionPrefix}.handoff-preserved`, JSON.stringify(value.handoffAfter));
168
+ return value;
169
+ }
170
+
171
+ function missingBindingControl(leg) {
172
+ const scenario = createScenario(leg, 'missing-binding');
173
+ const { context, payload, runtime, stopGate, api, sessionDir } = scenario;
174
+ context.workflow.lastMutationAt = 1000;
175
+ runtime.saveWorkflow(context);
176
+ writeJson(path.join(sessionDir, 'handoff-state.json'), { lastEditAt: 1000 });
177
+ const { value, loads } = withLoadSpy(leg, () => withFlag(null, () => {
178
+ const warnings = captureWarnings(() => stopGate.decide(payload));
179
+ const workflow = readJson(context.file);
180
+ return { state: workflow.state, unresolved: workflow.unresolved || [], warnings,
181
+ obligations: readJson(api.obligationPath(sessionDir)) };
182
+ }));
183
+ check(loads.length === 0, `missing.${leg.id}.no-e1-load`, loads.join('; '));
184
+ check(value.state === 'running' && value.unresolved.includes('binding:req-change:tdd:pending'),
185
+ `missing.${leg.id}.required-binding-reminder`, JSON.stringify(value.unresolved));
186
+ check(value.unresolved.includes('verify:pending') && value.unresolved.includes('verification-after-edit-missing'),
187
+ `missing.${leg.id}.verification-reminder`, JSON.stringify(value.unresolved));
188
+ }
189
+
190
+ function fableStopControl(leg, correlated) {
191
+ const label = correlated ? 'fable-correlated' : 'fable-missing-run';
192
+ const plan = { strategySelection: 'selected', tier: 'tier3', strategy: 'fable-staged' };
193
+ const requirements = [{ id: 'stage-work', summary: 'Implement the stage work', acceptance: 'The stage check passes' }];
194
+ const scenario = createScenario(leg, label, plan, requirements);
195
+ const { context, payload, runtime, stopGate, sessionDir } = scenario;
196
+ const runId = `run-${label}-${leg.id}`;
197
+ context.workflow.runId = runId;
198
+ runtime.saveWorkflow(context);
199
+ if (correlated) {
200
+ const state = require(path.join(leg.hooks, 'lib', 'harness-state.js'));
201
+ const stateRoot = state.getStateRoot(WORKSPACE);
202
+ const runRoot = path.join(stateRoot, 'fable-runs', runId);
203
+ const stageId = 'stage-work';
204
+ const planId = 'plan-p1-553';
205
+ const verifiedAt = '2026-11-27T00:00:00.000Z';
206
+ const checkCommand = 'node ci/stage-check.js';
207
+ writeJson(path.join(runRoot, 'run.json'), {
208
+ runId, workflowId: context.workflow.workflowId, sessionId: context.sessionId,
209
+ strategy: 'fable-staged', createdAt: verifiedAt, planId, stageIds: [stageId],
210
+ });
211
+ writeJson(path.join(runRoot, 'contracts', `${stageId}.json`), {
212
+ stageId, runId, planId, sessionId: context.sessionId, status: 'pass', checkCommand,
213
+ workerId: 'worker-p1-553', verifiedAt, requiredBindings: [], optionalBindings: [],
214
+ agent: 'fable-worker', writeSet: ['hooks/scripts/lib/workflow-obligations.js'], dependsOn: [],
215
+ });
216
+ writeJson(path.join(runRoot, 'evidence', `${stageId}.json`), {
217
+ status: 'pass', exitCode: 0, runId, planId, stageId, sessionId: context.sessionId,
218
+ workerId: 'worker-p1-553', observedAt: verifiedAt, checkCommand,
219
+ });
220
+ }
221
+ const { value, loads } = withLoadSpy(leg, () => withFlag(null, () => {
222
+ const warnings = captureWarnings(() => stopGate.decide(payload));
223
+ const workflow = readJson(context.file);
224
+ return { state: workflow.state, unresolved: workflow.unresolved || [], warnings };
225
+ }));
226
+ check(loads.length === 0, `fable.${leg.id}.${correlated ? 'correlated' : 'missing'}.no-e1-load`, loads.join('; '));
227
+ if (correlated) {
228
+ check(value.state === 'satisfied' && value.unresolved.length === 0,
229
+ `fable.${leg.id}.correlated-run-satisfies`, JSON.stringify(value));
230
+ } else {
231
+ check(value.state === 'running' && value.unresolved.includes('correlated-run-missing'),
232
+ `fable.${leg.id}.missing-run-reminds`, JSON.stringify(value));
233
+ }
234
+ }
235
+
236
+ function ordinaryStopStorageFailureControl(leg) {
237
+ const scenario = createScenario(leg, 'stop-storage-failure');
238
+ const { context, payload, runtime, sessionDir } = scenario;
239
+ runtime.saveWorkflow(context);
240
+ writeJson(path.join(sessionDir, 'handoff-state.json'), { lastEditAt: 1000 });
241
+ const stopGatePath = path.join(leg.hooks, 'workflow-stop-gate.js');
242
+ const preload = path.join(TEMP, `stop-save-failure-${leg.id}.js`);
243
+ fs.writeFileSync(preload, [
244
+ "'use strict';",
245
+ "const Module = require('module');",
246
+ "const path = require('path');",
247
+ 'const stopGate = path.resolve(process.env.HARNESS_P1_STOP_GATE);',
248
+ 'const original = Module._load;',
249
+ 'Module._load = function (request, parent, isMain) {',
250
+ " if (parent?.filename && path.resolve(parent.filename) === stopGate && request === './lib/workflow-runtime') {",
251
+ ' const runtime = Reflect.apply(original, this, [request, parent, isMain]);',
252
+ " return { ...runtime, saveWorkflow() { throw new Error('simulated ordinary Stop storage failure'); } };",
253
+ ' }',
254
+ ' return Reflect.apply(original, this, [request, parent, isMain]);',
255
+ '};',
256
+ ].join('\n') + '\n', 'utf8');
257
+ const result = require('child_process').spawnSync(process.execPath, ['--require', preload, stopGatePath], {
258
+ cwd: WORKSPACE,
259
+ encoding: 'utf8',
260
+ input: JSON.stringify(payload),
261
+ timeout: 10000,
262
+ env: {
263
+ ...process.env,
264
+ HARNESS_STATE_HOME: path.join(TEMP, 'state-home'),
265
+ HARNESS_WORKSPACE_ROOT: WORKSPACE,
266
+ HARNESS_P1_STOP_GATE: stopGatePath,
267
+ [SWITCH]: '',
268
+ },
269
+ });
270
+ check(result.status === 0, `storage.${leg.id}.ordinary-stop-exits-zero`, result.stderr || result.error?.message || `status ${result.status}`);
271
+ check((result.stderr || '').includes('simulated ordinary Stop storage failure') &&
272
+ !(result.stderr || '').includes('withhold-persist-failed'),
273
+ `storage.${leg.id}.ordinary-error-is-not-pilot-recovery`, result.stderr || 'no ordinary storage diagnostic');
274
+ }
275
+
276
+ console.log('=== P1-553 E1 workflow-credit unhook ===');
277
+ try {
278
+ for (const leg of LEGS) {
279
+ if (!fs.existsSync(path.join(leg.hooks, 'workflow-stop-gate.js'))) {
280
+ check(false, `layout.${leg.id}.present`, 'workflow-stop-gate.js is missing');
281
+ continue;
282
+ }
283
+ const results = new Map();
284
+ for (const [index, flag] of [null, '0', '1'].entries()) {
285
+ results.set(flag === null ? 'unset' : flag, completeOrdinaryWorkflow(leg, flag, `credit-${index}`));
286
+ }
287
+ const values = [...results.values()];
288
+ check(values.every(value => JSON.stringify(value) === JSON.stringify(values[0])),
289
+ `credit.${leg.id}.flag-values-identical`, JSON.stringify(Object.fromEntries(results)));
290
+
291
+ const legacyCases = [
292
+ {
293
+ id: 'doc-only', expectedState: 'running',
294
+ initialState: 'satisfied',
295
+ handoff: { lastEditAt: 1000, lastVerifyAt: 3000, lastDocVerifyAt: 3000, lastDocVerifyExitCode: 0 },
296
+ },
297
+ {
298
+ id: 'generic-then-doc', expectedState: 'satisfied',
299
+ handoff: { lastEditAt: 1000, lastVerifyAt: 3000, lastGenericVerifyAt: 2000,
300
+ lastGenericVerifyExitCode: 0, lastDocVerifyAt: 3000, lastDocVerifyExitCode: 0 },
301
+ },
302
+ { id: 'off-aggregate', expectedState: 'satisfied', handoff: { lastEditAt: 1000, lastVerifyAt: 2000 } },
303
+ ];
304
+ for (const fixture of legacyCases) {
305
+ completeOrdinaryWorkflow(leg, null, `legacy-${fixture.id}`, fixture);
306
+ }
307
+ missingBindingControl(leg);
308
+ fableStopControl(leg, false);
309
+ fableStopControl(leg, true);
310
+ ordinaryStopStorageFailureControl(leg);
311
+ }
312
+ } catch (error) {
313
+ console.error(`INFRA ${error.stack || error}`);
314
+ failed++;
315
+ } finally {
316
+ fs.rmSync(TEMP, { recursive: true, force: true });
317
+ if (ORIGINAL_ENV.stateHome === undefined) delete process.env.HARNESS_STATE_HOME;
318
+ else process.env.HARNESS_STATE_HOME = ORIGINAL_ENV.stateHome;
319
+ if (ORIGINAL_ENV.workspaceRoot === undefined) delete process.env.HARNESS_WORKSPACE_ROOT;
320
+ else process.env.HARNESS_WORKSPACE_ROOT = ORIGINAL_ENV.workspaceRoot;
321
+ if (ORIGINAL_ENV.pilot === undefined) delete process.env[SWITCH];
322
+ else process.env[SWITCH] = ORIGINAL_ENV.pilot;
323
+ }
324
+
325
+ if (failed) {
326
+ console.error(`FAIL P1-553 E1 workflow-credit unhook: ${failed} assertions`);
327
+ process.exitCode = 1;
328
+ } else console.log('PASS P1-553 E1 workflow-credit unhook');
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // P2a-553: the Claude hook manifest must not register the retired E1 pilot
5
+ // capture routes, while the general PostToolUse / PostToolUseFailure / Stop
6
+ // registrations and the Codex native subagent adapters stay reachable.
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const helper = require('./test-helper');
10
+
11
+ const ROOT = path.resolve(__dirname, '..');
12
+ const CLAUDE_MANIFEST = path.join(ROOT, 'hooks', 'hooks.json');
13
+ const CODEX_MANIFEST = path.join(ROOT, 'plugins', 'harness-everything', 'hooks', 'hooks.json');
14
+
15
+ const RETIRED = [
16
+ { id: 'harness:pre:pilot-capture', event: 'PreToolUse' },
17
+ { id: 'harness:post-task:pilot-capture', event: 'PostToolUse' },
18
+ { id: 'harness:subagent:start-capture', event: 'SubagentStart' },
19
+ { id: 'harness:subagent:stop-capture', event: 'SubagentStop' },
20
+ ];
21
+
22
+ // Drive the real manifest files, not a hand-built object (E-0008).
23
+ const claude = JSON.parse(fs.readFileSync(CLAUDE_MANIFEST, 'utf8'));
24
+ const codex = JSON.parse(fs.readFileSync(CODEX_MANIFEST, 'utf8'));
25
+ const hooks = claude.hooks || {};
26
+ const codexHooks = codex.hooks || {};
27
+ const groups = event => (Array.isArray(hooks[event]) ? hooks[event] : []);
28
+ const codexGroups = event => (Array.isArray(codexHooks[event]) ? codexHooks[event] : []);
29
+ const commands = group => ((group && group.hooks) || []).map(handler => (handler && handler.command) || '');
30
+ const registeredIds = () => Object.values(hooks).flat().map(group => group && group.id).filter(Boolean);
31
+ const check = (condition, id, detail) => helper.check(id, condition, detail);
32
+
33
+ // ---- Positive controls (must pass on the unchanged base) -------------------
34
+
35
+ check(groups('PostToolUse').some(group => group.id === 'harness:post:state-persist'),
36
+ 'p2a.claude.control.posttooluse-general-reachable',
37
+ 'general PostToolUse state-persist is absent from hooks/hooks.json');
38
+ check(groups('PostToolUseFailure').length > 0,
39
+ 'p2a.claude.control.posttoolusefailure-reachable',
40
+ 'PostToolUseFailure has no registrations');
41
+ check(groups('Stop').some(group => group.id === 'harness:stop:stop-gate') &&
42
+ groups('Stop').some(group => group.id === 'harness:stop:workflow-completion-gate'),
43
+ 'p2a.claude.control.stop-reachable',
44
+ 'Stop lost the stop-gate or workflow-completion-gate registration');
45
+ check(groups('PostToolUse').some(group => group.matcher === 'Task' &&
46
+ commands(group).some(command => /subagent-scope-guard\.js/.test(command))),
47
+ 'p2a.claude.control.task-post-general-preserved',
48
+ 'general Task post subagent-scope-guard was removed with the pilot capture');
49
+
50
+ // Positive control that reaches the real hook CLI: a general PostToolUse Bash
51
+ // still persists handoff state. Path-specific sentinel lives in the failure set.
52
+ helper.runHook('state-persist.js', {
53
+ session_id: helper.SESSION_ID,
54
+ hook_event_name: 'PostToolUse',
55
+ tool_name: 'Bash',
56
+ tool_response: { stdout: 'p2a-reach-probe', exitCode: 0 },
57
+ }, { HARNESS_DOC_RECONCILIATION_PILOT: '0' });
58
+ check(helper.stateExists('handoff-state.json'),
59
+ 'p2a.claude.control.state-persist-reaches-code',
60
+ 'the general state-persist hook did not write handoff-state.json');
61
+
62
+ // Codex native subagent adapters live in the packaged manifest. P2a must not
63
+ // edit that file (coordinator owns the mirror), so they must remain reachable.
64
+ check(codexGroups('SubagentStart').some(group =>
65
+ commands(group).some(command => /subagent-start\.js/.test(command))),
66
+ 'p2a.codex.control.subagent-start-adapter',
67
+ 'Codex SubagentStart adapter missing from plugins/harness-everything/hooks/hooks.json');
68
+ check(codexGroups('SubagentStop').some(group =>
69
+ commands(group).some(command => /subagent-stop\.js/.test(command))),
70
+ 'p2a.codex.control.subagent-stop-adapter',
71
+ 'Codex SubagentStop adapter missing from plugins/harness-everything/hooks/hooks.json');
72
+
73
+ // ---- RED assertions: acceptance row ①, one path-specific sentinel each -----
74
+
75
+ for (const { id, event } of RETIRED) {
76
+ check(!registeredIds().includes(id),
77
+ `p2a.claude.${event}.${id}.absent`,
78
+ `hooks/hooks.json still registers ${id} under ${event}`);
79
+ }
80
+ check(!Object.prototype.hasOwnProperty.call(hooks, 'SubagentStart') &&
81
+ !Object.prototype.hasOwnProperty.call(hooks, 'SubagentStop'),
82
+ 'p2a.claude.subagent-events.absent',
83
+ 'Claude manifest still declares SubagentStart/SubagentStop capture events');
84
+ check(!groups('PreToolUse').some(group =>
85
+ commands(group).some(command => /state-persist\.js/.test(command))),
86
+ 'p2a.claude.pre.state-persist.absent',
87
+ 'PreToolUse still routes to state-persist.js (pilot launch capture)');
88
+ check(!groups('PostToolUse').some(group =>
89
+ commands(group).some(command => /state-persist\.js/.test(command)) &&
90
+ /(?:^|\|)(Task|Agent)(?:\||$)/.test(group.matcher || '')),
91
+ 'p2a.claude.post-task.state-persist.absent',
92
+ 'PostToolUse still routes Task/Agent to state-persist.js (pilot result capture)');
93
+ check(!Object.values(hooks).flat().some(group =>
94
+ /Pilot-only doc-reconciliation/.test((group && group.description) || '')),
95
+ 'p2a.claude.pilot-descriptions.absent',
96
+ 'a pilot-only doc-reconciliation registration remains in hooks/hooks.json');
97
+
98
+ helper.finish();
@@ -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');