@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,240 @@
|
|
|
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 {spawn,spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {controlLaunchTarget} from './cm-ai-run.mjs';
|
|
10
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
11
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
13
|
+
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
14
|
+
import {createReviewedIntegrationFixture,syntheticIntegrationReview,fileRecord} from './fixtures/reviewed-integration.mjs';
|
|
15
|
+
|
|
16
|
+
const HOST=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
17
|
+
const DRIVE=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
18
|
+
const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'};
|
|
19
|
+
const expectedDigest='a'.repeat(64);
|
|
20
|
+
function cliFixture(t,{protectedMode=false}={}){
|
|
21
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-integration-launch-')));
|
|
22
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
23
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
|
|
24
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});
|
|
25
|
+
fs.writeFileSync(path.join(codeProject,'target.mjs'),'export const value=0;\n');
|
|
26
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
27
|
+
for(const file of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',file),'# Synthetic fixture\n');
|
|
28
|
+
fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),'- [ ] T-001: synthetic integration launch\n');
|
|
29
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specsDir)}));
|
|
30
|
+
const definition={version:1,codeProject,specsDir,feature:'1.work',
|
|
31
|
+
identity:{repositoryId:'integration-launch',runId:'integration-launch-original',taskId:'T-001',attempt:1},
|
|
32
|
+
scope:['target.mjs'],requirements:[]};
|
|
33
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify(definition));
|
|
34
|
+
fs.writeFileSync(path.join(root,'control.json'),JSON.stringify(policy));
|
|
35
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
|
|
36
|
+
prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
|
|
37
|
+
fs.writeFileSync(path.join(root,'evidence.json'),'{}\n');
|
|
38
|
+
const bin=path.join(root,'bin');fs.mkdirSync(bin);
|
|
39
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),path.join(bin,'codex'));
|
|
40
|
+
fs.chmodSync(path.join(bin,'codex'),0o700);
|
|
41
|
+
if(protectedMode)fs.writeFileSync(path.join(root,'protected.json'),JSON.stringify({
|
|
42
|
+
checkCommands:[{id:'synthetic',command:[process.execPath,'--check','target.mjs']}],timeoutMs:30000}));
|
|
43
|
+
const permissions=['--review-config','review.json',...(protectedMode?['--protected-conversation-config','protected.json']:[])];
|
|
44
|
+
const integration=['--integration-evidence','evidence.json','--accept-integration-digest',expectedDigest,'--expected-control','target.json'];
|
|
45
|
+
const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
46
|
+
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
|
|
47
|
+
const drive=(operation='status',extra={})=>{
|
|
48
|
+
fs.writeFileSync(path.join(root,'plan.json'),JSON.stringify({config:'run.json',controlConfig:'control.json',
|
|
49
|
+
mode:'resume',hostContext:'integration-launch-host',permissions,...extra}));
|
|
50
|
+
const result=spawnSync(process.execPath,[DRIVE,'--plan',path.join(root,'plan.json'),operation],{cwd:root,env,encoding:'utf8',timeout:30000});
|
|
51
|
+
return {...result,value:result.stdout.trim()?JSON.parse(result.stdout).result:null};
|
|
52
|
+
};
|
|
53
|
+
const host=(extra=[],{mode='resume',control=true,hostContext='integration-launch-host'}={})=>
|
|
54
|
+
spawnSync(process.execPath,[HOST,'serve','--config','run.json','--mode',mode,'--host-context',hostContext,
|
|
55
|
+
...(control?['--control-config','control.json']:['--allow-development']),...permissions,...extra],
|
|
56
|
+
{cwd:root,env,encoding:'utf8',input:'',timeout:30000});
|
|
57
|
+
const stateFile=path.join(specsDir,'.reviews','.execution',definition.identity.runId,'state.json');
|
|
58
|
+
return {root,codeProject,specsDir,env,definition,permissions,integration,drive,host,stateFile,
|
|
59
|
+
target:value=>fs.writeFileSync(path.join(root,'target.json'),JSON.stringify(value))};
|
|
60
|
+
}
|
|
61
|
+
function ready(t,options){
|
|
62
|
+
const f=cliFixture(t,options),created=f.drive('status',{mode:'create'});
|
|
63
|
+
assert.equal(created.status,0,created.stderr);assert.equal(created.value.state,'ready',JSON.stringify(created.value));
|
|
64
|
+
f.target(created.value.launchControlTarget);return {...f,launchTarget:created.value.launchControlTarget};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
test('real host requires paired explicit integration authority, v2 resume and a frozen launch target',t=>{
|
|
68
|
+
const f=cliFixture(t);
|
|
69
|
+
const cases=[
|
|
70
|
+
{args:['--integration-evidence','evidence.json']},
|
|
71
|
+
{args:['--accept-integration-digest',expectedDigest]},
|
|
72
|
+
{args:f.integration.filter((_,i)=>i<4)},
|
|
73
|
+
{args:f.integration,options:{mode:'create'}},
|
|
74
|
+
{args:f.integration,options:{control:false}},
|
|
75
|
+
{args:['--integration-evidence','evidence.json','--accept-integration-digest','invalid','--expected-control','target.json']},
|
|
76
|
+
];
|
|
77
|
+
f.target({version:2,identity:f.definition.identity,state:'ready',code:null,packageDigest:null,
|
|
78
|
+
effectId:null,invocationId:null,revision:'0'.repeat(64)});
|
|
79
|
+
for(const {args,options} of cases){
|
|
80
|
+
const result=f.host(args,options);assert.equal(result.status,1,result.stderr);
|
|
81
|
+
assert.match(result.stderr,/invalid_input|host_launch_authorization_required/);
|
|
82
|
+
assert.equal(fs.existsSync(f.stateFile),false,'invalid launch must not create an execution store');
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('real driver rejects integration advance and every mixed launch before opening the host',t=>{
|
|
87
|
+
const f=ready(t),before=fs.readFileSync(f.stateFile);
|
|
88
|
+
const attempts=[
|
|
89
|
+
['advance',f.integration],['start',f.integration],['cancel',f.integration],['qa',f.integration],
|
|
90
|
+
['status',f.integration.slice(0,2)],['status',f.integration.slice(2)],
|
|
91
|
+
['status',['--integration-evidence','evidence.json','--accept-integration-digest','A'.repeat(64),'--expected-control','target.json']],
|
|
92
|
+
['status',[...f.integration,'--rebind-spec-material','--spec-rebind-reason','Synthetic rebind']],
|
|
93
|
+
['status',[...f.integration,'--rerun-blocked-qa']],
|
|
94
|
+
['status',[...f.integration,'--hold-revision']],
|
|
95
|
+
];
|
|
96
|
+
for(const [operation,extra] of attempts){
|
|
97
|
+
const result=f.drive(operation,{permissions:[...f.permissions,...extra]});
|
|
98
|
+
assert.equal(result.status,2,result.stderr);assert.match(result.stderr,/受控集成接纳|permissions/);
|
|
99
|
+
assert.deepEqual(fs.readFileSync(f.stateFile),before);
|
|
100
|
+
}
|
|
101
|
+
const host=f.host([...f.integration,'--rerun-blocked-qa']);
|
|
102
|
+
assert.equal(host.status,1,host.stderr);assert.match(host.stderr,/invalid_input/);
|
|
103
|
+
assert.deepEqual(fs.readFileSync(f.stateFile),before);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
for(const protectedMode of [false,true])test(`real driver resolves evidence paths and rejects stale launch targets before writes (${protectedMode?'protected':'conversation'})`,t=>{
|
|
107
|
+
const f=ready(t,{protectedMode}),before=fs.readFileSync(f.stateFile);
|
|
108
|
+
f.target({...f.launchTarget,revision:'0'.repeat(64)});
|
|
109
|
+
const targetBefore=fs.readFileSync(path.join(f.root,'target.json'));
|
|
110
|
+
const result=f.drive('status',{hostContext:'integration-launch-new-host',originalHostContext:'integration-launch-host',
|
|
111
|
+
permissions:[...f.permissions,...f.integration]});
|
|
112
|
+
assert.equal(result.status,71,result.stderr);assert.match(result.stderr,/snapshot_changed/);
|
|
113
|
+
assert.deepEqual(fs.readFileSync(f.stateFile),before,'stale launch cannot append a session join or acceptance');
|
|
114
|
+
assert.deepEqual(fs.readFileSync(path.join(f.root,'target.json')),targetBefore,'driver must not refresh the frozen target');
|
|
115
|
+
assert.equal(fs.existsSync(path.join(f.root,expectedDigest)),false,'approved digest is a value, not a filename');
|
|
116
|
+
f.target(f.launchTarget);
|
|
117
|
+
const notCompleted=f.drive('status',{permissions:[...f.permissions,...f.integration]});
|
|
118
|
+
assert.equal(notCompleted.status,71,notCompleted.stderr);assert.match(notCompleted.stderr,/integration_parent_not_completed/);
|
|
119
|
+
assert.deepEqual(fs.readFileSync(f.stateFile),before,'valid target does not permit acceptance of an incomplete parent');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('integration launch validates option shape and remains unavailable without original control policy',async t=>{
|
|
123
|
+
const f=await createReviewedIntegrationFixture(t),before=fs.readFileSync(f.statePath('parent'));
|
|
124
|
+
const expectedControl=controlLaunchTarget(f.snapshot('parent'));
|
|
125
|
+
const reviewedIntegration={evidenceFile:f.evidenceFile,expectedDigest:digest(f.plan)};
|
|
126
|
+
await assert.rejects(f.openParent({reviewedIntegration,expectedControl}),{code:'recovery_launch_unavailable'});
|
|
127
|
+
await assert.rejects(f.openParent({reviewedIntegration:{...reviewedIntegration,allowed:true},expectedControl}),{code:'invalid_input'});
|
|
128
|
+
await assert.rejects(f.openParent({reviewedIntegration:{...reviewedIntegration,evidenceFile:'relative.json'},expectedControl}),{code:'invalid_input'});
|
|
129
|
+
assert.deepEqual(fs.readFileSync(f.statePath('parent')),before);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('original owner accepts a reviewed integration once, exposes status only and preserves all counts',async t=>{
|
|
133
|
+
const f=await createReviewedIntegrationFixture(t,{controlPolicy:policy});
|
|
134
|
+
const before=f.snapshot('parent'),calls={...f.calls};
|
|
135
|
+
const reviewedIntegration={evidenceFile:f.evidenceFile,expectedDigest:digest(f.plan)};
|
|
136
|
+
const options={reviewedIntegration,expectedControl:controlLaunchTarget(before)};
|
|
137
|
+
const run=await f.openParent(options);
|
|
138
|
+
try{
|
|
139
|
+
const status=await run.controlHost.handle({...f.request('parent','status'),version:2});
|
|
140
|
+
assert.equal(status.state,'fixture_completed',JSON.stringify(status));assert.equal(status.code,null);
|
|
141
|
+
const after=f.snapshot('parent');assert.deepEqual(after.records.slice(0,-1),before.records);
|
|
142
|
+
assert.equal(after.records.at(-1).payload.type,'reviewed-integration-accepted');
|
|
143
|
+
assert.equal(after.records.length,before.records.length+1);assert.deepEqual(f.calls,calls);
|
|
144
|
+
for(const operation of ['start','decision','complete','advance','qa','cancel','finish','run_finalize','fix_run','fix_action','revise_scope','development_rework']){
|
|
145
|
+
const blocked=await run.host.handle(f.request('parent',operation));
|
|
146
|
+
assert.deepEqual(blocked,{outcome:'rejected',code:'integration_launch_status_only'});
|
|
147
|
+
}
|
|
148
|
+
assert.deepEqual(f.snapshot('parent'),after);assert.deepEqual(f.calls,calls);
|
|
149
|
+
}finally{run.close();}
|
|
150
|
+
const acceptedBytes=fs.readFileSync(f.statePath('parent'));
|
|
151
|
+
await assert.rejects(f.openParent(options),{code:'snapshot_changed'});
|
|
152
|
+
assert.deepEqual(fs.readFileSync(f.statePath('parent')),acceptedBytes);
|
|
153
|
+
const reopened=await f.openParent({...options,expectedControl:controlLaunchTarget(f.snapshot('parent'))});
|
|
154
|
+
try{
|
|
155
|
+
assert.equal((await reopened.controlHost.handle({...f.request('parent','status'),version:2})).code,null);
|
|
156
|
+
assert.deepEqual(fs.readFileSync(f.statePath('parent')),acceptedBytes,'idempotent acceptance appends no duplicate');
|
|
157
|
+
}finally{reopened.close();}
|
|
158
|
+
assert.deepEqual(f.calls,calls);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('completed parent rejects wrong approved digest and changed evidence without altering any original record',async t=>{
|
|
162
|
+
const f=await createReviewedIntegrationFixture(t,{controlPolicy:policy}),before=fs.readFileSync(f.statePath('parent'));
|
|
163
|
+
const expectedControl=controlLaunchTarget(f.snapshot('parent')),calls={...f.calls};
|
|
164
|
+
await assert.rejects(f.openParent({expectedControl,reviewedIntegration:{evidenceFile:f.evidenceFile,expectedDigest:'0'.repeat(64)}}),
|
|
165
|
+
{code:'integration_target_changed'});
|
|
166
|
+
assert.deepEqual(fs.readFileSync(f.statePath('parent')),before);
|
|
167
|
+
fs.writeFileSync(f.evidenceFile,JSON.stringify({plan:f.plan,review:{...f.review,result:{}}}));
|
|
168
|
+
await assert.rejects(f.openParent({expectedControl,reviewedIntegration:{evidenceFile:f.evidenceFile,expectedDigest:digest(f.plan)}}));
|
|
169
|
+
assert.deepEqual(fs.readFileSync(f.statePath('parent')),before);assert.deepEqual(f.calls,calls);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('integration launch preserves a legal original provider configuration',async t=>{
|
|
173
|
+
const f=await createReviewedIntegrationFixture(t,{controlPolicy:{...policy,development:'provider'},providerDevelopment:true});
|
|
174
|
+
const before=f.snapshot('parent'),calls={...f.calls};
|
|
175
|
+
const run=await f.openParent({expectedControl:controlLaunchTarget(before),
|
|
176
|
+
reviewedIntegration:{evidenceFile:f.evidenceFile,expectedDigest:digest(f.plan)}});
|
|
177
|
+
try{
|
|
178
|
+
const status=await run.controlHost.handle({...f.request('parent','status'),version:2});
|
|
179
|
+
assert.equal(status.state,'fixture_completed',JSON.stringify(status));assert.equal(status.code,null);
|
|
180
|
+
assert.deepEqual(f.snapshot('parent').records.slice(0,-1),before.records);assert.deepEqual(f.calls,calls);
|
|
181
|
+
}finally{run.close();}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('real CLI driver accepts exact reviewed document evidence, then the transport refuses advance and QA-fix',async t=>{
|
|
185
|
+
const f=cliFixture(t),doc='docs/guide.md',before='# Guide\nApproved paragraph.\n',after=before+'Integrated paragraph.\n';
|
|
186
|
+
fs.mkdirSync(path.join(f.codeProject,'docs'));fs.writeFileSync(path.join(f.codeProject,doc),'# Guide\n');
|
|
187
|
+
f.definition.scope.push(doc);fs.writeFileSync(path.join(f.root,'run.json'),JSON.stringify(f.definition));
|
|
188
|
+
const answers=path.join(f.root,'answers');fs.mkdirSync(answers);
|
|
189
|
+
fs.writeFileSync(path.join(answers,'target.txt'),'export const value=1;\n');fs.writeFileSync(path.join(answers,'guide.txt'),before);
|
|
190
|
+
fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({status:'succeeded',
|
|
191
|
+
value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
192
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:{'target.mjs':'target.txt',[doc]:'guide.txt'}}));
|
|
193
|
+
const setup={answers:'answers',checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]};
|
|
194
|
+
const start=f.drive('start',{...setup,mode:'create'});assert.equal(start.status,0,start.stderr);
|
|
195
|
+
assert.equal(start.value.state,'awaiting_review',JSON.stringify(start.value));
|
|
196
|
+
const decision=f.drive('decision',{...setup,packageDigest:start.value.packageDigest});
|
|
197
|
+
assert.equal(decision.status,0,decision.stderr);assert.equal(decision.value.state,'approved',JSON.stringify(decision.value));
|
|
198
|
+
const completed=f.drive('complete',{...setup,packageDigest:start.value.packageDigest});
|
|
199
|
+
assert.equal(completed.status,0,completed.stderr);assert.equal(completed.value.state,'fixture_completed',JSON.stringify(completed.value));
|
|
200
|
+
const snapshot=()=>readExecutionSnapshot({specsRoot:f.specsDir,identity:{repositoryId:f.definition.identity.repositoryId,runId:f.definition.identity.runId}});
|
|
201
|
+
const original=snapshot(),history=readRunnerHistory(original.records,original.records[0].payload.config,3);
|
|
202
|
+
const plan={version:1,kind:'cm-reviewed-integration-v1',author:{provider:'codex',contextId:'synthetic-integration-author'},
|
|
203
|
+
target:{identity:f.definition.identity,rootDigest:history.original.rootDigest,baselineDigest:history.original.baselineDigest,
|
|
204
|
+
packageDigest:history.state.reviewPackage.packageDigest,recordCount:original.records.length,lastDigest:original.records.at(-1).digest},
|
|
205
|
+
sources:[],documents:[{path:doc,before:fileRecord(doc,before),after:fileRecord(doc,after)}]};
|
|
206
|
+
const review=await syntheticIntegrationReview(f.root,plan,{[doc]:{before,after}});
|
|
207
|
+
fs.writeFileSync(path.join(f.root,'evidence.json'),JSON.stringify({plan,review})+'\n');
|
|
208
|
+
fs.writeFileSync(path.join(f.codeProject,doc),after);f.target(controlLaunchTarget(original));
|
|
209
|
+
const permissions=[...f.permissions,'--integration-evidence','evidence.json','--accept-integration-digest',digest(plan),'--expected-control','target.json'];
|
|
210
|
+
const accepted=f.drive('status',{permissions});assert.equal(accepted.status,0,accepted.stderr);
|
|
211
|
+
assert.equal(accepted.value.state,'fixture_completed',JSON.stringify(accepted.value));assert.equal(accepted.value.code,null);
|
|
212
|
+
const acceptedSnapshot=snapshot(),acceptedBytes=fs.readFileSync(f.stateFile);
|
|
213
|
+
assert.deepEqual(acceptedSnapshot.records.slice(0,-1),original.records);
|
|
214
|
+
assert.equal(acceptedSnapshot.records.at(-1).payload.type,'reviewed-integration-accepted');
|
|
215
|
+
f.target(accepted.value.launchControlTarget);
|
|
216
|
+
const operations=['status','advance','fix_run','cancel'];
|
|
217
|
+
const result=await new Promise((resolve,reject)=>{
|
|
218
|
+
const child=spawn(process.execPath,[HOST,'serve','--config','run.json','--mode','resume','--host-context','integration-launch-host',
|
|
219
|
+
'--control-config','control.json',...permissions],{cwd:f.root,env:f.env,stdio:['pipe','pipe','pipe']});
|
|
220
|
+
let buffer='',stderr='',index=0;const rows=[];
|
|
221
|
+
const timer=setTimeout(()=>{child.kill();reject(Error('synthetic integration transport deadline'));},30000);
|
|
222
|
+
const next=()=>{if(index===operations.length){child.stdin.end();return;}
|
|
223
|
+
const operation=operations[index++];child.stdin.write(JSON.stringify({version:2,operation,requestId:operation,identity:f.definition.identity})+'\n');};
|
|
224
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});child.on('error',reject);
|
|
225
|
+
child.stdout.on('data',chunk=>{
|
|
226
|
+
buffer+=chunk;
|
|
227
|
+
while(buffer.includes('\n')){const end=buffer.indexOf('\n'),line=buffer.slice(0,end);buffer=buffer.slice(end+1);
|
|
228
|
+
if(!line.trim())continue;const row=JSON.parse(line);rows.push(row);
|
|
229
|
+
if(row.type==='host_request'){child.kill();reject(Error('integration launch dispatched a tool'));}
|
|
230
|
+
if(row.type==='host_ready'||row.requestId)next();
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
child.on('close',code=>{clearTimeout(timer);resolve({code,stderr,rows});});
|
|
234
|
+
});
|
|
235
|
+
assert.equal(result.code,0,result.stderr);
|
|
236
|
+
assert.equal(result.rows.find(row=>row.requestId==='status').result.code,null);
|
|
237
|
+
for(const operation of operations.slice(1))assert.deepEqual(result.rows.find(row=>row.requestId===operation).result,
|
|
238
|
+
{outcome:'rejected',code:'integration_launch_status_only'});
|
|
239
|
+
assert.deepEqual(fs.readFileSync(f.stateFile),acceptedBytes,'idempotent raw launch and rejected operations preserve all bytes');
|
|
240
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Read-only inspection. Does not construct a host or open the execution writer.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {fileURLToPath} from 'node:url';
|
|
6
|
+
import {readRunDefinition,controlLaunchTarget} from './cm-ai-run.mjs';
|
|
7
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
8
|
+
import {readRunnerHistory,attemptBaseline} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
9
|
+
import {readIntegrationPlan,readIntegrationEvidence,previewReviewedIntegration} from '../runtime/js/cm-ai/reviewed-integration.mjs';
|
|
10
|
+
import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
|
|
12
|
+
export function main(argv=process.argv.slice(2),output=process.stdout){
|
|
13
|
+
try{
|
|
14
|
+
const args=new Map();need(argv.length===4,'invalid_arguments');
|
|
15
|
+
for(let i=0;i<argv.length;i+=2){
|
|
16
|
+
need(['--run-definition','--plan','--evidence'].includes(argv[i])&&!args.has(argv[i])&&argv[i+1],'invalid_arguments');
|
|
17
|
+
args.set(argv[i],argv[i+1]);
|
|
18
|
+
}
|
|
19
|
+
need(args.has('--run-definition')&&Number(args.has('--plan'))+Number(args.has('--evidence'))===1,'invalid_arguments');
|
|
20
|
+
const definition=readRunDefinition(path.resolve(args.get('--run-definition')));
|
|
21
|
+
let plan,review=null;
|
|
22
|
+
if(args.has('--evidence'))({plan,review}=readIntegrationEvidence(path.resolve(args.get('--evidence'))));
|
|
23
|
+
else{
|
|
24
|
+
const file=path.resolve(args.get('--plan')),stat=fs.lstatSync(file);
|
|
25
|
+
need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size<=128*1024&&fs.realpathSync(file)===file,'integration_plan_invalid');
|
|
26
|
+
const bytes=fs.readFileSync(file),raw=JSON.parse(bytes);
|
|
27
|
+
need(bytes.equals(Buffer.from(JSON.stringify(raw)+'\n')),'integration_plan_invalid');plan=readIntegrationPlan(raw);
|
|
28
|
+
}
|
|
29
|
+
const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,identity:{
|
|
30
|
+
repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
|
|
31
|
+
const init=snapshot.records[0].payload,history=readRunnerHistory(snapshot.records,init.config,init.version);
|
|
32
|
+
const result=previewReviewedIntegration({root:init.config.root,specsRoot:definition.specsDir,
|
|
33
|
+
baseline:attemptBaseline(history.original,history.state.attempt),parentPackage:history.state.reviewPackage,
|
|
34
|
+
records:snapshot.records,plan,review});
|
|
35
|
+
output.write(JSON.stringify({...result,originalRevision:snapshot.revision,
|
|
36
|
+
launchControlTarget:controlLaunchTarget(snapshot),productRecoveryExecuted:false})+'\n');
|
|
37
|
+
return result.eligibleForAdoption?0:2;
|
|
38
|
+
}catch(error){output.write(JSON.stringify({eligibleForAdoption:false,code:error.code??'integration_evidence_invalid',
|
|
39
|
+
productRecoveryExecuted:false})+'\n');return 1;}
|
|
40
|
+
}
|
|
41
|
+
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=main();
|
|
@@ -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);
|
|
@@ -117,3 +117,74 @@ test('V5 the second no-result redispatch asks for the operator stop confirmation
|
|
|
117
117
|
const g=explain('blocked','review_transport_timeout','abandon_review',{reviewRedispatchStopRequired:true});
|
|
118
118
|
assert.equal(g.recoveryOperation,'abandon_review');assert.match(g.nextStep,/确认原审查进程/);assert.equal(g.authorizationGranted,false);
|
|
119
119
|
});
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
test('recovery guidance selects protocol and surface without changing native results',()=>{
|
|
123
|
+
const cases=[['unknown','execution_error','abandon_effect'],['unknown','execution_error','abandon_review'],
|
|
124
|
+
['blocked','bootstrap_review_mismatch','bootstrap_review_recover'],['blocked','develop_answer_missing','develop_redo'],
|
|
125
|
+
['blocked','documentation_sync_answer_missing','develop_redo']];
|
|
126
|
+
for(const protocol of ['legacy','v2'])for(const surface of ['single','batch'])for(const [state,code,action] of cases){
|
|
127
|
+
const input=result(state,code,action),before=JSON.stringify(input);
|
|
128
|
+
const value={...input,guidance:operatorGuidance(input,{protocol})};
|
|
129
|
+
const output=surface==='batch'?batchMemberResult(value,{protocol,taskKey:'1.work/T-001'}):value;
|
|
130
|
+
const rendered=guidanceText(output);
|
|
131
|
+
assert.equal(output.guidance.recoveryOperation,action);assert.equal(output.guidance.authorizationGranted,false);
|
|
132
|
+
assert.equal(JSON.stringify(input),before);
|
|
133
|
+
assert.equal(output.state,input.state);assert.equal(output.code,input.code);assert.equal(output.pendingAction,input.pendingAction);
|
|
134
|
+
if(protocol==='v2'){
|
|
135
|
+
assert.doesNotMatch(rendered,/--allow-|--supersede-reviewed-evidence/);
|
|
136
|
+
assert.match(rendered,/status/);assert.match(rendered,/expectedControl/);assert.match(rendered,/snapshot_changed/);
|
|
137
|
+
assert.match(rendered,/不自动刷新/);
|
|
138
|
+
}else assert.match(rendered,/--allow-/);
|
|
139
|
+
if(surface==='batch')assert.match(rendered,/批次/);
|
|
140
|
+
if(code==='documentation_sync_answer_missing')assert.match(rendered,/停止修改文档/);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('v2 exhausted recovery and launch recovery never advertise legacy exits',()=>{
|
|
145
|
+
for(const code of ['review_redispatch_limit','documentation_sync_retry_limit','check_answer_retry_limit','complete_recheck_limit','develop_redo_limit']){
|
|
146
|
+
for(const protocol of ['legacy','v2'])for(const surface of ['single','batch']){
|
|
147
|
+
const input=result('blocked',code,'none');input.guidance=operatorGuidance(input,{protocol});
|
|
148
|
+
const output=surface==='batch'?batchMemberResult(input,{protocol}):input;
|
|
149
|
+
assert.equal(output.guidance.recoveryOperation,null);
|
|
150
|
+
if(protocol==='v2'){assert.doesNotMatch(guidanceText(output),/--supersede-reviewed-evidence|--accept-superseded-code-drift/);
|
|
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),/取消本批次/);}
|
|
156
|
+
else assert.match(guidanceText(output),/--supersede-reviewed-evidence/);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for(const refusal of ['review_process_unverified','review_observation_invalid','review_boundary_unverified','review_abandon_budget_exhausted']){
|
|
160
|
+
const input=result('unknown','transport_incomplete','reconcile',{reviewAbandonRefusal:refusal});
|
|
161
|
+
input.guidance=operatorGuidance(input,{protocol:'v2'});
|
|
162
|
+
assert.doesNotMatch(guidanceText(input),/--supersede-reviewed-evidence/);
|
|
163
|
+
}
|
|
164
|
+
const qa=result('fixture_completed','qa_execution_unknown','reconcile');qa.guidance=operatorGuidance(qa,{protocol:'v2'});
|
|
165
|
+
assert.match(guidanceText(qa),/launchControlTarget/);assert.match(guidanceText(qa),/--expected-control/);
|
|
166
|
+
assert.doesNotMatch(guidanceText(qa),/--supersede-reviewed-evidence/);
|
|
167
|
+
const batch=batchMemberResult(qa,{protocol:'v2'});
|
|
168
|
+
assert.doesNotMatch(guidanceText(batch),/--rerun-unknown-qa|--expected-control/);
|
|
169
|
+
const drift=result('blocked','spec_drift','spec_rebind',{reason:'synthetic'});drift.guidance=operatorGuidance(drift,{protocol:'v2'});
|
|
170
|
+
assert.doesNotMatch(JSON.stringify(batchMemberResult(drift,{protocol:'v2'})),/--supersede-reviewed-evidence/);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('batch advance guidance uses the batch entry for every native resume family',()=>{
|
|
174
|
+
for(const code of ['documentation_sync_interrupted','develop_answer_missing','develop_out_of_scope','check_answer_missing','develop_checks_not_passed']){
|
|
175
|
+
const input=result('blocked',code,'resume');input.guidance=operatorGuidance(input);
|
|
176
|
+
const output=batchMemberResult(input);
|
|
177
|
+
assert.match(guidanceText(output),/原批次入口/);assert.doesNotMatch(guidanceText(output),/恢复原运行/);
|
|
178
|
+
}
|
|
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
|
+
});
|