@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,308 @@
|
|
|
1
|
+
// Per-task file scope in tasks.md (runtime/js/task-scope.mjs): how it is parsed,
|
|
2
|
+
// what the split self-check requires (rule 3), and how a new batch uses it to
|
|
3
|
+
// decide which tasks may run in parallel.
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {parseTaskScopes,declaredTaskScope,sameScope,validScopePath,sessionTaskProblem} from '../runtime/js/task-scope.mjs';
|
|
10
|
+
import {checkPrdDraftMechanics,PRD_SELF_CHECK_RULES,sessionTaskFindings} from '../runtime/js/cm-prd/self-check.mjs';
|
|
11
|
+
import {recordPrdTaskScopes,prdTaskScopeOptions,approvedScopeExemptions} from '../runtime/js/cm-prd/task-scope-record.mjs';
|
|
12
|
+
import {createHash} from 'node:crypto';
|
|
13
|
+
import {normalizeRuntimeMarkBytes} from './cm-spec-manifest.mjs';
|
|
14
|
+
import {spawnSync} from 'node:child_process';
|
|
15
|
+
import {createCmAiBatch} from './cm-ai-batch-run.mjs';
|
|
16
|
+
import {BATCH_SEGMENT_FIELD,batchSegment} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
17
|
+
|
|
18
|
+
const tasksText=lines=>lines.join('\n')+'\n';
|
|
19
|
+
|
|
20
|
+
test('scope, tests and device sub-items attach to the task line above them',()=>{
|
|
21
|
+
const {tasks,errors}=parseTaskScopes(tasksText(['## 任务列表','',
|
|
22
|
+
'- [ ] T-001: logic',' - 范围: `src/a.js`, `test/a.test.js`',' - 测试文件: `test/a.test.js`',
|
|
23
|
+
'- [ ] T-002: ui',' - scope: `index.html` `src/app.js`',' - device: required',
|
|
24
|
+
'- [ ] T-003: no scope','','## 依赖关系','','- T-002 依赖 T-001']));
|
|
25
|
+
assert.deepEqual(errors,[]);
|
|
26
|
+
assert.deepEqual(tasks.get('T-001'),{scope:['src/a.js','test/a.test.js'],tests:['test/a.test.js'],device:false,line:4});
|
|
27
|
+
assert.deepEqual(tasks.get('T-002'),{scope:['index.html','src/app.js'],tests:[],device:true,line:7});
|
|
28
|
+
assert.equal(tasks.has('T-003'),false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Task grammar 3 (spec-task-line.mjs): `- 开发: 会话` has meaning only under an
|
|
32
|
+
// approval that bound grammar 3; 1 and 2 read the very same text exactly as before.
|
|
33
|
+
test('开发 sub-item: grammar 3 reads it, grammar 1 and 2 keep it prose',t=>{
|
|
34
|
+
const text=tasksText(['- [ ] T-001: impl',' - 范围: `src/a.js`',' - 开发: 开发进程',
|
|
35
|
+
'- [ ] T-002:walk',' - 范围: `docs/qa.md`',' - developer: session']);
|
|
36
|
+
const three=parseTaskScopes(text,{grammar:3});
|
|
37
|
+
assert.deepEqual(three.errors,[]);assert.deepEqual([...three.sessions],['T-002']);
|
|
38
|
+
assert.deepEqual(three.tasks.get('T-002').scope,['docs/qa.md']);
|
|
39
|
+
assert.deepEqual(parseTaskScopes(text).sessions,three.sessions,'grammar 3 is the default for drafts');
|
|
40
|
+
// Grammar 2 keeps its own declaration grammar (the full-width colon is a task) and ignores 开发.
|
|
41
|
+
const two=parseTaskScopes(text,{grammar:2});
|
|
42
|
+
assert.deepEqual(two.errors,[]);assert.equal(two.sessions.size,0);assert.deepEqual([...two.tasks.keys()],['T-001','T-002']);
|
|
43
|
+
// Grammar 1 is the pre-grammar parse: `T-002:` is prose, so its scope is a stray item.
|
|
44
|
+
const one=parseTaskScopes(text,{grammar:1});
|
|
45
|
+
assert.equal(one.sessions.size,0);assert.deepEqual([...one.tasks.keys()],['T-001']);
|
|
46
|
+
assert.deepEqual(one.errors.map(item=>item.taskId),[null]);
|
|
47
|
+
// A value other than 会话/session (or the written-out default) is refused only under grammar 3.
|
|
48
|
+
for(const bad of [' - 开发: 张三',' - 开发: 会话\n - 开发: session']){
|
|
49
|
+
const bytes=tasksText(['- [ ] T-001: a',' - 范围: `a.js`',bad]);
|
|
50
|
+
assert.equal(parseTaskScopes(bytes,{grammar:3}).errors.length,1,bad);
|
|
51
|
+
assert.deepEqual(parseTaskScopes(bytes,{grammar:2}).errors,[],bad);
|
|
52
|
+
}
|
|
53
|
+
assert.match(parseTaskScopes(tasksText(['- [ ] T-001: a',' - 范围: `a.js`',' - 开发: 张三']),{grammar:3}).errors[0].message,/会话/);
|
|
54
|
+
// Not under any task: reported like a stray scope under 3, prose under 2; prose values stay prose.
|
|
55
|
+
const stray=tasksText(['- [ ] T-001: a',' - 范围: `a.js`','','## 说明','- 开发: 会话','- 开发: 由前端组负责']);
|
|
56
|
+
assert.deepEqual(parseTaskScopes(stray,{grammar:3}).errors.map(item=>item.taskId),[null]);
|
|
57
|
+
assert.deepEqual(parseTaskScopes(stray,{grammar:2}).errors,[]);
|
|
58
|
+
// 开发 does not count as a scope field: alone it leaves the task without scope, and 串行 may carry it.
|
|
59
|
+
const alone=parseTaskScopes(tasksText(['- [ ] T-001: a',' - 开发: 会话','- [ ] T-002: b',' - 范围: 串行',' - 开发: 会话']),{grammar:3});
|
|
60
|
+
assert.deepEqual(alone.errors,[]);assert.equal(alone.tasks.size,0);assert.deepEqual([...alone.serial],['T-002']);
|
|
61
|
+
assert.deepEqual([...alone.sessions],['T-001','T-002']);
|
|
62
|
+
// The runtime reads with the grammar the approval bound.
|
|
63
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-grammar-')));
|
|
64
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
65
|
+
fs.mkdirSync(path.join(root,'1.work'));
|
|
66
|
+
fs.writeFileSync(path.join(root,'1.work','tasks.md'),tasksText(['- [ ] T-001: a',' - 范围: `a.js`',' - 开发: 张三']));
|
|
67
|
+
for(const [status,refused] of [[{status:'approved',taskGrammar:3},true],[{status:'approved',taskGrammar:2},false],
|
|
68
|
+
[{status:'approved'},false],[{status:'awaiting_review',taskGrammar:3},false],[{status:'approved',taskGrammar:4},false]]){
|
|
69
|
+
fs.writeFileSync(path.join(root,'.cm-specs-status'),JSON.stringify(status));
|
|
70
|
+
if(refused)assert.throws(()=>declaredTaskScope(root,'1.work','T-001'),{code:'task_scope_invalid'});
|
|
71
|
+
else assert.deepEqual(declaredTaskScope(root,'1.work','T-001').scope,['a.js'],JSON.stringify(status));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a session task is at most one per feature and only its last task',()=>{
|
|
76
|
+
const lines=(...marks)=>tasksText(['- [ ] T-001: a',' - 范围: `a.js`',...(marks.includes(1)?[' - 开发: 会话']:[]),
|
|
77
|
+
'- [ ] T-002: b',' - 范围: `b.js`',...(marks.includes(2)?[' - 开发: 会话']:[]),
|
|
78
|
+
'- [ ] T-003: c ~~[DROPPED 不做]~~',' - 范围: `c.js`',...(marks.includes(3)?[' - 开发: 会话']:[])]);
|
|
79
|
+
const codes=(text,grammar=3)=>sessionTaskFindings('1.work',text,{grammar}).map(item=>item.code);
|
|
80
|
+
assert.deepEqual(codes(lines()),[]);
|
|
81
|
+
// A dropped task after it does not count: T-002 is the last task to run.
|
|
82
|
+
assert.deepEqual(codes(lines(2)),[]);
|
|
83
|
+
assert.deepEqual(codes(lines(1)),['session_task_not_final']);
|
|
84
|
+
assert.deepEqual(codes(lines(1,2)),['session_task_multiple']);
|
|
85
|
+
// A dropped task's mark is history, not a second session task.
|
|
86
|
+
assert.deepEqual(codes(lines(2,3)),[]);
|
|
87
|
+
// Grammar 2 never reads the mark.
|
|
88
|
+
assert.deepEqual(codes(lines(1),2),[]);assert.deepEqual(codes(lines(1,2),2),[]);
|
|
89
|
+
const finding=sessionTaskFindings('1.work',lines(1),{grammar:3})[0];
|
|
90
|
+
assert.deepEqual(finding.reason.tasks,['T-001']);assert.match(finding.reason.expected,/最后一个任务/);
|
|
91
|
+
assert.equal(sessionTaskProblem([{id:'T-001'},{id:'T-002'}],new Set(['T-002']),new Map()),null);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('rule 4: no task may wait for the session task, directly or through another task',()=>{
|
|
95
|
+
const text=(...deps)=>tasksText(['- [ ] T-001: a',' - 范围: `a.js`','- [ ] T-002: b',' - 范围: `b.js`',
|
|
96
|
+
'- [ ] T-003: walk',' - 范围: `qa.md`',' - 开发: 会话','- [ ] T-004: gone ~~[DROPPED 不做]~~',' - 范围: `d.js`','','## 依赖关系',...deps]);
|
|
97
|
+
const findings=(...deps)=>sessionTaskFindings('1.work',text(...deps),{grammar:3});
|
|
98
|
+
// Direct: T-003 is declared last, but the batch would run T-001 after it.
|
|
99
|
+
const direct=findings('- T-001 依赖 T-003');
|
|
100
|
+
assert.deepEqual(direct.map(item=>item.code),['session_task_depended_on']);
|
|
101
|
+
assert.deepEqual([direct[0].reason.tasks,direct[0].reason.dependents],[['T-003'],['T-001']]);
|
|
102
|
+
assert.match(direct[0].reason.expected,/T-001 直接或间接依赖.*T-003/);
|
|
103
|
+
// Transitive: T-001 waits for T-002, which waits for T-003.
|
|
104
|
+
const transitive=findings('- T-001 依赖 T-002','- T-002 依赖 T-003');
|
|
105
|
+
assert.deepEqual(transitive.map(item=>[item.code,item.reason.dependents]),[['session_task_depended_on',['T-001','T-002']]]);
|
|
106
|
+
// Legal: the session task waits for the others; a dropped task waiting for it holds
|
|
107
|
+
// nothing back, nor does a dropped task in the middle of a chain.
|
|
108
|
+
assert.deepEqual(findings('- T-003 依赖 T-001, T-002','- T-002 依赖 T-001'),[]);
|
|
109
|
+
assert.deepEqual(findings('- T-004 依赖 T-003'),[]);
|
|
110
|
+
assert.deepEqual(findings('- T-001 依赖 T-004','- T-004 依赖 T-003'),[]);
|
|
111
|
+
// Grammar 2 never reads the mark.
|
|
112
|
+
assert.deepEqual(sessionTaskFindings('1.work',text('- T-001 依赖 T-003'),{grammar:2}),[]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('only exact relative file paths in backticks are accepted',()=>{
|
|
116
|
+
for(const bad of ['src/*.js','src/','/etc/passwd','../x.js','a/./b.js','a\\b.js','AGENTS.md','.git/config','x?.js'])
|
|
117
|
+
assert.equal(validScopePath(bad),false,bad);
|
|
118
|
+
for(const good of ['README.md','src/deep/file.test.mjs','docs/中文.md'])assert.equal(validScopePath(good),true,good);
|
|
119
|
+
const {errors}=parseTaskScopes(tasksText(['- [ ] T-001: a',' - 范围: src/a.js','- [ ] T-002: b',' - 范围: `src/*.js`',
|
|
120
|
+
'- [ ] T-003: c',' - 范围: `a.js`, `a.js`','- [ ] T-004: d',' - 范围: `a.js`',' - 范围: `b.js`']));
|
|
121
|
+
assert.deepEqual(errors.map(item=>item.taskId),['T-001','T-002','T-003','T-004']);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('tests outside scope, a device mark without scope and a stray sub-item are reported',()=>{
|
|
125
|
+
const {tasks,errors}=parseTaskScopes(tasksText(['- 范围: `orphan.js`','- [ ] T-001: a',' - 范围: `src/a.js`',' - 测试文件: `test/a.test.js`',
|
|
126
|
+
'- [ ] T-002: b',' - 设备: 需要','- [ ] T-003: c',' - 设备: 是']));
|
|
127
|
+
assert.equal(tasks.size,0);
|
|
128
|
+
const messages=errors.map(item=>`${item.taskId}:${item.message}`);
|
|
129
|
+
assert.ok(messages.some(item=>item.startsWith('null:')&&item.includes('不在任何任务行下面')));
|
|
130
|
+
// Written at the task's own level (indent forgotten) is reported the same way.
|
|
131
|
+
const flat=parseTaskScopes(tasksText(['- [ ] T-009: a','- 范围: `a.js`']));
|
|
132
|
+
assert.equal(flat.tasks.size,0);assert.match(flat.errors[0].message,/要缩进/);
|
|
133
|
+
// Ordinary prose bullets that merely start with the same word are not scope.
|
|
134
|
+
assert.deepEqual(parseTaskScopes(tasksText(['- [ ] T-001: a',' - 范围: `a.js`','','## 风险点','- device: iPhone 15 无法覆盖','- 范围: 待定'])).errors,[]);
|
|
135
|
+
assert.ok(messages.some(item=>item.startsWith('T-001:')&&item.includes('测试文件不在范围里')));
|
|
136
|
+
assert.ok(messages.some(item=>item.startsWith('T-002:')&&item.includes('没有范围')));
|
|
137
|
+
assert.ok(messages.some(item=>item.startsWith('T-003:')&&item.includes('设备只能写')));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('sub-items inside a fence are examples, and a heading ends a task',()=>{
|
|
141
|
+
const {tasks,errors}=parseTaskScopes(tasksText(['- [ ] T-001: a','```md',' - 范围: `fenced.js`','```','## 说明',' - 范围: `after-heading.js`']));
|
|
142
|
+
assert.equal(tasks.has('T-001'),false);
|
|
143
|
+
assert.ok(errors.every(item=>item.taskId===null));
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('a task that cannot list its files declares 串行 and is never treated as having a scope',t=>{
|
|
147
|
+
const parsed=parseTaskScopes(tasksText(['- [ ] T-001: scaffold',' - 范围: 串行','- [ ] T-002: b',' - scope: serial',' - 设备: 需要']));
|
|
148
|
+
assert.deepEqual([...parsed.serial],['T-001']);assert.equal(parsed.tasks.size,0);
|
|
149
|
+
assert.match(parsed.errors[0].message,/串行/);
|
|
150
|
+
// Only a scaffold feature (N.bootstrap) may use it; a business feature must list files.
|
|
151
|
+
const scaffold=draft('- [ ] T-001: scaffold\n - 范围: 串行\n');scaffold.features[0].directory='1.bootstrap';
|
|
152
|
+
assert.equal(checkPrdDraftMechanics(scaffold,{rules:3}).status,'mechanical_subset_passed');
|
|
153
|
+
const business=checkPrdDraftMechanics(draft('- [ ] T-001: feature\n - 范围: 串行\n'),{rules:3});
|
|
154
|
+
assert.deepEqual(codes(business),['task_scope_invalid']);assert.match(business.findings[0].reason.problems[0],/只用于脚手架功能/);
|
|
155
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-serial-')));
|
|
156
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
157
|
+
// At run time too: a scaffold's 串行 is "no scope", anywhere else it is refused, not read as "none".
|
|
158
|
+
for(const feature of ['1.bootstrap','2.work']){
|
|
159
|
+
fs.mkdirSync(path.join(root,feature));fs.writeFileSync(path.join(root,feature,'tasks.md'),'- [ ] T-001: scaffold\n - 范围: 串行\n');
|
|
160
|
+
}
|
|
161
|
+
assert.equal(declaredTaskScope(root,'1.bootstrap','T-001'),null);
|
|
162
|
+
assert.throws(()=>declaredTaskScope(root,'2.work','T-001'),error=>error.code==='task_scope_invalid'&&/只用于脚手架功能/.test(error.reason));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('the same files in another order are the same scope',()=>{
|
|
166
|
+
assert.equal(sameScope(['a','b'],['b','a']),true);
|
|
167
|
+
assert.equal(sameScope(['a'],['a','b']),false);
|
|
168
|
+
assert.equal(sameScope(['a','a'],['a','b']),false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const draft=(tasks)=>({draftDigest:'d',features:[{directory:'1.sample',name:'sample',documents:[
|
|
172
|
+
{path:'requirements.md',content:'- [ ] [AC-001] works\n'},{path:'design.md',content:'# d\n'},{path:'tasks.md',content:tasks}]}]});
|
|
173
|
+
const codes=report=>report.findings.map(item=>item.code);
|
|
174
|
+
|
|
175
|
+
test('rule 3: every task of a new draft must declare its files; earlier rules do not ask',()=>{
|
|
176
|
+
assert.equal(PRD_SELF_CHECK_RULES,4,'rule 4 keeps the rule-3 scope check');
|
|
177
|
+
const without=draft('- [ ] T-001: a\n- [ ] T-002: b\n - 范围: `b.js`\n');
|
|
178
|
+
const report=checkPrdDraftMechanics(without,{rules:3});
|
|
179
|
+
assert.deepEqual(codes(report),['task_scope_missing']);
|
|
180
|
+
assert.deepEqual(report.findings[0].reason.tasks,['T-001']);
|
|
181
|
+
assert.equal(checkPrdDraftMechanics(without,{rules:2}).status,'mechanical_subset_passed');
|
|
182
|
+
// A dropped task (allowed in a change) needs no scope.
|
|
183
|
+
assert.equal(checkPrdDraftMechanics(draft('- [ ] T-001: a\n - 范围: `a.js`\n- [ ] ~~T-002: b~~ [DROPPED 合并]\n'),{rules:3,change:true}).status,'mechanical_subset_passed');
|
|
184
|
+
const malformed=checkPrdDraftMechanics(draft('- [ ] T-001: a\n - 范围: `src/*`\n'),{rules:3});
|
|
185
|
+
assert.deepEqual(codes(malformed),['task_scope_invalid']);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('rule 3 in a change proposal requires scope only for tasks the approval covered',()=>{
|
|
189
|
+
const previous={'1.sample':'- [x] T-001: old\n'},scopes={'1.sample':{exempt:['T-001']}};
|
|
190
|
+
const kept=draft('- [x] T-001: old\n- [ ] T-002: new\n - 范围: `b.js`\n');
|
|
191
|
+
assert.equal(checkPrdDraftMechanics(kept,{rules:3,change:true,previous,scopes}).status,'mechanical_subset_passed');
|
|
192
|
+
const added=draft('- [x] T-001: old\n- [ ] T-002: new\n');
|
|
193
|
+
assert.deepEqual(checkPrdDraftMechanics(added,{rules:3,change:true,previous,scopes}).findings[0].reason.tasks,['T-002']);
|
|
194
|
+
// The previous text alone exempts nothing: it may be an unapproved draft.
|
|
195
|
+
assert.deepEqual(checkPrdDraftMechanics(added,{rules:3,change:true,previous}).findings[0].reason.tasks,['T-001','T-002']);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('change exemptions come from the approved bytes and grammar, or the save record, never a draft',()=>{
|
|
199
|
+
const sha=text=>createHash('sha256').update(text).digest('hex');
|
|
200
|
+
// Under the legacy grammar the full-width colon line is a note, not an approved task.
|
|
201
|
+
const approvedText='- [ ] T-001: 原任务\n- [ ] T-002:旧说明\n';
|
|
202
|
+
const status=(text,extra={})=>JSON.stringify({status:'approved',features:['1.sample'],specFiles:[{path:'1.sample/tasks.md',sha256:sha(text)}],...extra});
|
|
203
|
+
const before=(text,statusText,scopeRecords)=>({files:{'1.sample/tasks.md':text},status:statusText,...(scopeRecords?{scopeRecords}:{})});
|
|
204
|
+
assert.deepEqual(approvedScopeExemptions(before(approvedText,status(approvedText)),['1.sample'],1),{'1.sample':{exempt:['T-001']}});
|
|
205
|
+
assert.deepEqual(approvedScopeExemptions(before(approvedText,status(approvedText)),['1.sample'],2),{'1.sample':{exempt:['T-001','T-002']}});
|
|
206
|
+
// A saved but unapproved draft (no status, or bytes that differ from the approval) exempts nothing ...
|
|
207
|
+
assert.deepEqual(approvedScopeExemptions(before('- [ ] T-001: new\n',null),['1.sample'],2),{'1.sample':{exempt:[]}});
|
|
208
|
+
assert.deepEqual(approvedScopeExemptions(before('- [ ] T-001: edited\n',status(approvedText)),['1.sample'],2),{'1.sample':{exempt:[]}});
|
|
209
|
+
// ... except what its own save recorded, which traces back to an approval.
|
|
210
|
+
const record=JSON.stringify({version:1,enforced:true,exempt:['T-001']})+'\n';
|
|
211
|
+
assert.deepEqual(approvedScopeExemptions(before('- [ ] T-001: edited\n',null,{'1.sample':record}),['1.sample'],2),{'1.sample':{exempt:['T-001']}});
|
|
212
|
+
assert.deepEqual(approvedScopeExemptions(before('x',null),['2.added'],2),{'2.added':{exempt:[]}});
|
|
213
|
+
// Approval rows are semantic digests: a task completed after approval still matches.
|
|
214
|
+
const done='- [x] T-001: 原任务\n',semantic=sha(normalizeRuntimeMarkBytes(Buffer.from(done),'tasks.md'));
|
|
215
|
+
const approval=JSON.stringify({status:'approved',specFiles:[{path:'1.sample/tasks.md',sha256:semantic}]});
|
|
216
|
+
assert.deepEqual(approvedScopeExemptions(before(done,approval),['1.sample'],2),{'1.sample':{exempt:['T-001']}});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('scope paths that differ only in case are refused, as the execution side would',()=>{
|
|
220
|
+
const parsed=parseTaskScopes('- [ ] T-001: a\n - 范围: `src/a.js`, `src/A.js`\n');
|
|
221
|
+
assert.equal(parsed.tasks.size,0);assert.match(parsed.errors[0].message,/大小写/);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('reading tasks.md never blocks on a non-regular file and stays inside the specs directory',t=>{
|
|
225
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-fifo-')));
|
|
226
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
227
|
+
fs.mkdirSync(path.join(root,'1.work'));
|
|
228
|
+
assert.equal(spawnSync('mkfifo',[path.join(root,'1.work','tasks.md')]).status,0);
|
|
229
|
+
assert.throws(()=>declaredTaskScope(root,'1.work','T-001'),error=>error.code==='task_scope_invalid'&&/不是普通文件/.test(error.reason));
|
|
230
|
+
const outside=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-outside-')));
|
|
231
|
+
t.after(()=>fs.rmSync(outside,{recursive:true,force:true}));
|
|
232
|
+
fs.writeFileSync(path.join(outside,'tasks.md'),'- [ ] T-001: a\n - 范围: `a.js`\n');
|
|
233
|
+
fs.mkdirSync(path.join(root,'2.link'));fs.symlinkSync(path.join(outside,'tasks.md'),path.join(root,'2.link','tasks.md'));
|
|
234
|
+
assert.throws(()=>declaredTaskScope(root,'2.link','T-001'),error=>error.code==='task_scope_invalid'&&/不在规格目录内/.test(error.reason));
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('a saved scope record holds later re-checks to the scope rule, approved tasks exempt',t=>{
|
|
238
|
+
const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-record-')));
|
|
239
|
+
t.after(()=>fs.rmSync(specs,{recursive:true,force:true}));
|
|
240
|
+
const feature=tasks=>draft(tasks).features[0];
|
|
241
|
+
// Without a record the re-check is unchanged (rule 1 asks nothing about scope).
|
|
242
|
+
assert.deepEqual(prdTaskScopeOptions(specs,'1.sample'),{});
|
|
243
|
+
recordPrdTaskScopes(specs,[feature('- [ ] T-001: old\n- [ ] T-002: new\n - 范围: `b.js`\n')],{'1.sample':{exempt:['T-001']}});
|
|
244
|
+
const options=prdTaskScopeOptions(specs,['1.sample']);
|
|
245
|
+
assert.deepEqual(options,{scopes:{'1.sample':{exempt:['T-001']}}});
|
|
246
|
+
assert.equal(checkPrdDraftMechanics(draft('- [ ] T-001: old\n- [ ] T-002: new\n'),options).findings[0].code,'task_scope_missing');
|
|
247
|
+
assert.equal(checkPrdDraftMechanics(draft('- [ ] T-001: old\n- [ ] T-002: new\n'),{}).status,'mechanical_subset_passed');
|
|
248
|
+
assert.equal(checkPrdDraftMechanics(draft('- [ ] T-001: old\n- [ ] T-002: new\n - 范围: `b.js`\n'),options).status,'mechanical_subset_passed');
|
|
249
|
+
// A draft without scopes records that, and stays on the old rule.
|
|
250
|
+
recordPrdTaskScopes(specs,[feature('- [ ] T-001: a\n')]);
|
|
251
|
+
assert.deepEqual(prdTaskScopeOptions(specs,'1.sample'),{});
|
|
252
|
+
fs.writeFileSync(path.join(specs,'.reviews/prd-sample-task-scope.json'),'{"version":1,"enforced":"yes","exempt":[]}\n',{mode:0o600});
|
|
253
|
+
assert.throws(()=>prdTaskScopeOptions(specs,'1.sample'),/prd_task_scope_record_invalid/);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
function batchSpecs(t,{tasks,log=[]}){
|
|
257
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-batch-')));
|
|
258
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
259
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');
|
|
260
|
+
fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);
|
|
261
|
+
fs.writeFileSync(path.join(codeProject,'req.md'),'# r\n');
|
|
262
|
+
fs.writeFileSync(path.join(specsDir,'1.work','tasks.md'),tasks);
|
|
263
|
+
if(log.length)fs.writeFileSync(path.join(specsDir,'运行日志.jsonl'),log.map(row=>JSON.stringify(row)).join('\n')+'\n');
|
|
264
|
+
const build=(batchId,taskScopes)=>createCmAiBatch({configuration:{version:1,repositoryId:'r',batchId,specsDir,codeProject,
|
|
265
|
+
parallel:[['1.work/T-001','1.work/T-002']],tasks:['T-001','T-002','T-003'].map((taskId,index)=>({feature:'1.work',taskId,
|
|
266
|
+
scope:[taskScopes[index]],requirements:['req.md']}))},executionFor:async()=>({}),logHome:path.join(root,'log')});
|
|
267
|
+
return {specsDir,build};
|
|
268
|
+
}
|
|
269
|
+
const scoped=(a,b,c,extra='')=>`- [ ] T-001: a\n - 范围: \`${a}\`\n${extra}- [ ] T-002: b\n - 范围: \`${b}\`\n- [ ] T-003: c\n - 范围: \`${c}\`\n\n- T-003 依赖 T-001, T-002\n`;
|
|
270
|
+
|
|
271
|
+
test('a new batch takes parallel members only from tasks that declare their files',t=>{
|
|
272
|
+
const declared=batchSpecs(t,{tasks:scoped('a.js','b.js','c.js')});
|
|
273
|
+
assert.ok(declared.build('scope-ok-1',['a.js','b.js','c.js']));
|
|
274
|
+
const undeclared=batchSpecs(t,{tasks:'- [ ] T-001: a\n- [ ] T-002: b\n- [ ] T-003: c\n\n- T-003 依赖 T-001, T-002\n'});
|
|
275
|
+
assert.throws(()=>undeclared.build('scope-none-1',['a.js','b.js','c.js']),{code:'parallel_scope_undeclared'});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('a device task never joins a parallel group',t=>{
|
|
279
|
+
const f=batchSpecs(t,{tasks:scoped('a.js','b.js','c.js',' - 设备: 需要\n')});
|
|
280
|
+
assert.throws(()=>f.build('device-1',['a.js','b.js','c.js']),{code:'parallel_device_task'});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('a batch member whose configured files depart from tasks.md is refused',t=>{
|
|
284
|
+
const f=batchSpecs(t,{tasks:scoped('a.js','b.js','c.js')});
|
|
285
|
+
assert.throws(()=>f.build('mismatch-1',['a.js','other.js','c.js']),error=>error.code==='task_scope_mismatch'&&/1\.work\/T-002/.test(error.reason));
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('a batch that started before tasks.md scope keeps resuming under its original rules',t=>{
|
|
289
|
+
const start={schema_version:1,workflow:'cm-ai',event:'decision',phase:'batch_start',run_id:'legacy-batch',from_key:'1.work/T-001'};
|
|
290
|
+
const f=batchSpecs(t,{tasks:'- [ ] T-001: a\n- [ ] T-002: b\n- [ ] T-003: c\n\n- T-003 依赖 T-001, T-002\n',log:[start]});
|
|
291
|
+
assert.ok(f.build('legacy-batch',['a.js','b.js','c.js']));
|
|
292
|
+
// The same tasks under a batch that has not started are refused.
|
|
293
|
+
assert.throws(()=>f.build('fresh-batch',['a.js','b.js','c.js']),{code:'parallel_scope_undeclared'});
|
|
294
|
+
// A recorded segment marks a new-style start; it does not exempt the batch from anything else.
|
|
295
|
+
const g=batchSpecs(t,{tasks:scoped('a.js','b.js','c.js'),log:[{...start,run_id:'new-batch',[BATCH_SEGMENT_FIELD]:batchSegment('new-batch')}]});
|
|
296
|
+
assert.ok(g.build('new-batch',['a.js','b.js','c.js']));
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('declaredTaskScope reads one task and refuses a malformed sub-item of that task only',t=>{
|
|
300
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-scope-read-')));
|
|
301
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
302
|
+
fs.mkdirSync(path.join(root,'1.work'));
|
|
303
|
+
fs.writeFileSync(path.join(root,'1.work','tasks.md'),'- [ ] T-001: a\n - 范围: `a.js`\n- [ ] T-002: b\n - 范围: `bad/*`\n- [ ] T-003: c\n');
|
|
304
|
+
assert.deepEqual(declaredTaskScope(root,'1.work','T-001').scope,['a.js']);
|
|
305
|
+
assert.equal(declaredTaskScope(root,'1.work','T-003'),null);
|
|
306
|
+
assert.throws(()=>declaredTaskScope(root,'1.work','T-002'),{code:'task_scope_invalid'});
|
|
307
|
+
assert.equal(declaredTaskScope(root,'2.none','T-001'),null);
|
|
308
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// One native sandbox inventory for CI exclusions, local runs and release smoke.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawn} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {assignShards, readWeights} from './ci-test-shards.mjs';
|
|
9
|
+
|
|
10
|
+
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
11
|
+
export const nativeTests = Object.freeze([
|
|
12
|
+
'scripts/cm-ai-batch-host.test.mjs',
|
|
13
|
+
'scripts/cm-ai-bootstrap.test.mjs',
|
|
14
|
+
'scripts/cm-ai-host.test.mjs',
|
|
15
|
+
'scripts/cm-ai-host-cli-workflow.test.mjs',
|
|
16
|
+
'scripts/cm-ai-host-protected.test.mjs',
|
|
17
|
+
'scripts/cm-ai-multi-root.test.mjs',
|
|
18
|
+
'scripts/cm-ai-nested-execution.test.mjs',
|
|
19
|
+
'scripts/cm-fix-protected-edits.test.mjs',
|
|
20
|
+
'scripts/cm-host-check.test.mjs',
|
|
21
|
+
].sort());
|
|
22
|
+
|
|
23
|
+
export function inventory(repo = root) {
|
|
24
|
+
const discover = dir => fs.readdirSync(path.join(repo, dir), {withFileTypes: true})
|
|
25
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.test.mjs'))
|
|
26
|
+
.map(entry => `${dir}/${entry.name}`).sort();
|
|
27
|
+
const all = discover('scripts');
|
|
28
|
+
const native = [...nativeTests];
|
|
29
|
+
if (native.length !== 9 || new Set(native).size !== 9) throw new Error('native inventory must contain exactly nine unique tests');
|
|
30
|
+
for (const file of native) if (!all.includes(file)) throw new Error(`missing native test: ${file}`);
|
|
31
|
+
const ordinary = all.filter(file => !native.includes(file));
|
|
32
|
+
const combined = [...ordinary, ...native];
|
|
33
|
+
if (new Set(combined).size !== all.length || combined.length !== all.length ||
|
|
34
|
+
combined.some(file => !all.includes(file))) throw new Error('test groups must cover scripts tests exactly once');
|
|
35
|
+
const history = discover('experiments/js-orchestration');
|
|
36
|
+
return {ordinary, native, history};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function selectTests(groups, group, {shards, index} = {}) {
|
|
40
|
+
if (!Object.hasOwn(groups, group)) throw new Error('group must be ordinary, native or history');
|
|
41
|
+
const files = groups[group];
|
|
42
|
+
if (shards === undefined && index === undefined) return files;
|
|
43
|
+
if (!Number.isInteger(shards) || shards < 1 || !Number.isInteger(index) || index < 0 || index >= shards)
|
|
44
|
+
throw new Error('--shards and --index must specify a positive count and an index in [0, shards)');
|
|
45
|
+
return assignShards(files, shards, readWeights())[index].files;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function runTests(files, concurrency) {
|
|
49
|
+
if (files.length === 0) throw new Error('selected test group or shard is empty');
|
|
50
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-test-suite-'));
|
|
51
|
+
const workflowHome = path.join(temp, 'workflow'), logHome = path.join(temp, 'logs');
|
|
52
|
+
fs.mkdirSync(workflowHome); fs.mkdirSync(logHome);
|
|
53
|
+
const args = ['--test', ...(concurrency === undefined ? [] : [`--test-concurrency=${concurrency}`]), ...files];
|
|
54
|
+
let child, requestedSignal;
|
|
55
|
+
const handlers = new Map();
|
|
56
|
+
try {
|
|
57
|
+
child = spawn(process.execPath, args, {cwd: root, stdio: 'inherit', detached: process.platform !== 'win32',
|
|
58
|
+
env: {...process.env, CM_WORKFLOW_HOME: workflowHome, CM_WORKFLOW_LOG_HOME: logHome}});
|
|
59
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
60
|
+
const handler = () => {
|
|
61
|
+
requestedSignal ??= signal;
|
|
62
|
+
if (!child.pid) return;
|
|
63
|
+
try {
|
|
64
|
+
if (process.platform === 'win32') child.kill(signal);
|
|
65
|
+
else process.kill(-child.pid, signal);
|
|
66
|
+
} catch (error) { if (error.code !== 'ESRCH') throw error; }
|
|
67
|
+
};
|
|
68
|
+
handlers.set(signal, handler); process.on(signal, handler);
|
|
69
|
+
}
|
|
70
|
+
const result = await new Promise((resolve, reject) => {
|
|
71
|
+
child.once('error', reject);
|
|
72
|
+
child.once('close', (code, signal) => resolve({code, signal}));
|
|
73
|
+
});
|
|
74
|
+
return {code: result.code ?? 1, signal: requestedSignal ?? result.signal};
|
|
75
|
+
} finally {
|
|
76
|
+
for (const [signal, handler] of handlers) process.off(signal, handler);
|
|
77
|
+
fs.rmSync(temp, {recursive: true, force: true});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function main(argv) {
|
|
82
|
+
const [command, ...rest] = argv;
|
|
83
|
+
if (!['check', 'list', 'run'].includes(command)) throw new Error('usage: cm-test-suite.mjs check | list|run ordinary|native|history [--shards N --index I] [--concurrency N]');
|
|
84
|
+
if (command === 'check') {
|
|
85
|
+
if (rest.length) throw new Error('check takes no arguments');
|
|
86
|
+
const groups = inventory();
|
|
87
|
+
for (const [group, files] of Object.entries(groups)) process.stdout.write(`${group}: ${files.length} files\n`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const group = rest.shift(), options = {};
|
|
91
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
92
|
+
const key = rest[i];
|
|
93
|
+
if (!['--shards', '--index', '--concurrency'].includes(key) || Object.hasOwn(options, key.slice(2)))
|
|
94
|
+
throw new Error(`unknown or repeated option: ${key}`);
|
|
95
|
+
if (!/^\d+$/.test(rest[i + 1] ?? '')) throw new Error(`invalid value for ${key}`);
|
|
96
|
+
options[key.slice(2)] = Number(rest[i + 1]);
|
|
97
|
+
}
|
|
98
|
+
if (options.concurrency !== undefined && (command !== 'run' || !Number.isSafeInteger(options.concurrency) || options.concurrency < 1))
|
|
99
|
+
throw new Error('--concurrency must be a positive integer for run');
|
|
100
|
+
const files = selectTests(inventory(), group, options);
|
|
101
|
+
if (command === 'list') { for (const file of files) process.stdout.write(`${file}\n`); return; }
|
|
102
|
+
const result = await runTests(files, options.concurrency);
|
|
103
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
104
|
+
else process.exitCode = result.code;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
108
|
+
main(process.argv.slice(2)).catch(error => { process.stderr.write(`cm-test-suite: ${error.message}\n`); process.exitCode = 1; });
|
|
109
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
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 {spawn, spawnSync} from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {nativeTests, inventory, selectTests} from './cm-test-suite.mjs';
|
|
10
|
+
import {assignShards, readWeights} from './ci-test-shards.mjs';
|
|
11
|
+
|
|
12
|
+
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
13
|
+
function cliEnv(env) {
|
|
14
|
+
const copy = {...env};
|
|
15
|
+
delete copy.NODE_TEST_CONTEXT; // The CLI starts an independent node --test invocation.
|
|
16
|
+
return copy;
|
|
17
|
+
}
|
|
18
|
+
const cli = (args, cwd = root, env = process.env) => spawnSync(process.execPath,
|
|
19
|
+
[path.join(cwd, 'scripts/cm-test-suite.mjs'), ...args], {cwd, env: cliEnv(env), encoding: 'utf8'});
|
|
20
|
+
|
|
21
|
+
function fixture(t, source = 'import test from "node:test"; test("fixture",()=>{});') {
|
|
22
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-test-suite-fixture-'));
|
|
23
|
+
t.after(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
24
|
+
fs.mkdirSync(path.join(dir, 'scripts'));
|
|
25
|
+
fs.mkdirSync(path.join(dir, 'experiments/js-orchestration'), {recursive: true});
|
|
26
|
+
for (const name of ['cm-test-suite.mjs', 'ci-test-shards.mjs', 'ci-test-weights.json'])
|
|
27
|
+
fs.copyFileSync(path.join(root, 'scripts', name), path.join(dir, 'scripts', name));
|
|
28
|
+
for (const file of nativeTests) fs.writeFileSync(path.join(dir, file), '');
|
|
29
|
+
fs.writeFileSync(path.join(dir, 'scripts/example.test.mjs'), source);
|
|
30
|
+
fs.writeFileSync(path.join(dir, 'experiments/js-orchestration/history.test.mjs'), source);
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test('approved native inventory is fixed, complete and disjoint from ordinary tests', () => {
|
|
35
|
+
assert.equal(nativeTests.length, 9);
|
|
36
|
+
// Approval fingerprint prevents additions, omissions and substitutions without a reviewed change.
|
|
37
|
+
assert.equal(createHash('sha256').update(nativeTests.join('\n')).digest('hex'), 'e036b229f15e0acca13f43c29a35a2cbc830b1dcdd812b1f379b46253f3eadce');
|
|
38
|
+
const groups = inventory(root);
|
|
39
|
+
const discovered = fs.readdirSync(path.join(root, 'scripts'))
|
|
40
|
+
.filter(name => name.endsWith('.test.mjs')).map(name => `scripts/${name}`).sort();
|
|
41
|
+
assert.deepEqual([...groups.ordinary, ...groups.native].sort(), discovered);
|
|
42
|
+
assert.equal(new Set([...groups.ordinary, ...groups.native]).size, discovered.length);
|
|
43
|
+
assert.deepEqual(groups.native, nativeTests);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('listing every group is install-free and ordinary shards reuse the existing assignment', () => {
|
|
47
|
+
for (const group of ['ordinary', 'native', 'history']) {
|
|
48
|
+
const run = cli(['list', group]);
|
|
49
|
+
assert.equal(run.status, 0, run.stderr);
|
|
50
|
+
assert.deepEqual(run.stdout.trim().split('\n'), inventory(root)[group]);
|
|
51
|
+
}
|
|
52
|
+
const groups = inventory(root);
|
|
53
|
+
const shards = assignShards(groups.ordinary, 4, readWeights());
|
|
54
|
+
for (let index = 0; index < 4; index++)
|
|
55
|
+
assert.deepEqual(selectTests(groups, 'ordinary', {shards: 4, index}), shards[index].files);
|
|
56
|
+
assert.deepEqual(shards.flatMap(shard => shard.files).sort(), groups.ordinary);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('new ordinary tests are included and missing native members stop the CLI', t => {
|
|
60
|
+
const dir = fixture(t);
|
|
61
|
+
fs.writeFileSync(path.join(dir, 'scripts/new.test.mjs'), '');
|
|
62
|
+
assert.match(cli(['list', 'ordinary'], dir).stdout, /scripts\/new.test.mjs/);
|
|
63
|
+
fs.unlinkSync(path.join(dir, nativeTests[0]));
|
|
64
|
+
const run = cli(['check'], dir);
|
|
65
|
+
assert.notEqual(run.status, 0);
|
|
66
|
+
assert.match(run.stderr, /missing native test/);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('runner isolates both CM homes and cleans up after success', t => {
|
|
70
|
+
const dir = fixture(t, `import test from 'node:test'; import assert from 'node:assert/strict';
|
|
71
|
+
import fs from 'node:fs';
|
|
72
|
+
test('isolation',()=>{
|
|
73
|
+
assert.notEqual(process.env.CM_WORKFLOW_HOME, process.env.CALLER_HOME);
|
|
74
|
+
assert.notEqual(process.env.CM_WORKFLOW_LOG_HOME, process.env.CALLER_LOG_HOME);
|
|
75
|
+
assert(fs.statSync(process.env.CM_WORKFLOW_HOME).isDirectory());
|
|
76
|
+
assert(fs.statSync(process.env.CM_WORKFLOW_LOG_HOME).isDirectory());
|
|
77
|
+
fs.writeFileSync(process.env.CAPTURE, JSON.stringify([process.env.CM_WORKFLOW_HOME,process.env.CM_WORKFLOW_LOG_HOME]));
|
|
78
|
+
});`);
|
|
79
|
+
const capture = path.join(dir, 'capture.json');
|
|
80
|
+
const callerHome = path.join(dir, 'caller-home'), callerLogs = path.join(dir, 'caller-logs');
|
|
81
|
+
const run = cli(['run', 'ordinary', '--concurrency', '1'], dir,
|
|
82
|
+
{...process.env, CM_WORKFLOW_HOME: callerHome, CM_WORKFLOW_LOG_HOME: callerLogs,
|
|
83
|
+
CALLER_HOME: callerHome, CALLER_LOG_HOME: callerLogs, CAPTURE: capture});
|
|
84
|
+
assert.equal(run.status, 0, run.stderr + run.stdout);
|
|
85
|
+
for (const item of JSON.parse(fs.readFileSync(capture))) assert.equal(fs.existsSync(item), false);
|
|
86
|
+
assert.equal(fs.existsSync(callerHome), false);
|
|
87
|
+
assert.equal(fs.existsSync(callerLogs), false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('explicit concurrency reaches the Node runner', t => {
|
|
91
|
+
const source = `import test from 'node:test'; import fs from 'node:fs'; import assert from 'node:assert/strict';
|
|
92
|
+
test('overlap',async()=>{
|
|
93
|
+
fs.writeFileSync(process.env.CAPTURE+'/'+process.pid,'ready');
|
|
94
|
+
const deadline=Date.now()+5000;
|
|
95
|
+
while(fs.readdirSync(process.env.CAPTURE).length<2 && Date.now()<deadline)
|
|
96
|
+
await new Promise(resolve=>setTimeout(resolve,10));
|
|
97
|
+
assert.equal(fs.readdirSync(process.env.CAPTURE).length,2,'both test files must run concurrently');
|
|
98
|
+
});`;
|
|
99
|
+
const dir = fixture(t, source), capture = path.join(dir, 'parallel');
|
|
100
|
+
fs.mkdirSync(capture);
|
|
101
|
+
fs.writeFileSync(path.join(dir, 'scripts/second.test.mjs'), source);
|
|
102
|
+
const run = cli(['run', 'ordinary', '--concurrency', '2'], dir, {...process.env, CAPTURE: capture});
|
|
103
|
+
assert.equal(run.status, 0, run.stderr + run.stdout);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('failed tests fail exactly once in ordinary and historical groups', t => {
|
|
107
|
+
const dir = fixture(t, `import test from 'node:test'; import fs from 'node:fs';
|
|
108
|
+
test('fail',()=>{fs.appendFileSync(process.env.CAPTURE,'attempt\\n');throw new Error('intentional fixture failure');});`);
|
|
109
|
+
for (const group of ['ordinary', 'history']) {
|
|
110
|
+
const capture = path.join(dir, `${group}.txt`);
|
|
111
|
+
const run = cli(['run', group], dir, {...process.env, CAPTURE: capture});
|
|
112
|
+
assert.equal(run.status, 1, run.stderr + run.stdout);
|
|
113
|
+
assert.equal(fs.readFileSync(capture, 'utf8'), 'attempt\n');
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('invalid arguments fail before running tests', t => {
|
|
118
|
+
const dir = fixture(t, 'throw new Error("must not execute");');
|
|
119
|
+
for (const args of [['run', 'unknown'], ['run', 'ordinary', '--concurrency', '0'],
|
|
120
|
+
['run', 'ordinary', '--shards', '4'], ['list', 'ordinary', '--index', '0'],
|
|
121
|
+
['run', 'ordinary', '--shards', '2', '--index', '2'], ['run', 'ordinary', '--retry']]) {
|
|
122
|
+
const run = cli(args, dir);
|
|
123
|
+
assert.notEqual(run.status, 0);
|
|
124
|
+
assert.doesNotMatch(run.stdout + run.stderr, /must not execute/);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('parent signals reach tests, preserve failure and remove temporary homes', {skip: process.platform === 'win32'}, async t => {
|
|
129
|
+
const dir = fixture(t, `import fs from 'node:fs';
|
|
130
|
+
process.on('SIGTERM',()=>{fs.writeFileSync(process.env.SIGNAL_CAPTURE,'received'); process.exit(0);});
|
|
131
|
+
fs.writeFileSync(process.env.CAPTURE, process.env.CM_WORKFLOW_HOME);
|
|
132
|
+
setInterval(()=>{},1000);`);
|
|
133
|
+
const capture = path.join(dir, 'ready'), signalCapture = path.join(dir, 'signal');
|
|
134
|
+
const child = spawn(process.execPath, [path.join(dir, 'scripts/cm-test-suite.mjs'), 'run', 'ordinary'],
|
|
135
|
+
{cwd: dir, env: cliEnv({...process.env, CAPTURE: capture, SIGNAL_CAPTURE: signalCapture}), stdio: 'ignore'});
|
|
136
|
+
t.after(() => { if (child.exitCode === null && child.signalCode === null) child.kill('SIGKILL'); });
|
|
137
|
+
const closed = new Promise(resolve => child.on('close', (code, signal) => resolve({code, signal})));
|
|
138
|
+
const deadline = Date.now() + 10000;
|
|
139
|
+
while (!fs.existsSync(capture) && Date.now() < deadline) await new Promise(resolve => setTimeout(resolve, 20));
|
|
140
|
+
assert(fs.existsSync(capture), 'test child did not become ready');
|
|
141
|
+
child.kill('SIGTERM');
|
|
142
|
+
let timer;
|
|
143
|
+
const result = await Promise.race([closed, new Promise((_, reject) => {
|
|
144
|
+
timer = setTimeout(() => reject(new Error('signal not propagated')), 10000);
|
|
145
|
+
})]).finally(() => clearTimeout(timer));
|
|
146
|
+
assert.equal(result.signal, 'SIGTERM');
|
|
147
|
+
assert.equal(fs.readFileSync(signalCapture, 'utf8'), 'received');
|
|
148
|
+
assert.equal(fs.existsSync(fs.readFileSync(capture, 'utf8')), false);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('CI and release smoke consume the same entrypoint without a second exclusion list', () => {
|
|
152
|
+
const ci = fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8');
|
|
153
|
+
const release = fs.readFileSync(path.join(root, 'scripts/cm-release-smoke.sh'), 'utf8');
|
|
154
|
+
assert.match(ci, /node scripts\/cm-test-suite\.mjs check/);
|
|
155
|
+
assert.match(ci, /node scripts\/cm-test-suite\.mjs run ordinary --shards 4 --index \$\{\{ matrix\.shard \}\}/);
|
|
156
|
+
assert.match(ci, /node scripts\/cm-test-suite\.mjs run history --concurrency 4/);
|
|
157
|
+
assert.match(release, /node "\$ROOT\/scripts\/cm-test-suite\.mjs" run native/);
|
|
158
|
+
for (const file of nativeTests) {
|
|
159
|
+
assert(!ci.includes(path.basename(file, '.test.mjs')), 'CI duplicated the native inventory');
|
|
160
|
+
assert(!release.includes(file), 'release duplicated the native inventory');
|
|
161
|
+
}
|
|
162
|
+
});
|