@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,157 @@
|
|
|
1
|
+
// #14: mutable project/user/plugin CM config must not make a QA run unopenable.
|
|
2
|
+
import test,{after} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {openControlRun,runConfigMaterial} from './cm-ai-run.mjs';
|
|
10
|
+
import {createConversationExecution} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
11
|
+
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
12
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
13
|
+
import {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
|
|
14
|
+
import {openTaskExecutionStore} from '../runtime/js/cm-ai/task-owner.mjs';
|
|
15
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
16
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
17
|
+
|
|
18
|
+
const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-fingerprint-home-'));
|
|
19
|
+
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
20
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
|
|
21
|
+
fs.mkdirSync(process.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
22
|
+
after(()=>{
|
|
23
|
+
for(const [key,value] of Object.entries(saved)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
|
|
24
|
+
fs.rmSync(isolated,{recursive:true,force:true});
|
|
25
|
+
});
|
|
26
|
+
const userRuntimes=preset=>fs.writeFileSync(path.join(process.env.CM_WORKFLOW_HOME,'runtimes.yml'),
|
|
27
|
+
`runtimes: {available: both}\npreset: ${preset}\n`);
|
|
28
|
+
const template=fs.readFileSync(fileURLToPath(new URL('../templates/cm-workflow.yml',import.meta.url)));
|
|
29
|
+
const identity={repositoryId:'fingerprint-fixture',runId:'fingerprint-run',taskId:'T-002',attempt:1};
|
|
30
|
+
const request=(operation,extra={})=>({version:1,operation,requestId:operation,identity,...extra});
|
|
31
|
+
|
|
32
|
+
function fixture(){
|
|
33
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'run-')));
|
|
34
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.work';
|
|
35
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
36
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'old\n');fs.writeFileSync(path.join(codeProject,'requirements.md'),'fixture\n');
|
|
37
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
38
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-002: fixture\n');
|
|
39
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
40
|
+
const definition={version:1,specsDir,codeProject,feature,identity,scope:['a.mjs'],requirements:['requirements.md']};
|
|
41
|
+
return {root,codeProject,specsDir,feature,definition,projectConfig:path.join(codeProject,'.cm-workflow.yml')};
|
|
42
|
+
}
|
|
43
|
+
const environment={kind:'web',carrier:'browser',target:'fixture',scope:'local'};
|
|
44
|
+
const syntax=[{id:'unit',command:[process.execPath,'--check','a.mjs'],caseIds:[]}];
|
|
45
|
+
|
|
46
|
+
// The real current-conversation factory builds the built-in QA executor.
|
|
47
|
+
const conversation=(f,commands=syntax)=>createConversationExecution(f.definition,'host-session-1',
|
|
48
|
+
{call:async()=>{throw new Error('not dispatched');}},null,null,
|
|
49
|
+
{qa:{commands,environment},documentationPaths:[],applicableAgentFiles:[]},true,'claude');
|
|
50
|
+
async function opens(f,mode,execution,options){
|
|
51
|
+
const run=await openControlRun(f.definition,mode,execution,options);run.close();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test('#14 user runtimes, project policies, the bootstrap template and test policy do not change the QA run fingerprint',async()=>{
|
|
55
|
+
for(const change of ['user-runtimes','auto-fix','bootstrap-template','test-policy']){
|
|
56
|
+
const f=fixture();userRuntimes('codex-codes');
|
|
57
|
+
await opens(f,'create',conversation(f));
|
|
58
|
+
const before=fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'));
|
|
59
|
+
if(change==='user-runtimes')userRuntimes('claude-codes');
|
|
60
|
+
if(change==='auto-fix')fs.writeFileSync(f.projectConfig,'version: 1\npolicies:\n auto_fix: auto\n');
|
|
61
|
+
if(change==='bootstrap-template')fs.writeFileSync(f.projectConfig,template);
|
|
62
|
+
if(change==='test-policy')fs.writeFileSync(f.projectConfig,'version: 1\npolicies:\n tests: [commands]\n');
|
|
63
|
+
await opens(f,'resume',conversation(f));
|
|
64
|
+
assert(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json')).equals(before),change);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('#14 the host QA inputs themselves stay bound by the fingerprint',async()=>{
|
|
69
|
+
const f=fixture();userRuntimes('codex-codes');
|
|
70
|
+
await opens(f,'create',conversation(f));
|
|
71
|
+
await assert.rejects(opens(f,'resume',conversation(f,[{id:'other',command:[process.execPath,'--version'],caseIds:[]}])),
|
|
72
|
+
{code:'fingerprint_mismatch'});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Synthetic trusted host that reaches N5 and N6 with the real built-in executor.
|
|
76
|
+
function synthetic(f,{commands=syntax,browser=null}={}){
|
|
77
|
+
const logHome=path.join(f.specsDir,'.reviews','host-log-mirror');
|
|
78
|
+
return {configuration:{kind:'synthetic-host-v1',hostContextId:'control',workflow:{qa:{commands,environment},documentationPaths:[],applicableAgentFiles:[]}},
|
|
79
|
+
timeoutMs:5000,excludedContexts:['control'],
|
|
80
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{
|
|
81
|
+
fs.writeFileSync(path.join(f.codeProject,'a.mjs'),'export const a=1;\n');
|
|
82
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
83
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
84
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
85
|
+
contexts:['review-one','review-two'],run:(review,{onEvent})=>{
|
|
86
|
+
onEvent({event:'thread.started',provider_thread:`thread-${review.identity.attempt}`});onEvent({event:'turn.started',item_type:null});
|
|
87
|
+
onEvent({event:'item.completed',item_type:'agent_message'});onEvent({event:'turn.completed',item_type:null});
|
|
88
|
+
onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
89
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:review.payload.reviewPackage.packageDigest,
|
|
90
|
+
examinedPaths:reviewPaths(review.payload.reviewPackage),findings:[],summary:'Synthetic review'}};}}],
|
|
91
|
+
reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],authorize:(review,{authorizationAt})=>{
|
|
92
|
+
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${review.identity.attempt}`,adapterId:'codex-review-adapter',
|
|
93
|
+
invocationId:review.invocationId,requestDigest:review.requestDigest,identity:review.identity,reviewerId:'reviewer',
|
|
94
|
+
logicalContextId:review.contextId,packageDigest:review.payload.reviewPackage.packageDigest,hostContextId:'control',
|
|
95
|
+
decisionId:'decision',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
96
|
+
return {...body,grantDigest:digest(body)};}},
|
|
97
|
+
hostDecision:{status:'approved'},check:createHostCheck({cwd:f.codeProject,commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]}),
|
|
98
|
+
qaLogHome:logHome,
|
|
99
|
+
qaDecisionProvider:{timeoutMs:1000,decide:async binding=>({decisionId:'qa-decision',identity:binding.identity,
|
|
100
|
+
packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-09-28T00:00:00Z'})},
|
|
101
|
+
qaExecutor:createHostQaExecutor({specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,requirements:['requirements.md'],
|
|
102
|
+
runtime:'codex',commands,environment,timeoutMs:60000,logHome,...(browser?{browser}:{})})};
|
|
103
|
+
}
|
|
104
|
+
const testRuns=f=>fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
|
|
105
|
+
.filter(row=>row.event==='test_run'&&['start','complete'].includes(row.phase));
|
|
106
|
+
|
|
107
|
+
test('#14 a completed QA run is recoverable after the user enables auto_fix, with the round bound in its QA records',async()=>{
|
|
108
|
+
const f=fixture();userRuntimes('codex-codes');
|
|
109
|
+
fs.writeFileSync(f.projectConfig,'version: 1\npolicies:\n auto_fix: explicit\n');
|
|
110
|
+
let run=await openControlRun(f.definition,'create',synthetic(f,{commands:[]}));
|
|
111
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_result_blocked');run.close();
|
|
112
|
+
// --auto-qa-fix needs this project policy; the next QA round must still open.
|
|
113
|
+
fs.writeFileSync(f.projectConfig,'version: 1\npolicies:\n auto_fix: auto\n');userRuntimes('claude-codes');
|
|
114
|
+
run=await openControlRun(f.definition,'resume',synthetic(f),{qaConfigRevision:{
|
|
115
|
+
previousWorkflow:{qa:{commands:[],environment},documentationPaths:[],applicableAgentFiles:[]},reason:'补上漏配的项目测试命令'}});
|
|
116
|
+
const result=await run.host.handle(request('advance'));run.close();
|
|
117
|
+
assert.equal(result.code,'qa_passed',JSON.stringify(result));
|
|
118
|
+
const rows=testRuns(f);
|
|
119
|
+
assert.deepEqual(rows.map(row=>[row.phase,row.attempt,row.mode,row.case_count]),
|
|
120
|
+
[['start',1,'commands',1],['complete',1,'commands',1],['start',2,'commands',1],['complete',2,'commands',1]]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('#14 a store fingerprinted in the historical plan form still opens and advances exactly as before',async()=>{
|
|
124
|
+
const f=fixture();userRuntimes('codex-codes');
|
|
125
|
+
let browserUp=false;
|
|
126
|
+
const browser=async browserRequest=>{
|
|
127
|
+
if(!browserUp)return {verdict:'BLOCKED',evidence:[],environment:browserRequest.environment,cleanup:'failed'};
|
|
128
|
+
const shot=path.join(f.specsDir,'.reviews','tc-001.txt');fs.writeFileSync(shot,'observed');
|
|
129
|
+
return {verdict:'PASS',evidence:[shot],environment:browserRequest.environment,cleanup:'not_needed'};
|
|
130
|
+
};
|
|
131
|
+
fs.writeFileSync(path.join(f.specsDir,f.feature,'requirements.md'),'# R\n\n- AC-001: page renders\n');
|
|
132
|
+
fs.writeFileSync(path.join(f.specsDir,f.feature,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases:[
|
|
133
|
+
{id:'TC-001',origin:'generated',kind:'browser',blocking:true,acIds:['AC-001'],taskIds:['T-002'],title:'renders',
|
|
134
|
+
preconditions:['fixture'],steps:['open'],expected:['visible'],cleanup:[]}]}));
|
|
135
|
+
const manifest=buildManifest(f.specsDir);
|
|
136
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[f.feature],specFiles:manifest,
|
|
137
|
+
testCases:manifest.filter(item=>item.path.endsWith('/test-cases.json'))}));
|
|
138
|
+
// An older runtime created the store with the plan-bearing fingerprint and
|
|
139
|
+
// stopped after the initializer; the current code must finish and keep it.
|
|
140
|
+
const legacy=runConfigMaterial(f.definition,synthetic(f,{browser}),{legacyQa:true});
|
|
141
|
+
const store=openTaskExecutionStore({tasksPath:path.join(f.specsDir,f.feature,'tasks.md'),feature:'work',specsRoot:f.specsDir,
|
|
142
|
+
identity:{repositoryId:identity.repositoryId,runId:identity.runId},create:true,
|
|
143
|
+
fingerprints:{workflow:digest('cm-ai-host-execution-v1'),config:digest(legacy),inputs:digest({feature:f.feature,task:identity.taskId})}});
|
|
144
|
+
store.close();
|
|
145
|
+
let run=await openControlRun(f.definition,'resume',synthetic(f,{browser}));
|
|
146
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_result_blocked');run.close();
|
|
147
|
+
const state=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
148
|
+
assert.equal(JSON.parse(fs.readFileSync(state)).fingerprints.config,digest(legacy));
|
|
149
|
+
// Historical stores keep their original fail-closed binding, now with a reason.
|
|
150
|
+
fs.writeFileSync(f.projectConfig,'version: 1\npolicies:\n auto_fix: auto\n');
|
|
151
|
+
await assert.rejects(openControlRun(f.definition,'resume',synthetic(f,{browser})),
|
|
152
|
+
error=>error.code==='fingerprint_mismatch'&&/\.cm-workflow\.yml/.test(error.reason));
|
|
153
|
+
fs.rmSync(f.projectConfig);browserUp=true;
|
|
154
|
+
run=await openControlRun(f.definition,'resume',synthetic(f,{browser}),{rerunBlockedQa:true});
|
|
155
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_passed');run.close();
|
|
156
|
+
assert.equal(JSON.parse(fs.readFileSync(state)).fingerprints.config,digest(legacy));
|
|
157
|
+
});
|
|
@@ -32,7 +32,7 @@ function events(onEvent,thread){
|
|
|
32
32
|
{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},
|
|
33
33
|
{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
34
34
|
}
|
|
35
|
-
async function fixture(t,{childHost=A,causeContext=null}={}){
|
|
35
|
+
async function fixture(t,{childHost=A,causeContext=null,lostCauseReviews=0}={}){
|
|
36
36
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'qa-fix-session-')));
|
|
37
37
|
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.value';
|
|
38
38
|
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
@@ -81,8 +81,12 @@ async function fixture(t,{childHost=A,causeContext=null}={}){
|
|
|
81
81
|
const qaSource={feature,identity,packageDigest:failed.packageDigest,testRunId:failed.fixHandoff.source.testRunId,
|
|
82
82
|
handoffDigest:failed.fixHandoff.handoffDigest};
|
|
83
83
|
const permissions=['--allow-cause-review'];
|
|
84
|
+
let causeReviews=0;
|
|
84
85
|
const reviewHost=live=>createFixReviewHost({codeProject,hostContextId:live,review,permissions,workerFactory:()=>async({prompt},{onEvent})=>{
|
|
85
|
-
const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
86
|
+
const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
87
|
+
if(++causeReviews<=lostCauseReviews){onEvent({event:'thread.started',provider_thread:`lost-child-review-${causeReviews}`});
|
|
88
|
+
throw Error('Synthetic lost cause review');}
|
|
89
|
+
events(onEvent,'synthetic-child-review');
|
|
86
90
|
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,
|
|
87
91
|
examinedPaths:['value.mjs'],findings:[],summary:'Synthetic cause review'}};
|
|
88
92
|
}});
|
|
@@ -253,3 +257,24 @@ test('QA-fix child abandons a lost local diagnosis only with its dedicated CLI f
|
|
|
253
257
|
assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');
|
|
254
258
|
assert(f.records().some(row=>row.id==='fix-diagnose-retry-1-result'));
|
|
255
259
|
});
|
|
260
|
+
|
|
261
|
+
test('#15 a QA-fix child cause review without a result is abandoned once through the parent host, then re-reviewed',async t=>{
|
|
262
|
+
const f=await fixture(t,{lostCauseReviews:1});
|
|
263
|
+
let owner=await f.open(A);
|
|
264
|
+
assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');
|
|
265
|
+
const reviewed=await owner.handle({...f.bound('fix_action'),fixOperation:'cause_review'});
|
|
266
|
+
assert.equal(reviewed.fixStage,'unknown');assert.equal(reviewed.actionResult.reviewAbandonable,'cause_review');
|
|
267
|
+
const request={...f.bound('fix_action'),fixOperation:'abandon_review',reason:'Child cause reviewer confirmed stopped'};
|
|
268
|
+
const before=fs.readFileSync(f.statePath);
|
|
269
|
+
await assert.rejects(owner.handle(request),{code:'fix_review_abandon_authorization_required'});
|
|
270
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
271
|
+
f.close();
|
|
272
|
+
const local=await cli(f,A,request,{flags:['--allow-qa-fix-abandon']});
|
|
273
|
+
assert.match(local.stderr,/fix_review_abandon_authorization_required/);assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
274
|
+
const allowed=await cli(f,A,request,{flags:['--allow-qa-fix-abandon-review']});
|
|
275
|
+
assert.equal(allowed.code,0,allowed.stderr);assert.equal(allowed.result?.fixStage,'cause_review_required');
|
|
276
|
+
assert(f.records().some(row=>row.id==='fix-cause-abandoned'));
|
|
277
|
+
owner=await f.open(A);
|
|
278
|
+
assert.equal((await owner.handle({...f.bound('fix_action'),fixOperation:'cause_review'})).fixStage,'red_test_required');
|
|
279
|
+
assert.equal(f.records().find(row=>row.id==='fix-cause-retry-started').payload.providerThreadId,'synthetic-child-review');
|
|
280
|
+
});
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
// QA re-run and timeout recovery through the real single-task host CLI.
|
|
2
|
+
// Fake codex reviewer and synthetic session answers only: no model, network,
|
|
3
|
+
// simulator or browser is used. Every log home is a temporary directory.
|
|
4
|
+
import test,{after} 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
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
|
+
import {findCmAiQaDecision,inspectCmAiQaResult,recordCmAiQaDecision,recordCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
15
|
+
import {readHostQaFixHandoff} from '../runtime/js/cm-ai/host-qa-fix.mjs';
|
|
16
|
+
import {inspectFixQaSource,qaFixIdentity} from '../runtime/js/cm-fix/qa-source.mjs';
|
|
17
|
+
|
|
18
|
+
const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-rerun-home-'));
|
|
19
|
+
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
20
|
+
process.env.CM_WORKFLOW_HOME=path.join(home,'user');process.env.CM_WORKFLOW_LOG_HOME=path.join(home,'logs');
|
|
21
|
+
after(()=>{
|
|
22
|
+
for(const [key,value] of Object.entries(saved))if(value===undefined)delete process.env[key];else process.env[key]=value;
|
|
23
|
+
fs.rmSync(home,{recursive:true,force:true});
|
|
24
|
+
});
|
|
25
|
+
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
26
|
+
// The host CLI scenarios run real QA commands (host-check needs POSIX process
|
|
27
|
+
// groups and refuses win32) and POSIX fixtures (fake codex, sh shim).
|
|
28
|
+
const POSIX={skip:process.platform==='win32'?'host-check QA commands and the fixtures need POSIX':false};
|
|
29
|
+
const identity={repositoryId:'qa-rerun-fixture',runId:'qa-rerun-run',taskId:'T-001',attempt:1};
|
|
30
|
+
const simulator={kind:'app',carrier:'ios-simulator',target:'Fixture-iPhone',scope:'local'};
|
|
31
|
+
const service={kind:'service',carrier:'cli',target:'node',scope:'local'};
|
|
32
|
+
const lowRisk={scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
33
|
+
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
34
|
+
|
|
35
|
+
// The QA command stands in for xcodebuild/simulator scripts. It reads a mode
|
|
36
|
+
// file outside both roots, so switching the "environment" never touches the
|
|
37
|
+
// reviewed code or the specs.
|
|
38
|
+
const PROBE=`import fs from 'node:fs';
|
|
39
|
+
const mode=fs.readFileSync(new URL('../environment-mode',import.meta.url),'utf8').trim();
|
|
40
|
+
if(mode==='killed')process.kill(process.pid,'SIGKILL');
|
|
41
|
+
if(mode==='exit65')process.exit(65);
|
|
42
|
+
if(mode!=='ready')process.exit(1);
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
function fixture(t,{browser=false}={}){
|
|
46
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-rerun-')));
|
|
47
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
48
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.work';
|
|
49
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
50
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# Fixture\n\n- [AC-001] tab bar shows four tabs\n');
|
|
51
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Fixture\n');
|
|
52
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
53
|
+
if(browser)fs.writeFileSync(path.join(specsDir,feature,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases:[
|
|
54
|
+
{id:'TC-001',origin:'generated',kind:'browser',blocking:true,acIds:['AC-001'],taskIds:['T-001'],title:'four tabs',
|
|
55
|
+
preconditions:['UI test'],steps:['launch on simulator'],expected:['four tabs visible'],cleanup:[]}]}));
|
|
56
|
+
const manifest=buildManifest(specsDir);
|
|
57
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:manifest,
|
|
58
|
+
...(browser?{testCases:manifest.filter(item=>item.path.endsWith('/test-cases.json'))}:{})}));
|
|
59
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
60
|
+
fs.writeFileSync(path.join(codeProject,'probe.mjs'),PROBE);
|
|
61
|
+
const definition={version:1,codeProject,specsDir,feature,identity,scope:['target.mjs'],requirements:['requirements.md']};
|
|
62
|
+
const config=path.join(root,'run.json');fs.writeFileSync(config,JSON.stringify(definition));
|
|
63
|
+
const bin=path.join(root,'bin');fs.mkdirSync(bin);
|
|
64
|
+
const fake=path.join(bin,'codex');
|
|
65
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),fake);fs.chmodSync(fake,0o700);
|
|
66
|
+
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
67
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture',disabledSkills:[],promptTransport:'stdin'})}};
|
|
68
|
+
const reviewFile=path.join(root,'review.json');fs.writeFileSync(reviewFile,JSON.stringify(review));
|
|
69
|
+
const log=path.join(specsDir,'运行日志.jsonl');
|
|
70
|
+
const f={root,codeProject,specsDir,feature,definition,config,reviewFile,log,
|
|
71
|
+
env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
72
|
+
CM_WORKFLOW_HOME:path.join(root,'user'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')},
|
|
73
|
+
environment:mode=>fs.writeFileSync(path.join(root,'environment-mode'),mode+'\n'),
|
|
74
|
+
rows:()=>fs.existsSync(log)?fs.readFileSync(log,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[],
|
|
75
|
+
journal:()=>JSON.parse(fs.readFileSync(path.join(specsDir,'.reviews','.execution',identity.runId,'state.json'))),
|
|
76
|
+
workflow:(name,qa)=>{const file=path.join(root,`${name}.json`);
|
|
77
|
+
fs.writeFileSync(file,JSON.stringify({qa,documentationPaths:[],applicableAgentFiles:[]}));return file;}};
|
|
78
|
+
f.environment('ready');
|
|
79
|
+
return f;
|
|
80
|
+
}
|
|
81
|
+
const qaRows=f=>f.rows().filter(row=>row.event==='qa'&&row.node==='N6');
|
|
82
|
+
const testRuns=(f,phase)=>f.rows().filter(row=>row.event==='test_run'&&(phase===undefined||row.phase===phase));
|
|
83
|
+
const probeQa=(extra={})=>({commands:[{id:'probe',command:[process.execPath,'probe.mjs'],caseIds:[]}],environment:service,...extra});
|
|
84
|
+
|
|
85
|
+
function defaultAnswer(f,row){
|
|
86
|
+
if(row.kind==='develop'){
|
|
87
|
+
fs.writeFileSync(path.join(f.codeProject,'target.mjs'),'export const value = 1;\n');
|
|
88
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
89
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
90
|
+
}
|
|
91
|
+
if(row.kind==='check')return [{id:'syntax',command:[process.execPath,'--check','target.mjs'],outcome:'passed',exitCode:0,
|
|
92
|
+
evidence:'Synthetic node --check'}];
|
|
93
|
+
if(row.kind==='qa_assess')return lowRisk;
|
|
94
|
+
if(row.kind==='documentation_inspect')return {syncId:row.payload.syncId,identity:row.payload.identity,
|
|
95
|
+
packageDigest:row.payload.packageDigest,contextDigest:row.payload.contextDigest,status:'completed',
|
|
96
|
+
reason:'No documentation path configured',at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
|
|
97
|
+
throw Error(`unexpected host request ${row.kind}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// A python3 shim that refuses only the N6 test_run/start append, so the real host
|
|
101
|
+
// leaves exactly the durable prefix a crash right before that append leaves.
|
|
102
|
+
// POSIX only: callers are skipped on win32 before this runs.
|
|
103
|
+
function failingStartShim(f){
|
|
104
|
+
const lookup=spawnSync('/bin/sh',['-c','command -v python3'],{encoding:'utf8'});
|
|
105
|
+
assert.equal(lookup.status,0,'python3 must be on PATH for the interruption fixture');
|
|
106
|
+
const dir=path.join(f.root,'shim');fs.mkdirSync(dir,{recursive:true});
|
|
107
|
+
fs.writeFileSync(path.join(dir,'python3'),
|
|
108
|
+
`#!/bin/sh\ncase " $* " in *" --event test_run --phase start "*) exit 3;; esac\nexec ${JSON.stringify(lookup.stdout.trim())} "$@"\n`,{mode:0o700});
|
|
109
|
+
return dir;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// answers[kind] may be a value, a function(row) or 'IGNORE' (never answered).
|
|
113
|
+
function launch(f,{mode='resume',operation='advance',workflow=null,extra=[],answers={},review=true,pathPrefix=null}={}){
|
|
114
|
+
return new Promise((resolve,reject)=>{
|
|
115
|
+
const args=['serve','--config',f.config,'--mode',mode,'--host-context','session-A','--allow-development',
|
|
116
|
+
'--review-config',f.reviewFile,...(review?['--allow-review-attempt','1']:[]),
|
|
117
|
+
...(workflow?['--workflow-config',workflow,'--allow-qa']:[]),...extra];
|
|
118
|
+
const env=pathPrefix?{...f.env,PATH:pathPrefix+path.delimiter+f.env.PATH}:f.env;
|
|
119
|
+
const child=spawn(process.execPath,[cli,...args],{env,stdio:['pipe','pipe','pipe']});
|
|
120
|
+
let buffer='',stderr='',sessionId=null;const rows=[],asked=[];
|
|
121
|
+
const timer=setTimeout(()=>{child.kill('SIGKILL');reject(Error(`host timeout: ${stderr}`));},60000);
|
|
122
|
+
const send=value=>{try{child.stdin.write(JSON.stringify(value)+'\n');}catch{}};
|
|
123
|
+
child.on('error',reject);child.stderr.on('data',chunk=>stderr+=chunk);
|
|
124
|
+
child.stdout.on('data',chunk=>{
|
|
125
|
+
buffer+=chunk;let index;
|
|
126
|
+
while((index=buffer.indexOf('\n'))>=0){
|
|
127
|
+
const line=buffer.slice(0,index);buffer=buffer.slice(index+1);if(!line)continue;
|
|
128
|
+
let row;try{row=JSON.parse(line);}catch{continue;}
|
|
129
|
+
rows.push(row);
|
|
130
|
+
if(row.type==='host_ready'){sessionId=row.sessionId;
|
|
131
|
+
send({version:1,operation,requestId:'request',identity});}
|
|
132
|
+
if(row.type==='host_request'){
|
|
133
|
+
asked.push(row.kind);
|
|
134
|
+
const configured=answers[row.kind];
|
|
135
|
+
if(configured==='IGNORE')continue;
|
|
136
|
+
let result;
|
|
137
|
+
try{result=configured===undefined?defaultAnswer(f,row):typeof configured==='function'?configured(row):configured;}
|
|
138
|
+
catch(error){child.kill('SIGKILL');clearTimeout(timer);reject(error);return;}
|
|
139
|
+
send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
|
|
140
|
+
}
|
|
141
|
+
if(row.requestId==='request'&&(row.result||row.error))send({type:'host_close',sessionId});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
child.once('close',code=>{clearTimeout(timer);
|
|
145
|
+
resolve({code,stderr,asked,result:rows.find(row=>row.requestId==='request')?.result??null});});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const done=run=>{assert.equal(run.code,0,run.stderr);assert(run.result,run.stderr);return run.result;};
|
|
149
|
+
|
|
150
|
+
test('#7 a qa_assess answer window miss is a retryable rejection, never a durable BLOCKED decision',POSIX,async t=>{
|
|
151
|
+
const f=fixture(t),workflow=f.workflow('workflow',probeQa({timeoutMs:1500}));
|
|
152
|
+
const first=done(await launch(f,{mode:'create',workflow,answers:{qa_assess:'IGNORE'}}));
|
|
153
|
+
assert.equal(first.outcome,'rejected',JSON.stringify(first));assert.equal(first.code,'qa_decision_timeout');
|
|
154
|
+
assert.equal(qaRows(f).length,0,'a transport timeout must not write an N6 decision');
|
|
155
|
+
const status=done(await launch(f,{operation:'status',workflow}));
|
|
156
|
+
assert.equal(status.state,'fixture_completed');assert.equal(status.code,null);
|
|
157
|
+
// The same run, same configuration: the session now answers and N6 continues.
|
|
158
|
+
const resumed=await launch(f,{workflow});
|
|
159
|
+
const result=done(resumed);
|
|
160
|
+
assert.equal(result.state,'run_done',JSON.stringify(result));
|
|
161
|
+
assert.deepEqual(resumed.asked.filter(kind=>kind==='qa_assess'),['qa_assess']);
|
|
162
|
+
assert.deepEqual(qaRows(f).map(row=>[row.status,row.reason]),[['triggered','feature_complete']]);
|
|
163
|
+
assert.deepEqual(testRuns(f,'complete').map(row=>row.result),['PASS']);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Writes exactly the row an older host wrote when qa_assess timed out:
|
|
167
|
+
// same writer, deterministic decision id and no supersession link.
|
|
168
|
+
function legacyTimeoutDecision(f,packageDigest){
|
|
169
|
+
if(qaRows(f).length)return;
|
|
170
|
+
recordCmAiQaDecision({specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,identity,packageDigest,
|
|
171
|
+
logHome:path.join(f.specsDir,'.reviews','host-log-mirror'),
|
|
172
|
+
decision:{decisionId:`qa-${digest({identity,packageDigest}).slice(0,48)}`,identity,packageDigest,
|
|
173
|
+
status:'blocked',reason:'host_request_timeout',score:null,at:'2026-09-28T10:48:11Z'}});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
test('#7 a legacy 阻塞:host_request_timeout decision stays blocked unless --rerun-blocked-qa re-asks qa_assess once',POSIX,async t=>{
|
|
177
|
+
const f=fixture(t),workflow=f.workflow('workflow',probeQa({timeoutMs:1500}));
|
|
178
|
+
done(await launch(f,{mode:'create',workflow,answers:{qa_assess:'IGNORE'}}));
|
|
179
|
+
const status=done(await launch(f,{operation:'status',workflow}));
|
|
180
|
+
legacyTimeoutDecision(f,status.packageDigest);
|
|
181
|
+
const [legacy]=qaRows(f);assert.equal(legacy.status,'blocked');assert.equal(legacy.reason,'host_request_timeout');
|
|
182
|
+
const logBefore=fs.readFileSync(f.log),journalBefore=f.journal();
|
|
183
|
+
// Compatibility: without the explicit flag the recorded decision is replayed as before.
|
|
184
|
+
const plain=await launch(f,{workflow});
|
|
185
|
+
const blocked=done(plain);
|
|
186
|
+
assert.equal(blocked.code,'qa_blocked');assert.equal(blocked.pendingAction,'none');
|
|
187
|
+
assert.equal(blocked.reason,'host_request_timeout');assert.deepEqual(plain.asked,[]);
|
|
188
|
+
assert(fs.readFileSync(f.log).equals(logBefore));assert.deepEqual(f.journal(),journalBefore);
|
|
189
|
+
// Explicit, audited recovery: the recorded decision is superseded, not rewritten.
|
|
190
|
+
const recovery=await launch(f,{workflow,extra:['--rerun-blocked-qa']});
|
|
191
|
+
const recovered=done(recovery);
|
|
192
|
+
assert.equal(recovered.state,'run_done',JSON.stringify(recovered));
|
|
193
|
+
assert.deepEqual(recovery.asked.filter(kind=>kind==='qa_assess'),['qa_assess']);
|
|
194
|
+
assert(fs.readFileSync(f.log).subarray(0,logBefore.length).equals(logBefore),'history bytes are kept');
|
|
195
|
+
const decisions=qaRows(f);
|
|
196
|
+
assert.deepEqual(decisions.map(row=>[row.status,row.reason]),[['blocked','host_request_timeout'],['triggered','feature_complete']]);
|
|
197
|
+
assert.equal(decisions[1].previous_decision_id,legacy.decision_id);assert.notEqual(decisions[1].decision_id,legacy.decision_id);
|
|
198
|
+
assert.deepEqual(testRuns(f,'start').map(row=>[row.attempt,row.qa_decision_id]),[[1,decisions[1].decision_id]]);
|
|
199
|
+
assert.deepEqual(testRuns(f,'complete').map(row=>row.result),['PASS']);
|
|
200
|
+
// Replays read the effective decision; the flag cannot supersede a second time.
|
|
201
|
+
for(const extra of [[],['--rerun-blocked-qa']]){
|
|
202
|
+
const again=await launch(f,{workflow,extra,answers:{qa_assess:()=>assert.fail('qa_assess must not be re-asked')}});
|
|
203
|
+
assert.equal(again.code,0,again.stderr);assert.equal(qaRows(f).length,2);
|
|
204
|
+
}
|
|
205
|
+
assert.deepEqual(f.journal().records.slice(0,journalBefore.records.length),journalBefore.records);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('#7 recovery interrupted after the replacement decision, before QA start, resumes with the same command',POSIX,async t=>{
|
|
209
|
+
const f=fixture(t),workflow=f.workflow('workflow',probeQa({timeoutMs:1500}));
|
|
210
|
+
done(await launch(f,{mode:'create',workflow,answers:{qa_assess:'IGNORE'}}));
|
|
211
|
+
legacyTimeoutDecision(f,done(await launch(f,{operation:'status',workflow})).packageDigest);
|
|
212
|
+
const interrupted=done(await launch(f,{workflow,extra:['--rerun-blocked-qa'],pathPrefix:failingStartShim(f)}));
|
|
213
|
+
assert.equal(interrupted.outcome,'rejected',JSON.stringify(interrupted));assert.equal(interrupted.code,'qa_log_failed');
|
|
214
|
+
const prefix=qaRows(f);
|
|
215
|
+
assert.deepEqual(prefix.map(row=>row.status),['blocked','triggered']);assert.equal(testRuns(f).length,0);
|
|
216
|
+
// The same authorized command finishes the recovery as the ordinary first
|
|
217
|
+
// round; qa_assess is not asked again. Here that round meets a killed command.
|
|
218
|
+
const noAssess={qa_assess:()=>assert.fail('qa_assess must not be re-asked')};
|
|
219
|
+
f.environment('killed');
|
|
220
|
+
const resumed=done(await launch(f,{workflow,extra:['--rerun-blocked-qa'],answers:noAssess}));
|
|
221
|
+
assert.equal(resumed.code,'qa_result_blocked',JSON.stringify(resumed));
|
|
222
|
+
assert.deepEqual(qaRows(f).map(row=>row.decision_id),prefix.map(row=>row.decision_id));
|
|
223
|
+
assert.deepEqual(testRuns(f,'start').map(row=>[row.attempt,row.qa_decision_id,row.previous_test_run_id]),[[1,prefix[1].decision_id,undefined]]);
|
|
224
|
+
// Once a round exists under the replacement, the flag is an ordinary rerun again.
|
|
225
|
+
f.environment('ready');
|
|
226
|
+
const result=done(await launch(f,{workflow,extra:['--rerun-blocked-qa'],answers:noAssess}));
|
|
227
|
+
assert.equal(result.state,'run_done',JSON.stringify(result));
|
|
228
|
+
assert.deepEqual(testRuns(f,'start').map(row=>row.attempt),[1,2]);
|
|
229
|
+
assert.deepEqual(testRuns(f,'superseded').map(row=>row.reason),['host_evidence_problem']);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('#13 a host-declared BLOCKED simulator case re-runs on unchanged code with --rerun-blocked-qa',POSIX,async t=>{
|
|
233
|
+
const f=fixture(t,{browser:true}),workflow=f.workflow('workflow',probeQa({environment:simulator}));
|
|
234
|
+
const evidence=path.join(f.specsDir,'.reviews','tc-001.png');
|
|
235
|
+
const down=row=>({verdict:'BLOCKED',evidence:[],environment:row.payload.environment,cleanup:'not_needed'});
|
|
236
|
+
const up=row=>{fs.writeFileSync(evidence,'png');return {verdict:'PASS',evidence:[evidence],environment:row.payload.environment,cleanup:'not_needed'};};
|
|
237
|
+
const first=done(await launch(f,{mode:'create',workflow,extra:['--browser-qa','available'],answers:{qa_browser:down}}));
|
|
238
|
+
assert.equal(first.code,'qa_result_blocked',JSON.stringify(first));
|
|
239
|
+
const rerun=await launch(f,{workflow,extra:['--browser-qa','available','--rerun-blocked-qa'],answers:{qa_browser:up}});
|
|
240
|
+
const result=done(rerun);
|
|
241
|
+
assert.equal(result.state,'run_done',JSON.stringify(result));
|
|
242
|
+
const superseded=testRuns(f,'superseded');
|
|
243
|
+
assert.equal(superseded.length,1);assert.equal(superseded[0].reason,'host_evidence_problem');
|
|
244
|
+
assert.deepEqual(superseded[0].blocked_cases,['TC-001']);
|
|
245
|
+
assert.deepEqual(testRuns(f,'start').map(row=>row.attempt),[1,2]);
|
|
246
|
+
assert.deepEqual(testRuns(f,'complete').map(row=>row.result),['BLOCKED','PASS']);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('#13 an unavailable QA command (killed, no exit code) re-runs; the round budget still caps at three',POSIX,async t=>{
|
|
250
|
+
const f=fixture(t),workflow=f.workflow('workflow',probeQa());
|
|
251
|
+
f.environment('killed');
|
|
252
|
+
const first=done(await launch(f,{mode:'create',workflow}));
|
|
253
|
+
assert.equal(first.code,'qa_result_blocked',JSON.stringify(first));
|
|
254
|
+
for(let round=2;round<=3;round++){
|
|
255
|
+
const again=done(await launch(f,{workflow,extra:['--rerun-blocked-qa']}));
|
|
256
|
+
assert.equal(again.code,'qa_result_blocked',JSON.stringify(again));
|
|
257
|
+
}
|
|
258
|
+
const exhausted=done(await launch(f,{workflow,extra:['--rerun-blocked-qa']}));
|
|
259
|
+
assert.equal(exhausted.code,'qa_round_invalid',JSON.stringify(exhausted));
|
|
260
|
+
assert.deepEqual(testRuns(f,'start').map(row=>row.attempt),[1,2,3]);
|
|
261
|
+
assert.deepEqual(testRuns(f,'superseded').map(row=>row.blocked_cases),[['probe'],['probe']]);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('#13 the environment recovers: an unavailable command reaches run_done on the same approved code',POSIX,async t=>{
|
|
265
|
+
const f=fixture(t),workflow=f.workflow('workflow',probeQa());
|
|
266
|
+
f.environment('killed');
|
|
267
|
+
assert.equal(done(await launch(f,{mode:'create',workflow})).code,'qa_result_blocked');
|
|
268
|
+
f.environment('ready');
|
|
269
|
+
const result=done(await launch(f,{workflow,extra:['--rerun-blocked-qa']}));
|
|
270
|
+
assert.equal(result.state,'run_done',JSON.stringify(result));
|
|
271
|
+
assert.deepEqual(testRuns(f,'complete').map(row=>row.result),['BLOCKED','PASS']);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test('#13 a non-zero QA exit stays a product FAIL; only an explicit, recorded operator declaration re-runs it',POSIX,async t=>{
|
|
275
|
+
const f=fixture(t),workflow=f.workflow('workflow',probeQa());
|
|
276
|
+
f.environment('exit65');
|
|
277
|
+
const first=done(await launch(f,{mode:'create',workflow}));
|
|
278
|
+
assert.equal(first.code,'qa_failed',JSON.stringify(first));
|
|
279
|
+
const logBefore=fs.readFileSync(f.log);
|
|
280
|
+
const refused=done(await launch(f,{workflow,extra:['--rerun-blocked-qa']}));
|
|
281
|
+
assert.equal(refused.code,'qa_rerun_not_blocked_by_evidence');assert(fs.readFileSync(f.log).equals(logBefore));
|
|
282
|
+
const orphan=await launch(f,{workflow,extra:['--qa-environment-failure','simulator runtime was missing']});
|
|
283
|
+
assert.equal(orphan.code,1);assert.match(orphan.stderr,/qa_recovery_authorization_required/);
|
|
284
|
+
// The host refuses the orphan declaration before it even reads the run definition.
|
|
285
|
+
const early=await launch({...f,config:path.join(f.root,'missing-run.json')},{workflow,extra:['--qa-environment-failure','x']});
|
|
286
|
+
assert.equal(early.code,1);assert.match(early.stderr,/qa_recovery_authorization_required/);
|
|
287
|
+
f.environment('ready');
|
|
288
|
+
const declared=done(await launch(f,{workflow,extra:['--rerun-blocked-qa','--qa-environment-failure','simulator runtime was missing']}));
|
|
289
|
+
assert.equal(declared.state,'run_done',JSON.stringify(declared));
|
|
290
|
+
const [superseded]=testRuns(f,'superseded');
|
|
291
|
+
assert.equal(superseded.reason,'declared_environment_failure');
|
|
292
|
+
assert.equal(superseded.environment_failure_reason,'simulator runtime was missing');
|
|
293
|
+
assert.deepEqual(superseded.failed_cases,['probe']);assert.deepEqual(superseded.blocked_cases,[]);
|
|
294
|
+
assert.deepEqual(testRuns(f,'start').map(row=>row.attempt),[1,2]);
|
|
295
|
+
assert.deepEqual(testRuns(f,'complete').map(row=>row.result),['FAIL','PASS']);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('#26 a wrong QA workflow config is revised before any QA round, without consuming a round',POSIX,async t=>{
|
|
299
|
+
const f=fixture(t);
|
|
300
|
+
const wrong=f.workflow('workflow-old',{commands:[{id:'probe',command:[process.execPath,'-e','process.exit(3)'],caseIds:[]}],environment:service});
|
|
301
|
+
const fixed=f.workflow('workflow-new',probeQa());
|
|
302
|
+
const waiting=done(await launch(f,{mode:'create',workflow:wrong,review:false}));
|
|
303
|
+
assert.equal(waiting.state,'awaiting_review',JSON.stringify(waiting));
|
|
304
|
+
const before=f.journal();
|
|
305
|
+
const drift=await launch(f,{workflow:fixed,review:false});
|
|
306
|
+
assert.equal(drift.code,1);assert.match(drift.stderr,/fingerprint_mismatch/);
|
|
307
|
+
const revise=['--revise-qa-config',wrong,'--qa-config-revision-reason','QA 命令写错,运行前修正'];
|
|
308
|
+
const revised=await launch(f,{workflow:fixed,extra:revise});
|
|
309
|
+
const result=done(revised);
|
|
310
|
+
assert.equal(result.state,'run_done',JSON.stringify(result));
|
|
311
|
+
const records=f.journal().records.filter(row=>row.payload.type==='qa-config-revised');
|
|
312
|
+
assert.equal(records.length,1);
|
|
313
|
+
assert.equal(records[0].payload.record.qaRound,0);assert.equal(records[0].payload.record.testRunId,null);
|
|
314
|
+
assert.deepEqual(f.journal().records.slice(0,before.records.length),before.records);
|
|
315
|
+
assert.equal(f.rows().filter(row=>row.event==='decision'&&row.phase==='qa_config_revise').length,1);
|
|
316
|
+
assert.deepEqual(testRuns(f,'start').map(row=>[row.attempt,row.previous_test_run_id]),[[1,undefined]]);
|
|
317
|
+
assert.equal(testRuns(f,'superseded').length,0);
|
|
318
|
+
assert.deepEqual(testRuns(f,'complete').map(row=>row.result),['PASS']);
|
|
319
|
+
// The chain now binds the corrected file; the old one no longer resumes.
|
|
320
|
+
assert.equal((await launch(f,{workflow:fixed,operation:'status'})).code,0);
|
|
321
|
+
const old=await launch(f,{workflow:wrong,operation:'status'});
|
|
322
|
+
assert.equal(old.code,1);assert.match(old.stderr,/fingerprint_mismatch/);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('#7 decision chain: one linked supersession of a timeout decision, read by N6 and cm-fix alike',t=>{
|
|
326
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-chain-')));
|
|
327
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
328
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),logHome=path.join(root,'logs');
|
|
329
|
+
fs.mkdirSync(path.join(specsDir,'.reviews'),{recursive:true});fs.mkdirSync(codeProject);
|
|
330
|
+
const packageDigest='a'.repeat(64),feature='1.work',binding={specsDir,codeProject,feature,identity,packageDigest,logHome};
|
|
331
|
+
const query={specsDir,feature,identity,packageDigest},log=path.join(specsDir,'运行日志.jsonl');
|
|
332
|
+
const decision=(decisionId,status,reason,at)=>({decisionId,identity,packageDigest,status,reason,score:null,at});
|
|
333
|
+
const legacy=decision('qa-legacy','blocked','host_request_timeout','2026-09-28T10:48:11Z');
|
|
334
|
+
assert.throws(()=>recordCmAiQaDecision({...binding,previousDecisionId:'qa-legacy',
|
|
335
|
+
decision:decision('qa-fresh','triggered','feature_complete','2026-09-28T11:00:00Z')}),{code:'qa_decision_conflict'});
|
|
336
|
+
recordCmAiQaDecision({...binding,decision:legacy});
|
|
337
|
+
const onlyLegacy=fs.readFileSync(log);
|
|
338
|
+
// A link must name a recorded decision, and an identical row is not a supersession of itself.
|
|
339
|
+
assert.throws(()=>recordCmAiQaDecision({...binding,packageDigest:'d'.repeat(64),previousDecisionId:'qa-legacy',
|
|
340
|
+
decision:{...legacy,decisionId:'qa-d',packageDigest:'d'.repeat(64)}}),{code:'qa_decision_conflict'});
|
|
341
|
+
assert.throws(()=>recordCmAiQaDecision({...binding,previousDecisionId:'qa-legacy',decision:legacy}),{code:'qa_decision_conflict'});
|
|
342
|
+
// Only a timeout decision is supersedable, only by a linked distinct decision.
|
|
343
|
+
assert.throws(()=>recordCmAiQaDecision({...binding,previousDecisionId:'qa-legacy',decision:{...legacy,at:'2026-09-28T11:00:00Z'}}),
|
|
344
|
+
{code:'qa_decision_conflict'});
|
|
345
|
+
assert.throws(()=>recordCmAiQaDecision({...binding,previousDecisionId:'qa-other',
|
|
346
|
+
decision:decision('qa-fresh','triggered','feature_complete','2026-09-28T11:00:00Z')}),{code:'qa_decision_conflict'});
|
|
347
|
+
assert.deepEqual(fs.readFileSync(log),onlyLegacy);
|
|
348
|
+
// A decision that is not a timeout block is never superseded, even when named exactly.
|
|
349
|
+
const other={...binding,packageDigest:'b'.repeat(64)},otherDecision={decisionId:'qa-other-package',identity,
|
|
350
|
+
packageDigest:'b'.repeat(64),status:'triggered',reason:'feature_complete',score:null,at:'2026-09-28T10:00:00Z'};
|
|
351
|
+
recordCmAiQaDecision({...other,decision:otherDecision});
|
|
352
|
+
const withOther=fs.readFileSync(log);
|
|
353
|
+
assert.throws(()=>recordCmAiQaDecision({...other,previousDecisionId:'qa-other-package',
|
|
354
|
+
decision:{...otherDecision,decisionId:'qa-other-fresh',at:'2026-09-28T11:00:00Z'}}),{code:'qa_decision_conflict'});
|
|
355
|
+
assert.deepEqual(fs.readFileSync(log),withOther);
|
|
356
|
+
// Only once: even a second timeout block (from a custom provider) is final.
|
|
357
|
+
const timeoutTwice={...binding,packageDigest:'c'.repeat(64)},block=(decisionId,at)=>({decisionId,identity,
|
|
358
|
+
packageDigest:'c'.repeat(64),status:'blocked',reason:'host_request_timeout',score:null,at});
|
|
359
|
+
recordCmAiQaDecision({...timeoutTwice,decision:block('qa-c1','2026-09-28T10:00:00Z')});
|
|
360
|
+
recordCmAiQaDecision({...timeoutTwice,previousDecisionId:'qa-c1',decision:block('qa-c2','2026-09-28T10:10:00Z')});
|
|
361
|
+
const twice=fs.readFileSync(log);
|
|
362
|
+
assert.throws(()=>recordCmAiQaDecision({...timeoutTwice,previousDecisionId:'qa-c2',
|
|
363
|
+
decision:{...block('qa-c3','2026-09-28T10:20:00Z'),status:'triggered',reason:'feature_complete'}}),{code:'qa_decision_conflict'});
|
|
364
|
+
assert.deepEqual(fs.readFileSync(log),twice);
|
|
365
|
+
const fresh=decision('qa-fresh','triggered','feature_complete','2026-09-28T11:00:00Z');
|
|
366
|
+
recordCmAiQaDecision({...binding,previousDecisionId:'qa-legacy',decision:fresh});
|
|
367
|
+
recordCmAiQaDecision({...binding,previousDecisionId:'qa-legacy',decision:fresh});
|
|
368
|
+
const chained=fs.readFileSync(log);
|
|
369
|
+
assert.equal(findCmAiQaDecision(query).decisionId,'qa-fresh');
|
|
370
|
+
assert.throws(()=>recordCmAiQaDecision({...binding,previousDecisionId:'qa-fresh',
|
|
371
|
+
decision:{...decision('qa-third','skipped','risk_score_below_threshold','2026-09-28T12:00:00Z'),score:4}}),{code:'qa_decision_conflict'});
|
|
372
|
+
assert.deepEqual(fs.readFileSync(log),chained);
|
|
373
|
+
// The QA round and a cm-fix child bind the effective decision.
|
|
374
|
+
const report=path.join(specsDir,'.reviews','qa-failure.md');fs.writeFileSync(report,'Synthetic QA FAIL');
|
|
375
|
+
const qa={...binding,mode:'commands',caseCount:1,testRunId:'qa-round-1'};
|
|
376
|
+
recordCmAiQaRun({...qa,phase:'start'});
|
|
377
|
+
recordCmAiQaRun({...qa,phase:'complete',result:{result:'FAIL',passed:0,failed:1,blocked:0,report}});
|
|
378
|
+
assert.equal(inspectCmAiQaResult({...query,testRunId:'qa-round-1'}).status,'failed');
|
|
379
|
+
assert.equal(fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse).find(row=>row.phase==='start').qa_decision_id,'qa-fresh');
|
|
380
|
+
const handoff=readHostQaFixHandoff({...query,codeProject,testRunId:'qa-round-1'});
|
|
381
|
+
const qaSource={feature,identity,packageDigest,testRunId:'qa-round-1',handoffDigest:handoff.handoffDigest};
|
|
382
|
+
const configuration={qaSource,reproduction:{cwd:codeProject}};
|
|
383
|
+
assert.equal(inspectFixQaSource({specsRoot:specsDir,identity:qaFixIdentity(qaSource),configuration}).handoffDigest,handoff.handoffDigest);
|
|
384
|
+
// Forged chains fail closed in every reader.
|
|
385
|
+
const rows=fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse);
|
|
386
|
+
const at=rows.findIndex(row=>row.decision_id==='qa-fresh');
|
|
387
|
+
for(const [label,forge] of [
|
|
388
|
+
['unlinked',list=>{delete list[at].previous_decision_id;}],
|
|
389
|
+
['orphan successor',list=>{list.splice(list.findIndex(row=>row.decision_id==='qa-legacy'),1);}],
|
|
390
|
+
['reused id',list=>{Object.assign(list[at],{decision_id:'qa-legacy'});}],
|
|
391
|
+
['non-timeout predecessor',list=>{list.find(row=>row.decision_id==='qa-legacy').reason='feature_complete';}],
|
|
392
|
+
['third decision',list=>{list.splice(at+1,0,{...list[at],decision_id:'qa-third',previous_decision_id:'qa-fresh'});}],
|
|
393
|
+
]){
|
|
394
|
+
const copy=structuredClone(rows);forge(copy);
|
|
395
|
+
fs.writeFileSync(log,copy.map(row=>JSON.stringify(row)).join('\n')+'\n');
|
|
396
|
+
assert.throws(()=>findCmAiQaDecision(query),{code:'context_not_ready'},label);
|
|
397
|
+
assert.throws(()=>inspectCmAiQaResult({...query,testRunId:'qa-round-1'}),{code:'qa_not_triggered'},label);
|
|
398
|
+
assert.throws(()=>inspectFixQaSource({specsRoot:specsDir,identity:qaFixIdentity(qaSource),configuration}),label);
|
|
399
|
+
}
|
|
400
|
+
});
|