@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
1
|
+
import test,{after} from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import {spawnSync} from 'node:child_process';
|
|
4
4
|
import fs from 'node:fs';
|
|
@@ -10,6 +10,15 @@ import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
|
10
10
|
import {openExecutionStore} from '../runtime/js/cm-ai/execution-store.mjs';
|
|
11
11
|
import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
|
|
12
12
|
|
|
13
|
+
// Never write the real ~/.cm-workflow home or its global log from this suite.
|
|
14
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-drive-home-'));
|
|
15
|
+
const savedHome={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
16
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedHome,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedHome,'logs');
|
|
17
|
+
after(()=>{
|
|
18
|
+
for(const [key,value] of Object.entries(savedHome)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
|
|
19
|
+
fs.rmSync(isolatedHome,{recursive:true,force:true});
|
|
20
|
+
});
|
|
21
|
+
|
|
13
22
|
// 驾驭员是宿主的中间人:开进程、发一条指令、代答反问、打结果。它的价值有两条要
|
|
14
23
|
// 拿真宿主验:确实能把一轮开起来并走下去;答案没备齐时停在发指令之前,不把运行做死。
|
|
15
24
|
const DRIVER=fileURLToPath(new URL('./cm-fix-drive.mjs',import.meta.url));
|
|
@@ -115,3 +124,29 @@ test('the driver abandons a local unknown step using only plan reason and flag',
|
|
|
115
124
|
assert.equal(JSON.parse(result.stdout).result.stage,'reproduce');
|
|
116
125
|
assert(JSON.parse(fs.readFileSync(statePath)).records.some(row=>row.id==='fix-abandoned-1'));
|
|
117
126
|
});
|
|
127
|
+
test('#15 the driver refuses abandon_review without plan reason and --allow-abandon-review before launching the host',{skip},t=>{
|
|
128
|
+
const f=fixture(t);
|
|
129
|
+
for(const plan of [f.plan({mode:'resume',permissions:[],reason:'Reviewer stopped',answers:undefined}),
|
|
130
|
+
f.plan({mode:'resume',permissions:['--allow-abandon'],reason:'Reviewer stopped',answers:undefined}),
|
|
131
|
+
f.plan({mode:'resume',permissions:['--allow-abandon-review'],answers:undefined})]){
|
|
132
|
+
const refused=drive(plan,'abandon_review');
|
|
133
|
+
assert.equal(refused.status,2);assert.match(refused.stderr,/abandon_review 需要 PLAN\.reason/);
|
|
134
|
+
}
|
|
135
|
+
assert.equal(fs.existsSync(path.join(f.archive,'.reviews')),false);
|
|
136
|
+
});
|
|
137
|
+
test('revision repair requires its own answer before launching the host',{skip},t=>{
|
|
138
|
+
const f=fixture(t);
|
|
139
|
+
fs.writeFileSync(path.join(f.answers,'learning.json'),JSON.stringify(learning));
|
|
140
|
+
fs.writeFileSync(path.join(f.answers,'diagnosis.json'),JSON.stringify(diagnosis));
|
|
141
|
+
assert.equal(drive(f.plan(),'advance').status,0);
|
|
142
|
+
const statePath=path.join(f.archive,'.reviews','.execution','drive-demo','state.json');
|
|
143
|
+
const state=JSON.parse(fs.readFileSync(statePath));
|
|
144
|
+
const store=openExecutionStore({specsRoot:f.archive,identity:state.identity,fingerprints:state.fingerprints,create:false});
|
|
145
|
+
store.append({id:'fix-revision-prepared',kind:'result',payload:{nextIdentity:{...state.identity,attempt:2}},
|
|
146
|
+
expectedRevision:store.snapshot().revision});store.close();
|
|
147
|
+
fs.writeFileSync(path.join(f.answers,'repair-edits.json'),JSON.stringify({'value.mjs':'repair.txt'}));
|
|
148
|
+
const before=fs.readFileSync(statePath);
|
|
149
|
+
const run=drive(f.plan({mode:'resume',permissions:['--allow-repair']}),'repair');
|
|
150
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/repair-edits-a2\.json/);
|
|
151
|
+
assert.deepEqual(fs.readFileSync(statePath),before);
|
|
152
|
+
});
|
package/scripts/cm-fix-host.mjs
CHANGED
|
@@ -6,12 +6,12 @@ import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
|
6
6
|
import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
|
|
7
7
|
import {createFixLearningPreparation} from '../runtime/js/cm-fix/learning.mjs';
|
|
8
8
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
9
|
-
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
9
|
+
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
10
10
|
import {id,json,need,shape,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
11
|
import {readConversationReviewConfiguration} from './cm-ai-host.mjs';
|
|
12
12
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
13
13
|
|
|
14
|
-
const usage='cm-fix-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-reproduction [--original-host-context ID] [--runtime codex|claude] [--review-config PATH] [--allow-cause-review] [--allow-final-review] [--allow-test-author] [--allow-red-test] [--allow-baseline] [--allow-repair] [--allow-regression] [--allow-learning-writeback]\nCodex or Claude current-host operations: prepare_revision, revision_test_check, advance, cause_review_package, cause_review, author_tests, red_test, baseline, repair, regression, retrospective, learning_writeback, handoff, final_review_package, final_review, publish_review, check_n5, post_review_regression, status, cancel. Runtime defaults to codex; claude uses its own matching diagnostic receipt and cannot reuse Codex preflight or disabledSkills settings. Runtime selection is bound to recovery; switching providers requires a separate run. This selects existing adapters, not permission to call them. Each write/check needs its respective launch flag and configuration. Test authoring, repair, cause and final review dispatch require matching existing stdin diagnostics; diagnostic alone is not authorization. Passing regression stops at handoff_required. The read-only retrospective operation yields handoff_ready or learning_writeback_required. learning_writeback requires its own flag, preserves project instructions and includes AGENTS.md in the review scope; it does not authorize provider calls. handoff publishes the fixed specs-local handoff with Learning evidence and moves to final_review_required; no provider is called and no task is completed. final_review_package is read-only and returns the final content-bound review package. final_review requires its own flag and matching diagnostics; observations do not complete the task. publish_review projects the registered result into the existing review file; it does not dispatch or complete tasks. check_n5 runs the original Learning-aware gate; post_review_regression requires --allow-regression and reaches closeout_required, not completion.';
|
|
14
|
+
const usage='cm-fix-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-reproduction [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--review-config PATH] [--allow-cause-review] [--allow-final-review] [--allow-test-author] [--allow-red-test] [--allow-baseline] [--allow-repair] [--allow-regression] [--allow-learning-writeback]\nCodex or Claude current-host operations: prepare_revision, revision_test_check, advance, cause_review_package, cause_review, author_tests, red_test, baseline, repair, regression, retrospective, learning_writeback, handoff, final_review_package, final_review, publish_review, check_n5, post_review_regression, status, cancel. Runtime defaults to codex; claude uses its own matching diagnostic receipt and cannot reuse Codex preflight or disabledSkills settings. Runtime selection is bound to recovery; switching providers requires a separate run. This selects existing adapters, not permission to call them. Each write/check needs its respective launch flag and configuration. Test authoring, repair, cause and final review dispatch require matching existing stdin diagnostics; diagnostic alone is not authorization. Passing regression stops at handoff_required. The read-only retrospective operation yields handoff_ready or learning_writeback_required. learning_writeback requires its own flag, preserves project instructions and includes AGENTS.md in the review scope; it does not authorize provider calls. handoff publishes the fixed specs-local handoff with Learning evidence and moves to final_review_required; no provider is called and no task is completed. final_review_package is read-only and returns the final content-bound review package. final_review requires its own flag and matching diagnostics; observations do not complete the task. publish_review projects the registered result into the existing review file; it does not dispatch or complete tasks. check_n5 runs the original Learning-aware gate; post_review_regression requires --allow-regression and reaches closeout_required, not completion.';
|
|
15
15
|
|
|
16
16
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr,reviewWorkerFactory=null}={}){
|
|
17
17
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Design-change escalation: approved cause_review reaches design_change_required when redTest is configured (test_author_required first if needed); author_tests/red_test keep their original flags and evidence checks. Confirmed red reaches escalation_required, never baseline/repair/regression. Non-visual runs without redTest reach escalation_required directly after approval and record why no failing test exists. Visual runs require a matching visual redTest with testFiles:[] and must complete the visual red step before escalation; opening without it fails with fix_visual_configuration_required. publish_dossier saves an 升级立项 dossier; finish requires --allow-finish, records run_done phase escalation/result escalated and closes the owner with escalationRunEnded:true. Retained tests become acceptance checks for the suggested $cm-prd --change. Resume the same run after a crash; conflicting exits fail with fix_escalation_exit_conflict. Terminal escalated is not completed: no task_done, metrics, repair or parent QA completion.\n');
|
|
@@ -20,6 +20,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
20
20
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('completion_evidence is read-only and available only after the original finish has completed and current evidence still validates. It returns the selected attempt, original reviewed package, handoff/review digests, completion event IDs and optional qaSource from the original owner. It does not complete or resume a parent task; JSON evidence alone is not authority.\n');
|
|
21
21
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('recover_final_review requires --allow-final-review-recovery and exact latest invocationId/packageDigest, previousInvocationStopped:true, and a nonempty reason. The legacy first continuation remains once-only. A further continuation additionally requires a fresh startup --final-review-recovery-invocation ID matching the latest unknown invocation, authorizing exactly one new call. Confirm the previous process stopped; this is a trusted host acknowledgment, not an automatic liveness check. Preparation dispatches nothing. Later final_review requires recovery permission and --allow-final-review; additional cycles require the same invocation binding after restart. Old records, task attempt, reviewed package and the original Review/N5/finish remain unchanged. No automatic retry, cancelled/complete-verdict recovery, missing-thread recovery, business-revision recovery or source-drift bypass. status adds a read-only progress projection, not authorization or current-source verification.\n');
|
|
22
22
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('abandon_step requires --allow-abandon, stage unknown, an eligible local pending kind, and a nonempty single-line reason up to 1000 UTF-8 bytes. It records the abandoned intent and returns to the required stage; a later separate action redoes the step. At most eight abandonments per run. Review, Learning writeback and handoff remain unavailable.\n');
|
|
23
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('abandon_review requires its own --allow-abandon-review flag (not --allow-abandon) and the same reason rules. Each run may abandon the cause review once and the second-round final review once, only while that registered review has no review result (interrupted, timed out, disconnected or cancelled); confirm the old reviewer stopped first. It records the abandoned invocation and returns to the review stage; the retry needs the original review flag, a fresh grant and a new reviewer thread. Reviews wait for the review configuration timeoutMs (default 900000), not the reproduction timeout.\n');
|
|
23
24
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('N6 child configuration may include qaSource {feature, identity, packageDigest, testRunId, handoffDigest}; derive the separate fixed child identity with qaFixIdentity. It requires --allow-qa-fix in addition to existing action flags. Close the parent host first: the original specs-wide owner lock is shared. Creation/resume rechecks the current failed round, project, report and policy; the source is bound to the original fix configuration. This does not resume the parent or automatically rerun QA, and does not authorize provider calls, installation or Git.\n');
|
|
24
25
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Second-round retrospective uses the cumulative original baseline, including previously authored tests and Learning scope. It persists the current round reflection and reaches revision_handoff_ready or revision_learning_writeback_required; neither state completes the task or publishes a new handoff. From revision_handoff_ready, handoff publishes a separate a2 handoff containing cumulative changes, current reflection, original red evidence and prior review/Learning history; final_review_package then reads that bound package. Pending Learning blocks publication. final_review requires --allow-final-review, uses fresh-thread exclusions and carries prior findings; publish_review writes the original r2 evidence and review log, and check_n5 runs the original Learning-aware gate. Approval reaches revision_post_review_regression_required, not completion.\n');
|
|
25
26
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('prepare_revision requires --allow-repair and either a published first-round changes_requested review or an approved first-round review followed by a package-bound walkthrough result of failed. The latter preserves the approved verdict and carries separate walkthrough failure evidence; passed, blocked, unknown, or drifted evidence cannot authorize this repair. An approved first-round review followed by package-bound post-review regression defect_remaining or regressed can also prepare the second repair when all baseline commands produced complete results. The regression commands must match the first reviewed handoff; passed, inconclusive, unavailable or partial evidence is refused. Regression and walkthrough failure feedback are mutually exclusive and neither replaces the next independent review. It rereads project Learning and persists the second-round preparation in the original store, preserving first-round evidence. repair then uses the original business scope and findings with separate second-round records. regression requires --allow-regression and reruns the original test commands against the second repair, preserving the original red evidence. Success reaches revision_handoff_required, not completion; handoff and final_review use the second-round package; review evidence publication and N5 are connected; post_review_regression requires --allow-regression and reaches revision_closeout_required after the original checks; walkthrough requires --allow-walkthrough and binds the second-round package and identity; finish reuses the original closeout with --allow-finish, preserving first-round history and recording completion for attempt 2. Second-round learning_writeback requires --allow-learning-writeback, includes the resulting AGENTS.md in the cumulative review package and preserves prior Learning history; pending or unknown writeback cannot advance to handoff. A lost repair or regression result stays unknown and is not redispatched.\n');
|
|
@@ -31,7 +32,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
31
32
|
need(['create','resume'].includes(argv[4]),'invalid_arguments');id(argv[6]);
|
|
32
33
|
const extra=new Map();
|
|
33
34
|
for(let index=8;index<argv.length;index++){
|
|
34
|
-
const flag=argv[index];need(!extra.has(flag)&&['--runtime','--review-config','--original-host-context','--final-review-recovery-invocation','--allow-qa-fix','--allow-cause-review','--allow-final-review','--allow-final-review-recovery','--allow-abandon','--allow-red-test','--allow-baseline','--allow-test-author','--allow-repair','--allow-regression','--allow-learning-writeback','--allow-walkthrough','--allow-finish'].includes(flag),'invalid_arguments');
|
|
35
|
+
const flag=argv[index];need(!extra.has(flag)&&['--runtime','--input-limit','--review-config','--original-host-context','--final-review-recovery-invocation','--allow-qa-fix','--allow-cause-review','--allow-final-review','--allow-final-review-recovery','--allow-abandon','--allow-abandon-review','--allow-red-test','--allow-baseline','--allow-test-author','--allow-repair','--allow-regression','--allow-learning-writeback','--allow-walkthrough','--allow-finish'].includes(flag),'invalid_arguments');
|
|
35
36
|
if(flag.startsWith('--allow-'))extra.set(flag,true);
|
|
36
37
|
else{need(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments');extra.set(flag,argv[++index]);}
|
|
37
38
|
}
|
|
@@ -43,6 +44,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
43
44
|
const recoveryInvocationId=extra.get('--final-review-recovery-invocation')??null;
|
|
44
45
|
if(recoveryInvocationId!==null){id(recoveryInvocationId);need(extra.has('--allow-final-review-recovery'),'fix_review_recovery_authorization_required');}
|
|
45
46
|
const runtime=extra.get('--runtime')??'codex';need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
47
|
+
// Transport only, like the cm-ai hosts: lines and tool replies share one limit.
|
|
48
|
+
const inputLimit=parseHostInputLimit(extra.get('--input-limit'));
|
|
46
49
|
const review=extra.has('--review-config')?readConversationReviewConfiguration(extra.get('--review-config')):null;
|
|
47
50
|
need(runtime!=='claude'||!review||review.disabledSkills.length===0,'invalid_review_config');
|
|
48
51
|
need(!extra.has('--allow-cause-review')||review!==null,'review_configuration_required');
|
|
@@ -66,7 +69,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
66
69
|
const {reviewer,authority,finalAuthority,execution:reviewExecution}=createFixReviewHost({
|
|
67
70
|
codeProject:config.reproduction.cwd,hostContextId:argv[6],runtime,review,
|
|
68
71
|
permissions:[...extra.keys()],workerFactory:reviewWorkerFactory});
|
|
69
|
-
bridge=createHostToolBridge();
|
|
72
|
+
bridge=createHostToolBridge({responseLimit:inputLimit});
|
|
70
73
|
owner=openFixExecution({specsRoot:config.specsRoot??null,identity:config.identity,create:argv[4]==='create',
|
|
71
74
|
hostContextId:argv[6],
|
|
72
75
|
configuration:{hostContextId:originalHostContext??argv[6],defect:config.defect,reproduction:config.reproduction,
|
|
@@ -86,12 +89,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
86
89
|
const host=createFixHost({owner,config,runtime,permissions:[...extra.keys(),'--allow-reproduction'],authority,finalAuthority,recoveryInvocationId});
|
|
87
90
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';
|
|
88
91
|
if(rawMode)input.setRawMode(true);
|
|
89
|
-
try{await serveCmAiHost({host,input,output,toolBridge:bridge});}
|
|
92
|
+
try{await serveCmAiHost({host,input,output,toolBridge:bridge,inputLimit});}
|
|
90
93
|
finally{if(rawMode)input.setRawMode(false);}
|
|
91
94
|
return 0;
|
|
92
95
|
}catch(cause){
|
|
93
96
|
const code=typeof cause?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)?cause.code:'fix_host_failed';
|
|
94
|
-
error.write(JSON.stringify({error:{code}})+'\n');return 1;
|
|
97
|
+
error.write(JSON.stringify({error:{code,...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;
|
|
95
98
|
}finally{bridge?.close();owner?.close();}
|
|
96
99
|
}
|
|
97
100
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// #15: cm-fix reviews wait for their own budget, record a timeout, and survive a
|
|
2
|
+
// host killed mid-review through one audited abandonment.
|
|
3
|
+
import test,{after} from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import {spawn} from 'node:child_process';
|
|
9
|
+
import {fileURLToPath} from 'node:url';
|
|
10
|
+
import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
11
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
12
|
+
import {createCauseReviewRun} from '../runtime/js/cm-ai/codex-review-adapter.mjs';
|
|
13
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
14
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
15
|
+
import {buildCmAiDriveRequest} from './cm-ai-drive.mjs';
|
|
16
|
+
|
|
17
|
+
const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-review-budget-'));
|
|
18
|
+
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
19
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
|
|
20
|
+
after(()=>{
|
|
21
|
+
for(const [key,value] of Object.entries(saved)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
|
|
22
|
+
fs.rmSync(isolated,{recursive:true,force:true});
|
|
23
|
+
});
|
|
24
|
+
const moduleUrl=relative=>new URL(relative,import.meta.url).href;
|
|
25
|
+
const identity={repositoryId:'fixture',runId:'cause-budget-run',taskId:'T-FIX-cause',attempt:1};
|
|
26
|
+
const reviewer={reviewerId:'cause-reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic',
|
|
27
|
+
contextId:'logical-review',excludedThreadIds:['other-author']};
|
|
28
|
+
const diagnosis={status:'diagnosed',rootCause:'Cross-layer constant',plan:'Correct after red test',affectedPaths:['value.mjs'],
|
|
29
|
+
affectedModules:['value'],crossLayer:true};
|
|
30
|
+
|
|
31
|
+
function fixture(){
|
|
32
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'run-')));
|
|
33
|
+
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
34
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
35
|
+
// The reproduction budget deliberately differs from the review budget below.
|
|
36
|
+
const options={specsRoot,identity,create:true,configuration:{hostContextId:'fixture-host',defect:'Synthetic value mismatch',causeReview:reviewer,
|
|
37
|
+
reproduction:{cwd,command:[process.execPath,'-e',"process.stderr.write('BUG');process.exit(3)"],
|
|
38
|
+
expectedFailure:{exitCode:3,outputIncludes:'BUG'},timeoutMs:3000}}};
|
|
39
|
+
const authority=createHostReviewAuthority({hostContextId:'fixture-host',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,
|
|
40
|
+
decide:async()=>({status:'approved'})});
|
|
41
|
+
const state={calls:0,hang:true};
|
|
42
|
+
const run=createCauseReviewRun(async({prompt},{onEvent})=>{
|
|
43
|
+
state.calls++;const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
44
|
+
onEvent({event:'thread.started',provider_thread:`fresh-review-${state.calls}`});
|
|
45
|
+
if(state.hang)return new Promise(()=>{});
|
|
46
|
+
for(const event of [{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
47
|
+
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
48
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,
|
|
49
|
+
examinedPaths:['value.mjs'],findings:[],summary:'No finding in synthetic package'}};
|
|
50
|
+
},'codex');
|
|
51
|
+
const statePath=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json');
|
|
52
|
+
return {root,cwd,specsRoot,options,authority,state,run,statePath,records:()=>JSON.parse(fs.readFileSync(statePath)).records,
|
|
53
|
+
bridge:{async call(){return diagnosis;}}};
|
|
54
|
+
}
|
|
55
|
+
async function decide(f,owner){
|
|
56
|
+
const pkg=owner.causeReviewPackage();
|
|
57
|
+
await f.authority.hostDecisionProvider.decide({identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test('#15 the cause review waits for its own budget, then records the timeout instead of stopping at unknown forever',async()=>{
|
|
61
|
+
const f=fixture(),causeReview={authorize:f.authority.authorize,run:f.run,timeoutMs:1000};
|
|
62
|
+
let owner=openFixExecution(f.options,{causeReview,bridge:f.bridge});
|
|
63
|
+
try{
|
|
64
|
+
assert.equal((await owner.advance({authorized:true})).stage,'cause_review_required');
|
|
65
|
+
await decide(f,owner);const started=Date.now();
|
|
66
|
+
const timedOut=await owner.reviewCause();
|
|
67
|
+
const elapsed=Date.now()-started;
|
|
68
|
+
assert(elapsed>=950&&elapsed<2500,`the review budget (1000 ms), not the reproduction budget (3000 ms), applies: ${elapsed}`);
|
|
69
|
+
assert.equal(timedOut.stage,'unknown');assert.equal(timedOut.pending,null);
|
|
70
|
+
assert.equal(timedOut.causeReview.code,'transport_timeout');assert.equal(timedOut.reviewAbandonable,'cause_review');
|
|
71
|
+
assert.deepEqual(f.records().map(row=>row.id).filter(id=>id.startsWith('fix-cause')),
|
|
72
|
+
['fix-cause-registered','fix-cause-started','fix-cause-result']);
|
|
73
|
+
owner.close();owner=openFixExecution({...f.options,create:false},{causeReview,bridge:f.bridge});
|
|
74
|
+
const result=f.records().find(row=>row.id==='fix-cause-result');
|
|
75
|
+
const abandoned=owner.abandonReview({authorized:true,reason:'Reviewer exceeded its budget and was stopped'});
|
|
76
|
+
assert.equal(abandoned.stage,'cause_review_required');
|
|
77
|
+
assert.equal(abandoned.causeReviewAbandonment.resultDigest.length,64);
|
|
78
|
+
assert.equal(abandoned.causeReviewAbandonment.providerThreadId,'fresh-review-1');
|
|
79
|
+
assert.notEqual(result,undefined);
|
|
80
|
+
f.state.hang=false;await decide(f,owner);
|
|
81
|
+
assert.equal((await owner.reviewCause()).stage,'red_test_required');assert.equal(f.state.calls,2);
|
|
82
|
+
}finally{owner.close();}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('#15 a host killed during the cause review leaves an abandonable registration, and the retry completes',async()=>{
|
|
86
|
+
const f=fixture();
|
|
87
|
+
// The child is a real separate host process: it registers and starts the
|
|
88
|
+
// review, then is killed before any result is written.
|
|
89
|
+
const child=spawn(process.execPath,['--input-type=module','-e',`
|
|
90
|
+
const {openFixExecution}=await import(${JSON.stringify(moduleUrl('../runtime/js/cm-fix/execution.mjs'))});
|
|
91
|
+
const {createHostReviewAuthority}=await import(${JSON.stringify(moduleUrl('../runtime/js/cm-ai/host-review-authority.mjs'))});
|
|
92
|
+
const {createCauseReviewRun}=await import(${JSON.stringify(moduleUrl('../runtime/js/cm-ai/codex-review-adapter.mjs'))});
|
|
93
|
+
const options=${JSON.stringify(f.options)},reviewer=options.configuration.causeReview;
|
|
94
|
+
const authority=createHostReviewAuthority({hostContextId:'fixture-host',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
95
|
+
const run=createCauseReviewRun(async(request,{onEvent})=>{onEvent({event:'thread.started',provider_thread:'killed-review'});
|
|
96
|
+
process.stdout.write('STARTED\\n');return new Promise(()=>{});},'codex');
|
|
97
|
+
const owner=openFixExecution(options,{causeReview:{authorize:authority.authorize,run,timeoutMs:600000},
|
|
98
|
+
bridge:{async call(){return ${JSON.stringify(diagnosis)};}}});
|
|
99
|
+
await owner.advance({authorized:true});const pkg=owner.causeReviewPackage();
|
|
100
|
+
await authority.hostDecisionProvider.decide({identity:options.identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
101
|
+
await owner.reviewCause();`],{env:process.env,stdio:['ignore','pipe','inherit']});
|
|
102
|
+
await new Promise((resolve,reject)=>{
|
|
103
|
+
child.stdout.on('data',chunk=>{if(String(chunk).includes('STARTED'))resolve();});
|
|
104
|
+
child.on('exit',code=>reject(new Error(`child exited early: ${code}`)));
|
|
105
|
+
});
|
|
106
|
+
const exited=new Promise(resolve=>child.on('exit',resolve));child.kill('SIGKILL');await exited;
|
|
107
|
+
assert.deepEqual(f.records().map(row=>row.id).filter(id=>id.startsWith('fix-cause')),['fix-cause-registered','fix-cause-started']);
|
|
108
|
+
f.state.hang=false;
|
|
109
|
+
const owner=openFixExecution({...f.options,create:false},{causeReview:{authorize:f.authority.authorize,run:f.run,timeoutMs:5000},bridge:f.bridge});
|
|
110
|
+
try{
|
|
111
|
+
const stuck=owner.status();
|
|
112
|
+
assert.equal(stuck.stage,'unknown');assert.equal(stuck.pending,'cause_review');assert.equal(stuck.reviewAbandonable,'cause_review');
|
|
113
|
+
assert.equal(owner.abandonReview({authorized:true,reason:'Host process was killed; reviewer confirmed gone'}).stage,'cause_review_required');
|
|
114
|
+
await decide(f,owner);
|
|
115
|
+
assert.equal((await owner.reviewCause()).stage,'red_test_required');
|
|
116
|
+
assert.equal(f.records().find(row=>row.id==='fix-cause-retry-started').payload.providerThreadId,'fresh-review-1');
|
|
117
|
+
}finally{owner.close();}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('#15 the shipped review host hands its review budget to the owner and the reviewer worker',()=>{
|
|
121
|
+
const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'host-')));
|
|
122
|
+
const review=timeoutMs=>({model:'synthetic',disabledSkills:[],...(timeoutMs?{timeoutMs}:{}),preflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',
|
|
123
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'synthetic',disabledSkills:[],promptTransport:'stdin'})}});
|
|
124
|
+
const seen=[];
|
|
125
|
+
const host=timeoutMs=>createFixReviewHost({codeProject,hostContextId:'host',review:review(timeoutMs),permissions:['--allow-cause-review'],
|
|
126
|
+
workerFactory:options=>{seen.push(options.timeoutMs);return async()=>({status:'failed',code:'unused'});}});
|
|
127
|
+
const configured=host(1234).execution;
|
|
128
|
+
assert.equal(configured.causeReview.timeoutMs,1234);assert.equal(configured.finalReview.timeoutMs,1234);
|
|
129
|
+
const defaulted=host(null).execution;
|
|
130
|
+
assert.equal(defaulted.causeReview.timeoutMs,900000);assert.equal(defaulted.finalReview.timeoutMs,900000);
|
|
131
|
+
// The worker is built with the budget before the adapter validates the request.
|
|
132
|
+
assert.throws(()=>configured.causeReview.run({},{signal:new AbortController().signal,onEvent:()=>true}),{code:'invalid_input'});
|
|
133
|
+
assert.deepEqual(seen,[1234]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('#15 the cm-ai driver forwards the QA-fix abandon_review reason inside fix_action',()=>{
|
|
137
|
+
const plan={packageDigest:'a'.repeat(64),testRunId:'qa-run',fixOperation:'abandon_review',reason:'Child reviewer stopped'};
|
|
138
|
+
const identity={repositoryId:'r',runId:'run',taskId:'T-1',attempt:1};
|
|
139
|
+
assert.deepEqual(buildCmAiDriveRequest('fix_action',plan,{identity}),{version:1,identity,packageDigest:plan.packageDigest,
|
|
140
|
+
testRunId:plan.testRunId,fixOperation:'abandon_review',reason:plan.reason});
|
|
141
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Guards for the test-only fixture process helper (2026-09-28: hung fake
|
|
2
|
+
// reviewers outlived their tests by 17+ hours).
|
|
3
|
+
import test from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
9
|
+
import {fixtureProcesses,guardFixtureSource,killFixtureProcesses,ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
10
|
+
|
|
11
|
+
const skip=process.platform==='win32';
|
|
12
|
+
const alive=pid=>{try{process.kill(pid,0);return true;}catch(error){return error.code!=='ESRCH';}};
|
|
13
|
+
async function until(predicate,ms=4000){
|
|
14
|
+
for(const deadline=Date.now()+ms;Date.now()<deadline;){if(predicate())return true;await new Promise(r=>setTimeout(r,25));}
|
|
15
|
+
return predicate();
|
|
16
|
+
}
|
|
17
|
+
function fixture(t){
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-fixture-process-')));
|
|
19
|
+
t.after(()=>{killFixtureProcesses(root);fs.rmSync(root,{recursive:true,force:true});});
|
|
20
|
+
return root;
|
|
21
|
+
}
|
|
22
|
+
const hang="process.on('SIGTERM',()=>{});setInterval(()=>{},1000);";
|
|
23
|
+
function readPid(child){
|
|
24
|
+
return new Promise((resolve,reject)=>{let out='';
|
|
25
|
+
child.stdout.on('data',b=>{out+=b;const m=out.match(/^(\d+)\n/);if(m)resolve(Number(m[1]));});
|
|
26
|
+
child.once('error',reject);child.once('close',code=>{if(!/^\d+\n/.test(out))reject(Error(`no pid: ${code}`));});});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('a guarded detached fixture dies with the test process that created it, even when TERM-resistant',{skip},async t=>{
|
|
30
|
+
const root=fixture(t),script=path.join(root,'hang.cjs');
|
|
31
|
+
// The owner stands in for a test process: it spawns the fixture detached, as
|
|
32
|
+
// the host under test does, then dies without any cleanup.
|
|
33
|
+
const owner=spawn(process.execPath,['--input-type=module','-e',`
|
|
34
|
+
import fs from 'node:fs';import {spawn,spawnSync} from 'node:child_process';
|
|
35
|
+
import {ownerGuardSource} from ${JSON.stringify(new URL('./fixtures/process-cleanup.mjs',import.meta.url).href)};
|
|
36
|
+
fs.writeFileSync(${JSON.stringify(script)},ownerGuardSource()+${JSON.stringify(hang)});
|
|
37
|
+
const c=spawn(process.execPath,[${JSON.stringify(script)}],{detached:true,stdio:'ignore'});c.unref();
|
|
38
|
+
process.stdout.write(c.pid+'\\n');setInterval(()=>{},1000);`],{stdio:['ignore','pipe','inherit']});
|
|
39
|
+
const pid=await readPid(owner);
|
|
40
|
+
assert.equal(fixtureProcesses(root).map(row=>row.pid).includes(pid),true);
|
|
41
|
+
await new Promise(r=>setTimeout(r,600));assert.equal(alive(pid),true,'guard must not stop a fixture while its owner lives');
|
|
42
|
+
owner.kill('SIGKILL');
|
|
43
|
+
assert.equal(await until(()=>!alive(pid)),true,`guarded fixture ${pid} outlived its owner`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('a guarded fixture stops at its lifetime ceiling while the owner lives',{skip},async t=>{
|
|
47
|
+
const root=fixture(t),script=path.join(root,'hang.cjs');
|
|
48
|
+
fs.writeFileSync(script,guardFixtureSource(`#!${process.execPath}\n${hang}`,{maxLifetimeMs:300}),{mode:0o700});
|
|
49
|
+
assert(fs.readFileSync(script,'utf8').startsWith(`#!${process.execPath}\n;(()=>{`));
|
|
50
|
+
const child=spawn(script,[],{stdio:'ignore'});
|
|
51
|
+
const closed=await new Promise(resolve=>child.once('close',(code,signal)=>resolve({code,signal})));
|
|
52
|
+
assert.deepEqual(closed,{code:null,signal:'SIGKILL'});
|
|
53
|
+
assert.throws(()=>ownerGuardSource({maxLifetimeMs:0}),/invalid_owner_guard/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('killFixtureProcesses removes a marked detached leader and its unmarked TERM-resistant descendant',{skip},async t=>{
|
|
57
|
+
const root=fixture(t),script=path.join(root,'leader.cjs');
|
|
58
|
+
fs.writeFileSync(script,`const c=require('node:child_process').spawn(process.execPath,['-e',${JSON.stringify(hang)}],{stdio:'ignore'});
|
|
59
|
+
process.stdout.write(c.pid+'\\n');${hang}`);
|
|
60
|
+
const leader=spawn(process.execPath,[script],{detached:true,stdio:['ignore','pipe','ignore']});
|
|
61
|
+
const descendant=await readPid(leader);
|
|
62
|
+
assert.equal(fixtureProcesses(root).some(row=>row.pid===descendant),false,'descendant carries no marker');
|
|
63
|
+
const killed=killFixtureProcesses(root);
|
|
64
|
+
assert.deepEqual(killed.map(row=>row.pid),[leader.pid]);
|
|
65
|
+
assert.equal(await until(()=>!alive(descendant)),true,'group kill must reach the descendant');
|
|
66
|
+
assert.deepEqual(fixtureProcesses(root),[]);
|
|
67
|
+
assert.throws(()=>fixtureProcesses('/tmp'),/invalid_fixture_marker/);
|
|
68
|
+
assert.throws(()=>fixtureProcesses('relative/fixture-root'),/invalid_fixture_marker/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('an unrelated process that merely names the fixture root survives, as does this test group',{skip},async t=>{
|
|
72
|
+
const root=fixture(t),log=path.join(root,'fixture.log');fs.writeFileSync(log,'');
|
|
73
|
+
// Double-fork via sh so these are no descendants of this test, like a user's
|
|
74
|
+
// own tail/grep of a fixture path or a node one-liner with the path as an argument.
|
|
75
|
+
const detach=command=>new Promise((resolve,reject)=>{
|
|
76
|
+
const sh=spawn('/bin/sh',['-c',`${command} >/dev/null 2>&1 </dev/null & echo $!`],{stdio:['ignore','pipe','ignore']});
|
|
77
|
+
let out='';sh.stdout.on('data',b=>out+=b);sh.once('error',reject);sh.once('close',()=>resolve(Number(out.trim())));
|
|
78
|
+
});
|
|
79
|
+
const q=value=>`'${value}'`;
|
|
80
|
+
const unrelated=[await detach(`/usr/bin/tail -f ${q(log)}`),
|
|
81
|
+
await detach(`${q(process.execPath)} -e ${q('setTimeout(()=>{},30000)')} ${q(log)}`)];
|
|
82
|
+
try{
|
|
83
|
+
for(const pid of unrelated)assert(Number.isSafeInteger(pid)&&alive(pid));
|
|
84
|
+
assert.equal(await until(()=>unrelated.every(pid=>fixtureProcesses(root).every(row=>row.pid!==pid)&&
|
|
85
|
+
spawnSync('ps',['-o','ppid=','-p',String(pid)],{encoding:'utf8'}).stdout.trim()==='1')),true);
|
|
86
|
+
assert.deepEqual(killFixtureProcesses(root),[]);
|
|
87
|
+
await new Promise(r=>setTimeout(r,300));
|
|
88
|
+
for(const pid of unrelated)assert.equal(alive(pid),true,`unrelated process ${pid} was killed`);
|
|
89
|
+
// A descendant of this test that carries the root is still taken, without touching this test's group.
|
|
90
|
+
const child=spawn(process.execPath,['-e','setInterval(()=>{},1000)',log],{stdio:'ignore'});
|
|
91
|
+
await until(()=>fixtureProcesses(root).some(row=>row.pid===child.pid));
|
|
92
|
+
assert.deepEqual(killFixtureProcesses(root).map(row=>row.pid),[child.pid]);
|
|
93
|
+
assert.equal(alive(process.pid),true);
|
|
94
|
+
}finally{for(const pid of unrelated)try{process.kill(pid,'SIGKILL');}catch{}}
|
|
95
|
+
});
|
|
@@ -8,9 +8,12 @@ import {captureReviewBaseline} from '../runtime/js/cm-ai/review-package.mjs';
|
|
|
8
8
|
import {createHostHandoff} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
9
9
|
import {loadHandoff,checkN4,checkN5} from './cm-task-gate.mjs';
|
|
10
10
|
import {developerArgs} from '../runtime/js/cm-ai/worker-codex-developer.mjs';
|
|
11
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
11
12
|
const identity={repositoryId:'test',runId:'run',taskId:'T-001',attempt:1};
|
|
12
13
|
const control=()=>({signal:new AbortController().signal});
|
|
13
14
|
const command=(id,code)=>({id,command:[process.execPath,'-e',code]});
|
|
15
|
+
// Hung checks die with this test process even if the host check never reaps them.
|
|
16
|
+
const hung=(id,code)=>command(id,ownerGuardSource()+code);
|
|
14
17
|
async function fixture(fn){const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-check-')));
|
|
15
18
|
try{await fn(root);}finally{fs.rmSync(root,{recursive:true,force:true});}}
|
|
16
19
|
|
|
@@ -37,7 +40,7 @@ test('host check evidence excludes credentials paths and timing output',()=>fixt
|
|
|
37
40
|
}));
|
|
38
41
|
|
|
39
42
|
test('async output capture rejects safely and waits for process cleanup',()=>fixture(async cwd=>{
|
|
40
|
-
const check=createHostCheck({cwd,commands:[
|
|
43
|
+
const check=createHostCheck({cwd,commands:[hung('capture',
|
|
41
44
|
"require('node:fs').writeFileSync('pid',String(process.pid));process.on('SIGTERM',()=>{});console.log('fixture');setInterval(()=>{},1000)")],
|
|
42
45
|
timeoutMs:3000,onOutput:async()=>{throw Error('synthetic capture failure');}});
|
|
43
46
|
const [result]=await check({identity},control());
|
|
@@ -78,7 +81,7 @@ for(const scenario of [
|
|
|
78
81
|
const baseline=captureReviewBaseline({root:cwd,identity,scope:['app.txt'],requirements:['requirements.md']});
|
|
79
82
|
fs.writeFileSync(path.join(cwd,'app.txt'),'after');
|
|
80
83
|
const security=scenario.name==='missing-tool'?{id:'security',command:[path.join(temp,'absent-scanner')]}:
|
|
81
|
-
command('security',scenario.name==='timeout'?'setInterval(()=>{},1000)':
|
|
84
|
+
(scenario.name==='timeout'?hung:command)('security',scenario.name==='timeout'?'setInterval(()=>{},1000)':
|
|
82
85
|
// Misleading success text must never override a nonzero exit code.
|
|
83
86
|
`console.log('PASS synthetic private scanner output');process.exit(${scenario.code})`);
|
|
84
87
|
const check=createHostCheck({cwd,timeoutMs:scenario.name==='timeout'?1000:5000,
|
|
@@ -128,7 +131,7 @@ test('native Codex profile allows business writes but protects specs for project
|
|
|
128
131
|
assert.equal(fs.readFileSync(path.join(cwd,'business.txt'),'utf8'),'allowed');
|
|
129
132
|
}));
|
|
130
133
|
test('cancelled check dispatches nothing and hung check is unavailable',()=>fixture(async cwd=>{
|
|
131
|
-
const check=createHostCheck({cwd,timeoutMs:50,commands:[
|
|
134
|
+
const check=createHostCheck({cwd,timeoutMs:50,commands:[hung('hang','setInterval(()=>{},1000)')]});
|
|
132
135
|
const ac=new AbortController();ac.abort();await assert.rejects(check({identity},{signal:ac.signal}),{code:'cancelled'});
|
|
133
136
|
const results=await check({identity},control());assert.equal(results[0].outcome,'unavailable');
|
|
134
137
|
assert.equal(results[0].evidence,'host check: timeout');
|