@aibyzero/cm-workflow 0.17.0 → 0.18.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.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +27 -0
- package/CHANGELOG.md +230 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +21 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +40 -13
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +153 -16
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +94 -21
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +24 -6
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +236 -34
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +14 -6
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +42 -9
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +63 -30
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +247 -41
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +38 -17
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +12 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +27 -14
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +483 -63
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +82 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +37 -5
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host-fixture.mjs +9 -6
- package/scripts/cm-ai-host-protected.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-host.test.mjs +15 -0
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +71 -0
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-review-timeout.test.mjs +20 -0
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +49 -0
- package/scripts/cm-claude-worker.test.mjs +16 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +12 -9
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-host-stage-observer.test.mjs +41 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +625 -75
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +46 -2
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +16 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +55 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +3 -15
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +89 -17
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
10
|
+
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
11
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {scopeRevisionBinding} from '../runtime/js/cm-ai/scope-revision.mjs';
|
|
13
|
+
import {readReviewPackage,verifyReviewPackage,captureReviewBaseline,readReviewBaseline,extendReviewBaseline,captureScopeRevisionSources} from '../runtime/js/cm-ai/review-package.mjs';
|
|
14
|
+
|
|
15
|
+
const DRIVE=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
16
|
+
const REVIEW=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
|
|
17
|
+
function fixture(t,{qa=false,protectedMode=false,selected=false}={}){
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-scope-revision-')));
|
|
19
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
20
|
+
const app=path.join(root,'app'),specs=path.join(root,'specs'),answers=path.join(root,'answers'),bin=path.join(root,'bin');
|
|
21
|
+
for(const directory of [app,answers,bin,path.join(specs,'1.work')])fs.mkdirSync(directory,{recursive:true});
|
|
22
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specs,'1.work',name),'# Synthetic fixture\n');
|
|
23
|
+
fs.writeFileSync(path.join(specs,'1.work/tasks.md'),'- [ ] T-001: synthetic local task\n');
|
|
24
|
+
fs.writeFileSync(path.join(specs,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specs)}));
|
|
25
|
+
fs.writeFileSync(path.join(app,'requirements.md'),'# Synthetic fixture\n');
|
|
26
|
+
const scope=Array.from({length:28},(_,n)=>`part-${String(n).padStart(2,'0')}.mjs`);
|
|
27
|
+
for(const file of scope)fs.writeFileSync(path.join(app,file),'export const value = 0;\n');
|
|
28
|
+
const added='pagination.test.mjs';fs.writeFileSync(path.join(app,added),'export const value = 0;\n');
|
|
29
|
+
const identity={repositoryId:'scope-fixture',runId:'scope-fixture-original',taskId:'T-001',attempt:1};
|
|
30
|
+
const definition={version:1,codeProject:app,specsDir:specs,feature:'1.work',identity,scope,requirements:['requirements.md']};
|
|
31
|
+
if(selected){
|
|
32
|
+
const admission=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url)),
|
|
33
|
+
'--specs-dir',specs,'--code-project',app,'--print-run-definition','--feature','1.work','--task',identity.taskId,
|
|
34
|
+
'--scope',scope.join(','),'--requirements','requirements.md','--run-id',identity.runId,'--repository-id',identity.repositoryId],{encoding:'utf8'});
|
|
35
|
+
assert.equal(admission.status,0,admission.stderr);Object.assign(definition,JSON.parse(admission.stdout));
|
|
36
|
+
assert.deepEqual(definition.taskSelection,{version:1,taskId:identity.taskId});
|
|
37
|
+
assert.deepEqual(definition.featureSelection,{version:1,feature:'1.work'});
|
|
38
|
+
}
|
|
39
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify(definition));
|
|
40
|
+
fs.writeFileSync(path.join(root,'control.json'),JSON.stringify({version:2,development:'conversation',bootstrap:'disabled',qa:qa?'run':'disabled',qaFix:'disabled'}));
|
|
41
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:app,model:'fixture'})}}));
|
|
42
|
+
fs.writeFileSync(path.join(bin,'codex'),fs.readFileSync(REVIEW),{mode:0o700});
|
|
43
|
+
fs.writeFileSync(path.join(answers,'new.txt'),'export const value = 1;\n');
|
|
44
|
+
const value={outcome:'implemented',application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
45
|
+
const deliver=edits=>fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({status:'succeeded',value,edits}));
|
|
46
|
+
deliver(Object.fromEntries(scope.map(file=>[file,'new.txt'])));
|
|
47
|
+
const command=[process.execPath,'-e',"import('./pagination.test.mjs').then(m=>process.exit(m.value===1?0:1))"];
|
|
48
|
+
if(qa)fs.writeFileSync(path.join(root,'workflow.json'),JSON.stringify({qa:{commands:[{id:'local',caseIds:[],command}],
|
|
49
|
+
environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'}},documentationPaths:[],applicableAgentFiles:[]}));
|
|
50
|
+
if(protectedMode)fs.writeFileSync(path.join(root,'protected.json'),JSON.stringify({checkCommands:[{id:'local',command}],timeoutMs:30000}));
|
|
51
|
+
const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
|
|
52
|
+
const drive=(operation='status',extra={})=>{
|
|
53
|
+
const plan=path.join(root,'plan.json');
|
|
54
|
+
let startup=false;
|
|
55
|
+
if(operation==='revise_scope'){
|
|
56
|
+
startup=true;operation='status';
|
|
57
|
+
const {scope,reason,expectedControl,...rest}=extra;
|
|
58
|
+
fs.writeFileSync(path.join(root,'launch.json'),JSON.stringify(expectedControl??null));
|
|
59
|
+
fs.writeFileSync(path.join(root,'scope.json'),JSON.stringify(scope));
|
|
60
|
+
extra={...rest,permissions:['--review-config','review.json',...(qa?['--workflow-config','workflow.json']:[]),
|
|
61
|
+
...(protectedMode?['--protected-conversation-config','protected.json']:[]),
|
|
62
|
+
'--revise-scope','scope.json','--scope-revision-reason',reason,'--expected-control','launch.json']};
|
|
63
|
+
}
|
|
64
|
+
fs.writeFileSync(plan,JSON.stringify({config:'run.json',controlConfig:'control.json',mode:'resume',hostContext:'scope-fixture-host',
|
|
65
|
+
permissions:['--review-config','review.json',...(qa?['--workflow-config','workflow.json']:[]),...(protectedMode?['--protected-conversation-config','protected.json']:[])],
|
|
66
|
+
answers:'answers',checks:[{id:'local',command}],...extra}));
|
|
67
|
+
const result=spawnSync(process.execPath,[DRIVE,'--plan',plan,operation],{encoding:'utf8',timeout:60000,env});
|
|
68
|
+
const value=result.stdout.trim()?JSON.parse(result.stdout).result:null;
|
|
69
|
+
if(startup&&value){assert.equal(result.status,0,result.stderr);assert.equal(rows().at(-1).payload.type,'scope-revised');}
|
|
70
|
+
const failure=result.stderr.match(/\"code\":\"([^\"]+)\"/);
|
|
71
|
+
return {...result,value:startup&&value?{...value,outcome:'recorded'}:value??(failure?{outcome:'rejected',code:failure[1]}:null)};
|
|
72
|
+
};
|
|
73
|
+
const stateFile=path.join(specs,'.reviews','.execution',identity.runId,'state.json');
|
|
74
|
+
const rows=()=>JSON.parse(fs.readFileSync(stateFile)).records;
|
|
75
|
+
return {root,app,specs,answers,identity,scope,added,drive,deliver,stateFile,rows};
|
|
76
|
+
}
|
|
77
|
+
function blocked(t,options){
|
|
78
|
+
const f=fixture(t,options),r=f.drive('start',{mode:'create'});
|
|
79
|
+
assert.equal(r.status,0,r.stderr);assert.equal(r.value.code,'develop_checks_not_passed',JSON.stringify(r.value));
|
|
80
|
+
f.target=f.drive().value.launchControlTarget;return f;
|
|
81
|
+
}
|
|
82
|
+
const revise=(f,extra={})=>f.drive('revise_scope',{scope:[...f.scope,f.added],reason:'Approve the local test scope',expectedControl:f.target,...extra});
|
|
83
|
+
function reseal(rows){
|
|
84
|
+
return rows.map((row,index)=>{
|
|
85
|
+
const {digest:discard,...body}=row;body.previousDigest=index?rows[index-1].digest:null;
|
|
86
|
+
const next={...body,digest:digest(body)};rows[index]=next;return next;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
test('real admission single-task CLI adds a path without rebasing 28 business edits',t=>{
|
|
90
|
+
const f=fixture(t,{selected:true}),config=fs.readFileSync(path.join(f.root,'run.json')),policy=fs.readFileSync(path.join(f.root,'control.json'));
|
|
91
|
+
const started=f.drive('start',{mode:'create'});assert.equal(started.status,0,started.stderr);assert.equal(started.value.code,'develop_checks_not_passed');
|
|
92
|
+
const before=f.rows(),target=f.drive().value.launchControlTarget;
|
|
93
|
+
const revised=f.drive('revise_scope',{scope:[...f.scope,f.added],reason:'Include the existing local regression test',expectedControl:target});
|
|
94
|
+
assert.equal(revised.status,0,revised.stderr);assert.equal(revised.value.outcome,'recorded',JSON.stringify(revised.value));
|
|
95
|
+
assert.deepEqual(revised.value.identity,f.identity);assert.deepEqual(revised.value.effectiveScope,[...f.scope,f.added].sort());
|
|
96
|
+
assert.deepEqual(f.rows().slice(0,before.length),before,'all original failure records remain exact');
|
|
97
|
+
const revision=f.rows().at(-1).payload;
|
|
98
|
+
assert.equal(revision.reason,'Include the existing local regression test');
|
|
99
|
+
assert.equal(new Date(revision.at).toISOString(),revision.at);
|
|
100
|
+
const snapshot=f.rows(),history=readRunnerHistory(snapshot,snapshot[0].payload.config,3);
|
|
101
|
+
const original=before[0].payload.baseline;
|
|
102
|
+
for(const file of f.scope)assert.deepEqual(history.original.files.find(row=>row.path===file),original.files.find(row=>row.path===file));
|
|
103
|
+
f.deliver({[f.added]:'new.txt'});
|
|
104
|
+
const delivered=f.drive('start');assert.equal(delivered.status,0,delivered.stderr);assert.equal(delivered.value.state,'awaiting_review',JSON.stringify(delivered.value));
|
|
105
|
+
const rows=f.rows(),checkpoint=rows.findLast(row=>row.payload.type==='effect-checkpoint').payload.checkpoint;
|
|
106
|
+
assert.equal(checkpoint.reviewPackage.changes.length,29);
|
|
107
|
+
assert.deepEqual(checkpoint.reviewPackage.changes.map(item=>item.path),[...f.scope,f.added].sort());
|
|
108
|
+
assert.ok(checkpoint.reviewPackage.changes.every(item=>Buffer.from(item.before.contentBase64,'base64').toString()==='export const value = 0;\n'));
|
|
109
|
+
const handoff=JSON.parse(fs.readFileSync(path.join(f.specs,'.reviews','work-T-001-a1-handoff.json')));
|
|
110
|
+
assert.deepEqual([...handoff.changed_files].sort(),[...f.scope,f.added].sort());
|
|
111
|
+
const decision=f.drive('decision',{packageDigest:delivered.value.packageDigest});assert.equal(decision.value.state,'approved',JSON.stringify(decision.value));
|
|
112
|
+
const complete=f.drive('complete',{packageDigest:decision.value.packageDigest});assert.equal(complete.value.state,'fixture_completed',JSON.stringify(complete.value));
|
|
113
|
+
assert.match(fs.readFileSync(path.join(f.specs,'1.work/tasks.md'),'utf8'),/\[x\] T-001/);
|
|
114
|
+
assert.ok(fs.readFileSync(path.join(f.root,'run.json')).equals(config));assert.ok(fs.readFileSync(path.join(f.root,'control.json')).equals(policy));
|
|
115
|
+
});
|
|
116
|
+
test('real qa:run policy permits N3 scope recovery; a new file is still a creation diff',t=>{
|
|
117
|
+
const f=blocked(t,{qa:true,selected:true}),newPath='testdata/viewport.json';
|
|
118
|
+
const policy=fs.readFileSync(path.join(f.root,'control.json'));
|
|
119
|
+
assert.equal(revise(f,{scope:[...f.scope,f.added,newPath]}).value.outcome,'recorded');
|
|
120
|
+
const snapshot=f.rows(),history=readRunnerHistory(snapshot,snapshot[0].payload.config,3);
|
|
121
|
+
assert.equal(history.original.files.some(file=>file.path===newPath),false);
|
|
122
|
+
assert.equal(history.scopeRevisions,1);assert.equal(history.state.attempt,1);
|
|
123
|
+
f.deliver({[f.added]:'new.txt',[newPath]:'viewport.txt'});
|
|
124
|
+
fs.writeFileSync(path.join(f.answers,'viewport.txt'),'{"rows":6}\n');
|
|
125
|
+
const next=f.drive('start');assert.equal(next.value.state,'awaiting_review',JSON.stringify(next.value));
|
|
126
|
+
const rows=f.rows(),pkg=readRunnerHistory(rows,rows[0].payload.config,3).state.reviewPackage;
|
|
127
|
+
assert.equal(pkg.changes.length,30);assert.equal(pkg.changes.find(file=>file.path===newPath).before,null);
|
|
128
|
+
assert.equal(Buffer.from(pkg.changes.find(file=>file.path===newPath).after.contentBase64,'base64').toString(),'{"rows":6}\n');
|
|
129
|
+
const decision=f.drive('decision',{packageDigest:next.value.packageDigest});assert.equal(decision.value.state,'approved',JSON.stringify(decision.value));
|
|
130
|
+
const complete=f.drive('complete',{packageDigest:decision.value.packageDigest});assert.equal(complete.value.state,'fixture_completed',JSON.stringify(complete.value));
|
|
131
|
+
assert.ok(fs.readFileSync(path.join(f.root,'control.json')).equals(policy));
|
|
132
|
+
});
|
|
133
|
+
test('newly scoped unchanged files retain complete bytes and modes in review material',t=>{
|
|
134
|
+
const f=fixture(t),unchanged='unchanged.test.mjs',content='export const untouched = true;\n';
|
|
135
|
+
fs.writeFileSync(path.join(f.app,unchanged),content,{mode:0o755});
|
|
136
|
+
const first=f.drive('start',{mode:'create'});assert.equal(first.value.code,'develop_checks_not_passed');
|
|
137
|
+
f.target=f.drive().value.launchControlTarget;
|
|
138
|
+
assert.equal(revise(f,{scope:[...f.scope,f.added,unchanged]}).value.outcome,'recorded');
|
|
139
|
+
f.deliver({[f.added]:'new.txt'});const delivered=f.drive('start');assert.equal(delivered.value.state,'awaiting_review',JSON.stringify(delivered.value)+'\n'+delivered.stderr);
|
|
140
|
+
const rows=f.rows(),history=readRunnerHistory(rows,rows[0].payload.config,3),pkg=history.state.reviewPackage;
|
|
141
|
+
const material=pkg.unchangedScope.find(file=>file.path===unchanged);assert.equal(material.mode,0o755);
|
|
142
|
+
assert.equal(Buffer.from(material.contentBase64,'base64').toString(),content);readReviewPackage(pkg);
|
|
143
|
+
fs.chmodSync(path.join(f.app,unchanged),0o644);
|
|
144
|
+
assert.throws(()=>verifyReviewPackage({root:f.app,baseline:history.original,checks:history.state.currentChecks,reviewPackage:pkg,expectedDigest:pkg.packageDigest,
|
|
145
|
+
handoffPath:path.join(f.specs,'.reviews','work-T-001-a1-handoff.json')}));
|
|
146
|
+
});
|
|
147
|
+
test('scope refusal leaves source records intact for stale, shrinking, protected and changed additions',t=>{
|
|
148
|
+
const f=blocked(t),before=fs.readFileSync(f.stateFile);
|
|
149
|
+
const refused=(extra,code)=>{
|
|
150
|
+
const r=revise(f,extra);assert.equal(r.status,71,r.stderr);assert.equal(r.value.code,code,JSON.stringify(r.value));
|
|
151
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(before),'rejection must not append a record');
|
|
152
|
+
};
|
|
153
|
+
refused({expectedControl:{...f.target,revision:'0'.repeat(64)}},'snapshot_changed');
|
|
154
|
+
refused({expectedControl:{...f.target,identity:{...f.identity,taskId:'T-002'}}},'snapshot_changed');
|
|
155
|
+
refused({scope:[f.added]},'scope_revision_shrink');
|
|
156
|
+
refused({scope:f.scope},'scope_revision_no_additions');
|
|
157
|
+
refused({scope:[...f.scope,f.added,f.scope[0]]},'invalid_input');
|
|
158
|
+
refused({scope:[...f.scope,'../escape.mjs']},'invalid_input');
|
|
159
|
+
refused({scope:[...f.scope,'AGENTS.md']},'protected_scope');
|
|
160
|
+
refused({scope:[...f.scope,'.env']},'unsupported_path');
|
|
161
|
+
refused({scope:[...f.scope,'.build/new.mjs']},'excluded_snapshot_path');
|
|
162
|
+
fs.writeFileSync(path.join(f.app,f.added),'changed without scope\n');
|
|
163
|
+
refused({},'scope_revision_source_changed');fs.writeFileSync(path.join(f.app,f.added),'export const value = 0;\n');
|
|
164
|
+
fs.chmodSync(path.join(f.app,f.added),0o755);refused({},'scope_revision_source_changed');fs.chmodSync(path.join(f.app,f.added),0o644);
|
|
165
|
+
fs.unlinkSync(path.join(f.app,f.added));fs.symlinkSync(f.scope[0],path.join(f.app,f.added));refused({},'unsupported_file');
|
|
166
|
+
fs.unlinkSync(path.join(f.app,f.added));fs.writeFileSync(path.join(f.app,f.added),'export const value = 0;\n');
|
|
167
|
+
fs.mkdirSync(path.join(f.app,'alias'));fs.symlinkSync('../'+f.added,path.join(f.app,'alias','test.mjs'));
|
|
168
|
+
refused({scope:[...f.scope,'alias/test.mjs']},'scope_revision_source_changed');
|
|
169
|
+
fs.symlinkSync('.',path.join(f.app,'linked'));refused({scope:[...f.scope,'linked/new.mjs']},'unsupported_path');
|
|
170
|
+
const missing=f.drive('revise_scope',{scope:[...f.scope,f.added],reason:'Scope',expectedControl:undefined});assert.equal(missing.status,71);assert.match(missing.stderr,/invalid_input/);
|
|
171
|
+
const legacy=f.drive('revise_scope',{controlConfig:undefined,scope:[...f.scope,f.added],reason:'Scope',expectedControl:f.target});assert.equal(legacy.status,71);assert.match(legacy.stderr,/invalid_input/);
|
|
172
|
+
assert.equal(revise(f).value.outcome,'recorded');
|
|
173
|
+
assert.equal(revise(f).value.code,'snapshot_changed');
|
|
174
|
+
f.target=f.drive().value.launchControlTarget;assert.equal(revise(f,{scope:[...f.scope,f.added,'another.mjs']}).value.code,'scope_revision_unavailable');
|
|
175
|
+
});
|
|
176
|
+
test('replay validates the revision source and handles prefixes before and after append without filesystem reads',t=>{
|
|
177
|
+
const f=blocked(t);assert.equal(revise(f).value.outcome,'recorded');
|
|
178
|
+
const rows=f.rows(),config=rows[0].payload.config,last=rows.at(-1);
|
|
179
|
+
assert.equal(last.payload.type,'scope-revised');
|
|
180
|
+
const before=readRunnerHistory(rows.slice(0,-1),config,3),after=readRunnerHistory(rows,config,3);
|
|
181
|
+
assert.equal(before.scopeRevisions,0);assert.equal(after.scopeRevisions,1);assert.deepEqual(after.state,before.state);
|
|
182
|
+
fs.writeFileSync(path.join(f.app,f.added),'later approved edit\n');
|
|
183
|
+
assert.deepEqual(readRunnerHistory(rows,config,3).original,after.original,'replay uses recorded original bytes');
|
|
184
|
+
for(const mutate of [p=>p.previousScopeDigest='0'.repeat(64),p=>p.failedCheckpointDigest='0'.repeat(64),p=>p.baselineDigest='0'.repeat(64),
|
|
185
|
+
p=>p.fromDigest='0'.repeat(64),p=>p.scope=[f.added],p=>p.reason='',p=>p.files[0].mode=0o755,p=>p.files[0].contentBase64=Buffer.from('false').toString('base64')]){
|
|
186
|
+
const bad=structuredClone(rows);mutate(bad.at(-1).payload);assert.throws(()=>readRunnerHistory(reseal(bad),config,3));
|
|
187
|
+
}
|
|
188
|
+
const repeated=structuredClone(rows);repeated.push({...last,id:`runner.${String(rows.length+1).padStart(6,'0')}`,seq:rows.length+1,
|
|
189
|
+
payload:{...last.payload,fromDigest:last.digest}});assert.throws(()=>readRunnerHistory(reseal(repeated),config,3),{code:'scope_revision_unavailable'});
|
|
190
|
+
for(const change of [{state:'ready',code:null},{state:'approved',code:null},{attempt:2},{reviewPackage:{}},{receipt:{}},{receipts:[{}]},
|
|
191
|
+
{reviewInvocation:{}},{priorReview:{verdict:'approved'}},{taskCommit:{}},{cancellationRequested:true},{workflowError:'workflow_error'}])
|
|
192
|
+
assert.throws(()=>scopeRevisionBinding({...before.state,...change},config),{code:'scope_revision_unavailable'});
|
|
193
|
+
for(const policy of [{...config.controlPolicy,development:'provider'},{...config.controlPolicy,bootstrap:'write'},
|
|
194
|
+
{...config.controlPolicy,qa:'run',qaFix:'manual'}])assert.throws(()=>scopeRevisionBinding(before.state,{...config,controlPolicy:policy}),{code:'scope_revision_unavailable'});
|
|
195
|
+
});
|
|
196
|
+
test('a protected conversation cannot expand its scope through the v2 recovery route',t=>{
|
|
197
|
+
const f=fixture(t,{protectedMode:true,selected:true});
|
|
198
|
+
const status=f.drive('status',{mode:'create'});assert.equal(status.status,0,status.stderr);
|
|
199
|
+
f.target=status.value.launchControlTarget;const before=fs.readFileSync(f.stateFile);
|
|
200
|
+
const r=revise(f);assert.equal(r.status,71,r.stderr);assert.equal(r.value.code,'recovery_launch_unavailable');
|
|
201
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(before));
|
|
202
|
+
const completion=f.drive('completion_rework',{reason:'Synthetic completion request',expectedControl:status.value.controlTarget});
|
|
203
|
+
assert.equal(completion.status,0,completion.stderr);
|
|
204
|
+
assert.equal(completion.value.code,'completion_rework_authorization_required');
|
|
205
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(before));
|
|
206
|
+
});
|
|
207
|
+
test('a trusted parallel batch cannot revise scope after a failed develop checkpoint',async t=>{
|
|
208
|
+
const f=fixture(t),definition=JSON.parse(fs.readFileSync(path.join(f.root,'run.json')));
|
|
209
|
+
fs.writeFileSync(path.join(f.specs,'1.work/tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n');
|
|
210
|
+
fs.writeFileSync(path.join(f.specs,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specs)}));
|
|
211
|
+
const {openControlRun,controlLaunchTarget}=await import('./cm-ai-run.mjs');
|
|
212
|
+
const {createCodexDeveloperRun}=await import('../runtime/js/cm-ai/codex-developer-adapter.mjs');
|
|
213
|
+
const parallelSelection={version:1,group:['T-001','T-002']};
|
|
214
|
+
const execution={configuration:{kind:'scope-batch-fixture',controlPolicy:JSON.parse(fs.readFileSync(path.join(f.root,'control.json')))},
|
|
215
|
+
timeoutMs:2000,excludedContexts:['host'],
|
|
216
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{
|
|
217
|
+
fs.writeFileSync(path.join(f.app,f.scope[0]),'export const value = 1;\n');
|
|
218
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
219
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
220
|
+
check:async()=>[{id:'local',command:['fixture'],outcome:'failed',exitCode:1,evidence:'synthetic failed check'}],
|
|
221
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,
|
|
222
|
+
available:true,contexts:['review-1','review-2'],run:async()=>{throw new Error('review must not run');}}],
|
|
223
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']}};
|
|
224
|
+
let run=await openControlRun(definition,'create',execution,{parallelSelection});
|
|
225
|
+
try{
|
|
226
|
+
const result=await run.controlHost.handle({version:2,operation:'start',requestId:'batch-start',identity:f.identity});
|
|
227
|
+
assert.equal(result.code,'develop_checks_not_passed',JSON.stringify(result));
|
|
228
|
+
}finally{run.close();}
|
|
229
|
+
run=await openControlRun(definition,'resume',execution,{parallelSelection});
|
|
230
|
+
try{
|
|
231
|
+
const status=await run.controlHost.handle({version:2,operation:'status',requestId:'batch-status',identity:f.identity});
|
|
232
|
+
const before=fs.readFileSync(f.stateFile);
|
|
233
|
+
const result=await run.controlHost.handle({version:2,operation:'revise_scope',requestId:'batch-revise',identity:f.identity,
|
|
234
|
+
expectedControl:status.controlTarget,scope:[...f.scope,f.added],reason:'Synthetic requested scope addition'});
|
|
235
|
+
assert.equal(result.code,'scope_revision_authorization_required',JSON.stringify(result));
|
|
236
|
+
const completion=await run.controlHost.handle({version:2,operation:'completion_rework',requestId:'batch-completion',identity:f.identity,
|
|
237
|
+
expectedControl:status.controlTarget,reason:'Synthetic batch completion request'});
|
|
238
|
+
assert.equal(completion.code,'completion_rework_authorization_required',JSON.stringify(completion));
|
|
239
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(before));
|
|
240
|
+
}finally{run.close();}
|
|
241
|
+
const before=fs.readFileSync(f.stateFile);
|
|
242
|
+
for(const recovery of [{scopeRevision:{scope:[...f.scope,f.added],reason:'Explicit batch scope request'}},
|
|
243
|
+
{developmentReworkReason:'Explicit batch development request'}]){
|
|
244
|
+
await assert.rejects(openControlRun(definition,'resume',execution,{parallelSelection,...recovery,
|
|
245
|
+
expectedControl:controlLaunchTarget(JSON.parse(before))}),{code:'recovery_launch_unavailable'});
|
|
246
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(before));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
test('ready, reviewed and completed runs refuse revisions without replacing evidence',t=>{
|
|
250
|
+
const f=fixture(t);assert.equal(f.drive('status',{mode:'create'}).value.state,'ready');
|
|
251
|
+
f.target=f.drive().value.launchControlTarget;const readyBytes=fs.readFileSync(f.stateFile);
|
|
252
|
+
assert.equal(revise(f).value.code,'scope_revision_unavailable');assert.ok(fs.readFileSync(f.stateFile).equals(readyBytes));
|
|
253
|
+
const g=fixture(t);fs.writeFileSync(path.join(g.app,g.added),'export const value = 1;\n');
|
|
254
|
+
const start=g.drive('start',{mode:'create'});assert.equal(start.value.state,'awaiting_review');
|
|
255
|
+
const deny=()=>{
|
|
256
|
+
g.target=g.drive().value.launchControlTarget;const bytes=fs.readFileSync(g.stateFile);
|
|
257
|
+
assert.equal(revise(g).value.code,'scope_revision_unavailable');assert.ok(fs.readFileSync(g.stateFile).equals(bytes));
|
|
258
|
+
};
|
|
259
|
+
deny();const review=g.drive('decision',{packageDigest:start.value.packageDigest});assert.equal(review.value.state,'approved');
|
|
260
|
+
deny();assert.equal(g.drive('complete',{packageDigest:review.value.packageDigest}).value.state,'fixture_completed');deny();
|
|
261
|
+
});
|
|
262
|
+
test('pending developer crash prefixes cannot accept an appended scope revision',t=>{
|
|
263
|
+
const f=blocked(t);assert.equal(revise(f).value.outcome,'recorded');
|
|
264
|
+
const rows=f.rows(),config=rows[0].payload.config;
|
|
265
|
+
const checkpoint=rows.findLastIndex(row=>row.payload.type==='effect-checkpoint');
|
|
266
|
+
const prefix=structuredClone(rows.slice(0,checkpoint));
|
|
267
|
+
assert.notEqual(readRunnerHistory(prefix,config,3).pending,null);
|
|
268
|
+
const revision=structuredClone(rows.at(-1));revision.id=`runner.${String(prefix.length+1).padStart(6,'0')}`;
|
|
269
|
+
revision.seq=prefix.length+1;revision.payload.fromDigest=prefix.at(-1).digest;prefix.push(revision);
|
|
270
|
+
assert.throws(()=>readRunnerHistory(reseal(prefix),config,3),{code:'scope_revision_unavailable'});
|
|
271
|
+
});
|
|
272
|
+
test('v1 baseline reading stays compatible but cannot authorize a scope extension',t=>{
|
|
273
|
+
const f=fixture(t),baseline=captureReviewBaseline({root:f.app,identity:f.identity,scope:f.scope,requirements:['requirements.md'],version:1});
|
|
274
|
+
assert.equal(readReviewBaseline(baseline).version,1);
|
|
275
|
+
assert.throws(()=>extendReviewBaseline(baseline,[...f.scope,f.added],[]),{code:'scope_revision_unsupported_baseline'});
|
|
276
|
+
assert.throws(()=>captureScopeRevisionSources(f.app,baseline,[...f.scope,'new.mjs']),{code:'scope_revision_unsupported_baseline'});
|
|
277
|
+
const legacyIgnore=captureReviewBaseline({root:f.app,identity:f.identity,scope:f.scope,requirements:['requirements.md']},false,1);
|
|
278
|
+
assert.equal(readReviewBaseline(legacyIgnore).ignorePolicy.version,1,'ordinary legacy reading remains compatible');
|
|
279
|
+
assert.throws(()=>extendReviewBaseline(legacyIgnore,[...f.scope,'new.mjs'],[]),{code:'scope_revision_unsupported_baseline'},
|
|
280
|
+
'legacy ignore evidence has no frozen omitted-path inventory');
|
|
281
|
+
});
|
|
282
|
+
test('replay refuses additions excluded by the creation baseline',t=>{
|
|
283
|
+
const f=fixture(t);
|
|
284
|
+
const git=spawnSync('git',['-C',f.app,'init','-b','main'],{encoding:'utf8'});assert.equal(git.status,0,git.stderr);
|
|
285
|
+
fs.writeFileSync(path.join(f.app,'.gitignore'),'ignored/\nignored-file.mjs\n');
|
|
286
|
+
fs.mkdirSync(path.join(f.app,'ignored'));fs.writeFileSync(path.join(f.app,'ignored','existing.mjs'),'ignored source\n');
|
|
287
|
+
fs.writeFileSync(path.join(f.app,'ignored-file.mjs'),'ignored source\n');
|
|
288
|
+
fs.mkdirSync(path.join(f.app,'Pods','Pods.xcodeproj'),{recursive:true});
|
|
289
|
+
fs.writeFileSync(path.join(f.app,'Pods','Manifest.lock'),'synthetic lock\n');fs.writeFileSync(path.join(f.app,'Podfile.lock'),'synthetic lock\n');
|
|
290
|
+
const start=f.drive('start',{mode:'create'});assert.equal(start.value.code,'develop_checks_not_passed',JSON.stringify(start.value));
|
|
291
|
+
f.target=f.drive().value.launchControlTarget;
|
|
292
|
+
const excluded=['node_modules/new.mjs','.venv/new.py','__pycache__/new.py','.build/new.mjs','.swiftpm/new.mjs',
|
|
293
|
+
'.DS_Store','ignored/new.mjs','ignored-file.mjs','Pods/new.mjs'];
|
|
294
|
+
const originalBytes=fs.readFileSync(f.stateFile);
|
|
295
|
+
for(const name of excluded){
|
|
296
|
+
const result=revise(f,{scope:[...f.scope,f.added,name]});assert.equal(result.value.code,'excluded_snapshot_path',name);
|
|
297
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(originalBytes));
|
|
298
|
+
}
|
|
299
|
+
assert.equal(revise(f).value.outcome,'recorded');
|
|
300
|
+
const rows=f.rows(),config=rows[0].payload.config,baseline=rows[0].payload.baseline;
|
|
301
|
+
assert.ok(baseline.ignorePolicy.ignoredPaths.includes('ignored-file.mjs'));
|
|
302
|
+
assert.ok(baseline.ignorePolicy.ignoredDirectories.includes('ignored'));
|
|
303
|
+
for(const name of excluded){
|
|
304
|
+
const altered=structuredClone(rows);altered.at(-1).payload.scope.push(name);altered.at(-1).payload.scope.sort();
|
|
305
|
+
assert.throws(()=>readRunnerHistory(reseal(altered),config,3),{code:'excluded_snapshot_path'},name);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
test('scope revisions reject ignored case aliases and preserve directory boundaries',t=>{
|
|
309
|
+
const f=fixture(t);
|
|
310
|
+
const git=spawnSync('git',['-C',f.app,'init','-b','main'],{encoding:'utf8'});assert.equal(git.status,0,git.stderr);
|
|
311
|
+
fs.writeFileSync(path.join(f.app,'.gitignore'),'ignored/\nignored-file.mjs\n');
|
|
312
|
+
fs.mkdirSync(path.join(f.app,'ignored'));fs.writeFileSync(path.join(f.app,'ignored','existing.mjs'),'ignored source\n');
|
|
313
|
+
fs.writeFileSync(path.join(f.app,'ignored-file.mjs'),'ignored source\n');
|
|
314
|
+
assert.equal(f.drive('start',{mode:'create'}).value.code,'develop_checks_not_passed');
|
|
315
|
+
f.target=f.drive().value.launchControlTarget;
|
|
316
|
+
const excluded=['IGNORED/new.mjs','IgNoReD/nested/new.mjs','IGNORED-FILE.MJS','IgNoReD-FiLe.mjs',
|
|
317
|
+
'ignored','IGNORED','IgNoReD','ignored/new.mjs'];
|
|
318
|
+
const originalBytes=fs.readFileSync(f.stateFile);
|
|
319
|
+
for(const name of excluded){
|
|
320
|
+
const result=revise(f,{scope:[...f.scope,f.added,name]});assert.equal(result.value.code,'excluded_snapshot_path',name);
|
|
321
|
+
assert.ok(fs.readFileSync(f.stateFile).equals(originalBytes));
|
|
322
|
+
}
|
|
323
|
+
const adjacent=['ignored-other/new.mjs','IGNOREDNESS/new.mjs','ignored-file.mjs-extra'];
|
|
324
|
+
assert.equal(revise(f,{scope:[...f.scope,f.added,...adjacent]}).value.outcome,'recorded');
|
|
325
|
+
const rows=f.rows(),config=rows[0].payload.config;
|
|
326
|
+
assert.deepEqual(readRunnerHistory(rows,config,3).effectiveScope,[...f.scope,f.added,...adjacent].sort());
|
|
327
|
+
for(const name of excluded){
|
|
328
|
+
const altered=structuredClone(rows);altered.at(-1).payload.scope.push(name);altered.at(-1).payload.scope.sort();
|
|
329
|
+
assert.throws(()=>readRunnerHistory(reseal(altered),config,3),{code:'excluded_snapshot_path'},name);
|
|
330
|
+
}
|
|
331
|
+
// A frozen directory exclusion stands on its own, even without an exact-path row.
|
|
332
|
+
const {baselineDigest:discard,...directoryOnly}=structuredClone(rows[0].payload.baseline);
|
|
333
|
+
directoryOnly.ignorePolicy.ignoredPaths=[];
|
|
334
|
+
const baseline={...directoryOnly,baselineDigest:digest(directoryOnly)};
|
|
335
|
+
for(const name of ['ignored','IGNORED','ignored/new.mjs','IGNORED/new.mjs']){
|
|
336
|
+
assert.throws(()=>extendReviewBaseline(baseline,[...f.scope,name],[]),{code:'excluded_snapshot_path'},name);
|
|
337
|
+
assert.throws(()=>captureScopeRevisionSources(f.app,baseline,[...f.scope,name]),{code:'excluded_snapshot_path'},name);
|
|
338
|
+
}
|
|
339
|
+
assert.deepEqual(captureScopeRevisionSources(f.app,baseline,[...f.scope,...adjacent]),[]);
|
|
340
|
+
assert.deepEqual(extendReviewBaseline(baseline,[...f.scope,...adjacent],[]).scope,[...baseline.scope,...adjacent].sort());
|
|
341
|
+
});
|
|
@@ -12,6 +12,7 @@ import {buildManifest} from './cm-spec-manifest.mjs';
|
|
|
12
12
|
import {openControlRun} from './cm-ai-run.mjs';
|
|
13
13
|
import {approveCmAiSpecs,inspectCmAiAdmission} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
14
14
|
import {writeSpecsStatus,readSpecsStatus} from '../runtime/js/specs-status.mjs';
|
|
15
|
+
import {approvedTaskGrammar} from '../runtime/js/spec-task-line.mjs';
|
|
15
16
|
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
16
17
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
17
18
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
@@ -447,6 +448,18 @@ test('a first approval with no earlier status binds the shared grammar directly'
|
|
|
447
448
|
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-001');
|
|
448
449
|
});
|
|
449
450
|
|
|
451
|
+
test('an approval binds the grammar its publication carried: 2 stays 2, 3 stays 3',t=>{
|
|
452
|
+
const f=fixture(t);
|
|
453
|
+
for(const grammar of [2,3,2]){
|
|
454
|
+
const prior=readSpecsStatus(f.specsDir).value;
|
|
455
|
+
writeSpecsStatus(f.specsDir,{status:'awaiting_review',summaryDigest:'a'.repeat(64),at:new Date().toISOString(),
|
|
456
|
+
features:prior.features,specFiles:buildManifest(f.specsDir),testCases:[],approval:null,taskGrammar:grammar});
|
|
457
|
+
assert.equal(approveCmAiSpecs({specsDir:f.specsDir,codeProject:f.codeProject,approvalResponse:'开始'}).approveRefused,undefined);
|
|
458
|
+
assert.equal(readSpecsStatus(f.specsDir).value.taskGrammar,grammar);
|
|
459
|
+
assert.equal(approvedTaskGrammar(f.specsDir),grammar);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
|
|
450
463
|
test('a parallel batch member is offered only the spec revert exit',async()=>{
|
|
451
464
|
const {batchMemberResult}=await import('./cm-ai-batch-run.mjs');
|
|
452
465
|
const drift={state:'blocked',code:'spec_drift',pendingAction:'spec_rebind',reason:'变更文件:1.work/tasks.md;需要换绑'};
|
|
@@ -402,6 +402,34 @@ test('provider develop without a usable result is redone after its worker group
|
|
|
402
402
|
if(process.env.DEBUG_KEEP)fs.writeFileSync(process.env.DEBUG_KEEP,f.root);else fs.rmSync(f.root,{recursive:true,force:true});}
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
+
// 2026-10-26: a provider develop that hit the API rate limit stops at the same
|
|
406
|
+
// develop_redo exit (it needs --allow-develop-redo and the worker-gone proof, so it
|
|
407
|
+
// is never retried automatically); the result names the class as developFailure.
|
|
408
|
+
test('provider develop ended by a rate limit names developer_rate_limited and still needs develop_redo',async()=>{
|
|
409
|
+
const f=runFixture();const children=[];
|
|
410
|
+
try{
|
|
411
|
+
const runId='provider-rate-limited',identity=identityFor(runId);
|
|
412
|
+
const execution=()=>{const value=executionFor(f,'written\n');
|
|
413
|
+
value.developer.run=createCodexDeveloperRun({requestedModel:'fixture',worker:async({prompt},control)=>{
|
|
414
|
+
control.onWorker({phase:'spawning'});
|
|
415
|
+
const child=spawnChild(process.execPath,['-e','setInterval(()=>{},1000)'],{detached:true,stdio:'ignore'});
|
|
416
|
+
child.unref();children.push(child);control.onWorker({phase:'started',pid:child.pid});
|
|
417
|
+
return {status:'unknown',code:'developer_rate_limited'};}});
|
|
418
|
+
return value;};
|
|
419
|
+
const definition={version:1,specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,
|
|
420
|
+
identity,scope:['a.mjs'],requirements:['requirements.md']};
|
|
421
|
+
const run=await openControlRun(definition,'create',execution());
|
|
422
|
+
try{
|
|
423
|
+
const first=await run.host.handle(requestFor(identity));
|
|
424
|
+
assert.equal(first.pendingAction,'develop_redo',JSON.stringify(first));assert.equal(first.developRedoRequired,true);
|
|
425
|
+
assert.equal(first.failureCode,'developer_rate_limited');assert.equal(first.developFailure,'developer_rate_limited');
|
|
426
|
+
// No other run retried it: the develop effect count is one.
|
|
427
|
+
const records=JSON.parse(fs.readFileSync(path.join(f.reviewsDir,'.execution',runId,'state.json'),'utf8')).records;
|
|
428
|
+
assert.equal(records.filter(row=>row.payload.type==='effect-intent'&&row.payload.effect.kind==='develop').length,1);
|
|
429
|
+
}finally{run.close();}
|
|
430
|
+
}finally{for(const child of children)try{process.kill(-child.pid,'SIGKILL');}catch{}fs.rmSync(f.root,{recursive:true,force:true});}
|
|
431
|
+
});
|
|
432
|
+
|
|
405
433
|
// R2: an interrupted step of the same kind is retired at most twice per run;
|
|
406
434
|
// the third host death shows effect_interrupt_limit and abandon_effect voids.
|
|
407
435
|
test('develop interruptions are capped at two per run, then abandon_effect voids the run',async()=>{
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import test,{after} from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
7
|
+
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
|
|
10
|
+
// Keep runtime declarations and log mirrors independent of the invoking user's home.
|
|
11
|
+
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-verification-auto-home-'));
|
|
12
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
13
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
14
|
+
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
15
|
+
|
|
16
|
+
// Protected writes and checks run in the native sandbox, as in cm-ai-nested-execution.
|
|
17
|
+
const supported=process.platform==='darwin'&&Number(process.versions.node.split('.')[0])>=24;
|
|
18
|
+
const identity={repositoryId:'fixture',runId:'auto-run',taskId:'T-001',attempt:1};
|
|
19
|
+
const request=operation=>({version:1,operation,requestId:operation,identity});
|
|
20
|
+
const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'disabled',qaFix:'disabled',verification:'auto'};
|
|
21
|
+
const TEST="require('node:assert/strict').equal(require('node:fs').readFileSync('a.js','utf8'),'new\\n');\n";
|
|
22
|
+
|
|
23
|
+
async function fixture(fn){
|
|
24
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-verification-auto-')));
|
|
25
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(codeProject,'specs'),feature='1.demo';
|
|
26
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
27
|
+
fs.writeFileSync(path.join(codeProject,'a.js'),'old\n');
|
|
28
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'Synthetic requirement\n');
|
|
29
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'codex'}}));
|
|
30
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# Requirements\n');
|
|
31
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Design\n');
|
|
32
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: 实现 a.js\n - 范围: `a.js`, `a.test.js`\n - 测试文件: `a.test.js`\n\n'
|
|
33
|
+
+'## 验证要求\n\n- T-001: RED 必须先失败;全部放入后检查通过。\n');
|
|
34
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
35
|
+
const definition={version:1,codeProject,specsDir,feature,identity,scope:['a.js','a.test.js'],requirements:['requirements.md'],
|
|
36
|
+
specification:{specsRoot:specsDir,feature}};
|
|
37
|
+
const protection={checkCommands:[{id:'unit',command:[process.execPath,'a.test.js']}],timeoutMs:5000};
|
|
38
|
+
try{await fn({definition,protection});}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
39
|
+
}
|
|
40
|
+
const develop=(requirements,test=TEST)=>({async call(kind,payload){
|
|
41
|
+
assert.equal(kind,'develop');
|
|
42
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
43
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null},...(requirements===undefined?{}:{requirements})},
|
|
44
|
+
edits:[{path:'a.js',beforeSha256:payload.expected['a.js'],content:'new\n'},{path:'a.test.js',beforeSha256:null,content:test}]};
|
|
45
|
+
}});
|
|
46
|
+
const run=async(definition,bridge,protection)=>{
|
|
47
|
+
const execution=createConversationExecution(definition,'host',bridge,null,null,null,false,'codex',{protection,controlPolicy:policy});
|
|
48
|
+
const control=await openControlRun(definition,'create',execution);
|
|
49
|
+
try{return await control.host.handle(request('start'));}finally{control.close();}
|
|
50
|
+
};
|
|
51
|
+
const handoff=definition=>JSON.parse(fs.readFileSync(path.join(definition.specsDir,'.reviews',`${definition.feature.replace(/^\d+\./,'')}-T-001-a1-handoff.json`),'utf8'));
|
|
52
|
+
|
|
53
|
+
test('auto gate: a failing-first claim the host replay confirms passes, and the handoff carries the host record',
|
|
54
|
+
{skip:!supported},()=>fixture(async({definition,protection})=>{
|
|
55
|
+
const result=await run(definition,develop([{requirement:'T-001: RED 必须先失败',satisfied:true,evidence:'a.test.js 在旧 a.js 下失败',run:'red'},
|
|
56
|
+
{requirement:'全部放入后检查通过',satisfied:true,evidence:'unit 检查'}]),protection);
|
|
57
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));
|
|
58
|
+
const entries=handoff(definition).evidence;
|
|
59
|
+
assert.match(entries.find(entry=>entry.startsWith('cm-requirement-evidence-v1: ')),/RED 必须先失败/);
|
|
60
|
+
// The host record is its own entry, not one of the developer's items.
|
|
61
|
+
const record=JSON.parse(entries.find(entry=>entry.startsWith('cm-host-replay-v1: ')).slice('cm-host-replay-v1: '.length));
|
|
62
|
+
assert.deepEqual([record.facts.status,record.facts.baseline.outcome,record.facts.red.outcome,record.facts.green.outcome],
|
|
63
|
+
['replayed','failed','failed','passed']);
|
|
64
|
+
assert.deepEqual(record.identity,{...identity,attempt:1});
|
|
65
|
+
assert.equal(fs.readFileSync(path.join(definition.codeProject,'a.js'),'utf8'),'new\n','the replay never writes the real project');
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
test('auto gate: no report from the developer stops before review, with nothing to hand off',
|
|
69
|
+
{skip:!supported},()=>fixture(async({definition,protection})=>{
|
|
70
|
+
const result=await run(definition,develop(undefined),protection);
|
|
71
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'verification_precheck_failed');
|
|
72
|
+
assert.equal(fs.existsSync(path.join(definition.specsDir,'.reviews',`${definition.feature.replace(/^\d+\./,'')}-T-001-a1-handoff.json`)),false);
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
test('auto gate: a failing-first claim the host replay contradicts stops before review',
|
|
76
|
+
{skip:!supported},()=>fixture(async({definition,protection})=>{
|
|
77
|
+
// This test passes with the old a.js too, so the test-files-only run passes.
|
|
78
|
+
const result=await run(definition,develop([{requirement:'T-001: RED 必须先失败',satisfied:true,evidence:'a.test.js',run:'red'}],
|
|
79
|
+
"process.exit(0);\n"),protection);
|
|
80
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'verification_precheck_failed');
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
// Acceptance regression: a gate that stops leaves the delivery in the project. A
|
|
84
|
+
// resumed process must still replay the state the task baseline recorded at
|
|
85
|
+
// creation, not the already-implemented files it finds on disk.
|
|
86
|
+
test('auto gate after a stopped attempt: the replay uses the task baseline, not the delivered files on disk',
|
|
87
|
+
{skip:!supported},()=>fixture(async({definition,protection})=>{
|
|
88
|
+
const first=await run(definition,develop(undefined),protection);
|
|
89
|
+
assert.equal(first.code,'verification_precheck_failed');
|
|
90
|
+
assert.equal(fs.readFileSync(path.join(definition.codeProject,'a.js'),'utf8'),'new\n','the stopped delivery stays on disk');
|
|
91
|
+
const execution=createConversationExecution(definition,'host',develop([{requirement:'T-001: RED 必须先失败',satisfied:true,
|
|
92
|
+
evidence:'a.test.js 在旧 a.js 下失败',run:'red'}]),null,null,null,false,'codex',{protection,controlPolicy:policy});
|
|
93
|
+
const control=await openControlRun(definition,'resume',execution);
|
|
94
|
+
let result;try{result=await control.host.handle(request('advance'));}finally{control.close();}
|
|
95
|
+
// The gate passed and the handoff was published; this fixture has no reviewer, so the run stops at review.
|
|
96
|
+
assert.notEqual(result.code,'verification_precheck_failed',JSON.stringify(result));
|
|
97
|
+
const record=JSON.parse(handoff(definition).evidence.find(entry=>entry.startsWith('cm-host-replay-v1: ')).slice('cm-host-replay-v1: '.length));
|
|
98
|
+
assert.deepEqual([record.facts.baseline.outcome,record.facts.red.outcome],['failed','failed']);
|
|
99
|
+
}));
|
|
@@ -10,6 +10,7 @@ import fs from 'node:fs';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import os from 'node:os';
|
|
12
12
|
import {createInterface} from 'node:readline';
|
|
13
|
+
import {withConfigLock,LockBusy} from './cm-config-lock.mjs';
|
|
13
14
|
|
|
14
15
|
export const ANNOUNCE_COMMAND='~/.cm-workflow/cm-announce.sh';
|
|
15
16
|
const DECLINED='announce-hook-declined';
|
|
@@ -19,11 +20,16 @@ export const settingsPath=(env=process.env)=>
|
|
|
19
20
|
export const declinedPath=(env=process.env)=>
|
|
20
21
|
path.join(path.resolve(env.CM_WORKFLOW_HOME||path.join(env.HOME||os.homedir(),'.cm-workflow')),DECLINED);
|
|
21
22
|
|
|
23
|
+
// The raw text (null when the file does not exist) lets a later write check that
|
|
24
|
+
// nobody changed the file in between.
|
|
25
|
+
export function readSettingsText(file){
|
|
26
|
+
try{return fs.readFileSync(file,'utf8');}catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
27
|
+
}
|
|
22
28
|
export function readSettings(file){
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if(!text.trim())return {};
|
|
29
|
+
const text=readSettingsText(file);
|
|
30
|
+
if(text===null)return {};
|
|
26
31
|
// A settings file we cannot parse is never rewritten: that would destroy user content.
|
|
32
|
+
// An existing empty file is not valid JSON either.
|
|
27
33
|
return JSON.parse(text);
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -41,11 +47,17 @@ export function withAnnounceHook(settings){
|
|
|
41
47
|
return next;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
export
|
|
50
|
+
export class SettingsChanged extends Error{}
|
|
51
|
+
// With `expected`, the file is re-read right before the rename and nothing is
|
|
52
|
+
// written if it no longer holds that text, so a concurrent edit is never lost.
|
|
53
|
+
export function writeSettings(file,settings,{expected}={}){
|
|
45
54
|
fs.mkdirSync(path.dirname(file),{recursive:true});
|
|
46
55
|
const temporary=`${file}.cm-announce.${process.pid}.tmp`;
|
|
47
56
|
fs.writeFileSync(temporary,JSON.stringify(settings,null,2)+'\n',{mode:0o600});
|
|
48
|
-
try{
|
|
57
|
+
try{
|
|
58
|
+
if(expected!==undefined&&readSettingsText(file)!==expected)throw new SettingsChanged();
|
|
59
|
+
fs.renameSync(temporary,file);
|
|
60
|
+
}finally{if(fs.existsSync(temporary))fs.unlinkSync(temporary);}
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
export async function main({env=process.env,input=process.stdin,output=process.stdout,
|
|
@@ -73,9 +85,24 @@ export async function main({env=process.env,input=process.stdin,output=process.s
|
|
|
73
85
|
try{fs.mkdirSync(path.dirname(declined),{recursive:true});fs.writeFileSync(declined,'');}catch{/* 记不住也只是下次再问一次 */}
|
|
74
86
|
output.write(` 未开启。${manual}\n`);return 0;
|
|
75
87
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
// The question may have waited a long time: start again from what is on disk now,
|
|
89
|
+
// under the lock CM's other settings writers share (no lock is held while asking).
|
|
90
|
+
let message;
|
|
91
|
+
try{
|
|
92
|
+
message=withConfigLock(env,file,()=>{
|
|
93
|
+
let current;
|
|
94
|
+
try{current=readSettingsText(file);settings=current===null?{}:JSON.parse(current);}
|
|
95
|
+
catch{return `⚠ 无法解析 ${file},未改动它。${manual}\n`;}
|
|
96
|
+
if(hasAnnounceHook(settings))return ' 更新播报已启用。\n';
|
|
97
|
+
writeSettings(file,withAnnounceHook(settings),{expected:current});
|
|
98
|
+
return ' 已开启:下次启动 Claude Code 时会告知更新。\n';
|
|
99
|
+
});
|
|
100
|
+
}catch(error){
|
|
101
|
+
message=error instanceof SettingsChanged?` ⚠ ${file} 刚被其他程序改动,未改写。${manual}\n`
|
|
102
|
+
:error instanceof LockBusy?` ⚠ 另一个 CM 程序正在改 ${file},未改写。${manual}\n`
|
|
103
|
+
:` ⚠ 写入 ${file} 失败,未改动它。${manual}\n`;
|
|
104
|
+
}
|
|
105
|
+
output.write(message);
|
|
79
106
|
return 0;
|
|
80
107
|
}
|
|
81
108
|
|
|
@@ -88,3 +88,28 @@ test('withAnnounceHook does not mutate its input',()=>{
|
|
|
88
88
|
withAnnounceHook(input);
|
|
89
89
|
assert.equal(JSON.stringify(input),snapshot);
|
|
90
90
|
});
|
|
91
|
+
|
|
92
|
+
test('an existing empty or blank settings file is reported and left byte-identical',async t=>{
|
|
93
|
+
for(const content of ['',' \n']){
|
|
94
|
+
const f=fixture(t,content);
|
|
95
|
+
const text=await run(f.env,'y');
|
|
96
|
+
assert.match(text,/无法解析/);
|
|
97
|
+
assert.equal(fs.readFileSync(settingsPath(f.env),'utf8'),content);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('settings edited while the question waits are kept, not overwritten by the old copy',async t=>{
|
|
102
|
+
const f=fixture(t,{statusLine:{command:'old'}});
|
|
103
|
+
let text='';
|
|
104
|
+
const output=new Writable({write(chunk,_e,cb){text+=chunk;cb();}});
|
|
105
|
+
// Someone edits settings.json while the user is still reading the question.
|
|
106
|
+
const input=new Readable({read(){
|
|
107
|
+
fs.writeFileSync(settingsPath(f.env),JSON.stringify({statusLine:{command:'new'},permissions:{allow:['x']}}));
|
|
108
|
+
this.push('y\n');this.push(null);
|
|
109
|
+
}});
|
|
110
|
+
await main({env:f.env,input,output,interactive:true});
|
|
111
|
+
const settings=f.read();
|
|
112
|
+
assert.equal(settings.statusLine.command,'new');
|
|
113
|
+
assert.deepEqual(settings.permissions,{allow:['x']});
|
|
114
|
+
assert.ok(hasAnnounceHook(settings));
|
|
115
|
+
});
|