@aibyzero/cm-workflow 0.16.9 → 0.17.0
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/CHANGELOG.md +12 -0
- package/README.md +9 -1
- package/VERSION +1 -1
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +101 -84
- package/docs/next-steps.md +11 -0
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +3 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +3 -0
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +1 -24
- package/runtime/js/cm-ai/review-package.mjs +16 -4
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/task-runner.mjs +36 -99
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-refactor/workflow.mjs +1 -1
- package/runtime/js/notify-send.mjs +15 -14
- package/runtime/js/notify.mjs +27 -4
- package/runtime/js/policy-binding-compat.mjs +2 -1
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
- package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
- package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
- package/scripts/cm-ai-batch-drive.mjs +50 -31
- package/scripts/cm-ai-batch-drive.test.mjs +62 -19
- package/scripts/cm-ai-batch-host.mjs +39 -20
- package/scripts/cm-ai-batch-host.test.mjs +62 -38
- package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
- package/scripts/cm-ai-batch-run.mjs +34 -8
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +1 -8
- package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +43 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +6 -10
- package/scripts/cm-ai-host-fixture.mjs +38 -10
- package/scripts/cm-ai-host-protected.test.mjs +35 -33
- package/scripts/cm-ai-host.mjs +103 -93
- package/scripts/cm-ai-host.test.mjs +19 -18
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +4 -7
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +1 -2
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -3
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +3 -4
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +13 -19
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +15 -128
- package/scripts/cm-ai-run.mjs +78 -24
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +3 -10
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-worker.test.mjs +5 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +3 -9
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-review-recovery.test.mjs +1 -1
- package/scripts/cm-host-qa-executor.test.mjs +1 -2
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-notify-command.test.mjs +54 -18
- package/scripts/cm-notify-read-drift.test.mjs +69 -4
- package/scripts/cm-notify.mjs +16 -4
- package/scripts/cm-notify.test.mjs +91 -19
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +60 -12
- package/skills/cm-ai/references/js-host-recovery.md +95 -47
- package/skills/cm-ai/references/js-host.md +65 -28
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-init/references/js-host.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
|
@@ -142,13 +142,62 @@ const RUNTIME=new URL('../runtime/js/',import.meta.url);
|
|
|
142
142
|
// lines), side-effect imports and dynamic import() with a literal specifier.
|
|
143
143
|
// A dynamic import() with anything else as its argument is reported as
|
|
144
144
|
// `nonLiteral` so the test fails instead of silently missing a dependency.
|
|
145
|
+
// Lexes the source once: comments are dropped, and every string and regex
|
|
146
|
+
// literal is replaced by a numbered placeholder so that "import x from './y'"
|
|
147
|
+
// inside a string, a comment wedged between two strings, or a regex with quotes
|
|
148
|
+
// in it can neither hide nor fake an import. Template literals keep only their
|
|
149
|
+
// ${...} expressions, lexed the same way, so a dynamic import() inside one still
|
|
150
|
+
// counts. Specifiers are read back from the placeholder table.
|
|
151
|
+
const KEYWORDS=new Set(['return','typeof','instanceof','in','of','new','delete','void','throw','case','do','else','yield','await']);
|
|
152
|
+
function lex(source,start,literals,stopAtBrace){
|
|
153
|
+
let out='',i=start,depth=0;const n=source.length;
|
|
154
|
+
// A `/` starts a regex after an operator, an opener or a keyword; it is a
|
|
155
|
+
// division after a value (identifier, number, `)`, `]`, postfix `++`/`--`).
|
|
156
|
+
// After `}` the two cannot be told apart without parsing (block end vs object
|
|
157
|
+
// literal), so the scan fails loudly instead of guessing.
|
|
158
|
+
const regexAllowed=()=>{
|
|
159
|
+
const head=out.replace(/\s+$/,''),prev=head.slice(-1),word=/(?:^|[^\w$])([A-Za-z_$][\w$]*)$/.exec(head)?.[1];
|
|
160
|
+
if(prev==='}')throw new Error(`import scan: ambiguous "/" after "}" at offset ${i}; rewrite the source so the scanner can tell division from a regex`);
|
|
161
|
+
if(/\+\+$|--$/.test(head))return false;
|
|
162
|
+
return prev===''||/[(,=:\[!&|?{;+\-*%<>~^]/.test(prev)||KEYWORDS.has(word);
|
|
163
|
+
};
|
|
164
|
+
const push=(kind,text)=>{literals.push({kind,text});out+=kind==='string'?`"\u00a7${literals.length-1}\u00a7"`:'/\u00a7R\u00a7/';};
|
|
165
|
+
while(i<n){
|
|
166
|
+
const c=source[i],d=source[i+1];
|
|
167
|
+
if(c==='/'&&d==='/'){while(i<n&&source[i]!=='\n')i++;continue;}
|
|
168
|
+
if(c==='/'&&d==='*'){const close=source.indexOf('*/',i+2);i=close===-1?n:close+2;out+=' ';continue;}
|
|
169
|
+
if(c==="'"||c==='"'){
|
|
170
|
+
let j=i+1;while(j<n&&source[j]!==c&&source[j]!=='\n'){if(source[j]==='\\')j++;j++;}
|
|
171
|
+
push('string',source.slice(i+1,j));i=j+1;continue;
|
|
172
|
+
}
|
|
173
|
+
if(c==='`'){
|
|
174
|
+
out+='`';let j=i+1;
|
|
175
|
+
while(j<n&&source[j]!=='`'){
|
|
176
|
+
if(source[j]==='\\'){j+=2;continue;}
|
|
177
|
+
if(source[j]==='$'&&source[j+1]==='{'){const inner=lex(source,j+2,literals,true);out+='${'+inner.code+'}';j=inner.index+1;continue;}
|
|
178
|
+
j++;
|
|
179
|
+
}
|
|
180
|
+
out+='`';i=j+1;continue;
|
|
181
|
+
}
|
|
182
|
+
if(c==='/'&®exAllowed()){
|
|
183
|
+
let j=i+1,cls=false;
|
|
184
|
+
while(j<n){const ch=source[j];if(ch==='\\'){j+=2;continue;}if(ch==='\n')break;if(cls){if(ch===']')cls=false;}else if(ch==='[')cls=true;else if(ch==='/')break;j++;}
|
|
185
|
+
push('regex',source.slice(i+1,j));i=j+1;continue;
|
|
186
|
+
}
|
|
187
|
+
if(stopAtBrace){if(c==='{')depth++;else if(c==='}'){if(depth===0)return {code:out,index:i};depth--;}}
|
|
188
|
+
out+=c;i++;
|
|
189
|
+
}
|
|
190
|
+
return {code:out,index:i};
|
|
191
|
+
}
|
|
192
|
+
export function lexForImports(source){const literals=[];return {code:lex(source,0,literals,false).code,literals};}
|
|
145
193
|
export function scanImports(source){
|
|
146
|
-
const code=source
|
|
194
|
+
const {code,literals}=lexForImports(source);
|
|
195
|
+
const text=index=>literals[Number(index)].text;
|
|
147
196
|
const specifiers=[];
|
|
148
|
-
for(const m of code.matchAll(/\b(?:import|export)\b[^;
|
|
149
|
-
for(const m of code.matchAll(/\bimport\s*
|
|
197
|
+
for(const m of code.matchAll(/\b(?:import|export)\b[^;"`()]*?\bfrom\s*"\u00a7(\d+)\u00a7"/g))specifiers.push(text(m[1]));
|
|
198
|
+
for(const m of code.matchAll(/\bimport\s*"\u00a7(\d+)\u00a7"/g))specifiers.push(text(m[1]));
|
|
150
199
|
let literal=0;
|
|
151
|
-
for(const m of code.matchAll(/\bimport\s*\(\s*
|
|
200
|
+
for(const m of code.matchAll(/\bimport\s*\(\s*"\u00a7(\d+)\u00a7"\s*\)/g)){specifiers.push(text(m[1]));literal+=1;}
|
|
152
201
|
const nonLiteral=[...code.matchAll(/\bimport\s*\(/g)].length-literal;
|
|
153
202
|
return {specifiers,nonLiteral};
|
|
154
203
|
}
|
|
@@ -173,6 +222,22 @@ test('import scanner: multi-line static imports, dynamic import() with a literal
|
|
|
173
222
|
assert.equal(multi.nonLiteral,0);
|
|
174
223
|
assert.equal(scanImports('const m=await import(name);import(`./${x}.mjs`);import("./ok.mjs");').nonLiteral,2);
|
|
175
224
|
assert.equal(scanImports('console.log(import.meta.url);').nonLiteral,0);
|
|
225
|
+
// Literals cannot hide or fake an import: text inside strings, a block comment
|
|
226
|
+
// wedged between two strings, a line-end comment, a regex with quotes.
|
|
227
|
+
const tricky=scanImports(`const a='x'; /* import './hidden.mjs' */ const b="import z from './fake.mjs'";
|
|
228
|
+
const c=a+'y'; // import './tail.mjs'
|
|
229
|
+
const d=/['"]\\/import/.test(c); import real from './real.mjs';
|
|
230
|
+
const e=\`import './tpl.mjs' \${await import('./dyn.mjs')}\`;`);
|
|
231
|
+
assert.deepEqual(tricky.specifiers.sort(),['./dyn.mjs','./real.mjs']);assert.equal(tricky.nonLiteral,0);
|
|
232
|
+
assert.deepEqual(lexForImports(`'a' /* c */ 'b'`).literals.map(l=>l.text),['a','b']);
|
|
233
|
+
// Division is not a regex: postfix ++/--, a value or a closing paren before "/"
|
|
234
|
+
// must not swallow a later import on the same line (or inside a template).
|
|
235
|
+
for(const source of ['let n=1; n++ / 2; function later(){ return import("./late.mjs"); }',
|
|
236
|
+
'const q=(a+b)/2, r=a/b; import late from "./late.mjs";',
|
|
237
|
+
'const t=`${n-- / 2} ${await import("./late.mjs")}`;']){
|
|
238
|
+
const found=scanImports(source);assert.deepEqual(found.specifiers,['./late.mjs'],source);assert.equal(found.nonLiteral,0,source);
|
|
239
|
+
}
|
|
240
|
+
assert.throws(()=>scanImports('const o={a:1}/2; import("./x.mjs");'),/ambiguous "\/" after "}"/);
|
|
176
241
|
});
|
|
177
242
|
|
|
178
243
|
const importChild=(file,env={})=>spawnSync(process.execPath,['--input-type=module','-e',
|
package/scripts/cm-notify.mjs
CHANGED
|
@@ -397,20 +397,32 @@ export async function sendTest(home,{platform=process.platform,env=process.env,n
|
|
|
397
397
|
child.stdin.end(`${JSON.stringify({title,body,event:'test',workflow:'cm-notify'})}\n`);
|
|
398
398
|
});
|
|
399
399
|
appendNotifyLog(home,now,{event:'test',workflow:'cm-notify',result:result.exit===0?'test ok':`test failed ${result.exit===null?result.reason:`exit_${result.exit}`}`});
|
|
400
|
-
return {kind:config.state,channel,dry:false,exit:result.exit,reason:result.reason};
|
|
400
|
+
return {kind:config.state,channel,dry:false,exit:result.exit,reason:result.reason,...(config.state==='managed'?{senderCurrent:config.senderCurrent===true}:{})};
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
|
|
403
|
+
// Custom and legacy commands, and a managed sender copied by an older plugin,
|
|
404
|
+
// keep the original words: there 3 may also be a timeout and 5/6 mean nothing.
|
|
405
|
+
export const COMMAND_EXIT_WORDS=Object.freeze({
|
|
404
406
|
[SEND_EXIT.ok]:'已被推送服务接受(不代表已送达)',
|
|
405
407
|
[SEND_EXIT.config]:'配置或密钥问题',
|
|
406
408
|
[SEND_EXIT.network]:'网络失败或超时',
|
|
407
409
|
[SEND_EXIT.rejected]:'服务端拒绝',
|
|
408
410
|
});
|
|
411
|
+
// Only the managed sender identical to this plugin's copy splits 3/5/6.
|
|
412
|
+
export const EXIT_WORDS=Object.freeze({
|
|
413
|
+
...COMMAND_EXIT_WORDS,
|
|
414
|
+
[SEND_EXIT.network]:'网络请求失败',
|
|
415
|
+
[SEND_EXIT.deadline]:'超过 12 秒期限(可能已送达)',
|
|
416
|
+
[SEND_EXIT.unexpected]:'意外错误',
|
|
417
|
+
});
|
|
409
418
|
export function formatTest(result){
|
|
410
419
|
const who=result.kind==='custom'?'自定义命令':`渠道 ${result.channel}`;
|
|
411
420
|
if(result.dry)return `${who}:演练模式(CM_NOTIFY_DRY_RUN=1),没有运行发送命令、没有联网,也没有读取或检查密钥文件(是否填好请用 /cm:notify 查看);下面是按渠道设置生成的脱敏请求。\n${result.preview}`;
|
|
412
|
-
|
|
413
|
-
|
|
421
|
+
const stale=result.kind==='managed'&&result.senderCurrent!==true;
|
|
422
|
+
const hint=stale?`托管发送器与当前插件版本不同,退出码按旧含义解释;重新执行 /cm:notify ${result.channel} 更新。`:'';
|
|
423
|
+
if(result.exit===null)return `${who}:命令没有正常结束(${result.reason}),未知。${hint}`;
|
|
424
|
+
const words=result.kind==='managed'&&!stale?EXIT_WORDS:COMMAND_EXIT_WORDS;
|
|
425
|
+
return `${who}:退出码 ${result.exit},${words[result.exit]??'未知'}。${hint}`;
|
|
414
426
|
}
|
|
415
427
|
|
|
416
428
|
const USAGE='用法:cm-notify.mjs [status|bark|pushplus|off|test|preview] [--replace-custom] [--json]';
|
|
@@ -329,6 +329,78 @@ test('command failure, timeout and broken state never throw; they log one line w
|
|
|
329
329
|
for(const h of [failing,slow,missing,broken])assert(!/demo-app|T-001|核对|run-1/.test(h.log()));
|
|
330
330
|
});
|
|
331
331
|
|
|
332
|
+
// State and lock files are read bounded: a FIFO, a symlink (live or dangling)
|
|
333
|
+
// or an oversized file never blocks the host and never counts as valid state.
|
|
334
|
+
// FIFO cases run in a child with a hard deadline so a regression hangs the
|
|
335
|
+
// child, not the suite.
|
|
336
|
+
test('state and lock reads never block on a FIFO and refuse symlinks and oversized files',{skip:process.platform==='win32'},t=>{
|
|
337
|
+
const fifo=file=>{const made=spawnSync('mkfifo',[file]);assert.equal(made.status,0,`mkfifo ${file}`);};
|
|
338
|
+
const cases=[
|
|
339
|
+
['state FIFO',h=>fifo(path.join(h.dir,'notify-state.json')),'state_invalid',true],
|
|
340
|
+
['state symlink',h=>{fs.writeFileSync(path.join(h.dir,'real.json'),JSON.stringify({version:1,keys:{},sends:[]}));fs.symlinkSync(path.join(h.dir,'real.json'),path.join(h.dir,'notify-state.json'));},'state_invalid'],
|
|
341
|
+
['state dangling symlink',h=>fs.symlinkSync(path.join(h.dir,'missing.json'),path.join(h.dir,'notify-state.json')),'state_invalid'],
|
|
342
|
+
['state oversized',h=>fs.writeFileSync(path.join(h.dir,'notify-state.json'),JSON.stringify({version:1,keys:{},sends:[],pad:'x'.repeat(300*1024)})),'state_invalid'],
|
|
343
|
+
['lock FIFO',h=>fifo(path.join(h.dir,'notify-state.lock')),'state_busy',true],
|
|
344
|
+
['lock symlink',h=>{fs.writeFileSync(path.join(h.dir,'real.lock'),JSON.stringify({pid:process.pid,at:Date.now()-60000,token:'old'}));fs.symlinkSync(path.join(h.dir,'real.lock'),path.join(h.dir,'notify-state.lock'));},'state_busy'],
|
|
345
|
+
['lock dangling symlink',h=>fs.symlinkSync(path.join(h.dir,'missing.lock'),path.join(h.dir,'notify-state.lock')),'state_busy'],
|
|
346
|
+
];
|
|
347
|
+
for(const [name,arrange,reason,inChild=false] of cases){
|
|
348
|
+
const h=home(t);arrange(h);const listing=()=>fs.readdirSync(h.dir).filter(name=>name!=='notify.log').sort(),before=listing();
|
|
349
|
+
let result;
|
|
350
|
+
if(inChild){
|
|
351
|
+
const child=spawnSync(process.execPath,['--input-type=module','-e',
|
|
352
|
+
`import {notify} from ${JSON.stringify(NOTIFY_URL)};process.stdout.write(JSON.stringify(notify(${JSON.stringify(fields('f'))},{now:${NOW}})));`],
|
|
353
|
+
{encoding:'utf8',timeout:5000,env:h.env});
|
|
354
|
+
assert.equal(child.signal,null,`${name}: bounded read must not block (child killed by ${child.signal})`);
|
|
355
|
+
assert.equal(child.status,0,`${name}: ${child.stderr}`);result=JSON.parse(child.stdout);
|
|
356
|
+
}else result=notify(fields('f'),{env:h.env,now:NOW});
|
|
357
|
+
assert.deepEqual(result,{sent:false,reason},name);
|
|
358
|
+
assert.equal(h.rows().length,0,name);
|
|
359
|
+
// Nothing but the log is written through or beside the refused entry.
|
|
360
|
+
assert.deepEqual(listing(),before,name);assert.match(h.log(),new RegExp(`skipped ${reason}`),name);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// Where O_NOFOLLOW is 0 (Windows), the open flags no longer refuse a symlink;
|
|
365
|
+
// only the lstat check before the open does. The child masks O_NOFOLLOW out of
|
|
366
|
+
// every open before the runtime loads (and proves the mask by opening a probe
|
|
367
|
+
// link that an unmasked open would refuse) and records every path opened, so
|
|
368
|
+
// the refusal is shown to happen before any open of the link: a build that
|
|
369
|
+
// first opens and only then notices the link goes red on every platform, not
|
|
370
|
+
// only in a Windows job. The link itself and its target are snapshotted so a
|
|
371
|
+
// same-name replacement or a rewritten target cannot hide behind a name list.
|
|
372
|
+
test('state and lock symlinks are refused before open when O_NOFOLLOW is masked (Windows semantics)',t=>{
|
|
373
|
+
const cases=[
|
|
374
|
+
['state symlink','notify-state.json','real.json',JSON.stringify({version:1,keys:{},sends:[]}),'state_invalid'],
|
|
375
|
+
['lock symlink','notify-state.lock','real.lock',JSON.stringify({pid:process.pid,at:Date.now()-60000,token:'old'}),'state_busy'],
|
|
376
|
+
];
|
|
377
|
+
for(const [name,linkName,targetName,targetBody,reason] of cases){
|
|
378
|
+
const h=home(t),link=path.join(h.dir,linkName),target=path.join(h.dir,targetName);
|
|
379
|
+
try{fs.writeFileSync(target,targetBody);fs.symlinkSync(target,link);fs.writeFileSync(path.join(h.dir,'probe.txt'),'probe');fs.symlinkSync(path.join(h.dir,'probe.txt'),path.join(h.dir,'probe.link'));}
|
|
380
|
+
catch(error){if(process.platform==='win32'&&error.code==='EPERM'){t.skip('symlink creation needs a privilege on this Windows host');return;}throw error;}
|
|
381
|
+
const snapshot=()=>({names:fs.readdirSync(h.dir).filter(name=>name!=='notify.log').sort(),isLink:fs.lstatSync(link).isSymbolicLink(),points:fs.readlinkSync(link),target:fs.readFileSync(target,'utf8')});
|
|
382
|
+
const before=snapshot();
|
|
383
|
+
const child=spawnSync(process.execPath,['--input-type=module','-e',
|
|
384
|
+
`import fs from 'node:fs';import path from 'node:path';const open=fs.openSync,opened=[];
|
|
385
|
+
fs.openSync=(file,flags,...rest)=>{opened.push(path.resolve(String(file)));return open(file,typeof flags==='number'?flags&~fs.constants.O_NOFOLLOW:flags,...rest);};
|
|
386
|
+
const probe=fs.openSync(${JSON.stringify(path.join(h.dir,'probe.link'))},fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
387
|
+
const followed=fs.readFileSync(probe,'utf8');fs.closeSync(probe);
|
|
388
|
+
const {notify}=await import(${JSON.stringify(NOTIFY_URL)});
|
|
389
|
+
const result=notify(${JSON.stringify(fields('f'))},{now:${NOW}});
|
|
390
|
+
process.stdout.write(JSON.stringify({followed,result,opened}));`],
|
|
391
|
+
{encoding:'utf8',timeout:5000,env:h.env});
|
|
392
|
+
assert.equal(child.status,0,`${name}: ${child.stderr}`);
|
|
393
|
+
const {followed,result,opened}=JSON.parse(child.stdout);
|
|
394
|
+
assert.equal(followed,'probe',`${name}: the masked open must follow links like a Windows open`);
|
|
395
|
+
assert.ok(opened.includes(path.join(h.dir,'probe.link')),`${name}: the open recorder must see the probe open`);
|
|
396
|
+
assert.ok(!opened.includes(link),`${name}: the link must be refused before any open of it (opened: ${opened.join(', ')})`);
|
|
397
|
+
assert.ok(!opened.includes(target),`${name}: the link target must never be opened`);
|
|
398
|
+
assert.deepEqual(result,{sent:false,reason},name);
|
|
399
|
+
assert.equal(h.rows().length,0,name);
|
|
400
|
+
assert.deepEqual(snapshot(),before,name);assert.match(h.log(),new RegExp(`skipped ${reason}`),name);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
332
404
|
// Lock contention never waits; only a provably stale lock is reclaimed, and
|
|
333
405
|
// a live lock is never removed.
|
|
334
406
|
test('lock: a live lock skips at once and is kept; a stale lock is reclaimed safely',async t=>{
|
|
@@ -590,48 +662,48 @@ await serveCmAiHost({host,input:process.stdin,output:process.stdout});`);
|
|
|
590
662
|
const op=(n,answer,extra={})=>({requestId:`r${n}`,operation:'advance',answer,...extra});
|
|
591
663
|
|
|
592
664
|
test('host session idle after a finished step notifies once: 疑似空转 for progress, 在等你 for a person',async t=>{
|
|
593
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
594
|
-
const progress=await run([[0,op(1,{stage:'requirements_analysis',runId:'prd-1'})],[
|
|
665
|
+
const h=home(t,{config:{idleMinutes:0.009}}),run=idleHost(h);
|
|
666
|
+
const progress=await run([[0,op(1,{stage:'requirements_analysis',runId:'prd-1'})],[2700,null]]);
|
|
595
667
|
assert.equal(progress.code,0);
|
|
596
668
|
assert(await h.until(()=>h.rows().length===1));
|
|
597
669
|
const [idle]=h.rows();
|
|
598
670
|
assert.equal(idle.title,'CM cm-prd 疑似空转 · '+path.basename(process.cwd()));
|
|
599
671
|
assert.equal(idle.stdin.event,'idle');assert.equal(idle.stdin.code,'no_next_step');
|
|
600
672
|
assert.equal(idle.stdin.runId,'prd-1');assert.equal(idle.stdin.stage,'requirements_analysis');
|
|
601
|
-
const waiting=home(t,{config:{idleMinutes:0.
|
|
602
|
-
const review=await idleHost(waiting)([[0,op(1,{stage:'awaiting_user',runId:'prd-2'})],[
|
|
673
|
+
const waiting=home(t,{config:{idleMinutes:0.009}});
|
|
674
|
+
const review=await idleHost(waiting)([[0,op(1,{stage:'awaiting_user',runId:'prd-2'})],[2700,null]]);
|
|
603
675
|
assert.equal(review.code,0);
|
|
604
676
|
assert(await waiting.until(()=>waiting.rows().length===1));
|
|
605
677
|
assert.equal(waiting.rows()[0].title,'CM cm-prd 在等你 · '+path.basename(process.cwd()));
|
|
606
678
|
assert.equal(waiting.rows()[0].stdin.event,'idle_waiting');assert.equal(waiting.rows()[0].stdin.code,'waiting_for_you');
|
|
607
|
-
await new Promise(resolve=>setTimeout(resolve,
|
|
679
|
+
await new Promise(resolve=>setTimeout(resolve,900));
|
|
608
680
|
assert.equal(h.rows().length,1);assert.equal(waiting.rows().length,1);
|
|
609
681
|
});
|
|
610
682
|
|
|
611
683
|
test('host session idle: next step, in-flight step and session end clear it; status polls do not',async t=>{
|
|
612
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
684
|
+
const h=home(t,{config:{idleMinutes:0.009}}),run=idleHost(h);
|
|
613
685
|
// Steady progress: each next operation arrives before the threshold.
|
|
614
|
-
const steady=[];for(let n=1;n<=6;n++)steady.push([n===1?0:
|
|
615
|
-
assert.equal((await run([...steady,[
|
|
686
|
+
const steady=[];for(let n=1;n<=6;n++)steady.push([n===1?0:180,op(n,{stage:'requirements_analysis'})]);
|
|
687
|
+
assert.equal((await run([...steady,[180,null]])).code,0);
|
|
616
688
|
// A long in-flight operation is not idleness; ending right after its reply clears the timer.
|
|
617
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'},{slowMs:
|
|
689
|
+
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'},{slowMs:2700})],[2850,null]])).code,0);
|
|
618
690
|
// A slow next operation: its arrival clears the timer armed by the previous reply.
|
|
619
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[
|
|
691
|
+
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[180,op(2,{stage:'requirements_analysis'},{slowMs:2700})],[2850,null]])).code,0);
|
|
620
692
|
// A cancel reply while another operation is still in flight does not arm it.
|
|
621
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'},{slowMs:
|
|
693
|
+
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'},{slowMs:2700})],[180,{requestId:'c1',operation:'cancel'}],[2700,null]])).code,0);
|
|
622
694
|
// Driver shape: EOF right after the reply arrived.
|
|
623
695
|
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],['reply:r1',null]])).code,0);
|
|
624
696
|
// A line the host rejects (not JSON, unknown operation) is still the session's next step.
|
|
625
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[
|
|
626
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[
|
|
627
|
-
await new Promise(resolve=>setTimeout(resolve,
|
|
697
|
+
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[180,'not json'],[2700,null]])).code,0);
|
|
698
|
+
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[180,{requestId:'x',operation:'no_such_op'}],[2700,null]])).code,0);
|
|
699
|
+
await new Promise(resolve=>setTimeout(resolve,1500));
|
|
628
700
|
assert.equal(h.rows().length,0,h.log());
|
|
629
701
|
// Polls (status via the control path, fix_status via the normal path) neither
|
|
630
702
|
// hold the timer off nor replace the last real step's result.
|
|
631
703
|
for(const poll of ['status','fix_status']){
|
|
632
704
|
const polls=[[0,op(1,{stage:'requirements_analysis',runId:`run-${poll}`})]];
|
|
633
|
-
for(let n=0;n<12;n++)polls.push([
|
|
634
|
-
assert.equal((await run([...polls,[
|
|
705
|
+
for(let n=0;n<12;n++)polls.push([180,{requestId:`s${n}`,operation:poll}]);
|
|
706
|
+
assert.equal((await run([...polls,[180,null]])).code,0);
|
|
635
707
|
assert(await h.until(()=>h.rows().some(row=>row.stdin.runId===`run-${poll}`)));
|
|
636
708
|
const row=h.rows().find(row=>row.stdin.runId===`run-${poll}`);
|
|
637
709
|
assert.equal(row.stdin.event,'idle');assert.equal(row.stdin.stage,'requirements_analysis');
|
|
@@ -642,8 +714,8 @@ test('host session idle: next step, in-flight step and session end clear it; sta
|
|
|
642
714
|
// A poll that is still running when the deadline passes holds the notice; it
|
|
643
715
|
// goes out right after the poll replies, not during it.
|
|
644
716
|
test('host session idle: a slow status in flight holds the notice until it replies',async t=>{
|
|
645
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
646
|
-
const result=await run([[0,op(1,{stage:'requirements_analysis'})],[
|
|
717
|
+
const h=home(t,{config:{idleMinutes:0.009}}),run=idleHost(h);
|
|
718
|
+
const result=await run([[0,op(1,{stage:'requirements_analysis'})],[180,{requestId:'s1',operation:'status',slowMs:2100}],['reply:s1',undefined],[1200,null]]);
|
|
647
719
|
assert.equal(result.code,0);
|
|
648
720
|
const doneAt=JSON.parse(result.stdout.split('\n').find(line=>line.includes('"requestId":"s1"'))).result.doneAt;
|
|
649
721
|
assert(await h.until(()=>h.rows().length===1));
|
|
@@ -653,7 +725,7 @@ test('host session idle: a slow status in flight holds the notice until it repli
|
|
|
653
725
|
|
|
654
726
|
// Tool-bridge sessions end with host_close from the driver: exit 0, no notice.
|
|
655
727
|
test('host session idle: host_close ends the session cleanly without a notice',async t=>{
|
|
656
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
728
|
+
const h=home(t,{config:{idleMinutes:0.009}});
|
|
657
729
|
const script=path.join(h.dir,'cm-demo-host.mjs');
|
|
658
730
|
fs.writeFileSync(script,`import {serveCmAiHost} from ${JSON.stringify(HOST_SESSION)};
|
|
659
731
|
import {createHostToolBridge} from ${JSON.stringify(BRIDGE)};
|
|
@@ -125,8 +125,9 @@ test('patrol: a single dead host names its run and workflow; rate-limited or off
|
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
test('--report prints the summary and neither notifies nor removes anything',t=>{
|
|
128
|
-
const h=home(t),gone=gonePid();
|
|
129
|
-
|
|
128
|
+
const h=home(t),gone=gonePid(),now=Date.now();
|
|
129
|
+
// The CLI uses the real clock; this fixture must remain inside the unchanged TTL.
|
|
130
|
+
h.write(KEYS[1],{pid:gone,startedAt:new Date(now-3600000).toISOString(),at:new Date(now-600000).toISOString()});
|
|
130
131
|
const run=spawnSync(process.execPath,[PATROL,'--report'],{encoding:'utf8',env:{...h.env,NODE_TEST_CONTEXT:undefined}});
|
|
131
132
|
assert.equal(run.status,0,run.stderr);
|
|
132
133
|
const summary=JSON.parse(run.stdout);
|
|
@@ -6,16 +6,17 @@ import path from 'node:path';
|
|
|
6
6
|
import {createHash} from 'node:crypto';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {spawnSync} from 'node:child_process';
|
|
9
|
-
import {checkN4,checkN5,implementationSha256,prepareHumanCorrection,publishHumanCorrectionReview,
|
|
9
|
+
import {captureBaseline,checkN4,checkN5,implementationSha256,prepareHumanCorrection,publishHumanCorrectionReview,
|
|
10
10
|
prepareMarkDone,verifyMarkDonePlan} from './cm-task-gate.mjs';
|
|
11
11
|
|
|
12
12
|
const sha=file=>createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
13
13
|
function fixture(t){
|
|
14
14
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-human-correction-')));
|
|
15
15
|
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
16
|
-
const reviewsDir=path.join(root,'.reviews');fs.mkdirSync(reviewsDir);
|
|
16
|
+
const reviewsDir=path.join(root,'specs','.reviews');fs.mkdirSync(reviewsDir,{recursive:true});
|
|
17
17
|
fs.mkdirSync(path.join(root,'src'));const code=path.join(root,'src/example.ts');fs.writeFileSync(code,'old');
|
|
18
|
-
const tasks=path.join(root,'tasks.md');fs.writeFileSync(tasks,'- [ ] T-001: fixture\n');
|
|
18
|
+
const tasks=path.join(root,'specs','tasks.md');fs.writeFileSync(tasks,'- [ ] T-001: fixture\n');
|
|
19
|
+
captureBaseline({projectRoot:root,reviewsDir,feature:'login',task:'T-001'});
|
|
19
20
|
const payload=attempt=>({schema_version:1,task_id:'T-001',attempt,status:'ready_for_review',changed_files:['src/example.ts'],
|
|
20
21
|
implementation_sha256:implementationSha256(root,['src/example.ts']),
|
|
21
22
|
verification:[{command:'fixture',status:'passed',evidence:'synthetic fixture'}],
|
|
@@ -27,9 +28,9 @@ function fixture(t){
|
|
|
27
28
|
fs.writeFileSync(handoff,JSON.stringify(payload(attempt)));review(file,handoff,attempt,verdict);history.push(handoff,file);
|
|
28
29
|
}
|
|
29
30
|
const original=history.map(sha);fs.writeFileSync(code,'fixed');
|
|
30
|
-
const draft=path.join(
|
|
31
|
+
const draft=path.join(reviewsDir,'draft.json');fs.writeFileSync(draft,JSON.stringify(payload(2)));
|
|
31
32
|
const selectors={handoff:draft,reviewsDir,feature:'login',task:'T-001',projectRoot:root,
|
|
32
|
-
|
|
33
|
+
reason:'Correct exact selector after original blocked round 2.'};
|
|
33
34
|
const prepare=()=>prepareHumanCorrection(selectors);
|
|
34
35
|
const finish=(record,verdict='approved')=>{
|
|
35
36
|
const selected={...selectors,...record,tasksPath:tasks};
|
|
@@ -39,6 +40,36 @@ function fixture(t){
|
|
|
39
40
|
return {root,reviewsDir,code,tasks,draft,history,original,selectors,review,prepare,finish};
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
test('library default human correction preserves results without an editing baseline',t=>{
|
|
44
|
+
const f=fixture(t);fs.unlinkSync(path.join(f.reviewsDir,'login-T-001-baseline.json'));
|
|
45
|
+
const record=f.prepare(),selected={...f.selectors,...record};
|
|
46
|
+
assert.equal(JSON.stringify(checkN4(selected)),JSON.stringify({gate:'n4',task:'T-001',attempt:2,
|
|
47
|
+
outcome:'ready_for_review',content_bound:true,handoff_sha256:sha(record.handoff),correction_sha256:record.correction_sha256}));
|
|
48
|
+
const done=f.finish(record);
|
|
49
|
+
assert.equal(JSON.stringify(checkN5(done)),JSON.stringify({gate:'n5',task:'T-001',attempt:2,
|
|
50
|
+
outcome:'approved',review:record.review,content_bound:true,correction_sha256:record.correction_sha256}));
|
|
51
|
+
const plan=prepareMarkDone(done);assert.equal(plan.evidence.length,8);
|
|
52
|
+
assert.deepEqual(verifyMarkDonePlan(done,plan.planDigest),{outcome:'matched',planDigest:plan.planDigest});
|
|
53
|
+
assert.deepEqual(f.history.map(sha),f.original);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('human correction CLI and internal opt-in still require an editing baseline',t=>{
|
|
57
|
+
const f=fixture(t);fs.unlinkSync(path.join(f.reviewsDir,'login-T-001-baseline.json'));
|
|
58
|
+
const record=f.prepare(),selected={...f.selectors,...record};
|
|
59
|
+
assert.throws(()=>checkN4({...selected,inventory:'required'}),/missing editing baseline/);
|
|
60
|
+
const script=fileURLToPath(new URL('./cm-task-gate.mjs',import.meta.url));
|
|
61
|
+
const cli=command=>spawnSync(process.execPath,[script,command,'--handoff',record.handoff,
|
|
62
|
+
'--reviews-dir',f.reviewsDir,'--feature','login','--task','T-001','--project-root',f.root,
|
|
63
|
+
'--correction',record.correction,...(command==='prepare-mark-done'?['--tasks',f.tasks]:[])],{encoding:'utf8'});
|
|
64
|
+
const n4=cli('check-n4');assert.equal(n4.status,1);assert.match(n4.stderr,/missing editing baseline/);
|
|
65
|
+
const done=f.finish(record);
|
|
66
|
+
assert.throws(()=>checkN5({...done,inventory:'required'}),/missing editing baseline/);
|
|
67
|
+
for(const command of ['check-n5','prepare-mark-done']){
|
|
68
|
+
const result=cli(command);assert.equal(result.status,1);assert.match(result.stderr,/missing editing baseline/);
|
|
69
|
+
}
|
|
70
|
+
assert.deepEqual(f.history.map(sha),f.original);assert.match(fs.readFileSync(f.tasks,'utf8'),/\[ \]/);
|
|
71
|
+
});
|
|
72
|
+
|
|
42
73
|
test('one-shot human correction retains blocked history and completes through the existing locked adapter',t=>{
|
|
43
74
|
const f=fixture(t),record=f.prepare(),selected={...f.selectors,...record};
|
|
44
75
|
assert.equal(checkN4(selected).outcome,'ready_for_review');
|
|
@@ -54,20 +85,19 @@ test('one-shot human correction retains blocked history and completes through th
|
|
|
54
85
|
assert.throws(()=>checkN5({...done,handoff:f.history[2],correction:null}),/implementation content changed/);
|
|
55
86
|
});
|
|
56
87
|
|
|
57
|
-
test('correction
|
|
88
|
+
test('correction reason, original verdict, full scope, and mandatory Learning cannot be omitted',t=>{
|
|
58
89
|
const f=fixture(t);
|
|
59
|
-
assert.throws(()=>prepareHumanCorrection({...f.selectors,humanAuthorized:false}),/authorization/);
|
|
60
90
|
assert.throws(()=>prepareHumanCorrection({...f.selectors,reason:''}),/reason/);
|
|
61
91
|
const draft=JSON.parse(fs.readFileSync(f.draft));draft.evidence=['unbound application'];fs.writeFileSync(f.draft,JSON.stringify(draft));
|
|
62
92
|
assert.throws(()=>prepareHumanCorrection({...f.selectors,allowLegacyUnbound:true}),/Learning/);
|
|
63
|
-
assert.equal(fs.readdirSync(f.reviewsDir).length,
|
|
93
|
+
assert.equal(fs.readdirSync(f.reviewsDir).length,6);
|
|
64
94
|
draft.evidence=['learning: no_relevant_lesson','learning: retrospective no_new_lesson'];draft.changed_files=['src/new.ts'];
|
|
65
95
|
fs.writeFileSync(path.join(f.root,'src/new.ts'),'new');draft.implementation_sha256=implementationSha256(f.root,draft.changed_files);
|
|
66
96
|
fs.writeFileSync(f.draft,JSON.stringify(draft));assert.throws(()=>f.prepare(),/full original/);
|
|
67
97
|
f.review(f.history[3],f.history[2],2,'approved');assert.throws(()=>f.prepare(),/blocked round 2/);
|
|
68
98
|
});
|
|
69
99
|
|
|
70
|
-
test('original evidence, correction handoff, implementation and
|
|
100
|
+
test('original evidence, correction handoff, implementation and source record drift invalidate approval',t=>{
|
|
71
101
|
const f=fixture(t),record=f.prepare(),done=f.finish(record),plan=prepareMarkDone(done);
|
|
72
102
|
for(const file of [...f.history,record.correction,record.handoff,record.review,done.receipt??path.join(f.reviewsDir,'login-T-001-human-correction-receipt.json'),f.code]){
|
|
73
103
|
const bytes=fs.readFileSync(file);fs.appendFileSync(file,'\nchanged');
|
|
@@ -87,13 +117,13 @@ test('blocked correction review is sealed once and cannot be replaced by a new a
|
|
|
87
117
|
assert.throws(()=>f.prepare(),/already exists/);
|
|
88
118
|
});
|
|
89
119
|
|
|
90
|
-
test('old review or self-degraded review
|
|
120
|
+
test('old review or self-degraded review does not meet correction declaration and binding requirements',t=>{
|
|
91
121
|
const f=fixture(t),record=f.prepare(),selected={...f.selectors,...record};
|
|
92
122
|
f.review(record.review,record.handoff,2,'approved');
|
|
93
|
-
assert.throws(()=>publishHumanCorrectionReview(selected),/
|
|
123
|
+
assert.throws(()=>publishHumanCorrectionReview(selected),/independent: true.*bound/);
|
|
94
124
|
f.review(record.review,record.handoff,2,'approved',record.correction_sha256);
|
|
95
125
|
fs.writeFileSync(record.review,fs.readFileSync(record.review,'utf8').replace('codex-subagent','self-degraded').replace('independent: true','independent: false').replace('scope:','degraded_reason: fixture\nscope:'));
|
|
96
|
-
assert.throws(()=>publishHumanCorrectionReview(selected),/
|
|
126
|
+
assert.throws(()=>publishHumanCorrectionReview(selected),/independent: true.*bound/);
|
|
97
127
|
});
|
|
98
128
|
|
|
99
129
|
test('correction file identities reject symlinks, hardlinks, sibling selection and duplicate record fields',t=>{
|
|
@@ -108,10 +138,33 @@ test('correction file identities reject symlinks, hardlinks, sibling selection a
|
|
|
108
138
|
assert.throws(()=>checkN4(selected),/non-symlink/);
|
|
109
139
|
});
|
|
110
140
|
|
|
111
|
-
test('CLI
|
|
141
|
+
test('CLI correction works without an authorization flag and rejects the removed flag',t=>{
|
|
112
142
|
const f=fixture(t),script=fileURLToPath(new URL('./cm-task-gate.mjs',import.meta.url));
|
|
113
|
-
const args=['prepare-human-correction','--handoff',f.draft,'--reviews-dir',f.reviewsDir,'--feature','login','--task','T-001','--project-root',f.root,'--reason','
|
|
114
|
-
const
|
|
115
|
-
|
|
143
|
+
const args=['prepare-human-correction','--handoff',f.draft,'--reviews-dir',f.reviewsDir,'--feature','login','--task','T-001','--project-root',f.root,'--reason','Correct exact selector'];
|
|
144
|
+
const removed=spawnSync(process.execPath,[script,...args,'--human-authorized'],{encoding:'utf8'});
|
|
145
|
+
assert.equal(removed.status,1);assert.match(removed.stderr,/invalid arguments/);
|
|
146
|
+
const result=spawnSync(process.execPath,[script,...args],{encoding:'utf8'});
|
|
116
147
|
assert.equal(result.status,0,result.stderr);assert.equal(JSON.parse(result.stdout).attempt,2);
|
|
117
148
|
});
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
test('correction review declarations and candidate package bindings remain mandatory',t=>{
|
|
152
|
+
const f=fixture(t),record=f.prepare(),selected={...f.selectors,...record};
|
|
153
|
+
f.review(record.review,record.handoff,2,'approved',record.correction_sha256);
|
|
154
|
+
const original=fs.readFileSync(record.review,'utf8');
|
|
155
|
+
for(const [before,after] of [
|
|
156
|
+
['independent: true','independent: yes'],
|
|
157
|
+
['reviewer: codex-subagent','reviewer: arbitrary'],
|
|
158
|
+
['handoff_sha256: '+sha(record.handoff),'handoff_sha256: '+'0'.repeat(64)],
|
|
159
|
+
['correction_sha256: '+record.correction_sha256,'correction_sha256: '+'0'.repeat(64)],
|
|
160
|
+
['verdict: approved','verdict: blocked'],
|
|
161
|
+
]){
|
|
162
|
+
fs.writeFileSync(record.review,original.replace(before,after));
|
|
163
|
+
assert.throws(()=>publishHumanCorrectionReview(selected),undefined,before);
|
|
164
|
+
assert.equal(fs.existsSync(path.join(f.reviewsDir,'login-T-001-human-correction-receipt.json')),false);
|
|
165
|
+
}
|
|
166
|
+
fs.writeFileSync(record.review,original);
|
|
167
|
+
publishHumanCorrectionReview(selected);
|
|
168
|
+
assert.equal(checkN5(selected).outcome,'approved');
|
|
169
|
+
assert.deepEqual(f.history.map(sha),f.original);
|
|
170
|
+
});
|