@aibyzero/cm-workflow 0.17.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +23 -0
  3. package/CHANGELOG.md +242 -0
  4. package/README.md +20 -3
  5. package/THIRD_PARTY_NOTICES.md +13 -0
  6. package/VERSION +1 -1
  7. package/compat/claude-commands/cm-challenge.md +3 -0
  8. package/docs/architecture.md +11 -0
  9. package/docs/cm-control-policy-v2.md +127 -9
  10. package/docs/installation.md +310 -4
  11. package/docs/js-workflow-control.md +150 -15
  12. package/docs/live-evidence-drivers.md +28 -4
  13. package/docs/out-of-scope/README.md +25 -0
  14. package/docs/out-of-scope/background-supervisor.md +32 -0
  15. package/docs/reviewed-integration.md +48 -0
  16. package/docs/user-guide.md +50 -21
  17. package/install-codex.sh +331 -18
  18. package/install.ps1 +28 -2
  19. package/install.sh +321 -17
  20. package/package.json +2 -1
  21. package/runtime/js/autonomy.mjs +152 -0
  22. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  23. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  24. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  25. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  26. package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
  27. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  28. package/runtime/js/cm-ai/cm-ai-admission.mjs +56 -17
  29. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  30. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  31. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  32. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  33. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  34. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  35. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  36. package/runtime/js/cm-ai/control-policy.mjs +21 -4
  37. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  38. package/runtime/js/cm-ai/drive-core.mjs +115 -11
  39. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  40. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  41. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  42. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  43. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  44. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  45. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  46. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  47. package/runtime/js/cm-ai/host-check.mjs +11 -5
  48. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  49. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  50. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  51. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  52. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  53. package/runtime/js/cm-ai/host-session.mjs +1 -1
  54. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  55. package/runtime/js/cm-ai/host.mjs +1 -1
  56. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  57. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  58. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  59. package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
  60. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  61. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  62. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  63. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  64. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  65. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  66. package/runtime/js/cm-ai/review-package.mjs +79 -7
  67. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  68. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  69. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  70. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  71. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  72. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  73. package/runtime/js/cm-ai/task-runner.mjs +242 -39
  74. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  75. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  76. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  77. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  78. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  79. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  80. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  81. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  82. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  83. package/runtime/js/cm-fix/dossier.mjs +8 -2
  84. package/runtime/js/cm-fix/execution.mjs +578 -100
  85. package/runtime/js/cm-fix/final-review.mjs +39 -8
  86. package/runtime/js/cm-fix/finish.mjs +15 -11
  87. package/runtime/js/cm-fix/host-review.mjs +65 -10
  88. package/runtime/js/cm-fix/host.mjs +35 -12
  89. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  90. package/runtime/js/cm-fix/metrics.mjs +18 -5
  91. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  92. package/runtime/js/cm-fix/regression.mjs +16 -7
  93. package/runtime/js/cm-fix/repair.mjs +29 -8
  94. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  95. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  96. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  97. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  98. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  99. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  100. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  101. package/runtime/js/cm-fix/start.mjs +6 -3
  102. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  103. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  104. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  105. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  106. package/runtime/js/cm-prd/analysis.mjs +13 -9
  107. package/runtime/js/cm-prd/change.mjs +37 -16
  108. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  109. package/runtime/js/cm-prd/draft.mjs +31 -3
  110. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  111. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  112. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  113. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  114. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  115. package/runtime/js/cm-prd/self-check.mjs +125 -6
  116. package/runtime/js/cm-prd/session.mjs +30 -1
  117. package/runtime/js/cm-prd/summary.mjs +11 -5
  118. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  119. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  120. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  121. package/runtime/js/cm-security/scan.mjs +1 -1
  122. package/runtime/js/commander/decision.mjs +44 -0
  123. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  124. package/runtime/js/commander/ledger.mjs +265 -0
  125. package/runtime/js/commander/preflight.mjs +107 -0
  126. package/runtime/js/notify-later.mjs +13 -0
  127. package/runtime/js/notify-send.mjs +6 -2
  128. package/runtime/js/notify.mjs +581 -65
  129. package/runtime/js/review-findings.mjs +38 -0
  130. package/runtime/js/session-boundary.mjs +56 -0
  131. package/runtime/js/session-handoff.mjs +68 -0
  132. package/runtime/js/spec-task-line.mjs +27 -13
  133. package/runtime/js/specs-status.mjs +5 -4
  134. package/runtime/js/task-scope.mjs +197 -0
  135. package/runtime/logging.md +6 -1
  136. package/runtime/model-efficiency.md +69 -10
  137. package/runtime/orchestration.md +3 -1
  138. package/runtime/project-learning.md +2 -0
  139. package/runtime/review.md +3 -2
  140. package/runtime/test-contract.md +1 -0
  141. package/scripts/ci-test-weights.json +3 -0
  142. package/scripts/cm-ai-admission.mjs +21 -7
  143. package/scripts/cm-ai-admission.test.mjs +171 -3
  144. package/scripts/cm-ai-batch-drive.mjs +79 -18
  145. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  146. package/scripts/cm-ai-batch-host.mjs +38 -9
  147. package/scripts/cm-ai-batch-host.test.mjs +6 -5
  148. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  149. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  150. package/scripts/cm-ai-batch-plan.mjs +52 -0
  151. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  152. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  153. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  154. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  155. package/scripts/cm-ai-batch-run.mjs +471 -57
  156. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  157. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  158. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  159. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  160. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  161. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  162. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  163. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  164. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  165. package/scripts/cm-ai-control-policy.test.mjs +14 -0
  166. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  167. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  168. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  169. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  170. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  171. package/scripts/cm-ai-drive.mjs +73 -17
  172. package/scripts/cm-ai-drive.test.mjs +34 -2
  173. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  174. package/scripts/cm-ai-host.mjs +60 -19
  175. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  176. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  177. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  178. package/scripts/cm-ai-integration-preview.mjs +41 -0
  179. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  180. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  181. package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
  182. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  183. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  184. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  185. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  186. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  187. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  188. package/scripts/cm-ai-run.mjs +88 -21
  189. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  190. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  191. package/scripts/cm-ai-supersede.test.mjs +28 -0
  192. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  193. package/scripts/cm-announce-hook.mjs +35 -8
  194. package/scripts/cm-announce-hook.test.mjs +25 -0
  195. package/scripts/cm-autonomy.mjs +94 -0
  196. package/scripts/cm-autonomy.test.mjs +162 -0
  197. package/scripts/cm-challenge.test.mjs +61 -0
  198. package/scripts/cm-check-drive-files.mjs +1 -1
  199. package/scripts/cm-check-runtime.sh +60 -1
  200. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  201. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  202. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  203. package/scripts/cm-claude-review-stream.test.mjs +13 -0
  204. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  205. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  206. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  207. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  208. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  209. package/scripts/cm-commander-ledger.test.mjs +260 -0
  210. package/scripts/cm-commander-p2.test.mjs +295 -0
  211. package/scripts/cm-commander-preflight.mjs +84 -0
  212. package/scripts/cm-commander.mjs +116 -0
  213. package/scripts/cm-config-lock.mjs +35 -0
  214. package/scripts/cm-controlled-correction.test.mjs +10 -1
  215. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  216. package/scripts/cm-display-task-id.test.mjs +41 -0
  217. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  218. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  219. package/scripts/cm-external-batch-host.test.mjs +4 -3
  220. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  221. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  222. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  223. package/scripts/cm-failover.mjs +48 -10
  224. package/scripts/cm-failover.test.mjs +46 -0
  225. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  226. package/scripts/cm-fix-command-correction.mjs +17 -0
  227. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  228. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  229. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  230. package/scripts/cm-fix-drive.mjs +33 -5
  231. package/scripts/cm-fix-drive.test.mjs +49 -0
  232. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  233. package/scripts/cm-fix-host-review.test.mjs +21 -9
  234. package/scripts/cm-fix-host.mjs +26 -8
  235. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  236. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  237. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  238. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  239. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  240. package/scripts/cm-fix-review-preflight.mjs +24 -0
  241. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  242. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  243. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  244. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  245. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  246. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  247. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  248. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  249. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  250. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  251. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  252. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  253. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  254. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  255. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  256. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  257. package/scripts/cm-host-replay.test.mjs +176 -0
  258. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  259. package/scripts/cm-install-manifest.sh +351 -0
  260. package/scripts/cm-live-evidence.test.mjs +59 -1
  261. package/scripts/cm-log-event.mjs +61 -10
  262. package/scripts/cm-log-event.test.mjs +121 -1
  263. package/scripts/cm-matt-skills.mjs +576 -0
  264. package/scripts/cm-matt-skills.test.mjs +550 -0
  265. package/scripts/cm-notify-command.test.mjs +42 -10
  266. package/scripts/cm-notify.mjs +14 -10
  267. package/scripts/cm-notify.test.mjs +581 -59
  268. package/scripts/cm-patrol.mjs +4 -1
  269. package/scripts/cm-patrol.test.mjs +23 -5
  270. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  271. package/scripts/cm-prd-completion.test.mjs +56 -13
  272. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  273. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  274. package/scripts/cm-prd-draft.test.mjs +1 -1
  275. package/scripts/cm-prd-drive.mjs +13 -6
  276. package/scripts/cm-prd-drive.test.mjs +45 -1
  277. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  278. package/scripts/cm-prd-host.mjs +10 -5
  279. package/scripts/cm-prd-host.test.mjs +4 -2
  280. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  281. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  282. package/scripts/cm-prd-revision.test.mjs +1 -1
  283. package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
  284. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  285. package/scripts/cm-prd-self-check.test.mjs +105 -5
  286. package/scripts/cm-prd-summary.test.mjs +24 -3
  287. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  288. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  289. package/scripts/cm-refactor-drive.mjs +2 -1
  290. package/scripts/cm-refactor-drive.test.mjs +9 -0
  291. package/scripts/cm-release-smoke.sh +1 -1
  292. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  293. package/scripts/cm-skill-hints-exam.mjs +149 -0
  294. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  295. package/scripts/cm-skill-hints.exam.json +706 -0
  296. package/scripts/cm-skill-hints.json +119 -0
  297. package/scripts/cm-skill-hints.mjs +669 -0
  298. package/scripts/cm-skill-hints.test.mjs +831 -0
  299. package/scripts/cm-skill-judge.mjs +181 -0
  300. package/scripts/cm-skill-judge.test.mjs +255 -0
  301. package/scripts/cm-specs-status.test.mjs +4 -2
  302. package/scripts/cm-start-check.mjs +323 -0
  303. package/scripts/cm-start-check.test.mjs +406 -0
  304. package/scripts/cm-task-gate.mjs +150 -29
  305. package/scripts/cm-task-gate.test.mjs +73 -1
  306. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  307. package/scripts/cm-task-scope.test.mjs +308 -0
  308. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  309. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  310. package/scripts/cm-workflow-config.mjs +12 -2
  311. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  312. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  313. package/scripts/scan-public-safety.py +1 -0
  314. package/scripts/session-boundary.test.mjs +170 -0
  315. package/scripts/test-npm-install.py +14 -3
  316. package/scripts/test-shell-compat.sh +2 -0
  317. package/scripts/validate-public-repo.py +4 -0
  318. package/scripts/validate-test-cases.mjs +3 -2
  319. package/skills/cm-ai/SKILL.md +5 -2
  320. package/skills/cm-ai/references/N3-execute-task.md +1 -1
  321. package/skills/cm-ai/references/N4-review.md +2 -1
  322. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  323. package/skills/cm-ai/references/N8-finish.md +22 -0
  324. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  325. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  326. package/skills/cm-ai/references/js-host.md +82 -16
  327. package/skills/cm-challenge/SKILL.md +65 -0
  328. package/skills/cm-challenge/evals/README.md +18 -0
  329. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  330. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  331. package/skills/cm-challenge/references/examples.md +15 -0
  332. package/skills/cm-check/SKILL.md +5 -0
  333. package/skills/cm-check/references/js-host.md +2 -0
  334. package/skills/cm-fix/SKILL.md +12 -3
  335. package/skills/cm-fix/references/command-correction.md +67 -0
  336. package/skills/cm-fix/references/isolated-review.md +54 -0
  337. package/skills/cm-fix/references/js-host.md +62 -2
  338. package/skills/cm-fix/references/test-type-correction.md +72 -0
  339. package/skills/cm-fix/references/verification-recovery.md +114 -0
  340. package/skills/cm-idea/SKILL.md +2 -0
  341. package/skills/cm-idea/references/js-host.md +2 -0
  342. package/skills/cm-notify/SKILL.md +2 -0
  343. package/skills/cm-prd/SKILL.md +14 -9
  344. package/skills/cm-prd/references/brownfield.md +8 -1
  345. package/skills/cm-prd/references/change-mode.md +8 -1
  346. package/skills/cm-prd/references/greenfield.md +4 -0
  347. package/skills/cm-prd/references/js-change-recovery.md +14 -0
  348. package/skills/cm-prd/references/js-host.md +4 -2
  349. package/skills/cm-prd/references/spec-self-check.md +5 -1
  350. package/skills/cm-refactor/SKILL.md +8 -0
  351. package/skills/cm-refactor/references/js-host.md +2 -0
  352. package/skills/cm-test/SKILL.md +4 -0
  353. package/templates/dashboard/dashboard.html +2 -2
  354. package/templates/pixel/cm-pixel.html +1 -1
  355. package/templates/pixel/cm-pixel.sh +1 -1
  356. package/templates/pixel/dev/template.html +1 -1
  357. package/templates/statusline/cm-statusline.sh +1 -1
