@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,436 @@
|
|
|
1
|
+
// Codex installer: replacing ~/plugins/cm-workflow must stop on files
|
|
2
|
+
// hand-edited since the last install, even with --yes. Runs in a disposable
|
|
3
|
+
// HOME/CODEX_HOME with a stub plugin creator and a stub `codex` CLI, so it
|
|
4
|
+
// never touches the real ~/plugins, ~/.agents or ~/.codex.
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import {spawn, spawnSync} from 'node:child_process';
|
|
11
|
+
import {fileURLToPath} from 'node:url';
|
|
12
|
+
|
|
13
|
+
const source = fileURLToPath(new URL('..', import.meta.url));
|
|
14
|
+
const MANIFEST = '.cm-install-manifest.sha256';
|
|
15
|
+
const EDITED = 'skills/cm-check/SKILL.md';
|
|
16
|
+
|
|
17
|
+
const STUB_CREATOR = `import json, pathlib, sys
|
|
18
|
+
args = sys.argv[1:]
|
|
19
|
+
path = pathlib.Path(args[args.index('--marketplace-path') + 1])
|
|
20
|
+
# Every run changes the file, so a later rollback has something to undo.
|
|
21
|
+
data = json.loads(path.read_text()) if path.exists() else {'name': 'personal', 'plugins': [{'name': 'cm-workflow'}]}
|
|
22
|
+
data['stubWrites'] = data.get('stubWrites', 0) + 1
|
|
23
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
24
|
+
path.write_text(json.dumps(data) + '\\n')
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
function sandbox(t) {
|
|
28
|
+
const home = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cm-codex-install-guard-')));
|
|
29
|
+
t.after(() => fs.rmSync(home, {recursive: true, force: true}));
|
|
30
|
+
const codexHome = path.join(home, '.codex');
|
|
31
|
+
const creator = path.join(codexHome, 'skills/.system/plugin-creator/scripts');
|
|
32
|
+
fs.mkdirSync(creator, {recursive: true});
|
|
33
|
+
fs.writeFileSync(path.join(creator, 'create_basic_plugin.py'), STUB_CREATOR);
|
|
34
|
+
const bin = path.join(home, 'bin');
|
|
35
|
+
fs.mkdirSync(bin);
|
|
36
|
+
fs.writeFileSync(path.join(bin, 'codex'), '#!/bin/sh\nexit 0\n', {mode: 0o755});
|
|
37
|
+
const env = {...process.env, HOME: home, CODEX_HOME: codexHome, PATH: `${bin}:${process.env.PATH}`,
|
|
38
|
+
CM_WORKFLOW_HOME: path.join(home, 'workflow'), CM_WORKFLOW_LOG_HOME: path.join(home, 'logs'), CM_MATT_SKILLS_INSTALL: 'off'};
|
|
39
|
+
return {home, bin, plugin: path.join(home, 'plugins/cm-workflow'), marketplace: path.join(home, '.agents/plugins/marketplace.json'), env};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function install(env, args) {
|
|
43
|
+
return spawnSync('/bin/bash', [path.join(source, 'install-codex.sh'), ...args],
|
|
44
|
+
{cwd: source, env, encoding: 'utf8', timeout: 240000, maxBuffer: 8 * 1024 * 1024, input: ''});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const output = result => result.stdout + result.stderr;
|
|
48
|
+
const lockOf = target => path.join(path.dirname(target), `.${path.basename(target)}.cm-install.lock`);
|
|
49
|
+
|
|
50
|
+
// Run an interactive install, call onPrompt() once the replace prompt is
|
|
51
|
+
// reached, then answer "y" (simulates another session editing meanwhile).
|
|
52
|
+
function installAtPrompt(env, onPrompt) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const child = spawn('/bin/bash', [path.join(source, 'install-codex.sh')], {cwd: source, env});
|
|
55
|
+
let stdout = '', stderr = '', answered = false;
|
|
56
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), 240000);
|
|
57
|
+
const check = () => {
|
|
58
|
+
if (answered || !/Replace the existing Codex plugin/.test(stdout)) return;
|
|
59
|
+
answered = true;
|
|
60
|
+
onPrompt();
|
|
61
|
+
child.stdin.end('y\n');
|
|
62
|
+
};
|
|
63
|
+
child.stdout.on('data', chunk => { stdout += chunk; check(); });
|
|
64
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
65
|
+
child.on('error', reject);
|
|
66
|
+
child.on('close', status => { clearTimeout(timer); resolve({status, stdout, stderr, answered}); });
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
test('codex install manifest: first install records hashes, unchanged reinstall passes, --yes cannot overwrite a hand edit, --overwrite-local-edits can',
|
|
71
|
+
{skip: process.platform === 'win32', timeout: 900000}, async t => {
|
|
72
|
+
const {plugin, marketplace, env} = sandbox(t);
|
|
73
|
+
const manifest = path.join(plugin, MANIFEST);
|
|
74
|
+
|
|
75
|
+
const first = install(env, ['--yes']);
|
|
76
|
+
assert.equal(first.status, 0, output(first));
|
|
77
|
+
assert.match(first.stdout, /No previous install manifest found/);
|
|
78
|
+
const lines = fs.readFileSync(manifest, 'utf8').trimEnd().split('\n');
|
|
79
|
+
assert.equal(lines[0], '# cm-workflow install manifest v1');
|
|
80
|
+
const recorded = new Map(lines.slice(1).map(line => [line.slice(66), line.slice(0, 64)]));
|
|
81
|
+
assert.match(recorded.get(EDITED) ?? '', /^[0-9a-f]{64}$/);
|
|
82
|
+
// The cache-version stamp happens before hashing, so the installed manifest is recorded as installed.
|
|
83
|
+
assert.ok(recorded.has('.codex-plugin/plugin.json'));
|
|
84
|
+
assert.equal(recorded.has(MANIFEST), false, 'the manifest must not record itself');
|
|
85
|
+
|
|
86
|
+
const unchanged = install(env, ['--yes']);
|
|
87
|
+
assert.equal(unchanged.status, 0, output(unchanged));
|
|
88
|
+
assert.doesNotMatch(output(unchanged), /changed since the last install/);
|
|
89
|
+
|
|
90
|
+
const edited = path.join(plugin, EDITED);
|
|
91
|
+
const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- approved local edit -->\n';
|
|
92
|
+
|
|
93
|
+
// Regression: edited by another session while this one waits at the replace prompt.
|
|
94
|
+
const marketplaceBefore = fs.readFileSync(marketplace, 'utf8');
|
|
95
|
+
const raced = await installAtPrompt(env, () => fs.writeFileSync(edited, handEdit));
|
|
96
|
+
assert.equal(raced.answered, true, output(raced));
|
|
97
|
+
assert.equal(raced.status, 3, output(raced));
|
|
98
|
+
assert.match(raced.stderr, /skills\/cm-check\/SKILL\.md/);
|
|
99
|
+
assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'an edit made while waiting at the prompt must survive "y"');
|
|
100
|
+
assert.equal(fs.readFileSync(marketplace, 'utf8'), marketplaceBefore);
|
|
101
|
+
// A file the installer never recorded is not judged.
|
|
102
|
+
fs.writeFileSync(path.join(plugin, 'scripts/my-own-tool.sh'), 'echo mine\n');
|
|
103
|
+
|
|
104
|
+
const refused = install(env, ['--yes']);
|
|
105
|
+
assert.equal(refused.status, 3, output(refused));
|
|
106
|
+
assert.match(refused.stderr, /changed since the last install/);
|
|
107
|
+
assert.match(refused.stderr, /skills\/cm-check\/SKILL\.md/);
|
|
108
|
+
assert.doesNotMatch(refused.stderr, /my-own-tool/);
|
|
109
|
+
assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'the hand edit must survive a refused --yes reinstall');
|
|
110
|
+
|
|
111
|
+
const overwritten = install(env, ['--overwrite-local-edits', '--yes']);
|
|
112
|
+
assert.equal(overwritten.status, 0, output(overwritten));
|
|
113
|
+
assert.match(overwritten.stdout, /these edits will be replaced/);
|
|
114
|
+
assert.equal(fs.readFileSync(edited, 'utf8'), fs.readFileSync(path.join(source, EDITED), 'utf8'));
|
|
115
|
+
assert.equal(fs.existsSync(lockOf(plugin)), false,
|
|
116
|
+
'every finished install releases its lock');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('codex install manifest: a manifest path that is a directory is a corrupt manifest, not a missing one',
|
|
120
|
+
{skip: process.platform === 'win32', timeout: 120000}, t => {
|
|
121
|
+
const {plugin, env} = sandbox(t);
|
|
122
|
+
fs.mkdirSync(path.join(plugin, MANIFEST), {recursive: true});
|
|
123
|
+
fs.mkdirSync(path.join(plugin, 'skills/cm-check'), {recursive: true});
|
|
124
|
+
fs.writeFileSync(path.join(plugin, EDITED), 'hand edit\n');
|
|
125
|
+
const refused = install(env, ['--yes']);
|
|
126
|
+
assert.equal(refused.status, 3, output(refused));
|
|
127
|
+
assert.match(refused.stderr, /Unrecognized install manifest/);
|
|
128
|
+
assert.doesNotMatch(refused.stdout, /No previous install manifest found/);
|
|
129
|
+
assert.equal(fs.readFileSync(path.join(plugin, EDITED), 'utf8'), 'hand edit\n');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('codex install lock: a held lock refuses the install without writing; a stale one is reported, never taken over',
|
|
133
|
+
{skip: process.platform === 'win32', timeout: 120000}, async t => {
|
|
134
|
+
const {plugin, marketplace, env} = sandbox(t);
|
|
135
|
+
const lock = lockOf(plugin);
|
|
136
|
+
fs.mkdirSync(lock, {recursive: true});
|
|
137
|
+
const holder = spawn('/bin/sleep', ['60']);
|
|
138
|
+
t.after(() => holder.kill('SIGKILL'));
|
|
139
|
+
const owner = pid => `pid=${pid}\nstarted=2026-10-20T00:00:00Z\ntarget=${plugin}\n`;
|
|
140
|
+
fs.writeFileSync(path.join(lock, 'owner'), owner(holder.pid));
|
|
141
|
+
|
|
142
|
+
const busy = install(env, ['--yes']);
|
|
143
|
+
assert.equal(busy.status, 4, output(busy));
|
|
144
|
+
assert.match(busy.stderr, /Another CM install is writing the same target/);
|
|
145
|
+
assert.match(busy.stderr, new RegExp(`Holder pid: ${holder.pid}`));
|
|
146
|
+
assert.match(busy.stderr, /still running/);
|
|
147
|
+
assert.equal(fs.existsSync(plugin), false);
|
|
148
|
+
assert.equal(fs.existsSync(marketplace), false);
|
|
149
|
+
assert.equal(fs.readFileSync(path.join(lock, 'owner'), 'utf8'), owner(holder.pid));
|
|
150
|
+
|
|
151
|
+
const exited = new Promise(resolve => holder.on('close', resolve));
|
|
152
|
+
holder.kill('SIGKILL');
|
|
153
|
+
await exited;
|
|
154
|
+
const stale = install(env, ['--yes']);
|
|
155
|
+
assert.equal(stale.status, 4, output(stale));
|
|
156
|
+
assert.match(stale.stderr, /no longer running/);
|
|
157
|
+
assert.ok(stale.stderr.includes(`rm -rf ${lock}`), stale.stderr);
|
|
158
|
+
assert.equal(fs.existsSync(plugin), false);
|
|
159
|
+
assert.equal(fs.readFileSync(path.join(lock, 'owner'), 'utf8'), owner(holder.pid));
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
function writeHook(dir, lines) {
|
|
163
|
+
const hook = path.join(dir, 'hook.sh');
|
|
164
|
+
fs.writeFileSync(hook, ['#!/bin/sh', ...lines, 'exit 0', ''].join('\n'), {mode: 0o755});
|
|
165
|
+
return hook;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
test('codex fault: a signal between taking the install lock and registering it still releases the lock',
|
|
169
|
+
{skip: process.platform === 'win32', timeout: 120000}, t => {
|
|
170
|
+
const {plugin, marketplace, env} = sandbox(t);
|
|
171
|
+
const hook = writeHook(path.dirname(path.dirname(plugin)), ['[ "$1" = lock-acquired ] || exit 0', 'kill -TERM "$PPID"']);
|
|
172
|
+
const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
173
|
+
assert.equal(result.status, 143, output(result));
|
|
174
|
+
assert.equal(fs.existsSync(lockOf(plugin)), false);
|
|
175
|
+
assert.equal(fs.existsSync(plugin), false);
|
|
176
|
+
assert.equal(fs.existsSync(marketplace), false);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('codex fault: a signal right after the new plugin is renamed into place restores the previous plugin',
|
|
180
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
181
|
+
const {plugin, marketplace, env} = sandbox(t);
|
|
182
|
+
const first = install(env, ['--yes']);
|
|
183
|
+
assert.equal(first.status, 0, output(first));
|
|
184
|
+
const pluginJson = path.join(plugin, '.codex-plugin/plugin.json');
|
|
185
|
+
const before = {json: fs.readFileSync(pluginJson), manifest: fs.readFileSync(path.join(plugin, MANIFEST)),
|
|
186
|
+
marketplace: fs.readFileSync(marketplace)};
|
|
187
|
+
const hook = writeHook(path.dirname(path.dirname(plugin)), ['[ "$1" = after-stage-moved ] || exit 0', 'kill -TERM "$PPID"']);
|
|
188
|
+
const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
189
|
+
assert.equal(result.status, 143, output(result));
|
|
190
|
+
assert.deepEqual(fs.readFileSync(pluginJson), before.json, 'the previous plugin (its cache-version stamp) is back');
|
|
191
|
+
assert.deepEqual(fs.readFileSync(path.join(plugin, MANIFEST)), before.manifest);
|
|
192
|
+
assert.deepEqual(fs.readFileSync(marketplace), before.marketplace);
|
|
193
|
+
assert.equal(fs.existsSync(lockOf(plugin)), false);
|
|
194
|
+
assert.deepEqual(fs.readdirSync(path.dirname(plugin)).filter(name => name !== 'cm-workflow'), []);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('codex access: a plugins directory that becomes unsearchable after the rename reports an incomplete rollback and keeps the lock and backup',
|
|
198
|
+
{skip: process.platform === 'win32' || process.getuid?.() === 0, timeout: 600000}, t => {
|
|
199
|
+
const {plugin, marketplace, env} = sandbox(t);
|
|
200
|
+
const first = install(env, ['--yes']);
|
|
201
|
+
assert.equal(first.status, 0, output(first));
|
|
202
|
+
const pluginJson = path.join(plugin, '.codex-plugin/plugin.json');
|
|
203
|
+
const before = {json: fs.readFileSync(pluginJson), marketplace: fs.readFileSync(marketplace)};
|
|
204
|
+
const plugins = path.dirname(plugin);
|
|
205
|
+
t.after(() => { try { fs.chmodSync(plugins, 0o755); } catch {} });
|
|
206
|
+
const hook = writeHook(path.dirname(plugins), ['[ "$1" = after-stage-moved ] || exit 0',
|
|
207
|
+
`chmod 000 '${plugins}'`, 'kill -TERM "$PPID"']);
|
|
208
|
+
const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
209
|
+
assert.equal(result.status, 143, output(result));
|
|
210
|
+
assert.match(result.stderr, /rollback is incomplete/, 'the skipped restore must be reported');
|
|
211
|
+
assert.match(result.stderr, /plugins directory cannot be accessed/);
|
|
212
|
+
assert.doesNotMatch(result.stderr, /was replaced during the install/, 'unsearchable is not "replaced"');
|
|
213
|
+
fs.chmodSync(plugins, 0o755);
|
|
214
|
+
const lock = lockOf(plugin);
|
|
215
|
+
assert.equal(fs.existsSync(lock), true, 'the lock is left for a person, not removed blind');
|
|
216
|
+
assert.match(result.stderr, new RegExp(path.basename(lock).replace(/\./g, '\\.')));
|
|
217
|
+
const kept = fs.readdirSync(plugins).filter(name => name.startsWith('.cm-workflow.backup.'));
|
|
218
|
+
assert.equal(kept.length, 1, 'the previous plugin must be kept');
|
|
219
|
+
assert.deepEqual(fs.readFileSync(path.join(plugins, kept[0], '.codex-plugin/plugin.json')), before.json);
|
|
220
|
+
assert.match(result.stderr, new RegExp(kept[0].replace(/\./g, '\\.')), 'its location is printed');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('codex path safety: a symlinked marketplace or plugins root is refused before anything is written',
|
|
224
|
+
{skip: process.platform === 'win32', timeout: 120000}, t => {
|
|
225
|
+
const {plugin, marketplace, env} = sandbox(t);
|
|
226
|
+
const home = path.dirname(path.dirname(plugin));
|
|
227
|
+
const outside = path.join(home, 'outside-marketplace.json');
|
|
228
|
+
fs.writeFileSync(outside, '{"name":"someone-else","plugins":[]}\n');
|
|
229
|
+
fs.mkdirSync(path.dirname(marketplace), {recursive: true});
|
|
230
|
+
fs.symlinkSync(outside, marketplace);
|
|
231
|
+
const linkedMarketplace = install(env, ['--yes']);
|
|
232
|
+
assert.equal(linkedMarketplace.status, 2, output(linkedMarketplace));
|
|
233
|
+
assert.match(linkedMarketplace.stderr, /Refusing a symlinked or wrong-type install path/);
|
|
234
|
+
assert.equal(fs.readFileSync(outside, 'utf8'), '{"name":"someone-else","plugins":[]}\n');
|
|
235
|
+
assert.equal(fs.existsSync(plugin), false);
|
|
236
|
+
fs.unlinkSync(marketplace);
|
|
237
|
+
|
|
238
|
+
const realPlugins = path.join(home, 'real-plugins');
|
|
239
|
+
fs.mkdirSync(realPlugins);
|
|
240
|
+
fs.symlinkSync(realPlugins, path.dirname(plugin));
|
|
241
|
+
const linkedRoot = install(env, ['--yes']);
|
|
242
|
+
assert.equal(linkedRoot.status, 2, output(linkedRoot));
|
|
243
|
+
assert.match(linkedRoot.stderr, /Refusing a symlinked install path/);
|
|
244
|
+
assert.deepEqual(fs.readdirSync(realPlugins), []);
|
|
245
|
+
assert.equal(fs.existsSync(marketplace), false);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ---- Fault injection on a copy of one real install --------------------------
|
|
249
|
+
let codexTemplate;
|
|
250
|
+
function installedCodexClone(t) {
|
|
251
|
+
if (!codexTemplate) {
|
|
252
|
+
const home = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cm-codex-install-template-')));
|
|
253
|
+
process.on('exit', () => fs.rmSync(home, {recursive: true, force: true}));
|
|
254
|
+
const box = sandbox({after: () => {}});
|
|
255
|
+
const first = install(box.env, ['--yes']);
|
|
256
|
+
assert.equal(first.status, 0, output(first));
|
|
257
|
+
for (const dir of ['plugins', '.agents']) {
|
|
258
|
+
assert.equal(spawnSync('cp', ['-Rp', path.join(box.home, dir), path.join(home, dir)]).status, 0);
|
|
259
|
+
}
|
|
260
|
+
fs.rmSync(box.home, {recursive: true, force: true});
|
|
261
|
+
codexTemplate = home;
|
|
262
|
+
}
|
|
263
|
+
const box = sandbox(t);
|
|
264
|
+
for (const dir of ['plugins', '.agents']) {
|
|
265
|
+
assert.equal(spawnSync('cp', ['-Rp', path.join(codexTemplate, dir), path.join(box.home, dir)]).status, 0);
|
|
266
|
+
}
|
|
267
|
+
const pluginJson = path.join(box.plugin, '.codex-plugin/plugin.json');
|
|
268
|
+
box.before = {json: fs.readFileSync(pluginJson), manifest: fs.readFileSync(path.join(box.plugin, MANIFEST)),
|
|
269
|
+
marketplace: fs.readFileSync(box.marketplace)};
|
|
270
|
+
box.pluginJson = pluginJson;
|
|
271
|
+
return box;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const realTool = name => spawnSync('/bin/sh', ['-c', `command -v ${name}`], {encoding: 'utf8'}).stdout.trim();
|
|
275
|
+
function fakeTool(bin, name, body) {
|
|
276
|
+
fs.writeFileSync(path.join(bin, name), ['#!/bin/sh', ...body, ''].join('\n'), {mode: 0o755});
|
|
277
|
+
}
|
|
278
|
+
const pluginsLeftovers = plugin => fs.readdirSync(path.dirname(plugin)).filter(name => name !== 'cm-workflow');
|
|
279
|
+
|
|
280
|
+
test('codex fault: a rename that completes but is then killed by a group signal still restores the previous plugin',
|
|
281
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
282
|
+
const box = installedCodexClone(t);
|
|
283
|
+
const mv = realTool('mv');
|
|
284
|
+
// Real side effect first, then the signal reaches both the installer and this command.
|
|
285
|
+
fakeTool(box.bin, 'mv', [`${mv} "$@"; rc=$?`,
|
|
286
|
+
'case "$1" in *"/.cm-workflow.stage."*) kill -TERM "$PPID"; kill -TERM $$ ;; esac', 'exit $rc']);
|
|
287
|
+
const result = install(box.env, ['--yes']);
|
|
288
|
+
assert.equal(result.status, 143, output(result));
|
|
289
|
+
assert.deepEqual(fs.readFileSync(box.pluginJson), box.before.json, 'the previous plugin is back');
|
|
290
|
+
assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
|
|
291
|
+
assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
|
|
292
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false);
|
|
293
|
+
assert.deepEqual(pluginsLeftovers(box.plugin), []);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('codex fault: a failing rollback step still restores the marketplace, unlocks and keeps the previous plugin',
|
|
297
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
298
|
+
const box = installedCodexClone(t);
|
|
299
|
+
const mv = realTool('mv');
|
|
300
|
+
fakeTool(box.bin, 'codex', ['exit 17']);
|
|
301
|
+
fakeTool(box.bin, 'mv', ['case "$2" in *"/.cm-workflow.failed."*) exit 1 ;; esac', `exec ${mv} "$@"`]);
|
|
302
|
+
const result = install(box.env, ['--yes']);
|
|
303
|
+
assert.equal(result.status, 17, output(result));
|
|
304
|
+
assert.match(result.stderr, /rollback is incomplete/);
|
|
305
|
+
assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace, 'later restores still run');
|
|
306
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false, 'the lock is released even when the rollback is incomplete');
|
|
307
|
+
const kept = pluginsLeftovers(box.plugin).filter(name => name.startsWith('.cm-workflow.backup.'));
|
|
308
|
+
assert.equal(kept.length, 1, 'the previous plugin must be kept');
|
|
309
|
+
assert.deepEqual(fs.readFileSync(path.join(path.dirname(box.plugin), kept[0], '.codex-plugin/plugin.json')), box.before.json);
|
|
310
|
+
assert.match(result.stderr, new RegExp(kept[0].replace(/\./g, '\\.')));
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('codex fault: an edit landing right before the old plugin is renamed aside is caught there and the plugin is put back',
|
|
314
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
315
|
+
const box = installedCodexClone(t);
|
|
316
|
+
const edited = path.join(box.plugin, EDITED);
|
|
317
|
+
const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- edited during the install -->\n';
|
|
318
|
+
const hook = writeHook(box.home, ['[ "$1" = before-plugin-rename ] || exit 0',
|
|
319
|
+
`printf '\\n<!-- edited during the install -->\\n' >> '${edited}'`]);
|
|
320
|
+
const result = install({...box.env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
321
|
+
assert.equal(result.status, 3, output(result));
|
|
322
|
+
assert.match(result.stderr, /changed during the install/);
|
|
323
|
+
assert.equal(fs.readFileSync(edited, 'utf8'), handEdit);
|
|
324
|
+
assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
|
|
325
|
+
assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
|
|
326
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false);
|
|
327
|
+
assert.deepEqual(pluginsLeftovers(box.plugin), []);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('codex path safety: a marketplace parent swapped for a symlink before the marketplace is written is refused',
|
|
331
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
332
|
+
const box = installedCodexClone(t);
|
|
333
|
+
const elsewhere = path.join(box.home, 'elsewhere');
|
|
334
|
+
fs.mkdirSync(elsewhere);
|
|
335
|
+
fs.writeFileSync(path.join(elsewhere, 'marketplace.json'), '{"name":"someone-else","plugins":[]}\n');
|
|
336
|
+
const parent = path.dirname(box.marketplace);
|
|
337
|
+
const hook = writeHook(box.home, ['[ "$1" = before-marketplace-check ] || exit 0',
|
|
338
|
+
`mv '${parent}' '${parent}.moved'`, `ln -s '${elsewhere}' '${parent}'`]);
|
|
339
|
+
const result = install({...box.env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
340
|
+
assert.equal(result.status, 2, output(result));
|
|
341
|
+
assert.match(result.stderr, /symlinked or wrong-type install path/);
|
|
342
|
+
assert.equal(fs.readFileSync(path.join(elsewhere, 'marketplace.json'), 'utf8'), '{"name":"someone-else","plugins":[]}\n');
|
|
343
|
+
assert.deepEqual(fs.readFileSync(path.join(`${parent}.moved`, 'marketplace.json')), box.before.marketplace);
|
|
344
|
+
assert.deepEqual(fs.readFileSync(box.pluginJson), box.before.json);
|
|
345
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false);
|
|
346
|
+
assert.deepEqual(pluginsLeftovers(box.plugin), []);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test('codex fault: a marketplace that became a directory is not "restored" into it; the backup is kept and reported',
|
|
350
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
351
|
+
const box = installedCodexClone(t);
|
|
352
|
+
fakeTool(box.bin, 'codex', [`rm -f '${box.marketplace}'`, `mkdir '${box.marketplace}'`, 'exit 17']);
|
|
353
|
+
const result = install(box.env, ['--yes']);
|
|
354
|
+
assert.equal(result.status, 17, output(result));
|
|
355
|
+
assert.match(result.stderr, /rollback is incomplete/);
|
|
356
|
+
assert.ok(fs.statSync(box.marketplace).isDirectory());
|
|
357
|
+
assert.deepEqual(fs.readdirSync(box.marketplace), [], 'nothing may be copied into the directory');
|
|
358
|
+
const kept = pluginsLeftovers(box.plugin).filter(name => name.startsWith('.cm-workflow.marketplace.backup.'));
|
|
359
|
+
assert.equal(kept.length, 1, 'the marketplace backup must be kept');
|
|
360
|
+
assert.deepEqual(fs.readFileSync(path.join(path.dirname(box.plugin), kept[0])), box.before.marketplace);
|
|
361
|
+
assert.deepEqual(fs.readFileSync(box.pluginJson), box.before.json, 'the previous plugin is still restored');
|
|
362
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test('codex path safety: a plugins directory replaced by a symlink during the install stops at the next check',
|
|
366
|
+
{skip: process.platform === 'win32', timeout: 600000}, t => {
|
|
367
|
+
const box = installedCodexClone(t);
|
|
368
|
+
const plugins = path.dirname(box.plugin);
|
|
369
|
+
const elsewhere = path.join(box.home, 'elsewhere-plugins');
|
|
370
|
+
fs.mkdirSync(elsewhere);
|
|
371
|
+
const hook = writeHook(box.home, ['[ "$1" = before-marketplace-check ] || exit 0',
|
|
372
|
+
`mv '${plugins}' '${plugins}.moved'`, `ln -s '${elsewhere}' '${plugins}'`]);
|
|
373
|
+
const result = install({...box.env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
374
|
+
assert.equal(result.status, 2, output(result));
|
|
375
|
+
assert.match(result.stderr, /no longer the one checked at start/);
|
|
376
|
+
assert.match(result.stderr, /lock location cannot be confirmed/);
|
|
377
|
+
assert.deepEqual(fs.readdirSync(elsewhere), [], 'nothing may be written through the replaced directory');
|
|
378
|
+
const moved = path.join(`${plugins}.moved`, 'cm-workflow');
|
|
379
|
+
assert.deepEqual(fs.readFileSync(path.join(moved, '.codex-plugin/plugin.json')), box.before.json);
|
|
380
|
+
assert.deepEqual(fs.readFileSync(path.join(moved, MANIFEST)), box.before.manifest);
|
|
381
|
+
assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test('codex path safety: ~/.agents replaced by a symlink before the marketplace directory is created is refused there',
|
|
385
|
+
{skip: process.platform === 'win32', timeout: 300000}, t => {
|
|
386
|
+
const {home, plugin, env} = sandbox(t);
|
|
387
|
+
const elsewhere = path.join(home, 'elsewhere-agents');
|
|
388
|
+
const hook = writeHook(home, ['[ "$1" = before-marketplace-check ] || exit 0',
|
|
389
|
+
`mkdir '${elsewhere}'`, `ln -s '${elsewhere}' '${path.join(home, '.agents')}'`]);
|
|
390
|
+
const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
391
|
+
assert.equal(result.status, 2, output(result));
|
|
392
|
+
assert.match(result.stderr, /symlinked or wrong-type install path/);
|
|
393
|
+
assert.deepEqual(fs.readdirSync(elsewhere), [], 'no directory may be created through the symlink');
|
|
394
|
+
assert.equal(fs.existsSync(plugin), false);
|
|
395
|
+
assert.equal(fs.existsSync(lockOf(plugin)), false);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('codex fault: an unreadable scan file during the last check stops the install instead of reporting no edits',
|
|
399
|
+
{skip: process.platform === 'win32' || process.getuid?.() === 0, timeout: 600000}, t => {
|
|
400
|
+
const box = installedCodexClone(t);
|
|
401
|
+
const tmp = path.join(box.home, 'tmp');
|
|
402
|
+
fs.mkdirSync(tmp);
|
|
403
|
+
const edited = path.join(box.plugin, EDITED);
|
|
404
|
+
const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- edited during the install -->\n';
|
|
405
|
+
// Right before the last scan: a hand edit lands, and the scan's own list becomes write-only.
|
|
406
|
+
const hook = writeHook(box.home, ['[ "$1" = before-plugin-rename ] || exit 0',
|
|
407
|
+
`printf '\\n<!-- edited during the install -->\\n' >> '${edited}'`,
|
|
408
|
+
`for work in '${tmp}'/cm-install-guard.*; do : > "$work/recorded-paths"; chmod 0200 "$work/recorded-paths"; done`]);
|
|
409
|
+
const result = install({...box.env, TMPDIR: tmp, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
|
|
410
|
+
assert.equal(result.status, 2, output(result));
|
|
411
|
+
assert.match(result.stderr, /changed during the install/);
|
|
412
|
+
assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'the hand edit must not be replaced');
|
|
413
|
+
assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
|
|
414
|
+
assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
|
|
415
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false);
|
|
416
|
+
assert.deepEqual(pluginsLeftovers(box.plugin), []);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test('codex access: a hand-edited file under a directory that cannot be searched stops the install',
|
|
420
|
+
{skip: process.platform === 'win32' || process.getuid?.() === 0, timeout: 600000}, t => {
|
|
421
|
+
const box = installedCodexClone(t);
|
|
422
|
+
const edited = path.join(box.plugin, EDITED);
|
|
423
|
+
const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- hand edit -->\n';
|
|
424
|
+
fs.writeFileSync(edited, handEdit);
|
|
425
|
+
const hidden = path.dirname(edited);
|
|
426
|
+
fs.chmodSync(hidden, 0o644);
|
|
427
|
+
t.after(() => { if (fs.existsSync(hidden)) fs.chmodSync(hidden, 0o755); });
|
|
428
|
+
const result = install(box.env, ['--yes']);
|
|
429
|
+
fs.chmodSync(hidden, 0o755);
|
|
430
|
+
assert.equal(result.status, 2, output(result));
|
|
431
|
+
assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'the hand edit must not be replaced');
|
|
432
|
+
assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
|
|
433
|
+
assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
|
|
434
|
+
assert.equal(fs.existsSync(lockOf(box.plugin)), false);
|
|
435
|
+
assert.deepEqual(pluginsLeftovers(box.plugin), []);
|
|
436
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
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 {captureReviewBaseline,createReviewPackage,readReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
|
|
8
|
+
import {createFixCausePackage,readFixCausePackage,causeReviewPaths} from '../runtime/js/cm-fix/cause-package.mjs';
|
|
9
|
+
import {buildReviewPrompt,buildCauseReviewPrompt,createCodexReviewRun,createCauseReviewRun} from '../runtime/js/cm-ai/codex-review-adapter.mjs';
|
|
10
|
+
import {expandReviewData} from '../runtime/js/cm-ai/review-presentation.mjs';
|
|
11
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
12
|
+
import {EXECUTION_POLICY_V1} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
13
|
+
import {digest,requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
15
|
+
|
|
16
|
+
const INPUT_LIMIT=1048576,marker='\n<cm-review-data-json>\n';
|
|
17
|
+
// Captured from the a401 baseline INSTRUCTIONS, not copied from the repair.
|
|
18
|
+
// The legacy prompt of the current main: it carries the scope-revision unchangedScope
|
|
19
|
+
// clause added after #223, so its digest differs from the #223-era value.
|
|
20
|
+
// Re-pinned deliberately when the reviewer instructions gained the requirement-evidence rule,
|
|
21
|
+
// and again when they gained the cm-host-replay-v1 rule (host-observed baseline/red record).
|
|
22
|
+
const LEGACY_PREFIX_SHA='e84123f370deb7d48eeade10e6ebdae84950f569d52c4e81e5718e0a6ae837c3';
|
|
23
|
+
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
24
|
+
const checks=[{id:'unit',command:['node','synthetic-unit.mjs'],outcome:'passed',exitCode:0,evidence:'Synthetic unit evidence, not a command execution'},
|
|
25
|
+
{id:'boundary',command:['node','synthetic-boundary.mjs'],outcome:'passed',exitCode:0,evidence:'Synthetic boundary evidence, not a provider call'}];
|
|
26
|
+
function fixture(t){
|
|
27
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prompt-input-')));
|
|
28
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
29
|
+
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs'),feature='1.prompt';
|
|
30
|
+
fs.mkdirSync(cwd);fs.mkdirSync(path.join(specsRoot,feature),{recursive:true});
|
|
31
|
+
const identity={repositoryId:'synthetic',runId:'prompt-input',taskId:'T-001',attempt:1};
|
|
32
|
+
const writeSpec=(name,content)=>fs.writeFileSync(path.join(specsRoot,feature,name),content);
|
|
33
|
+
writeSpec('tasks.md','# Tasks\n- [ ] T-001: preserve complete prompt evidence ~1h\n\n## 验证要求\n- T-001: node --test prompt.test.mjs\n');
|
|
34
|
+
writeSpec('requirements.md','# Requirements\n- [ ] [AC-001] Supply all exact evidence\n- AC-002: Preserve every check and the final handoff\n');
|
|
35
|
+
writeSpec('design.md','# Interface\nexport function preserveEvidence(value): Evidence;\n\n## System context\nSynthetic approved system context must survive presentation.\n');
|
|
36
|
+
writeSpec('test-cases.json',JSON.stringify({cases:[{id:'TC-001',taskIds:['T-001'],acIds:['AC-001','AC-002'],description:'Entire evidence survives'}]}));
|
|
37
|
+
fs.writeFileSync(path.join(specsRoot,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsRoot)}));
|
|
38
|
+
fs.writeFileSync(path.join(cwd,'context.md'),'Synthetic required caller context; retain this whole file.\n');
|
|
39
|
+
const handoffPath=path.join(specsRoot,'handoff.json');
|
|
40
|
+
fs.writeFileSync(handoffPath,JSON.stringify({synthetic:true,summary:'Final handoff and Learning evidence must remain exact',checks:checks.map(c=>c.id)})+'\n');
|
|
41
|
+
return {root,cwd,specsRoot,feature,identity,handoffPath};
|
|
42
|
+
}
|
|
43
|
+
function material(f,size=360*1024,format='utf8'){
|
|
44
|
+
const prefix='export const value=1;\n//',room=size-Buffer.byteLength(prefix)-1;
|
|
45
|
+
const before=Buffer.from(prefix+(format==='unicode'?'界'.repeat(Math.floor(room/3))+'x'.repeat(room%3):'x'.repeat(room))+'\n');
|
|
46
|
+
if(format==='bom')Buffer.from([0xef,0xbb,0xbf]).copy(before);
|
|
47
|
+
if(format==='binary')before.fill(0xff);
|
|
48
|
+
const after=Buffer.from(before);after[format==='binary'?0:prefix.indexOf('1')]=format==='binary'?0xfe:0x32;
|
|
49
|
+
fs.writeFileSync(path.join(f.cwd,'source.mjs'),before);
|
|
50
|
+
const baseline=captureReviewBaseline({root:f.cwd,specsRoot:f.specsRoot,identity:f.identity,scope:['source.mjs'],requirements:['source.mjs','context.md'],
|
|
51
|
+
specification:{specsRoot:f.specsRoot,feature:f.feature}});
|
|
52
|
+
fs.writeFileSync(path.join(f.cwd,'source.mjs'),after);
|
|
53
|
+
const pkg=createReviewPackage({root:f.cwd,baseline,checks,handoffPath:f.handoffPath});
|
|
54
|
+
assert.deepEqual(readReviewPackage(pkg),pkg);return pkg;
|
|
55
|
+
}
|
|
56
|
+
function cause(f,{differentContext=false}={}){
|
|
57
|
+
const content=Buffer.from('x'.repeat(600*1024));fs.writeFileSync(path.join(f.cwd,'source.mjs'),content);
|
|
58
|
+
const context=Buffer.from(content);if(differentContext)context[0]=0x79;
|
|
59
|
+
fs.writeFileSync(path.join(f.cwd,'caller.mjs'),context);
|
|
60
|
+
const identity={...f.identity,taskId:'T-FIX-input'};
|
|
61
|
+
const status={identity,stage:'cause_review_required',learning:null,
|
|
62
|
+
reproduction:{status:'reproduced',next:'diagnose',observation:{id:'reproduce',command:['node','synthetic-repro.mjs'],outcome:'failed',exitCode:1,evidence:'Synthetic reproduced boundary',signatureMatched:true}},
|
|
63
|
+
diagnosis:{status:'diagnosed',rootCause:'Synthetic prompt boundary',plan:'Preserve all current evidence',crossLayer:false,affectedPaths:['source.mjs'],affectedModules:['source']},
|
|
64
|
+
rediagnosis:{historyDigest:digest('synthetic history'),priorPackageDigest:digest('synthetic old package'),priorObservationDigest:digest('synthetic old observation'),reason:'Retain caller context',
|
|
65
|
+
reviewFeedback:{verdict:'changes_requested',packageDigest:digest('synthetic old package'),examinedPaths:['caller.mjs','source.mjs'],
|
|
66
|
+
findings:[{id:'F1',severity:'P2',path:'caller.mjs',message:'Caller context is required',evidence:'Synthetic context fixture'}],summary:'Synthetic earlier feedback'}}};
|
|
67
|
+
const pkg=createFixCausePackage({codeProject:f.cwd,defect:'Synthetic input size boundary',status});
|
|
68
|
+
assert.deepEqual(readFixCausePackage(pkg),pkg);assert.deepEqual(pkg.contextFiles.map(file=>file.path),['caller.mjs']);return pkg;
|
|
69
|
+
}
|
|
70
|
+
function request(pkg,provider){return requestFor({invocationId:'synthetic-review',identity:pkg.identity,role:'reviewer',provider,
|
|
71
|
+
requestedModel:'synthetic',contextId:'synthetic-review-context',payload:{reviewPackage:pkg,priorReview:null}});}
|
|
72
|
+
function parse(prompt){const at=prompt.indexOf(marker);assert(at>0);return {prefix:prompt.slice(0,at),data:JSON.parse(prompt.slice(at+marker.length))};}
|
|
73
|
+
function expected(pkg,isCause=false){return {reviewPackage:pkg,priorReview:null,examinedPaths:isCause?causeReviewPaths(pkg):reviewPaths(pkg),
|
|
74
|
+
...(!isCause&&pkg.handoff?{handoffPath:pkg.handoff.path}:{})};}
|
|
75
|
+
function complete(prompt,pkg,isCause=false){
|
|
76
|
+
const parsed=parse(prompt);assert(parsed.data.presentation,'Large fallback must retain a complete inline table');
|
|
77
|
+
const restored=expandReviewData(parsed.data),original=expected(pkg,isCause);
|
|
78
|
+
assert.deepEqual(restored,original);assert.equal(digest(restored),digest(original));
|
|
79
|
+
assert.equal(restored.reviewPackage.packageDigest,pkg.packageDigest);
|
|
80
|
+
(isCause?readFixCausePackage:readReviewPackage)(restored.reviewPackage);return parsed.data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
test('policy-null large Codex implementation prompt fits the input boundary with every canonical evidence byte preserved',t=>{
|
|
84
|
+
const f=fixture(t),pkg=material(f),raw=buildReviewPrompt(request(pkg,'claude'),'claude');
|
|
85
|
+
assert(Buffer.byteLength(raw,'utf8')>INPUT_LIMIT);assert.deepEqual(parse(raw).data,expected(pkg));
|
|
86
|
+
const prompt=buildReviewPrompt(request(pkg,'codex'),'codex');
|
|
87
|
+
assert(Buffer.byteLength(prompt,'utf8')<=INPUT_LIMIT,'CM_CODEX_PROMPT_INPUT: final complete Codex prompt must fit the conservative UTF-8 input bound');
|
|
88
|
+
const data=complete(prompt,pkg),restored=expandReviewData(data).reviewPackage;
|
|
89
|
+
assert.deepEqual(restored.checks,checks);assert.deepEqual(restored.handoff,pkg.handoff);assert.deepEqual(restored.specification,pkg.specification);
|
|
90
|
+
assert.deepEqual(restored.requirements,pkg.requirements);assert.equal(restored.specification.acceptanceCriteria.length,2);
|
|
91
|
+
assert.match(restored.specification.designExcerpt,/System context/);assert.equal(restored.specification.testCases.length,1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('small policy-null Codex and unchanged Claude keep the exact legacy prefix and serialized evidence',t=>{
|
|
95
|
+
const f=fixture(t),pkg=material(f,128),codex=buildReviewPrompt(request(pkg,'codex'),'codex'),claude=buildReviewPrompt(request(pkg,'claude'),'claude');
|
|
96
|
+
assert.equal(codex,claude);const parsed=parse(codex);assert.equal(sha(parsed.prefix),LEGACY_PREFIX_SHA);
|
|
97
|
+
assert.equal(codex,parsed.prefix+marker+JSON.stringify(expected(pkg)));assert.equal(parsed.data.presentation,undefined);
|
|
98
|
+
assert(Buffer.byteLength(codex,'utf8')<INPUT_LIMIT);
|
|
99
|
+
const large=material(f),largeClaude=buildReviewPrompt(request(large,'claude'),'claude');
|
|
100
|
+
assert.equal(sha(parse(largeClaude).prefix),LEGACY_PREFIX_SHA);assert.equal(parse(largeClaude).data.presentation,undefined);
|
|
101
|
+
assert.equal(largeClaude,parsed.prefix+marker+JSON.stringify(expected(large)));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('the existing explicit policy still chooses the same full or compact representation for both providers',t=>{
|
|
105
|
+
const f=fixture(t);
|
|
106
|
+
for(const size of [128,360*1024]){
|
|
107
|
+
const pkg=material(f,size),codex=buildReviewPrompt(request(pkg,'codex'),'codex',EXECUTION_POLICY_V1),claude=buildReviewPrompt(request(pkg,'claude'),'claude',EXECUTION_POLICY_V1);
|
|
108
|
+
assert.equal(codex,claude);assert(Buffer.byteLength(codex,'utf8')<=INPUT_LIMIT);
|
|
109
|
+
if(size===128){assert.equal(codex,buildReviewPrompt(request(pkg,'codex'),'codex'));assert.equal(parse(codex).data.presentation,undefined);}
|
|
110
|
+
else complete(codex,pkg);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('a large legal cause review retains all diagnosed files, round-two caller context and feedback',t=>{
|
|
115
|
+
const f=fixture(t),pkg=cause(f),raw=buildCauseReviewPrompt(request(pkg,'claude'),'claude');assert(Buffer.byteLength(raw,'utf8')>INPUT_LIMIT);
|
|
116
|
+
assert.deepEqual(parse(raw).data,expected(pkg,true));
|
|
117
|
+
const prompt=buildCauseReviewPrompt(request(pkg,'codex'),'codex');
|
|
118
|
+
assert(Buffer.byteLength(prompt,'utf8')<=INPUT_LIMIT,'CM_CODEX_PROMPT_INPUT: complete cause evidence and context must fit before dispatch');
|
|
119
|
+
complete(prompt,pkg,true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('uncompressible implementation and cause prompts fail before a worker sees any truncated evidence',t=>{
|
|
123
|
+
const f=fixture(t),pkg=material(f,700*1024);let calls=0;
|
|
124
|
+
const worker=()=>{calls++;throw Error('Unreachable: no provider or CLI is authorized in this fixture');};
|
|
125
|
+
const control={signal:new AbortController().signal,onEvent(){}};
|
|
126
|
+
for(const policy of [null,EXECUTION_POLICY_V1]){
|
|
127
|
+
assert.throws(()=>buildReviewPrompt(request(pkg,'codex'),'codex',policy),{code:'limit_exceeded'});
|
|
128
|
+
assert.throws(()=>createCodexReviewRun(worker,policy)(request(pkg,'codex'),control),{code:'limit_exceeded'});
|
|
129
|
+
}
|
|
130
|
+
const unicode=material(f,600*1024,'unicode'),unicodeCompact=buildReviewPrompt(request(unicode,'claude'),'claude',EXECUTION_POLICY_V1);
|
|
131
|
+
assert(unicodeCompact.length<INPUT_LIMIT);assert(Buffer.byteLength(unicodeCompact,'utf8')>INPUT_LIMIT);
|
|
132
|
+
for(const policy of [null,EXECUTION_POLICY_V1]){
|
|
133
|
+
assert.throws(()=>buildReviewPrompt(request(unicode,'codex'),'codex',policy),{code:'limit_exceeded'});
|
|
134
|
+
assert.throws(()=>createCodexReviewRun(worker,policy)(request(unicode,'codex'),control),{code:'limit_exceeded'});
|
|
135
|
+
}
|
|
136
|
+
const causePackage=cause(f,{differentContext:true});
|
|
137
|
+
for(const policy of [null,EXECUTION_POLICY_V1]){
|
|
138
|
+
assert.throws(()=>buildCauseReviewPrompt(request(causePackage,'codex'),'codex',policy),{code:'limit_exceeded'});
|
|
139
|
+
assert.throws(()=>createCauseReviewRun(worker,'codex',policy)(request(causePackage,'codex'),control),{code:'limit_exceeded'});
|
|
140
|
+
}
|
|
141
|
+
assert.equal(calls,0);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('binary and BOM source bytes survive the bounded prompt fallback without lossy UTF-8 conversion',t=>{
|
|
145
|
+
const f=fixture(t);
|
|
146
|
+
for(const format of ['binary','bom']){
|
|
147
|
+
const pkg=material(f,300*1024,format),prompt=buildReviewPrompt(request(pkg,'codex'),'codex');
|
|
148
|
+
assert(Buffer.byteLength(prompt,'utf8')<=INPUT_LIMIT,'CM_CODEX_PROMPT_INPUT: binary-preserving fallback must fit in full');
|
|
149
|
+
const data=complete(prompt,pkg),before=data.reviewPackage.changes[0].before;
|
|
150
|
+
assert.equal(data.contents[before.contentRef].encoding,'base64');
|
|
151
|
+
assert.equal(Buffer.from(expandReviewData(data).reviewPackage.changes[0].before.contentBase64,'base64').length,300*1024);
|
|
152
|
+
}
|
|
153
|
+
});
|