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.
Files changed (216) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +1 -1
  4. package/CHANGELOG.md +14 -0
  5. package/behavioral-evals/ledger-pairs/README.md +53 -0
  6. package/behavioral-evals/ledger-pairs/arm.js +359 -0
  7. package/behavioral-evals/ledger-pairs/fixture.js +138 -0
  8. package/behavioral-evals/ledger-pairs/preflight.js +96 -0
  9. package/behavioral-evals/ledger-pairs/score.js +155 -0
  10. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/README.md +108 -0
  11. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-plan.json +14 -0
  12. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-result.json +35 -0
  13. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-plan.json +14 -0
  14. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-result.json +35 -0
  15. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-plan.json +14 -0
  16. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-result.json +35 -0
  17. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-plan.json +14 -0
  18. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-result.json +35 -0
  19. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-plan.json +14 -0
  20. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-result.json +35 -0
  21. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-plan.json +14 -0
  22. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-result.json +35 -0
  23. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-plan.json +14 -0
  24. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-result.json +28 -0
  25. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-plan.json +14 -0
  26. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-result.json +35 -0
  27. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-plan.json +13 -0
  28. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-result.json +56 -0
  29. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-plan.json +13 -0
  30. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-result.json +56 -0
  31. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-plan.json +13 -0
  32. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-result.json +56 -0
  33. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-plan.json +13 -0
  34. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-result.json +56 -0
  35. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-plan.json +13 -0
  36. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-result.json +49 -0
  37. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-plan.json +13 -0
  38. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-result.json +49 -0
  39. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-plan.json +13 -0
  40. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-result.json +49 -0
  41. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-plan.json +13 -0
  42. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-result.json +56 -0
  43. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-plan.json +14 -0
  44. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-result.json +44 -0
  45. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/receipt.jsonl +17 -0
  46. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-plan.json +14 -0
  47. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-result.json +41 -0
  48. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/receipt.jsonl +58 -0
  49. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-plan.json +14 -0
  50. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-result.json +50 -0
  51. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/receipt.jsonl +101 -0
  52. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-plan.json +14 -0
  53. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-result.json +44 -0
  54. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/receipt.jsonl +29 -0
  55. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-plan.json +14 -0
  56. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-result.json +44 -0
  57. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/receipt.jsonl +23 -0
  58. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-plan.json +14 -0
  59. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-result.json +34 -0
  60. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/receipt.jsonl +24 -0
  61. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-plan.json +14 -0
  62. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-result.json +47 -0
  63. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/receipt.jsonl +69 -0
  64. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-plan.json +14 -0
  65. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-result.json +44 -0
  66. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/receipt.jsonl +65 -0
  67. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/run-order.sh +18 -0
  68. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/score.json +1032 -0
  69. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/README.md +50 -0
  70. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/collect-rerun.txt +3 -0
  71. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/export-report.json +22 -0
  72. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/host-version.txt +1 -0
  73. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-1.json +18 -0
  74. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-2.json +18 -0
  75. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/labels-observed-excerpt.jsonl +2 -0
  76. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/observations-index-excerpt.json +26 -0
  77. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/plugin-load-lines.txt +1 -0
  78. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/README.md +46 -0
  79. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/observations-index-excerpt.json +16 -0
  80. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/plugin-load-lines.txt +2 -0
  81. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/run-marks.txt +6 -0
  82. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-probe.js +16 -0
  83. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-trace.jsonl +167 -0
  84. package/ci/archive/325-prep/README.md +9 -2
  85. package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
  86. package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
  87. package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
  88. package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
  89. package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
  90. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  91. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
  92. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  93. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
  94. package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
  95. package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
  96. package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
  97. package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
  98. package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
  99. package/ci/fixtures/stop/fail-session-writes.js +109 -0
  100. package/ci/fixtures/workflow-contract/cases.json +3355 -0
  101. package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
  102. package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
  103. package/ci/mechanism-2an-workflow-replay.test.js +324 -0
  104. package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
  105. package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
  106. package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
  107. package/ci/mechanism-325-3b-preparation.test.js +208 -49
  108. package/ci/mechanism-325-3b-s1-review.test.js +20 -828
  109. package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
  110. package/ci/mechanism-325-f3-derived-views.test.js +140 -0
  111. package/ci/mechanism-332-fable-directive.test.js +180 -0
  112. package/ci/mechanism-341-opencode-lane.test.js +164 -284
  113. package/ci/mechanism-35-verification-contract.test.js +246 -0
  114. package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
  115. package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
  116. package/ci/mechanism-397-opencode-observations.test.js +151 -18
  117. package/ci/mechanism-552-ledger-pairs.test.js +159 -0
  118. package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
  119. package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
  120. package/ci/mechanism-553-p3-plan-start.test.js +212 -0
  121. package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
  122. package/ci/mechanism-553-stop.test.js +427 -0
  123. package/ci/mechanism-553-t2a-derive.test.js +110 -0
  124. package/ci/mechanism-553-t2c-derive.test.js +94 -0
  125. package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
  126. package/ci/mechanism-outline-sanitizer.test.js +0 -8
  127. package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
  128. package/ci/mechanism-prb-outline-review.test.js +101 -3283
  129. package/ci/router-workflow-plan.test.js +61 -21
  130. package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
  131. package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
  132. package/docs/doc-workflow-reconciliation.md +17 -2
  133. package/docs/document-lifecycle.md +6 -2
  134. package/docs/platform-capabilities.md +63 -16
  135. package/docs/platform-compatibility.json +5 -5
  136. package/harness-everything/SKILL.md +1 -1
  137. package/harness-everything/scripts/routing-keywords.json +0 -2
  138. package/harness-everything/scripts/tier-router.js +105 -11
  139. package/hooks/hooks.json +0 -46
  140. package/hooks/scripts/lib/workflow-obligations.js +0 -55
  141. package/hooks/scripts/state-persist.js +7 -95
  142. package/hooks/scripts/workflow-disposition.js +0 -2
  143. package/hooks/scripts/workflow-stop-gate.js +17 -30
  144. package/opencode-plugin/index.mjs +6 -70
  145. package/opencode-plugin/plugin.json +1 -1
  146. package/package.json +1 -1
  147. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  148. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  149. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
  150. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
  151. package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
  152. package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
  153. package/plugins/harness-everything/plugin.json +1 -1
  154. package/plugins/harness-everything/rules/AGENTS.md +1 -1
  155. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  156. package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
  157. package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +105 -11
  158. package/sbom.cdx.json +7 -7
  159. package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
  160. package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
  161. package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
  162. package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
  163. package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
  164. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
  165. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
  166. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
  167. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
  168. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
  169. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
  170. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
  171. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
  172. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
  173. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
  174. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
  175. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
  176. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
  177. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
  178. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
  179. package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
  180. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
  181. package/ci/lib/doc-reconciliation-file-spy.js +0 -23
  182. package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
  183. package/ci/lib/doc-reconciliation-replay.js +0 -104
  184. package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
  185. package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
  186. package/ci/mechanism-325-3b-s1.test.js +0 -188
  187. package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
  188. package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
  189. package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
  190. package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
  191. package/ci/mechanism-325-f4-invariants.test.js +0 -606
  192. package/ci/mechanism-325-f4-projections.test.js +0 -392
  193. package/ci/mechanism-325-f4-qualification.test.js +0 -228
  194. package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
  195. package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
  196. package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  197. package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  198. package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  199. package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  200. package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  201. package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  202. package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  203. package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  204. package/hooks/scripts/w6-state-operations.js +0 -239
  205. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  206. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  207. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  208. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  209. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  210. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  211. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  212. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  213. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
  214. package/scripts/system-one-eval-laya.js +0 -112
  215. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
  216. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
