@aibyzero/cm-workflow 0.17.1 → 0.19.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 +242 -0
- package/README.md +20 -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/autonomy.mjs +152 -0
- 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 +56 -17
- 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 +115 -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 +581 -65
- 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 +5 -4
- 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 +21 -7
- package/scripts/cm-ai-admission.test.mjs +171 -3
- 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-autonomy.mjs +94 -0
- package/scripts/cm-autonomy.test.mjs +162 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +60 -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 +581 -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 +323 -0
- package/scripts/cm-start-check.test.mjs +406 -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 +4 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N3-execute-task.md +1 -1
- 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 +82 -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 +14 -9
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +8 -1
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-change-recovery.md +14 -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
|
@@ -3,10 +3,11 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import {createCmAiBatch,taskCommitArgs,memberRescheduleAllowed,memberRunHistory} from './cm-ai-batch-run.mjs';
|
|
6
|
+
import {createCmAiBatch,taskCommitArgs,memberRescheduleAllowed,memberRunHistory,manualCleanupCommands} from './cm-ai-batch-run.mjs';
|
|
7
|
+
import {execFileSync} from 'node:child_process';
|
|
7
8
|
import {batchFixture} from './cm-ai-batch-run-fixture.mjs';
|
|
8
9
|
|
|
9
|
-
for(const mode of ['continuous','qa-resume','failed-qa','cancel','learning','policy','executor'])
|
|
10
|
+
for(const mode of ['continuous','qa-resume','failed-qa','cancel','learning','policy','executor','next-feature'])
|
|
10
11
|
test(`real multi-task runner keeps QA and recovery authoritative: ${mode}`,()=>batchFixture(mode));
|
|
11
12
|
|
|
12
13
|
// Q24/Q25: a strict-batch parallel member that can still recover in its own run stops
|
|
@@ -30,7 +31,8 @@ test('reschedule needs a raw checkpointed blocked state, never a projection over
|
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
test('dirty batch entry lists files and creates no member worktrees',()=>batchFixture('parallel-dirty'));
|
|
33
|
-
test('
|
|
34
|
+
test('parallel members that edit files already on HEAD run, merge both edits and finish',()=>batchFixture('parallel-existing'));
|
|
35
|
+
test('parallel members merge in task order even when the later task finishes first',()=>batchFixture('parallel-existing',{slowFirst:true}));
|
|
34
36
|
|
|
35
37
|
test('parallel groups reject transitive prerequisites, not just direct edges',()=>{
|
|
36
38
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-transitive-')));
|
|
@@ -39,7 +41,7 @@ test('parallel groups reject transitive prerequisites, not just direct edges',()
|
|
|
39
41
|
fs.writeFileSync(path.join(code,'req.md'),'# r\n');
|
|
40
42
|
// T-009 <- T-005 <- T-003 <- T-001; T-007 is unrelated.
|
|
41
43
|
fs.writeFileSync(path.join(specs,feature,'tasks.md'),
|
|
42
|
-
'- [ ] T-001: a\n- [ ] T-003: b\n- [ ] T-005: c\n- [ ] T-007: d\n- [ ] T-009: final\n\n'+
|
|
44
|
+
'- [ ] T-001: a\n - 范围: `a.js`\n- [ ] T-003: b\n - 范围: `b.js`\n- [ ] T-005: c\n - 范围: `c.js`\n- [ ] T-007: d\n - 范围: `e.js`\n- [ ] T-009: final\n - 范围: `d.js`\n\n'+
|
|
43
45
|
'- T-003 依赖 T-001\n- T-005 依赖 T-003\n- T-009 依赖 T-005\n');
|
|
44
46
|
const task=(taskId,scope)=>({feature,taskId,scope:[scope],requirements:['req.md']});
|
|
45
47
|
const tasks=[task('T-001','a.js'),task('T-003','b.js'),task('T-005','c.js'),task('T-007','e.js'),task('T-009','d.js')];
|
|
@@ -80,3 +82,20 @@ test('task commit subjects are single-line and bounded while bodies preserve des
|
|
|
80
82
|
assert.deepEqual(taskCommitArgs('T-001',description,'failed'),['-m','WIP T-001: blocked (failed)','-m',description]);
|
|
81
83
|
}
|
|
82
84
|
});
|
|
85
|
+
|
|
86
|
+
// Review r7: the cleanup commands a diverged one-member worktree prints must work when
|
|
87
|
+
// pasted into a shell, also for a project path with spaces and a single quote.
|
|
88
|
+
test('manual cleanup commands for a kept worktree run as printed, spaces and quotes included',()=>{
|
|
89
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),"cm cleanup it's ")));
|
|
90
|
+
try{
|
|
91
|
+
const repo=path.join(root,'my project'),worktree=path.join(root,'.cm-worktrees','seg x','T-001'),branch='cm/seg/feature/T-001';
|
|
92
|
+
fs.mkdirSync(repo,{recursive:true});
|
|
93
|
+
const git=(...args)=>execFileSync('git',['-C',repo,...args],{encoding:'utf8',stdio:['ignore','pipe','pipe']});
|
|
94
|
+
git('init','-q');fs.writeFileSync(path.join(repo,'a.txt'),'a\n');git('add','-A');
|
|
95
|
+
git('-c','user.email=t@t','-c','user.name=t','commit','-qm','init');
|
|
96
|
+
fs.mkdirSync(path.dirname(worktree),{recursive:true});git('worktree','add','-q','-b',branch,worktree,'HEAD');
|
|
97
|
+
for(const command of manualCleanupCommands({repo,worktree,branch}))execFileSync('/bin/sh',['-c',command],{cwd:os.tmpdir(),stdio:'pipe'});
|
|
98
|
+
assert.equal(fs.existsSync(worktree),false);
|
|
99
|
+
assert.equal(git('branch','--list',branch).trim(),'');
|
|
100
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
101
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// End to end: a v2 provider batch whose only member is a session task (task grammar 3,
|
|
2
|
+
// `开发: 会话`) is developed through the live develop channel by the test acting as the
|
|
3
|
+
// current session, reviewed by a fixture Codex, and completed by the real batch host.
|
|
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 {spawn,spawnSync} from 'node:child_process';
|
|
10
|
+
import {fileURLToPath} from 'node:url';
|
|
11
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
13
|
+
|
|
14
|
+
const BATCH=fileURLToPath(new URL('./cm-ai-batch-drive.mjs',import.meta.url));
|
|
15
|
+
const key='1.work/T-001',identity={repositoryId:'session-e2e-fixture'};
|
|
16
|
+
|
|
17
|
+
function fixture(t){
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-session-e2e-')));
|
|
19
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
20
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'app'),bin=path.join(root,'bin'),witness=path.join(root,'witness.jsonl');
|
|
21
|
+
fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
|
|
22
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
|
|
23
|
+
fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),'- [ ] T-001: walk the page\n - 范围: `target.mjs`\n - 开发: 会话\n');
|
|
24
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],
|
|
25
|
+
specFiles:buildManifest(specsDir),taskGrammar:3}));
|
|
26
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
27
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'codex'},
|
|
28
|
+
roles:{coder:{adapter:'codex-cli'},reviewer:{adapter:'codex-cli'}}}));
|
|
29
|
+
for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
|
|
30
|
+
const r=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(r.status,0,r.stderr);
|
|
31
|
+
}
|
|
32
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({batch:{version:1,repositoryId:identity.repositoryId,batchId:'session-e2e-batch',
|
|
33
|
+
specsDir,codeProject,tasks:[{feature:'1.work',taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']}],
|
|
34
|
+
memberDevelopment:{[key]:'session'}},
|
|
35
|
+
workflows:{[key]:{qa:null,documentationPaths:[],applicableAgentFiles:[]}}}));
|
|
36
|
+
fs.writeFileSync(path.join(root,'control.json'),JSON.stringify({version:2,development:'provider',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'}));
|
|
37
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
|
|
38
|
+
prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
|
|
39
|
+
fs.writeFileSync(path.join(root,'protected.json'),JSON.stringify({model:'fixture',timeoutMs:5000,
|
|
40
|
+
checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
|
|
41
|
+
const answers=path.join(root,'answers','1.work','T-001');fs.mkdirSync(answers,{recursive:true});
|
|
42
|
+
fs.writeFileSync(path.join(answers,'documentation-inspect.json'),JSON.stringify({status:'completed',reason:'Fixture inspected'}));
|
|
43
|
+
// Fixture Codex: sandboxed checks and independent review only. A develop prompt
|
|
44
|
+
// reaching it would mean the session member was handed to the provider.
|
|
45
|
+
fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}
|
|
46
|
+
const fs=require('node:fs'),cp=require('node:child_process');
|
|
47
|
+
const args=process.argv.slice(2),record=row=>fs.appendFileSync(${JSON.stringify(witness)},JSON.stringify(row)+'\\n');
|
|
48
|
+
if(args[0]==='sandbox'){
|
|
49
|
+
const command=args.slice(args.indexOf('--')+1);record({type:'check'});
|
|
50
|
+
const checked=cp.spawnSync(command[0],command.slice(1),{cwd:process.cwd(),encoding:'utf8'});
|
|
51
|
+
process.stdout.write(checked.stdout??'');process.stderr.write(checked.stderr??'');process.exit(checked.status??1);
|
|
52
|
+
}
|
|
53
|
+
let prompt='';process.stdin.on('data',part=>prompt+=part);process.stdin.on('end',()=>{
|
|
54
|
+
if(prompt.includes('<cm-developer-data-json>')){record({type:'provider_develop'});process.exit(1);}
|
|
55
|
+
const data=JSON.parse(prompt.split('<cm-review-data-json>\\n')[1]);
|
|
56
|
+
const value={verdict:'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,findings:[],summary:'Synthetic independent review'};
|
|
57
|
+
record({type:'review',attempt:data.reviewPackage.identity.attempt});
|
|
58
|
+
for(const event of [{type:'thread.started',thread_id:'fixture-session-member-review'},{type:'turn.started'},
|
|
59
|
+
{type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}])
|
|
60
|
+
process.stdout.write(JSON.stringify(event)+'\\n');
|
|
61
|
+
});
|
|
62
|
+
`,{mode:0o700});
|
|
63
|
+
const plan=path.join(root,'plan.json');
|
|
64
|
+
fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'create',hostContext:'session-e2e-host',controlConfig:'control.json',
|
|
65
|
+
permissions:['--review-config','review.json','--protected-config','protected.json'],answers:'answers',
|
|
66
|
+
liveEvidence:{directory:'exchange',kinds:['develop'],timeoutMs:60000}}));
|
|
67
|
+
return {root,specsDir,codeProject,plan,witness,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
68
|
+
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The test plays the current session: it answers each live develop request with a
|
|
72
|
+
// protected-text proposal bound to the host's expected hashes.
|
|
73
|
+
function answerLiveRequests(exchange,seen){
|
|
74
|
+
if(!fs.existsSync(exchange))return;
|
|
75
|
+
for(const dir of fs.readdirSync(exchange)){
|
|
76
|
+
const sub=path.join(exchange,dir);if(!fs.statSync(sub).isDirectory())continue;
|
|
77
|
+
for(const name of fs.readdirSync(sub).filter(item=>item.endsWith('.request.json'))){
|
|
78
|
+
const file=path.join(sub,name);if(seen.has(file))continue;seen.add(file);
|
|
79
|
+
const request=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
80
|
+
assert.equal(request.kind,'develop');
|
|
81
|
+
const payload=request.payload;
|
|
82
|
+
assert.equal(payload.editMode,'protected-text-v1');assert.deepEqual(payload.request.payload.scope,['target.mjs']);
|
|
83
|
+
const result={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
84
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
85
|
+
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]};
|
|
86
|
+
const target=file.replace(/\.request\.json$/,'.result.json'),tmp=target+'.tmp';
|
|
87
|
+
fs.writeFileSync(tmp,JSON.stringify({type:'host_result',sessionId:request.sessionId,callId:request.callId,
|
|
88
|
+
requestDigest:request.requestDigest,result}),{mode:0o600});fs.renameSync(tmp,target);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
test('a v2 provider batch completes its session member through live develop and an independent review',async t=>{
|
|
94
|
+
const f=fixture(t),exchange=path.join(f.root,'exchange'),seen=new Set();
|
|
95
|
+
const child=spawn(process.execPath,[BATCH,'--plan',f.plan,'advance'],{env:f.env,stdio:['ignore','pipe','pipe']});
|
|
96
|
+
let stdout='',stderr='';child.stdout.on('data',part=>stdout+=part);child.stderr.on('data',part=>stderr+=part);
|
|
97
|
+
const timer=setInterval(()=>{try{answerLiveRequests(exchange,seen);}catch(error){stderr+=`\n[test] ${error.stack}`;}},50);
|
|
98
|
+
const code=await new Promise(resolve=>{const kill=setTimeout(()=>child.kill('SIGKILL'),90000);child.on('exit',value=>{clearTimeout(kill);resolve(value);});});
|
|
99
|
+
clearInterval(timer);
|
|
100
|
+
assert.equal(code,0,stderr);
|
|
101
|
+
assert.equal(seen.size,1,'exactly one live develop request reached the session');
|
|
102
|
+
const result=JSON.parse(stdout.slice(stdout.indexOf('{'),stdout.lastIndexOf('}')+1)).result;
|
|
103
|
+
const rows=fs.readFileSync(f.witness,'utf8').trim().split('\n').map(JSON.parse);
|
|
104
|
+
assert.equal(rows.filter(row=>row.type==='provider_develop').length,0,'the session member never reaches the provider');
|
|
105
|
+
assert.deepEqual(rows.filter(row=>row.type==='review').map(row=>row.attempt),[1]);
|
|
106
|
+
assert.ok(rows.some(row=>row.type==='check'),'the protected checks ran');
|
|
107
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
|
|
108
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,'1.work/tasks.md'),'utf8'),/\[x\] T-001/);
|
|
109
|
+
// qa:"disabled" still asks the mandatory feature-completion QA decision (existing v2 rule),
|
|
110
|
+
// so the batch stops there, before run_done and the final commit; the member itself is complete.
|
|
111
|
+
assert.deepEqual([result.state,result.code,result.pendingAction],['fixture_completed','qa_triggered','qa_execution']);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Round 2: the first review asks for changes; the session gets a fresh live request
|
|
115
|
+
// carrying the prior review and the current hashes, and answers it anew.
|
|
116
|
+
test('a session member rejected once gets a fresh round-2 live develop request with the prior review',async t=>{
|
|
117
|
+
const f=fixture(t),exchange=path.join(f.root,'exchange'),seen=new Set(),payloads=[];
|
|
118
|
+
// Fixture reviewer: changes_requested on attempt 1, approved on attempt 2.
|
|
119
|
+
const codex=path.join(f.root,'bin','codex');
|
|
120
|
+
fs.writeFileSync(codex,fs.readFileSync(codex,'utf8').replace("const value={verdict:'approved',",
|
|
121
|
+
"const first=data.reviewPackage.identity.attempt===1;const value={verdict:first?'changes_requested':'approved',")
|
|
122
|
+
.replace("findings:[],summary:'Synthetic independent review'}",
|
|
123
|
+
"findings:first?[{id:'F1',severity:'P2',path:'target.mjs',message:'Use 43',evidence:'Synthetic finding'}]:[],summary:'Synthetic independent review'}"));
|
|
124
|
+
const answer=(file,request)=>{
|
|
125
|
+
const payload=request.payload;payloads.push({callId:request.callId,payload});
|
|
126
|
+
const round=payloads.length;
|
|
127
|
+
const result={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
128
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
129
|
+
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:`export const value = ${41+round};\n`}]};
|
|
130
|
+
const target=file.replace(/\.request\.json$/,'.result.json'),tmp=target+'.tmp';
|
|
131
|
+
fs.writeFileSync(tmp,JSON.stringify({type:'host_result',sessionId:request.sessionId,callId:request.callId,requestDigest:request.requestDigest,result}),{mode:0o600});
|
|
132
|
+
fs.renameSync(tmp,target);
|
|
133
|
+
};
|
|
134
|
+
const child=spawn(process.execPath,[BATCH,'--plan',f.plan,'advance'],{env:f.env,stdio:['ignore','pipe','pipe']});
|
|
135
|
+
let stdout='',stderr='';child.stdout.on('data',part=>stdout+=part);child.stderr.on('data',part=>stderr+=part);
|
|
136
|
+
const timer=setInterval(()=>{try{
|
|
137
|
+
if(!fs.existsSync(exchange))return;
|
|
138
|
+
for(const dir of fs.readdirSync(exchange))for(const name of fs.readdirSync(path.join(exchange,dir)).filter(item=>item.endsWith('.request.json'))){
|
|
139
|
+
const file=path.join(exchange,dir,name);if(seen.has(file))continue;seen.add(file);answer(file,JSON.parse(fs.readFileSync(file,'utf8')));
|
|
140
|
+
}
|
|
141
|
+
}catch(error){stderr+=`\n[test] ${error.stack}`;}},50);
|
|
142
|
+
const code=await new Promise(resolve=>{const kill=setTimeout(()=>child.kill('SIGKILL'),90000);child.on('exit',value=>{clearTimeout(kill);resolve(value);});});
|
|
143
|
+
clearInterval(timer);
|
|
144
|
+
assert.equal(code,0,stderr);
|
|
145
|
+
assert.equal(payloads.length,2,'one live request per round');
|
|
146
|
+
assert.notEqual(payloads[0].callId,payloads[1].callId,'round 2 is a fresh call, never the round-1 reply');
|
|
147
|
+
assert.equal(payloads[0].payload.request.payload.priorReview,null);
|
|
148
|
+
assert.equal(payloads[1].payload.request.payload.priorReview?.verdict,'changes_requested');
|
|
149
|
+
assert.equal(payloads[1].payload.request.identity.attempt,2);
|
|
150
|
+
assert.notEqual(payloads[1].payload.expected['target.mjs'],payloads[0].payload.expected['target.mjs'],'round 2 expects the round-1 bytes');
|
|
151
|
+
const rows=fs.readFileSync(f.witness,'utf8').trim().split('\n').map(JSON.parse);
|
|
152
|
+
assert.equal(rows.filter(row=>row.type==='provider_develop').length,0);
|
|
153
|
+
assert.deepEqual(rows.filter(row=>row.type==='review').map(row=>row.attempt),[1,2]);
|
|
154
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 43;\n');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Mixed batch with QA: a provider member then the session final member; the feature
|
|
158
|
+
// QA runs at the end and the batch reaches run_done with the session member committed.
|
|
159
|
+
test('a mixed v2 batch runs the provider member, then the session final member, through QA to run_done and commits both',async t=>{
|
|
160
|
+
const f=fixture(t),exchange=path.join(f.root,'exchange'),seen=new Set(),kinds=[];
|
|
161
|
+
const feature=path.join(f.specsDir,'1.work');
|
|
162
|
+
fs.writeFileSync(path.join(feature,'requirements.md'),'# Fixture\n\n- [ ] [AC-001] value is 43\n');
|
|
163
|
+
fs.writeFileSync(path.join(feature,'tasks.md'),'- [ ] T-001: implement\n - 范围: `lib.mjs`\n- [ ] T-002: walk the page\n - 范围: `qa.md`\n - 开发: 会话\n\n## 依赖关系\n\n- T-002 依赖 T-001\n');
|
|
164
|
+
fs.writeFileSync(path.join(feature,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases:[{id:'TC-001',origin:'generated',kind:'logic',
|
|
165
|
+
blocking:true,acIds:['AC-001'],taskIds:['T-001'],title:'value is 43',preconditions:[],steps:['import lib.mjs'],expected:['value is 43'],cleanup:[]}]},null,1)+'\n');
|
|
166
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir),taskGrammar:3}));
|
|
167
|
+
const qa={commands:[{id:'value',caseIds:['TC-001'],command:[process.execPath,'-e',"import('./lib.mjs').then(m=>{if(m.value!==43)process.exit(1)})"]}],
|
|
168
|
+
environment:{kind:'web',carrier:'browser',target:'local',scope:'local'},timeoutMs:60000};
|
|
169
|
+
const workflow={qa,documentationPaths:[],applicableAgentFiles:[]};
|
|
170
|
+
fs.writeFileSync(path.join(f.root,'run.json'),JSON.stringify({batch:{version:1,repositoryId:identity.repositoryId,batchId:'session-e2e-mixed',
|
|
171
|
+
specsDir:f.specsDir,codeProject:f.codeProject,tasks:[
|
|
172
|
+
{feature:'1.work',taskId:'T-001',scope:['lib.mjs'],requirements:['requirements.md']},
|
|
173
|
+
{feature:'1.work',taskId:'T-002',scope:['qa.md'],requirements:['requirements.md']}],
|
|
174
|
+
memberDevelopment:{'1.work/T-002':'session'}},
|
|
175
|
+
workflows:{'1.work/T-001':workflow,'1.work/T-002':workflow}}));
|
|
176
|
+
fs.writeFileSync(path.join(f.root,'control.json'),JSON.stringify({version:2,development:'provider',bootstrap:'disabled',qa:'run',qaFix:'disabled'}));
|
|
177
|
+
fs.writeFileSync(path.join(f.root,'protected.json'),JSON.stringify({model:'fixture',timeoutMs:5000,
|
|
178
|
+
checkCommands:[{id:'syntax',command:[process.execPath,'-e',"require('node:fs').existsSync('lib.mjs')&&process.exit(0)"]}]}));
|
|
179
|
+
for(const task of ['T-001','T-002']){
|
|
180
|
+
const dir=path.join(f.root,'answers','1.work',task);fs.mkdirSync(dir,{recursive:true});
|
|
181
|
+
fs.writeFileSync(path.join(dir,'documentation-inspect.json'),JSON.stringify({status:'completed',reason:'Fixture inspected'}));
|
|
182
|
+
fs.writeFileSync(path.join(dir,'qa-assess.json'),JSON.stringify({confirmed:true}));
|
|
183
|
+
}
|
|
184
|
+
// The fixture Codex now also develops the provider member T-001.
|
|
185
|
+
const codex=path.join(f.root,'bin','codex');
|
|
186
|
+
fs.writeFileSync(codex,fs.readFileSync(codex,'utf8').replace("if(prompt.includes('<cm-developer-data-json>')){record({type:'provider_develop'});process.exit(1);}",
|
|
187
|
+
`if(prompt.includes('<cm-developer-data-json>')){
|
|
188
|
+
const data=JSON.parse(prompt.split('<cm-developer-data-json>\\n')[1].split('\\n')[0]);
|
|
189
|
+
record({type:'provider_develop',task:data.specification.task.id});fs.writeFileSync('lib.mjs','export const value = 43;\\n');
|
|
190
|
+
const value={outcome:'implemented',application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
191
|
+
for(const event of [{type:'thread.started',thread_id:'fixture-provider-author'},{type:'turn.started'},
|
|
192
|
+
{type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}])process.stdout.write(JSON.stringify(event)+'\\n');
|
|
193
|
+
return;}`));
|
|
194
|
+
fs.writeFileSync(f.plan,JSON.stringify({config:'run.json',mode:'create',hostContext:'session-e2e-host',controlConfig:'control.json',
|
|
195
|
+
permissions:['--review-config','review.json','--protected-config','protected.json'],answers:'answers',
|
|
196
|
+
liveEvidence:{directory:'exchange',kinds:['develop','qa_logic'],timeoutMs:60000}}));
|
|
197
|
+
const reply=(file,request,result)=>{const target=file.replace(/\.request\.json$/,'.result.json'),tmp=target+'.tmp';
|
|
198
|
+
fs.writeFileSync(tmp,JSON.stringify({type:'host_result',sessionId:request.sessionId,callId:request.callId,requestDigest:request.requestDigest,result}),{mode:0o600});
|
|
199
|
+
fs.renameSync(tmp,target);};
|
|
200
|
+
const answer=(file,request)=>{kinds.push(request.kind);
|
|
201
|
+
if(request.kind==='develop'){
|
|
202
|
+
assert.equal(request.payload.request.identity.taskId,'T-002');
|
|
203
|
+
reply(file,request,{status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
204
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
205
|
+
edits:[{path:'qa.md',beforeSha256:request.payload.expected['qa.md'],content:'# Walkthrough\n\nTC-001 checked.\n'}]});
|
|
206
|
+
}else reply(file,request,{verdict:'SUPPORTED',evidence:['fixture: lib.mjs exports value 43']});
|
|
207
|
+
};
|
|
208
|
+
// Advance until the batch stops on its own; each advance may hand off to the next member.
|
|
209
|
+
let last=null;
|
|
210
|
+
for(let round=0;round<6;round++){
|
|
211
|
+
if(round>0)fs.writeFileSync(f.plan,JSON.stringify({...JSON.parse(fs.readFileSync(f.plan,'utf8')),mode:'resume',originalHostContext:'session-e2e-host'}));
|
|
212
|
+
const child=spawn(process.execPath,[BATCH,'--plan',f.plan,'advance'],{env:f.env,stdio:['ignore','pipe','pipe']});
|
|
213
|
+
let stdout='',stderr='';child.stdout.on('data',part=>stdout+=part);child.stderr.on('data',part=>stderr+=part);
|
|
214
|
+
const timer=setInterval(()=>{try{
|
|
215
|
+
if(!fs.existsSync(exchange))return;
|
|
216
|
+
for(const dir of fs.readdirSync(exchange))for(const name of fs.readdirSync(path.join(exchange,dir)).filter(item=>item.endsWith('.request.json'))){
|
|
217
|
+
const file=path.join(exchange,dir,name);if(seen.has(file))continue;seen.add(file);answer(file,JSON.parse(fs.readFileSync(file,'utf8')));
|
|
218
|
+
}
|
|
219
|
+
}catch(error){stderr+=`\n[test] ${error.stack}`;}},50);
|
|
220
|
+
const code=await new Promise(resolve=>{const kill=setTimeout(()=>child.kill('SIGKILL'),120000);child.on('exit',value=>{clearTimeout(kill);resolve(value);});});
|
|
221
|
+
clearInterval(timer);
|
|
222
|
+
assert.equal(code,0,stderr);
|
|
223
|
+
last=JSON.parse(stdout.slice(stdout.indexOf('{'),stdout.lastIndexOf('}')+1)).result;
|
|
224
|
+
if(last.state==='run_done'||last.state==='blocked')break;
|
|
225
|
+
}
|
|
226
|
+
assert.equal(last.state,'run_done',JSON.stringify(last).slice(0,800));
|
|
227
|
+
const rows=fs.readFileSync(f.witness,'utf8').trim().split('\n').map(JSON.parse);
|
|
228
|
+
assert.deepEqual(rows.filter(row=>row.type==='provider_develop').map(row=>row.task),['T-001'],'only the provider member reaches the provider');
|
|
229
|
+
assert.equal(kinds.filter(kind=>kind==='develop').length,1,'the session member is developed once through the live channel');
|
|
230
|
+
assert.ok(kinds.includes('qa_logic'),'the feature QA asked the session for its logic case');
|
|
231
|
+
const log=spawnSync('git',['-C',f.codeProject,'log','--format=%s'],{encoding:'utf8'}).stdout;
|
|
232
|
+
assert.match(log,/T-002/,`the batch committed the session final member: ${log}`);
|
|
233
|
+
assert.match(log,/T-001/);
|
|
234
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'qa.md'),'utf8'),'# Walkthrough\n\nTC-001 checked.\n');
|
|
235
|
+
});
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Grammar 3 session last task inside a batch (design 3.3): the planner's execution
|
|
2
|
+
// table batch.memberDevelopment, its checks in the batch owner, the batch host's member
|
|
3
|
+
// construction and the factory's development check.
|
|
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 {fileURLToPath,pathToFileURL} from 'node:url';
|
|
10
|
+
import {fixture as hostFixture,syntheticReviewConfig} from './cm-ai-host-fixture.mjs';
|
|
11
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
|
+
import {createCmAiBatch} from './cm-ai-batch-run.mjs';
|
|
13
|
+
import {planCmAiBatch} from '../runtime/js/cm-ai/batch-plan.mjs';
|
|
14
|
+
import {createConversationExecution} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
15
|
+
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
16
|
+
import {readRunDefinition} from './cm-ai-run.mjs';
|
|
17
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
18
|
+
|
|
19
|
+
const scope=file=>`\n - 范围: \`${file}\``;
|
|
20
|
+
const session='\n - 开发: 会话';
|
|
21
|
+
const tasks=(mark=3)=>[1,2,3].map(n=>`- [ ] T-00${n}: t${n}${scope(`t${n}.js`)}${n===mark?session:''}`).join('\n')+'\n';
|
|
22
|
+
function specs(t,text,{taskGrammar=3}={}){
|
|
23
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-session-member-')));
|
|
24
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
25
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');
|
|
26
|
+
fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);
|
|
27
|
+
fs.writeFileSync(path.join(codeProject,'README.md'),'# fixture\n');
|
|
28
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
|
|
29
|
+
fs.writeFileSync(path.join(specsDir,'1.work','tasks.md'),text);
|
|
30
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specsDir),
|
|
31
|
+
...(taskGrammar?{taskGrammar}:{})}));
|
|
32
|
+
return {root,specsDir,codeProject,plan:()=>planCmAiBatch({specsDir,codeProject,repositoryId:'r',batchId:'session-batch-1',
|
|
33
|
+
settings:{enabled:true,max:2,worktree_all:false}})};
|
|
34
|
+
}
|
|
35
|
+
const create=(f,configuration)=>createCmAiBatch({configuration,executionFor:async()=>({}),logHome:path.join(f.root,'log')});
|
|
36
|
+
|
|
37
|
+
test('the batch owner accepts the planned table and checks it against tasks.md again',t=>{
|
|
38
|
+
const f=specs(t,tasks()),{batch}=f.plan().config;
|
|
39
|
+
assert.deepEqual(batch.memberDevelopment,{'1.work/T-003':'session'});
|
|
40
|
+
assert.ok(create(f,batch));
|
|
41
|
+
const without=({memberDevelopment,...rest})=>rest;
|
|
42
|
+
// A new grammar-3 batch must carry the table its tasks.md implies, and only that.
|
|
43
|
+
assert.throws(()=>create(f,without(batch)),{code:'member_development_mismatch'});
|
|
44
|
+
assert.throws(()=>create(f,{...batch,memberDevelopment:{'1.work/T-002':'session'}}),{code:'member_development_mismatch'});
|
|
45
|
+
for(const memberDevelopment of [{},{'1.work/T-003':'provider'},{'1.work/T-999':'session'},null,[]])
|
|
46
|
+
assert.throws(()=>create(f,{...batch,memberDevelopment}),{code:'invalid_member_development'},JSON.stringify(memberDevelopment));
|
|
47
|
+
assert.throws(()=>create(f,{...batch,parallel:[['1.work/T-001','1.work/T-003']]}),error=>['session_task_parallel','parallel_final_task_excluded'].includes(error.code));
|
|
48
|
+
// The narrow rule is re-read from tasks.md, whatever the configuration says.
|
|
49
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),tasks(2));
|
|
50
|
+
assert.throws(()=>create(f,{...batch,memberDevelopment:{'1.work/T-002':'session'}}),{code:'session_task_not_final'});
|
|
51
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),tasks(2).replace(scope('t3.js'),scope('t3.js')+session));
|
|
52
|
+
assert.throws(()=>create(f,batch),{code:'session_task_multiple'});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('the batch owner refuses a hand-written configuration whose session member is not the last to run',t=>{
|
|
56
|
+
const f=specs(t,tasks()),{parallel,...batch}=f.plan().config.batch;
|
|
57
|
+
const write=deps=>fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),tasks()+'\n'+deps.join('\n')+'\n');
|
|
58
|
+
// Dependencies the planner would refuse; this configuration is written by hand, in tasks.md order.
|
|
59
|
+
write(['- T-001 依赖 T-003']);
|
|
60
|
+
assert.throws(()=>create(f,batch),error=>error.code==='session_task_depended_on'&&/任务 T-001 直接或间接依赖.*T-003/.test(error.reason));
|
|
61
|
+
write(['- T-001 依赖 T-002','- T-002 依赖 T-003']);
|
|
62
|
+
assert.throws(()=>create(f,batch),error=>error.code==='session_task_depended_on'&&/任务 T-001, T-002 直接或间接依赖.*T-003/.test(error.reason));
|
|
63
|
+
// Without dependencies, a configuration that lists the session member before another member.
|
|
64
|
+
write([]);
|
|
65
|
+
const reordered={...batch,tasks:[batch.tasks[0],batch.tasks[2],batch.tasks[1]]};
|
|
66
|
+
assert.throws(()=>create(f,reordered),error=>error.code==='session_task_not_final'&&/1\.work\/T-003.*1\.work\/T-002/.test(error.reason));
|
|
67
|
+
// Legal: the session member waits for the others and runs last.
|
|
68
|
+
write(['- T-003 依赖 T-001, T-002']);
|
|
69
|
+
assert.ok(create(f,batch));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a batch without session members keeps its configuration; grammar 2 never reads the mark',t=>{
|
|
73
|
+
for(const taskGrammar of [null,2]){
|
|
74
|
+
const f=specs(t,tasks(),{taskGrammar}),{batch}=f.plan().config;
|
|
75
|
+
assert.equal(Object.hasOwn(batch,'memberDevelopment'),false);assert.ok(create(f,batch));
|
|
76
|
+
assert.throws(()=>create(f,{...batch,memberDevelopment:{'1.work/T-003':'session'}}),{code:'member_development_mismatch'});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('the table is in planDigest: a started batch resumes only with the configuration it began with',async t=>{
|
|
81
|
+
const f=specs(t,tasks()),{batch}=f.plan().config,{memberDevelopment,...old}=batch;
|
|
82
|
+
const start=configuration=>fs.writeFileSync(path.join(f.specsDir,'运行日志.jsonl'),JSON.stringify({workflow:'cm-ai',event:'decision',
|
|
83
|
+
phase:'batch_start',run_id:batch.batchId,schema_version:1,repository_id:'r',plan_digest:digest(configuration),from_key:'1.work/T-001'})+'\n');
|
|
84
|
+
const status=async configuration=>{
|
|
85
|
+
try{return await create(f,configuration).handle({operation:'status',requestId:'status'});}catch(error){return {code:error.code};}
|
|
86
|
+
};
|
|
87
|
+
start(batch);
|
|
88
|
+
assert.notEqual((await status(batch)).code,'batch_plan_mismatch');
|
|
89
|
+
assert.equal((await status(old)).code,'batch_plan_mismatch');
|
|
90
|
+
// A batch started before the table existed resumes without it (no table injected) and refuses one added later.
|
|
91
|
+
start(old);
|
|
92
|
+
assert.notEqual((await status(old)).code,'batch_plan_mismatch');
|
|
93
|
+
assert.equal((await status(batch)).code,'batch_plan_mismatch');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const crossToolRoles='version: 1\nruntimes: {available: both}\nroles:\n coder: {adapter: codex-cli, source: subscription}\n reviewer: {adapter: claude-cli, source: subscription}\n';
|
|
97
|
+
const providerPolicy={version:2,development:'provider',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'};
|
|
98
|
+
test('factory: under a provider policy a session member carries no providerDevelopment and is reviewed by the declared reviewer',()=>{
|
|
99
|
+
const f=hostFixture(),bridge=createHostToolBridge();
|
|
100
|
+
try{
|
|
101
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),crossToolRoles);
|
|
102
|
+
const definition=readRunDefinition(f.config),protection={checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],timeoutMs:5000};
|
|
103
|
+
const make=(options,review=syntheticReviewConfig(f.codeProject,'claude'))=>createConversationExecution(definition,'session-member-host',bridge,
|
|
104
|
+
review,null,null,false,'codex',{controlPolicy:providerPolicy,protection,...options});
|
|
105
|
+
const member=make({memberDevelopment:'session',reviewRuntime:'claude'});
|
|
106
|
+
assert.equal(Object.hasOwn(member.configuration,'providerDevelopment'),false);
|
|
107
|
+
assert.equal(member.configuration.reviewRuntime,'claude');assert.deepEqual(member.configuration.protection,protection);
|
|
108
|
+
assert.equal(member.developer.provider,'codex');assert.equal(member.reviewers[0].provider,'claude');
|
|
109
|
+
const provider={model:'fixture',attempt:1,coderRuntime:'codex',reviewerRuntime:'claude'};
|
|
110
|
+
// The development check follows the table, both ways; it is not dropped.
|
|
111
|
+
assert.throws(()=>make({memberDevelopment:'session',providerDevelopment:provider}),{code:'invalid_arguments'});
|
|
112
|
+
assert.throws(()=>make({}),{code:'invalid_arguments'});
|
|
113
|
+
assert.ok(make({providerDevelopment:provider}).configuration.providerDevelopment);
|
|
114
|
+
assert.throws(()=>make({memberDevelopment:'provider',providerDevelopment:provider}),{code:'invalid_input'});
|
|
115
|
+
// The paired runtime checks stay: a reviewer the project does not declare is refused.
|
|
116
|
+
assert.throws(()=>make({memberDevelopment:'session',reviewRuntime:'codex'},syntheticReviewConfig(f.codeProject,'codex')),{code:'runtime_selection_mismatch'});
|
|
117
|
+
assert.throws(()=>make({memberDevelopment:'session',reviewRuntime:'claude',reviewerRuntime:'claude'}),{code:'runtime_selection_mismatch'});
|
|
118
|
+
// A conversation policy is unchanged by the mark.
|
|
119
|
+
const conversation=createConversationExecution(definition,'session-member-host',bridge,syntheticReviewConfig(f.codeProject,'claude'),null,null,false,'codex',
|
|
120
|
+
{controlPolicy:{...providerPolicy,development:'conversation'},protection,memberDevelopment:'session',reviewRuntime:'claude'});
|
|
121
|
+
assert.equal(Object.hasOwn(conversation.configuration,'providerDevelopment'),false);
|
|
122
|
+
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Review R1-01: a session member's review is rechecked against the declared pair right
|
|
126
|
+
// before dispatch, like a provider member's; the legacy --review-runtime session is not.
|
|
127
|
+
test('factory: a user default changed after construction refuses a session member review before dispatch',async()=>{
|
|
128
|
+
const f=hostFixture(),bridge=createHostToolBridge(),userFile=path.join(process.env.CM_WORKFLOW_HOME,'runtimes.yml');
|
|
129
|
+
try{
|
|
130
|
+
fs.mkdirSync(path.dirname(userFile),{recursive:true});
|
|
131
|
+
const preset=name=>fs.writeFileSync(userFile,`runtimes: {available: ${name==='codex-only'?'codex':'both'}}\npreset: ${name}\n`);
|
|
132
|
+
const definition=readRunDefinition(f.config),protection={checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],timeoutMs:5000};
|
|
133
|
+
const make=options=>createConversationExecution(definition,'session-member-host',bridge,syntheticReviewConfig(f.codeProject,'claude'),null,null,false,'codex',options);
|
|
134
|
+
// An empty request: the recheck runs before the request is read, so only a run past it reaches invalid_input.
|
|
135
|
+
const reviewOnce=execution=>execution.reviewers[0].run({},{signal:new AbortController().signal,onEvent(){}});
|
|
136
|
+
preset('codex-codes');
|
|
137
|
+
const member=make({controlPolicy:providerPolicy,protection,memberDevelopment:'session',reviewRuntime:'claude'});
|
|
138
|
+
const providerMember=make({controlPolicy:providerPolicy,protection,providerDevelopment:{model:'fixture',attempt:1,coderRuntime:'codex',reviewerRuntime:'claude'}});
|
|
139
|
+
const legacy=make({reviewRuntime:'claude'});
|
|
140
|
+
preset('codex-only');
|
|
141
|
+
// Refused synchronously, before any worker or review process exists.
|
|
142
|
+
assert.throws(()=>reviewOnce(member),{code:'runtime_selection_mismatch'});
|
|
143
|
+
assert.throws(()=>reviewOnce(providerMember),{code:'runtime_selection_mismatch'});
|
|
144
|
+
// The legacy session path keeps its old dispatch: no recheck, it goes on to read the request.
|
|
145
|
+
await assert.rejects(reviewOnce(legacy),{code:'invalid_input'});
|
|
146
|
+
preset('codex-codes');await assert.rejects(reviewOnce(member),{code:'invalid_input'});
|
|
147
|
+
}finally{fs.rmSync(userFile,{force:true});bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// The batch host with createCmAiBatch and the factory stubbed, so production parsing
|
|
151
|
+
// and executionFor run while the factory boundary is captured (as cm-ai-batch-host.test.mjs).
|
|
152
|
+
const cli=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
|
|
153
|
+
async function stubbedHost(root,{parallel=false}={}){
|
|
154
|
+
const stub=path.join(root,'stub.mjs'),host=path.join(root,'batch-host.mjs');
|
|
155
|
+
const hostModule=new URL('./cm-ai-host.mjs',import.meta.url).href,sessionModule=new URL('../runtime/js/cm-ai/host-session.mjs',import.meta.url).href;
|
|
156
|
+
fs.writeFileSync(stub,`
|
|
157
|
+
export {readConversationReviewConfiguration,readConversationReviewConfigurationValue,readConversationProtection} from ${JSON.stringify(hostModule)};
|
|
158
|
+
import {syntheticReviewConfig} from ${JSON.stringify(new URL('./cm-ai-host-fixture.mjs',import.meta.url).href)};
|
|
159
|
+
// A parallel member's review loopback, recorded by runtime instead of spawning a CLI.
|
|
160
|
+
export const preflights=[];
|
|
161
|
+
export async function runReviewPreflight(definition,{model,runtime}){preflights.push(runtime);return syntheticReviewConfig(definition.codeProject,runtime,model);}
|
|
162
|
+
export {parseHostInputLimit,inputLimitReason} from ${JSON.stringify(sessionModule)};
|
|
163
|
+
export const calls=[];export let scheduler;
|
|
164
|
+
export {batchTaskRunId,BATCH_MEMBER_ACTIONS} from ${JSON.stringify(new URL('./cm-ai-batch-run.mjs',import.meta.url).href)};
|
|
165
|
+
export function createConversationExecution(...args){calls.push(args);return {};}
|
|
166
|
+
export function createCmAiBatch(options){scheduler=options;return {async handle(){
|
|
167
|
+
for(const task of options.configuration.tasks)await options.executionFor({feature:task.feature,identity:{taskId:task.taskId},
|
|
168
|
+
codeProject:options.configuration.codeProject},{parallelMember:${parallel}&&(options.configuration.parallel??[]).flat().includes(task.feature+'/'+task.taskId)});
|
|
169
|
+
return {};}};}
|
|
170
|
+
export async function serveCmAiHost({host}){await host.handle({});}
|
|
171
|
+
`);
|
|
172
|
+
const stubUrl=pathToFileURL(stub).href;
|
|
173
|
+
fs.writeFileSync(host,fs.readFileSync(cli,'utf8').replace(/from '([^']+)'/g,(match,specifier)=>{
|
|
174
|
+
if(['./cm-ai-batch-run.mjs','./cm-ai-host.mjs','../runtime/js/cm-ai/host-session.mjs'].includes(specifier))return `from '${stubUrl}'`;
|
|
175
|
+
return specifier.startsWith('.')?`from '${new URL(specifier,new URL('./cm-ai-batch-host.mjs',import.meta.url)).href}'`:match;
|
|
176
|
+
}));
|
|
177
|
+
return {main:(await import(pathToFileURL(host).href)).main,capture:await import(stubUrl)};
|
|
178
|
+
}
|
|
179
|
+
test('batch host: a v2 provider batch builds its session member on the protected session transport with reviewRuntime',async t=>{
|
|
180
|
+
const f=specs(t,tasks()),{batch,workflows}=f.plan().config;
|
|
181
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),crossToolRoles);
|
|
182
|
+
const write=(name,value)=>{const file=path.join(f.root,name);fs.writeFileSync(file,JSON.stringify(value));return file;};
|
|
183
|
+
const protection={model:'fixture-coder',checkCommands:[{id:'syntax',command:[process.execPath,'--check','t1.js']}],timeoutMs:12345};
|
|
184
|
+
const files={bundle:write('batch.json',{batch,workflows}),old:write('old.json',{batch:(({memberDevelopment,...rest})=>rest)(batch),workflows}),
|
|
185
|
+
control:write('control.json',providerPolicy),review:write('review.json',syntheticReviewConfig(f.codeProject,'claude')),protected:write('protected.json',protection)};
|
|
186
|
+
const {main,capture}=await stubbedHost(f.root);
|
|
187
|
+
let stderr='';const io={input:{},output:{write(){}},error:{write(value){stderr+=value;}}};
|
|
188
|
+
const args=(bundle,...extra)=>['serve','--config',bundle,'--host-context','session-member-host','--control-config',files.control,
|
|
189
|
+
'--review-config',files.review,'--protected-config',files.protected,...extra];
|
|
190
|
+
assert.equal(await main(args(files.bundle),io),0,stderr);
|
|
191
|
+
const [first,second,last]=capture.calls.map(call=>call[8]);
|
|
192
|
+
for(const member of [first,second]){
|
|
193
|
+
assert.deepEqual(member.providerDevelopment,{model:'fixture-coder',attempt:1,coderRuntime:'codex',reviewerRuntime:'claude'});
|
|
194
|
+
assert.equal(Object.hasOwn(member,'memberDevelopment'),false);assert.equal(Object.hasOwn(member,'reviewRuntime'),false);
|
|
195
|
+
}
|
|
196
|
+
assert.equal(last.memberDevelopment,'session');assert.equal(last.reviewRuntime,'claude');
|
|
197
|
+
for(const absent of ['providerDevelopment','reviewerRuntime'])assert.equal(Object.hasOwn(last,absent),false,absent);
|
|
198
|
+
assert.deepEqual(last.protection,{checkCommands:protection.checkCommands,timeoutMs:12345});
|
|
199
|
+
assert.deepEqual(last.controlPolicy,providerPolicy);
|
|
200
|
+
// The table is bound into every member's batchWorkflowsDigest and the batch configuration.
|
|
201
|
+
assert.ok(capture.calls.every(call=>call[8].batchWorkflowsDigest===digest({workflows,bootstraps:null,memberDevelopment:batch.memberDevelopment})));
|
|
202
|
+
assert.deepEqual(capture.scheduler.configuration.memberDevelopment,batch.memberDevelopment);
|
|
203
|
+
// A batch without the table keeps its exact projection and gives every member to the provider.
|
|
204
|
+
capture.calls.length=0;
|
|
205
|
+
assert.equal(await main(args(files.old),io),0,stderr);
|
|
206
|
+
assert.ok(capture.calls.every(call=>call[8].batchWorkflowsDigest===digest(workflows)&&call[8].providerDevelopment&&!Object.hasOwn(call[8],'memberDevelopment')));
|
|
207
|
+
assert.equal(Object.hasOwn(capture.scheduler.configuration,'memberDevelopment'),false);
|
|
208
|
+
// Refusals before any member is built.
|
|
209
|
+
capture.calls.length=0;
|
|
210
|
+
stderr='';assert.equal(await main(args(files.bundle,'--execution-optimizations'),io),1);
|
|
211
|
+
assert.equal(JSON.parse(stderr).error.code,'session_member_unsupported_config');
|
|
212
|
+
stderr='';assert.equal(await main(args(files.bundle,'--runtime','claude'),io),1);
|
|
213
|
+
assert.equal(JSON.parse(stderr).error.code,'session_coder_runtime_mismatch');
|
|
214
|
+
assert.equal(capture.calls.length,0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('batch host: a legacy provider grant cannot name a session member',async t=>{
|
|
218
|
+
const f=specs(t,tasks()),{batch,workflows}=f.plan().config;
|
|
219
|
+
const write=(name,value)=>{const file=path.join(f.root,name);fs.writeFileSync(file,JSON.stringify(value));return file;};
|
|
220
|
+
const bundle=write('batch.json',{batch,workflows}),review=write('review.json',syntheticReviewConfig(f.codeProject,'codex'));
|
|
221
|
+
const protectedFile=write('protected.json',{model:'fixture',checkCommands:[],timeoutMs:1000});
|
|
222
|
+
const {main,capture}=await stubbedHost(f.root);
|
|
223
|
+
let stderr='';const io={input:{},output:{write(){}},error:{write(value){stderr+=value;}}};
|
|
224
|
+
const base=['serve','--config',bundle,'--host-context','session-member-host','--allow-development','--review-config',review,'--protected-config',protectedFile];
|
|
225
|
+
assert.equal(await main([...base,'--allow-provider-development','1.work/T-003:1'],io),1);
|
|
226
|
+
assert.equal(JSON.parse(stderr).error.code,'invalid_arguments');
|
|
227
|
+
stderr='';assert.equal(await main([...base,'--allow-provider-development','1.work/T-001:1'],io),0,stderr);
|
|
228
|
+
assert.equal(capture.calls.at(-1)[8].memberDevelopment,'session');
|
|
229
|
+
assert.equal(Object.hasOwn(capture.calls.at(-1)[8],'reviewRuntime'),false,'legacy batches keep their reviewer');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Found by the third sample run: the project declares Claude as coder and Codex as
|
|
233
|
+
// reviewer, and the batch has a parallel group. The session member's coder is the host,
|
|
234
|
+
// so the host runs with --runtime claude; a parallel member's review loopback must still
|
|
235
|
+
// use the declared reviewer (codex), not the host runtime.
|
|
236
|
+
const claudeCodesRoles='version: 1\nruntimes: {available: both}\nroles:\n coder: {adapter: claude-cli, source: subscription}\n reviewer: {adapter: codex-cli, source: subscription}\n';
|
|
237
|
+
test('batch host: Claude codes and Codex reviews; --runtime claude keeps the parallel members on the Codex reviewer',async t=>{
|
|
238
|
+
const text=['- [ ] T-001: t1'+scope('t1.js'),'- [ ] T-002: t2'+scope('t2.js'),'- [ ] T-003: t3'+scope('t3.js')+session,'',
|
|
239
|
+
'## 依赖关系','','- T-003 依赖 T-001, T-002',''].join('\n');
|
|
240
|
+
const f=specs(t,text),{batch,workflows}=f.plan().config;
|
|
241
|
+
assert.deepEqual(batch.parallel,[['1.work/T-001','1.work/T-002']]);
|
|
242
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),claudeCodesRoles);
|
|
243
|
+
const write=(name,value)=>{const file=path.join(f.root,name);fs.writeFileSync(file,JSON.stringify(value));return file;};
|
|
244
|
+
const files={bundle:write('batch.json',{batch,workflows}),control:write('control.json',providerPolicy),
|
|
245
|
+
review:write('review.json',syntheticReviewConfig(f.codeProject,'codex')),
|
|
246
|
+
protected:write('protected.json',{model:'fixture-coder',checkCommands:[{id:'syntax',command:[process.execPath,'--check','t1.js']}],timeoutMs:12345})};
|
|
247
|
+
const {main,capture}=await stubbedHost(f.root,{parallel:true});
|
|
248
|
+
let stderr='';const io={input:{},output:{write(){}},error:{write(value){stderr+=value;}}};
|
|
249
|
+
const args=(...extra)=>['serve','--config',files.bundle,'--host-context','session-member-host','--control-config',files.control,
|
|
250
|
+
'--review-config',files.review,'--protected-config',files.protected,...extra];
|
|
251
|
+
// Without --runtime the host is taken as codex, which is not the declared coder: refused before any member, with the fix in the reason.
|
|
252
|
+
assert.equal(await main(args(),io),1);
|
|
253
|
+
const refused=JSON.parse(stderr).error;
|
|
254
|
+
assert.equal(refused.code,'session_coder_runtime_mismatch');
|
|
255
|
+
assert.match(refused.reason,/--runtime claude/);
|
|
256
|
+
assert.equal(capture.calls.length,0);
|
|
257
|
+
stderr='';assert.equal(await main(args('--runtime','claude'),io),0,stderr);
|
|
258
|
+
const byTask=Object.fromEntries(capture.calls.map(call=>[call[0].identity.taskId,call]));
|
|
259
|
+
for(const id of ['T-001','T-002']){
|
|
260
|
+
const [,,,memberReview,,,,runtime,options]=byTask[id];
|
|
261
|
+
assert.deepEqual(options.providerDevelopment,{model:'fixture-coder',attempt:1,coderRuntime:'claude',reviewerRuntime:'codex'});
|
|
262
|
+
assert.equal(options.parallelMember,true);assert.equal(runtime,'claude');
|
|
263
|
+
assert.equal(memberReview.preflight.provider,'codex',`${id} review loopback runs on the declared reviewer`);
|
|
264
|
+
}
|
|
265
|
+
assert.deepEqual(capture.preflights,['codex','codex']);
|
|
266
|
+
const [,,,review,,,,runtime,options]=byTask['T-003'];
|
|
267
|
+
assert.equal(options.memberDevelopment,'session');assert.equal(options.reviewRuntime,'codex');assert.equal(runtime,'claude');
|
|
268
|
+
assert.equal(review.preflight.provider,'codex');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Review R1 of that fix: a legacy batch with --protected-config gives the provider only the
|
|
272
|
+
// granted members; an ungranted parallel member is still developed by the host and
|
|
273
|
+
// reviewed on the host runtime, so its loopback stays there.
|
|
274
|
+
test('batch host: a legacy ungranted parallel member keeps its review loopback on the host runtime',async t=>{
|
|
275
|
+
const text=['- [ ] T-001: t1'+scope('t1.js'),'- [ ] T-002: t2'+scope('t2.js'),'- [ ] T-003: t3'+scope('t3.js'),'',
|
|
276
|
+
'## 依赖关系','','- T-003 依赖 T-001, T-002',''].join('\n');
|
|
277
|
+
const f=specs(t,text),{batch,workflows}=f.plan().config;
|
|
278
|
+
assert.deepEqual(batch.parallel,[['1.work/T-001','1.work/T-002']]);
|
|
279
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),claudeCodesRoles);
|
|
280
|
+
const write=(name,value)=>{const file=path.join(f.root,name);fs.writeFileSync(file,JSON.stringify(value));return file;};
|
|
281
|
+
const bundle=write('batch.json',{batch,workflows}),review=write('review.json',syntheticReviewConfig(f.codeProject,'codex'));
|
|
282
|
+
const protectedFile=write('protected.json',{model:'fixture-coder',checkCommands:[],timeoutMs:1000});
|
|
283
|
+
const {main,capture}=await stubbedHost(f.root,{parallel:true});
|
|
284
|
+
let stderr='';const io={input:{},output:{write(){}},error:{write(value){stderr+=value;}}};
|
|
285
|
+
assert.equal(await main(['serve','--config',bundle,'--host-context','session-member-host','--allow-development','--runtime','claude',
|
|
286
|
+
'--review-config',review,'--protected-config',protectedFile,'--allow-provider-development','1.work/T-001:1'],io),0,stderr);
|
|
287
|
+
const byTask=Object.fromEntries(capture.calls.map(call=>[call[0].identity.taskId,call]));
|
|
288
|
+
assert.deepEqual(byTask['T-001'][8].providerDevelopment,{model:'fixture-coder',attempt:1,coderRuntime:'claude',reviewerRuntime:'codex'});
|
|
289
|
+
assert.equal(byTask['T-001'][3].preflight.provider,'codex','the granted member is reviewed by the declared reviewer');
|
|
290
|
+
assert.equal(Object.hasOwn(byTask['T-002'][8],'providerDevelopment'),false);
|
|
291
|
+
assert.equal(byTask['T-002'][3].preflight.provider,'claude','the ungranted member keeps the host runtime reviewer');
|
|
292
|
+
assert.deepEqual(capture.preflights,['codex','claude']);
|
|
293
|
+
});
|