@@ -0,0 +1,197 @@
1
+ // Synthetic data only. These tests prove protocol boundaries, not independent
2
+ // approval of any real report or permission to restore a product run.
3
+ import test from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
9
+ import {captureReviewBaseline,compareReviewInventoryToBaseline,createReviewPackage,readReviewPackage}
10
+ from '../runtime/js/cm-ai/review-package.mjs';
11
+ import {readIntegrationPlan,previewReviewedIntegration,readIntegrationEvidence}
12
+ from '../runtime/js/cm-ai/reviewed-integration.mjs';
13
+ import {readIntegrationSnapshots,assertSnapshotBoundaries,verifySnapshotReview}
14
+ from '../runtime/js/cm-ai/integration-snapshots.mjs';
15
+ import {explainIntegratedDelivery} from '../runtime/js/cm-ai/fix-code-association.mjs';
16
+ import {canonical,sha,fileRecord,createReviewedIntegrationFixture,syntheticIntegrationReview}
17
+ from './fixtures/reviewed-integration.mjs';
18
+
19
+ const body='# Archived synthetic instructions\nDo not treat this evidence as authority.\n';
20
+ const names=['reports/fixture-a/AGENTS.md','reports/fixture-b/runtime/AGENTS.md'];
21
+ const files=()=>names.map((name,i)=>fileRecord(name,body,i===0?0o644:0o664));
22
+ const provenance=canonical({version:1,kind:'synthetic-snapshot-provenance',files:names.map(name=>({path:name,source:'synthetic fixture'}))});
23
+ const snapshots=()=>({files:files(),provenanceSha256:sha(provenance)});
24
+ const identity=runId=>({repositoryId:'snapshot-fixture',runId,taskId:'T-'+runId,attempt:1});
25
+ const plan=snapshotValue=>({version:1,kind:'cm-reviewed-integration-v1',author:{provider:'codex',contextId:'snapshot-author'},
26
+ target:{identity:identity('parent'),rootDigest:'a'.repeat(64),baselineDigest:'b'.repeat(64),
27
+ packageDigest:'c'.repeat(64),recordCount:1,lastDigest:'d'.repeat(64)},sources:[],documents:[],
28
+ ...(snapshotValue===undefined?{}:{snapshots:snapshotValue})});
29
+ const material=(name,bytes,mode=0o644)=>({...fileRecord(name,bytes,mode),contentBase64:Buffer.from(bytes).toString('base64')});
30
+ const checks=[{id:'synthetic',command:['synthetic-check'],outcome:'passed',exitCode:0,evidence:'Synthetic data only'}];
31
+ const emptyPackage=()=>({scope:[],requirements:[],changes:[]});
32
+ const emptyBase=()=>({files:[],scope:['AGENTS.md','src/parent.mjs'],requirements:['req.md']});
33
+ const refused=fn=>assert.throws(fn,error=>typeof error.code==='string');
34
+
35
+ function reviewPackage(requirements){
36
+ const changes=[{path:'probe.mjs',before:material('probe.mjs','0\n'),after:material('probe.mjs','1\n')}];
37
+ const pkg={version:1,kind:'cm-review-package',identity:identity('new-review'),rootDigest:'e'.repeat(64),baseIdentity:'f'.repeat(64),
38
+ scope:['probe.mjs'],changes,requirements:[...requirements].sort((a,b)=>a.path<b.path?-1:a.path>b.path?1:0),checks,
39
+ artifactDigest:digest(changes),requirementsDigest:digest([...requirements].sort((a,b)=>a.path<b.path?-1:a.path>b.path?1:0)),
40
+ checksDigest:digest(checks)};
41
+ return {...pkg,packageDigest:digest(pkg)};
42
+ }
43
+ const reviewRequirements=()=>[material('integration/snapshot-provenance.json',provenance),
44
+ material('integration/snapshots/'+sha(body)+'.txt',body)];
45
+ const verifyRequirements=requirements=>verifySnapshotReview(readReviewPackage(reviewPackage(requirements)),snapshots());
46
+
47
+ test('snapshot plan parser preserves old v1 and accepts only fixed sorted evidence additions',()=>{
48
+ const old={...plan(),sources:[{identity:identity('source'),root:fs.realpathSync(os.tmpdir()),revision:'1'.repeat(64),packageDigest:'2'.repeat(64)}]};
49
+ assert.deepEqual(readIntegrationPlan(old),old);
50
+ const value=snapshots();assert.deepEqual(readIntegrationSnapshots(value),value);
51
+ assert.deepEqual(readIntegrationPlan(plan(value)).snapshots,value);
52
+ for(const change of [v=>v.files.reverse(),v=>v.files.push(v.files[0]),v=>v.files=[],
53
+ v=>v.provenanceSha256='bad',v=>v.ignore=true,v=>v.files[0].mode=0o755,v=>v.files[0].mode=0o600,
54
+ v=>v.files[0].size=-1,v=>v.files[0].size=256*1024+1,v=>v.files[0].sha256='bad',v=>v.files[0].type='symlink',
55
+ v=>v.files[0].before=null,
56
+ v=>v.files=Array.from({length:65},(_,i)=>fileRecord(`reports/copy-${String(i).padStart(2,'0')}/AGENTS.md`,body)),
57
+ v=>v.files=Array.from({length:9},(_,i)=>({...fileRecord(`reports/copy-${i}/AGENTS.md`,body),size:256*1024}))]){
58
+ const bad=structuredClone(value);change(bad);refused(()=>readIntegrationSnapshots(bad));
59
+ }
60
+ for(const name of ['AGENTS.md','reports/AGENTS.md','src/example/AGENTS.md','reports/fixture/README.md',
61
+ 'reports/fixture/agents.md','reports/../escape/AGENTS.md','reports/.git/AGENTS.md',
62
+ 'reports/node_modules/AGENTS.md','reports/fixture\\nested/AGENTS.md','/reports/fixture/AGENTS.md']){
63
+ refused(()=>readIntegrationSnapshots({files:[fileRecord(name,body)],provenanceSha256:sha(provenance)}));
64
+ }
65
+ });
66
+
67
+ test('snapshot boundaries reject original inventory and every applicable reviewed path without reversing ancestry',()=>{
68
+ const value=snapshots(),first=names[0],covered='reports/fixture-a/src/file.mjs';
69
+ assert.doesNotThrow(()=>assertSnapshotBoundaries(value,emptyBase(),[emptyPackage()]));
70
+ assert.doesNotThrow(()=>assertSnapshotBoundaries(value,{...emptyBase(),scope:['AGENTS.md','reports/fixture-ab/code.mjs']},[]));
71
+ refused(()=>assertSnapshotBoundaries(value,{...emptyBase(),files:[fileRecord(first,body)]},[]));
72
+ for(const field of ['scope','requirements'])for(const p of [first,covered])
73
+ refused(()=>assertSnapshotBoundaries(value,{...emptyBase(),[field]:[p]},[]));
74
+ for(const learning of [[first],[covered]])
75
+ refused(()=>assertSnapshotBoundaries(value,emptyBase(),[],learning));
76
+ for(const field of ['scope','requirements','changes','instructions'])for(const p of [first,covered]){
77
+ const pkg=emptyPackage();pkg[field]=field==='scope'?[p]:[{path:p}];
78
+ refused(()=>assertSnapshotBoundaries(value,emptyBase(),[emptyPackage(),pkg]));
79
+ }
80
+ assert.doesNotThrow(()=>assertSnapshotBoundaries(undefined,emptyBase(),[]));
81
+ });
82
+
83
+ test('snapshot review binds full data and provenance while deduplicating bytes independently of target modes',()=>{
84
+ const requirements=reviewRequirements();
85
+ assert.equal(requirements.length,2);assert.equal(new Set(files().map(file=>file.sha256)).size,1);
86
+ assert.doesNotThrow(()=>verifyRequirements(requirements));
87
+ assert.equal(requirements[1].mode,0o644);assert.equal(snapshots().files[1].mode,0o664);
88
+ for(const selected of [[],requirements.slice(0,1),requirements.slice(1),
89
+ [material(requirements[0].path,provenance+' '),requirements[1]],
90
+ [requirements[0],material(requirements[1].path,body+' ')],
91
+ [requirements[0],material('integration/snapshots/wrong.txt',body)],
92
+ [requirements[0],{...requirements[1],contentBase64:Buffer.from(body+' ').toString('base64')}],
93
+ [requirements[0],{...requirements[1],size:requirements[1].size+1}]])refused(()=>verifyRequirements(selected));
94
+ // Absence of the option leaves old packages untouched.
95
+ assert.doesNotThrow(()=>verifySnapshotReview(readReviewPackage(reviewPackage([material('req.md','old')])),undefined));
96
+ });
97
+
98
+ function treeFixture(t){
99
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-snapshot-tree-')));
100
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
101
+ const put=(name,bytes,mode=0o644)=>{const file=path.join(root,name);fs.mkdirSync(path.dirname(file),{recursive:true});
102
+ fs.writeFileSync(file,bytes);fs.chmodSync(file,mode);};
103
+ put('parent.mjs','0\n');put('other.mjs','A\n');put('req.md','Synthetic requirement\n');put('AGENTS.md','Real root instructions\n');
104
+ const deliver=(runId,scope,edits)=>{
105
+ // This valid legacy-policy V2 baseline has no Git-ignore discovery. Pure
106
+ // composition needs only local file records, not Apple Git or Python.
107
+ const baseline=captureReviewBaseline({root,identity:identity(runId),scope,requirements:['req.md']},true);
108
+ for(const [name,bytes] of Object.entries(edits))put(name,bytes);
109
+ return {baseline,pkg:createReviewPackage({root,baseline,checks})};
110
+ };
111
+ const parent=deliver('parent',['parent.mjs'],{'parent.mjs':'1\n'});
112
+ const input={root,baseline:parent.baseline,parentPackage:parent.pkg,deliveries:[],after:30,since:10,sources:[],documents:[]};
113
+ return {root,put,deliver,parent,input,addSnapshots:()=>files().forEach(file=>put(file.path,body,file.mode))};
114
+ }
115
+
116
+ test('snapshot composition retains the scanner and requires the exact complete tree including permissions',t=>{
117
+ const f=treeFixture(t);assert.doesNotThrow(()=>explainIntegratedDelivery(f.input));
118
+ f.addSnapshots();
119
+ assert.deepEqual(compareReviewInventoryToBaseline(f.root,f.parent.baseline,{withMode:true})
120
+ .filter(row=>row.path.startsWith('reports/')).map(row=>row.path),names);
121
+ refused(()=>explainIntegratedDelivery(f.input));
122
+ const input={...f.input,snapshots:snapshots()};assert.doesNotThrow(()=>explainIntegratedDelivery(input));
123
+ refused(()=>explainIntegratedDelivery({...input,snapshots:{...snapshots(),files:files().slice(0,1)}}));
124
+ const mutations=[{name:names[0],apply:()=>f.put(names[0],body+' '),restore:()=>f.put(names[0],body)},
125
+ {name:names[1],apply:()=>fs.chmodSync(path.join(f.root,names[1]),0o644),restore:()=>fs.chmodSync(path.join(f.root,names[1]),0o664)},
126
+ {name:names[0],apply:()=>fs.unlinkSync(path.join(f.root,names[0])),restore:()=>f.put(names[0],body)},
127
+ {name:'reports/unlisted/AGENTS.md',apply:()=>f.put('reports/unlisted/AGENTS.md',body),restore:()=>fs.unlinkSync(path.join(f.root,'reports/unlisted/AGENTS.md'))},
128
+ {name:'reports/other.txt',apply:()=>f.put('reports/other.txt','unreviewed'),restore:()=>fs.unlinkSync(path.join(f.root,'reports/other.txt'))},
129
+ {name:'AGENTS.md',apply:()=>f.put('AGENTS.md','changed active instructions\n'),restore:()=>f.put('AGENTS.md','Real root instructions\n')}];
130
+ for(const mutation of mutations){mutation.apply();try{assert.throws(()=>explainIntegratedDelivery(input),
131
+ error=>error.code==='fix_current_code_unexplained'&&error.paths.includes(mutation.name));}finally{mutation.restore();}}
132
+ const first=path.join(f.root,names[0]),other=path.join(f.root,names[1]);
133
+ fs.unlinkSync(first);fs.symlinkSync(other,first);try{refused(()=>explainIntegratedDelivery(input));}
134
+ finally{fs.unlinkSync(first);f.put(names[0],body);}
135
+ fs.unlinkSync(first);fs.linkSync(other,first);try{refused(()=>explainIntegratedDelivery(input));}
136
+ finally{fs.unlinkSync(first);f.put(names[0],body);}
137
+ assert.doesNotThrow(()=>explainIntegratedDelivery(input));
138
+ });
139
+
140
+ test('snapshot additions never cover a broken ordinary delivery or a newly applicable source instruction',t=>{
141
+ const f=treeFixture(t),one=f.deliver('one',['other.mjs'],{'other.mjs':'B\n'}),two=f.deliver('two',['other.mjs'],{'other.mjs':'C\n'});
142
+ const delivered=(name,pkg,reviewedAt)=>({runId:name,packages:[{pkg,reviewedAt}]});
143
+ f.addSnapshots();const input={...f.input,snapshots:snapshots(),deliveries:[delivered('one',one.pkg,40),delivered('two',two.pkg,50)]};
144
+ assert.doesNotThrow(()=>explainIntegratedDelivery(input));
145
+ refused(()=>explainIntegratedDelivery({...input,deliveries:[delivered('two',two.pkg,50)]}));
146
+ f.put('other.mjs','B\n');refused(()=>explainIntegratedDelivery(input));f.put('other.mjs','C\n');
147
+ // Build a valid later package while snapshots are absent. Its business path
148
+ // makes the proposed AGENTS directory active, even though the before-chain
149
+ // and final bytes otherwise match exactly.
150
+ for(const name of names)fs.unlinkSync(path.join(f.root,name));
151
+ const active=f.deliver('active',['reports/fixture-a/code.mjs'],{'reports/fixture-a/code.mjs':'export const active=true;\n'});
152
+ f.addSnapshots();
153
+ assert.throws(()=>explainIntegratedDelivery({...input,deliveries:[...input.deliveries,delivered('active',active.pkg,60)]}),
154
+ error=>error.code==='integration_snapshot_protected');
155
+ });
156
+
157
+ test('real owner accepts exact snapshot evidence once and preserves history and calls across resume drift',{timeout:120000},async t=>{
158
+ // The sole Git/owner fixture is lazy: selecting the pure snapshot tests above
159
+ // does not create it or require Git/Python. Setup has its original 90 s budget.
160
+ let timer;const deadline=new Promise((_,reject)=>{timer=setTimeout(()=>reject(new Error('Snapshot owner fixture exceeded 90000 ms')),90000);});
161
+ let f;try{f=await Promise.race([createReviewedIntegrationFixture(t),deadline]);}finally{clearTimeout(timer);}
162
+ const nextPlan={...f.plan,snapshots:snapshots()};
163
+ const review=await syntheticIntegrationReview(f.root,nextPlan,f.documents,{snapshotEvidence:{provenance,contents:{[sha(body)]:body}}});
164
+ const bytes=fs.readFileSync(f.statePath('parent')),before=f.history('parent'),calls={...f.calls},
165
+ tasks=fs.readFileSync(path.join(f.specsDir,f.definitions.parent.feature,'tasks.md'));
166
+ const input={...f.input,plan:nextPlan,review};
167
+ assert.equal(previewReviewedIntegration(input).eligibleForAdoption,false,'every declared snapshot must exist');
168
+ for(const file of files()){f.write(file.path,body);fs.chmodSync(path.join(f.codeProject,file.path),file.mode);}
169
+ const preview=previewReviewedIntegration({...input,review:null});assert.equal(preview.code,'integration_review_required',JSON.stringify(preview));
170
+ assert.equal(previewReviewedIntegration(input).eligibleForAdoption,true,JSON.stringify(previewReviewedIntegration(input)));
171
+ assert.deepEqual(fs.readFileSync(f.statePath('parent')),bytes);assert.deepEqual(f.calls,calls);
172
+ fs.writeFileSync(f.evidenceFile,canonical({plan:nextPlan,review}));
173
+ assert.deepEqual(readIntegrationEvidence(f.evidenceFile),{plan:nextPlan,review});
174
+ let run=await f.openParent();
175
+ try{
176
+ const args={allowed:true,evidenceFile:f.evidenceFile,expectedDigest:digest(nextPlan)};
177
+ const accepted=run.host.acceptReviewedIntegration(args);assert.equal(accepted.state,'fixture_completed',JSON.stringify(accepted));
178
+ assert.equal(accepted.code,null,JSON.stringify(accepted));
179
+ const after=f.history('parent');assert.equal(after.saved.records.length,before.saved.records.length+1);
180
+ assert.deepEqual(after.saved.records.slice(0,-1),before.saved.records);assert.deepEqual(after.state,before.state);
181
+ assert.deepEqual(after.original,before.original);assert.deepEqual(after.saved.identity,before.saved.identity);
182
+ assert.deepEqual(after.saved.fingerprints,before.saved.fingerprints);
183
+ assert.deepEqual(after.acceptedIntegration.plan.snapshots,nextPlan.snapshots);
184
+ const adopted=fs.readFileSync(f.statePath('parent'));
185
+ assert.equal(run.host.acceptReviewedIntegration(args).code,null);assert.deepEqual(fs.readFileSync(f.statePath('parent')),adopted);
186
+ run.close();run=null;run=await f.openParent();
187
+ assert.equal((await run.host.handle(f.request('parent','status'))).code,null);
188
+ f.write(names[0],body+' ');
189
+ const drift=await run.host.handle(f.request('parent','status'));assert.equal(drift.code,'correction_review_required',JSON.stringify(drift));
190
+ assert.deepEqual(f.history('parent').state,before.state);assert.deepEqual(fs.readFileSync(f.statePath('parent')),adopted);
191
+ f.write(names[0],body);assert.equal((await run.host.handle(f.request('parent','status'))).code,null);
192
+ const proof=fs.readFileSync(f.evidenceFile);fs.writeFileSync(f.evidenceFile,Buffer.concat([proof,Buffer.from(' ')]));
193
+ assert.equal((await run.host.handle(f.request('parent','status'))).code,'correction_review_required');fs.writeFileSync(f.evidenceFile,proof);
194
+ assert.deepEqual(fs.readFileSync(f.statePath('parent')),adopted);assert.deepEqual(f.calls,calls);
195
+ assert.deepEqual(fs.readFileSync(path.join(f.specsDir,f.definitions.parent.feature,'tasks.md')),tasks);
196
+ }finally{run?.close();}
197
+ });
@@ -5,10 +5,13 @@ import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import {spawn,spawnSync} from 'node:child_process';
7
7
  import {fileURLToPath} from 'node:url';
