@aibyzero/cm-workflow 0.16.4 → 0.16.6
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 +22 -0
- package/CHANGELOG.md +57 -0
- package/README.md +22 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +48 -7
- package/docs/js-workflow-control.md +293 -33
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/runtime-failover.md +1 -1
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +208 -34
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +181 -57
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +315 -0
- package/runtime/js/cm-ai/drive-core.mjs +47 -9
- package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +16 -5
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +438 -31
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +658 -75
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +279 -52
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +32 -9
- package/runtime/js/cm-fix/host.mjs +6 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +5 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +27 -15
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +135 -34
- package/scripts/cm-ai-batch-drive.test.mjs +209 -3
- package/scripts/cm-ai-batch-host.mjs +63 -24
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +101 -34
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +159 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
- package/scripts/cm-ai-bootstrap.test.mjs +174 -89
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +526 -60
- package/scripts/cm-ai-drive.test.mjs +336 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +142 -43
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +187 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +977 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +206 -62
- package/scripts/cm-ai-run.test.mjs +6 -4
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +2 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +12 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +10 -2
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +70 -23
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +24 -14
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +147 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +213 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +25 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-host.mjs +13 -4
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +164 -20
- package/scripts/cm-task-gate.py +2 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +101 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +11 -2
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +270 -43
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +52 -3
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
7
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
8
|
+
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
9
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
10
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
11
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {readRunnerHistory,runnerPayloadV3} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
13
|
+
|
|
14
|
+
function fixture(){
|
|
15
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-abandon-position-')));
|
|
16
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.work';
|
|
17
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
18
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'old\n');
|
|
19
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'fixture\n');
|
|
20
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
21
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-002: fixture\n');
|
|
22
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
23
|
+
return {root,codeProject,specsDir,feature,reviewsDir:path.join(specsDir,'.reviews'),
|
|
24
|
+
tasksPath:path.join(specsDir,feature,'tasks.md')};
|
|
25
|
+
}
|
|
26
|
+
const identity=runId=>({repositoryId:'abandon-position',runId,taskId:'T-002',attempt:1});
|
|
27
|
+
const definition=(f,runId)=>({version:1,specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,
|
|
28
|
+
identity:identity(runId),scope:['a.mjs'],requirements:['requirements.md']});
|
|
29
|
+
const request=runId=>({version:1,operation:'abandon_effect',requestId:'abandon',identity:identity(runId),reason:'Old host and children exited'});
|
|
30
|
+
function execution(f,verdict='blocked'){
|
|
31
|
+
const reviewer={id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',
|
|
32
|
+
allowed:true,available:true,contexts:['review-one','review-two'],run:(value,{onEvent})=>{
|
|
33
|
+
onEvent({event:'thread.started',provider_thread:'review-thread'});
|
|
34
|
+
onEvent({event:'turn.started',item_type:null});onEvent({event:'item.completed',item_type:'agent_message'});
|
|
35
|
+
onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
36
|
+
return {status:'succeeded',value:{verdict,packageDigest:value.payload.reviewPackage.packageDigest,
|
|
37
|
+
examinedPaths:reviewPaths(value.payload.reviewPackage),findings:[],summary:'Fixture review'}};
|
|
38
|
+
}};
|
|
39
|
+
return {configuration:{kind:'abandon-position-v1'},timeoutMs:2000,excludedContexts:['control'],
|
|
40
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:createCodexDeveloperRun({
|
|
41
|
+
requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.mjs'),'written\n');
|
|
42
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
43
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
44
|
+
reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
|
|
45
|
+
authorize:(value,{authorizationAt})=>{const body={version:1,kind:'cm-review-dispatch-grant',
|
|
46
|
+
grantId:'grant',adapterId:'codex-review-adapter',invocationId:value.invocationId,
|
|
47
|
+
requestDigest:value.requestDigest,identity:value.identity,reviewerId:'reviewer',
|
|
48
|
+
logicalContextId:value.contextId,packageDigest:value.payload.reviewPackage.packageDigest,
|
|
49
|
+
hostContextId:'control',decisionId:'approved',decision:'approved',issuedAt:authorizationAt,
|
|
50
|
+
expiresAt:authorizationAt+60000};return {...body,grantDigest:digest(body)};}},
|
|
51
|
+
hostDecision:{status:'approved'},check:createHostCheck({cwd:f.codeProject,
|
|
52
|
+
commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]})};
|
|
53
|
+
}
|
|
54
|
+
async function start(f,runId,verdict='blocked',options={}){
|
|
55
|
+
const run=await openControlRun(definition(f,runId),'create',execution(f,verdict),options);
|
|
56
|
+
try{return await run.host.handle({version:1,operation:'advance',requestId:'advance',identity:identity(runId)});}
|
|
57
|
+
finally{run.close();}
|
|
58
|
+
}
|
|
59
|
+
function statePath(f,runId){return path.join(f.reviewsDir,'.execution',runId,'state.json');}
|
|
60
|
+
function savePrefix(f,runId,type,kind){
|
|
61
|
+
const file=statePath(f,runId),state=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
62
|
+
const index=state.records.findIndex(row=>row.payload.type===type
|
|
63
|
+
&&(kind===null||row.payload.effect?.kind===kind));
|
|
64
|
+
assert(index>=0,`missing ${type} ${kind}`);
|
|
65
|
+
const {revision,...body}=state;body.records=state.records.slice(0,index+1);
|
|
66
|
+
fs.writeFileSync(file,JSON.stringify({...body,revision:digest(body)})+'\n');
|
|
67
|
+
return body.records;
|
|
68
|
+
}
|
|
69
|
+
function append(f,runId,type,fields,kind=type==='control'?'cancel':'result'){
|
|
70
|
+
const file=statePath(f,runId),state=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
71
|
+
const {revision,...body}=state,seq=body.records.length+1;
|
|
72
|
+
const record={version:1,seq,id:`runner.${String(seq).padStart(6,'0')}`,kind,
|
|
73
|
+
payload:runnerPayloadV3(type,fields),previousDigest:body.records.at(-1).digest};
|
|
74
|
+
body.records.push({...record,digest:digest(record)});
|
|
75
|
+
fs.writeFileSync(file,JSON.stringify({...body,revision:digest(body)})+'\n');
|
|
76
|
+
return body.records;
|
|
77
|
+
}
|
|
78
|
+
async function resume(f,runId,verdict='blocked'){
|
|
79
|
+
return openControlRun(definition(f,runId),'resume',execution(f,verdict),{allowAbandonEffect:true});
|
|
80
|
+
}
|
|
81
|
+
function mutated(records,index,change){
|
|
82
|
+
const result=structuredClone(records);change(result[index].payload);
|
|
83
|
+
for(let at=index;at<result.length;at++){
|
|
84
|
+
const {digest:discard,...body}=result[at];body.previousDigest=at?result[at-1].digest:null;
|
|
85
|
+
result[at]={...body,digest:digest(body)};
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for(const [kind,event] of [['develop','cancel'],['complete','late-cancel']])
|
|
91
|
+
test(`${kind} intent plus ${event} control replays and abandons at the bound position`,async()=>{
|
|
92
|
+
const f=fixture(),runId=`control-${kind}`;
|
|
93
|
+
try{
|
|
94
|
+
await start(f,runId,kind==='complete'?'approved':'blocked');
|
|
95
|
+
const intentRecords=savePrefix(f,runId,'effect-intent',kind);
|
|
96
|
+
const intent=intentRecords.at(-1);
|
|
97
|
+
const first=append(f,runId,'control',{event});
|
|
98
|
+
assert.equal(readRunnerHistory(first,first[0].payload.config,3).state.code,'reconciliation_required');
|
|
99
|
+
const prefix=append(f,runId,'control',{event:'workflow-error'});
|
|
100
|
+
const projected=readRunnerHistory(prefix,prefix[0].payload.config,3);
|
|
101
|
+
assert.equal(projected.state.state,'unknown');assert.equal(projected.state.code,'reconciliation_required');
|
|
102
|
+
assert.equal(projected.pendingAbandonable,true);
|
|
103
|
+
if(kind==='complete')fs.writeFileSync(f.tasksPath,'- [ ] T-002: fixture\n');
|
|
104
|
+
await assert.rejects(start(f,`${runId}-next`,'blocked',
|
|
105
|
+
{supersedeReason:'restart',acceptSupersededCodeDrift:true}),
|
|
106
|
+
error=>error.code==='supersede_unavailable'&&/abandon_effect/.test(error.reason));
|
|
107
|
+
const run=await resume(f,runId,kind==='complete'?'approved':'blocked');
|
|
108
|
+
try{
|
|
109
|
+
const status=await run.host.handle({version:1,operation:'status',requestId:'status',identity:identity(runId)});
|
|
110
|
+
assert.equal(status.pendingAction,'abandon_effect');
|
|
111
|
+
const result=await run.host.handle(request(runId));
|
|
112
|
+
assert.equal(result.outcome,'abandoned');assert.equal(result.state,'cancelled');
|
|
113
|
+
}finally{run.close();}
|
|
114
|
+
const records=JSON.parse(fs.readFileSync(statePath(f,runId),'utf8')).records;
|
|
115
|
+
const abandoned=records.at(-1);
|
|
116
|
+
assert.equal(abandoned.payload.intentDigest,intent.digest);
|
|
117
|
+
assert.equal(abandoned.payload.lastRecordDigest,records.at(-2).digest);
|
|
118
|
+
assert.equal(readRunnerHistory(records,records[0].payload.config,3).state.code,'effect_abandoned');
|
|
119
|
+
for(const key of ['intentDigest','lastRecordDigest']){
|
|
120
|
+
const wrong=mutated(records,records.length-1,p=>{p[key]='0'.repeat(64);});
|
|
121
|
+
assert.throws(()=>readRunnerHistory(wrong,wrong[0].payload.config,3),{code:'runner_abandon'});
|
|
122
|
+
}
|
|
123
|
+
const oldShape=mutated(records,records.length-1,p=>{delete p.lastRecordDigest;});
|
|
124
|
+
assert.throws(()=>readRunnerHistory(oldShape,oldShape[0].payload.config,3),{code:'runner_abandon'});
|
|
125
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('review intent before any join or registration uses abandon_effect; registration keeps abandon_review',async()=>{
|
|
129
|
+
const f=fixture(),runId='review-before-dispatch';
|
|
130
|
+
try{
|
|
131
|
+
await start(f,runId);
|
|
132
|
+
const prefix=savePrefix(f,runId,'effect-intent','review');
|
|
133
|
+
const config=prefix[0].payload.config;
|
|
134
|
+
const controlled=append(f,runId,'control',{event:'cancel'});
|
|
135
|
+
assert.equal(readRunnerHistory(controlled,config,3).pendingAbandonable,true);
|
|
136
|
+
await assert.rejects(start(f,'review-next','blocked',
|
|
137
|
+
{supersedeReason:'restart',acceptSupersededCodeDrift:true}),
|
|
138
|
+
error=>error.code==='supersede_unavailable'&&/abandon_effect/.test(error.reason));
|
|
139
|
+
const run=await resume(f,runId);
|
|
140
|
+
try{
|
|
141
|
+
const status=await run.host.handle({version:1,operation:'status',requestId:'status',identity:identity(runId)});
|
|
142
|
+
assert.equal(status.pendingAction,'abandon_effect');
|
|
143
|
+
assert.equal((await run.host.handle(request(runId))).code,'effect_abandoned');
|
|
144
|
+
}finally{run.close();}
|
|
145
|
+
const records=JSON.parse(fs.readFileSync(statePath(f,runId),'utf8')).records;
|
|
146
|
+
assert.equal(readRunnerHistory(records,config,3).state.state,'cancelled');
|
|
147
|
+
const events=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
148
|
+
assert.equal(events.findLast(row=>row.event==='effect_abandoned')?.node,'N4');
|
|
149
|
+
savePrefix(f,runId,'effect-intent','review');
|
|
150
|
+
append(f,runId,'host-joined',{hostContextId:'fresh-host'},'result');
|
|
151
|
+
const joined=JSON.parse(fs.readFileSync(statePath(f,runId),'utf8')).records;
|
|
152
|
+
assert.equal(readRunnerHistory(joined,config,3).pendingAbandonable,false);
|
|
153
|
+
const forged=append(f,runId,'effect-abandoned',{effectId:prefix.at(-1).payload.effect.id,
|
|
154
|
+
effectKind:'review',intentDigest:prefix.at(-1).digest,lastRecordDigest:joined.at(-1).digest,
|
|
155
|
+
reason:'old host exited',at:new Date().toISOString()},'result');
|
|
156
|
+
assert.throws(()=>readRunnerHistory(forged,config,3),{code:'runner_abandon'});
|
|
157
|
+
savePrefix(f,runId,'host-joined',null);
|
|
158
|
+
const joinedRun=await resume(f,runId);
|
|
159
|
+
try{assert.equal((await joinedRun.host.handle(request(runId))).code,'effect_abandon_review_pending');}
|
|
160
|
+
finally{joinedRun.close();}
|
|
161
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('legacy direct effect-abandoned record replays without the last-record field',async()=>{
|
|
165
|
+
const f=fixture(),runId='legacy-direct';
|
|
166
|
+
try{
|
|
167
|
+
await start(f,runId);
|
|
168
|
+
const records=savePrefix(f,runId,'effect-intent','develop');
|
|
169
|
+
const intent=records.at(-1);
|
|
170
|
+
const old=append(f,runId,'effect-abandoned',{effectId:intent.payload.effect.id,
|
|
171
|
+
effectKind:'develop',intentDigest:intent.digest,reason:'old host exited',
|
|
172
|
+
at:new Date().toISOString()},'result');
|
|
173
|
+
assert.equal(readRunnerHistory(old,old[0].payload.config,3).state.code,'effect_abandoned');
|
|
174
|
+
const extra=mutated(old,old.length-1,p=>{p.intentDigest='0'.repeat(64);});
|
|
175
|
+
assert.throws(()=>readRunnerHistory(extra,extra[0].payload.config,3),{code:'runner_abandon'});
|
|
176
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('registered review stays on abandon_review and cannot replay effect-abandoned',async()=>{
|
|
180
|
+
const f=fixture(),runId='review-registered';
|
|
181
|
+
try{
|
|
182
|
+
await start(f,runId);
|
|
183
|
+
const records=savePrefix(f,runId,'review-invocation-registered',null);
|
|
184
|
+
const config=records[0].payload.config,intent=records.findLast(row=>row.payload.type==='effect-intent');
|
|
185
|
+
const projected=readRunnerHistory(records,config,3);
|
|
186
|
+
assert.equal(projected.pendingAbandonable,false);
|
|
187
|
+
await assert.rejects(start(f,'registered-next','blocked',
|
|
188
|
+
{supersedeReason:'restart',acceptSupersededCodeDrift:true}),
|
|
189
|
+
error=>error.code==='supersede_unavailable'&&/abandon_review/.test(error.reason));
|
|
190
|
+
const run=await resume(f,runId);
|
|
191
|
+
try{
|
|
192
|
+
const status=await run.host.handle({version:1,operation:'status',requestId:'status',identity:identity(runId)});
|
|
193
|
+
assert.equal(status.pendingAction,'abandon_review');
|
|
194
|
+
assert.equal((await run.host.handle(request(runId))).code,'effect_abandon_review_pending');
|
|
195
|
+
}finally{run.close();}
|
|
196
|
+
const forged=append(f,runId,'effect-abandoned',{effectId:intent.payload.effect.id,
|
|
197
|
+
effectKind:'review',intentDigest:intent.digest,lastRecordDigest:records.at(-1).digest,
|
|
198
|
+
reason:'old host exited',at:new Date().toISOString()},'result');
|
|
199
|
+
assert.throws(()=>readRunnerHistory(forged,config,3),{code:'runner_abandon'});
|
|
200
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
201
|
+
});
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
|
-
import {inspectCmAiAdmission,approveCmAiSpecs} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
6
|
+
import {inspectCmAiAdmission,approveCmAiSpecs,matchesCmAiTaskSelection,explainCmAiTaskSelection} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
7
7
|
import {validateRunDefinition} from './cm-ai-run.mjs';
|
|
8
8
|
|
|
9
|
-
const usage='usage: cm-ai-admission.mjs --specs-dir PATH --code-project PATH [--code-project PATH ...] [--approval-response TEXT | --yes] [--approve --approval-response TEXT (no --yes)] [--print-run-definition --scope a,b [--requirements c,d] [--run-id X] [--repository-id Y]]';
|
|
9
|
+
const usage='usage: cm-ai-admission.mjs --specs-dir PATH --code-project PATH [--code-project PATH ...] [--approval-response TEXT | --yes] [--approve --approval-response TEXT (no --yes)] [--print-run-definition --scope a,b [--task T-xxx] [--requirements c,d] [--run-id X] [--repository-id Y]]';
|
|
10
10
|
|
|
11
11
|
function parse(argv){
|
|
12
12
|
const result={codeProjects:[]};
|
|
@@ -27,19 +27,23 @@ function parse(argv){
|
|
|
27
27
|
result.codeProjects.push(argv[++index]);continue;
|
|
28
28
|
}
|
|
29
29
|
const key={'--specs-dir':'specsDir','--approval-response':'approvalResponse',
|
|
30
|
-
'--scope':'scope','--requirements':'requirements','--run-id':'runId','--repository-id':'repositoryId'}[flag];
|
|
30
|
+
'--scope':'scope','--task':'task','--requirements':'requirements','--run-id':'runId','--repository-id':'repositoryId'}[flag];
|
|
31
31
|
if(!key||index+1>=argv.length||Object.hasOwn(result,key))throw new Error('invalid arguments');
|
|
32
32
|
result[key]=argv[++index];
|
|
33
33
|
}
|
|
34
34
|
if(!result.specsDir||result.codeProjects.length===0)throw new Error('specs and code project paths are required');
|
|
35
35
|
if(result.assumeYes&&Object.hasOwn(result,'approvalResponse'))throw new Error('approval input is duplicated');
|
|
36
|
-
if(!result.printRunDefinition&&['scope','requirements','runId','repositoryId'].some(key=>Object.hasOwn(result,key)))
|
|
36
|
+
if(!result.printRunDefinition&&['scope','task','requirements','runId','repositoryId'].some(key=>Object.hasOwn(result,key)))
|
|
37
37
|
throw new Error('run definition options require --print-run-definition');
|
|
38
38
|
return result;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function buildRunDefinition(admission,input){
|
|
42
42
|
if(!admission.codeProject)throw new Error('--print-run-definition requires one --code-project');
|
|
43
|
+
const selected=input.task===undefined?admission.nextTask:{feature:admission.nextTask.feature,id:input.task};
|
|
44
|
+
if(input.task!==undefined&&!matchesCmAiTaskSelection(admission,selected.feature,selected.id,{version:1,taskId:input.task}))
|
|
45
|
+
throw Object.assign(new Error('task_selection_mismatch'),{code:'task_selection_mismatch',
|
|
46
|
+
reason:explainCmAiTaskSelection(admission,{feature:selected.feature,taskId:input.task,selection:{version:1,taskId:input.task}})});
|
|
43
47
|
let repositoryId=input.repositoryId;
|
|
44
48
|
if(repositoryId===undefined){
|
|
45
49
|
let name;
|
|
@@ -49,10 +53,11 @@ function buildRunDefinition(admission,input){
|
|
|
49
53
|
}
|
|
50
54
|
const list=value=>value===undefined||value===''?[]:value.split(',').map(item=>item.trim());
|
|
51
55
|
const definition={version:1,specsDir:admission.specsDir,codeProject:admission.codeProject,
|
|
52
|
-
feature:
|
|
53
|
-
identity:{repositoryId,runId:input.runId??`${
|
|
54
|
-
taskId:
|
|
55
|
-
scope:list(input.scope),requirements:list(input.requirements)
|
|
56
|
+
feature:selected.feature,
|
|
57
|
+
identity:{repositoryId,runId:input.runId??`${selected.feature.replace(/^\d+\./,'')}-${selected.id}`,
|
|
58
|
+
taskId:selected.id,attempt:1},
|
|
59
|
+
scope:list(input.scope),requirements:list(input.requirements),
|
|
60
|
+
...(input.task===undefined?{}:{taskSelection:{version:1,taskId:selected.id}})};
|
|
56
61
|
return validateRunDefinition(definition);
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -71,14 +76,16 @@ export function main(argv=process.argv.slice(2)){
|
|
|
71
76
|
const decision=JSON.stringify({state:reference.state,reason:reference.reason,features:reference.features,nextTask:reference.nextTask});
|
|
72
77
|
const mismatch=!firstBlocked&&projectResults.some(item=>JSON.stringify({state:item.state,reason:item.reason,features:item.features,nextTask:item.nextTask})!==decision);
|
|
73
78
|
const selected=mismatch?{...reference,state:'blocked',reason:'project_admission_mismatch',nextTask:null}:reference;
|
|
74
|
-
const result={...selected,...(approval?.approveRefused?{approveRefused:approval.approveRefused}:{}),
|
|
79
|
+
const result={...selected,...(approval?.approveRefused?{approveRefused:approval.approveRefused}:{}),
|
|
80
|
+
...(approval?.approveReason?{approveReason:approval.approveReason}:{}),codeProject:input.codeProjects.length===1?selected.codeProject:null,
|
|
75
81
|
codeProjects:projectResults.map(item=>item.codeProject),
|
|
76
82
|
projectAdmissions:projectResults.map(item=>({codeProject:item.codeProject,state:item.state,reason:item.reason}))};
|
|
77
83
|
if(result.state==='awaiting_spec_approval'&&(result.approvalIntent!=='explicit'||input.assumeYes))
|
|
78
|
-
result.message='
|
|
84
|
+
result.message='确认规格摘要后,用 --approval-response 传入用户原话,并明确回复“开始”。';
|
|
79
85
|
if(input.printRunDefinition&&!result.approveRefused&&result.state==='ready'){
|
|
80
86
|
try{process.stdout.write(`${JSON.stringify(buildRunDefinition(result,input))}\n`);return 0;}
|
|
81
|
-
catch(error){process.stderr.write(`${JSON.stringify({error:{code:error.code??error.message
|
|
87
|
+
catch(error){process.stderr.write(`${JSON.stringify({error:{code:error.code??error.message,
|
|
88
|
+
...(typeof error.reason==='string'?{reason:error.reason}:{})}})}\n`);return 1;}
|
|
82
89
|
}
|
|
83
90
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
84
91
|
return result.state==='blocked'||result.approveRefused?1:0;
|
|
@@ -5,7 +5,7 @@ import os from 'node:os';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {spawnSync} from 'node:child_process';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
|
-
import {parseFeatureTaskText,validDependencies} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
8
|
+
import {parseFeatureTaskText,validDependencies,identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
9
9
|
import {validateRunDefinition} from './cm-ai-run.mjs';
|
|
10
10
|
|
|
11
11
|
const entry=fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url));
|
|
@@ -39,6 +39,36 @@ test('product admission reports generic continuation without approving or writin
|
|
|
39
39
|
assert.equal(fs.readdirSync(root).length,2);
|
|
40
40
|
}));
|
|
41
41
|
|
|
42
|
+
test('spec approval accepts only normalized explicit start phrases',()=>fixture(({specs,code})=>{
|
|
43
|
+
fs.writeFileSync(path.join(specs,'.cm-specs-status'),JSON.stringify({status:'awaiting_review',features:['1.login'],testCases:[]}));
|
|
44
|
+
const run=reply=>{
|
|
45
|
+
const result=spawnSync(process.execPath,[entry,'--specs-dir',specs,'--code-project',code,'--approval-response',reply],{encoding:'utf8'});
|
|
46
|
+
assert.equal(result.status,0,result.stderr);return JSON.parse(result.stdout);
|
|
47
|
+
};
|
|
48
|
+
for(const reply of ['开始','开始吧','可以开始','确认开始','开始执行','现在开始',' 开始吧。 ','现在开始! ','可以开始!.~~ ']){
|
|
49
|
+
const result=run(reply);assert.equal(result.approvalIntent,'explicit',reply);
|
|
50
|
+
assert.equal(result.reason,'approval_write_required',reply);
|
|
51
|
+
}
|
|
52
|
+
for(const reply of ['继续','可以','好','好的','OK','按最优解处理','你看着办','行','开始开发','开始吧,请继续']){
|
|
53
|
+
const result=run(reply);assert.equal(result.approvalIntent,'not_approval',reply);
|
|
54
|
+
assert.equal(result.reason,'spec_approval_required',reply);
|
|
55
|
+
assert.match(result.message,/回复.*开始/);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
test('approve writes only after a whitelisted reply and preserves the original reply',()=>fixture(({specs,code})=>{
|
|
59
|
+
const status=path.join(specs,'.cm-specs-status');
|
|
60
|
+
fs.writeFileSync(status,JSON.stringify({status:'awaiting_review',features:['1.login'],testCases:[]}));
|
|
61
|
+
const before=fs.readFileSync(status);
|
|
62
|
+
const invoke=reply=>spawnSync(process.execPath,[entry,'--specs-dir',specs,'--code-project',code,
|
|
63
|
+
'--approve','--approval-response',reply],{encoding:'utf8'});
|
|
64
|
+
const rejected=invoke('好的');assert.equal(rejected.status,1);
|
|
65
|
+
assert.equal(JSON.parse(rejected.stdout).approveRefused,'explicit_approval_required');
|
|
66
|
+
assert.deepEqual(fs.readFileSync(status),before);
|
|
67
|
+
const accepted=invoke('开始吧!');assert.equal(accepted.status,0,`stdout: ${accepted.stdout}\nstderr: ${accepted.stderr}`);
|
|
68
|
+
assert.equal(JSON.parse(accepted.stdout).state,'ready');
|
|
69
|
+
assert.equal(JSON.parse(fs.readFileSync(status,'utf8')).approval.response,'开始吧!');
|
|
70
|
+
}));
|
|
71
|
+
|
|
42
72
|
test('ready admission prints a directly valid run definition without writing the project',()=>fixture(({root,specs,code})=>{
|
|
43
73
|
fs.writeFileSync(path.join(specs,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.login'],testCases:[]}));
|
|
44
74
|
fs.writeFileSync(path.join(code,'package.json'),JSON.stringify({name:'login-app'}));
|
|
@@ -94,6 +124,21 @@ function admission(specs,code,names,exitCode=0){
|
|
|
94
124
|
|
|
95
125
|
const threeTasks='- [x] T-001: first\n- [ ] T-002: second\n- [ ] T-003: third\n';
|
|
96
126
|
|
|
127
|
+
test('approved bootstrap identity accepts numbered scaffold and rejects ambiguous candidates',()=>fixture(({specs,code})=>{
|
|
128
|
+
writeFeature(specs,'1.bootstrap','- [ ] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 和 .claude/ 规范\n');
|
|
129
|
+
fs.rmSync(path.join(specs,'1.login'),{recursive:true});
|
|
130
|
+
fs.rmSync(path.join(code,'README.md'));
|
|
131
|
+
assert.equal(identifyApprovedBootstrapFeature(['1.bootstrap']),'1.bootstrap');
|
|
132
|
+
assert.equal(identifyApprovedBootstrapFeature(['1.bootstrap-extra']),null);
|
|
133
|
+
assert.equal(admission(specs,code,['1.bootstrap']).nextTask.feature,'1.bootstrap');
|
|
134
|
+
assert.throws(()=>identifyApprovedBootstrapFeature(['0.bootstrap','1.bootstrap']),{code:'bootstrap_feature_ambiguous'});
|
|
135
|
+
assert.throws(()=>identifyApprovedBootstrapFeature(['1.bootstrap','2.bootstrap']),{code:'bootstrap_feature_ambiguous'});
|
|
136
|
+
for(const names of [['0.bootstrap','1.bootstrap'],['1.bootstrap','2.bootstrap']]){
|
|
137
|
+
for(const name of names)if(!fs.existsSync(path.join(specs,name)))writeFeature(specs,name,'- [ ] T-001: scaffold\n');
|
|
138
|
+
assert.equal(admission(specs,code,names,1).reason,'bootstrap_feature_ambiguous');
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
141
|
+
|
|
97
142
|
test('dependency parser accepts sentence punctuation per ID and preserves internal ID characters',()=>{
|
|
98
143
|
for(const suffix of ['。','.','.',';',';','、',' 。 ..;;、 \t']){
|
|
99
144
|
const parsed=parseFeatureTaskText(threeTasks+`- T-002 依赖 T-001${suffix}\n- T-003 依赖 T-001${suffix},T-002${suffix}\n`,
|
|
@@ -185,3 +230,22 @@ test('parallel eligibility preserves nextTask and returns only dependency-ready
|
|
|
185
230
|
assert.equal(admission.nextTask.id,'T-001');
|
|
186
231
|
assert.deepEqual(admission.eligibleTasks,[{feature:'1.login',id:'T-001'},{feature:'1.login',id:'T-002'}]);
|
|
187
232
|
}));
|
|
233
|
+
|
|
234
|
+
test('explicit task prints only a dependency-ready member and binds selection in the definition',()=>fixture(({specs,code})=>{
|
|
235
|
+
fs.writeFileSync(path.join(specs,'1.login','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
|
|
236
|
+
fs.writeFileSync(path.join(specs,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.login']}));
|
|
237
|
+
const args=[entry,'--specs-dir',specs,'--code-project',code,'--print-run-definition','--scope','src/a.js'];
|
|
238
|
+
const chosen=spawnSync(process.execPath,[...args,'--task','T-002'],{encoding:'utf8'});
|
|
239
|
+
assert.equal(chosen.status,0,chosen.stderr);
|
|
240
|
+
const definition=JSON.parse(chosen.stdout);
|
|
241
|
+
assert.equal(definition.identity.taskId,'T-002');
|
|
242
|
+
assert.deepEqual(definition.taskSelection,{version:1,taskId:'T-002'});
|
|
243
|
+
assert.deepEqual(validateRunDefinition(definition),definition);
|
|
244
|
+
for(const task of ['T-003','T-999']){
|
|
245
|
+
const refused=spawnSync(process.execPath,[...args,'--task',task],{encoding:'utf8'});
|
|
246
|
+
assert.equal(refused.status,1,refused.stderr);assert.equal(JSON.parse(refused.stderr).error.code,'task_selection_mismatch');
|
|
247
|
+
assert.equal(refused.stdout,'');
|
|
248
|
+
}
|
|
249
|
+
const invalid=spawnSync(process.execPath,[entry,'--specs-dir',specs,'--code-project',code,'--task','T-002'],{encoding:'utf8'});
|
|
250
|
+
assert.equal(invalid.status,2);assert.match(invalid.stderr,/--print-run-definition/);
|
|
251
|
+
}));
|