@aibyzero/cm-workflow 0.10.5
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 +30 -0
- package/AGENTS.md +74 -0
- package/CONTRIBUTING.md +62 -0
- package/LICENSE +21 -0
- package/README.md +263 -0
- package/SECURITY.md +49 -0
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/VERSION +1 -0
- package/agents/cm-backend-agent.md +34 -0
- package/agents/cm-contract-agent.md +34 -0
- package/agents/cm-database-agent.md +34 -0
- package/agents/cm-frontend-agent.md +33 -0
- package/agents/cm-miniprogram-agent.md +33 -0
- package/agents/cm-ui-agent.md +34 -0
- package/assets/docs/command-picker-mobile.svg +56 -0
- package/assets/docs/command-picker.svg +56 -0
- package/assets/docs/user-guide-hero-mobile.svg +35 -0
- package/assets/docs/user-guide-hero.svg +36 -0
- package/assets/readme/delivery-flow.svg +86 -0
- package/assets/readme/hero.svg +77 -0
- package/assets/readme/recovery-record.svg +73 -0
- package/assets/readme/test-evidence.svg +64 -0
- package/compat/claude-commands/cm-ai.md +3 -0
- package/compat/claude-commands/cm-check.md +3 -0
- package/compat/claude-commands/cm-fix.md +3 -0
- package/compat/claude-commands/cm-idea.md +3 -0
- package/compat/claude-commands/cm-init.md +3 -0
- package/compat/claude-commands/cm-prd.md +3 -0
- package/compat/claude-commands/cm-refactor.md +3 -0
- package/compat/claude-commands/cm-test.md +3 -0
- package/docs/architecture.md +155 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a1-handoff.json +57 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a2-handoff.json +58 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-r1.md +121 -0
- package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-a1-handoff.json +56 -0
- package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-r1.md +100 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a1-handoff.json +61 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a2-handoff.json +63 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r1.md +58 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r2.md +55 -0
- package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-a1-handoff.json +65 -0
- package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-r1.md +88 -0
- package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r1.md +33 -0
- package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r2.md +31 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a1-handoff.json +56 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a2-handoff.json +85 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r1.md +53 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r2.md +80 -0
- package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-a1-handoff.json +35 -0
- package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-r1.md +33 -0
- package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r1.md +30 -0
- package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r2.md +16 -0
- package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-a1-handoff.json +40 -0
- package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-r1.md +30 -0
- package/docs/fixes/20260729-windows-cp1252-log-output.md +65 -0
- package/docs/fixes/20260804-manifest-runtime-checkbox-drift.md +67 -0
- package/docs/fixes/20260806-model-call-boundary-identity.md +80 -0
- package/docs/fixes/20260807-prelanding-integrity.md +58 -0
- package/docs/fixes/20260826-openai-compatible-depth-fixture.md +39 -0
- package/docs/fixes/20260903-cm-js-n1n2-admission-r1.md +64 -0
- package/docs/fixes/20260903-cm-js-n1n2-admission-successor.md +83 -0
- package/docs/fixes/20260903-s4c1b-v3-cancel-throw.md +89 -0
- package/docs/fixes/20260904-f01-codex-dual-failure-terminal.md +89 -0
- package/docs/fixes/20260907-wip-triage-log.md +44 -0
- package/docs/installation.md +202 -0
- package/docs/js-workflow-control.md +1010 -0
- package/docs/sample-prd/prd-funding-rate-alert.md +42 -0
- package/docs/sample-specs/docs//351/234/200/346/261/202/347/244/272/344/276/213.md +24 -0
- package/docs/user-guide.md +526 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/README.md +19 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.excalidraw +3650 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.mp4 +0 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.png +0 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.spec.json +223 -0
- package/install-codex.sh +184 -0
- package/install.ps1 +206 -0
- package/install.sh +244 -0
- package/package.json +58 -0
- package/runtime/external-expert.md +302 -0
- package/runtime/js/cm-ai/accepted-fix.mjs +28 -0
- package/runtime/js/cm-ai/claude-developer-adapter.mjs +6 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +16 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +53 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +107 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +353 -0
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +217 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +538 -0
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +119 -0
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +172 -0
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +320 -0
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +107 -0
- package/runtime/js/cm-ai/code-projects.mjs +85 -0
- package/runtime/js/cm-ai/codex-config.mjs +48 -0
- package/runtime/js/cm-ai/codex-developer-adapter.mjs +5 -0
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +6 -0
- package/runtime/js/cm-ai/codex-developer-output.schema.json +37 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +73 -0
- package/runtime/js/cm-ai/contracts.mjs +156 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +93 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +504 -0
- package/runtime/js/cm-ai/effect-contract.mjs +102 -0
- package/runtime/js/cm-ai/execution-platform.mjs +7 -0
- package/runtime/js/cm-ai/execution-store.mjs +211 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +40 -0
- package/runtime/js/cm-ai/gate-bridge.mjs +25 -0
- package/runtime/js/cm-ai/host-bootstrap.mjs +170 -0
- package/runtime/js/cm-ai/host-check.mjs +89 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +125 -0
- package/runtime/js/cm-ai/host-documentation.mjs +40 -0
- package/runtime/js/cm-ai/host-handoff.mjs +71 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +58 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +238 -0
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +131 -0
- package/runtime/js/cm-ai/host-qa-fix.mjs +30 -0
- package/runtime/js/cm-ai/host-qa-policy.mjs +70 -0
- package/runtime/js/cm-ai/host-review-authority.mjs +36 -0
- package/runtime/js/cm-ai/host-review-file.mjs +56 -0
- package/runtime/js/cm-ai/host-role-routing.mjs +41 -0
- package/runtime/js/cm-ai/host-session.mjs +96 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +53 -0
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +45 -0
- package/runtime/js/cm-ai/host.mjs +20 -0
- package/runtime/js/cm-ai/index.mjs +7 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +86 -0
- package/runtime/js/cm-ai/qa-fix-definition.mjs +21 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +38 -0
- package/runtime/js/cm-ai/review-package.mjs +426 -0
- package/runtime/js/cm-ai/review-result.schema.json +40 -0
- package/runtime/js/cm-ai/review-runner.mjs +35 -0
- package/runtime/js/cm-ai/task-commit-codec.mjs +54 -0
- package/runtime/js/cm-ai/task-commit.mjs +201 -0
- package/runtime/js/cm-ai/task-owner.mjs +97 -0
- package/runtime/js/cm-ai/task-runner.mjs +766 -0
- package/runtime/js/cm-ai/tool-preview.mjs +205 -0
- package/runtime/js/cm-ai/worker-claude.mjs +104 -0
- package/runtime/js/cm-ai/worker-codex-developer.mjs +124 -0
- package/runtime/js/cm-ai/worker-codex.mjs +143 -0
- package/runtime/js/cm-check/host.mjs +101 -0
- package/runtime/js/cm-fix/baseline.mjs +70 -0
- package/runtime/js/cm-fix/cause-evidence.mjs +24 -0
- package/runtime/js/cm-fix/cause-invocation.mjs +40 -0
- package/runtime/js/cm-fix/cause-package.mjs +68 -0
- package/runtime/js/cm-fix/dossier.mjs +140 -0
- package/runtime/js/cm-fix/execution.mjs +1549 -0
- package/runtime/js/cm-fix/final-review-evidence.mjs +20 -0
- package/runtime/js/cm-fix/final-review.mjs +156 -0
- package/runtime/js/cm-fix/finish.mjs +124 -0
- package/runtime/js/cm-fix/handoff.mjs +64 -0
- package/runtime/js/cm-fix/host-review.mjs +38 -0
- package/runtime/js/cm-fix/host.mjs +96 -0
- package/runtime/js/cm-fix/investigation.mjs +25 -0
- package/runtime/js/cm-fix/layout.mjs +17 -0
- package/runtime/js/cm-fix/learning-writeback.mjs +86 -0
- package/runtime/js/cm-fix/learning.mjs +31 -0
- package/runtime/js/cm-fix/metrics.mjs +75 -0
- package/runtime/js/cm-fix/progress.mjs +64 -0
- package/runtime/js/cm-fix/protected-edits.mjs +95 -0
- package/runtime/js/cm-fix/qa-source.mjs +58 -0
- package/runtime/js/cm-fix/red-test.mjs +92 -0
- package/runtime/js/cm-fix/regression-evidence.mjs +64 -0
- package/runtime/js/cm-fix/regression.mjs +41 -0
- package/runtime/js/cm-fix/repair.mjs +95 -0
- package/runtime/js/cm-fix/reproduce.mjs +54 -0
- package/runtime/js/cm-fix/retrospective.mjs +41 -0
- package/runtime/js/cm-fix/review-baseline.mjs +47 -0
- package/runtime/js/cm-fix/start.mjs +49 -0
- package/runtime/js/cm-fix/test-author.mjs +63 -0
- package/runtime/js/cm-fix/visual.mjs +72 -0
- package/runtime/js/cm-fix/walkthrough.mjs +126 -0
- package/runtime/js/cm-idea/session.mjs +79 -0
- package/runtime/js/cm-init/draft-generation.mjs +66 -0
- package/runtime/js/cm-init/draft-inspection.mjs +70 -0
- package/runtime/js/cm-init/project-analysis.mjs +60 -0
- package/runtime/js/cm-init/project-scan.mjs +55 -0
- package/runtime/js/cm-init/review-evidence.mjs +80 -0
- package/runtime/js/cm-prd/accepted-design.mjs +46 -0
- package/runtime/js/cm-prd/analysis.mjs +260 -0
- package/runtime/js/cm-prd/change.mjs +268 -0
- package/runtime/js/cm-prd/correction-check.mjs +49 -0
- package/runtime/js/cm-prd/design-risk.mjs +30 -0
- package/runtime/js/cm-prd/disposition-plan.mjs +33 -0
- package/runtime/js/cm-prd/draft-save.mjs +122 -0
- package/runtime/js/cm-prd/draft.mjs +70 -0
- package/runtime/js/cm-prd/materials.mjs +48 -0
- package/runtime/js/cm-prd/review-correction.mjs +158 -0
- package/runtime/js/cm-prd/review-disposition.mjs +96 -0
- package/runtime/js/cm-prd/review-findings.mjs +36 -0
- package/runtime/js/cm-prd/review-host.mjs +48 -0
- package/runtime/js/cm-prd/review-preparation.mjs +49 -0
- package/runtime/js/cm-prd/review-publication.mjs +56 -0
- package/runtime/js/cm-prd/self-check.mjs +75 -0
- package/runtime/js/cm-prd/session.mjs +74 -0
- package/runtime/js/cm-prd/summary.mjs +133 -0
- package/runtime/js/cm-refactor/host.mjs +2 -0
- package/runtime/js/cm-refactor/records.mjs +86 -0
- package/runtime/js/cm-refactor/workflow.mjs +478 -0
- package/runtime/js/cm-test/declared-command.mjs +32 -0
- package/runtime/js/cm-test/host.mjs +319 -0
- package/runtime/js/cm-test/logic-results.mjs +39 -0
- package/runtime/js/cm-test/recovery.mjs +58 -0
- package/runtime/js/cm-test/session.mjs +56 -0
- package/runtime/js/cm-test/source-snapshot.mjs +136 -0
- package/runtime/logging.md +207 -0
- package/runtime/model-efficiency.md +201 -0
- package/runtime/orchestration.md +113 -0
- package/runtime/project-context.md +43 -0
- package/runtime/project-learning.md +49 -0
- package/runtime/review.md +140 -0
- package/runtime/steelman-review.md +111 -0
- package/runtime/task-gates.md +283 -0
- package/runtime/task-handoff.schema.json +103 -0
- package/runtime/test-contract.md +212 -0
- package/runtime/workflow-config.md +118 -0
- package/runtime/workflow-routing.md +82 -0
- package/scripts/cm-ai-admission.mjs +50 -0
- package/scripts/cm-ai-admission.test.mjs +38 -0
- package/scripts/cm-ai-batch-host.mjs +77 -0
- package/scripts/cm-ai-batch-host.test.mjs +155 -0
- package/scripts/cm-ai-batch-run.mjs +136 -0
- package/scripts/cm-ai-batch-run.test.mjs +128 -0
- package/scripts/cm-ai-bootstrap.test.mjs +228 -0
- package/scripts/cm-ai-fix-integration.test.mjs +233 -0
- package/scripts/cm-ai-host.mjs +175 -0
- package/scripts/cm-ai-host.test.mjs +368 -0
- package/scripts/cm-ai-multi-root.test.mjs +289 -0
- package/scripts/cm-ai-nested-execution.test.mjs +313 -0
- package/scripts/cm-ai-run.mjs +293 -0
- package/scripts/cm-ai-run.test.mjs +336 -0
- package/scripts/cm-check-entry.mjs +120 -0
- package/scripts/cm-check-host.mjs +29 -0
- package/scripts/cm-check-host.test.mjs +71 -0
- package/scripts/cm-check-runtime.ps1 +69 -0
- package/scripts/cm-check-runtime.sh +910 -0
- package/scripts/cm-claude-probe.test.mjs +54 -0
- package/scripts/cm-claude-review-stream.test.mjs +45 -0
- package/scripts/cm-claude-worker.test.mjs +92 -0
- package/scripts/cm-codex-developer-adapter.test.mjs +85 -0
- package/scripts/cm-codex-developer-worker.test.mjs +128 -0
- package/scripts/cm-codex-review-progress.test.mjs +96 -0
- package/scripts/cm-execution-platform.test.mjs +47 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +72 -0
- package/scripts/cm-fix-cause-package.test.mjs +68 -0
- package/scripts/cm-fix-code-association.test.mjs +55 -0
- package/scripts/cm-fix-entry.mjs +132 -0
- package/scripts/cm-fix-execution.test.mjs +63 -0
- package/scripts/cm-fix-final-review.test.mjs +124 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +34 -0
- package/scripts/cm-fix-host-review.test.mjs +261 -0
- package/scripts/cm-fix-host-sequence.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +89 -0
- package/scripts/cm-fix-host.test.mjs +105 -0
- package/scripts/cm-fix-learning-writeback.test.mjs +73 -0
- package/scripts/cm-fix-learning.test.mjs +66 -0
- package/scripts/cm-fix-metrics.test.mjs +58 -0
- package/scripts/cm-fix-no-existing-tests.test.mjs +92 -0
- package/scripts/cm-fix-observation-dossier.test.mjs +452 -0
- package/scripts/cm-fix-progress.test.mjs +45 -0
- package/scripts/cm-fix-protected-edits.test.mjs +54 -0
- package/scripts/cm-fix-qa-source.test.mjs +206 -0
- package/scripts/cm-fix-red-owner.test.mjs +143 -0
- package/scripts/cm-fix-red-test.test.mjs +38 -0
- package/scripts/cm-fix-regression.test.mjs +57 -0
- package/scripts/cm-fix-repair-owner.test.mjs +370 -0
- package/scripts/cm-fix-repair.test.mjs +68 -0
- package/scripts/cm-fix-reproduce.test.mjs +31 -0
- package/scripts/cm-fix-retrospective.test.mjs +46 -0
- package/scripts/cm-fix-review-baseline.test.mjs +54 -0
- package/scripts/cm-fix-review-recovery.test.mjs +197 -0
- package/scripts/cm-fix-test-author.test.mjs +105 -0
- package/scripts/cm-fix-visual-bare.test.mjs +171 -0
- package/scripts/cm-fix-walkthrough.test.mjs +45 -0
- package/scripts/cm-host-check.test.mjs +113 -0
- package/scripts/cm-host-documentation.test.mjs +45 -0
- package/scripts/cm-host-handoff.test.mjs +58 -0
- package/scripts/cm-host-qa-executor.test.mjs +156 -0
- package/scripts/cm-host-qa-policy.test.mjs +59 -0
- package/scripts/cm-host-review-authority.test.mjs +60 -0
- package/scripts/cm-host-role-routing.test.mjs +33 -0
- package/scripts/cm-idea-entry.mjs +104 -0
- package/scripts/cm-idea-host.mjs +144 -0
- package/scripts/cm-idea-host.test.mjs +75 -0
- package/scripts/cm-idea-recovery.test.mjs +90 -0
- package/scripts/cm-init-analysis-host.test.mjs +50 -0
- package/scripts/cm-init-draft-generation.test.mjs +52 -0
- package/scripts/cm-init-draft-inspection.test.mjs +41 -0
- package/scripts/cm-init-entry.mjs +170 -0
- package/scripts/cm-init-host.mjs +284 -0
- package/scripts/cm-init-host.test.mjs +231 -0
- package/scripts/cm-init-project-analysis.test.mjs +47 -0
- package/scripts/cm-init-project-scan.test.mjs +41 -0
- package/scripts/cm-init-revision-host.test.mjs +61 -0
- package/scripts/cm-init-session.test.mjs +122 -0
- package/scripts/cm-log-event.mjs +538 -0
- package/scripts/cm-log-event.py +133 -0
- package/scripts/cm-log-event.test.mjs +70 -0
- package/scripts/cm-openai-compatible-call.py +661 -0
- package/scripts/cm-prd-analysis.test.mjs +67 -0
- package/scripts/cm-prd-completion.test.mjs +190 -0
- package/scripts/cm-prd-design-phase.test.mjs +296 -0
- package/scripts/cm-prd-draft-save.test.mjs +63 -0
- package/scripts/cm-prd-draft.test.mjs +39 -0
- package/scripts/cm-prd-entry.mjs +245 -0
- package/scripts/cm-prd-host.mjs +273 -0
- package/scripts/cm-prd-host.test.mjs +169 -0
- package/scripts/cm-prd-materials.test.mjs +41 -0
- package/scripts/cm-prd-review-claim.test.mjs +42 -0
- package/scripts/cm-prd-review-disposition.test.mjs +196 -0
- package/scripts/cm-prd-review-gate.mjs +194 -0
- package/scripts/cm-prd-review-gate.py +26 -0
- package/scripts/cm-prd-review-host.test.mjs +30 -0
- package/scripts/cm-prd-review-preparation.test.mjs +69 -0
- package/scripts/cm-prd-review-publication.test.mjs +95 -0
- package/scripts/cm-prd-revision.test.mjs +32 -0
- package/scripts/cm-prd-self-check.test.mjs +23 -0
- package/scripts/cm-prd-sources.test.mjs +76 -0
- package/scripts/cm-prd-timing.py +272 -0
- package/scripts/cm-refactor-entry.mjs +145 -0
- package/scripts/cm-refactor-host.mjs +26 -0
- package/scripts/cm-refactor-host.test.mjs +201 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +67 -0
- package/scripts/cm-review-inventory.test.mjs +109 -0
- package/scripts/cm-spec-manifest.mjs +104 -0
- package/scripts/cm-spec-manifest.py +26 -0
- package/scripts/cm-task-gate.mjs +879 -0
- package/scripts/cm-task-gate.py +312 -0
- package/scripts/cm-task-gate.test.mjs +202 -0
- package/scripts/cm-test-declared-command.test.mjs +18 -0
- package/scripts/cm-test-entry.mjs +231 -0
- package/scripts/cm-test-host.mjs +40 -0
- package/scripts/cm-test-host.test.mjs +169 -0
- package/scripts/cm-test-logic-results.test.mjs +26 -0
- package/scripts/cm-test-session.test.mjs +138 -0
- package/scripts/cm-usage-report.py +516 -0
- package/scripts/cm-workflow-config.mjs +463 -0
- package/scripts/cm-workflow-config.test.mjs +181 -0
- package/scripts/cm-workflow.mjs +36 -0
- package/scripts/cm-workflow.test.mjs +51 -0
- package/scripts/cm_workflow_config.py +52 -0
- package/scripts/fixtures/claude-review-process.mjs +35 -0
- package/scripts/fixtures/codex-review-process.mjs +22 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +320 -0
- package/scripts/fixtures/spec-manifest-python-oracle.py +172 -0
- package/scripts/scan-public-safety.py +117 -0
- package/scripts/test-cm-log-event.py +1213 -0
- package/scripts/test-cm-openai-compatible-call.py +1185 -0
- package/scripts/test-cm-prd-review-gate.py +272 -0
- package/scripts/test-cm-prd-timing.py +168 -0
- package/scripts/test-cm-usage-report.py +584 -0
- package/scripts/test-npm-install.py +171 -0
- package/scripts/test-scan-public-safety.py +76 -0
- package/scripts/test-shell-compat.sh +365 -0
- package/scripts/test-spec-manifest.py +263 -0
- package/scripts/test-task-gate.py +46 -0
- package/scripts/test-workflow-config.py +30 -0
- package/scripts/validate-public-repo.py +245 -0
- package/scripts/validate-test-cases.mjs +71 -0
- package/scripts/validate-test-cases.py +27 -0
- package/scripts/validate-test-cases.test.mjs +36 -0
- package/skills/cm-ai/SKILL.md +137 -0
- package/skills/cm-ai/references/N1-init.md +108 -0
- package/skills/cm-ai/references/N2-enter-feature.md +38 -0
- package/skills/cm-ai/references/N3-execute-task.md +123 -0
- package/skills/cm-ai/references/N4-review.md +103 -0
- package/skills/cm-ai/references/N5-mark-done.md +117 -0
- package/skills/cm-ai/references/N6-qa-eval.md +102 -0
- package/skills/cm-ai/references/N7-context.md +23 -0
- package/skills/cm-ai/references/N8-finish.md +103 -0
- package/skills/cm-ai/references/js-host.md +126 -0
- package/skills/cm-backend-engineer/SKILL.md +100 -0
- package/skills/cm-check/SKILL.md +52 -0
- package/skills/cm-check/references/js-host.md +44 -0
- package/skills/cm-contract-engineer/SKILL.md +136 -0
- package/skills/cm-database-engineer/SKILL.md +89 -0
- package/skills/cm-devops-engineer/SKILL.md +137 -0
- package/skills/cm-doc-syncer/SKILL.md +150 -0
- package/skills/cm-finance-expert/SKILL.md +85 -0
- package/skills/cm-fix/SKILL.md +199 -0
- package/skills/cm-fix/references/cross-boundary-debugging.md +44 -0
- package/skills/cm-fix/references/js-host.md +135 -0
- package/skills/cm-frontend-engineer/SKILL.md +127 -0
- package/skills/cm-idea/SKILL.md +55 -0
- package/skills/cm-idea/references/domains/trading.md +97 -0
- package/skills/cm-idea/references/example-prd.md +92 -0
- package/skills/cm-idea/references/idea-to-prd.md +282 -0
- package/skills/cm-idea/references/js-host.md +63 -0
- package/skills/cm-init/SKILL.md +191 -0
- package/skills/cm-init/references/js-host.md +123 -0
- package/skills/cm-miniprogram-engineer/SKILL.md +141 -0
- package/skills/cm-miniprogram-engineer/references/platform-readiness.md +58 -0
- package/skills/cm-miniprogram-engineer/references/release-checklist.md +59 -0
- package/skills/cm-prd/SKILL.md +548 -0
- package/skills/cm-prd/references/brownfield.md +13 -0
- package/skills/cm-prd/references/change-mode.md +145 -0
- package/skills/cm-prd/references/context-scope.md +62 -0
- package/skills/cm-prd/references/greenfield.md +80 -0
- package/skills/cm-prd/references/js-change-recovery.md +57 -0
- package/skills/cm-prd/references/js-host.md +98 -0
- package/skills/cm-prd/references/phase-timing.md +68 -0
- package/skills/cm-prd/references/spec-self-check.md +22 -0
- package/skills/cm-product-manager/SKILL.md +83 -0
- package/skills/cm-qa-engineer/SKILL.md +142 -0
- package/skills/cm-refactor/SKILL.md +236 -0
- package/skills/cm-refactor/references/js-batch.md +75 -0
- package/skills/cm-refactor/references/js-host.md +78 -0
- package/skills/cm-test/SKILL.md +288 -0
- package/skills/cm-test/references/js-host.md +118 -0
- package/skills/cm-ui-engineer/SKILL.md +105 -0
- package/skills/codebase-context/SKILL.md +489 -0
- package/skills/darwin-skill/NOTICE.md +26 -0
- package/skills/darwin-skill/README.md +272 -0
- package/skills/darwin-skill/SKILL.md +492 -0
- package/skills/darwin-skill/references/runtime-neutrality.md +68 -0
- package/skills/darwin-skill/references/skilllens-evidence.md +142 -0
- package/skills/darwin-skill/scripts/screenshot.mjs +71 -0
- package/skills/darwin-skill/templates/result-card-dark.html +698 -0
- package/skills/darwin-skill/templates/result-card-white.html +444 -0
- package/skills/darwin-skill/templates/result-card.html +616 -0
- package/skills/external-expert/SKILL.md +250 -0
- package/templates/arch-reference.md +68 -0
- package/templates/auto-update/cm-announce.sh +19 -0
- package/templates/auto-update/cm-update.sh +274 -0
- package/templates/cm-workflow.yml +52 -0
- package/templates/dashboard/dashboard.html +153 -0
- package/templates/dashboard/serve.sh +10 -0
- package/templates/hooks/pre-commit-cm-task-check +67 -0
- package/templates/pixel/cm-pixel.html +388 -0
- package/templates/pixel/cm-pixel.sh +212 -0
- package/templates/pixel/dev/README.md +20 -0
- package/templates/pixel/dev/atlas-preview.png +0 -0
- package/templates/pixel/dev/build.py +55 -0
- package/templates/pixel/dev/sheets/roguelikeChar_transparent.png +0 -0
- package/templates/pixel/dev/sheets/roguelikeCity_tilemap.png +0 -0
- package/templates/pixel/dev/sheets/roguelikeIndoor_transparent.png +0 -0
- package/templates/pixel/dev/template.html +388 -0
- package/templates/pixel/serve.sh +12 -0
- package/templates/refactor/cm-refactor-denies.json +14 -0
- package/templates/rules/backend-api.md +36 -0
- package/templates/rules/coding-style.md +44 -0
- package/templates/rules/database.md +27 -0
- package/templates/rules/finance.md +32 -0
- package/templates/rules/frontend.md +32 -0
- package/templates/rules/git-workflow.md +25 -0
- package/templates/rules/miniprogram.md +31 -0
- package/templates/rules/security.md +31 -0
- package/templates/rules/smart-contract.md +28 -0
- package/templates/rules/testing.md +36 -0
- package/templates/statusline/cm-statusline.sh +73 -0
- package/templates/ui-lens/cm-ui-lens-extract.mjs +55 -0
|
@@ -0,0 +1,113 @@
|
|
|
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 {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
7
|
+
import {captureReviewBaseline} from '../runtime/js/cm-ai/review-package.mjs';
|
|
8
|
+
import {createHostHandoff} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
9
|
+
import {loadHandoff,checkN4,checkN5} from './cm-task-gate.mjs';
|
|
10
|
+
import {developerArgs} from '../runtime/js/cm-ai/worker-codex-developer.mjs';
|
|
11
|
+
const identity={repositoryId:'test',runId:'run',taskId:'T-001',attempt:1};
|
|
12
|
+
const control=()=>({signal:new AbortController().signal});
|
|
13
|
+
const command=(id,code)=>({id,command:[process.execPath,'-e',code]});
|
|
14
|
+
async function fixture(fn){const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-check-')));
|
|
15
|
+
try{await fn(root);}finally{fs.rmSync(root,{recursive:true,force:true});}}
|
|
16
|
+
|
|
17
|
+
test('async output capture rejects safely and waits for process cleanup',()=>fixture(async cwd=>{
|
|
18
|
+
const check=createHostCheck({cwd,commands:[command('capture',
|
|
19
|
+
"require('node:fs').writeFileSync('pid',String(process.pid));process.on('SIGTERM',()=>{});console.log('fixture');setInterval(()=>{},1000)")],
|
|
20
|
+
timeoutMs:3000,onOutput:async()=>{throw Error('synthetic capture failure');}});
|
|
21
|
+
const [result]=await check({identity},control());
|
|
22
|
+
assert.equal(result.outcome,'unavailable');assert.equal(result.evidence,'host check: output_capture_failed');
|
|
23
|
+
assert.throws(()=>process.kill(Number(fs.readFileSync(path.join(cwd,'pid'),'utf8')),0),{code:'ESRCH'});
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
test('actual check output stays private while exit result feeds existing handoff',()=>fixture(async temp=>{
|
|
27
|
+
const cwd=path.join(temp,'code');fs.mkdirSync(cwd);
|
|
28
|
+
fs.writeFileSync(path.join(cwd,'a.txt'),'old');fs.writeFileSync(path.join(cwd,'requirements.md'),'synthetic task');
|
|
29
|
+
const baseline=captureReviewBaseline({root:cwd,identity,scope:['a.txt'],requirements:['requirements.md']});
|
|
30
|
+
fs.writeFileSync(path.join(cwd,'a.txt'),'new');
|
|
31
|
+
const check=createHostCheck({cwd,commands:[command('content',"require('node:assert/strict').equal(require('node:fs').readFileSync('a.txt','utf8'),'new');console.log('private output');")]});
|
|
32
|
+
const checks=await check({identity},control());assert.equal(checks[0].outcome,'passed');
|
|
33
|
+
assert(!checks[0].evidence.includes('private output'));
|
|
34
|
+
const handoffPath=path.join(temp,'handoff.json');createHostHandoff({root:cwd,baseline,checks,handoffPath});
|
|
35
|
+
assert.equal(loadHandoff(handoffPath).status,'ready_for_review');
|
|
36
|
+
}));
|
|
37
|
+
test('nonzero exit stops subsequent commands and does not report pass',()=>fixture(async cwd=>{
|
|
38
|
+
const check=createHostCheck({cwd,commands:[command('fail','process.exit(3)'),command('later',"require('node:fs').writeFileSync('unexpected','x')")]});
|
|
39
|
+
const results=await check({identity},control());assert.equal(results.length,1);
|
|
40
|
+
assert.equal(results[0].outcome,'failed');assert.equal(results[0].exitCode,3);
|
|
41
|
+
assert.equal(fs.existsSync(path.join(cwd,'unexpected')),false);
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
// Synthetic project scanner contract, not evidence of any real scanner's coverage.
|
|
45
|
+
for(const scenario of [
|
|
46
|
+
{name:'clean',code:0,outcome:'passed',exitCode:0},
|
|
47
|
+
{name:'finding',code:1,outcome:'failed',exitCode:1},
|
|
48
|
+
{name:'scanner-error',code:2,outcome:'failed',exitCode:2},
|
|
49
|
+
{name:'missing-tool',outcome:'unavailable',exitCode:null},
|
|
50
|
+
{name:'timeout',outcome:'unavailable',exitCode:null},
|
|
51
|
+
])test(`project security check ${scenario.name} reaches the existing review gate`,()=>fixture(async temp=>{
|
|
52
|
+
const cwd=path.join(temp,'code'),reviewsDir=path.join(temp,'reviews');
|
|
53
|
+
fs.mkdirSync(cwd);fs.mkdirSync(reviewsDir);
|
|
54
|
+
fs.writeFileSync(path.join(cwd,'app.txt'),'before');
|
|
55
|
+
fs.writeFileSync(path.join(cwd,'requirements.md'),'Run the declared project security check');
|
|
56
|
+
const baseline=captureReviewBaseline({root:cwd,identity,scope:['app.txt'],requirements:['requirements.md']});
|
|
57
|
+
fs.writeFileSync(path.join(cwd,'app.txt'),'after');
|
|
58
|
+
const security=scenario.name==='missing-tool'?{id:'security',command:[path.join(temp,'absent-scanner')]}:
|
|
59
|
+
command('security',scenario.name==='timeout'?'setInterval(()=>{},1000)':
|
|
60
|
+
// Misleading success text must never override a nonzero exit code.
|
|
61
|
+
`console.log('PASS synthetic private scanner output');process.exit(${scenario.code})`);
|
|
62
|
+
const check=createHostCheck({cwd,timeoutMs:scenario.name==='timeout'?1000:5000,
|
|
63
|
+
commands:[command('unit','process.exit(0)'),security,command('later','process.exit(0)')]});
|
|
64
|
+
const checks=await check({identity},control());
|
|
65
|
+
assert.equal(checks[0].outcome,'passed');
|
|
66
|
+
assert.equal(checks[1].outcome,scenario.outcome);assert.equal(checks[1].exitCode,scenario.exitCode);
|
|
67
|
+
const passed=scenario.outcome==='passed';assert.equal(checks.length,passed?3:2);
|
|
68
|
+
const handoff=path.join(reviewsDir,'work-T-001-a1-handoff.json');
|
|
69
|
+
createHostHandoff({root:cwd,baseline,checks,handoffPath:handoff,
|
|
70
|
+
evidence:['learning: no_relevant_lesson','learning: retrospective no_new_lesson']});
|
|
71
|
+
const payload=loadHandoff(handoff);
|
|
72
|
+
assert.equal(payload.status,passed?'ready_for_review':'blocked');
|
|
73
|
+
assert(payload.verification.every(row=>!row.evidence.includes('synthetic private scanner output')));
|
|
74
|
+
const selectors={handoff,reviewsDir,feature:'work',task:identity.taskId,projectRoot:cwd,requireLearning:true};
|
|
75
|
+
if(passed){
|
|
76
|
+
assert.equal(checkN4(selectors).content_bound,true);
|
|
77
|
+
assert.throws(()=>checkN5(selectors)); // Passing scans still requires independent Review.
|
|
78
|
+
}else{
|
|
79
|
+
assert(payload.blockers.some(value=>value.includes('security')));
|
|
80
|
+
assert.throws(()=>checkN4(selectors),/N4 requires a ready_for_review handoff/);
|
|
81
|
+
assert.throws(()=>checkN5(selectors),/N5 requires a ready_for_review handoff/);
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
test('native Codex profile allows business writes but protects specs for project checks',
|
|
85
|
+
{skip:process.platform!=='darwin'},()=>fixture(async cwd=>{
|
|
86
|
+
const specsRoot=path.join(cwd,'specs');fs.mkdirSync(specsRoot);
|
|
87
|
+
fs.writeFileSync(path.join(specsRoot,'tasks.md'),'host-owned');
|
|
88
|
+
const args=developerArgs({cwd,specsRoot,model:'fixture',schemaPath:'/unused'});
|
|
89
|
+
assert(!args.includes('--sandbox'));assert(!args.some(x=>x.startsWith('sandbox_workspace_write')));
|
|
90
|
+
assert(args.includes('default_permissions="cm-specs"'));
|
|
91
|
+
const check=createHostCheck({cwd,specsRoot,commands:[command('verify',`
|
|
92
|
+
const fs=require('node:fs'),assert=require('node:assert/strict');
|
|
93
|
+
const denied=fn=>assert.throws(fn,e=>['EPERM','EACCES'].includes(e.code));
|
|
94
|
+
fs.writeFileSync('business.txt','allowed');
|
|
95
|
+
assert.equal(fs.readFileSync('specs/tasks.md','utf8'),'host-owned');
|
|
96
|
+
denied(()=>fs.writeFileSync('specs/tasks.md','bad'));
|
|
97
|
+
denied(()=>fs.writeFileSync('specs/new.md','bad'));
|
|
98
|
+
denied(()=>fs.renameSync('specs','moved-specs'));
|
|
99
|
+
denied(()=>fs.writeFileSync('AGENTS.md','bad'));
|
|
100
|
+
const child=require('node:child_process').spawnSync(process.execPath,['-e',
|
|
101
|
+
'require("node:fs").writeFileSync("specs/tasks.md","bad")']);
|
|
102
|
+
assert.notEqual(child.status,0);
|
|
103
|
+
`)]});
|
|
104
|
+
const result=await check({identity},control());assert.equal(result[0].outcome,'passed',JSON.stringify(result));
|
|
105
|
+
assert.equal(fs.readFileSync(path.join(specsRoot,'tasks.md'),'utf8'),'host-owned');
|
|
106
|
+
assert.equal(fs.readFileSync(path.join(cwd,'business.txt'),'utf8'),'allowed');
|
|
107
|
+
}));
|
|
108
|
+
test('cancelled check dispatches nothing and hung check is unavailable',()=>fixture(async cwd=>{
|
|
109
|
+
const check=createHostCheck({cwd,timeoutMs:50,commands:[command('hang','setInterval(()=>{},1000)')]});
|
|
110
|
+
const ac=new AbortController();ac.abort();await assert.rejects(check({identity},{signal:ac.signal}),{code:'cancelled'});
|
|
111
|
+
const results=await check({identity},control());assert.equal(results[0].outcome,'unavailable');
|
|
112
|
+
assert.equal(results[0].evidence,'host check: timeout');
|
|
113
|
+
}));
|
|
@@ -0,0 +1,45 @@
|
|
|
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 {withHostDocumentation} from '../runtime/js/cm-ai/host-documentation.mjs';
|
|
7
|
+
import {requestFor,terminalFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
8
|
+
|
|
9
|
+
for(const mode of ['write','unchanged','later-feature','out-of-scope','unapproved-path','cancel'])
|
|
10
|
+
test(`pre-review documentation uses only the final approved task: ${mode}`,async()=>{
|
|
11
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-docs-')));
|
|
12
|
+
try{
|
|
13
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
|
|
14
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,'1.feature'),{recursive:true});
|
|
15
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Requirements\n');
|
|
16
|
+
fs.writeFileSync(path.join(codeProject,'README.md'),'# Before\n');
|
|
17
|
+
const features=mode==='later-feature'?['1.feature','2.later']:['1.feature'];
|
|
18
|
+
for(const feature of features){
|
|
19
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
20
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
21
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: implement\n');
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features}));
|
|
24
|
+
const identity={repositoryId:'docs',runId:'docs-test',taskId:'T-001',attempt:1};
|
|
25
|
+
const request=requestFor({invocationId:'docs-1',identity,role:'developer',provider:'codex',
|
|
26
|
+
requestedModel:'fixture',contextId:'author',payload:{scope:['README.md'],requirements:[{path:'requirements.md'}],priorReview:null}});
|
|
27
|
+
const controller=new AbortController();let writes=0;
|
|
28
|
+
const developer={provider:'codex',requestedModel:'fixture',contextId:'author',run:async()=>{
|
|
29
|
+
if(mode==='cancel')controller.abort();
|
|
30
|
+
return terminalFor({version:1,invocationId:request.invocationId,contextId:'author',provider:'codex',
|
|
31
|
+
effectiveModel:'unknown',status:'succeeded',accepted:true,result:{outcome:'implemented'}},request);
|
|
32
|
+
}};
|
|
33
|
+
const build=()=>withHostDocumentation({developer,specsDir,codeProject,feature:'1.feature',scope:['README.md'],
|
|
34
|
+
documentationSync:{paths:[mode==='unapproved-path'?'extra.md':'README.md'],run:async()=>{
|
|
35
|
+
writes++;
|
|
36
|
+
if(mode!=='unchanged')fs.writeFileSync(path.join(codeProject,mode==='out-of-scope'?'requirements.md':'README.md'),'# Updated\n');
|
|
37
|
+
return {status:'completed'};
|
|
38
|
+
}}});
|
|
39
|
+
if(mode==='unapproved-path')assert.throws(build,{code:'documentation_scope_required'});
|
|
40
|
+
else if(['out-of-scope','cancel'].includes(mode))await assert.rejects(build().run(request,{signal:controller.signal}),
|
|
41
|
+
{code:mode==='cancel'?'cancelled':'out_of_scope'});
|
|
42
|
+
else assert.equal((await build().run(request,{signal:controller.signal})).status,'succeeded');
|
|
43
|
+
assert.equal(writes,['later-feature','unapproved-path','cancel'].includes(mode)?0:1);
|
|
44
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
45
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import {captureReviewBaseline} from '../runtime/js/cm-ai/review-package.mjs';
|
|
7
|
+
import {createHostHandoff} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
8
|
+
import {loadHandoff,implementationSha256} from './cm-task-gate.mjs';
|
|
9
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
|
+
import {createCmAiTaskLearningApplication,createCmAiTaskLearningRetrospective} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
11
|
+
import {writeCmAiProjectLearning} from '../runtime/js/cm-ai/cm-ai-learning-writer.mjs';
|
|
12
|
+
import {writeCmAiTaskLearningHandoff,verifyCmAiTaskLearningHandoff} from '../runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs';
|
|
13
|
+
|
|
14
|
+
function fixture(fn){
|
|
15
|
+
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-host-handoff-')));
|
|
16
|
+
const root=path.join(temp,'code'),reviews=path.join(temp,'reviews');fs.mkdirSync(root);fs.mkdirSync(reviews);
|
|
17
|
+
fs.writeFileSync(path.join(root,'a.mjs'),'old');fs.writeFileSync(path.join(root,'requirements.md'),'synthetic task');
|
|
18
|
+
const baseline=captureReviewBaseline({root,identity:{repositoryId:'test',runId:'run',taskId:'T-001',attempt:1},
|
|
19
|
+
scope:['a.mjs'],requirements:['requirements.md']});
|
|
20
|
+
fs.writeFileSync(path.join(root,'a.mjs'),'new');
|
|
21
|
+
const input={root,baseline,handoffPath:path.join(reviews,'task-handoff.json'),
|
|
22
|
+
checks:[{id:'unit',command:['node','--test'],outcome:'passed',exitCode:0,evidence:'host fixture check'}]};
|
|
23
|
+
try{fn(input);}finally{fs.rmSync(temp,{recursive:true,force:true});}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test('host handoff uses existing gate and binds actual changed bytes',()=>fixture(input=>{
|
|
27
|
+
assert.equal(createHostHandoff(input).status,'ready_for_review');
|
|
28
|
+
const handoff=loadHandoff(input.handoffPath,{task:'T-001',attempt:1});
|
|
29
|
+
assert.deepEqual(handoff.changed_files,['a.mjs']);
|
|
30
|
+
assert.equal(handoff.implementation_sha256,implementationSha256(input.root,['a.mjs']));
|
|
31
|
+
const before=fs.readFileSync(input.handoffPath);
|
|
32
|
+
assert.throws(()=>createHostHandoff(input),{code:'EEXIST'});
|
|
33
|
+
assert.deepEqual(fs.readFileSync(input.handoffPath),before);
|
|
34
|
+
}));
|
|
35
|
+
test('failed host check produces blocked handoff rather than invented success',()=>fixture(input=>{
|
|
36
|
+
input.checks[0]={...input.checks[0],outcome:'failed',exitCode:1};
|
|
37
|
+
assert.equal(createHostHandoff(input).status,'blocked');
|
|
38
|
+
assert.equal(loadHandoff(input.handoffPath).blockers.length,1);
|
|
39
|
+
}));
|
|
40
|
+
test('out-of-scope change rejects without publishing a handoff',()=>fixture(input=>{
|
|
41
|
+
fs.writeFileSync(path.join(input.root,'outside.mjs'),'not authorized');
|
|
42
|
+
assert.throws(()=>createHostHandoff(input));assert.equal(fs.existsSync(input.handoffPath),false);
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
test('new host handoff feeds existing Learning writer and verifier',()=>fixture(input=>{
|
|
46
|
+
createHostHandoff(input);
|
|
47
|
+
const identity=input.baseline.identity,feature='1.fixture',learningFiles=[];
|
|
48
|
+
const learningDigest=digest({version:1,feature,identity,files:learningFiles});
|
|
49
|
+
const learningInput={version:1,workflow:'cm-ai',phase:'task_learning_input',feature,identity,learningDigest,learningFiles};
|
|
50
|
+
const binding={feature,identity,learningDigest};
|
|
51
|
+
const application=createCmAiTaskLearningApplication({...binding,status:'no_relevant_lesson',note:null});
|
|
52
|
+
const retrospective=createCmAiTaskLearningRetrospective({...binding,status:'no_new_lesson',candidates:[],reason:null});
|
|
53
|
+
const writeback=writeCmAiProjectLearning({codeProject:input.root,learningInput,retrospective});
|
|
54
|
+
const args={handoffPath:input.handoffPath,feature,identity,learningInput,application,retrospective,writeback};
|
|
55
|
+
writeCmAiTaskLearningHandoff(args);verifyCmAiTaskLearningHandoff(args);
|
|
56
|
+
const evidence=loadHandoff(input.handoffPath).evidence;
|
|
57
|
+
assert.equal(evidence.filter(x=>x.startsWith('cm-learning-')).length,2);
|
|
58
|
+
}));
|
|
@@ -0,0 +1,156 @@
|
|
|
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 {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
|
|
7
|
+
import {recordCmAiQaDecision,recordCmAiQaRun,inspectCmAiQaResult} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
8
|
+
|
|
9
|
+
function fixture() {
|
|
10
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-exec-')));
|
|
11
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.work',logHome=path.join(root,'logs');
|
|
12
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
13
|
+
fs.mkdirSync(path.join(specsDir,'.reviews'));
|
|
14
|
+
fs.writeFileSync(path.join(codeProject,'source.mjs'),'export const value=42;\n');
|
|
15
|
+
fs.writeFileSync(path.join(codeProject,'check.test.mjs'),"import assert from 'node:assert/strict'; import {value} from './source.mjs'; assert.equal(value,42);\n");
|
|
16
|
+
fs.writeFileSync(path.join(codeProject,'AGENTS.md'),'# Fixture\nTest command: node --test check.test.mjs\n');
|
|
17
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,
|
|
18
|
+
project:{workflow:'web-frontend'},policies:{tests:['commands']}}));
|
|
19
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'- [AC-001]: fixture\n');
|
|
20
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Fixture\n');
|
|
21
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: fixture\n');
|
|
22
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature]}));
|
|
23
|
+
const cases=['logic','browser','browser'].map((kind,index)=>({id:`TC-00${index+1}`,kind,blocking:index!==2,
|
|
24
|
+
origin:'user',acIds:['AC-001'],taskIds:['T-001'],title:'Synthetic case',preconditions:[],steps:['Observe fixture'],
|
|
25
|
+
expected:['Synthetic expected behavior'],cleanup:index===1?['Close synthetic resource']:[]}));
|
|
26
|
+
fs.writeFileSync(path.join(specsDir,feature,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases}));
|
|
27
|
+
const identity={repositoryId:'qa-fixture',runId:'qa-fixture-run',taskId:'T-001',attempt:1},packageDigest='a'.repeat(64);
|
|
28
|
+
const binding={codeProject,specsDir,feature,identity,packageDigest,testRunId:'qa-fixture-test'};
|
|
29
|
+
const configuration={codeProject,specsDir,feature,runtime:'codex',requirements:['source.mjs'],
|
|
30
|
+
commands:[{id:'declared-test',command:[process.execPath,'--test','check.test.mjs'],caseIds:['TC-001']}],
|
|
31
|
+
environment:{kind:'web',carrier:'browser',target:'http://127.0.0.1:4100',scope:'local'},timeoutMs:5000,logHome};
|
|
32
|
+
recordCmAiQaDecision({codeProject,specsDir,feature,identity,packageDigest,logHome,decision:{decisionId:'qa-fixture-decision',
|
|
33
|
+
identity,packageDigest,status:'triggered',score:null,reason:'fixture',at:'2026-09-08T01:00:00Z'}});
|
|
34
|
+
return {root,binding,configuration,cleanup:()=>fs.rmSync(root,{recursive:true,force:true})};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function begin(f,executor) {
|
|
38
|
+
const input={...f.binding,mode:executor.mode,caseCount:executor.caseCount};
|
|
39
|
+
recordCmAiQaRun({...input,phase:'start',logHome:f.configuration.logHome});
|
|
40
|
+
return input;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test('QA producer records three distinct rounds and rejects unknown, skipped and exhausted retries',async()=>{
|
|
44
|
+
const f=fixture();
|
|
45
|
+
try{
|
|
46
|
+
const executor=createHostQaExecutor({...f.configuration,
|
|
47
|
+
logic:async()=>({verdict:'SUPPORTED',evidence:['source.mjs:1']}),
|
|
48
|
+
browser:async request=>{
|
|
49
|
+
const artifact=path.join(f.configuration.specsDir,'.reviews','round-browser.txt');
|
|
50
|
+
fs.writeFileSync(artifact,'Synthetic failed browser observation; no real browser used');
|
|
51
|
+
return {verdict:'FAIL',evidence:[artifact],environment:request.environment,cleanup:'completed'};
|
|
52
|
+
}});
|
|
53
|
+
const base={...f.binding,mode:executor.mode,caseCount:executor.caseCount,logHome:f.configuration.logHome};
|
|
54
|
+
const start=(qaRound,testRunId)=>recordCmAiQaRun({...base,qaRound,testRunId,phase:'start'});
|
|
55
|
+
assert.throws(()=>start(2,'qa-round-2'));
|
|
56
|
+
for(let qaRound=1;qaRound<=3;qaRound++){
|
|
57
|
+
const testRunId=`qa-round-${qaRound}`;
|
|
58
|
+
if(qaRound===3)assert.throws(()=>start(3,'qa-round-1'));
|
|
59
|
+
start(qaRound,testRunId);
|
|
60
|
+
assert.throws(()=>start(qaRound+1,`qa-unknown-${qaRound}`));
|
|
61
|
+
const input={...f.binding,mode:executor.mode,caseCount:executor.caseCount,qaRound,testRunId};
|
|
62
|
+
await assert.rejects(executor.run({...input,qaRound:qaRound+1},new AbortController().signal));
|
|
63
|
+
const result=await executor.run(input,new AbortController().signal);
|
|
64
|
+
assert.equal(result.result,'FAIL');
|
|
65
|
+
if(qaRound>1)assert.throws(()=>recordCmAiQaRun({...base,testRunId,phase:'complete',result}));
|
|
66
|
+
recordCmAiQaRun({...base,qaRound,testRunId,phase:'complete',result});
|
|
67
|
+
assert.equal(inspectCmAiQaResult({specsDir:input.specsDir,feature:input.feature,identity:input.identity,
|
|
68
|
+
packageDigest:input.packageDigest,testRunId}).status,'failed');
|
|
69
|
+
if(qaRound===1)assert.throws(()=>start(3,'qa-skipped'));
|
|
70
|
+
}
|
|
71
|
+
const log=path.join(f.configuration.specsDir,'运行日志.jsonl'),before=fs.readFileSync(log,'utf8');
|
|
72
|
+
assert.throws(()=>start(4,'qa-round-4'));assert.throws(()=>start(1,'qa-reset'));
|
|
73
|
+
assert.equal(fs.readFileSync(log,'utf8'),before);
|
|
74
|
+
const rows=before.trim().split('\n').map(JSON.parse);
|
|
75
|
+
for(const phase of ['start','case_start','case_complete','complete'])
|
|
76
|
+
assert.deepEqual(rows.filter(row=>row.event==='test_run'&&row.phase===phase).map(row=>row.attempt),[1,2,3]);
|
|
77
|
+
}finally{f.cleanup();}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('host QA runs a declared command, retains blocking disabled modes and archives per-case evidence',async()=>{
|
|
81
|
+
const f=fixture(),seen=[];
|
|
82
|
+
try{
|
|
83
|
+
const executor=createHostQaExecutor({...f.configuration,
|
|
84
|
+
logic:async request=>{seen.push(request.case.id);return {verdict:'SUPPORTED',evidence:['source.mjs:1']};},
|
|
85
|
+
browser:async request=>{
|
|
86
|
+
seen.push(request.case.id);assert.equal(request.case.blocking,true);
|
|
87
|
+
const log=fs.readFileSync(path.join(f.configuration.specsDir,'运行日志.jsonl'),'utf8');
|
|
88
|
+
assert(log.includes('case_start'));assert(log.includes('browser_qa'));
|
|
89
|
+
const artifact=path.join(f.configuration.specsDir,'.reviews','browser-fixture.txt');
|
|
90
|
+
fs.writeFileSync(artifact,'Synthetic browser-host evidence; no real browser used\n');
|
|
91
|
+
return {verdict:'PASS',evidence:[artifact],environment:request.environment,cleanup:'completed'};
|
|
92
|
+
}});
|
|
93
|
+
assert.equal(executor.mode,'all');assert.equal(executor.caseCount,3);
|
|
94
|
+
const input=begin(f,executor),result=await executor.run(input,new AbortController().signal);
|
|
95
|
+
assert.equal(result.result,'PASS');assert.equal(result.passed,3);assert.deepEqual(seen,['TC-002','TC-001']);
|
|
96
|
+
const report=fs.readFileSync(result.report,'utf8');assert(report.includes('"staticVerdict": "SUPPORTED"'));
|
|
97
|
+
assert(report.includes('"commandEvidence": ['));assert(!report.includes('TC-003'));
|
|
98
|
+
recordCmAiQaRun({...input,phase:'complete',result,logHome:f.configuration.logHome});
|
|
99
|
+
assert.equal(inspectCmAiQaResult({specsDir:input.specsDir,feature:input.feature,identity:input.identity,
|
|
100
|
+
packageDigest:input.packageDigest,testRunId:input.testRunId}).status,'passed');
|
|
101
|
+
assert.throws(()=>recordCmAiQaRun({...input,qaRound:2,testRunId:'qa-after-pass',phase:'start',logHome:f.configuration.logHome}));
|
|
102
|
+
const rows=fs.readFileSync(path.join(input.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
103
|
+
assert.equal(rows.filter(row=>row.phase==='case_start').length,1);
|
|
104
|
+
assert.equal(rows.filter(row=>row.phase==='case_complete').length,1);
|
|
105
|
+
assert(rows.filter(row=>row.phase==='route').every(row=>!Object.hasOwn(row,'effective_model')));
|
|
106
|
+
assert.equal(rows.filter(row=>row.event==='resource'&&row.phase==='acquired').length,1);
|
|
107
|
+
assert.equal(rows.filter(row=>row.event==='resource'&&row.phase==='released').length,1);
|
|
108
|
+
const status=JSON.parse(fs.readFileSync(path.join(input.specsDir,'.cm-status.json'),'utf8'));
|
|
109
|
+
assert.equal(status.node,'N6');assert(status.detail.includes('TC-002: case_complete'));
|
|
110
|
+
}finally{f.cleanup();}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
for(const mode of ['no-runtime-evidence','wrong-carrier','cleanup-failed','source-drift','empty-evidence'])
|
|
114
|
+
test(`host QA does not convert incomplete or unsafe evidence to PASS: ${mode}`,async()=>{
|
|
115
|
+
const f=fixture();
|
|
116
|
+
try{
|
|
117
|
+
if(mode==='no-runtime-evidence'){
|
|
118
|
+
const source=path.join(f.configuration.specsDir,f.configuration.feature,'test-cases.json');
|
|
119
|
+
const contract=JSON.parse(fs.readFileSync(source));contract.cases=contract.cases.slice(0,1);
|
|
120
|
+
fs.writeFileSync(source,JSON.stringify(contract));
|
|
121
|
+
fs.writeFileSync(path.join(f.configuration.codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{tests:['logic']}}));
|
|
122
|
+
f.configuration.commands=[];
|
|
123
|
+
}
|
|
124
|
+
const executor=createHostQaExecutor({...f.configuration,
|
|
125
|
+
logic:async()=>({verdict:'SUPPORTED',evidence:['source.mjs:1']}),browser:async request=>{
|
|
126
|
+
const artifact=path.join(f.configuration.specsDir,'.reviews','browser-fixture.txt');
|
|
127
|
+
fs.writeFileSync(artifact,mode==='empty-evidence'?'':'Synthetic evidence');
|
|
128
|
+
if(mode==='source-drift')fs.writeFileSync(path.join(f.configuration.codeProject,'source.mjs'),'export const value=43;\n');
|
|
129
|
+
return {verdict:'PASS',evidence:[artifact],environment:mode==='wrong-carrier'?{...request.environment,kind:'app'}:request.environment,
|
|
130
|
+
cleanup:mode==='cleanup-failed'?'failed':'completed'};
|
|
131
|
+
}});
|
|
132
|
+
const result=await executor.run(begin(f,executor),new AbortController().signal);
|
|
133
|
+
assert.equal(result.result,'BLOCKED');assert(result.blocked>0);
|
|
134
|
+
if(mode==='no-runtime-evidence')assert.equal(result.passed,0);
|
|
135
|
+
if(mode==='source-drift')assert(fs.readFileSync(result.report,'utf8').includes('"sourceChanged": true'));
|
|
136
|
+
if(mode==='empty-evidence'){
|
|
137
|
+
assert(fs.readFileSync(result.report,'utf8').includes('"evidenceProblem": "qa_evidence_required"'));
|
|
138
|
+
recordCmAiQaRun({...f.binding,mode:executor.mode,caseCount:executor.caseCount,phase:'complete',result,logHome:f.configuration.logHome});
|
|
139
|
+
const {specsDir,feature,identity,packageDigest,testRunId}=f.binding;
|
|
140
|
+
assert.equal(inspectCmAiQaResult({specsDir,feature,identity,packageDigest,testRunId}).status,'blocked');
|
|
141
|
+
}
|
|
142
|
+
}finally{f.cleanup();}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('host QA cancellation leaves an unfinished invocation and never writes success',async()=>{
|
|
146
|
+
const f=fixture(),controller=new AbortController();
|
|
147
|
+
try{
|
|
148
|
+
const executor=createHostQaExecutor({...f.configuration,browser:async request=>{
|
|
149
|
+
controller.abort();return {verdict:'PASS',evidence:['ignored-after-cancel'],environment:request.environment,cleanup:'completed'};
|
|
150
|
+
}});
|
|
151
|
+
await assert.rejects(executor.run(begin(f,executor),controller.signal),{code:'cancelled'});
|
|
152
|
+
const rows=fs.readFileSync(path.join(f.configuration.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
153
|
+
assert(!rows.some(row=>row.event==='test_run'&&row.phase==='complete'));
|
|
154
|
+
assert.equal(fs.readdirSync(path.join(f.configuration.specsDir,'.reviews')).filter(name=>name.endsWith('execution.md')).length,0);
|
|
155
|
+
}finally{f.cleanup();}
|
|
156
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
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 {createHostQaDecisionProvider,decideHostQaPolicy} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
7
|
+
|
|
8
|
+
const low=()=>({scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
9
|
+
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
|
|
10
|
+
test('N6 enforces mandatory triggers ahead of low scores and bounds the API merge exemption',()=>{
|
|
11
|
+
const input={assessment:low(),pending:2,mergeEligible:false,unassessedTasks:1};
|
|
12
|
+
assert.equal(decideHostQaPolicy(input).status,'skipped');
|
|
13
|
+
assert.equal(decideHostQaPolicy({...input,pending:0}).reason,'feature_complete');
|
|
14
|
+
assert.equal(decideHostQaPolicy({...input,unassessedTasks:5}).reason,'five_tasks_without_qa');
|
|
15
|
+
for(const field of Object.keys(input.assessment.changes)){
|
|
16
|
+
const assessment=low();assessment.changes[field]=true;
|
|
17
|
+
assert.equal(decideHostQaPolicy({...input,assessment}).status,'triggered',field);
|
|
18
|
+
}
|
|
19
|
+
const assessment=low();assessment.changes.api=true;
|
|
20
|
+
assert.equal(decideHostQaPolicy({...input,assessment,pending:1,mergeEligible:true}).reason,'merged_to_feature_qa');
|
|
21
|
+
assessment.changes.payment=true;
|
|
22
|
+
assert.equal(decideHostQaPolicy({...input,assessment,pending:1,mergeEligible:true}).reason,'payment');
|
|
23
|
+
const high=low();high.scores.risk=5;
|
|
24
|
+
assert.deepEqual(decideHostQaPolicy({...input,assessment:high}),{status:'triggered',score:8,reason:'risk_score'});
|
|
25
|
+
high.scores.risk=0;assert.throws(()=>decideHostQaPolicy({...input,assessment:high}),{code:'qa_assessment_invalid'});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('N6 derives consecutive work from original task inventory and QA log without a counter store',async()=>{
|
|
29
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-policy-')));
|
|
30
|
+
try{
|
|
31
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
32
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
33
|
+
fs.writeFileSync(path.join(codeProject,'source.js'),'// fixture\n');
|
|
34
|
+
for(const file of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,file),'# Fixture\n');
|
|
35
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),Array.from({length:7},(_,i)=>`- [${i<5?'x':' '}] T-00${i+1}: task`).join('\n'));
|
|
36
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature]}));
|
|
37
|
+
const binding={specsDir,codeProject,feature,identity:{repositoryId:'fixture',runId:'run-current',taskId:'T-005',attempt:1},packageDigest:'a'.repeat(64)};
|
|
38
|
+
const seen=[];
|
|
39
|
+
const provider=createHostQaDecisionProvider({timeoutMs:1000,assess:async input=>{seen.push(input.unassessedTasks);return low();}});
|
|
40
|
+
const decide=()=>provider.decide(binding,new AbortController().signal);
|
|
41
|
+
assert.equal((await decide()).reason,'five_tasks_without_qa');
|
|
42
|
+
const rows=Array.from({length:4},(_,i)=>({schema_version:1,workflow:'cm-ai',event:'qa',node:'N6',feature,
|
|
43
|
+
repository_id:'fixture',run_id:`run-task-${i}`,task:`T-00${i+1}`,attempt:1,package_digest:'b'.repeat(64),
|
|
44
|
+
decision_id:`decision-${i}`,status:i===3?'triggered':'skipped',reason:'fixture',score:i===3?null:4,at:'2026-09-07T01:00:00+00:00'}));
|
|
45
|
+
const log=path.join(specsDir,'运行日志.jsonl');
|
|
46
|
+
fs.writeFileSync(log,rows.map(row=>JSON.stringify(row)).join('\n')+'\n');
|
|
47
|
+
assert.equal((await decide()).status,'skipped');assert.deepEqual(seen,[5,1]);
|
|
48
|
+
// Omitting old decisions cannot silently pretend those tasks were covered.
|
|
49
|
+
fs.writeFileSync(log,JSON.stringify(rows[3])+'\n');
|
|
50
|
+
await decide();assert.equal(seen.at(-1),4);
|
|
51
|
+
const oldCurrent={...rows[3],task:'T-005',run_id:'old-run',package_digest:'c'.repeat(64)};
|
|
52
|
+
const skips=rows.map(row=>({...row,status:'skipped',score:4}));
|
|
53
|
+
fs.writeFileSync(log,[oldCurrent,...skips].map(row=>JSON.stringify(row)).join('\n')+'\n');
|
|
54
|
+
assert.equal((await decide()).reason,'five_tasks_without_qa');assert.equal(seen.at(-1),5);
|
|
55
|
+
const stale=createHostQaDecisionProvider({timeoutMs:1000,assess:async()=>{
|
|
56
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-005: task\n');return low();}});
|
|
57
|
+
await assert.rejects(stale.decide(binding,new AbortController().signal),{code:'stale_qa'});
|
|
58
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
59
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
4
|
+
import {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
5
|
+
import {validateReviewDispatchGrant} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
6
|
+
import {requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
7
|
+
|
|
8
|
+
const identity={repositoryId:'review-host',runId:'run',taskId:'T-001',attempt:1},packageDigest='a'.repeat(64);
|
|
9
|
+
const binding={specsDir:'/specs',codeProject:'/code',feature:'1.work',identity,packageDigest};
|
|
10
|
+
const operation=name=>({version:1,operation:name,requestId:name,identity,...(name==='decision'?{packageDigest}:{})});
|
|
11
|
+
const request=requestFor({invocationId:'actual-request',identity,role:'reviewer',provider:'codex',
|
|
12
|
+
requestedModel:'fixture',contextId:'review-context',payload:{reviewPackage:{packageDigest},priorReview:null}});
|
|
13
|
+
const authority=decide=>createHostReviewAuthority({hostContextId:'host',reviewerId:'reviewer',adapterId:'codex-review-adapter',decide});
|
|
14
|
+
|
|
15
|
+
test('host decision issues one original grant only after the actual request exists',async()=>{
|
|
16
|
+
const host=authority(async got=>{assert.deepEqual(got,binding);return {status:'approved'};});
|
|
17
|
+
assert.deepEqual(host.authorize(request,{authorizationAt:Date.now()}),{status:'denied',code:'permission_denied'});
|
|
18
|
+
await host.hostDecisionProvider.decide(binding,new AbortController().signal);
|
|
19
|
+
const authorizationAt=Date.now(),grant=host.authorize(request,{authorizationAt});
|
|
20
|
+
assert.deepEqual(validateReviewDispatchGrant(grant,{request,reviewerId:'reviewer',adapterId:'codex-review-adapter',
|
|
21
|
+
packageDigest,hostContextIds:['host'],authorizationAt,registeredAt:authorizationAt}),grant);
|
|
22
|
+
assert.deepEqual(host.authorize(request,{authorizationAt}),{status:'denied',code:'permission_denied'});
|
|
23
|
+
for(const mode of ['package','cancel','expired','denied']){
|
|
24
|
+
const controlled=authority(async()=>mode==='denied'?{status:'denied',code:'permission_denied'}:{status:'approved'});
|
|
25
|
+
const controller=new AbortController();await controlled.hostDecisionProvider.decide(binding,controller.signal);
|
|
26
|
+
if(mode==='cancel')controller.abort();
|
|
27
|
+
const input=mode==='package'?{...request,payload:{reviewPackage:{packageDigest:'b'.repeat(64)}}}:request;
|
|
28
|
+
assert.deepEqual(controlled.authorize(input,{authorizationAt:Date.now()+(mode==='expired'?60001:0)}),
|
|
29
|
+
{status:'denied',code:'permission_denied'},mode);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
for(const mode of ['approved','awaiting','denied','timeout','cancel','drift'])test(`dynamic review decision: ${mode}`,async()=>{
|
|
34
|
+
let current={state:'awaiting_review',code:null,identity,packageDigest},effects=0,started,release;
|
|
35
|
+
const ready=new Promise(resolve=>{started=resolve;});
|
|
36
|
+
const runner={status:()=>current,run:async()=>current,
|
|
37
|
+
cancel:()=>{current={...current,state:'cancelled',code:'cancelled',cancellationRequested:true};return current;},
|
|
38
|
+
executeEffect:async()=>{effects++;return current;}};
|
|
39
|
+
let decisions=0;
|
|
40
|
+
const entry=createCmAiConversationEntry({specsDir:binding.specsDir,codeProject:binding.codeProject,
|
|
41
|
+
feature:binding.feature,identity,runner,hostDecisionProvider:{timeoutMs:mode==='timeout'?10:1000,
|
|
42
|
+
decide:async(got,signal)=>{
|
|
43
|
+
decisions++;assert.deepEqual(got,binding);assert.equal(signal.aborted,false);started();
|
|
44
|
+
if(mode==='cancel'||mode==='timeout')return new Promise(resolve=>{release=resolve;});
|
|
45
|
+
if(mode==='drift')current={...current,packageDigest:'b'.repeat(64)};
|
|
46
|
+
if(mode==='awaiting')return null;
|
|
47
|
+
return mode==='denied'?{status:'denied',code:'permission_denied'}:{status:'approved'};
|
|
48
|
+
}}});
|
|
49
|
+
const running=entry.handle(operation('decision'));await ready;
|
|
50
|
+
if(mode==='cancel')await entry.handle(operation('cancel'));
|
|
51
|
+
const result=await running;
|
|
52
|
+
if(release){release({status:'approved'});await Promise.resolve();}
|
|
53
|
+
assert.equal(effects,mode==='approved'?1:0);
|
|
54
|
+
const expected={approved:null,awaiting:'decision_required',denied:'permission_denied',
|
|
55
|
+
timeout:'review_decision_timeout',cancel:'cancelled',drift:'stale_decision'};
|
|
56
|
+
assert.equal(result.code,expected[mode]);
|
|
57
|
+
current={state:'unknown',code:'reconciliation_required',identity,packageDigest};
|
|
58
|
+
const historical=await entry.handle(operation('decision'));
|
|
59
|
+
assert.equal(historical.state,'unknown');assert.equal(decisions,1,'unknown review must not ask for another decision');
|
|
60
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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 {resolveHostRole} from '../runtime/js/cm-ai/host-role-routing.mjs';
|
|
7
|
+
|
|
8
|
+
test('current host rereads role config and logs degradation/errors without model invocation',()=>{
|
|
9
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-host-role-')));
|
|
10
|
+
try{
|
|
11
|
+
const definition={specsDir:path.join(root,'specs'),codeProject:path.join(root,'code'),feature:'1.work'};
|
|
12
|
+
fs.mkdirSync(definition.specsDir);fs.mkdirSync(definition.codeProject);
|
|
13
|
+
const config=path.join(definition.codeProject,'.cm-workflow.json');
|
|
14
|
+
const identity={repositoryId:'roles',runId:'roles-fixture-run',taskId:'T-001',attempt:1};
|
|
15
|
+
const controller=new AbortController();
|
|
16
|
+
const resolve=role=>resolveHostRole({definition,identity,role,signal:controller.signal});
|
|
17
|
+
assert.equal(resolve('coder').model,'default');
|
|
18
|
+
fs.writeFileSync(config,JSON.stringify({version:1,roles:{tester:{adapter:'claude-cli',model:'requested-only',source:'subscription'}}}));
|
|
19
|
+
assert.equal(resolve('tester').model,'requested-only');
|
|
20
|
+
const logfile=path.join(definition.specsDir,'运行日志.jsonl');
|
|
21
|
+
let rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
22
|
+
assert(rows.some(row=>row.event==='degrade'&&row.outcome==='current_conversation_only'));
|
|
23
|
+
assert(rows.every(row=>!Object.hasOwn(row,'effective_model')&&row.event!=='model_usage'));
|
|
24
|
+
fs.writeFileSync(config,'{invalid-private-value');
|
|
25
|
+
assert.throws(()=>resolve('coder'),{code:'invalid_workflow_config'});
|
|
26
|
+
assert(!fs.readFileSync(logfile,'utf8').includes('invalid-private-value'));
|
|
27
|
+
rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
28
|
+
assert.equal(rows.at(-1).event,'error');
|
|
29
|
+
const before=fs.readFileSync(logfile);controller.abort();
|
|
30
|
+
assert.throws(()=>resolve('tester'),{code:'cancelled'});
|
|
31
|
+
assert.deepEqual(fs.readFileSync(logfile),before);
|
|
32
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
33
|
+
});
|