@@ -0,0 +1,427 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // General Stop and handoff controls retained while the E1-specific suites retire.
5
+ // Every behavioral leg enters through the real source or packaged hook/CLI.
6
+
7
+ const assert = require('node:assert/strict');
8
+ const fs = require('node:fs');
9
+ const os = require('node:os');
10
+ const path = require('node:path');
11
+ const { execFileSync, spawnSync } = require('node:child_process');
12
+ const { getWorkspaceKey } = require('../scripts/lib/workspace');
13
+ const { canonical } = require('../hooks/scripts/lib/workflow-isolation');
14
+
15
+ const ROOT = path.resolve(__dirname, '..');
16
+ const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-553-stop-'));
17
+ const PRELOAD = path.join(__dirname, 'fixtures', 'stop', 'fail-session-writes.js');
18
+ const FAILURE_SESSION_ENV = 'HARNESS_STOP_TEST_SESSION_DIR';
19
+ const REQUIREMENTS = [
20
+ { id: 'req-change', stepType: 'behavior-change', summary: 'Make the code change', acceptance: 'The change is recorded.' },
21
+ { id: 'req-verify', stepType: 'verification', summary: 'Verify the change', acceptance: 'A successful generic check is recorded.' },
22
+ ];
23
+ const LEGS = [
24
+ {
25
+ id: 'source',
26
+ hooks: path.join(ROOT, 'hooks', 'scripts'),
27
+ kernel: path.join(ROOT, 'harness-everything', 'scripts', 'kernel-router.js'),
28
+ },
29
+ {
30
+ id: 'packaged',
31
+ hooks: path.join(ROOT, 'plugins', 'harness-everything', 'hooks', 'scripts'),
32
+ kernel: path.join(ROOT, 'plugins', 'harness-everything', 'skills', 'harness-everything', 'scripts', 'kernel-router.js'),
33
+ },
34
+ ];
35
+
36
+ let passed = 0;
37
+ let failed = 0;
38
+ let sequence = 0;
39
+
40
+ function check(condition, id, detail = '') {
41
+ if (condition) {
42
+ passed++;
43
+ console.log(` PASS ${id}`);
44
+ } else {
45
+ failed++;
46
+ console.error(` FAIL ${id}${detail ? ` — ${detail}` : ''}`);
47
+ }
48
+ }
49
+
50
+ function writeJson(file, value) {
51
+ fs.mkdirSync(path.dirname(file), { recursive: true });
52
+ fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n', 'utf8');
53
+ }
54
+
55
+ function git(cwd, args) {
56
+ const env = { ...process.env };
57
+ for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
58
+ return execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env });
59
+ }
60
+
61
+ function initWorkspace(workspace) {
62
+ fs.mkdirSync(workspace, { recursive: true });
63
+ fs.writeFileSync(path.join(workspace, 'README.md'), 'baseline\n', 'utf8');
64
+ writeJson(path.join(workspace, 'package.json'), {
65
+ name: 'stop-fixture', version: '1.0.0', private: true,
66
+ scripts: { test: 'node -e "process.exit(0)"' },
67
+ });
68
+ git(workspace, ['init', '-q']);
69
+ git(workspace, ['config', 'user.name', 'Harness Stop Test']);
70
+ git(workspace, ['config', 'user.email', 'stop@example.invalid']);
71
+ git(workspace, ['add', 'README.md', 'package.json']);
72
+ git(workspace, ['-c', 'commit.gpgsign=false', 'commit', '-q', '--no-verify', '-m', 'seed']);
73
+ }
74
+
75
+ function makeCase(leg, label) {
76
+ sequence++;
77
+ const workspace = path.join(TEMP, `${leg.id}-${label}-${sequence}`);
78
+ const stateHome = path.join(TEMP, 'state', `${leg.id}-${label}-${sequence}`);
79
+ const sessionId = `stop553-${leg.id}-${label}-${sequence}`;
80
+ initWorkspace(workspace);
81
+ return { leg, label, workspace, stateHome, sessionId };
82
+ }
83
+
84
+ function childEnv(testCase, sessionDirectory) {
85
+ const env = { ...process.env };
86
+ for (const key of Object.keys(env)) if (key.startsWith('HARNESS_')) delete env[key];
87
+ delete env.CLAUDE_PLUGIN_ROOT;
88
+ delete env.PLUGIN_ROOT;
89
+ delete env.NODE_OPTIONS;
90
+ env.HARNESS_STATE_HOME = testCase.stateHome;
91
+ env.HARNESS_WORKSPACE_ROOT = testCase.workspace;
92
+ if (sessionDirectory) env[FAILURE_SESSION_ENV] = sessionDirectory;
93
+ return env;
94
+ }
95
+
96
+ function run(testCase, script, args = [], options = {}) {
97
+ const commandArgs = options.failWrites ? ['--require', PRELOAD, script, ...args] : [script, ...args];
98
+ const result = spawnSync(process.execPath, commandArgs, {
99
+ cwd: testCase.workspace,
100
+ encoding: 'utf8',
101
+ env: childEnv(testCase, options.failWrites ? options.sessionDirectory : null),
102
+ input: options.input === undefined ? undefined : JSON.stringify(options.input),
103
+ timeout: 60000,
104
+ maxBuffer: 8 * 1024 * 1024,
105
+ });
106
+ if (result.error) throw result.error;
107
+ return result;
108
+ }
109
+
110
+ function sessionDir(testCase) {
111
+ return path.join(testCase.stateHome, 'workspaces', getWorkspaceKey(testCase.workspace), 'state', 'sessions', testCase.sessionId);
112
+ }
113
+
114
+ function workflowFile(testCase) { return path.join(sessionDir(testCase), 'workflow-run.json'); }
115
+ function handoffFile(testCase) { return path.join(sessionDir(testCase), 'handoff-state.json'); }
116
+ function readJson(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
117
+
118
+ function expectZero(result, label) {
119
+ assert.equal(result.status, 0, `${label}: exit=${result.status}\nstdout=${result.stdout}\nstderr=${result.stderr}`);
120
+ }
121
+
122
+ function controller(testCase, args) {
123
+ const result = run(testCase, path.join(testCase.leg.hooks, 'workflow-disposition.js'), args);
124
+ expectZero(result, `workflow-disposition ${args[0]}`);
125
+ return result;
126
+ }
127
+
128
+ function routeAndPlan(testCase, strategy = 'iterative-single') {
129
+ const route = run(testCase, testCase.leg.kernel, [], {
130
+ input: { session_id: testCase.sessionId, cwd: testCase.workspace, prompt: 'Fix this checkout bug and add a regression test.' },
131
+ });
132
+ expectZero(route, 'kernel route');
133
+ controller(testCase, [
134
+ 'plan', '--session-id', testCase.sessionId,
135
+ '--requirements-json', JSON.stringify(REQUIREMENTS), '--strategy', strategy,
136
+ '--evidence', 'two dependent code and verification requirements',
137
+ ]);
138
+ }
139
+
140
+ function resolveAndPass(testCase, stepId, bindingId) {
141
+ controller(testCase, [
142
+ 'binding', '--session-id', testCase.sessionId, '--step-id', stepId,
143
+ '--binding-id', bindingId, '--disposition', 'loaded', '--evidence', 'the required step binding is available',
144
+ ]);
145
+ controller(testCase, [
146
+ 'step', '--session-id', testCase.sessionId, '--step-id', stepId,
147
+ '--disposition', 'pass', '--evidence', 'the requirement acceptance condition is met',
148
+ ]);
149
+ }
150
+
151
+ function start(testCase) {
152
+ controller(testCase, ['start', '--session-id', testCase.sessionId]);
153
+ resolveAndPass(testCase, 'req-change', 'tdd');
154
+ }
155
+
156
+ function genericVerify(testCase, options = {}) {
157
+ const hook = path.join(testCase.leg.hooks, 'state-persist.js');
158
+ return run(testCase, hook, [], {
159
+ input: {
160
+ session_id: testCase.sessionId,
161
+ cwd: testCase.workspace,
162
+ hook_event_name: options.failed ? 'PostToolUseFailure' : 'PostToolUse',
163
+ tool_name: 'Bash',
164
+ tool_input: { command: 'npm test' },
165
+ tool_response: options.failed
166
+ ? { stdout: '', stderr: 'fixture failure', exitCode: 1 }
167
+ : { stdout: 'ok', stderr: '', exitCode: 0 },
168
+ },
169
+ });
170
+ }
171
+
172
+ function stop(testCase, options = {}) {
173
+ return run(testCase, path.join(testCase.leg.hooks, 'workflow-stop-gate.js'), [], {
174
+ input: { session_id: testCase.sessionId, cwd: testCase.workspace, hook_event_name: 'Stop' },
175
+ failWrites: options.failWrites,
176
+ sessionDirectory: sessionDir(testCase),
177
+ });
178
+ }
179
+
180
+ function genericStop(testCase) {
181
+ return run(testCase, path.join(testCase.leg.hooks, 'stop-gate.js'), [], {
182
+ input: { session_id: testCase.sessionId, cwd: testCase.workspace, hook_event_name: 'Stop' },
183
+ });
184
+ }
185
+
186
+ function stripTrailingSeparators(value, isWin32) {
187
+ return String(value).replace(isWin32 ? /[\\/]+$/ : /\/+$/, '');
188
+ }
189
+
190
+ function normaliseWriteFailure(stderr, directory, options = {}) {
191
+ const platform = options.platform || process.platform;
192
+ const isWin32 = platform === 'win32';
193
+ const pathApi = isWin32 ? path.win32 : path.posix;
194
+ const resolveCanonical = options.canonical || (platform === process.platform ? canonical : value => pathApi.resolve(value));
195
+ const matchKey = value => (isWin32
196
+ ? value.replace(/\\/g, '/').replace(/[A-Z]/g, ch => ch.toLowerCase())
197
+ : value);
198
+
199
+ const rawCandidates = [directory, pathApi.resolve(directory), resolveCanonical(directory)];
200
+ const seen = new Set();
201
+ const candidates = [];
202
+ for (const candidate of rawCandidates) {
203
+ if (typeof candidate !== 'string' || !candidate) continue;
204
+ const trimmed = stripTrailingSeparators(candidate, isWin32);
205
+ if (!trimmed) continue;
206
+ const needle = matchKey(trimmed);
207
+ if (seen.has(needle)) continue;
208
+ seen.add(needle);
209
+ candidates.push(needle);
210
+ }
211
+ candidates.sort((a, b) => b.length - a.length);
212
+
213
+ let text = String(stderr || '');
214
+ for (const needle of candidates) {
215
+ const searchText = matchKey(text);
216
+ let cursor = 0;
217
+ let output = '';
218
+ while (cursor < text.length) {
219
+ const idx = searchText.indexOf(needle, cursor);
220
+ if (idx === -1) break;
221
+ const after = idx + needle.length;
222
+ const sep = text[after];
223
+ const validLead = idx === 0 || /\s/.test(text[idx - 1]);
224
+ const validSep = sep === '/' || (isWin32 && sep === '\\');
225
+ if (!validLead || !validSep) {
226
+ output += text.slice(cursor, idx + 1);
227
+ cursor = idx + 1;
228
+ continue;
229
+ }
230
+ let end = after + 1;
231
+ while (end < text.length && !/[\s)]/.test(text[end])) end++;
232
+ const tail = text.slice(after + 1, end);
233
+ const normalisedTail = isWin32 ? tail.replace(/\\/g, '/') : tail;
234
+ output += `${text.slice(cursor, idx)}<session>/${normalisedTail}`;
235
+ cursor = end;
236
+ }
237
+ output += text.slice(cursor);
238
+ text = output;
239
+ }
240
+
241
+ return text.replace(/workflow-run\.json\.\d+\.\d+\.tmp/g, 'workflow-run.json.tmp').trim();
242
+ }
243
+
244
+ const EXPECTED_WRITE_FAILURE = '[Workflow Reminder] EACCES: permission denied, write <session>/workflow-run.json.tmp (simulated session store write failure)';
245
+
246
+ function runNormaliseWriteFailureUnitChecks() {
247
+ const shortDir = 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\harness-553-stop-JFe9HP\\state\\source-off-pending-failure-3\\workspaces\\ws-key\\state\\sessions\\stop553-source-off-pending-failure-3';
248
+ const longDir = 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\harness-553-stop-JFe9HP\\state\\source-off-pending-failure-3\\workspaces\\ws-key\\state\\sessions\\stop553-source-off-pending-failure-3';
249
+ const wrongDir = 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\harness-553-stop-OTHER1\\state\\source-off-pending-failure-3\\workspaces\\ws-key\\state\\sessions\\stop553-source-off-pending-failure-3';
250
+ const winOptions = { platform: 'win32', canonical: () => longDir };
251
+
252
+ const shortStderr = `[Workflow Reminder] EACCES: permission denied, write ${shortDir}\\workflow-run.json.4321.1700000000000.tmp (simulated session store write failure)\n`;
253
+ const shortNormalised = normaliseWriteFailure(shortStderr, shortDir, winOptions);
254
+ check(shortNormalised === EXPECTED_WRITE_FAILURE,
255
+ 'unit.normalise-write-failure.win32-short-path-positive', shortNormalised);
256
+
257
+ const longStderr = `[Workflow Reminder] EACCES: permission denied, write ${longDir.toLowerCase()}\\workflow-run.json.4321.1700000000000.tmp (simulated session store write failure)\n`;
258
+ const longNormalised = normaliseWriteFailure(longStderr, shortDir, winOptions);
259
+ check(longNormalised === EXPECTED_WRITE_FAILURE,
260
+ 'unit.normalise-write-failure.win32-canonical-case-positive', longNormalised);
261
+
262
+ const wrongStderr = `[Workflow Reminder] EACCES: permission denied, write ${wrongDir}\\workflow-run.json.4321.1700000000000.tmp (simulated session store write failure)\n`;
263
+ const wrongNormalised = normaliseWriteFailure(wrongStderr, shortDir, winOptions);
264
+ check(wrongNormalised !== EXPECTED_WRITE_FAILURE && wrongNormalised.includes(wrongDir),
265
+ 'unit.normalise-write-failure.win32-wrong-dir-negative', wrongNormalised);
266
+
267
+ const siblingStderr = `[Workflow Reminder] EACCES: permission denied, write ${shortDir}-other\\workflow-run.json.4321.1700000000000.tmp (simulated session store write failure)\n`;
268
+ const siblingNormalised = normaliseWriteFailure(siblingStderr, shortDir, winOptions);
269
+ check(siblingNormalised !== EXPECTED_WRITE_FAILURE && siblingNormalised.includes(`${shortDir}-other`),
270
+ 'unit.normalise-write-failure.win32-sibling-prefix-negative', siblingNormalised);
271
+
272
+ const outsideBackslashStderr = `[Workflow Reminder] EACCES: permission denied, write ${shortDir}\\workflow-run.json.4321.1700000000000.tmp (simulated\\session store write failure)\n`;
273
+ const outsideBackslashNormalised = normaliseWriteFailure(outsideBackslashStderr, shortDir, winOptions);
274
+ check(outsideBackslashNormalised !== EXPECTED_WRITE_FAILURE && outsideBackslashNormalised.includes('simulated\\session'),
275
+ 'unit.normalise-write-failure.win32-preserves-outside-backslash-negative', outsideBackslashNormalised);
276
+ }
277
+
278
+ function seedSatisfied(testCase) {
279
+ routeAndPlan(testCase);
280
+ start(testCase);
281
+ resolveAndPass(testCase, 'req-verify', 'verification-loop');
282
+ expectZero(genericVerify(testCase), 'successful generic verification');
283
+ expectZero(stop(testCase), 'initial Stop marks workflow satisfied');
284
+ assert.equal(readJson(workflowFile(testCase)).state, 'satisfied');
285
+ return testCase;
286
+ }
287
+
288
+ function runClosedWorkflowControl(leg) {
289
+ const testCase = seedSatisfied(makeCase(leg, 'closed-workflow'));
290
+ const result = run(testCase, path.join(leg.hooks, 'workflow-disposition.js'), [
291
+ 'step', '--session-id', testCase.sessionId, '--step-id', 'req-verify',
292
+ '--disposition', 'pass', '--evidence', 'attempt to mutate the closed workflow',
293
+ ]);
294
+ check(result.status === 2 && /no unresolved workflow contract exists/i.test(result.stderr),
295
+ `closed-workflow@${leg.id}.refuses-late-step`, `exit=${result.status} stderr=${result.stderr.trim()}`);
296
+ }
297
+
298
+ function seedOffPending(testCase) {
299
+ seedSatisfied(testCase);
300
+ const handoff = readJson(handoffFile(testCase));
301
+ handoff.lastEditAt = Date.now() + 10000;
302
+ writeJson(handoffFile(testCase), handoff);
303
+ return testCase;
304
+ }
305
+
306
+ function runOffPendingWriteFailure(leg) {
307
+ const control = seedOffPending(makeCase(leg, 'off-pending-control'));
308
+ const controlStop = stop(control);
309
+ expectZero(controlStop, 'writable OFF pending Stop');
310
+ const controlWorkflow = readJson(workflowFile(control));
311
+ check(controlWorkflow.state === 'satisfied'
312
+ && (controlWorkflow.unresolved || []).includes('verification-after-edit-missing')
313
+ && /verification-after-edit-missing/.test(controlStop.stderr),
314
+ `p2a-off-pending@${leg.id}.positive-control`, JSON.stringify({ state: controlWorkflow.state, unresolved: controlWorkflow.unresolved, stderr: controlStop.stderr.trim() }));
315
+
316
+ const testCase = seedOffPending(makeCase(leg, 'off-pending-failure'));
317
+ const before = fs.readFileSync(workflowFile(testCase), 'utf8');
318
+ const result = stop(testCase, { failWrites: true });
319
+ check(result.status === 0, `p2a-off-pending@${leg.id}.write-failure-exit-0`, `exit=${result.status}`);
320
+ check(normaliseWriteFailure(result.stderr, sessionDir(testCase)) === EXPECTED_WRITE_FAILURE,
321
+ `p2a-off-pending@${leg.id}.real-eacces-stderr`, result.stderr.trim());
322
+ check(fs.readFileSync(workflowFile(testCase), 'utf8') === before,
323
+ `p2a-off-pending@${leg.id}.workflow-unchanged-after-failure`);
324
+ }
325
+
326
+ function seedFablePending(testCase) {
327
+ routeAndPlan(testCase, 'fable-staged');
328
+ return testCase;
329
+ }
330
+
331
+ function runFablePendingWriteFailure(leg) {
332
+ const control = seedFablePending(makeCase(leg, 'fable-pending-control'));
333
+ const controlStop = stop(control);
334
+ expectZero(controlStop, 'writable Fable pending Stop');
335
+ const controlWorkflow = readJson(workflowFile(control));
336
+ check((controlWorkflow.unresolved || []).includes('execution:not-started')
337
+ && /execution:not-started/.test(controlStop.stderr),
338
+ `p2a-fable-on@${leg.id}.positive-control`, JSON.stringify({ unresolved: controlWorkflow.unresolved, stderr: controlStop.stderr.trim() }));
339
+
340
+ const testCase = seedFablePending(makeCase(leg, 'fable-pending-failure'));
341
+ const before = fs.readFileSync(workflowFile(testCase), 'utf8');
342
+ const result = stop(testCase, { failWrites: true });
343
+ check(result.status === 0, `p2a-fable-on@${leg.id}.write-failure-exit-0`, `exit=${result.status}`);
344
+ check(normaliseWriteFailure(result.stderr, sessionDir(testCase)) === EXPECTED_WRITE_FAILURE,
345
+ `p2a-fable-on@${leg.id}.real-eacces-stderr`, result.stderr.trim());
346
+ check(fs.readFileSync(workflowFile(testCase), 'utf8') === before,
347
+ `p2a-fable-on@${leg.id}.workflow-unchanged-after-failure`);
348
+ }
349
+
350
+ function runRepeatedOffNegativeControl(leg) {
351
+ const testCase = seedSatisfied(makeCase(leg, 'off-negative-repeat'));
352
+ const before = fs.readFileSync(workflowFile(testCase), 'utf8');
353
+ const first = stop(testCase, { failWrites: true });
354
+ check(first.status === 0, `p2b-off-negative@${leg.id}.first-stop-exit-0`, `exit=${first.status}`);
355
+ check(normaliseWriteFailure(first.stderr, sessionDir(testCase)) === EXPECTED_WRITE_FAILURE,
356
+ `p2b-off-negative@${leg.id}.first-stop-real-write-failure`, first.stderr.trim());
357
+ check(fs.readFileSync(workflowFile(testCase), 'utf8') === before,
358
+ `p2b-off-negative@${leg.id}.first-stop-keeps-state`);
359
+
360
+ const second = stop(testCase);
361
+ const finalWorkflow = readJson(workflowFile(testCase));
362
+ check(second.status === 0 && second.stderr === '', `p2b-off-negative@${leg.id}.second-stop-exit-and-stderr`, `exit=${second.status} stderr=${second.stderr.trim()}`);
363
+ check(finalWorkflow.state === 'satisfied' && (finalWorkflow.unresolved || []).length === 0,
364
+ `p2b-off-negative@${leg.id}.still-satisfied-after-repeat`, JSON.stringify(finalWorkflow));
365
+ }
366
+
367
+ function markWorkspaceEdited(testCase) {
368
+ const file = path.join(testCase.workspace, 'README.md');
369
+ fs.appendFileSync(file, 'edited after baseline\n', 'utf8');
370
+ const result = run(testCase, path.join(testCase.leg.hooks, 'state-persist.js'), [], {
371
+ input: {
372
+ session_id: testCase.sessionId,
373
+ cwd: testCase.workspace,
374
+ hook_event_name: 'PostToolUse',
375
+ tool_name: 'Edit',
376
+ tool_input: { file_path: file },
377
+ tool_response: { stdout: '' },
378
+ },
379
+ });
380
+ expectZero(result, 'record in-workspace edit');
381
+ }
382
+
383
+ function runOrdinaryStopControl(leg, hasGenericVerify) {
384
+ const label = hasGenericVerify ? 'ordinary-satisfied' : 'ordinary-missing-verify';
385
+ const testCase = makeCase(leg, label);
386
+ routeAndPlan(testCase);
387
+ start(testCase);
388
+ markWorkspaceEdited(testCase);
389
+ if (hasGenericVerify) {
390
+ resolveAndPass(testCase, 'req-verify', 'verification-loop');
391
+ expectZero(genericVerify(testCase), 'ordinary successful verification');
392
+ }
393
+ const beforeHandoff = fs.readFileSync(handoffFile(testCase), 'utf8');
394
+ const result = stop(testCase);
395
+ const finalWorkflow = readJson(workflowFile(testCase));
396
+ check(result.status === 0, `p5.${label}@${leg.id}.stop-exit-0`, `exit=${result.status}`);
397
+ check(fs.readFileSync(handoffFile(testCase), 'utf8') === beforeHandoff,
398
+ `p5.${label}@${leg.id}.handoff-untouched`);
399
+ if (hasGenericVerify) {
400
+ check(finalWorkflow.state === 'satisfied' && (finalWorkflow.unresolved || []).length === 0,
401
+ `p5.${label}@${leg.id}.stop-satisfied`, JSON.stringify(finalWorkflow));
402
+ } else {
403
+ check(finalWorkflow.state === 'running'
404
+ && (finalWorkflow.unresolved || []).includes('step:req-verify:pending')
405
+ && (finalWorkflow.unresolved || []).includes('verification-after-edit-missing')
406
+ && /verification-after-edit-missing/.test(result.stderr),
407
+ `p5.${label}@${leg.id}.stop-still-requires-verify`, JSON.stringify({ state: finalWorkflow.state, unresolved: finalWorkflow.unresolved, stderr: result.stderr.trim() }));
408
+ }
409
+ }
410
+
411
+ try {
412
+ console.log('=== T2-S generic Stop controls ===');
413
+ runNormaliseWriteFailureUnitChecks();
414
+ for (const leg of LEGS) {
415
+ runClosedWorkflowControl(leg);
416
+ runOffPendingWriteFailure(leg);
417
+ runFablePendingWriteFailure(leg);
418
+ runRepeatedOffNegativeControl(leg);
419
+ runOrdinaryStopControl(leg, false);
420
+ runOrdinaryStopControl(leg, true);
421
+ }
422
+ } finally {
423
+ fs.rmSync(TEMP, { recursive: true, force: true });
424
+ }
425
+
426
+ console.log(`\nT2-S generic Stop controls: ${passed} PASS, ${failed} FAIL`);
427
+ if (failed) process.exitCode = 1;
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // #553 T2-A dedicated 3a-H1 derive suite. The two F4-POS-body-edit full-MUST
5
+ // derivation cells moved here from ci/mechanism-325-3b-h1-qualification.test.js.
6
+ // Base, candidate and config are byte-exact copies in ci/fixtures/553-t2a/body-edit/;
7
+ // the read-only F4 corpus is no longer a dependency of this suite.
8
+ // Both legs load the real doc-obligations.js (canonical and packaged). No skip,
9
+ // no fingerprint or golden recapture.
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const ROOT = path.resolve(__dirname, '..');
15
+ const FIXTURE = path.join(__dirname, 'fixtures', '553-t2a', 'body-edit');
16
+ const CONFIG_REL = '.agents/harness-everything/project-docs.json';
17
+ const LEGS = [
18
+ { name: 'source', dir: path.join(ROOT, 'harness-everything', 'scripts') },
19
+ { name: 'packaged', dir: path.join(ROOT, 'plugins', 'harness-everything', 'skills', 'harness-everything', 'scripts') }
20
+ ];
21
+ const EXPECTED_MUSTS = [
22
+ { id: 'doc-change:doc-lint', capability: 'doc-lint', strength: 'MUST', applicability: 'applicable', scope: { paths: ['docs/a.md'] }, acceptance: 'Run document lifecycle lint for every changed governed document.' },
23
+ { id: 'doc-change:link-check', capability: 'link-check', strength: 'MUST', applicability: 'applicable', scope: { paths: ['docs/a.md'] }, acceptance: 'Check in-repository links for every changed governed document.' }
24
+ ];
25
+
26
+ let passCount = 0;
27
+ let failCount = 0;
28
+ let infraCount = 0;
29
+
30
+ function deepEqual(left, right) {
31
+ return JSON.stringify(left) === JSON.stringify(right);
32
+ }
33
+
34
+ function record(status, id, detail) {
35
+ const suffix = detail ? ` - ${detail}` : '';
36
+ if (status === 'PASS') passCount += 1;
37
+ else if (status === 'FAIL') failCount += 1;
38
+ else infraCount += 1;
39
+ console.log(` ${status.padEnd(5)} ${id}${suffix}`);
40
+ }
41
+
42
+ function readFixture(rel) {
43
+ return fs.readFileSync(path.join(FIXTURE, rel), 'utf8');
44
+ }
45
+
46
+ function buildInput() {
47
+ const baseFiles = {
48
+ [CONFIG_REL]: readFixture(path.join('base', CONFIG_REL)),
49
+ 'docs/a.md': readFixture(path.join('base', 'docs', 'a.md')),
50
+ 'docs/b.md': readFixture(path.join('base', 'docs', 'b.md'))
51
+ };
52
+ const candidateFiles = { 'docs/a.md': readFixture(path.join('candidate', 'docs', 'a.md')) };
53
+ return {
54
+ config: JSON.parse(baseFiles[CONFIG_REL]),
55
+ base: { files: baseFiles },
56
+ candidate: { files: { ...baseFiles, ...candidateFiles } }
57
+ };
58
+ }
59
+
60
+ function checkDerivedMusts(leg, input) {
61
+ const id = `H1.${leg.name}.derived-full-musts`;
62
+ const modulePath = path.join(leg.dir, 'doc-obligations.js');
63
+ if (!fs.existsSync(modulePath)) {
64
+ record('INFRA', id, `module-missing: ${path.relative(ROOT, modulePath)} does not exist`);
65
+ return false;
66
+ }
67
+ let module;
68
+ try {
69
+ delete require.cache[require.resolve(modulePath)];
70
+ module = require(modulePath);
71
+ } catch (error) {
72
+ record('INFRA', id, `module-load: ${error.message.split('\n')[0]}`);
73
+ return false;
74
+ }
75
+ const { facts } = module.deriveDocFacts({ base: input.base, candidate: input.candidate, config: input.config, inventory: { complete: true } });
76
+ const obligations = module.deriveDocObligations(facts);
77
+ const fullMusts = obligations.filter(item => item.strength === 'MUST' && item.applicability === 'applicable');
78
+
79
+ let ok = deepEqual(fullMusts, EXPECTED_MUSTS);
80
+ for (const item of fullMusts) {
81
+ if (!item.id || !item.capability || !item.strength || !item.applicability || !item.scope || !Array.isArray(item.scope.paths) || item.scope.paths.some(pathValue => !pathValue) || !item.acceptance) ok = false;
82
+ }
83
+ record(ok ? 'PASS' : 'FAIL', id, ok ? '' : JSON.stringify(fullMusts));
84
+ return ok;
85
+ }
86
+
87
+ function main() {
88
+ console.log('\n== 553 T2-A derive: F4-POS-body-edit full MUSTs, source and packaged legs ==');
89
+ let input;
90
+ try {
91
+ input = buildInput();
92
+ } catch (error) {
93
+ console.error(`[553-t2a-derive] infrastructure: fixture unreadable: ${error.message.split('\n')[0]}`);
94
+ return 2;
95
+ }
96
+ for (const leg of LEGS) checkDerivedMusts(leg, input);
97
+
98
+ console.log('\n== 553 T2-A derive evidence ==');
99
+ console.log(`passing checks: ${passCount}`);
100
+ console.log(`unexpected failures: ${failCount}`);
101
+ console.log(`infrastructure faults: ${infraCount}`);
102
+ if (failCount === 0 && infraCount === 0) {
103
+ console.log('\nSTATUS: GREEN (all assertions passed)');
104
+ return 0;
105
+ }
106
+ console.log('\nSTATUS: NOT-GREEN');
107
+ return 1;
108
+ }
109
+
110
+ process.exitCode = main();
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Dedicated 3a derived-MUST suite (T2-C #553): preserves doc-change:derived-regenerate
5
+ // MUST semantics from ci/mechanism-e1-derived-regenerate.test.js against the surviving
6
+ // doc-obligations.js entry on both source and packaged legs.
7
+ const assert = require('node:assert/strict');
8
+ const fs = require('node:fs');
9
+ const path = require('node:path');
10
+ const helper = require('./test-helper');
11
+
12
+ const ROOT = path.resolve(__dirname, '..');
13
+ const FIXTURE_DIR = path.join(__dirname, 'fixtures', '553-t2c', 'derived-regenerate-must');
14
+ const VIEW = 'docs/governed-index.md';
15
+ const LEGS = [
16
+ { name: 'source', modulePath: path.join(ROOT, 'harness-everything', 'scripts', 'doc-obligations.js') },
17
+ { name: 'packaged', modulePath: path.join(ROOT, 'plugins', 'harness-everything', 'skills', 'harness-everything', 'scripts', 'doc-obligations.js') },
18
+ ];
19
+
20
+ function readTree(root) {
21
+ const files = {};
22
+ if (!fs.existsSync(root)) return files;
23
+ const walk = dir => {
24
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
25
+ const full = path.join(dir, entry.name);
26
+ if (entry.isDirectory()) walk(full);
27
+ else {
28
+ const rel = path.relative(root, full).split(path.sep).join('/');
29
+ files[rel] = fs.readFileSync(full, 'utf8');
30
+ }
31
+ }
32
+ };
33
+ walk(root);
34
+ return files;
35
+ }
36
+
37
+ const CONFIG = JSON.parse(fs.readFileSync(path.join(FIXTURE_DIR, 'config.json'), 'utf8'));
38
+ const BASE_FILES = readTree(path.join(FIXTURE_DIR, 'base'));
39
+ const CANDIDATE_FILES = readTree(path.join(FIXTURE_DIR, 'candidate'));
40
+
41
+ console.log('\n[553-t2c] derived-regenerate MUST semantics (source + packaged)...');
42
+
43
+ for (const leg of LEGS) {
44
+ let deriveDocFacts;
45
+ let deriveDocObligations;
46
+ try {
47
+ ({ deriveDocFacts, deriveDocObligations } = require(leg.modulePath));
48
+ } catch (error) {
49
+ helper.check(`553-t2c [${leg.name}] doc-obligations module is available`, false, error.message);
50
+ continue;
51
+ }
52
+
53
+ try {
54
+ const result = deriveDocFacts({
55
+ base: { files: { ...BASE_FILES } },
56
+ candidate: { files: { ...CANDIDATE_FILES } },
57
+ config: CONFIG,
58
+ });
59
+ const obligations = deriveDocObligations(result.facts);
60
+ const obligation = obligations.find(item => item.capability === 'derived-regenerate');
61
+ assert.ok(obligation, 'derived-regenerate must derive from the real baseline and candidate bytes');
62
+ assert.equal(obligation.id, 'doc-change:derived-regenerate');
63
+ assert.equal(obligation.strength, 'MUST');
64
+ assert.equal(obligation.applicability, 'applicable', 'derived-regenerate must not disappear as N/A');
65
+ assert.deepEqual(obligation.scope, { paths: [VIEW] });
66
+ helper.check(`553-t2c [${leg.name}] wholeSeamFixture derives doc-change:derived-regenerate as applicable MUST`, true);
67
+ } catch (error) {
68
+ helper.check(`553-t2c [${leg.name}] wholeSeamFixture derives doc-change:derived-regenerate as applicable MUST`, false, error.message);
69
+ }
70
+
71
+ try {
72
+ const staleCandidate = {
73
+ ...CANDIDATE_FILES,
74
+ [VIEW]: CANDIDATE_FILES[VIEW] + '\nmanual stale edit\n',
75
+ };
76
+ const result = deriveDocFacts({
77
+ base: { files: { ...BASE_FILES } },
78
+ candidate: { files: staleCandidate },
79
+ config: CONFIG,
80
+ });
81
+ const obligations = deriveDocObligations(result.facts);
82
+ const obligation = obligations.find(item => item.capability === 'derived-regenerate');
83
+ assert.ok(obligation, 'stale view must remain an expected derived MUST');
84
+ assert.equal(obligation.id, 'doc-change:derived-regenerate');
85
+ assert.equal(obligation.strength, 'MUST');
86
+ assert.equal(obligation.applicability, 'applicable', 'stale view must remain applicable');
87
+ assert.deepEqual(obligation.scope, { paths: [VIEW] });
88
+ helper.check(`553-t2c [${leg.name}] stale derived view retains doc-change:derived-regenerate as applicable MUST`, true);
89
+ } catch (error) {
90
+ helper.check(`553-t2c [${leg.name}] stale derived view retains doc-change:derived-regenerate as applicable MUST`, false, error.message);
91
+ }
92
+ }
93
+
94
+ helper.finish();