@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,211 @@
|
|
|
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 {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
9
|
+
import {openExecutionStore} from '../runtime/js/cm-ai/execution-store.mjs';
|
|
10
|
+
import * as execution from '../runtime/js/cm-fix/execution.mjs';
|
|
11
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {assertJestConfigurationDiscovery} from '../runtime/js/cm-fix/jest-command-correction.mjs';
|
|
13
|
+
import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
|
|
14
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
15
|
+
import {fixFinalReviewConfiguration} from '../runtime/js/cm-fix/final-review.mjs';
|
|
16
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
17
|
+
|
|
18
|
+
const DRIVER=fileURLToPath(new URL('./cm-fix-drive.mjs',import.meta.url));
|
|
19
|
+
const INSPECT=fileURLToPath(new URL('./cm-fix-command-correction.mjs',import.meta.url));
|
|
20
|
+
|
|
21
|
+
async function fixture(t,{green=false,unrelated=false,closeout=false,summaryFailure=false,configRepairScope=false,commandSuffix=[]}={}){
|
|
22
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-jest-correction-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
|
|
23
|
+
fs.mkdirSync(path.join(cwd,'app/node_modules/jest/bin'),{recursive:true});fs.mkdirSync(specsRoot);
|
|
24
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
25
|
+
fs.writeFileSync(path.join(cwd,'app/package.json'),JSON.stringify({jest:{}}));
|
|
26
|
+
if(closeout)fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
27
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
28
|
+
fs.writeFileSync(path.join(cwd,'test.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('TARGET BUG');process.exit(1)}");
|
|
29
|
+
const cli='app/node_modules/jest/bin/jest.js',callsPath=path.join(root,'check-calls');
|
|
30
|
+
fs.writeFileSync(path.join(cwd,cli),`const fs=require('node:fs');fs.appendFileSync(${JSON.stringify(callsPath)},'1');if(!process.argv.includes('--config')){console.error('Error: Could not find a config file based on provided values:\\ncwd: "'+process.cwd()+'"');process.exit(1)}if(process.argv.includes('--baseline'))process.exit(0);import(process.cwd()+'/test.mjs');`);
|
|
31
|
+
if(summaryFailure){const file=path.join(cwd,cli);fs.writeFileSync(file,fs.readFileSync(file,'utf8').replace('process.exit(1)',"console.error('Test Suites: 1 failed, 1 total');process.exit(1)"));}
|
|
32
|
+
const command=[process.execPath,cli,'--rootDir','app',...commandSuffix];
|
|
33
|
+
const options={specsRoot,identity:{repositoryId:'fixture',runId:'jest-command',taskId:'T-FIX-command',attempt:1},create:true,configuration:{hostContextId:'fixture-host',defect:'Wrong constant',
|
|
34
|
+
reproduction:{cwd,command:[process.execPath,'test.mjs'],expectedFailure:{exitCode:1,outputIncludes:'TARGET BUG'},timeoutMs:3000},
|
|
35
|
+
redTest:{cwd,command:green?[process.execPath,'-e','process.exit(0)']:unrelated?[process.execPath,'-e',"console.error('OTHER');process.exit(1)"]:command,testFiles:['test.mjs'],expectedFailure:{exitCode:1,outputIncludes:'TARGET BUG'},timeoutMs:3000},
|
|
36
|
+
baseline:{cwd,testFiles:['test.mjs'],commands:[{id:'existing',command:[...command,'--baseline']}],timeoutMs:3000},
|
|
37
|
+
repair:{scope:configRepairScope?['value.mjs','app/package.json']:['value.mjs'],requirements:['value.mjs']},walkthrough:{flows:[{id:'flow',modules:['one'],kind:'commands',steps:['Run constant'],expected:['No error'],command}],timeoutMs:3000}}};
|
|
38
|
+
if(closeout){options.configuration.reviewRuntime='claude';options.configuration.causeReview={reviewerId:'fixture-cause',adapterId:'claude-review-adapter',provider:'claude',requestedModel:'synthetic',contextId:'fixture-cause-context',excludedThreadIds:[]};}
|
|
39
|
+
const learning={files:[],contextDigest:digest([]),application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'Fixture'}};
|
|
40
|
+
const bridge={call:async(kind)=>{
|
|
41
|
+
if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],plan:'Set value to 2',crossLayer:false,affectedModules:['one'],investigation:{discardedAlternatives:[],boundaryAnalysis:null}};
|
|
42
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
|
|
43
|
+
assert.equal(kind,'fix_repair');fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=2;');return {outcome:'repaired'};
|
|
44
|
+
}};
|
|
45
|
+
const capabilities={bridge,assertReviewReady(){},...(closeout?{prepare:async()=>learning}:{})};
|
|
46
|
+
let owner=openFixExecution(options,capabilities);t.after(()=>owner.close());
|
|
47
|
+
if(closeout)startFixRun({specsRoot,identity:options.identity,configuration:options.configuration});
|
|
48
|
+
await owner.advance({authorized:true});assert.equal((await owner.runRedTest({authorized:true})).stage,'red_test_not_confirmed');
|
|
49
|
+
const statePath=path.join(specsRoot,'.reviews/.execution/jest-command/state.json'),state=()=>JSON.parse(fs.readFileSync(statePath));
|
|
50
|
+
const reopen=(extra={})=>{owner.close();owner=openFixExecution({...options,create:false},{...capabilities,...extra});return owner;};
|
|
51
|
+
return {root,cwd,specsRoot,options,statePath,state,reopen,checkCalls:()=>fs.readFileSync(callsPath,'utf8'),get owner(){return owner;},declaration:{kind:'jest-config-path',path:'app/package.json'}};
|
|
52
|
+
}
|
|
53
|
+
test('original not-red run gains one explicit correction; all later command phases and replay use corrected argv',async t=>{
|
|
54
|
+
const f=await fixture(t),before=f.state(),output=f.owner.status().redTest.output,old=fs.readFileSync(path.join(f.specsRoot,output.path));
|
|
55
|
+
const expected=f.owner.inspectCommandCorrection({declaration:f.declaration});
|
|
56
|
+
assert.deepEqual(f.state(),before);assert.equal(expected.commands.length,3);
|
|
57
|
+
assert.throws(()=>f.owner.prepareCommandCorrection({expected,declaration:f.declaration,previousInvocationStopped:true,reason:'explicit config'}),{code:'fix_command_correction_authorization_required'});
|
|
58
|
+
const input={authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'Explicitly add config discovery only'};
|
|
59
|
+
assert.equal(f.owner.prepareCommandCorrection(input).stage,'red_test_required');
|
|
60
|
+
assert.deepEqual(f.state().records.slice(0,before.records.length),before.records);assert.deepEqual(f.state().fingerprints,before.fingerprints);
|
|
61
|
+
assert.equal((await f.reopen().runRedTest({authorized:true})).stage,'baseline_required');
|
|
62
|
+
assert.match(f.owner.status().redTest.output.path,/-retry-1\.md$/);assert.deepEqual(fs.readFileSync(path.join(f.specsRoot,output.path)),old);
|
|
63
|
+
assert.equal((await f.owner.captureBaseline({authorized:true})).stage,'repair_required');
|
|
64
|
+
assert.equal(f.owner.status().baseline.observations[0].outcome,'passed');
|
|
65
|
+
assert.equal((await f.owner.repair({authorized:true})).stage,'regression_required');
|
|
66
|
+
assert.equal((await f.owner.runRegression({authorized:true})).stage,'handoff_required');
|
|
67
|
+
assert.equal(f.reopen().status().stage,'handoff_required');
|
|
68
|
+
assert.equal(f.owner.status().regression.red.outcome,'passed');assert.equal(f.owner.status().regression.baseline.observations[0].outcome,'passed');
|
|
69
|
+
assert.throws(()=>f.owner.prepareCommandCorrection(input),{code:'fix_command_correction_used'});
|
|
70
|
+
});
|
|
71
|
+
test('qualification rejects real green/unrelated failure, stale history, changed tests/config and arbitrary corrections',async t=>{
|
|
72
|
+
for(const mode of ['green','unrelated']){
|
|
73
|
+
const f=await fixture(t,{[mode]:true});assert.throws(()=>f.owner.inspectCommandCorrection({declaration:f.declaration}),{code:'fix_command_correction_unavailable'});f.owner.close();
|
|
74
|
+
}
|
|
75
|
+
const f=await fixture(t),expected=f.owner.inspectCommandCorrection({declaration:f.declaration});
|
|
76
|
+
for(const override of [{previousInvocationStopped:false},{reason:''},{expected:{...expected,historyDigest:digest('stale')}}]){
|
|
77
|
+
assert.throws(()=>f.owner.prepareCommandCorrection({authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'fixed',...override}));
|
|
78
|
+
}
|
|
79
|
+
const old=fs.readFileSync(path.join(f.cwd,'test.mjs'));fs.appendFileSync(path.join(f.cwd,'test.mjs'),'\n// drift');
|
|
80
|
+
assert.throws(()=>f.owner.prepareCommandCorrection({authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'fixed'}));
|
|
81
|
+
fs.writeFileSync(path.join(f.cwd,'test.mjs'),old);
|
|
82
|
+
assert.throws(()=>f.owner.inspectCommandCorrection({declaration:{...f.declaration,command:['anything']}}));
|
|
83
|
+
fs.appendFileSync(path.join(f.cwd,'app/package.json'),' ');
|
|
84
|
+
assert.throws(()=>f.owner.prepareCommandCorrection({authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'fixed'}),{code:'fix_command_correction_stale'});
|
|
85
|
+
});
|
|
86
|
+
test('read-only inspection API exists and new-run launch preflight rejects every missing Jest configuration',()=>{
|
|
87
|
+
assert.equal(typeof execution.inspectFixCommandCorrection,'function');
|
|
88
|
+
const config={reproduction:{cwd:'/no-such-fixture'},redTest:{cwd:'/no-such-fixture',command:['node','app/node_modules/jest/bin/jest.js','--rootDir','app']}};
|
|
89
|
+
assert.throws(()=>assertJestConfigurationDiscovery(config),{code:'fix_jest_config_path_required'});
|
|
90
|
+
assert.doesNotThrow(()=>assertJestConfigurationDiscovery({...config,redTest:{...config.redTest,command:[...config.redTest.command,'--config','app/package.json']}}));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('real inspector and driver prepare one correction without running checks or altering old records',async t=>{
|
|
94
|
+
const f=await fixture(t),before=f.state(),checkCalls=f.checkCalls();f.owner.close();
|
|
95
|
+
const config=path.join(f.root,'config.json'),plan=path.join(f.root,'plan.json');
|
|
96
|
+
const {hostContextId,...configuration}=f.options.configuration;
|
|
97
|
+
fs.writeFileSync(config,JSON.stringify({...configuration,specsRoot:f.specsRoot,identity:f.options.identity}));
|
|
98
|
+
const cli=args=>spawnSync(process.execPath,args,{encoding:'utf8',timeout:30000,env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});
|
|
99
|
+
const preview=cli([INSPECT,'--config',config,'--jest-config',f.declaration.path]);
|
|
100
|
+
assert.equal(preview.status,0,preview.stdout+preview.stderr);
|
|
101
|
+
const expected=JSON.parse(preview.stdout).expected;assert.equal(expected.commands.length,3);assert.deepEqual(f.state(),before);
|
|
102
|
+
const base={config,cwd:f.cwd,mode:'resume',hostContext:hostContextId,runtime:'codex',expected,commandCorrection:f.declaration,previousInvocationStopped:true,reason:'Explicit Jest discovery correction'};
|
|
103
|
+
const drive=(permissions,extra={})=>{fs.writeFileSync(plan,JSON.stringify({...base,permissions,...extra}));return cli([DRIVER,'--plan',plan,'prepare_command_correction']);};
|
|
104
|
+
for(const [permissions,extra]of [[[],{}],[['--allow-command-correction'],{previousInvocationStopped:false}],[['--allow-command-correction'],{mode:'create'}]]){
|
|
105
|
+
const rejected=drive(permissions,extra);assert.notEqual(rejected.status,0);assert.deepEqual(f.state(),before);
|
|
106
|
+
}
|
|
107
|
+
const prepared=drive(['--allow-command-correction']);assert.equal(prepared.status,0,prepared.stdout+prepared.stderr);
|
|
108
|
+
assert.match(prepared.stdout,/red_test_required/);
|
|
109
|
+
const after=f.state();assert.deepEqual(after.records.slice(0,before.records.length),before.records);assert.deepEqual(after.fingerprints,before.fingerprints);
|
|
110
|
+
assert.equal(after.records.length,before.records.length+1);
|
|
111
|
+
const again=drive(['--allow-command-correction']);assert.notEqual(again.status,0);assert.deepEqual(f.state(),after);
|
|
112
|
+
const used=cli([INSPECT,'--config',config,'--jest-config',f.declaration.path]);assert.notEqual(used.status,0);assert.match(used.stderr,/fix_command_correction_used/);
|
|
113
|
+
assert.equal(f.checkCalls(),checkCalls);
|
|
114
|
+
assert.equal((await f.reopen().runRedTest({authorized:true})).stage,'baseline_required');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('corrected original run completes fixture review, N5, post-review regression, walkthrough and finish',async t=>{
|
|
118
|
+
const f=await fixture(t,{closeout:true}),before=f.state(),expected=f.owner.inspectCommandCorrection({declaration:f.declaration});
|
|
119
|
+
f.owner.prepareCommandCorrection({authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'Explicit Jest discovery correction'});
|
|
120
|
+
assert.equal((await f.reopen().runRedTest({authorized:true})).stage,'baseline_required');
|
|
121
|
+
assert.equal((await f.owner.captureBaseline({authorized:true})).stage,'repair_required');
|
|
122
|
+
assert.equal((await f.owner.repair({authorized:true})).stage,'regression_required');
|
|
123
|
+
assert.equal((await f.owner.runRegression({authorized:true})).stage,'handoff_required');
|
|
124
|
+
assert.equal((await f.owner.retrospect()).stage,'handoff_ready');
|
|
125
|
+
assert.equal(f.owner.createHandoff().stage,'final_review_required');
|
|
126
|
+
const pkg=f.owner.finalReviewPackage();assert(pkg.checks.every(c=>c.outcome==='passed'));
|
|
127
|
+
const settings=fixFinalReviewConfiguration(f.options.configuration),authority=createHostReviewAuthority({hostContextId:settings.hostContextId,reviewerId:settings.reviewer.reviewerId,adapterId:settings.reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
128
|
+
await authority.hostDecisionProvider.decide({identity:pkg.identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
129
|
+
let calls=0;
|
|
130
|
+
f.reopen({finalReview:{authorize:authority.authorize,run:async(request,{onEvent})=>{
|
|
131
|
+
assert.equal(request.provider,'claude');assert.equal(request.requestedModel,'synthetic');
|
|
132
|
+
calls++;for(const event of [{event:'thread.started',provider_thread:'synthetic-command-correction-reviewer'},{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])assert.equal(onEvent(event),true);
|
|
133
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic fixture only; no Claude call'}};
|
|
134
|
+
}}});
|
|
135
|
+
assert.equal((await f.owner.reviewFinal()).stage,'final_review_evidence_required');assert.equal(calls,1);
|
|
136
|
+
assert.equal(f.owner.publishReview().stage,'completion_gate_required');
|
|
137
|
+
assert.equal(f.owner.checkCompletionGate().stage,'post_review_regression_required');
|
|
138
|
+
assert.equal((await f.owner.runRegression({authorized:true,postReview:true})).stage,'closeout_required');
|
|
139
|
+
assert.equal((await f.reopen().runWalkthrough({authorized:true})).stage,'closeout_required');
|
|
140
|
+
assert.equal(f.owner.status().walkthrough.status,'passed');
|
|
141
|
+
assert.equal(f.owner.status().walkthrough.rows[0].observation.command.at(-1),'app/package.json');
|
|
142
|
+
f.owner.publishDossier();
|
|
143
|
+
const finished=f.owner.finish({authorized:true});assert.equal(finished.stage,'completed');assert.equal(finished.completionEligible,true);
|
|
144
|
+
assert.equal(f.reopen().status().stage,'completed');assert.equal(f.owner.completionEvidence().identity.runId,f.options.identity.runId);
|
|
145
|
+
assert.deepEqual(f.state().records.slice(0,before.records.length),before.records);assert.deepEqual(f.state().fingerprints,before.fingerprints);
|
|
146
|
+
assert.equal(calls,1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('prepared correction refuses source drift before corrected red without losing history or executing another check',async t=>{
|
|
150
|
+
const f=await fixture(t),expected=f.owner.inspectCommandCorrection({declaration:f.declaration});
|
|
151
|
+
f.owner.prepareCommandCorrection({authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'Explicit Jest discovery correction'});
|
|
152
|
+
const prepared=f.state(),checkCalls=f.checkCalls(),source=path.join(f.cwd,'value.mjs'),original=fs.readFileSync(source);
|
|
153
|
+
fs.appendFileSync(source,'\n// unrelated drift after qualification');
|
|
154
|
+
assert.equal(f.owner.status().stage,'command_correction_drift');
|
|
155
|
+
assert.equal((await f.owner.runRedTest({authorized:true})).stage,'command_correction_drift');
|
|
156
|
+
assert.deepEqual(f.state(),prepared);
|
|
157
|
+
f.reopen();assert.equal(f.owner.status().stage,'command_correction_drift');assert.deepEqual(f.state(),prepared);
|
|
158
|
+
assert.equal(f.checkCalls(),checkCalls);
|
|
159
|
+
fs.writeFileSync(source,original);
|
|
160
|
+
assert.equal(f.owner.status().stage,'red_test_required');
|
|
161
|
+
assert.equal((await f.owner.runRedTest({authorized:true})).stage,'baseline_required');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Startup correction must not become a retry for tests that actually ran, or
|
|
165
|
+
// freeze a configuration file which the declared repair itself must change.
|
|
166
|
+
test('qualification rejects Jest test summaries and repair-owned configuration',async t=>{
|
|
167
|
+
for(const option of ['summaryFailure','configRepairScope']){
|
|
168
|
+
const f=await fixture(t,{[option]:true}),before=f.state();
|
|
169
|
+
assert.throws(()=>f.owner.inspectCommandCorrection({declaration:f.declaration}),{code:option==='summaryFailure'?'fix_command_correction_unavailable':'fix_command_correction_config'});
|
|
170
|
+
assert.deepEqual(f.state(),before);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('corrected red retry budget refuses an eighth abandon before poisoning replay',async t=>{
|
|
175
|
+
const f=await fixture(t),expected=f.owner.inspectCommandCorrection({declaration:f.declaration});
|
|
176
|
+
f.owner.prepareCommandCorrection({authorized:true,expected,declaration:f.declaration,previousInvocationStopped:true,reason:'Explicit Jest discovery correction'});
|
|
177
|
+
for(let retry=1;retry<=8;retry++){
|
|
178
|
+
// An occupied private result path makes this isolated command's publication
|
|
179
|
+
// unknown, without fabricating or editing a journal record.
|
|
180
|
+
const output=path.join(f.specsRoot,`.reviews/fix-command-a1-red-output-retry-${retry}.md`);
|
|
181
|
+
fs.writeFileSync(output,'existing evidence must survive',{mode:0o600});
|
|
182
|
+
assert.equal((await f.owner.runRedTest({authorized:true})).stage,'unknown');
|
|
183
|
+
if(retry<8){assert.equal(f.owner.abandonStep({authorized:true,reason:'Stopped fixture command; preserve lost result'}).stage,'red_test_required');f.reopen();}
|
|
184
|
+
}
|
|
185
|
+
const before=f.state();
|
|
186
|
+
assert.throws(()=>f.owner.abandonStep({authorized:true,reason:'Must not create retry nine'}),{code:'fix_abandon_limit'});
|
|
187
|
+
assert.deepEqual(f.state(),before);assert.equal(f.reopen().status().stage,'unknown');
|
|
188
|
+
assert.equal((await f.owner.runRedTest({authorized:true})).stage,'unknown');assert.deepEqual(f.state(),before);
|
|
189
|
+
assert.equal(f.state().records.some(r=>r.id.includes('retry-9')),false);
|
|
190
|
+
// Upgrade fixture: the old runtime could already have appended abandon #8.
|
|
191
|
+
// Preserve that legal prefix and refuse the next intent before any append.
|
|
192
|
+
f.owner.close();
|
|
193
|
+
const history=f.state(),store=openExecutionStore({specsRoot:f.specsRoot,identity:history.identity,fingerprints:history.fingerprints,create:false});
|
|
194
|
+
try{store.append({id:'fix-abandoned-8',kind:'result',expectedRevision:history.revision,payload:{pending:'red_test',reason:'Old-runtime legal abandon',abandonedAt:Date.now(),intentDigest:digest(history.records.at(-1))}});}finally{store.close();}
|
|
195
|
+
const legacy=f.state();assert.equal(f.reopen().status().stage,'red_test_required');
|
|
196
|
+
await assert.rejects(()=>f.owner.runRedTest({authorized:true}),{code:'fix_abandon_limit'});
|
|
197
|
+
assert.deepEqual(f.state(),legacy);assert.equal(f.reopen().status().stage,'red_test_required');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('new-run configuration discovery accepts Jest default package.json without jest field',t=>{
|
|
201
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'jest-default-config-')));t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
202
|
+
fs.writeFileSync(path.join(root,'package.json'),'{}');
|
|
203
|
+
assert.doesNotThrow(()=>assertJestConfigurationDiscovery({reproduction:{cwd:root},redTest:{cwd:root,command:['node','node_modules/jest/bin/jest.js','--rootDir','.']}}));
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('qualification refuses Jest option separators and existing short config alias',async t=>{
|
|
207
|
+
for(const commandSuffix of [['--'],['-c','app/package.json']]){
|
|
208
|
+
const f=await fixture(t,{commandSuffix}),before=f.state();
|
|
209
|
+
assert.throws(()=>f.owner.inspectCommandCorrection({declaration:f.declaration}),{code:'fix_command_correction_config'});assert.deepEqual(f.state(),before);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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 {createHash} from 'node:crypto';
|
|
7
|
+
import {appendFixMetrics,appendFixMetricsSteps} from '../runtime/js/cm-fix/metrics.mjs';
|
|
8
|
+
import {runStepsSync,runStepsCooperatively} from '../runtime/js/cm-fix/cooperative.mjs';
|
|
9
|
+
import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
|
|
10
|
+
import {finishFixSteps} from '../runtime/js/cm-fix/finish.mjs';
|
|
11
|
+
|
|
12
|
+
function fixture(t){
|
|
13
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cooperative-')));t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
14
|
+
fs.mkdirSync(path.join(root,'fixes'));const dossierFile='20261015-value.md',body='Fixture dossier\n';
|
|
15
|
+
fs.writeFileSync(path.join(root,'fixes',dossierFile),body);
|
|
16
|
+
const identity={repositoryId:'fixture',runId:'cooperative-run',taskId:'T-FIX-value',attempt:1};
|
|
17
|
+
const common={workflow:'cm-fix',node:'FIX',repository_id:identity.repositoryId,run_id:identity.runId,task:identity.taskId,attempt:1};
|
|
18
|
+
const events=[{...common,event:'task_start',at:'2026-10-15T01:00:00Z',event_id:'start'},
|
|
19
|
+
{...common,event:'review',phase:'complete',review_kind:'implementation',round:1,result:'approved',finding_count:0,package_digest:'a'.repeat(64),event_id:'review'},
|
|
20
|
+
{...common,event:'task_done',at:'2026-10-15T01:01:00Z',event_id:'done',result:'completed',dossier_file:`fixes/${dossierFile}`,dossier_sha256:createHash('sha256').update(body).digest('hex'),package_digest:'a'.repeat(64),walkthrough_result:'passed'}];
|
|
21
|
+
fs.writeFileSync(path.join(root,'运行日志.jsonl'),events.map(e=>JSON.stringify(e)).join('\n')+'\n');
|
|
22
|
+
const initial='User notes stay.\n\n| 任务 | Feature | 开始 | 结束 | 审查轮次 | 独立审查拦截 | QA | 人工介入(次:原因) |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n';
|
|
23
|
+
const metrics=path.join(root,'METRICS.md'),source=path.join(root,'reviewed-source'),gate=path.join(root,'reviewed-n5');
|
|
24
|
+
fs.writeFileSync(metrics,initial);fs.writeFileSync(source,'reviewed');fs.writeFileSync(gate,'approved');
|
|
25
|
+
const guard=()=>{assert.equal(fs.readFileSync(source,'utf8'),'reviewed');assert.equal(fs.readFileSync(gate,'utf8'),'approved');};
|
|
26
|
+
return {root,options:{specsRoot:root,identity,dossierFile},initial,metrics,source,gate,guard};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('cooperative metrics yields before every fresh owner check; sync API returns the same evidence',async t=>{
|
|
30
|
+
const f=fixture(t);let pulses=0,checks=0;
|
|
31
|
+
setImmediate(()=>{pulses++;});
|
|
32
|
+
const written=await runStepsCooperatively(appendFixMetricsSteps(f.options,{assertOwned(){
|
|
33
|
+
f.guard();checks++;assert.equal(pulses,checks,'each guard observes separately scheduled event-loop work');setImmediate(()=>{pulses++;});
|
|
34
|
+
}}));
|
|
35
|
+
assert.equal(checks,3);assert.equal(written.deduplicated,false);const bytes=fs.readFileSync(f.metrics);
|
|
36
|
+
const sync=appendFixMetrics(f.options,{assertOwned:f.guard});assert.equal(sync.deduplicated,true);assert.equal(sync.line,written.line);assert.deepEqual(fs.readFileSync(f.metrics),bytes);
|
|
37
|
+
const cooperative=await runStepsCooperatively(appendFixMetricsSteps(f.options,{assertOwned:f.guard}));assert.deepEqual(cooperative,sync);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('a source or N5 change during a metrics checkpoint is rejected before append',async t=>{
|
|
41
|
+
for(const field of ['source','gate']){
|
|
42
|
+
const f=fixture(t),steps=appendFixMetricsSteps(f.options,{assertOwned:f.guard});
|
|
43
|
+
assert.equal(steps.next().done,false);assert.equal(steps.next().done,false);
|
|
44
|
+
fs.writeFileSync(f[field],'changed between checkpoints');assert.throws(()=>steps.next());
|
|
45
|
+
assert.equal(fs.readFileSync(f.metrics,'utf8'),f.initial);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('metrics changes across a checkpoint are rejected, including same-size changes and dedupe',t=>{
|
|
50
|
+
for(const mode of ['append','same-size','dedupe','after-write']){
|
|
51
|
+
const f=fixture(t);if(mode==='dedupe')appendFixMetrics(f.options,{assertOwned:f.guard});
|
|
52
|
+
const steps=appendFixMetricsSteps(f.options,{assertOwned:f.guard});steps.next();steps.next();
|
|
53
|
+
if(mode==='after-write')steps.next();
|
|
54
|
+
const before=fs.readFileSync(f.metrics,'utf8'),changed=mode==='append'?before+'user edit\n':before.replace('User notes stay.','User notes edit.');
|
|
55
|
+
fs.writeFileSync(f.metrics,changed);
|
|
56
|
+
assert.throws(()=>steps.next(),{code:'metrics_file_changed'});assert.equal(fs.readFileSync(f.metrics,'utf8'),changed);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('synchronous and cooperative runners reject Promise owner guards and close abandoned generators',async t=>{
|
|
61
|
+
const f=fixture(t);
|
|
62
|
+
assert.throws(()=>appendFixMetrics(f.options,{async assertOwned(){}}),{code:'metrics_owner_required'});
|
|
63
|
+
await assert.rejects(runStepsCooperatively(appendFixMetricsSteps(f.options,{async assertOwned(){}})),{code:'metrics_owner_required'});
|
|
64
|
+
assert.equal(fs.readFileSync(f.metrics,'utf8'),f.initial);
|
|
65
|
+
for(const run of [runStepsSync,runStepsCooperatively]){
|
|
66
|
+
let finalized=false;function* fail(){try{yield;throw Error('fixture failure');}finally{finalized=true;}}
|
|
67
|
+
if(run===runStepsSync)assert.throws(()=>run(fail()),/fixture failure/);else await assert.rejects(run(fail()),/fixture failure/);
|
|
68
|
+
assert.equal(finalized,true);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('host finish selects cooperative execution while retaining the original finish authority',async()=>{
|
|
73
|
+
for(const authorized of [false,true]){
|
|
74
|
+
let calls=0;const host=createFixHost({config:{},permissions:authorized?['--allow-finish']:[],owner:{finish(options){calls++;assert.deepEqual(options,{authorized,cooperative:true});return {stage:'closeout_required'};}}});
|
|
75
|
+
assert.equal((await host.handle({requestId:'finish',operation:'finish'})).stage,'closeout_required');assert.equal(calls,1);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('real finish generator yields before its first guard and still rejects asynchronous ownership',async t=>{
|
|
80
|
+
const f=fixture(t),status={stage:'closeout_required',completionEligible:false,handoffEvidenceCoverage:'defect_and_learning',walkthrough:{status:'passed'},diagnosis:{crossLayer:false,investigation:{}},retrospective:{content:{candidates:[]}}};
|
|
81
|
+
const options={...f.options,configuration:{reproduction:{cwd:f.root}},status,registeredAt:1};let checks=0;
|
|
82
|
+
const steps=finishFixSteps(options,{assertOwned(){checks++;}});
|
|
83
|
+
assert.equal(steps.next().done,false);assert.equal(checks,0);steps.return();
|
|
84
|
+
assert.throws(()=>runStepsSync(finishFixSteps(options,{async assertOwned(){}})),{code:'fix_owner_required'});
|
|
85
|
+
await assert.rejects(runStepsCooperatively(finishFixSteps(options,{async assertOwned(){}})),{code:'fix_owner_required'});
|
|
86
|
+
assert.equal(fs.readFileSync(f.metrics,'utf8'),f.initial);
|
|
87
|
+
});
|
|
@@ -0,0 +1,217 @@
|
|
|
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 {Readable,Writable} from 'node:stream';
|
|
7
|
+
import {spawnSync} from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import * as execution from '../runtime/js/cm-fix/execution.mjs';
|
|
10
|
+
import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
|
|
11
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
12
|
+
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
13
|
+
import {digest,need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
|
+
import {readFixCausePackage} from '../runtime/js/cm-fix/cause-package.mjs';
|
|
15
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
16
|
+
|
|
17
|
+
const MARK='CM_DIAGNOSIS_MODULE_CORRECTION',OP='prepare_diagnosis_module_correction',FLAG='--allow-diagnosis-module-correction';
|
|
18
|
+
const isolated=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-diagnosis-module-test-home-'))),priorEnvironment={};
|
|
19
|
+
for(const key of ['HOME','CLAUDE_HOME','CODEX_HOME','CM_WORKFLOW_HOME','CM_WORKFLOW_LOG_HOME']){priorEnvironment[key]=process.env[key];process.env[key]=path.join(isolated,key);fs.mkdirSync(process.env[key]);}
|
|
20
|
+
after(()=>{for(const [key,value]of Object.entries(priorEnvironment))if(value===undefined)delete process.env[key];else process.env[key]=value;fs.rmSync(isolated,{recursive:true,force:true});});
|
|
21
|
+
const DRIVER=fileURLToPath(new URL('./cm-fix-drive.mjs',import.meta.url)),HOST=fileURLToPath(new URL('./cm-fix-host.mjs',import.meta.url));
|
|
22
|
+
const denied=/^(?:fix_diagnosis_module_correction_(?:unavailable|stale|binding|confirmation|authorization_required|drift)|fix_busy|unsupported_file)$/;
|
|
23
|
+
function api(owner){assert.equal(typeof execution.inspectFixDiagnosisModuleCorrection,'function',MARK+': missing read-only API');assert.equal(typeof owner.inspectDiagnosisModuleCorrection,'function',MARK+': missing owner preview');assert.equal(typeof owner.prepareDiagnosisModuleCorrection,'function',MARK+': missing owner prepare');}
|
|
24
|
+
const bytes=p=>fs.readFileSync(p),parsed=p=>JSON.parse(bytes(p));
|
|
25
|
+
function output(){let value='';return {stream:new Writable({write(c,e,cb){value+=c;cb();}}),get value(){return value;}};}
|
|
26
|
+
async function fixture(t,{aligned=false,outside=false,waitingDiagnosis=false,lifecycle=false}={}){
|
|
27
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-diagnosis-module-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
|
|
28
|
+
fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);fs.mkdirSync(path.join(cwd,'one'));fs.mkdirSync(path.join(cwd,'two'));
|
|
29
|
+
fs.writeFileSync(path.join(cwd,'one/value.mjs'),'export const value=1;');
|
|
30
|
+
fs.writeFileSync(path.join(cwd,'test.mjs'),"import {value} from './one/value.mjs';if(value!==2){console.error('OWNED MODULE BUG');process.exit(1)}");
|
|
31
|
+
const saved={},home=path.join(root,'home');fs.mkdirSync(home);
|
|
32
|
+
for(const k of ['HOME','CLAUDE_HOME','CODEX_HOME','CM_WORKFLOW_HOME','CM_WORKFLOW_LOG_HOME']){saved[k]=process.env[k];process.env[k]=path.join(home,k);fs.mkdirSync(process.env[k],{recursive:true});}
|
|
33
|
+
const review={model:'synthetic',disabledSkills:[],preflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd,model:'synthetic',disabledSkills:[],promptTransport:'stdin'})}};
|
|
34
|
+
let workerCalls=0,started=null,releaseWorker=null,releaseDiagnosis=null;
|
|
35
|
+
const host=createFixReviewHost({codeProject:cwd,hostContextId:'owned-host',review,permissions:['--allow-cause-review'],workerFactory:()=>async(input,{onEvent,signal})=>{
|
|
36
|
+
workerCalls++;onEvent({event:'thread.started',provider_thread:'owned-started-thread'});started=true;
|
|
37
|
+
if(lifecycle){const data=JSON.parse(input.prompt.split('<cm-review-data-json>\n')[1]);for(const event of [{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
38
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:['one/value.mjs'],findings:[],summary:'Owned synthetic reviewer; no provider'}};}
|
|
39
|
+
return new Promise(resolve=>{releaseWorker=()=>resolve({status:'failed',code:'owned_stopped'});signal.addEventListener('abort',releaseWorker,{once:true});});
|
|
40
|
+
}});
|
|
41
|
+
const diagnosis={status:'diagnosed',rootCause:'The owned constant is wrong',affectedPaths:['one/value.mjs'],plan:'Set the owned constant to two',crossLayer:true,
|
|
42
|
+
affectedModules:outside?['one','foreign']:aligned?['one','two']:['one'],investigation:{discardedAlternatives:[],boundaryAnalysis:null}};
|
|
43
|
+
const configuration={hostContextId:'owned-host',defect:'Owned wrong value',causeReview:host.reviewer,
|
|
44
|
+
reproduction:{cwd,command:[process.execPath,'test.mjs'],expectedFailure:{exitCode:1,outputIncludes:'OWNED MODULE BUG'},timeoutMs:5000},
|
|
45
|
+
redTest:{cwd,command:[process.execPath,lifecycle?'regression.test.mjs':'test.mjs'],testFiles:[lifecycle?'regression.test.mjs':'test.mjs'],expectedFailure:{exitCode:1,outputIncludes:'OWNED MODULE BUG'},timeoutMs:5000},
|
|
46
|
+
...(lifecycle?{testAuthor:{requirements:['one/value.mjs']}}:{}),
|
|
47
|
+
baseline:{cwd,testFiles:['test.mjs'],commands:[{id:'existing',command:[process.execPath,'--check','test.mjs']}],timeoutMs:5000},
|
|
48
|
+
repair:{scope:['one/value.mjs'],requirements:['one/value.mjs']},
|
|
49
|
+
walkthrough:{flows:[{id:'one',modules:['two','one'],kind:'commands',steps:['Read the owned constant'],expected:['The constant is two'],command:[process.execPath,'test.mjs']}],timeoutMs:5000}};
|
|
50
|
+
const identity={repositoryId:'owned-fixture',runId:'diagnosis-module',taskId:'T-FIX-module',attempt:1};
|
|
51
|
+
const capabilities={...host.execution,...(lifecycle?{prepare:async()=>({contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'Owned fixture has no project lessons'}})}:{}),bridge:{async call(kind){
|
|
52
|
+
if(kind==='fix_test_author'){assert(lifecycle);fs.writeFileSync(path.join(cwd,'regression.test.mjs'),fs.readFileSync(path.join(cwd,'test.mjs')));return {outcome:'authored'};}
|
|
53
|
+
if(kind==='fix_repair'){assert(lifecycle);fs.writeFileSync(path.join(cwd,'one/value.mjs'),'export const value=2;');return {outcome:'repaired'};}
|
|
54
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
|
|
55
|
+
assert.equal(kind,'fix_diagnose');if(waitingDiagnosis)await new Promise(resolve=>{releaseDiagnosis=resolve;});return diagnosis;
|
|
56
|
+
}}};
|
|
57
|
+
let owner=execution.openFixExecution({specsRoot,identity,configuration,create:true},capabilities);
|
|
58
|
+
const statePath=path.join(specsRoot,'.reviews/.execution/diagnosis-module/state.json');
|
|
59
|
+
t.after(()=>{owner?.close();for(const [k,v]of Object.entries(saved))if(v===undefined)delete process.env[k];else process.env[k]=v;fs.rmSync(root,{recursive:true,force:true});});
|
|
60
|
+
const advancement=owner.advance({authorized:true});
|
|
61
|
+
if(!waitingDiagnosis){await advancement;assert.equal(owner.status().stage,aligned?'cause_review_required':'walkthrough_configuration_mismatch');}
|
|
62
|
+
else{for(let i=0;i<100&&!releaseDiagnosis;i++)await new Promise(resolve=>setTimeout(resolve,5));assert(releaseDiagnosis);}
|
|
63
|
+
return {root,cwd,specsRoot,identity,configuration,diagnosis,review,statePath,host,advancement,get owner(){return owner;},get workerCalls(){return workerCalls;},get started(){return started;},releaseDiagnosis:()=>releaseDiagnosis?.(),close(){owner.close();},reopen(options={},extra={}){owner.close();owner=execution.openFixExecution({specsRoot,identity,configuration,create:false,...options},{...capabilities,...extra});return owner;}};
|
|
64
|
+
}
|
|
65
|
+
const request=(expected,extra={})=>({authorized:true,expected,previousInvocationStopped:true,reason:'Explicitly align only the frozen walkthrough modules',...extra});
|
|
66
|
+
const refused=(fn,code)=>assert.throws(fn,error=>code?error.code===code:denied.test(error.code));
|
|
67
|
+
|
|
68
|
+
test('diagnosis module correction: real mismatch gains exactly the frozen union and preserves original diagnosis, records and replay',async t=>{
|
|
69
|
+
const f=await fixture(t),before=parsed(f.statePath),old=bytes(f.statePath);api(f.owner);
|
|
70
|
+
const expected=f.owner.inspectDiagnosisModuleCorrection();assert.deepEqual(bytes(f.statePath),old);
|
|
71
|
+
f.close();const publicTarget=execution.inspectFixDiagnosisModuleCorrection({specsRoot:f.specsRoot,identity:{repositoryId:f.identity.repositoryId,runId:f.identity.runId}});
|
|
72
|
+
assert.deepEqual(publicTarget,expected);assert.deepEqual(bytes(f.statePath),old);f.reopen();
|
|
73
|
+
assert.deepEqual(expected.originalModules,['one']);assert.deepEqual(expected.modules,['one','two']);
|
|
74
|
+
assert.equal(expected.configurationDigest,digest(before.records[0].payload.configuration));assert.equal(expected.historyDigest,digest(before.records));assert.equal(expected.diagnosisDigest,digest(f.diagnosis));
|
|
75
|
+
assert.deepEqual(expected.files.map(x=>x.path),['one/value.mjs']);assert.equal(expected.snapshotDigest,digest(expected.files));
|
|
76
|
+
const input=request(expected),receipt=f.owner.prepareDiagnosisModuleCorrection(input),after=parsed(f.statePath),status=f.owner.status();
|
|
77
|
+
assert.equal(after.records.length,before.records.length+1);assert.deepEqual(after.records.slice(0,before.records.length),before.records);assert.deepEqual(after.fingerprints,before.fingerprints);
|
|
78
|
+
assert.equal(after.records.at(-1).id,'fix-diagnosis-module-corrected');assert.equal(after.records.at(-1).kind,'result');
|
|
79
|
+
assert.deepEqual(status.originalDiagnosis,f.diagnosis);assert.deepEqual(status.diagnosis,{...f.diagnosis,affectedModules:['one','two']});assert.equal(status.stage,'cause_review_required');
|
|
80
|
+
assert.equal(receipt.correctionDigest,digest({target:expected,reason:input.reason,previousInvocationStopped:true}));
|
|
81
|
+
const prepared=bytes(f.statePath);assert.deepEqual(f.owner.prepareDiagnosisModuleCorrection(input),receipt);assert.deepEqual(bytes(f.statePath),prepared);
|
|
82
|
+
f.reopen();assert.deepEqual(f.owner.status().diagnosis,status.diagnosis);assert.deepEqual(f.owner.prepareDiagnosisModuleCorrection(input),receipt);assert.deepEqual(bytes(f.statePath),prepared);
|
|
83
|
+
const pkg=f.owner.causeReviewPackage();assert.deepEqual(pkg.diagnosis,status.diagnosis);assert.deepEqual(pkg.diagnosisModuleCorrection.originalDiagnosis,f.diagnosis);
|
|
84
|
+
assert.equal(pkg.diagnosisModuleCorrection.correctionDigest,receipt.correctionDigest);assert.deepEqual(readFixCausePackage(pkg),pkg);
|
|
85
|
+
const forged={...pkg,diagnosis:{...pkg.diagnosis,plan:'Forged replacement plan'}};const {packageDigest,...body}=forged;forged.packageDigest=digest(body);assert.throws(()=>readFixCausePackage(forged));
|
|
86
|
+
assert.equal(f.workerCalls,0);assert.deepEqual(bytes(f.statePath),prepared);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('diagnosis module correction: authority, stopped confirmation, exact target and reason are mandatory before append',async t=>{
|
|
90
|
+
const f=await fixture(t);api(f.owner);const expected=f.owner.inspectDiagnosisModuleCorrection(),before=bytes(f.statePath);
|
|
91
|
+
for(const extra of [{authorized:false},{previousInvocationStopped:false},{reason:''},{reason:'not\na single line'},{expected:{...expected,modules:['one','two','foreign']}},{expected:{...expected,originalModules:['foreign']}},{expected:{...expected,historyDigest:'0'.repeat(64)}}]){
|
|
92
|
+
refused(()=>f.owner.prepareDiagnosisModuleCorrection(request(expected,extra)));assert.deepEqual(bytes(f.statePath),before);
|
|
93
|
+
}
|
|
94
|
+
const input=request(expected),receipt=f.owner.prepareDiagnosisModuleCorrection(input),prepared=bytes(f.statePath);
|
|
95
|
+
refused(()=>f.owner.prepareDiagnosisModuleCorrection({...input,reason:'A different authorization'}));refused(()=>f.owner.prepareDiagnosisModuleCorrection({...input,expected:{...expected,modules:['two']}}));
|
|
96
|
+
assert.deepEqual(bytes(f.statePath),prepared);assert.equal(f.workerCalls,0);assert(receipt.correctionDigest);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('diagnosis module correction: omission-only refuses aligned and outside-module owner declarations and strict schema deletion',async t=>{
|
|
100
|
+
for(const mode of ['aligned','outside']){
|
|
101
|
+
const f=await fixture(t,{[mode]:true});api(f.owner);const before=bytes(f.statePath);
|
|
102
|
+
refused(()=>f.owner.inspectDiagnosisModuleCorrection());refused(()=>f.owner.prepareDiagnosisModuleCorrection(request({})));assert.deepEqual(bytes(f.statePath),before);assert.equal(f.workerCalls,0);f.close();
|
|
103
|
+
}
|
|
104
|
+
const f=await fixture(t);api(f.owner);const expected=f.owner.inspectDiagnosisModuleCorrection();f.owner.prepareDiagnosisModuleCorrection(request(expected));
|
|
105
|
+
const pkg=f.owner.causeReviewPackage(),relation=structuredClone(pkg.diagnosisModuleCorrection);
|
|
106
|
+
relation.originalDiagnosis.affectedModules=['one','foreign'];relation.target.originalModules=['one','foreign'];relation.target.diagnosisDigest=digest(relation.originalDiagnosis);
|
|
107
|
+
relation.correctionDigest=digest({target:relation.target,reason:relation.reason,previousInvocationStopped:relation.previousInvocationStopped});
|
|
108
|
+
const {packageDigest,...body}=pkg,forged={...body,diagnosisModuleCorrection:relation};forged.packageDigest=digest(forged);
|
|
109
|
+
assert.throws(()=>readFixCausePackage(forged),undefined,'A matching self-digest cannot authorize removing an originally declared outside module');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('diagnosis module correction: live source bytes, mode and configuration target drift refuse without rewriting history',async t=>{
|
|
113
|
+
const f=await fixture(t);api(f.owner);const expected=f.owner.inspectDiagnosisModuleCorrection(),before=bytes(f.statePath),file=path.join(f.cwd,'one/value.mjs'),old=bytes(file),mode=fs.statSync(file).mode&511;
|
|
114
|
+
for(const change of ['bytes','mode','symlink']){
|
|
115
|
+
if(change==='bytes')fs.appendFileSync(file,'\n// drift');else if(change==='mode')fs.chmodSync(file,mode^64);else{fs.renameSync(file,file+'.owned');fs.symlinkSync(file+'.owned',file);}
|
|
116
|
+
refused(()=>f.owner.prepareDiagnosisModuleCorrection(request(expected)));assert.deepEqual(bytes(f.statePath),before);
|
|
117
|
+
if(change==='symlink'){fs.unlinkSync(file);fs.renameSync(file+'.owned',file);}else{fs.writeFileSync(file,old);fs.chmodSync(file,mode);}
|
|
118
|
+
}
|
|
119
|
+
refused(()=>f.owner.prepareDiagnosisModuleCorrection(request({...expected,configurationDigest:'0'.repeat(64)})));assert.deepEqual(bytes(f.statePath),before);
|
|
120
|
+
const input=request(expected);f.owner.prepareDiagnosisModuleCorrection(input);const prepared=bytes(f.statePath);fs.appendFileSync(file,'\n// after correction drift');
|
|
121
|
+
refused(()=>f.owner.prepareDiagnosisModuleCorrection(input));assert.deepEqual(bytes(f.statePath),prepared);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('diagnosis module correction: pending diagnosis and started review cannot authorize a correction or repeat it late',async t=>{
|
|
125
|
+
const pending=await fixture(t,{waitingDiagnosis:true});
|
|
126
|
+
try{api(pending.owner);const old=bytes(pending.statePath);refused(()=>pending.owner.inspectDiagnosisModuleCorrection());assert.deepEqual(bytes(pending.statePath),old);}
|
|
127
|
+
finally{pending.releaseDiagnosis();await pending.advancement;pending.close();}
|
|
128
|
+
const f=await fixture(t);api(f.owner);const expected=f.owner.inspectDiagnosisModuleCorrection(),input=request(expected);f.owner.prepareDiagnosisModuleCorrection(input);
|
|
129
|
+
const pkg=f.owner.causeReviewPackage();await f.host.authority.hostDecisionProvider.decide({identity:f.identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
130
|
+
const reviewing=f.owner.reviewCause();for(let i=0;i<100&&!f.started;i++)await new Promise(resolve=>setTimeout(resolve,5));assert.equal(f.started,true);const started=bytes(f.statePath);
|
|
131
|
+
refused(()=>f.owner.inspectDiagnosisModuleCorrection());refused(()=>f.owner.prepareDiagnosisModuleCorrection(input));assert.deepEqual(bytes(f.statePath),started);assert.equal(f.workerCalls,1);
|
|
132
|
+
f.owner.cancel();await reviewing;const stopped=bytes(f.statePath);refused(()=>f.owner.prepareDiagnosisModuleCorrection(input));assert.deepEqual(bytes(f.statePath),stopped);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('diagnosis module correction: actual stdio parser routes only the authorized existing host operation',async()=>{
|
|
136
|
+
for(const allowed of [false,true]){
|
|
137
|
+
let calls=0;const expected={owned:'sentinel'},owner={prepareDiagnosisModuleCorrection(input){calls++;need(input.authorized===true,'fix_diagnosis_module_correction_authorization_required');assert.deepEqual(input,{authorized:true,expected,previousInvocationStopped:true,reason:'Owned authority'});return {sentinel:'routed'};}};
|
|
138
|
+
const host=createFixHost({owner,config:{},permissions:allowed?[FLAG]:[]}),out=output(),err=output();
|
|
139
|
+
await serveCmAiHost({host,input:Readable.from([JSON.stringify({requestId:'route',operation:OP,expected,previousInvocationStopped:true,reason:'Owned authority'})+'\n']),output:out.stream,errorOutput:err.stream});
|
|
140
|
+
const reply=out.value.trim().split('\n').map(JSON.parse).find(x=>x.requestId==='route');
|
|
141
|
+
assert(reply,MARK+': stdio rejected the registered correction operation before routing');assert.equal(calls,1);
|
|
142
|
+
if(allowed)assert.deepEqual(reply.result,{sentinel:'routed'});else{assert(reply.error);assert.match(err.value,/fix_diagnosis_module_correction_authorization_required/);}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('diagnosis module correction: actual CLI startup, driver and resumed owner preserve permissions and old prefix',async t=>{
|
|
147
|
+
const f=await fixture(t);api(f.owner);const expected=f.owner.inspectDiagnosisModuleCorrection(),before=bytes(f.statePath),beforeState=parsed(f.statePath);f.close();
|
|
148
|
+
const config=path.join(f.root,'config.json'),review=path.join(f.root,'review.json'),plan=path.join(f.root,'plan.json');const {hostContextId,causeReview,...stored}=f.configuration;
|
|
149
|
+
fs.writeFileSync(config,JSON.stringify({...stored,specsRoot:f.specsRoot,identity:f.identity}));fs.writeFileSync(review,JSON.stringify(f.review));
|
|
150
|
+
const cli=args=>spawnSync(process.execPath,args,{encoding:'utf8',timeout:15000,env:{...process.env,CM_NOTIFY_DISABLED:'1'}});
|
|
151
|
+
const base={config,cwd:f.cwd,mode:'resume',hostContext:hostContextId,runtime:'codex',reviewConfig:review,expected,previousInvocationStopped:true,reason:'Owned CLI module correction'};
|
|
152
|
+
const drive=(permissions,extra={})=>{fs.writeFileSync(plan,JSON.stringify({...base,permissions,...extra}));return cli([DRIVER,'--plan',plan,OP]);};
|
|
153
|
+
for(const [permissions,extra]of [[[],{}],[[FLAG],{mode:'create'}],[[FLAG],{previousInvocationStopped:false}]]){const r=drive(permissions,extra);assert.notEqual(r.status,0);assert.deepEqual(bytes(f.statePath),before);}
|
|
154
|
+
const direct=cli([HOST,'serve','--config',config,'--mode','create','--host-context',hostContextId,'--allow-reproduction',FLAG,'--review-config',review]);assert.notEqual(direct.status,0);assert.deepEqual(bytes(f.statePath),before);
|
|
155
|
+
const prepared=drive([FLAG]);assert.equal(prepared.status,0,MARK+': actual driver/host did not prepare correction: '+prepared.stdout+prepared.stderr);
|
|
156
|
+
const after=parsed(f.statePath);assert.equal(after.records.length,beforeState.records.length+1);assert.deepEqual(after.records.slice(0,beforeState.records.length),beforeState.records);assert.deepEqual(after.fingerprints,beforeState.fingerprints);
|
|
157
|
+
const raw=bytes(f.statePath),again=drive([FLAG]);assert.equal(again.status,0,again.stdout+again.stderr);assert.deepEqual(bytes(f.statePath),raw);
|
|
158
|
+
const reopened=f.reopen();assert.equal(reopened.status().stage,'cause_review_required');assert.deepEqual(reopened.status().diagnosis.plan,f.diagnosis.plan);assert.equal(f.workerCalls,0);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('diagnosis module correction: real owner retains relation through cause, author, repair, handoff and final package replay',async t=>{
|
|
162
|
+
const f=await fixture(t,{lifecycle:true});api(f.owner);const before=parsed(f.statePath),expected=f.owner.inspectDiagnosisModuleCorrection(),input=request(expected),receipt=f.owner.prepareDiagnosisModuleCorrection(input);
|
|
163
|
+
const cause=f.owner.causeReviewPackage(),relation=cause.diagnosisModuleCorrection;
|
|
164
|
+
await f.host.authority.hostDecisionProvider.decide({identity:f.identity,packageDigest:cause.packageDigest},new AbortController().signal);
|
|
165
|
+
await f.owner.reviewCause();assert.equal(f.workerCalls,1);assert.equal(f.owner.status().causeReview.review.verdict,'approved');
|
|
166
|
+
assert.equal(f.owner.status().stage,'test_author_required');assert.equal((await f.owner.authorTests({authorized:true})).stage,'red_test_required');
|
|
167
|
+
assert.equal((await f.owner.runRedTest({authorized:true})).stage,'baseline_required');assert.equal((await f.owner.captureBaseline({authorized:true})).stage,'repair_required');
|
|
168
|
+
assert.equal((await f.owner.repair({authorized:true})).stage,'regression_required');assert.equal((await f.owner.runRegression({authorized:true})).stage,'handoff_required');
|
|
169
|
+
assert.equal((await f.owner.retrospect()).stage,'handoff_ready');assert.equal(f.owner.createHandoff().stage,'final_review_required');
|
|
170
|
+
const pkg=f.owner.finalReviewPackage(),evidence=pkg.checks[0].evidence;
|
|
171
|
+
assert.equal(typeof evidence,'string');assert(evidence.includes(JSON.stringify(relation)),'Final package must carry the exact structured relation in its existing bounded check evidence');
|
|
172
|
+
assert(evidence.includes(f.diagnosis.plan));assert(evidence.includes(receipt.correctionDigest));assert(pkg.checks.every(c=>c.outcome==='passed'));
|
|
173
|
+
const current=parsed(f.statePath),handoff=current.records.find(r=>r.id==='fix-handoff-intent');assert(handoff.payload.evidence.some(row=>typeof row==='string'&&row.includes(JSON.stringify(relation))));
|
|
174
|
+
assert.deepEqual(current.records.slice(0,before.records.length),before.records);assert.deepEqual(current.fingerprints,before.fingerprints);
|
|
175
|
+
assert.deepEqual(f.owner.status().originalDiagnosis,f.diagnosis);f.reopen();assert.equal(f.owner.status().stage,'final_review_required');assert.deepEqual(f.owner.finalReviewPackage(),pkg);assert.equal(f.workerCalls,1);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('diagnosis module correction: joined host survives failed registration and source drift still blocks the first review',async t=>{
|
|
179
|
+
const f=await fixture(t);api(f.owner);const expected=f.owner.inspectDiagnosisModuleCorrection(),receipt=f.owner.prepareDiagnosisModuleCorrection(request(expected));
|
|
180
|
+
const prepared=parsed(f.statePath),hostContextId='owned-successor-host';let newWorkerCalls=0;
|
|
181
|
+
const successor=createFixReviewHost({codeProject:f.cwd,hostContextId,review:f.review,permissions:['--allow-cause-review'],workerFactory:()=>async()=>{newWorkerCalls++;return {status:'failed',code:'must_not_execute'};}});
|
|
182
|
+
f.reopen({hostContextId},successor.execution);const pkg=f.owner.causeReviewPackage();
|
|
183
|
+
await successor.authority.hostDecisionProvider.decide({identity:f.identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
184
|
+
const rename=fs.renameSync;let failedRegistration=0;
|
|
185
|
+
const fault=t.mock.method(fs,'renameSync',(from,to)=>{
|
|
186
|
+
if(to===f.statePath){const candidate=JSON.parse(fs.readFileSync(from,'utf8'));
|
|
187
|
+
if(candidate.records.at(-1)?.id==='fix-cause-registered'){failedRegistration++;throw Object.assign(new Error('Owned registration disk fault'),{code:'EIO'});}}
|
|
188
|
+
return rename(from,to);
|
|
189
|
+
});
|
|
190
|
+
try{await assert.rejects(()=>f.owner.reviewCause(),{code:'cause_authorization_invalid'});}finally{fault.mock.restore();}
|
|
191
|
+
assert.equal(failedRegistration,1,'The real writer must reach exactly the registered atomic-state rename');
|
|
192
|
+
const joined=parsed(f.statePath);assert.deepEqual(joined.records.slice(0,prepared.records.length),prepared.records);assert.deepEqual(joined.fingerprints,prepared.fingerprints);
|
|
193
|
+
assert.equal(joined.records.length,prepared.records.length+1);assert.equal(joined.records.at(-1).id,'fix-host-joined-1');assert.equal(joined.records.at(-1).payload.hostContextId,hostContextId);
|
|
194
|
+
assert.equal(joined.records.some(row=>row.id==='fix-cause-registered'),false);assert.equal(newWorkerCalls,0);assert.equal(f.workerCalls,0);
|
|
195
|
+
f.reopen({hostContextId},successor.execution);assert.equal(f.owner.status().stage,'cause_review_required');
|
|
196
|
+
fs.appendFileSync(path.join(f.cwd,'one/value.mjs'),'\n// source changed after the interrupted first registration');
|
|
197
|
+
assert.equal(f.owner.status().stage,'diagnosis_module_correction_drift','A host-joined record cannot spend or disable the original source binding');
|
|
198
|
+
const beforeRetry=bytes(f.statePath);f.reopen({hostContextId},successor.execution);assert.equal(f.owner.status().stage,'diagnosis_module_correction_drift');
|
|
199
|
+
const stopped=await f.owner.reviewCause();assert.equal(stopped.stage,'diagnosis_module_correction_drift');assert.deepEqual(bytes(f.statePath),beforeRetry);
|
|
200
|
+
assert.equal(newWorkerCalls,0);assert.equal(parsed(f.statePath).records.some(row=>row.id==='fix-cause-registered'),false);
|
|
201
|
+
assert.equal(f.owner.status().diagnosisModuleCorrection.correctionDigest,receipt.correctionDigest);
|
|
202
|
+
f.close();
|
|
203
|
+
// A real grant can be valid while a trusted host callback changes the source
|
|
204
|
+
// before registration. Candidate replay alone sees the old bound package;
|
|
205
|
+
// the live preappend guard must still reject before persisting or running it.
|
|
206
|
+
const g=await fixture(t);api(g.owner);g.owner.prepareDiagnosisModuleCorrection(request(g.owner.inspectDiagnosisModuleCorrection()));
|
|
207
|
+
const original=g.host.execution.causeReview,originalPkg=g.owner.causeReviewPackage();
|
|
208
|
+
await g.host.authority.hostDecisionProvider.decide({identity:g.identity,packageDigest:originalPkg.packageDigest},new AbortController().signal);
|
|
209
|
+
let authorityChanges=0,callbackWorkerCalls=0;
|
|
210
|
+
g.reopen({}, {causeReview:{...original,authorize(review,control){const grant=original.authorize(review,control);fs.appendFileSync(path.join(g.cwd,'one/value.mjs'),'\n// owned authorize callback drift');authorityChanges++;return grant;},async run(){callbackWorkerCalls++;return {status:'failed',code:'must_not_execute'};}}});
|
|
211
|
+
const beforeAuthority=bytes(g.statePath);let rejected=null;
|
|
212
|
+
try{await g.owner.reviewCause();}catch(error){rejected=error;}
|
|
213
|
+
assert.equal(authorityChanges,1,'The actual authority must issue its grant before the owned drift');
|
|
214
|
+
assert.equal(callbackWorkerCalls,0,'A valid grant does not authorize a source changed before append');assert.deepEqual(bytes(g.statePath),beforeAuthority);
|
|
215
|
+
assert.equal(parsed(g.statePath).records.some(row=>row.id==='fix-cause-registered'),false);assert.equal(g.owner.status().stage,'diagnosis_module_correction_drift');
|
|
216
|
+
if(rejected)assert.equal(rejected.code,'cause_authorization_invalid');
|
|
217
|
+
});
|