8
- import {createCodexExecution,openControlRun} from './cm-ai-run.mjs';
8
+ import {createCodexExecution,openControlRun,runConfigMaterial} from './cm-ai-run.mjs';
9
9
  import {createConversationExecution,conversationProtection} from './cm-ai-host.mjs';
10
10
  import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
11
11
  import {buildManifest} from './cm-spec-manifest.mjs';
12
+ import {digest} from '../runtime/js/cm-ai/contracts.mjs';
13
+ import {openTaskExecutionStore} from '../runtime/js/cm-ai/task-owner.mjs';
14
+ import {isImplicitQaDecision} from '../runtime/js/cm-ai/implicit-qa-decision.mjs';
12
15
  import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
13
16
 
14
17
  // Keep runtime declarations and log mirrors independent of the invoking user's home.
@@ -107,6 +110,31 @@ for(const runtime of ['codex','claude'])test(`protected ${runtime} conversation
107
110
  assert.match(fs.readFileSync(path.join(definition.specsDir,definition.feature,'tasks.md'),'utf8'),/\[ \]/);
108
111
  }));
109
112
 
113
+ test('a protected v2 run created before the implicit QA decision resumes still protected: completion rework stays closed',
114
+ {skip:!supported},()=>fixture(async({definition,config})=>{
115
+ const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'};
116
+ const review={model:'synthetic',disabledSkills:[],preflight:config.reviewerPreflight};
117
+ const execution=createConversationExecution(definition,'host',{async call(){throw new Error('no dispatch');}},review,null,null,false,'codex',
118
+ {protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},controlPolicy:policy});
119
+ assert.notEqual(conversationProtection(execution),null);assert.equal(isImplicitQaDecision(execution.qaDecisionProvider),true);
120
+ // A store created before the fix: its fingerprint has no QA decision. The
121
+ // frozen, factory-registered execution cannot be copied into that form, so
122
+ // the store is created directly from the earlier material.
123
+ const {qaDecisionProvider,...earlier}=execution;
124
+ const fingerprints={workflow:digest('cm-ai-host-execution-v1'),config:digest(runConfigMaterial(definition,earlier)),
125
+ inputs:digest({feature:definition.feature,task:identity.taskId})};
126
+ openTaskExecutionStore({tasksPath:path.join(definition.specsDir,definition.feature,'tasks.md'),feature:definition.feature.replace(/^\d+\./,''),
127
+ specsRoot:definition.specsDir,identity:{repositoryId:identity.repositoryId,runId:identity.runId},fingerprints,create:true}).close();
128
+ const run=await openControlRun(definition,'resume',execution);
129
+ try{
130
+ assert.equal((await run.host.handle(request('status'))).state,'ready');
131
+ // Still protected after the fallback: the completion rework entry stays closed
132
+ // (a lost protection identity opens it and the runner answers completion_rework_unavailable).
133
+ const rework=await run.host.handle({...request('completion_rework'),reason:'regression probe'});
134
+ assert.equal(rework.code,'completion_rework_authorization_required',JSON.stringify(rework));
135
+ }finally{run.close();}
136
+ }));
137
+
110
138
  test('protected factory binds exact roots and rejects copied/mutable claims before creating a store',
111
139
  {skip:!supported},()=>fixture(async({root,definition,config,authority})=>{
112
140
  const execution=await createCodexExecution(config,authority);
@@ -148,7 +148,11 @@ test('v2 exhausted recovery and launch recovery never advertise legacy exits',()
148
148
  const output=surface==='batch'?batchMemberResult(input,{protocol}):input;
149
149
  assert.equal(output.guidance.recoveryOperation,null);
150
150
  if(protocol==='v2'){assert.doesNotMatch(guidanceText(output),/--supersede-reviewed-evidence|--accept-superseded-code-drift/);
151
- assert.match(guidanceText(output),/保留/);}
151
+ assert.match(guidanceText(output),/保留/);
152
+ // commander phase 0: v2 has a create supersede exit; guidance names it instead of denying it.
153
+ assert.match(guidanceText(output),/inspect-history/);assert.match(guidanceText(output),/supersedeTarget/);
154
+ assert.doesNotMatch(guidanceText(output),/没有作废旧证据/);
155
+ if(surface==='batch')assert.match(guidanceText(output),/取消本批次/);}
152
156
  else assert.match(guidanceText(output),/--supersede-reviewed-evidence/);
153
157
  }
154
158
  }
@@ -173,3 +177,14 @@ test('batch advance guidance uses the batch entry for every native resume family
173
177
  assert.match(guidanceText(output),/原批次入口/);assert.doesNotMatch(guidanceText(output),/恢复原运行/);
174
178
  }
175
179
  });
180
+
181
+
182
+ test('invalid checkpoint package material remains a preservation-only diagnostic without redispatch authority',()=>{
183
+ for(const state of ['blocked','unknown']){
184
+ const input=result(state,'checkpoint_package_material_invalid','resume'),before=JSON.stringify(input);
185
+ const guidance=operatorGuidance(input);
186
+ assert.match(guidance.summary,/引用或原始材料校验失败/);assert.match(guidance.nextStep,/不改写历史或重新派发/);
187
+ assert.equal(guidance.recoveryOperation,null);assert.equal(guidance.authorizationGranted,false);
188
+ assert.equal(JSON.stringify(input),before);
189
+ }
190
+ });
@@ -0,0 +1,278 @@
1
+ // A completed task may finish its approving review after another task has
2
+ // delivered unrelated code. Prove the entire ordered chain from a trusted
3
+ // first-review anchor; matching the current file to an old after-state is not
4
+ // sufficient evidence.
5
+ import test,{after} from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import fs from 'node:fs';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ import {buildManifest} from './cm-spec-manifest.mjs';
11
+ import {openControlRun} from './cm-ai-run.mjs';
12
+ import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
13
+ import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
14
+ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
15
+ import {approvedReviewAt,completedReviewedDeliveries} from '../runtime/js/cm-ai/reviewed-deliveries.mjs';
16
+ import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
17
+ import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
18
+ import {explainCompletedDelivery,firstReviewAt} from '../runtime/js/cm-ai/fix-code-association.mjs';
19
+
20
+ const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prefinal-delivery-'));
21
+ const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
22
+ process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
23
+ after(()=>{
24
+ for(const [key,value] of Object.entries(saved)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
25
+ fs.rmSync(isolated,{recursive:true,force:true});
26
+ });
27
+ const checks=[{id:'synthetic',command:['true'],outcome:'passed',exitCode:0,evidence:'Synthetic fixture'}];
28
+
29
+ function unitRoot(files={'parent.mjs':'0\n','other.mjs':'A\n'}){
30
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'unit-')));
31
+ const edit=changes=>{for(const [name,value] of Object.entries(changes)){
32
+ const file=path.join(root,name);
33
+ if(value===null)fs.rmSync(file);else if(typeof value==='number')fs.chmodSync(file,value);
34
+ else fs.writeFileSync(file,value);
35
+ }};
36
+ edit({...files,'req.md':'Synthetic requirements\n'});
37
+ const write=(runId,scope,changes)=>{
38
+ const baseline=captureReviewBaseline({root,identity:{repositoryId:'fixture',runId,taskId:`T-${runId}`,attempt:1},
39
+ scope,requirements:['req.md']});
40
+ edit(changes);
41
+ return {baseline,pkg:createReviewPackage({root,baseline,checks})};
42
+ };
43
+ return {root,edit,write};
44
+ }
45
+ const delivered=(runId,item,reviewedAt)=>({runId,packages:[{pkg:item.pkg,reviewedAt}]});
46
+ const inspect=(f,parent,deliveries,extra={})=>explainCompletedDelivery({root:f.root,baseline:parent.baseline,
47
+ parentPackage:parent.pkg,since:10,after:30,deliveries,...extra});
48
+
49
+ test('the lower anchor uses the first validated registration for exactly this task identity',()=>{
50
+ const identity={repositoryId:'fixture',runId:'parent',taskId:'T-parent',attempt:2};
51
+ const registration=(registeredAt,extra={})=>({payload:{protocol:'cm-task-runner',version:3,type:'review-invocation-registered',
52
+ registeredAt,binding:{identity:{...identity,attempt:1}},...extra}});
53
+ assert.equal(firstReviewAt([registration(10),registration(30)],identity),10);
54
+ assert.equal(firstReviewAt([],identity),null);
55
+ for(const extra of [{version:2},{registeredAt:10.5},{protocol:'other-protocol'},
56
+ ...['repositoryId','runId','taskId'].map(key=>({binding:{identity:{...identity,[key]:'different'}}})),
57
+ {binding:{identity:{...identity,attempt:0}}}]){
58
+ assert.equal(firstReviewAt([registration(10,extra),registration(30)],identity),null);
59
+ }
60
+ });
61
+
62
+ test('a completed delivery between the first and final parent reviews explains unrelated code',()=>{
63
+ const f=unitRoot(),parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
64
+ const early=f.write('early',['other.mjs'],{'other.mjs':'B\n'});
65
+ assert.doesNotThrow(()=>inspect(f,parent,[delivered('early',early,20)]));
66
+ });
67
+
68
+ test('all early deliveries compose in review order before the parent and every later delivery',()=>{
69
+ const f=unitRoot(),parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
70
+ const one=f.write('one',['other.mjs'],{'other.mjs':'B\n'});
71
+ const two=f.write('two',['other.mjs'],{'other.mjs':'C\n'});
72
+ const later=f.write('later',['other.mjs','parent.mjs'],{'other.mjs':'D\n','parent.mjs':'2\n'});
73
+ const deliveries=[delivered('later',later,40),delivered('two',two,25),delivered('one',one,20)];
74
+ assert.doesNotThrow(()=>inspect(f,parent,deliveries));
75
+ assert.throws(()=>inspect(f,parent,deliveries.filter(item=>item.runId!=='one')));
76
+ assert.throws(()=>inspect(f,parent,deliveries.filter(item=>item.runId!=='two')));
77
+ f.edit({'other.mjs':'C\n'});
78
+ assert.throws(()=>inspect(f,parent,deliveries),'a completed later delivery cannot be omitted to match current content');
79
+ });
80
+
81
+ test('the early window is open at both anchors and requires a valid earlier first-review time',()=>{
82
+ const f=unitRoot(),parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
83
+ const early=f.write('early',['other.mjs'],{'other.mjs':'B\n'});
84
+ for(const reviewedAt of [0,10,30])assert.throws(()=>inspect(f,parent,[delivered('early',early,reviewedAt)]),String(reviewedAt));
85
+ for(const since of [undefined,null,NaN,9.5,30,31])
86
+ assert.throws(()=>inspect(f,parent,[delivered('early',early,20)],{since}),String(since));
87
+ for(const after of [null,NaN,29.5])
88
+ assert.throws(()=>inspect(f,parent,[delivered('early',early,20)],{after}),String(after));
89
+ assert.doesNotThrow(()=>inspect(f,parent,[delivered('early',early,20)]));
90
+ });
91
+
92
+ test('the historical strict proof succeeds without reconsidering irrelevant early packages',()=>{
93
+ const f=unitRoot(),parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
94
+ const bad={...parent.pkg,packageDigest:'0'.repeat(64)};
95
+ assert.doesNotThrow(()=>inspect(f,parent,[{runId:'irrelevant',packages:[{pkg:bad,reviewedAt:20}]}]));
96
+ const later=f.write('later',['other.mjs'],{'other.mjs':'B\n'});
97
+ assert.doesNotThrow(()=>inspect(f,parent,[{runId:'irrelevant',packages:[{pkg:bad,reviewedAt:20}]},delivered('later',later,40)]));
98
+ });
99
+
100
+ test('early changes to parent scope never override the parent final reviewed bytes, including unchanged scope',()=>{
101
+ const f=unitRoot({'parent.mjs':'0\n','unchanged.mjs':'stable\n','other.mjs':'A\n'});
102
+ const parent=f.write('parent',['parent.mjs','unchanged.mjs'],{'parent.mjs':'1\n'});
103
+ // The other task saw the original parent bytes, and its complete early chain
104
+ // is valid. The parent's own final review is authoritative for its full scope.
105
+ f.edit({'parent.mjs':'0\n'});
106
+ const early=f.write('early',['parent.mjs','unchanged.mjs','other.mjs'],
107
+ {'parent.mjs':'2\n','unchanged.mjs':'different\n','other.mjs':'B\n'});
108
+ const deliveries=[delivered('early',early,20)];
109
+ f.edit({'parent.mjs':'1\n','unchanged.mjs':'stable\n'});
110
+ assert.doesNotThrow(()=>inspect(f,parent,deliveries));
111
+ f.edit({'parent.mjs':'2\n'});
112
+ assert.throws(()=>inspect(f,parent,deliveries),'an early after-state cannot hide a rollback of the final parent');
113
+ f.edit({'parent.mjs':'1\n','unchanged.mjs':'different\n'});
114
+ assert.throws(()=>inspect(f,parent,deliveries),'unchanged parent scope is still bound to the final review');
115
+ });
116
+
117
+ test('early A to B to A does not justify a later manual return to B or a discontinuous package',()=>{
118
+ const f=unitRoot({'parent.mjs':'0\n','other.mjs':'A\n','marker.mjs':'0\n'});
119
+ const parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
120
+ const one=f.write('one',['other.mjs','marker.mjs'],{'other.mjs':'B\n','marker.mjs':'1\n'});
121
+ const two=f.write('two',['other.mjs'],{'other.mjs':'A\n'});
122
+ const deliveries=[delivered('one',one,15),delivered('two',two,20)];
123
+ assert.doesNotThrow(()=>inspect(f,parent,deliveries));
124
+ f.edit({'other.mjs':'B\n'});
125
+ assert.throws(()=>inspect(f,parent,deliveries),'must not select only the historical package whose after-state happens to match');
126
+ f.edit({'other.mjs':'unreviewed gap\n'});
127
+ const gap=f.write('gap',['other.mjs'],{'other.mjs':'C\n'});
128
+ assert.throws(()=>inspect(f,parent,[...deliveries,delivered('gap',gap,25)]),'each early before-state is mandatory');
129
+ });
130
+
131
+ test('a digest mismatch or another code root cannot explain the current early drift',()=>{
132
+ const f=unitRoot(),parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
133
+ const early=f.write('early',['other.mjs'],{'other.mjs':'B\n'});
134
+ assert.throws(()=>inspect(f,parent,[delivered('early',{pkg:{...early.pkg,packageDigest:'0'.repeat(64)}},20)]));
135
+ const other=unitRoot(),foreign=other.write('foreign',['other.mjs'],{'other.mjs':'B\n'});
136
+ assert.throws(()=>inspect(f,parent,[delivered('foreign',foreign,20)]));
137
+ });
138
+
139
+ test('early additions, deletions and executable mode changes require the exact resulting inventory',()=>{
140
+ const f=unitRoot({'parent.mjs':'0\n','remove.mjs':'gone\n','mode.mjs':'export const n=1;\n'});
141
+ const parent=f.write('parent',['parent.mjs'],{'parent.mjs':'1\n'});
142
+ const changes={'added.mjs':'new\n','remove.mjs':null,...(process.platform==='win32'?{}:{'mode.mjs':0o755})};
143
+ const early=f.write('early',Object.keys(changes),changes),deliveries=[delivered('early',early,20)];
144
+ assert.doesNotThrow(()=>inspect(f,parent,deliveries));
145
+ f.edit({'remove.mjs':'gone\n'});assert.throws(()=>inspect(f,parent,deliveries));f.edit({'remove.mjs':null});
146
+ f.edit({'added.mjs':'manual\n'});assert.throws(()=>inspect(f,parent,deliveries));f.edit({'added.mjs':'new\n'});
147
+ if(process.platform!=='win32'){
148
+ f.edit({'mode.mjs':0o644});assert.throws(()=>inspect(f,parent,deliveries));f.edit({'mode.mjs':0o755});
149
+ }
150
+ assert.doesNotThrow(()=>inspect(f,parent,deliveries));
151
+ });
152
+
153
+ const events=(onEvent,thread)=>{
154
+ for(const event of [{event:'thread.started',provider_thread:thread},{event:'turn.started',item_type:null},
155
+ {event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},
156
+ {event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
157
+ };
158
+
159
+ async function twoReviewFixture(){
160
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'integration-')));
161
+ const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');fs.mkdirSync(codeProject);
162
+ for(const [feature,task] of [['1.parent','T-001'],['2.other','T-002']]){
163
+ fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
164
+ for(const name of ['requirements','design'])fs.writeFileSync(path.join(specsDir,feature,`${name}.md`),'# Synthetic fixture\n');
165
+ fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),`- [ ] ${task}: implement\n`);
166
+ }
167
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.parent','2.other'],
168
+ specFiles:buildManifest(specsDir)}));
169
+ const edit=(file,bytes)=>fs.writeFileSync(path.join(codeProject,file),bytes);
170
+ edit('parent.mjs','export const n=0;\n');edit('other.mjs','export const n=0;\n');edit('req.md','Synthetic requirement\n');
171
+ edit('.cm-workflow.json',JSON.stringify({version:1,policies:{delivery:'diff'}}));
172
+ const calls={develop:0,review:0,check:0},definitions={},executions={};
173
+ for(const [name,task] of [['parent','T-001'],['other','T-002']]){
174
+ const identity={repositoryId:'fixture',runId:`${name}-run`,taskId:task,attempt:1};
175
+ definitions[name]={version:1,specsDir,codeProject,feature:name==='parent'?'1.parent':'2.other',identity,
176
+ featureSelection:{version:1,feature:name==='parent'?'1.parent':'2.other'},
177
+ scope:[`${name}.mjs`],requirements:['req.md']};
178
+ let develops=0;
179
+ const check=createHostCheck({cwd:codeProject,commands:[{id:'syntax',command:[process.execPath,'--check',`${name}.mjs`]}]});
180
+ executions[name]={configuration:{kind:'synthetic-prefinal-delivery'},timeoutMs:3000,excludedContexts:['fixture-host'],
181
+ developer:{provider:'codex',requestedModel:'synthetic',contextId:`${name}-author`,
182
+ run:createCodexDeveloperRun({requestedModel:'synthetic',worker:async()=>{
183
+ calls.develop++;develops++;edit(`${name}.mjs`,`export const n=${develops};\n`);
184
+ return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
185
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
186
+ }})},
187
+ reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic',allowed:true,available:true,
188
+ contexts:[`${name}-review-1`,`${name}-review-2`],run:async(request,{onEvent})=>{
189
+ calls.review++;events(onEvent,`synthetic-${request.identity.runId}-${request.identity.attempt}`);
190
+ const revise=name==='parent'&&request.identity.attempt===1;
191
+ return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',
192
+ packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:reviewPaths(request.payload.reviewPackage),
193
+ findings:revise?[{id:'F1',severity:'P2',path:'parent.mjs',message:'Use the second value',evidence:'Synthetic first-round finding'}]:[],
194
+ summary:'Synthetic review'}};
195
+ }}],
196
+ reviewInvocation:{developerThreadId:`${name}-author`,excludedThreadIds:['fixture-host']},
197
+ check:async(...args)=>{calls.check++;return check(...args);},applicableAgentFiles:[]};
198
+ }
199
+ const statePath=name=>path.join(specsDir,'.reviews','.execution',definitions[name].identity.runId,'state.json');
200
+ const history=name=>{
201
+ const saved=JSON.parse(fs.readFileSync(statePath(name),'utf8'));
202
+ return {saved,...readRunnerHistory(saved.records,saved.records[0].payload.config,3)};
203
+ };
204
+ const request=(name,operation,attempt=1,extra={})=>({version:1,requestId:`${name}-${operation}-${attempt}`,operation,
205
+ identity:{...definitions[name].identity,attempt},...extra});
206
+ const invoke=async(run,name,operation,attempt=1,extra={})=>{
207
+ assert.ok(run.host,JSON.stringify(run.blocked));
208
+ return run.host.handle(request(name,operation,attempt,extra));
209
+ };
210
+ let parent,other;
211
+ try{
212
+ parent=await openControlRun(definitions.parent,'create',executions.parent);
213
+ const first=await invoke(parent,'parent','start');assert.equal(first.state,'awaiting_review',JSON.stringify(first));
214
+ const rejected=await invoke(parent,'parent','decision',1,{packageDigest:first.packageDigest});
215
+ assert.equal(rejected.state,'changes_requested',JSON.stringify(rejected));
216
+ const second=await invoke(parent,'parent','resume',2);assert.equal(second.state,'awaiting_review',JSON.stringify(second));
217
+ parent.close();parent=null;
218
+
219
+ // The second parent's candidate exists before this independent task begins.
220
+ // Its review registers between the parent's two review registrations.
221
+ other=await openControlRun(definitions.other,'create',executions.other);
222
+ const start=await invoke(other,'other','start');assert.equal(start.state,'awaiting_review',JSON.stringify(start));
223
+ const approved=await invoke(other,'other','decision',1,{packageDigest:start.packageDigest});
224
+ assert.equal(approved.state,'approved',JSON.stringify(approved));other.close();other=null;
225
+ const reviewedOther=fs.readFileSync(path.join(codeProject,'other.mjs'));
226
+ // Fixture-only shelving: the parent's final review still checks its own
227
+ // original code inventory. Then restore the other's exact reviewed bytes
228
+ // and finish that task through the normal owner. No unreviewed edit remains.
229
+ edit('other.mjs','export const n=0;\n');
230
+ parent=await openControlRun(definitions.parent,'resume',executions.parent);
231
+ const finalReview=await invoke(parent,'parent','decision',2,{packageDigest:second.packageDigest});
232
+ assert.equal(finalReview.state,'approved',JSON.stringify(finalReview));
233
+ const completed=await invoke(parent,'parent','complete',2,{packageDigest:second.packageDigest});
234
+ assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));parent.close();parent=null;
235
+ edit('other.mjs',reviewedOther);
236
+ const approvedBytes=fs.readFileSync(statePath('other'));
237
+ // Discovery must not count an approved review before normal task completion.
238
+ assert.deepEqual(completedReviewedDeliveries({specsRoot:specsDir,root:codeProject,identity:definitions.parent.identity}),[]);
239
+ other=await openControlRun(definitions.other,'resume',executions.other);
240
+ const delivered=await invoke(other,'other','complete',1,{packageDigest:start.packageDigest});
241
+ assert.equal(delivered.state,'fixture_completed',JSON.stringify(delivered));other.close();other=null;
242
+ return {root,codeProject,specsDir,calls,definitions,executions,statePath,history,request,approvedBytes};
243
+ }finally{parent?.close();other?.close();}
244
+ }
245
+
246
+ test('real two-review resume proves the early completed delivery without changing history or provider counts',{timeout:30000},async()=>{
247
+ const f=await twoReviewFixture(),parent=f.history('parent');
248
+ const registrations=parent.saved.records.filter(row=>row.payload.type==='review-invocation-registered');
249
+ assert.equal(registrations.length,2);
250
+ const first=registrations[0].payload.registeredAt;
251
+ const final=approvedReviewAt(parent.state);
252
+ const deliveries=completedReviewedDeliveries({specsRoot:f.specsDir,root:f.codeProject,identity:f.definitions.parent.identity});
253
+ assert.equal(deliveries.length,1);
254
+ assert(first<deliveries[0].packages[0].reviewedAt&&deliveries[0].packages[0].reviewedAt<final);
255
+ const before=fs.readFileSync(f.statePath('parent')),counts={...f.calls};
256
+ const status=async()=>{
257
+ const run=await openControlRun(f.definitions.parent,'resume',f.executions.parent);
258
+ try{return await run.host.handle(f.request('parent','status',2));}finally{run.close();}
259
+ };
260
+ const accepted=await status();
261
+ assert.deepEqual([accepted.state,accepted.code,accepted.identity.attempt],['fixture_completed',null,2],JSON.stringify(accepted));
262
+ assert.deepEqual(fs.readFileSync(f.statePath('parent')),before);assert.deepEqual(f.calls,counts);
263
+ // A reviewed but unfinished run cannot justify the same current bytes.
264
+ const completedBytes=fs.readFileSync(f.statePath('other'));
265
+ try{
266
+ fs.writeFileSync(f.statePath('other'),f.approvedBytes);
267
+ const refused=await status();assert.equal(refused.code,'correction_review_required');
268
+ }finally{fs.writeFileSync(f.statePath('other'),completedBytes);}
269
+ // Discovery preserves repository, task and code-root identity boundaries.
270
+ const discover=overrides=>completedReviewedDeliveries({specsRoot:f.specsDir,root:f.codeProject,
271
+ identity:f.definitions.parent.identity,...overrides});
272
+ assert.deepEqual(discover({identity:{...f.definitions.parent.identity,repositoryId:'other-repository'}}),[]);
273
+ assert.deepEqual(discover({identity:{...f.definitions.parent.identity,taskId:'T-002'}}),[]);
274
+ assert.deepEqual(discover({root:path.join(f.root,'other-root')}),[]);
275
+ fs.writeFileSync(path.join(f.codeProject,'other.mjs'),'export const n=99;\n');
276
+ const unreviewed=await status();assert.equal(unreviewed.code,'correction_review_required');
277
+ assert.deepEqual(fs.readFileSync(f.statePath('parent')),before);assert.deepEqual(f.calls,counts);
278
+ });
@@ -400,3 +400,59 @@ test('#17 a skip is fine while tasks remain, but a terminal feature whose latest
400
400
  assert.equal(refused.code,'project_qa_not_passed',JSON.stringify(refused));
401
401
  assert.deepEqual(refused.outstandingQa,[{feature:'1.work',runId:'run-T-001',taskId:'T-001',attempt:1,status:'qa_skipped'}]);
402
402
  });
403
+
404
+ // AI潮 2026-10 batches: an iOS task check already ran the full unit and UI suites on the
405
+ // reviewed package; the QA round ran the identical command again for minutes. reuseCheck
406
+ // lets a QA command take that passed check while the code root still matches the package.
407
+ test('qaCompletionChecks returns the reviewed checks only while the code root matches the package',async()=>{
408
+ const p=project(),identity=p.first.identity;
409
+ const terminal=(request,result)=>({version:1,invocationId:request.invocationId,
410
+ contextId:request.contextId,provider:request.provider,effectiveModel:'fixture',status:'succeeded',accepted:true,result});
411
+ const checks=[{id:'syntax',command:[process.execPath,'--check','a.mjs'],outcome:'passed',exitCode:0,evidence:'fixture'}];
412
+ const runner=createTaskRunner({root:p.codeProject,identity,scope:p.first.scope,requirements:p.first.requirements,
413
+ excludedContexts:['control'],timeoutMs:5000,
414
+ developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:request=>{
415
+ fs.writeFileSync(path.join(p.codeProject,'a.mjs'),'export const a=1;\n');
416
+ return terminal(request,{outcome:'implemented'});}},
417
+ reviewers:[{id:'reviewer',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
418
+ contexts:['review-one','review-two'],run:request=>terminal(request,{verdict:'approved',
419
+ packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:reviewPaths(request.payload.reviewPackage),
420
+ findings:[],summary:'Synthetic review'})}],
421
+ check:()=>checks,commit:()=>({outcome:'fixture_completed'})});
422
+ const effect=kind=>({version:1,id:`${kind}-1`,identity,kind});
423
+ await runner.executeEffect(effect('develop'));
424
+ const reviewed=await runner.executeEffect(effect('review'));
425
+ assert.throws(()=>runner.qaCompletionChecks(reviewed.packageDigest),{code:'stale_qa'});
426
+ const completed=await runner.executeEffect(effect('complete'));
427
+ assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));
428
+ assert.deepEqual(runner.qaCompletionChecks(completed.packageDigest),checks);
429
+ const wrongDigest=(completed.packageDigest[0]==='0'?'1':'0')+completed.packageDigest.slice(1);
430
+ assert.throws(()=>runner.qaCompletionChecks(wrongDigest),{code:'stale_qa'});
431
+ // The code root moved on after completion: the checks no longer speak for it.
432
+ fs.writeFileSync(path.join(p.codeProject,'a.mjs'),'export const a=3;\n');
433
+ assert.throws(()=>runner.qaCompletionChecks(completed.packageDigest));
434
+ assert.equal(runner.status().state,'fixture_completed');
435
+ });
436
+
437
+ test('a QA command with reuseCheck takes the identical passed task check; anything else runs and says why',async()=>{
438
+ for(const [name,command,expected] of [
439
+ ['reused','syntax',null],
440
+ ['other command',null,'command_differs'],
441
+ ['unknown check','missing','check_not_in_package']]){
442
+ const p=project();p.state.browserUp=true;
443
+ const qaCommand={id:'unit',command:[process.execPath,'--check',name==='other command'?'b.mjs':'a.mjs'],caseIds:[],reuseCheck:command??'syntax'};
444
+ const createExecutor=options=>createHostQaExecutor({...options,commands:[qaCommand]});
445
+ const done=await p.advance(p.first,p.execution('1.work',{createExecutor,
446
+ write:()=>fs.writeFileSync(path.join(p.codeProject,'a.mjs'),'export const a=1;\n')}),'create');
447
+ assert.notEqual(done.code,'qa_result_blocked',`${name}: ${JSON.stringify(done)}`);
448
+ const start=fs.readFileSync(path.join(p.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
449
+ .filter(row=>row.event==='test_run'&&row.phase==='start').at(-1);
450
+ const report=fs.readFileSync(path.join(p.specsDir,'.reviews',`${start.operation_id}-execution.md`),'utf8');
451
+ const row=report.split(/^## /m).slice(1).map(part=>JSON.parse(part.slice(part.indexOf('\n')+1))).find(item=>item.id==='unit');
452
+ assert.equal(row.verdict,'PASS',name);
453
+ if(expected===null){
454
+ assert.equal(row.reusedCheck,'syntax');assert.equal(row.reuseUnavailable,undefined);
455
+ assert.match(row.evidence[0],/^reused task check syntax of reviewed package [0-9a-f]{12}: /);
456
+ }else{assert.equal(row.reusedCheck,undefined,name);assert.equal(row.reuseUnavailable,expected,name);}
457
+ }
458
+ });