@aibyzero/cm-workflow 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +23 -0
- package/CHANGELOG.md +224 -0
- package/README.md +14 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +114 -11
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +11 -5
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +242 -39
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +11 -5
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +3 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +6 -5
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +471 -57
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +14 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +4 -3
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +575 -59
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +45 -1
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-summary.test.mjs +24 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +1 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +56 -16
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -0,0 +1,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,172 @@
|
|
|
1
|
+
// Upgrade compatibility (review R2-02, part 2): a batch started before the batch
|
|
2
|
+
// execution table (batch.memberDevelopment, design 3.7) resumes on the new code with its
|
|
3
|
+
// original plan digest, member fingerprints and path, and runs to completion.
|
|
4
|
+
//
|
|
5
|
+
// Archive format pinned from f73402d (the last commit before the upgrade):
|
|
6
|
+
// - scripts/cm-ai-batch-run.mjs: planDigest=digest(config) (line 160), and the first
|
|
7
|
+
// advance writes record('batch_start',{from_key,[BATCH_SEGMENT_FIELD]:batchSegment(batchId)})
|
|
8
|
+
// (line 530) through cm-log-event.py before any member run exists;
|
|
9
|
+
// - scripts/cm-ai-batch-host.mjs: config={...batch,controlPolicy} for a v2 batch;
|
|
10
|
+
// - runtime/js/cm-ai/batch-location.mjs: batchSegment = first 8 chars of batchId ('.'->'-')
|
|
11
|
+
// + '-' + sha256(batchId)[0..12], field worktree_segment.
|
|
12
|
+
// A real f73402d run of this fixture wrote exactly these batch_start keys (checked by the
|
|
13
|
+
// last test whenever f73402d is in the local history; CI shallow clones skip it).
|
|
14
|
+
import test from 'node:test';
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
20
|
+
import {spawnSync} from 'node:child_process';
|
|
21
|
+
import {fileURLToPath} from 'node:url';
|
|
22
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
24
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
25
|
+
|
|
26
|
+
const repo=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
27
|
+
const LEGACY_COMMIT='f73402d';
|
|
28
|
+
const batchId='legacy-batch-run',repositoryId='legacy-batch-fixture';
|
|
29
|
+
const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'run',qaFix:'disabled'};
|
|
30
|
+
const develop={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
31
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
32
|
+
// The batch_start keys f73402d wrote (cm-log-event.py envelope + record() data).
|
|
33
|
+
const LEGACY_START_KEYS=['schema_version','run_id','at','workflow','event','runtime','project','detail','phase',
|
|
34
|
+
'project_path','specs_path','repository_id','plan_digest','from_key','worktree_segment','event_id'].sort();
|
|
35
|
+
|
|
36
|
+
// Two serial members (T-002 waits for T-001), task grammar 2 approval, v2 conversation
|
|
37
|
+
// development with QA, no execution table: the shape every pre-upgrade batch had.
|
|
38
|
+
function fixture(t){
|
|
39
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-batch-')));
|
|
40
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
41
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'app'),bin=path.join(root,'bin'),reject=path.join(root,'reject-T-002');
|
|
42
|
+
fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
|
|
43
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
|
|
44
|
+
fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),
|
|
45
|
+
'- [ ] T-001: first\n - 范围: `target.mjs`\n- [ ] T-002: second\n - 范围: `other.mjs`\n\n## 依赖关系\n\n- T-002 依赖 T-001\n');
|
|
46
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],
|
|
47
|
+
specFiles:buildManifest(specsDir),taskGrammar:2}));
|
|
48
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
49
|
+
for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
|
|
50
|
+
const r=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(r.status,0,r.stderr);
|
|
51
|
+
}
|
|
52
|
+
const workflow={qa:{commands:[{id:'value',caseIds:[],command:[process.execPath,'-e',"import('./target.mjs').then(m=>{if(m.value!==42)process.exit(1)})"]}],
|
|
53
|
+
environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'}},documentationPaths:[],applicableAgentFiles:[]};
|
|
54
|
+
const bundle={batch:{version:1,repositoryId,batchId,specsDir,codeProject,tasks:[
|
|
55
|
+
{feature:'1.work',taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']},
|
|
56
|
+
{feature:'1.work',taskId:'T-002',scope:['other.mjs'],requirements:['requirements.md']}]},
|
|
57
|
+
workflows:{'1.work/T-001':workflow,'1.work/T-002':workflow}};
|
|
58
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify(bundle));
|
|
59
|
+
fs.writeFileSync(path.join(root,'control.json'),JSON.stringify(policy));
|
|
60
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
|
|
61
|
+
prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
|
|
62
|
+
// Fixture Codex reviewer: approves, except T-002 while the reject marker exists.
|
|
63
|
+
fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}
|
|
64
|
+
const fs=require('node:fs');let prompt='';process.stdin.on('data',part=>prompt+=part);process.stdin.on('end',()=>{
|
|
65
|
+
const marker='<cm-review-data-json>\\n',data=JSON.parse(prompt.slice(prompt.indexOf(marker)+marker.length));
|
|
66
|
+
const reject=data.reviewPackage.identity.taskId==='T-002'&&fs.existsSync(${JSON.stringify(reject)});
|
|
67
|
+
const value={verdict:reject?'changes_requested':'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,
|
|
68
|
+
findings:reject?[{id:'F1',severity:'P2',path:'other.mjs',message:'Use 2',evidence:'Fixture finding'}]:[],summary:'Synthetic review'};
|
|
69
|
+
for(const event of [{type:'thread.started',thread_id:'fixture-'+Date.now()},{type:'turn.started'},
|
|
70
|
+
{type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}])process.stdout.write(JSON.stringify(event)+'\\n');
|
|
71
|
+
});
|
|
72
|
+
`,{mode:0o700});
|
|
73
|
+
for(const [task,file,source] of [['T-001','target.mjs','export const value = 42;\n'],['T-002','other.mjs','export const other = 1;\n']]){
|
|
74
|
+
const dir=path.join(root,'answers/1.work',task);fs.mkdirSync(dir,{recursive:true});
|
|
75
|
+
fs.writeFileSync(path.join(dir,'develop.json'),JSON.stringify({...develop,edits:{[file]:`${task}.txt`}}));
|
|
76
|
+
fs.writeFileSync(path.join(dir,`${task}.txt`),source);
|
|
77
|
+
fs.writeFileSync(path.join(dir,'documentation-inspect.json'),JSON.stringify({status:'completed',reason:'Fixture inspected'}));
|
|
78
|
+
fs.writeFileSync(path.join(dir,'qa-assess.json'),JSON.stringify({confirmed:true}));
|
|
79
|
+
}
|
|
80
|
+
const plan=path.join(root,'plan.json');
|
|
81
|
+
const writePlan=mode=>fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode,hostContext:'legacy-host',
|
|
82
|
+
...(mode==='resume'?{originalHostContext:'legacy-host'}:{}),controlConfig:'control.json',
|
|
83
|
+
permissions:['--review-config','review.json'],answers:'answers',
|
|
84
|
+
checks:{'1.work/T-001':[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],
|
|
85
|
+
'1.work/T-002':[{id:'syntax',command:[process.execPath,'--check','other.mjs']}]}}));
|
|
86
|
+
writePlan('create');
|
|
87
|
+
const drive=(workflowRoot=repo)=>spawnSync(process.execPath,[path.join(workflowRoot,'scripts/cm-ai-batch-drive.mjs'),'--plan',plan,'advance'],
|
|
88
|
+
{encoding:'utf8',timeout:120000,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
89
|
+
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
|
|
90
|
+
return {root,specsDir,codeProject,bundle,reject,writePlan,drive,log:path.join(specsDir,'运行日志.jsonl')};
|
|
91
|
+
}
|
|
92
|
+
// The plan digest and worktree segment exactly as f73402d computed them.
|
|
93
|
+
const legacyPlanDigest=bundle=>digest({...bundle.batch,controlPolicy:policy});
|
|
94
|
+
const legacySegment=id=>`${id.slice(0,8).replace(/\./g,'-')}-${createHash('sha256').update(id).digest('hex').slice(0,12)}`;
|
|
95
|
+
const batchRows=f=>fs.readFileSync(f.log,'utf8').trim().split('\n').map(line=>JSON.parse(line))
|
|
96
|
+
.filter(row=>row.run_id===batchId&&row.event==='decision'&&row.phase.startsWith('batch_'));
|
|
97
|
+
const memberStates=f=>{
|
|
98
|
+
const dir=path.join(f.specsDir,'.reviews/.execution');
|
|
99
|
+
return Object.fromEntries(fs.readdirSync(dir).filter(name=>fs.existsSync(path.join(dir,name,'state.json')))
|
|
100
|
+
.map(name=>[name,JSON.parse(fs.readFileSync(path.join(dir,name,'state.json'),'utf8'))]));
|
|
101
|
+
};
|
|
102
|
+
const lastResult=r=>JSON.parse(r.stdout.slice(r.stdout.indexOf('{'),r.stdout.lastIndexOf('}')+1)).result;
|
|
103
|
+
// Resume with the current code until the batch stops on its own.
|
|
104
|
+
function resumeToDone(f){
|
|
105
|
+
f.writePlan('resume');let result=null;
|
|
106
|
+
for(let round=0;round<6;round++){
|
|
107
|
+
const r=f.drive();assert.equal(r.status,0,r.stderr);result=lastResult(r);
|
|
108
|
+
if(['run_done','blocked'].includes(result.state)||result.outcome==='rejected')break;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function assertLegacyCompletion(f,expectedPlanDigest){
|
|
113
|
+
const rows=batchRows(f);
|
|
114
|
+
assert.deepEqual(rows.map(row=>row.phase),['batch_start','batch_task_committed','batch_handoff','batch_task_committed']);
|
|
115
|
+
assert.deepEqual([...new Set(rows.map(row=>row.plan_digest))],[expectedPlanDigest],'every row keeps the pre-upgrade plan digest');
|
|
116
|
+
const text=fs.readFileSync(f.log,'utf8');
|
|
117
|
+
assert.doesNotMatch(text,/memberDevelopment|member_development/,'no execution table enters the log');
|
|
118
|
+
assert.equal(Object.hasOwn(JSON.parse(fs.readFileSync(path.join(f.root,'run.json'),'utf8')).batch,'memberDevelopment'),false);
|
|
119
|
+
for(const [runId,state] of Object.entries(memberStates(f)))
|
|
120
|
+
assert.doesNotMatch(JSON.stringify(state),/memberDevelopment/,`${runId} carries no execution table`);
|
|
121
|
+
const log=spawnSync('git',['-C',f.codeProject,'log','--format=%s'],{encoding:'utf8'}).stdout;
|
|
122
|
+
assert.deepEqual(log.trim().split('\n'),['T-002: second','T-001: first','baseline'],'both members committed on the original serial path');
|
|
123
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,'1.work/tasks.md'),'utf8'),/\[x\] T-001[\s\S]*\[x\] T-002/);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
test('a batch whose pre-upgrade host wrote batch_start and stopped before its first member resumes on the old plan digest to run_done',t=>{
|
|
127
|
+
const f=fixture(t),planDigest=legacyPlanDigest(f.bundle);
|
|
128
|
+
// Hand-written archive: the one row f73402d wrote at the first advance, before any member run.
|
|
129
|
+
const row={schema_version:1,run_id:batchId,at:'2026-10-20T08:00:00+00:00',workflow:'cm-ai',event:'decision',runtime:'codex',
|
|
130
|
+
project:'app',detail:'Approved task batch started',phase:'batch_start',project_path:f.codeProject,specs_path:f.specsDir,
|
|
131
|
+
repository_id:repositoryId,plan_digest:planDigest,from_key:'1.work/T-001',worktree_segment:legacySegment(batchId),event_id:randomUUID()};
|
|
132
|
+
assert.deepEqual(Object.keys(row).sort(),LEGACY_START_KEYS);
|
|
133
|
+
fs.writeFileSync(f.log,JSON.stringify(row)+'\n');
|
|
134
|
+
const result=resumeToDone(f);
|
|
135
|
+
assert.equal(result.state,'run_done',JSON.stringify(result).slice(0,800));
|
|
136
|
+
assertLegacyCompletion(f,planDigest);
|
|
137
|
+
assert.equal(batchRows(f)[0].event_id,row.event_id,'the original batch_start row is kept, not rewritten');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const legacyAvailable=spawnSync('git',['-C',repo,'cat-file','-e',`${LEGACY_COMMIT}^{commit}`]).status===0;
|
|
141
|
+
test('a batch the f73402d code really ran to mid-member resumes on the new code with unchanged fingerprints to run_done',
|
|
142
|
+
{skip:legacyAvailable?false:`${LEGACY_COMMIT} 不在本地历史(浅克隆),跳过真实旧代码运行`,timeout:300000},t=>{
|
|
143
|
+
const old=fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-old-'));t.after(()=>fs.rmSync(old,{recursive:true,force:true}));
|
|
144
|
+
const archive=spawnSync('sh',['-c',`git -C "$1" archive ${LEGACY_COMMIT} | tar -x -C "$2"`,'archive',repo,old],{encoding:'utf8'});
|
|
145
|
+
assert.equal(archive.status,0,archive.stderr);
|
|
146
|
+
const f=fixture(t);fs.writeFileSync(f.reject,'');
|
|
147
|
+
// Pre-upgrade run: T-001 done and handed off, T-002 stopped after a changes_requested review.
|
|
148
|
+
const first=f.drive(old);assert.equal(first.status,0,first.stderr);
|
|
149
|
+
const stopped=lastResult(first);
|
|
150
|
+
assert.deepEqual([stopped.state,stopped.code,stopped.identity.taskId],['changes_requested','revision_answer_required','T-002']);
|
|
151
|
+
const before=batchRows(f),states=memberStates(f);
|
|
152
|
+
assert.deepEqual(before.map(row=>row.phase),['batch_start','batch_task_committed','batch_handoff']);
|
|
153
|
+
// The hand-written archive above matches the real one: same row keys, same digest formula.
|
|
154
|
+
assert.deepEqual(Object.keys(before[0]).sort(),LEGACY_START_KEYS);
|
|
155
|
+
assert.equal(before[0].plan_digest,legacyPlanDigest(f.bundle));
|
|
156
|
+
assert.equal(before[0].worktree_segment,legacySegment(batchId));
|
|
157
|
+
assert.equal(Object.keys(states).length,2);
|
|
158
|
+
for(const state of Object.values(states))assert.deepEqual(Object.keys(state.fingerprints).sort(),['config','inputs','workflow']);
|
|
159
|
+
// Upgrade: the T-002 author answers the review; the reviewer now approves.
|
|
160
|
+
fs.rmSync(f.reject);
|
|
161
|
+
const answers=path.join(f.root,'answers/1.work/T-002');
|
|
162
|
+
fs.writeFileSync(path.join(answers,'develop-a2.json'),JSON.stringify({...develop,edits:{'other.mjs':'second.txt'}}));
|
|
163
|
+
fs.writeFileSync(path.join(answers,'second.txt'),'export const other = 2;\n');
|
|
164
|
+
const result=resumeToDone(f);
|
|
165
|
+
assert.equal(result.state,'run_done',JSON.stringify(result).slice(0,800));
|
|
166
|
+
assertLegacyCompletion(f,before[0].plan_digest);
|
|
167
|
+
assert.deepEqual(batchRows(f).slice(0,3),before,'the pre-upgrade rows are kept byte for byte');
|
|
168
|
+
const after=memberStates(f);
|
|
169
|
+
for(const [runId,state] of Object.entries(states))
|
|
170
|
+
assert.deepEqual(after[runId].fingerprints,state.fingerprints,`${runId} keeps its pre-upgrade fingerprints`);
|
|
171
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'other.mjs'),'utf8'),'export const other = 2;\n');
|
|
172
|
+
});
|