@aibyzero/cm-workflow 0.16.4 → 0.16.5
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 +8 -0
- package/CHANGELOG.md +50 -0
- package/README.md +12 -1
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/runtime-failover.md +1 -1
- 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-stream.mjs +12 -0
- 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 +137 -22
- 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 +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- 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 +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- 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-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- 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 +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- 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 +427 -31
- 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/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -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-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/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- 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 +92 -20
- package/scripts/cm-ai-batch-drive.test.mjs +164 -3
- package/scripts/cm-ai-batch-host.mjs +27 -11
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +33 -10
- 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 +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -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 +479 -47
- package/scripts/cm-ai-drive.test.mjs +240 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +84 -25
- 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-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -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 +917 -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 +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- 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-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-probe.test.mjs +9 -1
- 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-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 +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -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 +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- 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-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- 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.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- 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/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +261 -42
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// attempt and the registered V3 boundary; preflight is only local diagnostics.
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
6
7
|
import {fileURLToPath} from 'node:url';
|
|
7
8
|
import {REVIEWED_HANDOFF_HINT} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
8
9
|
import {readRunDefinition,openControlRun,createCodexExecution} from './cm-ai-run.mjs';
|
|
9
10
|
import {createConversationExecution as executionFor} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
10
11
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
11
|
-
import {serveCmAiHost,parseHostInputLimit} from '../runtime/js/cm-ai/host-session.mjs';
|
|
12
|
+
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
12
13
|
import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
|
|
13
14
|
import {createFixLearningPreparation} from '../runtime/js/cm-fix/learning.mjs';
|
|
14
15
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
@@ -21,6 +22,9 @@ export function withHandoffDiagnostic(host,error){
|
|
|
21
22
|
return {...host,async handle(request){
|
|
22
23
|
const result=await host.handle(request);
|
|
23
24
|
if(result?.code==='handoff_exists')error.write(`[host] ${REVIEWED_HANDOFF_HINT}\n`);
|
|
25
|
+
if(['out_of_scope','check_output_out_of_scope','unsupported_file','limit_exceeded','package_mismatch',
|
|
26
|
+
'review_package_changed','completion_package_changed'].includes(result?.code)&&typeof result.reason==='string')
|
|
27
|
+
error.write(`[host] ${result.reason}\n`);
|
|
24
28
|
return result;
|
|
25
29
|
}};
|
|
26
30
|
}
|
|
@@ -33,11 +37,31 @@ export function readBootstrapConfiguration(file){
|
|
|
33
37
|
const stat=fs.lstatSync(file);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_bootstrap_config');
|
|
34
38
|
const config=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(config,['selection']);return config;
|
|
35
39
|
}
|
|
40
|
+
// Launch-input refusals keep their code and name the input, so the operator can
|
|
41
|
+
// find the exit without reading the host source.
|
|
42
|
+
const refuse=(ok,code,reason)=>{if(!ok)throw Object.assign(new Error(code),{code,reason});};
|
|
43
|
+
const REASONED_CODES=['supersede_unavailable','supersede_code_drift','handoff_exists','browser_capability_required',
|
|
44
|
+
'browser_capability_unavailable','invalid_arguments','fingerprint_mismatch','task_selection_mismatch','review_configuration_required',
|
|
45
|
+
'spec_rebind_refused','spec_rebind_unavailable'];
|
|
36
46
|
const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon',
|
|
37
|
-
'test-author','repair','cause-review','final-review']
|
|
47
|
+
'abandon-review','test-author','repair','cause-review','final-review']
|
|
38
48
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
39
49
|
|
|
40
|
-
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--failover] [--review-
|
|
50
|
+
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--failover] [--allow-review-attempt 1|2] [--allow-abandon-review] [--allow-abandon-effect] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
51
|
+
|
|
52
|
+
export function formatClaudeModelHint(config,version=null){
|
|
53
|
+
const marker=config?.preflight?.request_checks?.find(check=>check?.model_recognized===false);
|
|
54
|
+
if(!marker)return null;
|
|
55
|
+
const model=marker.reported_model??config.model;
|
|
56
|
+
return `Model ${model} is not accepted by the installed Claude CLI${version?` (${version})`:''}. Try a family alias accepted by Claude CLI 2.1.x, for example claude-opus-5; this is not a list of available ids.`;
|
|
57
|
+
}
|
|
58
|
+
function claudeCliVersion(){
|
|
59
|
+
try{
|
|
60
|
+
const result=spawnSync('claude',['--version'],{encoding:'utf8',timeout:2000,maxBuffer:1024});
|
|
61
|
+
const value=result.status===0?result.stdout.trim():'';
|
|
62
|
+
return /^\d+\.\d+\.\d+ \(Claude Code\)$/.test(value)?value:null;
|
|
63
|
+
}catch{return null;}
|
|
64
|
+
}
|
|
41
65
|
|
|
42
66
|
export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
|
|
43
67
|
return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
|
|
@@ -135,24 +159,29 @@ function canResumeLegacyProtected(definition,runtime){
|
|
|
135
159
|
}
|
|
136
160
|
|
|
137
161
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
138
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--original-host-context ID is resume-only: keep the creating session in durable configuration while --host-context remains the real live session.
|
|
139
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved 0.bootstrap
|
|
140
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session mode (Codex or Claude; also batch): --protected-conversation-config PATH with {checkCommands,timeoutMs}; timeoutMs bounds
|
|
162
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--original-host-context ID is resume-only: keep the creating session in durable configuration while --host-context remains the real live session. Omit it for same-session resume; a different session must declare the creating session. Equal IDs are equivalent to omission. Parent conversation runs only; legacy protected runs, batch and QA-fix children are unchanged.\n');
|
|
163
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved bootstrap feature (0.bootstrap or a single numbered *.bootstrap): --bootstrap-config PATH {selection:null for scaffold, or original cm-init selection for rules} and --allow-bootstrap-write. Original scope must include fixed instruction targets; they are host-written inside the original task effect, checked/reviewed and reloaded. No Git/install/network grant. Optional codeProjects selects disjoint real roots below codeProject; prefix scope/requirements and use protected current-session checks with a declared codeProject per command.\n');
|
|
164
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session mode (Codex or Claude; also batch): --protected-conversation-config PATH with {checkCommands,timeoutMs}; timeoutMs bounds check commands and is the reviewer budget only when review-config has no timeoutMs. A review transport timeout with no result can resume once per attempt with fresh review authorization; a result-bearing timeout still requires reconciliation. No extra model call. The current host returns scoped UTF-8 edits (optional mode "0755"/"0644" on written files; new files are 0644); native Codex sandbox applies them and runs the declared checks. Original author runtime, per-attempt Review and QA permissions remain required. Do not combine with --protected-config. The input limit defaults to 64 KiB and may be raised with --input-limit; unavailable/binary changes stop, never switch to direct writes.\n');
|
|
141
165
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected single-task CLI mode: add --protected-config PATH --allow-provider-development-attempt 1|2 and --review-config PATH. Protected config is {model,checkCommands,timeoutMs}; roots and host identity come from the original run definition and launch. This explicitly permits one task attempt of real developer execution and its declared native-sandbox checks; --allow-development alone does not. Review separately requires --allow-review-attempt 1|2. Diagnostics are required but are not review authorization. Optional original --workflow-config PATH and --allow-qa connect protected QA commands and documentation within the same developer invocation before Review; host semantic/browser/inspection requests retain their original contracts, not arbitrary writes. Default current-session mode is unchanged. Protected parent mode selects coder/reviewer CLIs from the project declaration; Claude returns protected-text-v1 proposals for host validation and sandbox application; original QA-fix options require child configuration.protectSpecs=true and all original child action permissions. Protected fix writes use text proposals, not direct host edits. The original QA/documentation/finalizer gates remain required. No installation or Git authority.\n');
|
|
142
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--browser-qa is required when the approved contract for this feature contains blocking
|
|
166
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--browser-qa is required when the approved contract for this feature contains blocking or policy-enabled interactive QA cases and QA is enabled. It covers the declared carrier (browser, ios-simulator, and others); the flag name is retained for compatibility. It is a declaration by the launching session, not a probe. The gate applies to create and resume, and is not persisted. unavailable refuses to start.\n');
|
|
143
167
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--revise-qa-config PREVIOUS_WORKFLOW.json --qa-config-revision-reason REASON: 仅 resume 且 --allow-qa;核对旧配置后追加 QA 修订,旧 QA 作废留史,下一轮仍受三轮上限约束。未知 QA 须先处理;不能修改开发配置或重开 N5。\n');
|
|
144
168
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--auto-qa-fix optionally connects parent advance -> fix_run -> re-QA. Requires --qa-fix-template-config, --allow-qa-fix-start, original action permissions and project policies.auto_fix=auto. Explicit/never policies stop. Unknown, blocked or incomplete repair stops; status/cancel remain available and no fourth QA round is dispatched.\n');
|
|
145
169
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-template-config PATH is an alternative to --qa-fix-owner-config. Supply {specsRoot, feature, identity: parent identity, configuration: original fix configuration without qaSource}. Each fix request binds it to the latest completed QA failure; identity/digests are generated, commands/scope/permissions are not. Existing child configuration remains immutable.\n');
|
|
146
170
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state; a design-change child closes as escalated and reports qa_fix_incomplete, never qa_fix_completed. It does not auto-switch child configuration or run parent QA.\n');
|
|
147
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish, --allow-qa-fix-abandon. abandon_step also requires a reason in the fix_action request and only applies to eligible local unknown steps. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
|
|
171
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish, --allow-qa-fix-abandon, --allow-qa-fix-abandon-review. abandon_step also requires a reason in the fix_action request and only applies to eligible local unknown steps; abandon_review requires --allow-qa-fix-abandon-review and a reason, and applies once to the child cause review and once to its second-round final review while that registered review has no review result. The parent run\'s own --allow-abandon-review does not reach the child. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
|
|
148
172
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child runtime must match this host. A new child hostContextId must be the live session or the parent durable creator; an existing child retains its fingerprint-verified configuration. Child opens and review grants use the live session. It does not authorize test authoring, repair, independent provider Review, finish, Git or re-QA. Active child status/cancel use the original child owner; repeated advance never resets an unknown or completed step.\n');
|
|
149
173
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-owner-config PATH enables read-only fix_status. The file contains the existing fix owner definition {specsRoot, identity, configuration}, including its exact original qaSource and immutable configuration, not provider grants. fix_status binds the parent identity/packageDigest/testRunId, serially closes the parent writer, opens only an existing child, reads its original completion evidence, closes it and resumes the same parent. It does not create/execute repairs, rerun QA or clear correction gates.\n');
|
|
150
174
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session invalid_result means local value/Learning validation failed before file writes. Fix the reply, keep the same configuration, host identity and runId, restart with --mode resume and advance: blocked/developer_result_invalid retries develop at the same attempt. no_new_lesson requires reason:null (dogfood incident: nonempty reason previously wrote files then stranded the run as unknown). Already-applied proposals must match expected disk hashes; conflicts block as protected_edit_stale. Worker exceptions/timeouts and old unknown history are not retryable.\n');
|
|
151
175
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('New cm-ai runs carry approved specification data in developer requests and review packages: task/verification, all AC lines, design (64 KiB UTF-8 maximum, truncated:true above it), task-related test cases and manifest hashes. Sources must match .cm-specs-status.specFiles or spec_drift blocks. requirements may be [] or additional code-project files; specs never become writable scope. Legacy runs/packages retain their original representation. Dogfood: separate specs/code roots previously left developers and reviewers without task/interface contracts.\n');
|
|
152
176
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Completed fixture_completed runs originally without QA may explicitly attach N6 once on --mode resume with --workflow-config (non-null qa) and --allow-qa. Original definition, scope, requirements, identity and non-workflow configuration must match. The immutable qa-attached journal record binds the full resumed config fingerprint; later resumes require that same configuration and fresh --allow-qa. qa still requests qa_assess; no automatic decision or repeated development/Review. Dogfood: missing workflow at create previously stranded mandatory feature QA.\n');
|
|
153
177
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-unknown-qa requires --mode resume and fresh --allow-qa with the original workflow config. Only an unfinished QA invocation whose recorded case results are all PASS and which has no fixed execution report may be abandoned and rerun under a new testRunId at the same qaRound. The abandoned record lists partial_pass_cases; every case is rerun and old PASS evidence is history only. FAIL/BLOCKED results and unclosed resources remain blocked; no complete is fabricated.\n');
|
|
154
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-blocked-qa requires --mode resume, the original --workflow-config and fresh --allow-qa. Only the latest completed BLOCKED invocation with zero failures and exclusively host/environment evidence gaps can be superseded: browser evidenceProblem, failed cleanup, environment mismatch or host
|
|
155
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--
|
|
178
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-blocked-qa requires --mode resume, the original --workflow-config and fresh --allow-qa. Only the latest completed BLOCKED invocation with zero failures and exclusively host/environment evidence gaps can be superseded: browser evidenceProblem, failed cleanup, environment mismatch, host timeout or a host-declared BLOCKED answer; logic INSUFFICIENT_EVIDENCE or blocked only by a mapped command without exit code; QA commands that produced no exit code (timeout, killed, spawn/output failure). Missing/deferred command rows ([需确认], commands-unavailable, no-applicable-cases, no browser capability) and source drift are excluded. A new testRunId reruns every case at qaRound+1 (maximum 3, the shared QA round budget); superseded and start link previous_test_run_id. The flag is consumed once, never persisted; no development/Review/task replay or new QA decision. Do not combine with --rerun-unknown-qa.\n');
|
|
179
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('For a QA decision an older host recorded as blocked/host_request_timeout, --rerun-blocked-qa instead re-asks qa_assess once and appends a decision linked by previous_decision_id; history is kept (current hosts report a missed qa_assess window as retryable rejected/qa_decision_timeout and record nothing). --qa-environment-failure REASON (with --rerun-blocked-qa, single line, at most 500 UTF-8 bytes) declares that the non-zero QA command exits of the latest completed FAIL came from the environment: only command exits and logic cases failed solely by them qualify, never browser FAIL or CONTRADICTED; the superseded row records reason, failed_cases and blocked_cases. Every rerun reuses the three-round QA budget. Single-task host only.\n');
|
|
180
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-review: resume 原 run 后发送 abandon_review,request.reason 必须是单行且不超过 500 UTF-8 字节。操作员先确认旧 host 与 review 进程已退出;旗标只消费一次,不写入配置。\n');
|
|
181
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-effect: resume 原 run 后发送 abandon_effect,request.reason 必须是单行且不超过 500 UTF-8 字节。操作员须确认旧 host 和 effect 启动的检查/构建进程均已退出;仅当前会话 develop/complete 且无 task-commit-intent 时可用。\n');
|
|
182
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。若保留直接前驱运行留下的代码漂移,可额外使用 --accept-superseded-code-drift;漂移文件会作为新运行的已有代码并记录当前 SHA-256。\n');
|
|
183
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rebind-spec-material --spec-rebind-reason REASON:仅 resume。规格经 cm-prd --change 重新批准后,若本任务的描述、验证要求、验收标准、设计摘录与测试用例都未变,只换绑批准哈希并写 specification-rebound 记录,已有开发与审查结论保留;内容有变则拒绝并列出变化。status 的 spec_drift 会说明是否可换绑。\n');
|
|
184
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('当前会话手动驱动请用 scripts/cm-ai-drive.mjs(批次 cm-ai-batch-drive.mjs;修复 cm-fix-drive.mjs;规格 cm-prd-drive.mjs);详情见 skills/cm-ai/references/js-host.md。\n');
|
|
156
185
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
157
186
|
let run,bridge;
|
|
158
187
|
try{
|
|
@@ -163,24 +192,34 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
163
192
|
need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
164
193
|
const definition=readRunDefinition(argv[2]);
|
|
165
194
|
const config=await runReviewPreflight(definition,{model:argv[4],runtime});
|
|
166
|
-
output.write(JSON.stringify(config)+'\n');
|
|
195
|
+
output.write(JSON.stringify({...config,timeoutMs:900000})+'\n');
|
|
196
|
+
if(runtime==='claude'){
|
|
197
|
+
const hint=formatClaudeModelHint(config,claudeCliVersion());if(hint)error.write(hint+'\n');
|
|
198
|
+
}
|
|
199
|
+
return config.preflight.passed?0:1;
|
|
167
200
|
}
|
|
168
201
|
need(argv.length>=8&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--mode'
|
|
169
202
|
&&argv[5]==='--host-context'&&argv[7]==='--allow-development','host_launch_authorization_required');
|
|
170
203
|
const extra=new Map();
|
|
171
204
|
for(let index=8;index<argv.length;index++){
|
|
172
|
-
const name=argv[index];
|
|
173
|
-
|
|
174
|
-
if(['--supersede-reviewed-evidence','--allow-bootstrap-write','--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
175
|
-
else{
|
|
205
|
+
const name=argv[index];refuse(!extra.has(name),'invalid_arguments',`参数重复:${name}`);
|
|
206
|
+
refuse(['--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--allow-abandon-review','--allow-abandon-effect','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
|
|
207
|
+
if(['--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
208
|
+
else{refuse(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments',`${name} 需要一个值`);extra.set(name,argv[++index]);}
|
|
176
209
|
}
|
|
177
|
-
|
|
210
|
+
let inputLimit;
|
|
211
|
+
try{inputLimit=parseHostInputLimit(extra.get('--input-limit'));}
|
|
212
|
+
catch(error){refuse(error.code!=='invalid_arguments','invalid_arguments','--input-limit 须为 65536–4194304 的整数字节数');throw error;}
|
|
178
213
|
const revisionRequested=extra.has('--revise-qa-config')||extra.has('--qa-config-revision-reason');
|
|
179
|
-
need(!extra.has('--supersede-reviewed-evidence')&&!extra.has('--supersede-reason')
|
|
214
|
+
need(!extra.has('--supersede-reviewed-evidence')&&!extra.has('--supersede-reason')&&!extra.has('--accept-superseded-code-drift')
|
|
180
215
|
||(argv[4]==='create'&&extra.has('--supersede-reviewed-evidence')&&extra.has('--supersede-reason')),
|
|
181
216
|
'supersede_unavailable');
|
|
182
217
|
need(!revisionRequested||(argv[4]==='resume'&&extra.has('--allow-qa')&&extra.has('--revise-qa-config')
|
|
183
218
|
&&extra.has('--qa-config-revision-reason')&&!extra.has('--rerun-unknown-qa')&&!extra.has('--rerun-blocked-qa')),'qa_revision_authorization_required');
|
|
219
|
+
need(!extra.has('--allow-abandon-review')||argv[4]==='resume','review_abandon_unavailable');
|
|
220
|
+
refuse(extra.has('--rebind-spec-material')===extra.has('--spec-rebind-reason')&&(!extra.has('--rebind-spec-material')||argv[4]==='resume'),
|
|
221
|
+
'spec_rebind_unavailable','--rebind-spec-material 只用于 --mode resume,并须同时提供单行 --spec-rebind-reason 原因');
|
|
222
|
+
need(!extra.has('--allow-abandon-effect')||argv[4]==='resume','effect_abandon_unavailable');
|
|
184
223
|
const qaConfigRevision=revisionRequested?{previousWorkflow:readHostWorkflowConfiguration(extra.get('--revise-qa-config')),
|
|
185
224
|
reason:extra.get('--qa-config-revision-reason')}:null;
|
|
186
225
|
const originalHostContextId=extra.get('--original-host-context')??null;
|
|
@@ -189,10 +228,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
189
228
|
const review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config')):null;
|
|
190
229
|
const workflow=extra.has('--workflow-config')?readHostWorkflowConfiguration(extra.get('--workflow-config')):null;
|
|
191
230
|
let allowedAttempt=null;
|
|
192
|
-
if(extra.has('--allow-review-attempt')){
|
|
193
|
-
|
|
231
|
+
if(extra.has('--allow-review-attempt')){refuse(['1','2'].includes(extra.get('--allow-review-attempt')),'invalid_arguments','--allow-review-attempt 只接受 1 或 2');allowedAttempt=Number(extra.get('--allow-review-attempt'));}
|
|
232
|
+
refuse(!extra.has('--allow-qa')||workflow?.qa!=null,'invalid_arguments',
|
|
233
|
+
workflow===null?'--allow-qa 需要同时提供 --workflow-config':'--allow-qa 需要 --workflow-config 中的 qa 不为 null;本运行没有 QA 时去掉 --allow-qa');
|
|
194
234
|
need(!(extra.has('--rerun-unknown-qa')&&extra.has('--rerun-blocked-qa')),'qa_recovery_authorization_required');
|
|
195
235
|
need(!(extra.has('--rerun-unknown-qa')||extra.has('--rerun-blocked-qa'))||(argv[4]==='resume'&&extra.has('--allow-qa')),'qa_recovery_authorization_required');
|
|
236
|
+
need(!extra.has('--qa-environment-failure')||extra.has('--rerun-blocked-qa'),'qa_recovery_authorization_required');
|
|
196
237
|
const hasFix=extra.has('--qa-fix-owner-config')||extra.has('--qa-fix-template-config');
|
|
197
238
|
need(!(extra.has('--qa-fix-owner-config')&&extra.has('--qa-fix-template-config')),'invalid_fix_config');
|
|
198
239
|
need(!extra.has('--allow-qa-fix-start')||hasFix,'qa_fix_source_required');
|
|
@@ -200,7 +241,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
200
241
|
need(!extra.has('--auto-qa-fix')||(extra.has('--qa-fix-template-config')&&extra.has('--allow-qa-fix-start')),'qa_fix_auto_authorization_required');
|
|
201
242
|
need(![...fixLocalPermissions.keys()].some(flag=>extra.has(flag))||extra.has('--allow-qa-fix-start'),'qa_fix_start_authorization_required');
|
|
202
243
|
need(!extra.has('--allow-provider-development-attempt')||extra.has('--protected-config'),'protected_configuration_required');
|
|
203
|
-
|
|
244
|
+
refuse(!(extra.has('--protected-config')&&extra.has('--protected-conversation-config')),'invalid_arguments','--protected-config 与 --protected-conversation-config 不能同时使用');
|
|
204
245
|
const protection=extra.has('--protected-conversation-config')?readConversationProtection(extra.get('--protected-conversation-config')):null;
|
|
205
246
|
const bootstrap=extra.has('--bootstrap-config')?readBootstrapConfiguration(extra.get('--bootstrap-config')):null;
|
|
206
247
|
need(!extra.has('--allow-bootstrap-write')||bootstrap!==null,'bootstrap_configuration_required');
|
|
@@ -210,8 +251,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
210
251
|
// Launch-time capability assertion. See host-workflow-capabilities: this is a
|
|
211
252
|
// fresh declaration, not a probe the host performs.
|
|
212
253
|
readBrowserCapability(extra.get('--browser-qa'),
|
|
213
|
-
workflow?.qa!=null&&featureHasBrowserCases(definition.specsDir,definition.feature,definition.codeProject)
|
|
214
|
-
|
|
254
|
+
workflow?.qa!=null&&featureHasBrowserCases(definition.specsDir,definition.feature,definition.codeProject)
|
|
255
|
+
?[workflow.qa.environment?.carrier??'browser']:[]);
|
|
256
|
+
// Tool replies travel on the same input lines, so they share the one limit.
|
|
257
|
+
bridge=createHostToolBridge({responseLimit:inputLimit});
|
|
215
258
|
// Startup-only role failover. The project's runtimes.available declaration is
|
|
216
259
|
// primary: it fixes which runtimes may be chosen and, via roles.coder, the
|
|
217
260
|
// requested start runtime. The CLI probe only confirms reachability. It never
|
|
@@ -238,11 +281,17 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
238
281
|
fix=json(JSON.parse(fs.readFileSync(file,'utf8')),64*1024);
|
|
239
282
|
if(extra.has('--protected-config')||protection)need(fix.configuration?.protectSpecs===true,'protected_fix_required');
|
|
240
283
|
}
|
|
284
|
+
// The reviewer binding is part of the durable configuration fingerprint, so
|
|
285
|
+
// it cannot be added on resume. Requiring it at create removes the trap of
|
|
286
|
+
// a run that can reach awaiting_review but never be reviewed. Authorizing a
|
|
287
|
+
// review attempt is still the separate --allow-review-attempt.
|
|
288
|
+
refuse(argv[4]!=='create'||review!==null,'review_configuration_required',
|
|
289
|
+
'create 必须带 --review-config:审查配置写进运行指纹,resume 时不能再补。先用 cm-ai-host.mjs preflight --config 运行定义 --review-model 模型 --runtime 端 生成 review.json;是否真正派发审查仍由 --allow-review-attempt 单独授权');
|
|
241
290
|
let execution;
|
|
242
291
|
if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
|
|
243
292
|
try{
|
|
244
293
|
execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
|
|
245
|
-
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),supersedeReason:extra.get('--supersede-reason')??null});
|
|
294
|
+
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),specRebindReason:extra.get('--spec-rebind-reason')??null});
|
|
246
295
|
error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
|
|
247
296
|
}catch(cause){
|
|
248
297
|
if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
|
|
@@ -254,7 +303,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
254
303
|
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap)
|
|
255
304
|
:executionFor(definition,argv[6],bridge,review,allowedAttempt,workflow,extra.has('--allow-qa'),runtime,
|
|
256
305
|
{...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
|
|
257
|
-
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),supersedeReason:extra.get('--supersede-reason')??null});
|
|
306
|
+
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),specRebindReason:extra.get('--spec-rebind-reason')??null});
|
|
258
307
|
}
|
|
259
308
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
260
309
|
if(hasFix){
|
|
@@ -288,7 +337,17 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
288
337
|
}catch(cause){
|
|
289
338
|
const code=typeof cause?.code==='string'&&(/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)
|
|
290
339
|
||cause.code.startsWith('invalid_config: '))?cause.code:'host_launch_failed';
|
|
291
|
-
|
|
340
|
+
const snapshotReason=['out_of_scope','unsupported_file','limit_exceeded','package_mismatch'].includes(code)
|
|
341
|
+
&&typeof cause?.message==='string'&&cause.message.length<=8192&&!/[\r\n\0]/.test(cause.message)
|
|
342
|
+
?cause.message:null;
|
|
343
|
+
const reason=REASONED_CODES.includes(code)&&typeof cause?.reason==='string'&&cause.reason.length<=8192
|
|
344
|
+
&&!/[\r\n\0]/.test(cause.reason)?cause.reason:null;
|
|
345
|
+
if(code==='handoff_exists')error.write(`[host] ${REVIEWED_HANDOFF_HINT}\n`);
|
|
346
|
+
if(['supersede_code_drift','fingerprint_mismatch'].includes(code)&&reason)error.write(`[host] ${reason}\n`);
|
|
347
|
+
if(snapshotReason)error.write(`[host] ${snapshotReason}\n`);
|
|
348
|
+
const limitReason=code==='request_too_large'?inputLimitReason(cause.limit):null;
|
|
349
|
+
if(limitReason)error.write(`[host] request_too_large: ${limitReason}\n`);
|
|
350
|
+
error.write(JSON.stringify({error:{code,...(snapshotReason?{reason:snapshotReason}:{}),...(limitReason?{reason:limitReason}:{}),...(reason?{reason}:{})}})+'\n');return 1;
|
|
292
351
|
}finally{bridge?.close();run?.close();}
|
|
293
352
|
}
|
|
294
353
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -7,15 +7,23 @@ import path from 'node:path';
|
|
|
7
7
|
import {spawn,spawnSync} from 'node:child_process';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
10
|
-
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
10
|
+
import {createConversationExecution,main as hostMain} from './cm-ai-host.mjs';
|
|
11
11
|
import {readRunDefinition,openControlRun} from './cm-ai-run.mjs';
|
|
12
12
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
13
|
+
import {fixtureProcesses,guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
|
|
13
14
|
|
|
14
15
|
// Keep runtime declarations and log mirrors independent of the invoking user's home.
|
|
15
16
|
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-host-home-'));
|
|
16
17
|
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
17
18
|
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
18
19
|
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
20
|
+
// Every fixture root is swept once the file finishes: a surviving fake CLI or
|
|
21
|
+
// host is a leak even if its test passed (2026-09-28: fake reviewers ran 17h).
|
|
22
|
+
const fixtureRoots=new Set();
|
|
23
|
+
after(()=>{
|
|
24
|
+
const leaked=[...fixtureRoots].flatMap(root=>killFixtureProcesses(root));
|
|
25
|
+
assert.deepEqual(leaked.map(row=>row.command.slice(0,160)),[],'fixture processes outlived their tests');
|
|
26
|
+
});
|
|
19
27
|
|
|
20
28
|
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
21
29
|
const identity={repositoryId:'host-fixture',runId:'host-fixture-run',taskId:'T-001',attempt:1};
|
|
@@ -43,6 +51,35 @@ test('single host CLI rejects out-of-range and non-integer input limits before o
|
|
|
43
51
|
assert.equal(run.status,1);assert.match(run.stderr,/invalid_arguments/);
|
|
44
52
|
}
|
|
45
53
|
});
|
|
54
|
+
test('killing a real host at develop request leaves the original effect intent for recovery',async()=>{
|
|
55
|
+
const f=fixture();
|
|
56
|
+
try{
|
|
57
|
+
let buffer='',sawDevelop=false,stderr='';
|
|
58
|
+
const child=spawn(process.execPath,[cli,...launchArgs(f)],{stdio:['pipe','pipe','pipe'],env:process.env});
|
|
59
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
60
|
+
const done=new Promise((resolve,reject)=>{
|
|
61
|
+
const timer=setTimeout(()=>{child.kill('SIGKILL');reject(new Error('host kill fixture timed out: '+stderr));},10000);
|
|
62
|
+
child.stdout.on('data',chunk=>{
|
|
63
|
+
buffer+=chunk;
|
|
64
|
+
let newline;
|
|
65
|
+
while((newline=buffer.indexOf('\n'))!==-1){
|
|
66
|
+
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);
|
|
67
|
+
if(!line)continue;
|
|
68
|
+
const row=JSON.parse(line);
|
|
69
|
+
if(row.type==='host_ready')child.stdin.write(JSON.stringify(request('advance'))+'\n');
|
|
70
|
+
if(row.type==='host_request'&&row.kind==='develop'){sawDevelop=true;child.kill('SIGKILL');}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
child.once('error',error=>{clearTimeout(timer);reject(error);});
|
|
74
|
+
child.once('exit',(code,signal)=>{clearTimeout(timer);resolve({code,signal});});
|
|
75
|
+
});
|
|
76
|
+
const exited=await done;
|
|
77
|
+
assert.equal(sawDevelop,true,stderr);assert.equal(exited.signal,'SIGKILL');
|
|
78
|
+
const state=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'),'utf8'));
|
|
79
|
+
assert(state.records.some(row=>row.payload.type==='effect-intent'&&row.payload.effect.kind==='develop'));
|
|
80
|
+
assert.equal(state.records.some(row=>row.payload.type==='effect-checkpoint'),false);
|
|
81
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
82
|
+
});
|
|
46
83
|
test('resume accepts a changed transport input limit without changing the durable fingerprint',async()=>{
|
|
47
84
|
const f=fixture(),bridge=createHostToolBridge();
|
|
48
85
|
try{
|
|
@@ -56,13 +93,15 @@ test('resume accepts a changed transport input limit without changing the durabl
|
|
|
56
93
|
await serveHostTransport({host:{}},'65536',async options=>{limit=options.inputLimit;});
|
|
57
94
|
assert.equal(limit,65536);
|
|
58
95
|
const resumed=await openControlRun(definition,'resume',execution);resumed.close();
|
|
96
|
+
const otherSession=createConversationExecution(definition,'other-host-fixture',bridge,null,null,null,false,'codex');
|
|
97
|
+
await assert.rejects(openControlRun(definition,'resume',otherSession),{code:'fingerprint_mismatch'});
|
|
59
98
|
await serveHostTransport({host:{}},'1048576',async options=>{limit=options.inputLimit;});
|
|
60
99
|
assert.equal(limit,1048576);
|
|
61
100
|
assert.deepEqual(JSON.parse(fs.readFileSync(state,'utf8')).fingerprints,before);
|
|
62
101
|
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
63
102
|
});
|
|
64
103
|
function fixture(){
|
|
65
|
-
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-host-')));
|
|
104
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-host-')));fixtureRoots.add(root);
|
|
66
105
|
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work',config=path.join(root,'run.json');
|
|
67
106
|
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
68
107
|
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
@@ -70,15 +109,97 @@ function fixture(){
|
|
|
70
109
|
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
71
110
|
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
72
111
|
fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,scope:['target.mjs'],requirements:['requirements.md']}));
|
|
73
|
-
|
|
112
|
+
// create requires a bound review configuration; it grants no review attempt.
|
|
113
|
+
const reviewFile=path.join(root,'placeholder-review.json');
|
|
114
|
+
fs.writeFileSync(reviewFile,JSON.stringify({model:'fixture',preflight:{}}));
|
|
115
|
+
return {root,specsDir,codeProject,config,reviewFile,args:['serve','--config',config,'--mode','create','--host-context','native-host-fixture','--allow-development']};
|
|
74
116
|
}
|
|
117
|
+
// A test that supplies its own --review-config keeps it; others use the placeholder.
|
|
118
|
+
const launchArgs=f=>f.args.includes('--review-config')?f.args:[...f.args,'--review-config',f.reviewFile];
|
|
119
|
+
|
|
120
|
+
test('D1 SIGKILL at a real host develop request leaves an intent without checkpoint',async()=>{
|
|
121
|
+
const f=fixture();
|
|
122
|
+
try{
|
|
123
|
+
const result=await new Promise((resolve,reject)=>{
|
|
124
|
+
const child=spawn(process.execPath,[cli,...launchArgs(f)],{stdio:['pipe','pipe','pipe']});
|
|
125
|
+
let buffer='',asked=false;
|
|
126
|
+
const timer=setTimeout(()=>{child.kill('SIGKILL');reject(Error('host request timeout'));},15000);
|
|
127
|
+
child.once('error',error=>{clearTimeout(timer);reject(error);});
|
|
128
|
+
child.stdout.on('data',chunk=>{
|
|
129
|
+
buffer+=chunk;
|
|
130
|
+
for(let newline;(newline=buffer.indexOf('\n'))!==-1;){
|
|
131
|
+
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);
|
|
132
|
+
if(!line)continue;
|
|
133
|
+
const row=JSON.parse(line);
|
|
134
|
+
if(row.type==='host_ready')child.stdin.write(JSON.stringify(request('advance'))+'\n');
|
|
135
|
+
if(row.type==='host_request'&&row.kind==='develop'){asked=true;child.kill('SIGKILL');}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
child.once('close',(code,signal)=>{clearTimeout(timer);resolve({code,signal,asked});});
|
|
139
|
+
});
|
|
140
|
+
assert.equal(result.signal,'SIGKILL');assert.equal(result.asked,true);
|
|
141
|
+
const state=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
142
|
+
const records=JSON.parse(fs.readFileSync(state,'utf8')).records;
|
|
143
|
+
assert.equal(records.at(-1).payload.type,'effect-intent');
|
|
144
|
+
assert.equal(records.some(row=>row.payload.type==='effect-checkpoint'),false);
|
|
145
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('split-root SwiftUI Claude control run creates a baseline beside Git-ignored Xcode and SwiftPM output',async()=>{
|
|
149
|
+
const f=fixture(),bridge=createHostToolBridge();
|
|
150
|
+
try{
|
|
151
|
+
const specs5=path.join(f.root,'specs5'),app=path.join(f.root,'app');
|
|
152
|
+
fs.renameSync(f.specsDir,specs5);fs.renameSync(f.codeProject,app);
|
|
153
|
+
fs.mkdirSync(path.join(app,'Sources'));fs.writeFileSync(path.join(app,'Sources','App.swift'),'import SwiftUI\n');
|
|
154
|
+
fs.writeFileSync(path.join(app,'.gitignore'),'custom-cache/\n');
|
|
155
|
+
assert.equal(spawnSync('git',['init','-q',app]).status,0);
|
|
156
|
+
fs.mkdirSync(path.join(app,'.build'));fs.symlinkSync('missing',path.join(app,'.build','workspace-state'));
|
|
157
|
+
fs.mkdirSync(path.join(app,'custom-cache'));fs.symlinkSync('missing',path.join(app,'custom-cache','linked'));
|
|
158
|
+
fs.mkdirSync(path.join(app,'DerivedData','Build'),{recursive:true});
|
|
159
|
+
for(let i=0;i<10005;i++)fs.writeFileSync(path.join(app,'DerivedData','Build',String(i)),'');
|
|
160
|
+
fs.mkdirSync(path.join(app,'App.xcodeproj','xcuserdata'),{recursive:true});
|
|
161
|
+
fs.writeFileSync(path.join(app,'App.xcodeproj','xcuserdata','UserInterfaceState.xcuserstate'),'bplist00');
|
|
162
|
+
fs.writeFileSync(path.join(app,'.DS_Store'),'finder');
|
|
163
|
+
const run=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
164
|
+
fs.writeFileSync(f.config,JSON.stringify({...run,specsDir:specs5,codeProject:app,scope:['Sources/App.swift']}));
|
|
165
|
+
const definition=readRunDefinition(f.config);
|
|
166
|
+
const execution=createConversationExecution(definition,'native-host-fixture',bridge,null,null,null,false,'claude');
|
|
167
|
+
const opened=await openControlRun(definition,'create',execution);
|
|
168
|
+
try{
|
|
169
|
+
const baseline=opened.runner?.baseline??JSON.parse(fs.readFileSync(path.join(specs5,'.reviews','.execution',identity.runId,'state.json'),'utf8')).records[0].payload.baseline;
|
|
170
|
+
assert(baseline.files.some(file=>file.path==='Sources/App.swift'));
|
|
171
|
+
assert(!baseline.files.some(file=>/\.build|DerivedData|xcuserdata|custom-cache|DS_Store/.test(file.path)));
|
|
172
|
+
}finally{opened.close();}
|
|
173
|
+
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('host create reports the offending unsupported file on stderr before transport starts',async()=>{
|
|
177
|
+
const f=fixture(),lines=[];
|
|
178
|
+
try{
|
|
179
|
+
fs.symlinkSync('missing',path.join(f.codeProject,'alien.swift'));
|
|
180
|
+
const exit=await hostMain(launchArgs(f),{input:{},output:{write(){}},error:{write(value){lines.push(value);}}});
|
|
181
|
+
assert.equal(exit,1);
|
|
182
|
+
assert.match(lines.join(''),/\[host\] unsupported_file: alien\.swift/);
|
|
183
|
+
assert.match(lines.join(''),/"reason":"unsupported_file: alien\.swift"/);
|
|
184
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
185
|
+
});
|
|
75
186
|
|
|
76
187
|
function runCli(f,mode,action='create'){
|
|
77
188
|
return new Promise((resolve,reject)=>{
|
|
78
|
-
const args=[...f
|
|
189
|
+
const args=[...launchArgs(f)];args[4]=action;
|
|
79
190
|
const child=spawn(process.execPath,[cli,...args],{stdio:['pipe','pipe','pipe'],env:f.env??process.env});
|
|
80
191
|
let buffer='',stderr='',closed=false,sessionId;const rows=[],calls=[];
|
|
81
|
-
|
|
192
|
+
// Provider children run in their own process groups: stopping only the host
|
|
193
|
+
// would orphan a hung fake reviewer, so failure and watchdog paths stop the
|
|
194
|
+
// whole fixture tree. f.watchdog(expire) may replace the timer; it returns a disarm function.
|
|
195
|
+
let disarm=()=>{};
|
|
196
|
+
const fail=error=>{
|
|
197
|
+
disarm();child.kill('SIGKILL');
|
|
198
|
+
try{killFixtureProcesses(f.root);}catch(cleanup){error=new AggregateError([error,cleanup],String(error?.message??error));}
|
|
199
|
+
reject(error);
|
|
200
|
+
};
|
|
201
|
+
disarm=(f.watchdog??(expire=>{const timer=setTimeout(expire,Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
202
|
+
return ()=>clearTimeout(timer);}))(()=>fail(new Error('host fixture timed out')));
|
|
82
203
|
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
83
204
|
child.once('error',reject);
|
|
84
205
|
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
@@ -166,10 +287,10 @@ function runCli(f,mode,action='create'){
|
|
|
166
287
|
closed=true;
|
|
167
288
|
if(mode!=='disconnect'||action==='resume')send({type:'host_close',sessionId});
|
|
168
289
|
}
|
|
169
|
-
}catch(error){
|
|
290
|
+
}catch(error){fail(error);return;}
|
|
170
291
|
}
|
|
171
292
|
});
|
|
172
|
-
child.once('close',code=>{
|
|
293
|
+
child.once('close',code=>{disarm();resolve({code,stderr,rows,calls});});
|
|
173
294
|
send(f.request??request('advance'));
|
|
174
295
|
});
|
|
175
296
|
}
|
|
@@ -789,7 +910,7 @@ function installTimeoutReviewer(f,runtime){
|
|
|
789
910
|
fs.renameSync(fake,delegate);
|
|
790
911
|
const modeFile=path.join(f.root,'review-mode.json');
|
|
791
912
|
fs.writeFileSync(modeFile,JSON.stringify('approved'));
|
|
792
|
-
fs.writeFileSync(fake,String.raw`#!${process.execPath}
|
|
913
|
+
fs.writeFileSync(fake,guardFixtureSource(String.raw`#!${process.execPath}
|
|
793
914
|
const fs=require('node:fs'),cp=require('node:child_process'),crypto=require('node:crypto');
|
|
794
915
|
const args=process.argv.slice(2),runtime=${JSON.stringify(runtime)},modeFile=${JSON.stringify(modeFile)};
|
|
795
916
|
if(args[0]==='sandbox'){const r=cp.spawnSync(${JSON.stringify(delegate)},args,{stdio:'inherit'});process.exit(r.status??1);}
|
|
@@ -811,9 +932,11 @@ let prompt='';process.stdin.on('data',s=>prompt+=s);process.stdin.on('end',()=>{
|
|
|
811
932
|
send({type:'result',subtype:'success',session_id:thread,is_error:false,num_turns:1,result:'{"verdict":"approved"}'});
|
|
812
933
|
}
|
|
813
934
|
}
|
|
935
|
+
// A hung reviewer announces its pid so the watchdog regression can find it.
|
|
936
|
+
fs.writeFileSync(modeFile+'.hung',String(process.pid));
|
|
814
937
|
setInterval(()=>{},1000);
|
|
815
938
|
});
|
|
816
|
-
|
|
939
|
+
`),{mode:0o700});
|
|
817
940
|
return mode=>fs.writeFileSync(modeFile,JSON.stringify(mode));
|
|
818
941
|
}
|
|
819
942
|
for(const [runtime,second] of [['codex','approved'],['claude','approved'],['codex','timeout'],['codex','result'],['claude','result']])
|
|
@@ -824,18 +947,22 @@ test(`protected conversation review timeout ${runtime} -> ${second}`,async()=>{
|
|
|
824
947
|
const setMode=installTimeoutReviewer(f,runtime);
|
|
825
948
|
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime',runtime],
|
|
826
949
|
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
827
|
-
const
|
|
950
|
+
const review=JSON.parse(preview.stdout);assert.equal(review.timeoutMs,900000);
|
|
951
|
+
delete review.timeoutMs;
|
|
952
|
+
const config=path.join(f.root,'review.json');fs.writeFileSync(config,JSON.stringify(review));
|
|
828
953
|
f.args.push('--review-config',config,'--allow-review-attempt','1');
|
|
829
954
|
f.develop=payload=>({status:'succeeded',value:implementedValue(),
|
|
830
955
|
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]});
|
|
831
956
|
setMode(second==='result'?'result':'timeout');
|
|
832
957
|
const start=Date.now(),first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
833
958
|
const result=first.rows.find(row=>row.requestId==='advance').result;
|
|
834
|
-
// A
|
|
959
|
+
// A legacy review config without timeoutMs inherits the protected conversation's 5s reviewer budget.
|
|
835
960
|
assert(Date.now()-start>=4900);assert(Date.now()-start<14000);
|
|
836
961
|
assert.equal(result.state,second==='result'?'unknown':'pending_review');
|
|
837
962
|
assert.equal(result.code,second==='result'?'transport_timeout':'review_transport_timeout');
|
|
838
|
-
|
|
963
|
+
// A final message cut off by the timeout is never retried by itself; its
|
|
964
|
+
// only exit is the explicit, audited abandon_review (see cm-ai-review-failure).
|
|
965
|
+
assert.equal(result.pendingAction,second==='result'?'abandon_review':'resume');
|
|
839
966
|
const before=lastCheckpoint(f),original=before.reviewInvocation;
|
|
840
967
|
assert.equal(before.calls.at(-1).terminal,second==='result'?'unknown':'failed');
|
|
841
968
|
assert.equal(original.result.outcome,'timed_out');
|
|
@@ -876,6 +1003,39 @@ test(`protected conversation review timeout ${runtime} -> ${second}`,async()=>{
|
|
|
876
1003
|
}
|
|
877
1004
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
878
1005
|
});
|
|
1006
|
+
// Regression (2026-09-28): a host stopped by the fixture watchdog while its
|
|
1007
|
+
// detached fake reviewer hung left that reviewer running for 17+ hours.
|
|
1008
|
+
test('fixture watchdog stopping a host mid-review leaves no process from the fixture root',async()=>{
|
|
1009
|
+
const f=protectedResultFixture();
|
|
1010
|
+
try{
|
|
1011
|
+
f.runtime='claude';f.args.push('--runtime','claude');
|
|
1012
|
+
const setMode=installTimeoutReviewer(f,'claude');
|
|
1013
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime','claude'],
|
|
1014
|
+
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
1015
|
+
// Keep the 15-minute reviewer budget: only the watchdog can end this review.
|
|
1016
|
+
const review=JSON.parse(preview.stdout);assert.equal(review.timeoutMs,900000);
|
|
1017
|
+
const config=path.join(f.root,'review.json');fs.writeFileSync(config,JSON.stringify(review));
|
|
1018
|
+
f.args.push('--review-config',config,'--allow-review-attempt','1');
|
|
1019
|
+
f.develop=payload=>({status:'succeeded',value:implementedValue(),
|
|
1020
|
+
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]});
|
|
1021
|
+
setMode('timeout');
|
|
1022
|
+
const hung=path.join(f.root,'review-mode.json.hung');
|
|
1023
|
+
// Fire as soon as the reviewer hangs, but never later than the usual
|
|
1024
|
+
// fixture deadline: a host stalled before review is a bounded failure.
|
|
1025
|
+
f.watchdog=expire=>{
|
|
1026
|
+
const poll=setInterval(()=>{if(fs.existsSync(hung)&&fs.readFileSync(hung,'utf8')){clearInterval(poll);expire();}},25);
|
|
1027
|
+
const limit=setTimeout(expire,Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
1028
|
+
return ()=>{clearInterval(poll);clearTimeout(limit);};
|
|
1029
|
+
};
|
|
1030
|
+
await assert.rejects(runCli(f,'normal'),/host fixture timed out/);
|
|
1031
|
+
assert(fs.existsSync(hung),'the host was stopped by the outer deadline before its reviewer hung');
|
|
1032
|
+
const reviewer=Number(fs.readFileSync(hung,'utf8'));assert(Number.isSafeInteger(reviewer)&&reviewer>1);
|
|
1033
|
+
const gone=()=>{try{process.kill(reviewer,0);return false;}catch(error){return error.code==='ESRCH';}};
|
|
1034
|
+
for(const deadline=Date.now()+3000;!gone()&&Date.now()<deadline;)await new Promise(resolve=>setTimeout(resolve,25));
|
|
1035
|
+
assert(gone(),`hung fake reviewer ${reviewer} survived the watchdog`);
|
|
1036
|
+
assert.deepEqual(fixtureProcesses(f.root),[]);
|
|
1037
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1038
|
+
});
|
|
879
1039
|
|
|
880
1040
|
test('new host refuses unapproved manifest bytes before any developer call',async()=>{
|
|
881
1041
|
const f=fixture();
|
|
@@ -1030,3 +1190,63 @@ test('F7 CLI explicitly revises missing QA commands after N5 and resumes the sam
|
|
|
1030
1190
|
assert.deepEqual(JSON.parse(fs.readFileSync(stateFile)),after);
|
|
1031
1191
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1032
1192
|
});
|
|
1193
|
+
|
|
1194
|
+
// Protected current-session driver answers (#10, #11, #31). These reach the real
|
|
1195
|
+
// Codex sandbox that applies protected edits, so they live in this excluded file.
|
|
1196
|
+
const protectedDriver=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
1197
|
+
function protectedDriveFixture({scope,files={},checkCommands=[{id:'noop',command:['/usr/bin/true']}]}){
|
|
1198
|
+
const f=fixture(),definition=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
1199
|
+
definition.scope=scope;fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
1200
|
+
for(const [file,content] of Object.entries(files)){
|
|
1201
|
+
fs.mkdirSync(path.dirname(path.join(f.codeProject,file)),{recursive:true});
|
|
1202
|
+
fs.writeFileSync(path.join(f.codeProject,file),content);fs.chmodSync(path.join(f.codeProject,file),0o644);
|
|
1203
|
+
}
|
|
1204
|
+
const answers=path.join(f.root,'answers');fs.mkdirSync(answers);
|
|
1205
|
+
fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands,timeoutMs:120000}));
|
|
1206
|
+
f.content=(name,bytes)=>fs.writeFileSync(path.join(answers,name),bytes);
|
|
1207
|
+
f.developAnswer=edits=>fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({status:'succeeded',
|
|
1208
|
+
value:implementedValue(),edits}));
|
|
1209
|
+
f.drive=(permissions=[],umask='022')=>{
|
|
1210
|
+
const plan=path.join(f.root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
1211
|
+
fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'create',hostContext:'native-host-fixture',
|
|
1212
|
+
permissions:['--protected-conversation-config','protection.json','--review-config',f.reviewFile,...permissions],answers:'answers'}));
|
|
1213
|
+
return spawnSync('/bin/sh',['-c',`umask ${umask}; exec "$0" "$@"`,process.execPath,protectedDriver,'--plan',plan,'advance'],
|
|
1214
|
+
{encoding:'utf8',timeout:120000,
|
|
1215
|
+
env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});
|
|
1216
|
+
};
|
|
1217
|
+
return f;
|
|
1218
|
+
}
|
|
1219
|
+
const lastPackageChanges=f=>new Map(lastCheckpoint(f).reviewPackage.changes.map(change=>[change.path,change]));
|
|
1220
|
+
test('#10 the driver carries a protected develop reply above 64 KiB once --input-limit is raised',()=>{
|
|
1221
|
+
const f=protectedDriveFixture({scope:['App.xcodeproj/project.pbxproj']});
|
|
1222
|
+
try{
|
|
1223
|
+
const content='// !$*UTF8*$!\n'+'\t\tA1D0000000000000000001 /* x */ = {isa = PBXBuildFile; };\n'.repeat(1500);
|
|
1224
|
+
f.content('pbxproj.txt',content);f.developAnswer({'App.xcodeproj/project.pbxproj':'pbxproj.txt'});
|
|
1225
|
+
const run=f.drive(['--input-limit','1048576']);
|
|
1226
|
+
assert.equal(run.signal,null,'driver waited on a rejected reply');assert.equal(run.status,0,run.stderr);
|
|
1227
|
+
assert.equal(JSON.parse(run.stdout).result.state,'awaiting_review',run.stdout);
|
|
1228
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'App.xcodeproj','project.pbxproj'),'utf8'),content);
|
|
1229
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1230
|
+
});
|
|
1231
|
+
test('#11 #31 protected driver deletes, sets the executable bit, creates new files 0644 and keeps BOM/CRLF text exact',()=>{
|
|
1232
|
+
const f=protectedDriveFixture({scope:['scripts/test.sh','old/Legacy.swift','new/Legacy.swift','App/Home.swift'],
|
|
1233
|
+
files:{'scripts/test.sh':'#!/bin/sh\necho TEST SUCCEEDED\n','old/Legacy.swift':'// legacy\n'},
|
|
1234
|
+
checkCommands:[{id:'test',command:['./scripts/test.sh']}]});
|
|
1235
|
+
try{
|
|
1236
|
+
const home=Buffer.from('import SwiftUI\r\nstruct Home {}\r\n','utf8');
|
|
1237
|
+
f.content('legacy.swift','// legacy\n');f.content('home.swift',home);
|
|
1238
|
+
f.developAnswer({'scripts/test.sh':{mode:'0755'},'old/Legacy.swift':{delete:true},
|
|
1239
|
+
'new/Legacy.swift':'legacy.swift','App/Home.swift':'home.swift'});
|
|
1240
|
+
const run=f.drive([],'077');
|
|
1241
|
+
assert.equal(run.status,0,run.stderr);assert.equal(JSON.parse(run.stdout).result.state,'awaiting_review',run.stdout);
|
|
1242
|
+
assert.equal(fs.statSync(path.join(f.codeProject,'scripts/test.sh')).mode&0o777,0o755);
|
|
1243
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'old/Legacy.swift')),false);
|
|
1244
|
+
assert.equal(fs.statSync(path.join(f.codeProject,'new/Legacy.swift')).mode&0o777,0o644);
|
|
1245
|
+
assert.equal(fs.statSync(path.join(f.codeProject,'App/Home.swift')).mode&0o777,0o644);
|
|
1246
|
+
assert.deepEqual(fs.readFileSync(path.join(f.codeProject,'App/Home.swift')),home);
|
|
1247
|
+
const changes=lastPackageChanges(f);
|
|
1248
|
+
assert.equal(changes.get('scripts/test.sh').before.mode,0o644);assert.equal(changes.get('scripts/test.sh').after.mode,0o755);
|
|
1249
|
+
assert.equal(changes.get('old/Legacy.swift').after,null);
|
|
1250
|
+
assert.equal(changes.get('new/Legacy.swift').after.mode,0o644);
|
|
1251
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1252
|
+
});
|