@aibyzero/cm-workflow 0.12.0 → 0.13.3
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 +1 -0
- package/CHANGELOG.md +60 -1
- package/README.md +36 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-runtime.md +3 -0
- package/docs/installation.md +58 -1
- package/docs/js-workflow-control.md +63 -6
- package/docs/runtime-failover.md +97 -0
- package/docs/user-guide.md +50 -1
- package/install-codex.sh +5 -0
- package/install.ps1 +10 -2
- package/install.sh +5 -0
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +151 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +69 -8
- package/runtime/js/cm-ai/claude-tool-preview.mjs +6 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +38 -16
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +44 -17
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +105 -12
- package/runtime/js/cm-ai/codex-config.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +6 -2
- package/runtime/js/cm-ai/developer-adapter.mjs +41 -16
- package/runtime/js/cm-ai/durable-runner-state.mjs +72 -15
- package/runtime/js/cm-ai/effect-contract.mjs +10 -1
- package/runtime/js/cm-ai/fix-code-association.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +112 -27
- package/runtime/js/cm-ai/host-documentation.mjs +4 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +17 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +6 -3
- package/runtime/js/cm-ai/host-role-routing.mjs +9 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +10 -7
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +9 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/provider-review-observation.mjs +8 -4
- package/runtime/js/cm-ai/qa-attachment.mjs +30 -0
- package/runtime/js/cm-ai/review-package.mjs +76 -18
- package/runtime/js/cm-ai/review-runner.mjs +15 -3
- package/runtime/js/cm-ai/runtime-failover.mjs +75 -0
- package/runtime/js/cm-ai/specification-material.mjs +98 -0
- package/runtime/js/cm-ai/task-runner.mjs +57 -20
- package/runtime/js/cm-ai/worker-claude-developer.mjs +174 -0
- package/runtime/js/cm-ai/worker-claude.mjs +18 -5
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -4
- package/runtime/js/cm-ai/worker-codex.mjs +8 -12
- package/runtime/js/cm-init/draft-generation.mjs +24 -4
- package/runtime/js/cm-init/draft-inspection.mjs +29 -1
- package/runtime/js/cm-prd/session.mjs +19 -2
- package/runtime/js/cm-prd/summary.mjs +46 -20
- package/runtime/review.md +11 -1
- package/runtime/workflow-config.md +39 -2
- package/runtime/workflow-routing.md +6 -1
- package/scripts/cm-ai-admission.test.mjs +99 -0
- package/scripts/cm-ai-batch-host.test.mjs +4 -1
- package/scripts/cm-ai-batch-run.test.mjs +7 -1
- package/scripts/cm-ai-bootstrap.test.mjs +9 -2
- package/scripts/cm-ai-fix-integration.test.mjs +2 -1
- package/scripts/cm-ai-host.mjs +81 -12
- package/scripts/cm-ai-host.test.mjs +527 -6
- package/scripts/cm-ai-multi-root.test.mjs +16 -4
- package/scripts/cm-ai-nested-execution.test.mjs +18 -5
- package/scripts/cm-ai-review-timeout.test.mjs +226 -0
- package/scripts/cm-ai-run.mjs +40 -13
- package/scripts/cm-ai-run.test.mjs +45 -9
- package/scripts/cm-check-host.test.mjs +8 -2
- package/scripts/cm-check-runtime.sh +51 -1
- package/scripts/cm-claude-developer-worker.test.mjs +236 -0
- package/scripts/cm-claude-probe.test.mjs +64 -1
- package/scripts/cm-claude-review-stream.test.mjs +236 -1
- package/scripts/cm-claude-worker.test.mjs +110 -1
- package/scripts/cm-codex-developer-adapter.test.mjs +50 -2
- package/scripts/cm-codex-developer-worker.test.mjs +84 -1
- package/scripts/cm-codex-review-progress.test.mjs +34 -6
- package/scripts/cm-failover.mjs +288 -0
- package/scripts/cm-failover.test.mjs +184 -0
- package/scripts/cm-fix-host-review.test.mjs +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +277 -0
- package/scripts/cm-host-tool-bridge.test.mjs +31 -0
- package/scripts/cm-init-draft-generation.test.mjs +62 -0
- package/scripts/cm-init-draft-inspection.test.mjs +76 -0
- package/scripts/cm-init-host.mjs +4 -4
- package/scripts/cm-init-host.test.mjs +12 -7
- package/scripts/cm-init-session.test.mjs +50 -0
- package/scripts/cm-log-event.mjs +34 -5
- package/scripts/cm-prd-completion.test.mjs +9 -3
- package/scripts/cm-prd-host.mjs +39 -3
- package/scripts/cm-prd-host.test.mjs +52 -0
- package/scripts/cm-prd-review-gate.mjs +11 -2
- package/scripts/cm-prd-review-gate.test.mjs +62 -0
- package/scripts/cm-prd-session-recovery.test.mjs +167 -0
- package/scripts/cm-prd-summary.test.mjs +147 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +10 -0
- package/scripts/cm-review-inventory.test.mjs +189 -0
- package/scripts/cm-review-schema.test.mjs +35 -1
- package/scripts/cm-review-scope-recovery.test.mjs +63 -0
- package/scripts/cm-runtime-edit.mjs +104 -0
- package/scripts/cm-runtime-failover.test.mjs +130 -0
- package/scripts/cm-runtime-i18n.mjs +32 -0
- package/scripts/cm-runtime-install.mjs +68 -0
- package/scripts/cm-runtime.mjs +141 -0
- package/scripts/cm-runtime.test.mjs +218 -0
- package/scripts/cm-spec-manifest.mjs +24 -21
- package/scripts/cm-spec-manifest.test.mjs +19 -0
- package/scripts/cm-workflow-config.mjs +113 -5
- package/scripts/cm-workflow-config.test.mjs +124 -1
- package/scripts/fixtures/prd-review-gate-python-oracle.py +18 -2
- package/scripts/test-cm-prd-review-gate.py +30 -0
- package/scripts/test-shell-compat.sh +34 -0
- package/scripts/validate-public-repo.py +5 -0
- package/skills/cm-ai/references/N4-review.md +5 -4
- package/skills/cm-ai/references/js-host.md +36 -2
- package/skills/cm-check/SKILL.md +7 -3
- package/skills/cm-init/SKILL.md +4 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-init/references/runtime-declaration.md +26 -0
- package/skills/cm-prd/SKILL.md +3 -3
- package/skills/cm-prd/references/js-change-recovery.md +24 -3
- package/skills/cm-prd/references/summary-card.md +7 -0
- package/skills/cm-runtime/SKILL.md +53 -0
- package/templates/auto-update/cm-update.sh +1 -1
- package/templates/cm-workflow.yml +16 -0
|
@@ -30,7 +30,7 @@ test('wrong session, tools, child agents, errors, repeated or incomplete termina
|
|
|
30
30
|
m=>{m[1].message.content=[{type:'tool_use',name:'Bash'}];},
|
|
31
31
|
m=>{m[1].parent_tool_use_id='child';},
|
|
32
32
|
m=>{m[2].is_error=true;},
|
|
33
|
-
m=>{m[2].num_turns=
|
|
33
|
+
m=>{m[2].num_turns=21;},
|
|
34
34
|
m=>{m[2].structured_output=null;},
|
|
35
35
|
m=>{m.push(m[2]);},
|
|
36
36
|
m=>{m.splice(1,1);},
|
|
@@ -43,3 +43,238 @@ test('wrong session, tools, child agents, errors, repeated or incomplete termina
|
|
|
43
43
|
assert.throws(()=>stream.finish(), {code:'incomplete_result'});
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
+
|
|
47
|
+
const thinkingTokens = () => ({type:'system',subtype:'thinking_tokens',session_id:'fresh-review',estimated_tokens:10});
|
|
48
|
+
const assistant = content => ({...transcript()[1],message:{role:'assistant',content}});
|
|
49
|
+
const tool = (id,name='StructuredOutput') => ({type:'tool_use',id,name,input:{}});
|
|
50
|
+
const toolResult = (id,is_error=false) => ({type:'user',session_id:'fresh-review',
|
|
51
|
+
message:{role:'user',content:[{type:'tool_result',tool_use_id:id,is_error,content:'synthetic result'}]}});
|
|
52
|
+
function decode(messages) {
|
|
53
|
+
const stream=createClaudeReviewStream(()=>{});
|
|
54
|
+
messages.forEach(m=>stream.accept(m));
|
|
55
|
+
return stream.finish();
|
|
56
|
+
}
|
|
57
|
+
test('thinking and redacted thinking preserve stage before and after substantive output',()=>{
|
|
58
|
+
const [init,text,result]=transcript();
|
|
59
|
+
const thoughts=assistant([{type:'thinking',thinking:'private',signature:'sig'},{type:'redacted_thinking',data:'private'}]);
|
|
60
|
+
assert.equal(decode([init,rateLimit(),thinkingTokens(),thinkingTokens(),thoughts,text,result]).status,'succeeded');
|
|
61
|
+
assert.equal(decode([init,...Array.from({length:4096},thinkingTokens),
|
|
62
|
+
assistant([...thoughts.message.content,...text.message.content]),thoughts,result]).status,'succeeded');
|
|
63
|
+
assert.throws(()=>decode([init,thoughts,result]),{code:'unexpected_result'});
|
|
64
|
+
assert.throws(()=>decode([init,...Array.from({length:4097},thinkingTokens),text,result]),{code:'unexpected_event'});
|
|
65
|
+
for(const subtype of ['unknown','init'])assert.throws(()=>decode([init,{...thinkingTokens(),subtype}]),{code:'unexpected_event'});
|
|
66
|
+
assert.throws(()=>decode([init,{...thinkingTokens(),session_id:'other'}]),{code:'session_mismatch'});
|
|
67
|
+
assert.throws(()=>decode([thinkingTokens(),init]),{code:'missing_init'});
|
|
68
|
+
assert.throws(()=>decode([init,text,result,thinkingTokens()]),{code:'unexpected_event'});
|
|
69
|
+
});
|
|
70
|
+
test('paired rejected tool attempts and CLI StructuredOutput permit multiple turns',()=>{
|
|
71
|
+
const [init,text,result]=transcript();
|
|
72
|
+
const calls=[];
|
|
73
|
+
for(let i=0;i<16;i++)calls.push(assistant([tool(`denied-${i}`,i%2?'Bash':'Read')]),toolResult(`denied-${i}`,true));
|
|
74
|
+
const wire=[init,text,...calls,assistant([{type:'thinking',thinking:'private'},tool('output')]),toolResult('output'),
|
|
75
|
+
{...result,num_turns:20,result:'not JSON: structured_output takes precedence'}];
|
|
76
|
+
assert.equal(decode(wire).status,'succeeded');
|
|
77
|
+
assert.equal(decode([init,assistant([tool('bash','Bash')]),toolResult('bash',true),{...result,num_turns:2}]).status,'succeeded');
|
|
78
|
+
assert.throws(()=>decode([init,...calls,assistant([tool('denied-17','Glob')])]),{code:'unexpected_tool_or_content'});
|
|
79
|
+
});
|
|
80
|
+
test('non-StructuredOutput success or ambiguous result fails immediately, including mixed tool batches',()=>{
|
|
81
|
+
for(const name of ['Bash','bash','Read','Grep','Glob','LS','structuredoutput'])for(const flag of [false,undefined,null,'true']){
|
|
82
|
+
const stream=createClaudeReviewStream(()=>{});
|
|
83
|
+
stream.accept(transcript()[0]);stream.accept(assistant([tool('output'),tool('bad',name)]));
|
|
84
|
+
stream.accept(toolResult('output'));
|
|
85
|
+
const result=toolResult('bad',flag);
|
|
86
|
+
if(flag===undefined)delete result.message.content[0].is_error;
|
|
87
|
+
assert.throws(()=>stream.accept(result),{code:'unexpected_tool_or_content'});
|
|
88
|
+
assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
test('tool identities, result contents and unresolved calls fail closed',()=>{
|
|
92
|
+
const [init,,result]=transcript();
|
|
93
|
+
for(const extra of [
|
|
94
|
+
[toolResult('missing',true)],
|
|
95
|
+
[assistant([tool('a')]),toolResult('wrong')],
|
|
96
|
+
[assistant([tool('a')]),toolResult('a'),toolResult('a')],
|
|
97
|
+
[assistant([tool('a'),tool('a','Bash')])],
|
|
98
|
+
[assistant([tool('a')]),toolResult('a'),assistant([tool('a','Bash')])],
|
|
99
|
+
[assistant([{type:'image'}])],
|
|
100
|
+
[assistant([null])],
|
|
101
|
+
[{...toolResult('a'),message:{role:'user',content:[{type:'text',text:'tool succeeded'}]}}],
|
|
102
|
+
[{...toolResult('a'),message:{role:'user',content:[]}}],
|
|
103
|
+
])assert.throws(()=>decode([init,...extra,result]),{code:'unexpected_tool_or_content'});
|
|
104
|
+
assert.throws(()=>decode([init,assistant([tool('pending')]),result]),{code:'unexpected_result'});
|
|
105
|
+
for(const num_turns of [0,-1,1.5,'2',21])assert.throws(()=>decode([...transcript().slice(0,2),{...result,num_turns}]),{code:'unexpected_result'});
|
|
106
|
+
for(const structured_output of [null,[],true,'{}'])assert.throws(()=>decode([
|
|
107
|
+
...transcript().slice(0,2),{...result,structured_output,result:'{"verdict":"approved"}'},
|
|
108
|
+
]),{code:'invalid_output_json'});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const rateLimit = (overrides={}) => ({type:'rate_limit_event',session_id:'fresh-review',
|
|
112
|
+
rate_limit_info:{status:'allowed',rateLimitType:'five_hour',resetsAt:123,active:true,reason:null,
|
|
113
|
+
nested:{text:'private provider payload'},list:['private provider payload']},...overrides});
|
|
114
|
+
const expectedNotice = {kind:'rate_limit',info:{status:'allowed',rateLimitType:'five_hour',
|
|
115
|
+
resetsAt:123,active:true,reason:null}};
|
|
116
|
+
test('rate limit notices preserve both output formats, stage and exact observer events',()=>{
|
|
117
|
+
const baseline=[],original=createClaudeReviewStream(e=>baseline.push(e));
|
|
118
|
+
transcript().forEach(m=>original.accept(m));
|
|
119
|
+
for(const structured of [true,false])for(const count of [1,8,32]){
|
|
120
|
+
const events=[],notices=[],stream=createClaudeReviewStream(e=>events.push(e),n=>notices.push(n));
|
|
121
|
+
const messages=transcript();
|
|
122
|
+
if(!structured){delete messages[2].structured_output;messages[2].result='{"verdict":"approved"}';}
|
|
123
|
+
stream.accept(messages[0]);
|
|
124
|
+
for(let i=0;i<count;i++){
|
|
125
|
+
if(i===1)stream.accept(messages[1]);
|
|
126
|
+
stream.accept(rateLimit());
|
|
127
|
+
}
|
|
128
|
+
if(count===1)stream.accept(messages[1]);
|
|
129
|
+
stream.accept(messages[2]);
|
|
130
|
+
assert.deepEqual(notices,Array.from({length:count},()=>expectedNotice));
|
|
131
|
+
assert.deepEqual(stream.finish(),original.finish());assert.deepEqual(events,baseline);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
test('optional or throwing notice callbacks and non-object info do not affect results',()=>{
|
|
135
|
+
for(const callback of [undefined,null,()=>{throw Error('notice consumer');}]){
|
|
136
|
+
const stream=createClaudeReviewStream(()=>{},callback),messages=transcript();
|
|
137
|
+
stream.accept(messages[0]);stream.accept(rateLimit());
|
|
138
|
+
messages.slice(1).forEach(m=>stream.accept(m));assert.equal(stream.finish().status,'succeeded');
|
|
139
|
+
}
|
|
140
|
+
for(const info of [undefined,null,'raw text',['raw text'],{bad:Infinity,missing:undefined}]){
|
|
141
|
+
const notices=[],stream=createClaudeReviewStream(()=>{},n=>notices.push(n));
|
|
142
|
+
stream.accept(transcript()[0]);stream.accept(rateLimit({rate_limit_info:info}));
|
|
143
|
+
assert.deepEqual(notices,[{kind:'rate_limit',info:{}}]);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
test('rate limit session, count, whitelist and terminal boundaries fail closed',()=>{
|
|
147
|
+
for(const [extra,code,count] of [
|
|
148
|
+
[[rateLimit({session_id:'other'})],'session_mismatch',0],
|
|
149
|
+
[[rateLimit({session_id:''})],'invalid_session',0],
|
|
150
|
+
[Array.from({length:33},()=>rateLimit()),'unexpected_event',32],
|
|
151
|
+
[[rateLimit({type:'foo_event'})],'unexpected_event',0],
|
|
152
|
+
]){
|
|
153
|
+
const notices=[],stream=createClaudeReviewStream(()=>{},n=>notices.push(n));
|
|
154
|
+
stream.accept(transcript()[0]);
|
|
155
|
+
assert.throws(()=>extra.forEach(m=>stream.accept(m)),{code});assert.equal(notices.length,count);
|
|
156
|
+
assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
157
|
+
}
|
|
158
|
+
const before=createClaudeReviewStream(()=>{});
|
|
159
|
+
assert.throws(()=>before.accept(rateLimit()),{code:'missing_init'});
|
|
160
|
+
const after=createClaudeReviewStream(()=>{});
|
|
161
|
+
transcript().forEach(m=>after.accept(m));
|
|
162
|
+
assert.throws(()=>after.accept(rateLimit()),{code:'unexpected_event'});
|
|
163
|
+
const noAssistant=createClaudeReviewStream(()=>{}),messages=transcript();
|
|
164
|
+
noAssistant.accept(messages[0]);noAssistant.accept(rateLimit());
|
|
165
|
+
assert.throws(()=>noAssistant.accept(messages[2]),{code:'unexpected_result'});
|
|
166
|
+
const noCallback=createClaudeReviewStream(()=>{});
|
|
167
|
+
noCallback.accept(messages[0]);
|
|
168
|
+
for(let i=0;i<32;i++)noCallback.accept(rateLimit());
|
|
169
|
+
assert.throws(()=>noCallback.accept(rateLimit()),{code:'unexpected_event'});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const systemNotice = (subtype='api_retry',extra={}) => ({type:'system',subtype,session_id:'fresh-review',...extra});
|
|
173
|
+
function observe(messages,callback) {
|
|
174
|
+
const events=[],notices=[];
|
|
175
|
+
const stream=createClaudeReviewStream(e=>events.push(e),callback ?? (n=>notices.push(n)));
|
|
176
|
+
messages.forEach(m=>stream.accept(m));
|
|
177
|
+
return {result:stream.finish(),events,notices};
|
|
178
|
+
}
|
|
179
|
+
test('88-heartbeat dogfood event counts preserve structured findings and exact observation',()=>{
|
|
180
|
+
const [init,text,result]=transcript();
|
|
181
|
+
const value={verdict:'changes_requested',packageDigest:'a'.repeat(64),examinedPaths:['code.mjs'],
|
|
182
|
+
findings:Array.from({length:6},(_,i)=>({id:`F${i+1}`,severity:'P2',path:'code.mjs',
|
|
183
|
+
message:'Synthetic finding',evidence:'Synthetic evidence'})),summary:'Synthetic six findings'};
|
|
184
|
+
// Reconstruct the observed event counts, without private provider text.
|
|
185
|
+
const wire=[init,...Array.from({length:44},thinkingTokens),rateLimit(),
|
|
186
|
+
assistant([{type:'thinking',thinking:'synthetic',signature:'sig'}]),
|
|
187
|
+
assistant([tool('denied','Read')]),toolResult('denied',true),
|
|
188
|
+
...Array.from({length:44},thinkingTokens),text,
|
|
189
|
+
assistant([tool('output')]),toolResult('output'),rateLimit(),
|
|
190
|
+
{...result,num_turns:4,structured_output:value,result:'structured output is authoritative'}];
|
|
191
|
+
const actual=observe(wire);
|
|
192
|
+
assert.deepEqual(actual.result,{status:'succeeded',value});
|
|
193
|
+
assert.deepEqual(actual.events,observe(transcript()).events);
|
|
194
|
+
assert.deepEqual(actual.notices,[expectedNotice,expectedNotice]);
|
|
195
|
+
});
|
|
196
|
+
test('thinking budget is cumulative across stages and cannot advance a verdict',()=>{
|
|
197
|
+
const [init,text,result]=transcript();
|
|
198
|
+
const half=Array.from({length:2048},thinkingTokens);
|
|
199
|
+
const actual=observe([init,...half,text,...half,result]);
|
|
200
|
+
assert.deepEqual(actual,observe(transcript()));
|
|
201
|
+
assert.throws(()=>decode([init,...half,text,...half,thinkingTokens(),result]),{code:'unexpected_event'});
|
|
202
|
+
assert.throws(()=>decode([init,...Array.from({length:4096},thinkingTokens),result]),{code:'unexpected_result'});
|
|
203
|
+
});
|
|
204
|
+
test('dogfood retry, thinking, StructuredOutput and rate limit sequence succeeds without extra observer events',()=>{
|
|
205
|
+
const [init,text,result]=transcript();
|
|
206
|
+
const actual=observe([init,systemNotice('api_retry',{attempt:1,max_retries:3,error_status:529,
|
|
207
|
+
retry_delay_ms:1000,error:'private error'}),thinkingTokens(),thinkingTokens(),text,
|
|
208
|
+
assistant([tool('output')]),toolResult('output'),rateLimit(),
|
|
209
|
+
{...result,result:'not JSON: structured_output is authoritative'}]);
|
|
210
|
+
const baseline=observe(transcript());
|
|
211
|
+
assert.deepEqual(actual.result,baseline.result);assert.deepEqual(actual.events,baseline.events);
|
|
212
|
+
assert.deepEqual(actual.notices,[{kind:'claude_system_notice',subtype:'api_retry',attempt:1,max_retries:3,error_status:529},expectedNotice]);
|
|
213
|
+
});
|
|
214
|
+
test('hook and commands notifications emit only allowlisted summaries at every nonterminal stage',()=>{
|
|
215
|
+
const [init,text,result]=transcript();
|
|
216
|
+
const subtypes=['hook_started','hook_response','commands_changed'];
|
|
217
|
+
const notices=subtypes.map(subtype=>systemNotice(subtype,{hook_name:'SessionStart:fixture',
|
|
218
|
+
output:'private output',stdout:'private stdout',stderr:'private stderr',commands:['private command'],
|
|
219
|
+
error:'private error',unknown:{verdict:'approved'}}));
|
|
220
|
+
const actual=observe([init,notices[0],text,assistant([tool('output')]),notices[1],toolResult('output'),notices[2],result]);
|
|
221
|
+
const baseline=observe(transcript());
|
|
222
|
+
assert.deepEqual(actual.result,baseline.result);assert.deepEqual(actual.events,baseline.events);
|
|
223
|
+
assert.deepEqual(actual.notices,subtypes.map(subtype=>({kind:'claude_system_notice',subtype,hook_name:'SessionStart:fixture'})));
|
|
224
|
+
for(const callback of [()=>{},()=>{throw Error('notice consumer');}]){
|
|
225
|
+
assert.deepEqual(observe([init,...notices,text,result],callback).result,baseline.result);
|
|
226
|
+
}
|
|
227
|
+
assert.deepEqual(decode([init,...notices,text,result]),baseline.result);
|
|
228
|
+
const malformed=observe([init,systemNotice('api_retry',{attempt:{text:'private'},max_retries:['private'],
|
|
229
|
+
error_status:Infinity,hook_name:{stdout:'private'}}),text,result]);
|
|
230
|
+
assert.deepEqual(malformed.notices,[{kind:'claude_system_notice',subtype:'api_retry'}]);
|
|
231
|
+
});
|
|
232
|
+
test('all system notices retain initialization, session, stage and terminal boundaries',()=>{
|
|
233
|
+
const [init,text,result]=transcript();
|
|
234
|
+
for(const subtype of ['api_retry','hook_started','hook_response','commands_changed']){
|
|
235
|
+
const notice=systemNotice(subtype);
|
|
236
|
+
assert.throws(()=>decode([notice,init,text,result]),{code:'missing_init'});
|
|
237
|
+
assert.throws(()=>decode([init,{...notice,session_id:'other'},text,result]),{code:'session_mismatch'});
|
|
238
|
+
assert.throws(()=>decode([init,{...notice,session_id:''},text,result]),{code:'invalid_session'});
|
|
239
|
+
assert.throws(()=>decode([init,notice,result]),{code:'unexpected_result'});
|
|
240
|
+
assert.throws(()=>decode([init,text,result,notice]),{code:'unexpected_event'});
|
|
241
|
+
assert.throws(()=>decode([init,notice]),{code:'incomplete_result'});
|
|
242
|
+
assert.throws(()=>decode([init,assistant([tool('bad','Bash')]),notice,toolResult('bad'),result]),{code:'unexpected_tool_or_content'});
|
|
243
|
+
}
|
|
244
|
+
for(const subtype of ['future_notice','API_RETRY','init',null,undefined]){
|
|
245
|
+
const notices=[],stream=createClaudeReviewStream(()=>{},n=>notices.push(n));
|
|
246
|
+
stream.accept(init);
|
|
247
|
+
assert.throws(()=>stream.accept({...systemNotice(),subtype}),{code:'unexpected_event'});
|
|
248
|
+
assert.deepEqual(notices,[]);
|
|
249
|
+
assert.throws(()=>stream.accept(systemNotice()),{code:'unexpected_event'});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
test('rate limit and system notices share exactly 32 slots independent of thinking and callbacks',()=>{
|
|
253
|
+
const [init,text,result]=transcript();
|
|
254
|
+
const kinds=['api_retry','hook_started','hook_response','commands_changed','rate_limit'];
|
|
255
|
+
for(const mixed of [false,true]){
|
|
256
|
+
const notices=Array.from({length:32},(_,i)=>mixed&&i%5===4?rateLimit():systemNotice(kinds[mixed?i%5:i%4]));
|
|
257
|
+
const actual=observe([init,...notices,...Array.from({length:4096},thinkingTokens),text,result]);
|
|
258
|
+
assert.equal(actual.notices.length,32);assert.deepEqual(actual.result,decode(transcript()));
|
|
259
|
+
for(const extra of [rateLimit(),systemNotice()])for(const callbackEnabled of [true,false]){
|
|
260
|
+
const received=[],stream=createClaudeReviewStream(()=>{},callbackEnabled?n=>received.push(n):null);
|
|
261
|
+
[init,...notices,text].forEach(m=>stream.accept(m));
|
|
262
|
+
assert.throws(()=>stream.accept(extra),{code:'unexpected_event'});
|
|
263
|
+
assert.equal(received.length,callbackEnabled?32:0);
|
|
264
|
+
assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
test('exhausted retries do not decide success or suppress provider failure',()=>{
|
|
269
|
+
const [init,text,result]=transcript();
|
|
270
|
+
for(const attempt of [3,4]){
|
|
271
|
+
const notice=systemNotice('api_retry',{attempt,max_retries:3,error_status:529});
|
|
272
|
+
assert.deepEqual(decode([init,notice,text,result]),decode(transcript()));
|
|
273
|
+
for(const failed of [{...result,subtype:'error_during_execution',is_error:true},{...result,is_error:true}]){
|
|
274
|
+
const notices=[],stream=createClaudeReviewStream(()=>{},n=>notices.push(n));
|
|
275
|
+
[init,notice,text].forEach(m=>stream.accept(m));
|
|
276
|
+
assert.equal(notices.length,1);
|
|
277
|
+
assert.throws(()=>stream.accept(failed),{code:'provider_failed'});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
@@ -3,7 +3,9 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import {EventEmitter} from 'node:events';
|
|
4
4
|
import {PassThrough} from 'node:stream';
|
|
5
5
|
import {spawn} from 'node:child_process';
|
|
6
|
-
import {
|
|
6
|
+
import {createHash} from 'node:crypto';
|
|
7
|
+
import {readFileSync} from 'node:fs';
|
|
8
|
+
import {claudeWorker,claudeReviewArgs,claudeReviewFingerprint,claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
7
9
|
|
|
8
10
|
const config={cwd:'/tmp',model:'claude-fixture',cli:'never-dispatch-real-cli'};
|
|
9
11
|
const receipt={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)};
|
|
@@ -13,6 +15,21 @@ const messages=[
|
|
|
13
15
|
message:{role:'assistant',content:[{type:'text',text:'review'}]}},
|
|
14
16
|
{type:'result',subtype:'success',session_id:'fresh-review',is_error:false,num_turns:1,result:'{"verdict":"approved"}'},
|
|
15
17
|
];
|
|
18
|
+
test('review schema is canonical without metadata and invalidates legacy preflight fingerprint',()=>{
|
|
19
|
+
const args=claudeReviewArgs(config.model),index=args.indexOf('--json-schema');
|
|
20
|
+
assert.ok(index>0);assert.equal(args.lastIndexOf('--json-schema'),index);
|
|
21
|
+
const expected=JSON.parse(readFileSync(new URL('../runtime/js/cm-ai/review-result.schema.json',import.meta.url),'utf8'));
|
|
22
|
+
delete expected.$schema;delete expected.$id;
|
|
23
|
+
const schema=JSON.parse(args[index+1]);assert.deepEqual(schema,expected);
|
|
24
|
+
assert.equal('$schema' in schema,false);assert.equal('$id' in schema,false);
|
|
25
|
+
// The schema changes the effective CLI configuration, so old diagnostic receipts must expire.
|
|
26
|
+
const legacyArgs=args.slice();legacyArgs.splice(index,2);
|
|
27
|
+
const legacy=createHash('sha256').update(JSON.stringify({cwd:config.cwd,cli:config.cli,args:legacyArgs,
|
|
28
|
+
environmentPolicy:1,promptTransport:'stdin'})).digest('hex');
|
|
29
|
+
assert.notEqual(claudeReviewFingerprint(config),legacy);
|
|
30
|
+
assert.equal(claudePreflightMatches({...receipt,config_fingerprint:legacy},config),false);
|
|
31
|
+
assert.equal(claudePreflightMatches(receipt,config),true);
|
|
32
|
+
});
|
|
16
33
|
function fake(action, observed) {
|
|
17
34
|
return (cli,args,options)=>{
|
|
18
35
|
observed.push({cli,args,options});
|
|
@@ -27,6 +44,84 @@ function fake(action, observed) {
|
|
|
27
44
|
return child;
|
|
28
45
|
};
|
|
29
46
|
}
|
|
47
|
+
const rateLimit=(overrides={})=>({type:'rate_limit_event',session_id:'fresh-review',
|
|
48
|
+
rate_limit_info:{status:'allowed',resetsAt:123,nested:{raw:'private'},list:['private']},...overrides});
|
|
49
|
+
test('successful forbidden tool triggers synchronous group SIGKILL without completion',async()=>{
|
|
50
|
+
const observed=[],events=[],kills=[];
|
|
51
|
+
const worker=claudeWorker({...config,preflight:receipt,
|
|
52
|
+
killProcess:(pid,signal)=>{kills.push({pid,signal});observed.at(-1).child.kill(signal);},
|
|
53
|
+
spawnProcess:fake(({child})=>{
|
|
54
|
+
const wire=[messages[0],{...messages[1],message:{role:'assistant',content:[{type:'tool_use',id:'bash-1',name:'Bash',input:{}}]}},
|
|
55
|
+
{type:'user',session_id:'fresh-review',message:{role:'user',content:[{type:'tool_result',tool_use_id:'bash-1',is_error:false}]}},
|
|
56
|
+
...messages.slice(1)];
|
|
57
|
+
child.stdout.write(wire.map(JSON.stringify).join('\n')+'\n');
|
|
58
|
+
assert.deepEqual(kills,[{pid:-12345,signal:'SIGKILL'}]);
|
|
59
|
+
},observed)});
|
|
60
|
+
const result=await worker({prompt:'synthetic'}, {signal:new AbortController().signal,onEvent:e=>events.push(e)});
|
|
61
|
+
assert.deepEqual(result,{status:'failed',code:'unexpected_tool_or_content'});
|
|
62
|
+
assert.ok(!events.some(e=>e.event==='turn.completed'||e.event==='item.completed'));
|
|
63
|
+
assert.equal(events.at(-1).signal,'SIGKILL');
|
|
64
|
+
});
|
|
65
|
+
async function runMessages(wireMessages,onNotice){
|
|
66
|
+
const observed=[],events=[];
|
|
67
|
+
const worker=claudeWorker({...config,preflight:receipt,onNotice,
|
|
68
|
+
killProcess:(_pid,signal)=>observed.at(-1).child.kill(signal),
|
|
69
|
+
spawnProcess:fake(({child,close})=>{
|
|
70
|
+
child.stdout.write(wireMessages.map(JSON.stringify).join('\n')+'\n');close(0,null);
|
|
71
|
+
},observed)});
|
|
72
|
+
const result=await worker({prompt:'synthetic-only'},
|
|
73
|
+
{signal:new AbortController().signal,onEvent:e=>events.push(e)});
|
|
74
|
+
return {result,events};
|
|
75
|
+
}
|
|
76
|
+
test('worker accepts 88 and 4096 thinking heartbeats but rejects 4097 without completion',async()=>{
|
|
77
|
+
const baseline=await runMessages(messages);
|
|
78
|
+
for(const count of [88,4096,4097]){
|
|
79
|
+
const notices=[],wire=[messages[0],...Array.from({length:count},()=>({
|
|
80
|
+
type:'system',subtype:'thinking_tokens',session_id:'fresh-review',estimated_tokens:10})),...messages.slice(1)];
|
|
81
|
+
const actual=await runMessages(wire,n=>notices.push(n));
|
|
82
|
+
assert.deepEqual(notices,[]);
|
|
83
|
+
if(count<=4096)assert.deepEqual(actual,baseline);
|
|
84
|
+
else{
|
|
85
|
+
assert.deepEqual(actual.result,{status:'failed',code:'unexpected_event'});
|
|
86
|
+
assert(!actual.events.some(e=>e.event==='turn.completed'||e.event==='item.completed'));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
test('thinking remains subject to the existing 1000000-byte total worker output cap',async()=>{
|
|
91
|
+
const heartbeat={type:'system',subtype:'thinking_tokens',session_id:'fresh-review',padding:''};
|
|
92
|
+
const wire=[messages[0],heartbeat,...messages.slice(1)];
|
|
93
|
+
const overhead=Buffer.byteLength(wire.map(JSON.stringify).join('\n')+'\n');
|
|
94
|
+
heartbeat.padding='x'.repeat(1_000_000-overhead);
|
|
95
|
+
assert.deepEqual(await runMessages(wire),await runMessages(messages));
|
|
96
|
+
heartbeat.padding+='x';
|
|
97
|
+
const actual=await runMessages(wire);
|
|
98
|
+
assert.deepEqual(actual.result,{status:'failed',code:'output_limit'});
|
|
99
|
+
assert(!actual.events.some(e=>e.event==='turn.completed'));
|
|
100
|
+
});
|
|
101
|
+
test('worker forwards scalar-only rate limit notices without changing results or observer events',async()=>{
|
|
102
|
+
const baseline=await runMessages(messages);
|
|
103
|
+
for(const count of [1,8,32]){
|
|
104
|
+
const notices=[],wire=[messages[0],...Array.from({length:count},()=>rateLimit()),...messages.slice(1)];
|
|
105
|
+
const actual=await runMessages(wire,n=>notices.push(n));
|
|
106
|
+
assert.deepEqual(actual,baseline);
|
|
107
|
+
assert.deepEqual(notices,Array.from({length:count},()=>({kind:'rate_limit',info:{status:'allowed',resetsAt:123}})));
|
|
108
|
+
assert.deepEqual(await runMessages(wire),baseline);
|
|
109
|
+
assert.deepEqual(await runMessages(wire,()=>{throw Error('notice consumer');}),baseline);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
test('worker rejects mismatched, excessive, unknown and terminal rate limit events',async()=>{
|
|
113
|
+
for(const [wire,code,count] of [
|
|
114
|
+
[[messages[0],rateLimit({session_id:'other'}),...messages.slice(1)],'session_mismatch',0],
|
|
115
|
+
[[messages[0],...Array.from({length:33},()=>rateLimit()),...messages.slice(1)],'unexpected_event',32],
|
|
116
|
+
[[messages[0],rateLimit({type:'foo_event'}),...messages.slice(1)],'unexpected_event',0],
|
|
117
|
+
[[rateLimit(),...messages],'missing_init',0],
|
|
118
|
+
[[...messages,rateLimit()],'unexpected_event',0],
|
|
119
|
+
]){
|
|
120
|
+
const notices=[],{result,events}=await runMessages(wire,n=>notices.push(n));
|
|
121
|
+
assert.deepEqual(result,{status:'failed',code});assert.equal(notices.length,count);
|
|
122
|
+
assert.ok(events.every(e=>['thread.started','turn.started','item.completed','turn.completed','process_closed'].includes(e.event)));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
30
125
|
test('single stdin dispatch maps actual close; prompt never enters argv; repeat refused',async()=>{
|
|
31
126
|
const observed=[],events=[],control={signal:new AbortController().signal,onEvent:e=>events.push(e)};
|
|
32
127
|
const worker=claudeWorker({...config,preflight:receipt,spawnProcess:fake(({child,close,input})=>{
|
|
@@ -90,3 +185,17 @@ test('timeout kills inherited-pipe descendants, including TERM-ignoring children
|
|
|
90
185
|
}
|
|
91
186
|
}
|
|
92
187
|
});
|
|
188
|
+
|
|
189
|
+
test('worker forwards system notice summaries without changing result or observation',async()=>{
|
|
190
|
+
const baseline=await runMessages(messages);
|
|
191
|
+
const subtypes=['api_retry','hook_started','hook_response','commands_changed'];
|
|
192
|
+
const wire=[messages[0],...subtypes.map(subtype=>({type:'system',subtype,session_id:'fresh-review',
|
|
193
|
+
output:'private output',stdout:'private stdout',stderr:'private stderr',commands:['private command']})),
|
|
194
|
+
rateLimit(),...messages.slice(1)];
|
|
195
|
+
const notices=[];
|
|
196
|
+
assert.deepEqual(await runMessages(wire,n=>notices.push(n)),baseline);
|
|
197
|
+
assert.deepEqual(notices,[...subtypes.map(subtype=>({kind:'claude_system_notice',subtype})),
|
|
198
|
+
{kind:'rate_limit',info:{status:'allowed',resetsAt:123}}]);
|
|
199
|
+
assert.deepEqual(await runMessages(wire),baseline);
|
|
200
|
+
assert.deepEqual(await runMessages(wire,()=>{throw Error('notice consumer');}),baseline);
|
|
201
|
+
});
|
|
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import {requestFor,terminalFor,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
4
4
|
import * as codex from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
5
5
|
import * as claude from '../runtime/js/cm-ai/claude-developer-adapter.mjs';
|
|
6
|
+
import {validateDeveloperValue} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
6
7
|
for(const [provider,createCodexDeveloperRun,buildCodexDeveloperPrompt] of [
|
|
7
8
|
['codex',codex.createCodexDeveloperRun,codex.buildCodexDeveloperPrompt],
|
|
8
9
|
['claude',claude.createClaudeDeveloperRun,claude.buildClaudeDeveloperPrompt],
|
|
@@ -36,7 +37,7 @@ test('invalid digest, role, model and cancelled input never reach worker',async(
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
test('provider ambiguity is unknown and is not retried',async()=>{
|
|
39
|
-
for(const response of [{status:'cancelled'},{status:'mystery'},null]){
|
|
40
|
+
for(const response of [{status:'cancelled'},{status:'mystery'},{status:'unknown',detail:undefined},null]){
|
|
40
41
|
let calls=0;const run=createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{calls++;return response;}});
|
|
41
42
|
// Invalid JSON terminal shape is also ambiguous, not successful.
|
|
42
43
|
const result=await run(request(),control());assert.equal(result.status,'unknown');assert.equal(calls,1);
|
|
@@ -58,10 +59,38 @@ test('host-owned instructions and workflow evidence never reach the developer',a
|
|
|
58
59
|
|
|
59
60
|
test('developer cannot return a completion envelope as implementation',async()=>{
|
|
60
61
|
const run=createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>({status:'succeeded',value:{outcome:'completed'}})});
|
|
61
|
-
await
|
|
62
|
+
const result=await run(request(),control());
|
|
63
|
+
assert.equal(result.status,'failed');assert.deepEqual(result.result,{code:'invalid_result',reason:'invalid_result'});
|
|
62
64
|
assert.throws(()=>buildCodexDeveloperPrompt(requestFor({...request(),payload:{...request().payload,scope:['../tasks.md']}})));
|
|
63
65
|
});
|
|
64
66
|
|
|
67
|
+
test('worker exceptions and timeout signals remain unknown',async()=>{
|
|
68
|
+
for(const code of ['execution_error','call_timeout']){
|
|
69
|
+
const run=createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{throw Object.assign(new Error(code),{code});}});
|
|
70
|
+
assert.equal((await run(request(),control())).status,'unknown');
|
|
71
|
+
}
|
|
72
|
+
const controller=new AbortController();
|
|
73
|
+
const run=createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{
|
|
74
|
+
controller.abort();return {status:'succeeded',value:{outcome:'implemented'}};
|
|
75
|
+
}});
|
|
76
|
+
assert.equal((await run(request(),{signal:controller.signal})).status,'unknown');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('local value shape and Learning contract failures are explicit invalid_result',async()=>{
|
|
80
|
+
const base=request(),feature='1.fixture',learningFiles=[];
|
|
81
|
+
const learningDigest=digest({version:1,feature,identity:base.identity,files:learningFiles});
|
|
82
|
+
const r=requestFor({...base,payload:{...base.payload,learningInput:{version:1,workflow:'cm-ai',
|
|
83
|
+
phase:'task_learning_input',feature,identity:base.identity,learningDigest,learningFiles}}});
|
|
84
|
+
const valid={outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
85
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
86
|
+
for(const value of [undefined,null,{}, {...valid,extra:true},{...valid,application:{status:'applied',note:null}},
|
|
87
|
+
{...valid,retrospective:{status:'no_new_lesson',candidates:[],reason:'No lesson'}}]){
|
|
88
|
+
const run=createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>({status:'succeeded',value})});
|
|
89
|
+
const result=await run(r,control());assert.equal(result.status,'failed');
|
|
90
|
+
assert.deepEqual(result.result,{code:'invalid_result',reason:'invalid_input'});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
65
94
|
test('explicit blocked implementation returns failure, never completion',async()=>{
|
|
66
95
|
const run=createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>({status:'succeeded',value:{outcome:'blocked'}})});
|
|
67
96
|
const result=await run(request(),control());
|
|
@@ -81,5 +110,24 @@ test('Learning observations use existing constructors for task-bound evidence',a
|
|
|
81
110
|
assert.deepEqual(result.application.identity,base.identity);
|
|
82
111
|
assert.equal(result.retrospective.feature,feature);
|
|
83
112
|
const {applicationDigest,...body}=result.application;assert.equal(applicationDigest,digest(body));
|
|
113
|
+
assert.throws(()=>validateDeveloperValue({outcome:'implemented',
|
|
114
|
+
application:{status:'no_relevant_lesson',note:null},
|
|
115
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:'No new lesson today'}},r),{code:'invalid_input'});
|
|
116
|
+
assert.throws(()=>validateDeveloperValue({outcome:'implemented',
|
|
117
|
+
application:{status:'no_relevant_lesson',note:null},
|
|
118
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
119
|
+
{...r,identity:{...r.identity,taskId:'T-002'}}),{code:'identity_mismatch'});
|
|
84
120
|
});
|
|
85
121
|
}
|
|
122
|
+
|
|
123
|
+
test('structured developer failures cannot broaden reviewer or unknown envelopes',()=>{
|
|
124
|
+
const r=requestFor({invocationId:'review-1',identity:{repositoryId:'test',runId:'run',taskId:'T-001',attempt:1},
|
|
125
|
+
role:'reviewer',provider:'codex',requestedModel:'fixture',contextId:'reviewer',payload:{}});
|
|
126
|
+
const raw={version:1,invocationId:r.invocationId,contextId:r.contextId,provider:r.provider,
|
|
127
|
+
effectiveModel:'unknown',status:'failed',accepted:true,result:{code:'invalid_result',reason:'invalid_input'}};
|
|
128
|
+
assert.throws(()=>terminalFor(raw,r));
|
|
129
|
+
const dev={...r,role:'developer'};
|
|
130
|
+
assert.throws(()=>terminalFor({...raw,status:'unknown'},dev));
|
|
131
|
+
assert.throws(()=>terminalFor({...raw,result:{...raw.result,retryable:true}},dev));
|
|
132
|
+
assert.throws(()=>terminalFor({...raw,result:{code:'made_up',reason:'invalid_input'}},dev));
|
|
133
|
+
});
|
|
@@ -33,10 +33,41 @@ test('coding argv enables tools without weakening reviewer argv',()=>{
|
|
|
33
33
|
const coding=developerArgs(options),review=commonArgs(options);
|
|
34
34
|
assert.equal(coding[coding.indexOf('--sandbox')+1],'workspace-write');
|
|
35
35
|
assert.equal(review[review.indexOf('--sandbox')+1],'read-only');
|
|
36
|
-
|
|
36
|
+
const values=(args,flag)=>args.flatMap((arg,i)=>arg===flag?[args[i+1]]:[]);
|
|
37
|
+
const reviewDisabled=values(review,'--disable'),codingDisabled=values(coding,'--disable');
|
|
38
|
+
for(const name of ['shell_tool','unified_exec','code_mode_host']){
|
|
39
|
+
assert(reviewDisabled.includes(name));assert(!codingDisabled.includes(name));
|
|
40
|
+
}
|
|
41
|
+
assert.deepEqual(codingDisabled,reviewDisabled.filter(name=>!['shell_tool','unified_exec','code_mode_host'].includes(name)));
|
|
42
|
+
assert.deepEqual(values(coding,'--enable'),['shell_tool','unified_exec']);
|
|
43
|
+
assert(!coding.includes('code_mode'));assert(!coding.includes('code_mode_host'));
|
|
44
|
+
assert(coding.includes('sandbox_workspace_write.network_access=false'));
|
|
37
45
|
assert.equal(coding.at(-1),'-');assert(!coding.includes('--dangerously-bypass-approvals-and-sandbox'));
|
|
38
46
|
});
|
|
39
47
|
|
|
48
|
+
test('coding and review argv both suppress the user skills catalog (2026-09-16: 18249 -> 11706 input tokens)',()=>{
|
|
49
|
+
const options={cwd:'/fixture',model:'fixture',schemaPath:'/schema.json'};
|
|
50
|
+
for(const args of [developerArgs(options),commonArgs(options)]){
|
|
51
|
+
const i=args.indexOf('skills.include_instructions=false');
|
|
52
|
+
assert(i>0,'skills.include_instructions=false missing');assert.equal(args[i-1],'-c');
|
|
53
|
+
assert.equal(args.filter(arg=>arg==='skills.include_instructions=false').length,1);
|
|
54
|
+
// Per-folder disables stay as the second defence; the catalog switch must precede them.
|
|
55
|
+
const config=args.findIndex(arg=>arg.startsWith('skills.config='));
|
|
56
|
+
assert(config>i);assert.equal(args[config-1],'-c');
|
|
57
|
+
assert(!args.some(arg=>/^skills\.max_context_tokens=/.test(arg)));
|
|
58
|
+
assert(!args.includes('skip_host_skill_discovery'));assert(!args.includes('--ignore-rules'));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('coding tool channel preserves the specs read-only permission profile',()=>fixture(async temp=>{
|
|
63
|
+
const cwd=fs.realpathSync(temp),specsRoot=path.join(cwd,'specs');fs.mkdirSync(specsRoot);
|
|
64
|
+
const args=developerArgs({cwd,specsRoot,model:'fixture',schemaPath:'/schema.json'});
|
|
65
|
+
assert(!args.includes('code_mode_host'));assert(!args.includes('code_mode'));
|
|
66
|
+
assert(!args.includes('--sandbox'));assert(args.includes('default_permissions="cm-specs"'));
|
|
67
|
+
assert(args.includes(`permissions.cm-specs={extends=":workspace",filesystem={${JSON.stringify(specsRoot)}="read",":workspace_roots"={"AGENTS.md"="read","CLAUDE.md"="read",".claude"="read"}},network={enabled=false}}`));
|
|
68
|
+
assert.deepEqual(args.flatMap((arg,i)=>arg==='--enable'?[args[i+1]]:[]),['shell_tool','unified_exec']);
|
|
69
|
+
}));
|
|
70
|
+
|
|
40
71
|
test('protected worker refuses a specs symlink substituted while awaiting dispatch',()=>fixture(async temp=>{
|
|
41
72
|
const cwd=fs.realpathSync(temp),specsRoot=path.join(cwd,'specs');fs.mkdirSync(specsRoot);
|
|
42
73
|
let calls=0;
|
|
@@ -126,3 +157,55 @@ test('cancellation kills a TERM-resistant descendant inheriting output pipes',()
|
|
|
126
157
|
assert.equal(fs.existsSync(path.join(cwd,'leaked.txt')),false);
|
|
127
158
|
}finally{try{process.kill(-child.pid,'SIGKILL');}catch{}}
|
|
128
159
|
}));
|
|
160
|
+
|
|
161
|
+
const startupNotices=[
|
|
162
|
+
'Code Mode is unavailable because code-mode host is disabled. Code mode will fail closed; enable `features.code_mode_host` and install `codex-code-mode-host`.',
|
|
163
|
+
'Skill descriptions were shortened to fit the skills context budget. '+ 'x'.repeat(200),
|
|
164
|
+
];
|
|
165
|
+
const noticeEvent=message=>({type:'item.completed',item:{type:'error',message,extra:'not retained'}});
|
|
166
|
+
const noticeStream=[{type:'thread.started',thread_id:'notice-fixture'},noticeEvent(startupNotices[0]),
|
|
167
|
+
{type:'turn.started'},noticeEvent(startupNotices[1])];
|
|
168
|
+
const completedStream=[{type:'item.completed',item:{type:'agent_message',text:'{"outcome":"implemented"}'}},
|
|
169
|
+
{type:'turn.completed'}];
|
|
170
|
+
for(const [name,events,code,expectedNotices=startupNotices,exitCode=0] of [
|
|
171
|
+
['startup notices',[...noticeStream,...completedStream],null],
|
|
172
|
+
['no notices',[noticeStream[0],noticeStream[2],...completedStream],null,[]],
|
|
173
|
+
['duplicate notice',[...noticeStream,noticeEvent(startupNotices[0]),...completedStream],null,[...startupNotices,startupNotices[0]]],
|
|
174
|
+
['changed notice',[...noticeStream,noticeEvent('different diagnostic'),...completedStream],null,[...startupNotices,'different diagnostic']],
|
|
175
|
+
['eight notices',[...noticeStream,...Array.from({length:6},()=>noticeEvent('extra')),...completedStream],null,[...startupNotices,...Array(6).fill('extra')]],
|
|
176
|
+
['ninth notice',[...noticeStream,...Array.from({length:7},()=>noticeEvent('extra')),...completedStream],'invalid_event',[...startupNotices,...Array(6).fill('extra')]],
|
|
177
|
+
['nonzero exit',[...noticeStream,...completedStream],'incomplete_result',startupNotices,1],
|
|
178
|
+
['top-level error',[...noticeStream,{type:'error',message:'fatal'},...completedStream],'provider_failed'],
|
|
179
|
+
['turn failed',[...noticeStream,{type:'turn.failed',error:{message:'fatal'}},...completedStream],'provider_failed'],
|
|
180
|
+
['unknown item',[...noticeStream,{type:'item.completed',item:{type:'future_item'}},...completedStream],'unexpected_tool_or_item'],
|
|
181
|
+
['unfinished error item',[...noticeStream,{type:'item.started',item:{type:'error',message:'unfinished'}},...completedStream],'unexpected_tool_or_item'],
|
|
182
|
+
['malformed notice',[...noticeStream,noticeEvent(null),...completedStream],'invalid_event'],
|
|
183
|
+
['notice before thread',[noticeEvent('early'),...noticeStream,...completedStream],'thread_missing',[]],
|
|
184
|
+
['notice after terminal',[...noticeStream,...completedStream,noticeEvent('late')],'invalid_event'],
|
|
185
|
+
['notice after failure',[...noticeStream,{type:'turn.failed'},noticeEvent('late'),...completedStream],'provider_failed'],
|
|
186
|
+
['notices without result',noticeStream,'incomplete_result'],
|
|
187
|
+
])test(`developer notice stream: ${name}`,()=>fixture(async cwd=>{
|
|
188
|
+
const emit=`process.stdin.resume();for(const row of ${JSON.stringify(events)})process.stdout.write(JSON.stringify(row)+'\\n');process.exitCode=${exitCode};`;
|
|
189
|
+
const notices=[];
|
|
190
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',learning:false,onNotice:message=>notices.push(message),
|
|
191
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',emit],options)});
|
|
192
|
+
const result=await worker({prompt:'synthetic'},{signal:new AbortController().signal});
|
|
193
|
+
if(code)assert.deepEqual(result,{status:'unknown',code});
|
|
194
|
+
else assert.deepEqual(result,{status:'succeeded',value:{outcome:'implemented'},providerThread:'notice-fixture'});
|
|
195
|
+
assert.deepEqual(notices,expectedNotices.map(x=>x.slice(0,200)));
|
|
196
|
+
assert(!JSON.stringify(result).includes('not retained'));
|
|
197
|
+
}));
|
|
198
|
+
|
|
199
|
+
for(const mode of ['omitted','non-function','throwing'])test(`developer notice callback: ${mode}`,()=>fixture(async cwd=>{
|
|
200
|
+
let calls=0;
|
|
201
|
+
const callbacks={omitted:{},'non-function':{onNotice:'ignored'},throwing:{onNotice(){calls++;throw Error('diagnostic sink failed');}}};
|
|
202
|
+
const events=[...noticeStream,...completedStream];
|
|
203
|
+
const emit=`process.stdin.resume();for(const row of ${JSON.stringify(events)})process.stdout.write(JSON.stringify(row)+'\\n');`;
|
|
204
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',learning:false,...callbacks[mode],
|
|
205
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',emit],options)});
|
|
206
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),
|
|
207
|
+
{status:'succeeded',value:{outcome:'implemented'},providerThread:'notice-fixture'});
|
|
208
|
+
assert.equal(calls,mode==='throwing'?2:0);
|
|
209
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),
|
|
210
|
+
{status:'unavailable',code:'worker_dispatch_limit'});
|
|
211
|
+
}));
|