@aibyzero/cm-workflow 0.17.1 → 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 +23 -0
- package/CHANGELOG.md +224 -0
- package/README.md +14 -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 +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- 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 +83 -14
- 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 +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +114 -11
- 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 +11 -5
- 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 +1 -1
- 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 +9 -2
- 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 +242 -39
- 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 +11 -5
- 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 +3 -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 +6 -5
- 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 +471 -57
- 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 +14 -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.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- 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 +16 -1
- 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-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 +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-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -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-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 +4 -3
- 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-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -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 +575 -59
- 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 +45 -1
- 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 +1 -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-summary.test.mjs +24 -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 +1 -1
- 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-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/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 +56 -16
- 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,218 @@
|
|
|
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 {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
7
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
8
|
+
import {createFixFinalReview,inspectFixFinalResult,fixFinalReviewConfiguration} from '../runtime/js/cm-fix/final-review.mjs';
|
|
9
|
+
|
|
10
|
+
import {inspectCauseResult} from '../runtime/js/cm-fix/cause-invocation.mjs';
|
|
11
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {bindVerificationDiagnostic,verificationFailure} from '../runtime/js/cm-fix/review-verification-diagnostic.mjs';
|
|
13
|
+
const failedDiagnostic=request=>bindVerificationDiagnostic(verificationFailure({phase:'check',code:'review_verification_check_failed',checkId:'unit',result:{exitCode:1,outcome:'failed',output:'SYNTHETIC_PRIVATE_OUTPUT'}}),{request,configuration:verification,providerThreadId:'actual-review'});
|
|
14
|
+
import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
|
|
15
|
+
import {createHostHandoff} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
16
|
+
|
|
17
|
+
function evidence(request){
|
|
18
|
+
const pkg=request.payload.reviewPackage, file=pkg.files?.[0]??pkg.changes[0].after;
|
|
19
|
+
const files=[{path:'value.mjs',sha256:file.sha256,mode:file.mode}];
|
|
20
|
+
return {version:1,requestDigest:request.requestDigest,packageDigest:request.payload.reviewPackage.packageDigest,profileDigest:digest(verification),providerThreadId:'actual-review',files,snapshotDigest:digest(files),
|
|
21
|
+
checks:[{id:'unit',commandDigest:digest(verification.checks[0].command),exitCode:0,outputSha256:'b'.repeat(64),startedAt:1,endedAt:2}],
|
|
22
|
+
mutations:[{path:'value.mjs',beforeSha256:files[0].sha256,afterSha256:'c'.repeat(64),checkId:'unit',baselineExitCode:0,mutatedExitCode:1,restoredExitCode:0,restoredSha256:files[0].sha256,startedAt:3,endedAt:4}]};
|
|
23
|
+
}
|
|
24
|
+
const verification={files:['value.mjs'],checks:[{id:'unit',command:['node','--test','value.mjs']}],mutationPaths:['value.mjs'],timeoutMs:1000};
|
|
25
|
+
const reviewer={reviewerId:'cause-reviewer',adapterId:'claude-cause-review-adapter',provider:'claude',requestedModel:'synthetic',contextId:'fresh-review',excludedThreadIds:[]};
|
|
26
|
+
|
|
27
|
+
test('final review derivation preserves opt-in verification without changing old configuration',()=>{
|
|
28
|
+
const old={hostContextId:'author',causeReview:reviewer};
|
|
29
|
+
assert.equal(Object.hasOwn(fixFinalReviewConfiguration(old),'reviewVerification'),false);
|
|
30
|
+
assert.deepEqual(fixFinalReviewConfiguration({...old,reviewVerification:verification}).reviewVerification,verification);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
for(const mode of ['legacy','missing','valid','duplicate','tampered','failed','diagnosed','callback-thrown','bad-diagnostic'])test(`cause ${mode} result binds mechanical evidence and resume keeps configuration`,async()=>{
|
|
34
|
+
const enabled=mode!=='legacy';
|
|
35
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-verification-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
|
|
36
|
+
fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
37
|
+
const identity={repositoryId:'fixture',runId:'verify-cause',taskId:'T-FIX-verify',attempt:1};
|
|
38
|
+
const configuration={hostContextId:'author',defect:'Synthetic mismatch',causeReview:reviewer,
|
|
39
|
+
reproduction:{cwd,command:[process.execPath,'-e',"process.stderr.write('BUG');process.exit(3)"],expectedFailure:{exitCode:3,outputIncludes:'BUG'},timeoutMs:1000},
|
|
40
|
+
...(enabled?{reviewVerification:verification}:{})};
|
|
41
|
+
const authority=createHostReviewAuthority({hostContextId:'author',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
42
|
+
let owner,calls=0,lateVerification,readinessCalls=0;
|
|
43
|
+
const causeReview={authorize:authority.authorize,async run(request,{onEvent,onVerification}){
|
|
44
|
+
calls++;
|
|
45
|
+
for(const event of [{event:'thread.started',provider_thread:'actual-review'},{event:'turn.started',item_type:null},
|
|
46
|
+
{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);
|
|
47
|
+
lateVerification=onVerification;
|
|
48
|
+
if(['valid','duplicate','tampered','callback-thrown'].includes(mode)){
|
|
49
|
+
const proof=evidence(request);if(['tampered','callback-thrown'].includes(mode))proof.providerThreadId='wrong-thread';
|
|
50
|
+
if(mode==='callback-thrown')onVerification(proof);
|
|
51
|
+
try{onVerification(proof);if(mode==='duplicate')onVerification(proof);}catch{/* A misbehaving worker swallowing callback failures must not gain success. */}
|
|
52
|
+
}
|
|
53
|
+
if(mode==='failed')return {status:'failed',code:'timeout'};
|
|
54
|
+
if(mode==='bad-diagnostic'){const d=failedDiagnostic(request);d.requestDigest='f'.repeat(64);return {status:'failed',code:'review_verification_evidence',verificationDiagnostic:d};}
|
|
55
|
+
if(mode==='diagnosed')return {status:'failed',code:'review_verification_evidence',verificationDiagnostic:failedDiagnostic(request)};
|
|
56
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:['value.mjs'],findings:[],summary:'Synthetic'}};
|
|
57
|
+
}};
|
|
58
|
+
try{
|
|
59
|
+
owner=openFixExecution({specsRoot,identity,configuration,create:true},{causeReview,assertReviewReady(pkg){readinessCalls++;if(pkg)assert.equal(pkg.kind,'cm-fix-cause-review-package');},bridge:{async call(){return {status:'diagnosed',rootCause:'Constant mismatch',plan:'Correct after red test',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:true};}}});
|
|
60
|
+
await owner.advance({authorized:true});
|
|
61
|
+
await authority.hostDecisionProvider.decide({identity,packageDigest:owner.causeReviewPackage().packageDigest},new AbortController().signal);
|
|
62
|
+
const result=await owner.reviewCause();assert.equal(readinessCalls,enabled?2:1);
|
|
63
|
+
if(['legacy','valid'].includes(mode))assert.equal(result.stage,'red_test_required');else assert.notEqual(result.stage,'red_test_required');
|
|
64
|
+
if(lateVerification)assert.equal(lateVerification({}),false);
|
|
65
|
+
owner.close();owner=null;
|
|
66
|
+
if(mode==='valid'){
|
|
67
|
+
assert.throws(()=>openFixExecution({specsRoot,identity,configuration:{...configuration,reviewVerification:{...verification,timeoutMs:2000}},create:false}),{code:'fingerprint_mismatch'});
|
|
68
|
+
const legacy={...configuration};delete legacy.reviewVerification;
|
|
69
|
+
assert.throws(()=>openFixExecution({specsRoot,identity,configuration:legacy,create:false}),{code:'fingerprint_mismatch'});
|
|
70
|
+
}
|
|
71
|
+
owner=openFixExecution({specsRoot,identity,configuration,create:false},{causeReview});
|
|
72
|
+
assert.equal((await owner.reviewCause()).stage,result.stage);assert.equal(calls,1);
|
|
73
|
+
const rows=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json'))).records;
|
|
74
|
+
assert.equal(Object.hasOwn(rows[0].payload.configuration,'reviewVerification'),enabled);
|
|
75
|
+
if(mode==='valid'){
|
|
76
|
+
const registration=rows.find(r=>r.id==='fix-cause-registered').payload,value=rows.find(r=>r.id==='fix-cause-result').payload;
|
|
77
|
+
assert.deepEqual(value.verification,evidence(registration.request));
|
|
78
|
+
assert.equal(inspectCauseResult(value,registration,configuration,'actual-review').observationStatus,'completed');
|
|
79
|
+
const missing=structuredClone(value);delete missing.verification;
|
|
80
|
+
assert.throws(()=>inspectCauseResult(missing,registration,configuration,'actual-review'));
|
|
81
|
+
const tampered=structuredClone(value);tampered.verification.packageDigest='f'.repeat(64);
|
|
82
|
+
assert.throws(()=>inspectCauseResult(tampered,registration,configuration,'actual-review'),{code:'review_verification_binding'});
|
|
83
|
+
assert.throws(()=>inspectCauseResult(value,registration,{...configuration,reviewVerification:undefined},'actual-review'),{code:'review_verification_invalid'});
|
|
84
|
+
}
|
|
85
|
+
if(['duplicate','tampered','callback-thrown'].includes(mode)){
|
|
86
|
+
const value=rows.find(r=>r.id==='fix-cause-result')?.payload;assert(value,'callback rejection must be durable');
|
|
87
|
+
assert.equal(value.observation.result.status,'failed');assert(!Object.hasOwn(value,'verification'));
|
|
88
|
+
assert.equal(value.verificationDiagnostic.phase,'callback');
|
|
89
|
+
assert.equal(value.verificationDiagnostic.code,mode==='duplicate'?'review_verification_invalid':'review_verification_binding');
|
|
90
|
+
assert.equal(value.verificationDiagnostic.providerThreadId,'actual-review');
|
|
91
|
+
}
|
|
92
|
+
if(mode==='bad-diagnostic'){
|
|
93
|
+
const value=rows.find(r=>r.id==='fix-cause-result')?.payload;assert(value,'invalid optional metadata must not erase a failed observation');
|
|
94
|
+
assert.equal(value.observation.result.status,'failed');assert.equal(value.observation.result.code,'review_verification_evidence');
|
|
95
|
+
assert.equal(value.verificationDiagnostic.code,'review_verification_binding');
|
|
96
|
+
assert.equal(value.verificationDiagnostic.requestDigest,rows.find(r=>r.id==='fix-cause-registered').payload.request.requestDigest);
|
|
97
|
+
}
|
|
98
|
+
if(mode==='diagnosed'){
|
|
99
|
+
const value=rows.find(r=>r.id==='fix-cause-result').payload;
|
|
100
|
+
assert.equal(value.verificationDiagnostic.code,'review_verification_check_failed');
|
|
101
|
+
assert.equal(value.observation.result.code,'review_verification_evidence');
|
|
102
|
+
assert(!Object.hasOwn(value.observation.result,'verificationDiagnostic'));
|
|
103
|
+
const registration=rows.find(r=>r.id==='fix-cause-registered').payload;
|
|
104
|
+
const tampered=structuredClone(value);tampered.verificationDiagnostic.requestDigest='f'.repeat(64);
|
|
105
|
+
assert.throws(()=>inspectCauseResult(tampered,registration,configuration,'actual-review'),{code:'review_verification_binding'});
|
|
106
|
+
}
|
|
107
|
+
if(!enabled)assert.equal(Object.hasOwn(rows.find(r=>r.id==='fix-cause-result').payload,'verification'),false);
|
|
108
|
+
}finally{owner?.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
for(const mode of ['legacy','missing','valid','duplicate','tampered','failed','diagnosed','callback-thrown','bad-diagnostic'])test(`final ${mode} result retains original grant and binds execution evidence`,async()=>{
|
|
112
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-final-verification-'))),cwd=path.join(root,'code');fs.mkdirSync(cwd);
|
|
113
|
+
try{
|
|
114
|
+
const identity={repositoryId:'fixture',runId:'verify-final',taskId:'T-FIX-verify',attempt:1};
|
|
115
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
116
|
+
const baseline=captureReviewBaseline({root:cwd,identity,scope:['value.mjs'],requirements:['value.mjs']});
|
|
117
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=2;');
|
|
118
|
+
const checks=[{id:'unit',command:['synthetic-check'],outcome:'passed',exitCode:0,evidence:'Synthetic only'}];
|
|
119
|
+
const handoffPath=path.join(root,'fix-verify-T-FIX-verify-a1-handoff.json');
|
|
120
|
+
createHostHandoff({root:cwd,baseline,checks,handoffPath,evidence:['learning: no_relevant_lesson','learning: retrospective no_new_lesson']});
|
|
121
|
+
const pkg=createReviewPackage({root:cwd,baseline,checks,handoffPath});
|
|
122
|
+
const configuration=fixFinalReviewConfiguration({hostContextId:'author',causeReview:reviewer,...(mode==='legacy'?{}:{reviewVerification:verification})});
|
|
123
|
+
const authority=createHostReviewAuthority({hostContextId:'author',reviewerId:configuration.reviewer.reviewerId,adapterId:configuration.reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
124
|
+
await authority.hostDecisionProvider.decide({identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
125
|
+
let registration,lateVerification;
|
|
126
|
+
const review=createFixFinalReview({reviewPackage:pkg,configuration,timeoutMs:1000},{authorize:authority.authorize,async run(request,{onEvent,onVerification}){
|
|
127
|
+
for(const event of [{event:'thread.started',provider_thread:'actual-review'},{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
128
|
+
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
129
|
+
lateVerification=onVerification;
|
|
130
|
+
if(['valid','duplicate','tampered','callback-thrown'].includes(mode)){
|
|
131
|
+
const proof=evidence(request);if(['tampered','callback-thrown'].includes(mode))proof.profileDigest='f'.repeat(64);
|
|
132
|
+
if(mode==='callback-thrown')onVerification(proof);
|
|
133
|
+
try{onVerification(proof);if(mode==='duplicate')onVerification(proof);}catch{}
|
|
134
|
+
}
|
|
135
|
+
if(mode==='failed')return {status:'failed',code:'timeout'};
|
|
136
|
+
if(mode==='bad-diagnostic'){const d=failedDiagnostic(request);d.requestDigest='f'.repeat(64);return {status:'failed',code:'review_verification_evidence',verificationDiagnostic:d};}
|
|
137
|
+
if(mode==='diagnosed')return {status:'failed',code:'review_verification_evidence',verificationDiagnostic:failedDiagnostic(request)};
|
|
138
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:pkg.packageDigest,examinedPaths:['value.mjs'],findings:[],summary:'Synthetic only'}};
|
|
139
|
+
}});
|
|
140
|
+
const result=await review({signal:new AbortController().signal,register(value){registration=value;},onStarted(){}});
|
|
141
|
+
if(['duplicate','tampered','callback-thrown'].includes(mode)){
|
|
142
|
+
assert(result.value,'callback rejection must retain its failed observation');
|
|
143
|
+
assert.equal(result.value.observation.result.status,'failed');assert(!Object.hasOwn(result.value,'verification'));
|
|
144
|
+
assert.notEqual(result.inspection.observationStatus,'completed');
|
|
145
|
+
assert.equal(result.value.verificationDiagnostic.phase,'callback');
|
|
146
|
+
assert.equal(result.value.verificationDiagnostic.code,mode==='duplicate'?'review_verification_invalid':'review_verification_binding');
|
|
147
|
+
}
|
|
148
|
+
assert.equal(result.outcome,['valid','legacy','failed','diagnosed','duplicate','tampered','callback-thrown','bad-diagnostic'].includes(mode)?'observed':'unknown');
|
|
149
|
+
if(lateVerification)assert.equal(lateVerification({}),false);
|
|
150
|
+
if(mode==='valid'){
|
|
151
|
+
assert.deepEqual(result.value.verification,evidence(registration.request));
|
|
152
|
+
const missing=structuredClone(result.value);delete missing.verification;
|
|
153
|
+
assert.throws(()=>inspectFixFinalResult(missing,registration,configuration,'actual-review'));
|
|
154
|
+
const changed=structuredClone(result.value);changed.verification.requestDigest='f'.repeat(64);
|
|
155
|
+
assert.throws(()=>inspectFixFinalResult(changed,registration,configuration,'actual-review'),{code:'review_verification_binding'});
|
|
156
|
+
const legacy={...configuration};delete legacy.reviewVerification;
|
|
157
|
+
assert.throws(()=>inspectFixFinalResult(result.value,registration,legacy,'actual-review'),{code:'review_verification_invalid'});
|
|
158
|
+
}
|
|
159
|
+
if(mode==='bad-diagnostic'){
|
|
160
|
+
assert(result.value,'invalid optional metadata must not erase a failed observation');
|
|
161
|
+
assert.equal(result.value.observation.result.status,'failed');assert.notEqual(result.inspection.observationStatus,'completed');
|
|
162
|
+
assert.equal(result.value.verificationDiagnostic.code,'review_verification_binding');
|
|
163
|
+
assert.equal(result.value.verificationDiagnostic.requestDigest,registration.request.requestDigest);
|
|
164
|
+
}
|
|
165
|
+
if(mode==='diagnosed'){
|
|
166
|
+
assert.equal(result.value.verificationDiagnostic.code,'review_verification_check_failed');
|
|
167
|
+
assert(!Object.hasOwn(result.value.observation.result,'verificationDiagnostic'));
|
|
168
|
+
const changed=structuredClone(result.value);changed.verificationDiagnostic.providerThreadId='wrong-thread';
|
|
169
|
+
assert.throws(()=>inspectFixFinalResult(changed,registration,configuration,'actual-review'),{code:'review_verification_binding'});
|
|
170
|
+
}
|
|
171
|
+
if(['legacy','failed'].includes(mode))assert.equal(Object.hasOwn(result.value,'verification'),false);
|
|
172
|
+
if(mode==='failed')assert.notEqual(result.inspection.observationStatus,'completed');
|
|
173
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
for(const phase of ['cause','final'])for(const code of ['review_verification_package_binding','review_verification_source_drift','review_verification_sync_required'])
|
|
177
|
+
test(`${phase} package precheck rejects ${code} before any grant or registration`,async()=>{
|
|
178
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-package-precheck-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
|
|
179
|
+
fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
180
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
181
|
+
fs.writeFileSync(path.join(cwd,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
182
|
+
fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
183
|
+
const identity={repositoryId:'fixture',runId:'package-precheck',taskId:'T-FIX-verify',attempt:1};
|
|
184
|
+
const configuration={hostContextId:'author',defect:'Wrong constant',causeReview:reviewer,reviewVerification:verification,
|
|
185
|
+
reproduction:{cwd,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
186
|
+
redTest:{cwd,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
187
|
+
baseline:{cwd,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
188
|
+
repair:{scope:['value.mjs'],requirements:['value.mjs']}};
|
|
189
|
+
let grants=0,calls=0,owner,packages=0;
|
|
190
|
+
const review={authorize(){grants++;throw Error('must not authorize');},async run(){calls++;throw Error('must not dispatch');}};
|
|
191
|
+
const options={specsRoot,identity,configuration,create:true};
|
|
192
|
+
const runtime={causeReview:review,finalReview:review,assertReviewReady(pkg){if(!pkg)return;packages++;
|
|
193
|
+
assert.equal(pkg.kind,phase==='cause'?'cm-fix-cause-review-package':'cm-review-package');
|
|
194
|
+
if(code==='review_verification_sync_required')return Promise.resolve();
|
|
195
|
+
throw Object.assign(new Error(code),{code});
|
|
196
|
+
},prepare:async()=>({contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No fixture instructions'}}),
|
|
197
|
+
bridge:{async call(kind){
|
|
198
|
+
if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong value',plan:'Correct value',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:phase==='cause',...(phase==='final'?{investigation:{discardedAlternatives:[],boundaryAnalysis:null}}:{})};
|
|
199
|
+
if(kind==='fix_repair'){fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=2;');return {outcome:'repaired'};}
|
|
200
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
|
|
201
|
+
throw Error(kind);
|
|
202
|
+
}}};
|
|
203
|
+
try{
|
|
204
|
+
owner=openFixExecution(options,runtime);await owner.advance({authorized:true});
|
|
205
|
+
if(phase==='final'){
|
|
206
|
+
await owner.runRedTest({authorized:true});await owner.captureBaseline({authorized:true});await owner.repair({authorized:true});await owner.runRegression({authorized:true});await owner.retrospect();owner.createHandoff();
|
|
207
|
+
}
|
|
208
|
+
assert.equal(owner.status().stage,phase==='cause'?'cause_review_required':'final_review_required');
|
|
209
|
+
const statePath=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json'),before=fs.readFileSync(statePath);
|
|
210
|
+
await assert.rejects(phase==='cause'?owner.reviewCause():owner.reviewFinal(),{code});
|
|
211
|
+
assert.equal(grants,0);assert.equal(calls,0);assert.equal(packages,1);
|
|
212
|
+
assert.deepEqual(fs.readFileSync(statePath),before);
|
|
213
|
+
assert.equal(JSON.parse(before).records.filter(r=>r.id.includes(phase)&&r.id.endsWith('-registered')).length,0);
|
|
214
|
+
owner.close();owner=openFixExecution({...options,create:false},runtime);
|
|
215
|
+
await assert.rejects(phase==='cause'?owner.reviewCause():owner.reviewFinal(),{code});
|
|
216
|
+
assert.deepEqual(fs.readFileSync(statePath),before);assert.equal(grants,0);
|
|
217
|
+
}finally{owner?.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
218
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import test from 'node:test';import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';import os from 'node:os';import path from 'node:path';import {spawn,spawnSync} from 'node:child_process';
|
|
3
|
+
import {fileURLToPath} from 'node:url';
|
|
4
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
5
|
+
import {claudeWorker,claudeReviewFingerprint,claudeReviewArgs} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
6
|
+
import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
7
|
+
const verification={files:['value.mjs','value.test.mjs'],checks:[{id:'unit',command:[process.execPath,'value.test.mjs']}],mutationPaths:['value.mjs'],timeoutMs:5000};
|
|
8
|
+
test('isolated Claude args preserve native tool prohibition and bind the exact profile',()=>{
|
|
9
|
+
const base=claudeReviewArgs('synthetic'),args=claudeReviewArgs('synthetic',null,verification,{mcpConfig:'FIXED'});
|
|
10
|
+
assert(base.includes('--safe-mode'));assert(!base.includes('--restricted'));assert.equal(base[base.indexOf('--mcp-config')+1],'{"mcpServers":{}}');
|
|
11
|
+
assert(args.includes('--restricted'));assert(!args.includes('--safe-mode'));assert.equal(args[args.indexOf('--mcp-config')+1],'FIXED');
|
|
12
|
+
assert.equal(args[args.indexOf('--tools')+1],'');assert.equal(args[args.indexOf('--setting-sources')+1],'');
|
|
13
|
+
const options={cwd:'/fixture',model:'synthetic'};
|
|
14
|
+
assert.notEqual(claudeReviewFingerprint(options),claudeReviewFingerprint({...options,verification}));
|
|
15
|
+
assert.notEqual(claudeReviewFingerprint({...options,verification}),claudeReviewFingerprint({...options,verification:{...verification,timeoutMs:6000}}));
|
|
16
|
+
});
|
|
17
|
+
for(const mode of ['valid','missing-mutation','failed-check'])test(`real MCP server and CLI protocol ${mode} preserves mechanical cause evidence across resume`,{skip:process.platform!=='darwin',timeout:30000},async()=>{
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-tools-integration-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
|
|
19
|
+
fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
20
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
21
|
+
fs.writeFileSync(path.join(cwd,'value.test.mjs'),mode==='failed-check'?"process.stderr.write('SYNTHETIC_PRIVATE_OUTPUT_DO_NOT_PERSIST');process.exit(1);":"import {value} from './value.mjs';if(value!==1)process.exit(1);");
|
|
22
|
+
fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'},roles:{coder:{adapter:'codex-cli'},reviewer:{adapter:'claude-cli'}},runtimes:{available:'both'}}));
|
|
23
|
+
const review={model:'synthetic',disabledSkills:[],preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:'synthetic',verification})}};
|
|
24
|
+
let calls=0,owner;
|
|
25
|
+
const fixture=fileURLToPath(new URL('./fixtures/fix-verification-claude.mjs',import.meta.url));
|
|
26
|
+
const host=createFixReviewHost({codeProject:cwd,hostContextId:'author',runtime:'codex',reviewRuntime:'claude',review,verification,permissions:['--allow-cause-review'],workerFactory:options=>claudeWorker({...options,spawnProcess:(_cli,args,opts)=>{calls++;return spawn(process.execPath,[fixture,...args],{...opts,env:{...opts.env,CM_VERIFICATION_FIXTURE_MODE:mode}});}})});
|
|
27
|
+
const identity={repositoryId:'fixture',runId:'tools-integration',taskId:'T-FIX-tools',attempt:1};
|
|
28
|
+
const configuration={hostContextId:'author',reviewRuntime:'claude',causeReview:host.reviewer,reviewVerification:verification,defect:'Fixture missing value guard',reproduction:{cwd,command:[process.execPath,'-e',"console.error('BUG');process.exit(3)"],expectedFailure:{exitCode:3,outputIncludes:'BUG'},timeoutMs:1000}};
|
|
29
|
+
try{
|
|
30
|
+
owner=openFixExecution({specsRoot,identity,configuration,create:true},{...host.execution,bridge:{async call(){return {status:'diagnosed',rootCause:'Synthetic root cause',plan:'Correct within scope after red test',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:true};}}});
|
|
31
|
+
await owner.advance({authorized:true});
|
|
32
|
+
await host.authority.hostDecisionProvider.decide({identity,packageDigest:owner.causeReviewPackage().packageDigest},new AbortController().signal);
|
|
33
|
+
const result=await owner.reviewCause();assert.equal(result.stage,mode==='valid'?'red_test_required':'unknown',JSON.stringify(result));assert.equal(calls,1);
|
|
34
|
+
owner.close();owner=openFixExecution({specsRoot,identity,configuration,create:false},host.execution);
|
|
35
|
+
assert.equal((await owner.reviewCause()).stage,result.stage);assert.equal(calls,1);
|
|
36
|
+
const rows=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews/.execution/tools-integration/state.json'))).records;
|
|
37
|
+
const saved=rows.find(r=>r.id==='fix-cause-result').payload;
|
|
38
|
+
if(mode!=='valid'){
|
|
39
|
+
assert.equal(saved.observation.result.code,'review_verification_evidence');
|
|
40
|
+
assert.equal(saved.verificationDiagnostic.code,mode==='failed-check'?'review_verification_check_failed':'review_verification_mutation_missing');
|
|
41
|
+
assert.equal(saved.verificationDiagnostic.providerThreadId,'synthetic-isolated-review');
|
|
42
|
+
assert(!JSON.stringify(saved.verificationDiagnostic).includes('SYNTHETIC_PRIVATE_OUTPUT'));
|
|
43
|
+
assert(!Object.hasOwn(saved,'verification'));return;
|
|
44
|
+
}
|
|
45
|
+
const proof=saved.verification;
|
|
46
|
+
assert.equal(proof.providerThreadId,'synthetic-isolated-review');assert.equal(proof.checks.length,1);assert.equal(proof.mutations.length,1);
|
|
47
|
+
assert.deepEqual([proof.mutations[0].baselineExitCode,proof.mutations[0].mutatedExitCode,proof.mutations[0].restoredExitCode],[0,1,0]);
|
|
48
|
+
assert.equal(fs.readFileSync(path.join(cwd,'value.mjs'),'utf8'),'export const value=1;');
|
|
49
|
+
}finally{owner?.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('synthetic local preflight checks the actual MCP tool catalog through the same args',{skip:process.platform!=='darwin',timeout:30000},async()=>{
|
|
53
|
+
const {previewClaudeTools}=await import('../runtime/js/cm-ai/claude-tool-preview.mjs');
|
|
54
|
+
const {createReviewVerificationSession}=await import('../runtime/js/cm-fix/review-verification.mjs');
|
|
55
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-tools-preflight-')));
|
|
56
|
+
fs.writeFileSync(path.join(root,'value.mjs'),'export const value=1;');fs.writeFileSync(path.join(root,'value.test.mjs'),'');
|
|
57
|
+
const s=createReviewVerificationSession({codeProject:root,configuration:verification,request:{requestDigest:'a'.repeat(64),payload:{reviewPackage:{packageDigest:'b'.repeat(64),files:[]}}}});
|
|
58
|
+
try{
|
|
59
|
+
const fixture=fileURLToPath(new URL('./fixtures/fix-verification-claude.mjs',import.meta.url));
|
|
60
|
+
const receipt=await previewClaudeTools({cwd:root,model:'synthetic',verification,verificationTransport:s.transport,
|
|
61
|
+
spawnProcess:(command,args,options)=>{assert.equal(command,'/usr/bin/sandbox-exec');return spawn(command,[...args.slice(0,2),process.execPath,fixture,...args.slice(3)],options);}});
|
|
62
|
+
assert.equal(receipt.preflight.passed,true,JSON.stringify(receipt));
|
|
63
|
+
assert(receipt.preflight.request_checks.some(c=>c.tool_names?.includes('mcp__cm_review__mutate_check')));
|
|
64
|
+
assert.equal(receipt.preflight.config_fingerprint,claudeReviewFingerprint({cwd:root,model:'synthetic',verification}));
|
|
65
|
+
}finally{await s.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
test('one snapshot refuses a second MCP server before it can reset evidence',{skip:process.platform!=='darwin',timeout:10000},async()=>{
|
|
70
|
+
const {createReviewVerificationSession}=await import('../runtime/js/cm-fix/review-verification.mjs');
|
|
71
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-tools-single-server-')));
|
|
72
|
+
fs.writeFileSync(path.join(root,'value.mjs'),'export const value=1;');fs.writeFileSync(path.join(root,'value.test.mjs'),'');
|
|
73
|
+
const s=createReviewVerificationSession({codeProject:root,configuration:verification,request:{requestDigest:'a'.repeat(64),payload:{reviewPackage:{packageDigest:'b'.repeat(64),files:[]}}}});
|
|
74
|
+
try{
|
|
75
|
+
const server=fileURLToPath(new URL('../runtime/js/cm-fix/review-verification-server.mjs',import.meta.url));
|
|
76
|
+
const args=[server,s.configPath],options={input:JSON.stringify({jsonrpc:'2.0',id:1,method:'initialize'})+'\n',encoding:'utf8',timeout:3000};
|
|
77
|
+
assert.equal(spawnSync(process.execPath,args,options).status,0);
|
|
78
|
+
const second=spawnSync(process.execPath,args,options);
|
|
79
|
+
assert.equal(second.status,1);assert.match(second.stderr,/review_verification_server_already_started/);assert.equal(second.stdout,'');
|
|
80
|
+
}finally{await s.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
81
|
+
});
|
|
@@ -0,0 +1,198 @@
|
|
|
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 {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
7
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
8
|
+
import {fixFinalReviewConfiguration} from '../runtime/js/cm-fix/final-review.mjs';
|
|
9
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
10
|
+
import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
11
|
+
import {spawnSync} from 'node:child_process';
|
|
12
|
+
import {fileURLToPath} from 'node:url';
|
|
13
|
+
import {createHash} from 'node:crypto';
|
|
14
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
15
|
+
|
|
16
|
+
async function fixture(t,phase='cause',{validVerdict=null}={}){
|
|
17
|
+
if(phase==='revision')validVerdict='changes_requested';
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-bounded-review-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
|
|
19
|
+
fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
20
|
+
fs.writeFileSync(path.join(cwd,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
21
|
+
fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
22
|
+
const verification={files:['value.mjs','red.mjs','existing.mjs'],checks:[{id:'unit',command:[process.execPath,'existing.mjs']}],mutationPaths:['value.mjs'],timeoutMs:2000};
|
|
23
|
+
fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'both'},roles:{coder:{adapter:'codex-cli'},reviewer:{adapter:'claude-cli'}}}));
|
|
24
|
+
const reviewConfig={model:'synthetic',disabledSkills:[],preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:'synthetic',verification})}};
|
|
25
|
+
const reviewer=createFixReviewHost({codeProject:cwd,hostContextId:'author',runtime:'codex',reviewRuntime:'claude',verification,review:reviewConfig}).reviewer;
|
|
26
|
+
const identity={repositoryId:'fixture',runId:'bounded-'+phase,taskId:'T-FIX-bounded',attempt:1};
|
|
27
|
+
const configuration={hostContextId:'author',reviewRuntime:'claude',defect:'Wrong constant',causeReview:reviewer,reviewVerification:verification,
|
|
28
|
+
reproduction:{cwd,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
29
|
+
redTest:{cwd,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
30
|
+
baseline:{cwd,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},repair:{scope:['value.mjs'],requirements:['value.mjs']}};
|
|
31
|
+
const authority=createHostReviewAuthority({hostContextId:'author',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
32
|
+
const finalConfig=fixFinalReviewConfiguration(configuration),finalAuthority=createHostReviewAuthority({hostContextId:'author',reviewerId:finalConfig.reviewer.reviewerId,adapterId:finalConfig.reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
33
|
+
let calls=0,owner,threadOverride=null,proofAuxiliaryChanged=false;const review=auth=>({authorize:auth.authorize,async run(request,{onEvent,onVerification}){calls++;for(const e of [{event:'thread.started',provider_thread:threadOverride??'thread-'+calls},{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(e);if(validVerdict){const files=verification.files.map(p=>({path:p,sha256:createHash('sha256').update(fs.readFileSync(path.join(cwd,p))).digest('hex'),mode:fs.statSync(path.join(cwd,p)).mode&511}));if(proofAuxiliaryChanged)files.find(f=>f.path==='existing.mjs').sha256='d'.repeat(64);onVerification({version:1,requestDigest:request.requestDigest,packageDigest:request.payload.reviewPackage.packageDigest,profileDigest:digest(verification),providerThreadId:'thread-'+calls,files,snapshotDigest:digest(files),checks:[{id:'unit',commandDigest:digest(verification.checks[0].command),exitCode:0,outputSha256:'b'.repeat(64),startedAt:1,endedAt:2}],mutations:[{path:'value.mjs',beforeSha256:files[0].sha256,afterSha256:'c'.repeat(64),checkId:'unit',baselineExitCode:0,mutatedExitCode:1,restoredExitCode:0,restoredSha256:files[0].sha256,startedAt:3,endedAt:4}]});return {status:'succeeded',value:{verdict:validVerdict,packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:['value.mjs'],findings:validVerdict==='changes_requested'?[{id:'F1',severity:'P2',path:'value.mjs',message:'Synthetic valid rejection',evidence:'Fixture'}]:[],summary:'Synthetic conclusion'}};}return {status:'failed',code:'review_verification_evidence'};}});
|
|
34
|
+
const runtime={causeReview:review(authority),finalReview:review(finalAuthority),assertReviewReady(){},prepare:async()=>({contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No fixture instructions'}}),bridge:{async call(kind){
|
|
35
|
+
if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong value',plan:'Correct value',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:phase==='cause',...(phase!=='cause'?{investigation:{discardedAlternatives:[],boundaryAnalysis:null}}:{})};
|
|
36
|
+
if(kind==='fix_repair'){fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=2;'+(owner.status().revision?'\n// revision':''));return {outcome:'repaired'};}
|
|
37
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};throw Error(kind);
|
|
38
|
+
}}};
|
|
39
|
+
const options={specsRoot,identity,configuration,create:true};owner=openFixExecution(options,runtime);
|
|
40
|
+
t.after(()=>{owner?.close();fs.rmSync(root,{recursive:true,force:true});});
|
|
41
|
+
await owner.advance({authorized:true});
|
|
42
|
+
if(phase!=='cause'){await owner.runRedTest({authorized:true});await owner.captureBaseline({authorized:true});await owner.repair({authorized:true});await owner.runRegression({authorized:true});await owner.retrospect();owner.createHandoff();}
|
|
43
|
+
const reviewNow=async token=>{const pkg=phase==='cause'?owner.causeReviewPackage():owner.finalReviewPackage();await (phase==='cause'?authority:finalAuthority).hostDecisionProvider.decide({identity:pkg.identity,packageDigest:pkg.packageDigest},new AbortController().signal);return phase==='cause'?owner.reviewCause({verificationRecoveryAuthorization:token}):owner.reviewFinal({verificationRecoveryAuthorization:token});};
|
|
44
|
+
await reviewNow();
|
|
45
|
+
if(phase==='revision'){owner.publishReview();await owner.prepareRevision({authorized:true});await owner.repair({authorized:true});await owner.runRegression({authorized:true});await owner.retrospect();owner.createHandoff();validVerdict=null;await reviewNow();}
|
|
46
|
+
if((phase==='cause'||phase==='revision')&&!validVerdict)for(let i=0;i<2;i++){owner.abandonReview({authorized:true,reason:'Failed verification worker closed'});await reviewNow();}
|
|
47
|
+
const statePath=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json');
|
|
48
|
+
return {root,cwd,configuration,identity,specsRoot,statePath,reviewNow,reviewConfig,setVerdict(verdict){validVerdict=verdict;},setThread(thread){threadOverride=thread;},changeProofAuxiliary(){proofAuxiliaryChanged=true;},close(){owner.close();owner=null;},get owner(){return owner;},get calls(){return calls;},reopen(){owner?.close();owner=openFixExecution({...options,create:false},runtime);}};
|
|
49
|
+
}
|
|
50
|
+
for(const phase of ['cause','final','revision'])test(`${phase} verification recovery is single prepared and explicitly dispatched without rewriting history`,{skip:process.platform!=='darwin'},async t=>{
|
|
51
|
+
const f=await fixture(t,phase),before=fs.readFileSync(f.statePath),old=JSON.parse(before),calls=f.calls;
|
|
52
|
+
const eligible=await f.owner.inspectVerificationRecovery();assert.equal(eligible.phase,phase==='cause'?'cause_review':phase==='revision'?'revision_final_review':'final_review');assert.equal(f.calls,calls);assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
53
|
+
const input={authorized:true,expected:eligible,previousInvocationStopped:true,reason:'Runtime verification transport repaired; retain all prior evidence'};
|
|
54
|
+
const prepared=await f.owner.prepareVerificationRecovery(input);assert.equal(f.calls,calls);
|
|
55
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(f.statePath)).records.slice(0,old.records.length),old.records);
|
|
56
|
+
assert.deepEqual(await f.owner.prepareVerificationRecovery(input),prepared);
|
|
57
|
+
f.reopen();await assert.rejects(f.reviewNow(),{code:'fix_verification_recovery_authorization_required'});assert.equal(f.calls,calls);
|
|
58
|
+
await f.reviewNow(prepared.authorizationDigest);assert.equal(f.calls,calls+1);assert.equal(f.owner.status().stage,'unknown');
|
|
59
|
+
await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_verification_recovery_used'});
|
|
60
|
+
assert.throws(()=>f.owner.abandonReview({authorized:true,reason:'No extra budget'}),{code:'fix_verification_recovery_used'});
|
|
61
|
+
f.reopen();assert.equal(f.owner.status().stage,'unknown');assert.deepEqual(JSON.parse(fs.readFileSync(f.statePath)).fingerprints,old.fingerprints);
|
|
62
|
+
});
|
|
63
|
+
for(const verdict of ['approved','changes_requested'])test(`valid ${verdict} is never verification recovery eligibility`,{skip:process.platform!=='darwin'},async t=>{
|
|
64
|
+
const f=await fixture(t,'cause',{validVerdict:verdict});
|
|
65
|
+
assert.notEqual(f.owner.status().stage,'unknown');
|
|
66
|
+
const before=fs.readFileSync(f.statePath),calls=f.calls;
|
|
67
|
+
await assert.rejects(f.owner.inspectVerificationRecovery(),{code:'fix_verification_recovery_unavailable'});
|
|
68
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(f.calls,calls);
|
|
69
|
+
});
|
|
70
|
+
for(const drift of ['source','auxiliary','baseline'])test(`verification recovery refuses ${drift} drift before preparing history`,{skip:process.platform!=='darwin'},async t=>{
|
|
71
|
+
const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery(),before=fs.readFileSync(f.statePath),calls=f.calls;
|
|
72
|
+
if(drift==='source')fs.appendFileSync(path.join(f.cwd,'value.mjs'),'\n// changed');
|
|
73
|
+
else if(drift==='auxiliary')fs.appendFileSync(path.join(f.cwd,'existing.mjs'),'\n// changed');
|
|
74
|
+
else fs.writeFileSync(path.join(f.cwd,'existing.mjs'),'process.exit(1)');
|
|
75
|
+
await assert.rejects(f.owner.prepareVerificationRecovery({authorized:true,expected,previousInvocationStopped:true,reason:'Bounded recovery'}),{code:drift==='source'?'review_verification_package_binding':drift==='baseline'?'review_verification_check_failed':'fix_verification_recovery_stale'});
|
|
76
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(f.calls,calls);
|
|
77
|
+
});
|
|
78
|
+
test('preparation and continuation reject missing confirmations, stale targets and old threads',{skip:process.platform!=='darwin'},async t=>{
|
|
79
|
+
const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery(),before=fs.readFileSync(f.statePath);
|
|
80
|
+
const args={authorized:true,expected,previousInvocationStopped:true,reason:'Runtime repaired'};
|
|
81
|
+
await assert.rejects(f.owner.prepareVerificationRecovery({...args,authorized:false}),{code:'fix_verification_recovery_authorization_required'});
|
|
82
|
+
await assert.rejects(f.owner.prepareVerificationRecovery({...args,previousInvocationStopped:false}),{code:'fix_verification_recovery_confirmation'});
|
|
83
|
+
await assert.rejects(f.owner.prepareVerificationRecovery({...args,expected:{...expected,invocationId:'another'}}),{code:'fix_verification_recovery_stale'});
|
|
84
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
85
|
+
const prepared=await f.owner.prepareVerificationRecovery(args);
|
|
86
|
+
f.setThread('thread-1');await f.reviewNow(prepared.authorizationDigest);
|
|
87
|
+
const state=JSON.parse(fs.readFileSync(f.statePath));assert.equal(state.records.some(r=>r.id==='fix-verification-recovery-started'),false);
|
|
88
|
+
assert.equal(f.owner.status().stage,'unknown');f.reopen();assert.equal(f.owner.status().stage,'unknown');
|
|
89
|
+
});
|
|
90
|
+
test('prepared auxiliary snapshot stays binding at dispatch and across resume',{skip:process.platform!=='darwin'},async t=>{
|
|
91
|
+
const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery();
|
|
92
|
+
const prepared=await f.owner.prepareVerificationRecovery({authorized:true,expected,previousInvocationStopped:true,reason:'Runtime repaired'}),before=fs.readFileSync(f.statePath),calls=f.calls;
|
|
93
|
+
fs.appendFileSync(path.join(f.cwd,'existing.mjs'),'\n// changed after permission');f.reopen();
|
|
94
|
+
await assert.rejects(f.reviewNow(prepared.authorizationDigest),{code:'fix_verification_recovery_drift'});
|
|
95
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(f.calls,calls);
|
|
96
|
+
});
|
|
97
|
+
const DRIVER=fileURLToPath(new URL('./cm-fix-drive.mjs',import.meta.url)),INSPECT=fileURLToPath(new URL('./cm-fix-verification-recovery.mjs',import.meta.url));
|
|
98
|
+
function cliFiles(f){
|
|
99
|
+
const {hostContextId,causeReview,reviewRuntime,...run}=f.configuration,config=path.join(f.root,'config.json'),review=path.join(f.root,'review.json');
|
|
100
|
+
fs.writeFileSync(config,JSON.stringify({...run,identity:f.identity,specsRoot:f.specsRoot}));fs.writeFileSync(review,JSON.stringify(f.reviewConfig));
|
|
101
|
+
const answers=path.join(f.root,'answers');fs.mkdirSync(answers);return {config,review,answers};
|
|
102
|
+
}
|
|
103
|
+
function spawnFixture(command,f){return spawnSync(process.execPath,command,{encoding:'utf8',timeout:20000,env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});}
|
|
104
|
+
test('read-only inspection CLI reports frozen baseline failure without a writer or provider',{skip:process.platform!=='darwin'},async t=>{
|
|
105
|
+
const f=await fixture(t),{config}=cliFiles(f),before=fs.readFileSync(f.statePath),dir=path.dirname(f.statePath);
|
|
106
|
+
const beforeFiles=fs.readdirSync(dir).map(p=>[p,fs.statSync(path.join(dir,p)).mtimeMs]);
|
|
107
|
+
fs.writeFileSync(path.join(f.cwd,'existing.mjs'),'process.exit(1)');
|
|
108
|
+
const run=spawnFixture([INSPECT,'--config',config],f);assert.equal(run.status,1,run.stderr);
|
|
109
|
+
const diagnostic=JSON.parse(run.stderr.trim().split('\n').at(-1));assert.equal(diagnostic.code,'review_verification_check_failed');assert.equal(diagnostic.verificationDiagnostic.checkId,'unit');assert.equal(diagnostic.verificationDiagnostic.exitCode,1);
|
|
110
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);assert.deepEqual(fs.readdirSync(dir).map(p=>[p,fs.statSync(path.join(dir,p)).mtimeMs]),beforeFiles);
|
|
111
|
+
});
|
|
112
|
+
test('real driver prepares once and forwards bounded startup authorization without dispatch permission',{skip:process.platform!=='darwin'},async t=>{
|
|
113
|
+
const f=await fixture(t),files=cliFiles(f),before=fs.readFileSync(f.statePath);f.close();
|
|
114
|
+
const inspected=spawnFixture([INSPECT,'--config',files.config],f);assert.equal(inspected.status,0,inspected.stderr);assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
115
|
+
const expected=JSON.parse(inspected.stdout).expected,plan=path.join(f.root,'plan.json');
|
|
116
|
+
const base={config:files.config,cwd:f.cwd,mode:'resume',hostContext:'author',runtime:'codex',reviewRuntime:'claude',reviewConfig:files.review,expected,previousInvocationStopped:true,reason:'Explicit bounded runtime repair',permissions:['--allow-verification-recovery']};
|
|
117
|
+
fs.writeFileSync(plan,JSON.stringify(base));let run=spawnFixture([DRIVER,'--plan',plan,'prepare_verification_recovery'],f);assert.equal(run.status,0,run.stderr+run.stdout);
|
|
118
|
+
const prepared=JSON.parse(run.stdout).result;assert.match(prepared.authorizationDigest,/^[a-f0-9]{64}$/);
|
|
119
|
+
const preparedBytes=fs.readFileSync(f.statePath);run=spawnFixture([DRIVER,'--plan',plan,'prepare_verification_recovery'],f);assert.equal(run.status,0,run.stderr);assert.deepEqual(fs.readFileSync(f.statePath),preparedBytes);
|
|
120
|
+
fs.writeFileSync(plan,JSON.stringify({...base,answers:files.answers,permissions:[]}));run=spawnFixture([DRIVER,'--plan',plan,'cause_review'],f);assert.match(run.stdout+run.stderr,/fix_verification_recovery_authorization_required/);
|
|
121
|
+
fs.writeFileSync(plan,JSON.stringify({...base,answers:files.answers,permissions:[],verificationRecoveryAuthorization:prepared.authorizationDigest}));run=spawnFixture([DRIVER,'--plan',plan,'cause_review'],f);assert.match(run.stdout+run.stderr,/permission_denied/);
|
|
122
|
+
assert.deepEqual(fs.readFileSync(f.statePath),preparedBytes,'No dispatch grant or invocation without the original review permission');
|
|
123
|
+
});
|
|
124
|
+
for(const phase of ['cause','final'])test(`${phase} recovered valid review publishes original round without rewriting failed evidence`,{skip:process.platform!=='darwin'},async t=>{
|
|
125
|
+
const f=await fixture(t,phase),expected=await f.owner.inspectVerificationRecovery();
|
|
126
|
+
const prepared=await f.owner.prepareVerificationRecovery({authorized:true,expected,previousInvocationStopped:true,reason:'Verification transport fixed'}),old=JSON.parse(fs.readFileSync(f.statePath)).records;
|
|
127
|
+
f.setVerdict('approved');await f.reviewNow(prepared.authorizationDigest);
|
|
128
|
+
assert.equal(f.owner.status().stage,phase==='cause'?'red_test_required':'final_review_evidence_required');
|
|
129
|
+
if(phase==='final')assert.equal(f.owner.publishReview().stage,'completion_gate_required');
|
|
130
|
+
f.reopen();assert.equal(f.owner.status().stage,phase==='cause'?'red_test_required':'completion_gate_required');
|
|
131
|
+
const rows=JSON.parse(fs.readFileSync(f.statePath)).records;assert.deepEqual(rows.slice(0,old.length),old);
|
|
132
|
+
assert.equal(rows.filter(r=>r.id==='fix-verification-recovery-registered').length,1);
|
|
133
|
+
const latest=rows.find(r=>r.id==='fix-verification-recovery-registered');assert.equal(latest.payload.request.identity.attempt,1);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('observation-cause correction packages are explicitly outside verification recovery',{skip:process.platform!=='darwin'},async t=>{
|
|
137
|
+
const f=await fixture(t),target=await f.owner.inspectVerificationRecovery();
|
|
138
|
+
const {verificationRecoveryTarget}=await import('../runtime/js/cm-fix/review-verification-recovery.mjs');
|
|
139
|
+
const records=JSON.parse(fs.readFileSync(f.statePath)).records;
|
|
140
|
+
const registration=structuredClone(records.findLast(r=>r.id.endsWith('-registered')&&r.payload.request?.role==='reviewer'));
|
|
141
|
+
registration.payload.request.payload.reviewPackage.correction={reason:'observation_cause_review_omitted'};
|
|
142
|
+
const prefix=registration.id.slice(0,-11);
|
|
143
|
+
assert.throws(()=>verificationRecoveryTarget({records,configuration:f.configuration,stage:'unknown',phase:'cause_review',registration,
|
|
144
|
+
started:records.find(r=>r.id===prefix+'-started'),result:records.find(r=>r.id===prefix+'-result'),
|
|
145
|
+
baseline:{files:target.files,snapshotDigest:target.snapshotDigest,checks:f.configuration.reviewVerification.checks.map(c=>({id:c.id,commandDigest:digest(c.command),exitCode:0}))}}),{code:'fix_verification_recovery_unavailable'});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
for(const phase of ['cause','final'])test(`${phase} recovery persists rejected auxiliary proof as a failed observation`,{skip:process.platform!=='darwin'},async t=>{
|
|
149
|
+
const f=await fixture(t,phase),expected=await f.owner.inspectVerificationRecovery();
|
|
150
|
+
const prepared=await f.owner.prepareVerificationRecovery({authorized:true,expected,previousInvocationStopped:true,reason:'Verification transport repaired'});
|
|
151
|
+
const old=JSON.parse(fs.readFileSync(f.statePath)).records,source=fs.readFileSync(path.join(f.cwd,'existing.mjs'));
|
|
152
|
+
f.setVerdict('approved');f.changeProofAuxiliary();await f.reviewNow(prepared.authorizationDigest);
|
|
153
|
+
assert.equal(f.owner.status().stage,'unknown');
|
|
154
|
+
const rows=JSON.parse(fs.readFileSync(f.statePath)).records;
|
|
155
|
+
assert.deepEqual(rows.slice(0,old.length),old);
|
|
156
|
+
const failed=rows.find(r=>r.id==='fix-verification-recovery-result');
|
|
157
|
+
assert.ok(failed,'Rejected recovery proof must leave a durable failed result');
|
|
158
|
+
assert.equal(failed.payload.verification,undefined);
|
|
159
|
+
assert.deepEqual(failed.payload.observation.result,{status:'failed',code:'fix_verification_recovery_binding'});
|
|
160
|
+
assert.equal(failed.payload.verificationDiagnostic.code,'fix_verification_recovery_binding');
|
|
161
|
+
assert.deepEqual(fs.readFileSync(path.join(f.cwd,'existing.mjs')),source);
|
|
162
|
+
f.reopen();assert.equal(f.owner.status().stage,'unknown');
|
|
163
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(f.statePath)).records,rows);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('real driver preserves F24 request and invocation permissions through bounded final recovery',{skip:process.platform!=='darwin'},async t=>{
|
|
167
|
+
const f=await fixture(t,'final'),files=cliFiles(f),plan=path.join(f.root,'f24-plan.json');
|
|
168
|
+
const base={config:files.config,cwd:f.cwd,mode:'resume',hostContext:'author',runtime:'codex',reviewRuntime:'claude',reviewConfig:files.review};
|
|
169
|
+
const drive=(operation,value)=>{fs.writeFileSync(plan,JSON.stringify({...base,...value}));return spawnFixture([DRIVER,'--plan',plan,operation],f);};
|
|
170
|
+
let f24Invocation;
|
|
171
|
+
for(let cycle=0;cycle<2;cycle++){
|
|
172
|
+
const rows=JSON.parse(fs.readFileSync(f.statePath)).records;
|
|
173
|
+
const prior=rows.findLast(r=>r.id.endsWith('-registered')&&r.payload.request?.role==='reviewer').payload;
|
|
174
|
+
f24Invocation=prior.request.invocationId;
|
|
175
|
+
const request={permissions:['--allow-final-review-recovery'],invocationId:f24Invocation,packageDigest:prior.request.payload.reviewPackage.packageDigest,previousInvocationStopped:true,reason:'Original F24 retry after closed failed worker',...(cycle?{finalReviewRecoveryInvocation:f24Invocation}:{})};
|
|
176
|
+
f.close();const old=fs.readFileSync(f.statePath);
|
|
177
|
+
if(cycle){const denied=drive('recover_final_review',{...request,finalReviewRecoveryInvocation:'wrong-invocation'});assert.match(denied.stdout+denied.stderr,/fix_review_recovery_authorization_required/);assert.deepEqual(fs.readFileSync(f.statePath),old);}
|
|
178
|
+
const recovered=drive('recover_final_review',request);assert.equal(recovered.status,0,recovered.stdout+recovered.stderr);
|
|
179
|
+
// No answers directory is required: this request records permission, not an author response.
|
|
180
|
+
assert.equal(Object.hasOwn(request,'answers'),false);
|
|
181
|
+
f.reopen();assert.equal(f.owner.status().finalReviewRecoveryCount,cycle+1);
|
|
182
|
+
await f.reviewNow();assert.equal(f.owner.status().stage,'unknown');
|
|
183
|
+
}
|
|
184
|
+
const expected=await f.owner.inspectVerificationRecovery(),old=JSON.parse(fs.readFileSync(f.statePath)).records;
|
|
185
|
+
f.close();const preparedRun=drive('prepare_verification_recovery',{permissions:['--allow-verification-recovery'],expected,previousInvocationStopped:true,reason:'Runtime verification transport repaired'});
|
|
186
|
+
assert.equal(preparedRun.status,0,preparedRun.stdout+preparedRun.stderr);
|
|
187
|
+
const prepared=JSON.parse(preparedRun.stdout).result,preparedBytes=fs.readFileSync(f.statePath);
|
|
188
|
+
assert.deepEqual(JSON.parse(preparedBytes).records.slice(0,old.length),old);
|
|
189
|
+
const continuation={answers:files.answers,verificationRecoveryAuthorization:prepared.authorizationDigest};
|
|
190
|
+
for(const extra of [{permissions:[]},{permissions:['--allow-final-review-recovery']},{permissions:['--allow-final-review-recovery'],finalReviewRecoveryInvocation:'wrong-invocation'}]){
|
|
191
|
+
const denied=drive('final_review',{...continuation,...extra});assert.match(denied.stdout+denied.stderr,/fix_review_recovery_authorization_required/);assert.deepEqual(fs.readFileSync(f.statePath),preparedBytes);
|
|
192
|
+
}
|
|
193
|
+
const originalPermission=drive('final_review',{...continuation,permissions:['--allow-final-review-recovery'],finalReviewRecoveryInvocation:f24Invocation});
|
|
194
|
+
assert.match(originalPermission.stdout+originalPermission.stderr,/permission_denied/);
|
|
195
|
+
assert.doesNotMatch(originalPermission.stdout+originalPermission.stderr,/fix_review_recovery_authorization_required/);
|
|
196
|
+
assert.deepEqual(fs.readFileSync(f.statePath),preparedBytes,'Passing F24 binding still cannot dispatch without original final-review permission');
|
|
197
|
+
f.reopen();assert.equal(f.owner.status().finalReviewRecoveryCount,2);assert.equal(f.calls,3);
|
|
198
|
+
});
|