@aibyzero/cm-workflow 0.16.9 → 0.17.1
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 +4 -0
- package/CHANGELOG.md +18 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +16 -1
- package/VERSION +1 -1
- package/docs/architecture.md +29 -13
- 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/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +104 -85
- 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/claude-review-stream.mjs +12 -8
- 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 +112 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +124 -25
- 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-check.mjs +3 -1
- 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-session.mjs +41 -8
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +25 -9
- 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 +57 -54
- 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 +41 -101
- 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-prd/summary.mjs +27 -12
- 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 +61 -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 +83 -47
- 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 +46 -14
- 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 +192 -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 +57 -27
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +46 -87
- 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 +47 -16
- 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 +34 -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-operator-guidance.test.mjs +56 -0
- 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 +35 -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-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-stream.test.mjs +36 -0
- package/scripts/cm-claude-worker.test.mjs +21 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-external-batch-host.test.mjs +38 -17
- 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-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- 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-host-stage-observer.test.mjs +41 -0
- 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 +135 -29
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-drive.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +15 -0
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +31 -0
- package/scripts/cm-release-smoke.sh +2 -14
- 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/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- 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 +98 -29
- 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
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import test from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
4
|
-
import {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
5
4
|
import {validateReviewDispatchGrant} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
6
5
|
import {requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
7
6
|
|
|
8
7
|
const identity={repositoryId:'review-host',runId:'run',taskId:'T-001',attempt:1},packageDigest='a'.repeat(64);
|
|
9
8
|
const binding={specsDir:'/specs',codeProject:'/code',feature:'1.work',identity,packageDigest};
|
|
10
|
-
const operation=name=>({version:1,operation:name,requestId:name,identity,...(name==='decision'?{packageDigest}:{})});
|
|
11
9
|
const request=requestFor({invocationId:'actual-request',identity,role:'reviewer',provider:'codex',
|
|
12
10
|
requestedModel:'fixture',contextId:'review-context',payload:{reviewPackage:{packageDigest},priorReview:null}});
|
|
13
11
|
const authority=decide=>createHostReviewAuthority({hostContextId:'host',reviewerId:'reviewer',adapterId:'codex-review-adapter',decide});
|
|
@@ -29,32 +27,3 @@ test('host decision issues one original grant only after the actual request exis
|
|
|
29
27
|
{status:'denied',code:'permission_denied'},mode);
|
|
30
28
|
}
|
|
31
29
|
});
|
|
32
|
-
|
|
33
|
-
for(const mode of ['approved','awaiting','denied','timeout','cancel','drift'])test(`dynamic review decision: ${mode}`,async()=>{
|
|
34
|
-
let current={state:'awaiting_review',code:null,identity,packageDigest},effects=0,started,release;
|
|
35
|
-
const ready=new Promise(resolve=>{started=resolve;});
|
|
36
|
-
const runner={status:()=>current,run:async()=>current,
|
|
37
|
-
cancel:()=>{current={...current,state:'cancelled',code:'cancelled',cancellationRequested:true};return current;},
|
|
38
|
-
executeEffect:async()=>{effects++;return current;}};
|
|
39
|
-
let decisions=0;
|
|
40
|
-
const entry=createCmAiConversationEntry({specsDir:binding.specsDir,codeProject:binding.codeProject,
|
|
41
|
-
feature:binding.feature,identity,runner,hostDecisionProvider:{timeoutMs:mode==='timeout'?10:1000,
|
|
42
|
-
decide:async(got,signal)=>{
|
|
43
|
-
decisions++;assert.deepEqual(got,binding);assert.equal(signal.aborted,false);started();
|
|
44
|
-
if(mode==='cancel'||mode==='timeout')return new Promise(resolve=>{release=resolve;});
|
|
45
|
-
if(mode==='drift')current={...current,packageDigest:'b'.repeat(64)};
|
|
46
|
-
if(mode==='awaiting')return null;
|
|
47
|
-
return mode==='denied'?{status:'denied',code:'permission_denied'}:{status:'approved'};
|
|
48
|
-
}}});
|
|
49
|
-
const running=entry.handle(operation('decision'));await ready;
|
|
50
|
-
if(mode==='cancel')await entry.handle(operation('cancel'));
|
|
51
|
-
const result=await running;
|
|
52
|
-
if(release){release({status:'approved'});await Promise.resolve();}
|
|
53
|
-
assert.equal(effects,mode==='approved'?1:0);
|
|
54
|
-
const expected={approved:null,awaiting:'decision_required',denied:'permission_denied',
|
|
55
|
-
timeout:'review_decision_timeout',cancel:'cancelled',drift:'stale_decision'};
|
|
56
|
-
assert.equal(result.code,expected[mode]);
|
|
57
|
-
current={state:'unknown',code:'reconciliation_required',identity,packageDigest};
|
|
58
|
-
const historical=await entry.handle(operation('decision'));
|
|
59
|
-
assert.equal(historical.state,'unknown');assert.equal(decisions,1,'unknown review must not ask for another decision');
|
|
60
|
-
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {withHostStageObserver,beginHostStage} from '../runtime/js/cm-ai/host-stage-observer.mjs';
|
|
7
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
8
|
+
|
|
9
|
+
test('nested native stage preserves outer deadline and restores its identity',async()=>{
|
|
10
|
+
const rows=[];
|
|
11
|
+
await withHostStageObserver(row=>rows.push(row),async()=>{
|
|
12
|
+
const outer=beginHostStage('develop',1000),parent=rows.at(-1);
|
|
13
|
+
const inner=beginHostStage('check',5000),child=rows.at(-1);
|
|
14
|
+
assert.equal(child.kind,'check');assert.notEqual(child.id,parent.id);assert.equal(child.deadlineMs,parent.deadlineMs);
|
|
15
|
+
inner();assert.deepEqual(rows.at(-1),parent);outer();assert.equal(rows.at(-1),null);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
test('overlapping operations and late stages cannot replace another operation telemetry',async()=>{
|
|
19
|
+
const a=[],b=[];let wake,late;
|
|
20
|
+
const waiting=new Promise(resolve=>{wake=resolve;});
|
|
21
|
+
const first=withHostStageObserver(row=>a.push(row),async()=>{late=beginHostStage('review',1000);await waiting;});
|
|
22
|
+
await withHostStageObserver(row=>b.push(row),async()=>{const end=beginHostStage('check',2000);assert.equal(a.at(-1).kind,'review');end();});
|
|
23
|
+
const before=b.length;wake();await first;late();assert.equal(b.length,before);assert.equal(a.at(-1),null);
|
|
24
|
+
});
|
|
25
|
+
test('observer failures and absent observers never alter original result or error',async()=>{
|
|
26
|
+
beginHostStage('check',1)();
|
|
27
|
+
assert.equal(await withHostStageObserver(()=>{throw Error('observer');},async()=>{beginHostStage('check',1)();return 7;}),7);
|
|
28
|
+
const failure=Error('original');
|
|
29
|
+
await assert.rejects(withHostStageObserver(()=>{throw Error('observer');},async()=>{beginHostStage('review',1);throw failure;}),error=>error===failure);
|
|
30
|
+
});
|
|
31
|
+
test('real native checks publish a distinct configured deadline per command without changing checks',async t=>{
|
|
32
|
+
const cwd=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-stage-')));
|
|
33
|
+
t.after(()=>fs.rmSync(cwd,{recursive:true,force:true}));const rows=[];
|
|
34
|
+
const check=createHostCheck({cwd,timeoutMs:2500,commands:['first','second'].map(id=>({id,command:[process.execPath,'-e','0']}))});
|
|
35
|
+
const result=await withHostStageObserver(row=>rows.push(row),()=>check({identity:{repositoryId:'stage-fixture',runId:'stage-fixture-run',taskId:'T-001',attempt:1}},{signal:new AbortController().signal}));
|
|
36
|
+
assert.deepEqual(result.map(row=>row.outcome),['passed','passed']);
|
|
37
|
+
const stages=rows.filter(Boolean);assert.equal(stages.length,2);
|
|
38
|
+
assert.equal(new Set(stages.map(row=>row.id)).size,2);
|
|
39
|
+
for(const row of stages){assert.equal(row.kind,'check');assert.equal(row.deadlineMs-Date.parse(row.startedAt),2500);assert.deepEqual(Object.keys(row).sort(),['deadlineMs','id','kind','startedAt']);}
|
|
40
|
+
assert.equal(rows.at(-1),null);
|
|
41
|
+
});
|
|
@@ -35,11 +35,11 @@ async function fixture(fn,{pending=false}={}){
|
|
|
35
35
|
const stateFile=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
36
36
|
const definition={version:1,specsDir,codeProject,feature,identity,scope:['README.md'],requirements:[]};
|
|
37
37
|
const execution=(enabled)=>({configuration:{kind:'synthetic-host-v1',...(enabled===undefined?{}:{workflow:{knowledgeCloseout:enabled}})},timeoutMs:1000,
|
|
38
|
-
excludedContexts:['main'],
|
|
38
|
+
excludedContexts:['main'],check:()=>[],applicableAgentFiles:[],documentationProvider:{timeoutMs:1000,inspect:async()=>{throw Error('unexpected inspection');}},
|
|
39
39
|
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:async()=>{throw Error('unexpected dispatch');}},
|
|
40
40
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
41
41
|
contexts:['review-1','review-2'],run:async()=>{throw Error('unexpected review');}}],
|
|
42
|
-
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['main'],hostContextId:'main'
|
|
42
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['main'],hostContextId:'main'}});
|
|
43
43
|
try{return await fn({root,specsDir,codeProject,feature,definition,entry,seedQa,response,stateFile,execution,effects:()=>effects});}
|
|
44
44
|
finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
45
45
|
}
|
|
@@ -124,7 +124,7 @@ test('real legacy init without closeout resumes byte-identically; explicit activ
|
|
|
124
124
|
excludedContexts:execution.excludedContexts,developer:execution.developer,reviewers:execution.reviewers,reviewInvocation:execution.reviewInvocation,
|
|
125
125
|
check:()=>[],timeoutMs:1000,taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(n=>path.join(f.specsDir,'.reviews',`fixture-T-001-a${n}-handoff.json`))},
|
|
126
126
|
taskLearning:{feature:f.feature,hostHandoff:true},persistence:{store,mode:'create',version:3}},entry:{specsDir:f.specsDir,codeProject:f.codeProject,
|
|
127
|
-
feature:f.feature,identity,
|
|
127
|
+
feature:f.feature,identity,applicableAgentFiles:[],documentationProvider:execution.documentationProvider}});}finally{store.close();}
|
|
128
128
|
const before=fs.readFileSync(f.stateFile);assert(!Object.hasOwn(JSON.parse(before).records[0].payload.config,'knowledgeCloseout'));
|
|
129
129
|
const resumed=await openControlRun(f.definition,'resume',execution);resumed.close();assert.deepEqual(fs.readFileSync(f.stateFile),before);
|
|
130
130
|
await assert.rejects(openControlRun(f.definition,'resume',f.execution(true)),{code:'closeout_policy_changed'});
|
|
@@ -157,17 +157,17 @@ test('bark and pushplus requests: fields, numeric code check, rejected responses
|
|
|
157
157
|
assert.deepEqual(JSON.parse(server.seen.at(-1).body),{token:PUSH_SECRET,title:'t'.repeat(100),content:'正文',template:'txt',channel:'wechat'});
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
-
test('network failure, deadline (also while waiting on stdin) and unexpected errors
|
|
160
|
+
test('network failure exits 3, the deadline (also while waiting on stdin) 5 and unexpected errors 6, without details',async t=>{
|
|
161
161
|
const s=sandbox(t);
|
|
162
162
|
s.write('notify-channel.conf','CHANNEL=bark\n');s.write('bark.env',`BARK_KEY=${BARK_SECRET}\n`);
|
|
163
163
|
const server=await fakeServer(t,()=>{});// never answers
|
|
164
164
|
let err=sink();
|
|
165
165
|
let code=await runSender({env:s.env,home:s.home,stdin:endedStdin(),stdout:sink().stream,stderr:err.stream,request:server.request,deadlineMs:300});
|
|
166
|
-
assert.equal(code,SEND_EXIT.
|
|
166
|
+
assert.equal(code,SEND_EXIT.deadline);assert.equal(err.text(),'cm-notify: 整次调用超过 1 秒,已放弃\n');
|
|
167
167
|
err=sink();const silent=new PassThrough();t.after(()=>silent.destroy());
|
|
168
168
|
const started=process.hrtime.bigint();
|
|
169
169
|
code=await runSender({env:s.env,home:s.home,stdin:silent,stdout:sink().stream,stderr:err.stream,request:()=>{throw new Error('must not send');},deadlineMs:200});
|
|
170
|
-
assert.equal(code,SEND_EXIT.
|
|
170
|
+
assert.equal(code,SEND_EXIT.deadline);assert.match(err.text(),/整次调用超过/);
|
|
171
171
|
assert(Number(process.hrtime.bigint()-started)/1e6<2000);
|
|
172
172
|
// A line without EOF is enough: the sender does not wait for the stream to end.
|
|
173
173
|
const open=new PassThrough();open.write('{"title":"x"}\n');t.after(()=>open.destroy());
|
|
@@ -175,11 +175,11 @@ test('network failure, deadline (also while waiting on stdin) and unexpected err
|
|
|
175
175
|
assert.equal(code,0);
|
|
176
176
|
err=sink();
|
|
177
177
|
code=await runSender({env:s.env,home:s.home,stdin:endedStdin(),stdout:sink().stream,stderr:err.stream,request:()=>{throw new Error(`boom ${BARK_SECRET}`);}});
|
|
178
|
-
assert.equal(code,SEND_EXIT.
|
|
178
|
+
assert.equal(code,SEND_EXIT.unexpected);assert.equal(err.text(),'cm-notify: 意外错误(详情已隐藏,避免带出密钥)\n');
|
|
179
179
|
err=sink();
|
|
180
180
|
code=await runSender({env:s.env,home:s.home,stdin:endedStdin(),stdout:sink().stream,stderr:err.stream,
|
|
181
181
|
request:(options,callback)=>http.request({...options,hostname:'127.0.0.1',port:1},callback)});
|
|
182
|
-
assert.equal(code,SEND_EXIT.network);assert.equal(err.text(),'cm-notify: bark
|
|
182
|
+
assert.equal(code,SEND_EXIT.network);assert.equal(err.text(),'cm-notify: bark 网络请求失败\n');
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
const [major,minor]=process.versions.node.split('.').map(Number);
|
|
@@ -338,7 +338,7 @@ test('test goes through the configured command, bypasses dedupe/limits, and repo
|
|
|
338
338
|
assert.equal(s.log(),'','dry-run runs nothing');
|
|
339
339
|
result=s.cli(['test']);// real sender, loopback port 1: refused connection, no external network
|
|
340
340
|
assert.equal(result.status,SEND_EXIT.network,result.stderr);
|
|
341
|
-
assert.equal(result.stdout,'渠道 bark:退出码 3
|
|
341
|
+
assert.equal(result.stdout,'渠道 bark:退出码 3,网络请求失败。\n');
|
|
342
342
|
noSecret(result.stdout+result.stderr);noSecret(s.log(),'notify.log');
|
|
343
343
|
assert.match(s.log(),/test cm-notify key=- test failed exit_3/);
|
|
344
344
|
// A custom command receives the same contract as the runtime launcher.
|
|
@@ -402,12 +402,14 @@ fs.writeFileSync(${JSON.stringify(record)},JSON.stringify({options:process.env.N
|
|
|
402
402
|
process.stdout.write('${BARK_SECRET}\\n');process.stderr.write('cm-notify: leaked ${BARK_SECRET}\\n');process.exit(${code});});`;
|
|
403
403
|
// The installed managed sender itself is replaced: same command shape, output still never shown.
|
|
404
404
|
const preload=path.join(s.root,'preload.cjs');fs.writeFileSync(preload,'// harmless for the manager itself\n');
|
|
405
|
-
|
|
405
|
+
// The replaced sender is no longer this plugin's copy: original words, 5/6 unknown, and an update hint.
|
|
406
|
+
const words={0:'已被推送服务接受(不代表已送达)',2:'配置或密钥问题',3:'网络失败或超时',4:'服务端拒绝',5:'未知',6:'未知',7:'未知'};
|
|
407
|
+
const staleHint='托管发送器与当前插件版本不同,退出码按旧含义解释;重新执行 /cm:notify bark 更新。';
|
|
406
408
|
for(const [code,word] of Object.entries(words)){
|
|
407
409
|
fs.writeFileSync(managedSenderPath(s.home),fake(code),{mode:0o600});
|
|
408
410
|
const result=s.cli(['test'],{NODE_OPTIONS:`--require=${preload}`});
|
|
409
411
|
assert.equal(result.status,Number(code),result.stderr);
|
|
410
|
-
assert.equal(result.stdout,`渠道 bark:退出码 ${code},${word}
|
|
412
|
+
assert.equal(result.stdout,`渠道 bark:退出码 ${code},${word}。${staleHint}\n`);noSecret(result.stdout+result.stderr);
|
|
411
413
|
assert.deepEqual(JSON.parse(fs.readFileSync(record,'utf8')),{options:null,execArgv:[]},'NODE_OPTIONS is not passed to the sender');
|
|
412
414
|
}
|
|
413
415
|
// Dry-run never runs the installed command.
|
|
@@ -423,7 +425,24 @@ process.stdout.write('${BARK_SECRET}\\n');process.stderr.write('cm-notify: leake
|
|
|
423
425
|
s.write('notify.json',JSON.stringify({version:1,command:[process.execPath,managedSenderPath(s.home)]}));
|
|
424
426
|
const result=await sendTest(s.home,{env:s.env,beforeSpawn:()=>s.write('notify.json',JSON.stringify({version:1,command:['/bin/sh','-c','exit 9']}))});
|
|
425
427
|
assert.equal(result.exit,0);assert.deepEqual(JSON.parse(fs.readFileSync(record,'utf8')).execArgv,[]);
|
|
426
|
-
assert.equal(
|
|
428
|
+
assert.equal(result.senderCurrent,false);
|
|
429
|
+
assert.equal(formatTest(result),`渠道 bark:退出码 0,已被推送服务接受(不代表已送达)。${staleHint}`);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('test explains 3/5/6 with the new words only for the current managed sender',()=>{
|
|
433
|
+
const current={kind:'managed',channel:'bark',dry:false,reason:null,senderCurrent:true};
|
|
434
|
+
assert.equal(formatTest({...current,exit:3}),'渠道 bark:退出码 3,网络请求失败。');
|
|
435
|
+
assert.equal(formatTest({...current,exit:5}),'渠道 bark:退出码 5,超过 12 秒期限(可能已送达)。');
|
|
436
|
+
assert.equal(formatTest({...current,exit:6}),'渠道 bark:退出码 6,意外错误。');
|
|
437
|
+
assert.equal(formatTest({...current,exit:7}),'渠道 bark:退出码 7,未知。');
|
|
438
|
+
// A custom or legacy command keeps the original meaning of its exit codes.
|
|
439
|
+
for(const [kind,who] of [['custom','自定义命令'],['legacy','渠道 bark']])for(const [exit,word] of [[3,'网络失败或超时'],[5,'未知'],[6,'未知']])
|
|
440
|
+
assert.equal(formatTest({kind,channel:'bark',dry:false,reason:null,exit}),`${who}:退出码 ${exit},${word}。`);
|
|
441
|
+
// An older managed sender: original words plus the update hint, also when the command did not end normally.
|
|
442
|
+
const stale={...current,senderCurrent:false},hint='托管发送器与当前插件版本不同,退出码按旧含义解释;重新执行 /cm:notify bark 更新。';
|
|
443
|
+
assert.equal(formatTest({...stale,exit:3}),`渠道 bark:退出码 3,网络失败或超时。${hint}`);
|
|
444
|
+
assert.equal(formatTest({...stale,exit:5}),`渠道 bark:退出码 5,未知。${hint}`);
|
|
445
|
+
assert.equal(formatTest({...stale,exit:null,reason:'timeout'}),`渠道 bark:命令没有正常结束(timeout),未知。${hint}`);
|
|
427
446
|
});
|
|
428
447
|
|
|
429
448
|
// Simulated slow reads: file-system calls of the sender replaced through its module API.
|
|
@@ -433,7 +452,7 @@ const delayedOps=({lstatMs=0,block=false,before}={})=>({open:fsp.open,lstat:asyn
|
|
|
433
452
|
else if(lstatMs)await new Promise(resolve=>setTimeout(resolve,lstatMs));
|
|
434
453
|
return fsp.lstat(file,options);}});
|
|
435
454
|
|
|
436
|
-
test('slow reads (blocking or async) end with
|
|
455
|
+
test('slow reads (blocking or async) end with 5 on time; dry-run, --check and sends never return 0 after the budget',async t=>{
|
|
437
456
|
const s=sandbox(t);
|
|
438
457
|
s.write('notify-channel.conf','CHANNEL=bark\n');s.write('bark.env',`BARK_KEY=${BARK_SECRET}\n`);
|
|
439
458
|
let sent=0;const request=()=>{sent++;throw new Error('must not send');};
|
|
@@ -442,7 +461,7 @@ test('slow reads (blocking or async) end with 3 on time; dry-run, --check and se
|
|
|
442
461
|
const err=sink(),out=sink();const begin=performance.now();
|
|
443
462
|
const code=await runSender({argv,env:{...s.env,...env},home:s.home,stdin:endedStdin(),stdout:out.stream,stderr:err.stream,fileOps,request,deadlineMs});
|
|
444
463
|
const took=performance.now()-begin,label=`${kind} ${argv} ${JSON.stringify(env)} ${deadlineMs}`;
|
|
445
|
-
assert.equal(code,SEND_EXIT.
|
|
464
|
+
assert.equal(code,SEND_EXIT.deadline,label);assert.equal(out.text(),'',label);
|
|
446
465
|
assert.match(err.text(),/^cm-notify: 整次调用超过 1 秒,已放弃/,label);
|
|
447
466
|
if(kind==='slowAsync')assert(took<deadlineMs+150,`${label} returned on time (${Math.round(took)} ms)`);
|
|
448
467
|
}
|
|
@@ -454,16 +473,16 @@ test('slow reads (blocking or async) end with 3 on time; dry-run, --check and se
|
|
|
454
473
|
const lastRead=argv.length||env.CM_NOTIFY_DRY_RUN?(argv.length?2:1):99;
|
|
455
474
|
const code=await runSender({argv,env:{...s.env,...env},home:s.home,stdin:endedStdin(),stdout:out.stream,stderr:err.stream,deadlineMs:5000,
|
|
456
475
|
clock:()=>now,request:(...args)=>{now=6000;return req(...args);},fileOps:delayedOps({before:()=>{if(++reads===lastRead)now=6000;}})});
|
|
457
|
-
assert.equal(code,SEND_EXIT.
|
|
476
|
+
assert.equal(code,SEND_EXIT.deadline,`${argv} ${JSON.stringify(env)}`);assert.equal(out.text(),'');assert.match(err.text(),/整次调用超过 5 秒,已放弃/);
|
|
458
477
|
}
|
|
459
|
-
assert.equal(server0.seen.length,1,'the late send was accepted but is still reported as
|
|
478
|
+
assert.equal(server0.seen.length,1,'the late send was accepted but is still reported as 5');
|
|
460
479
|
// With enough budget the same slow read still sends.
|
|
461
480
|
const server=await fakeServer(t,(req,res)=>json(res,200,{code:200}));
|
|
462
481
|
const code=await runSender({env:s.env,home:s.home,stdin:endedStdin(),stdout:sink().stream,stderr:sink().stream,fileOps:kinds.blocking,request:server.request,deadlineMs:2000});
|
|
463
482
|
assert.equal(code,0);assert.equal(server.seen.length,1);
|
|
464
483
|
});
|
|
465
484
|
|
|
466
|
-
test('the process entry arms a hard timer: a read that never settles still exits
|
|
485
|
+
test('the process entry arms a hard timer: a read that never settles still exits 5 at the deadline',async t=>{
|
|
467
486
|
const s=sandbox(t);
|
|
468
487
|
s.write('notify-channel.conf','CHANNEL=bark\n');s.write('bark.env',`BARK_KEY=${BARK_SECRET}\n`);
|
|
469
488
|
const sender=new URL('../runtime/js/notify-send.mjs',import.meta.url).href;
|
|
@@ -475,12 +494,29 @@ runCli({argv:[],deadlineMs:300,softDeadlineMs:1e9,senderOptions:{fileOps:{open:f
|
|
|
475
494
|
const begin=performance.now();
|
|
476
495
|
const result=spawnSync(process.execPath,['--input-type=module','-e',script],{input:'{}\n',encoding:'utf8',env:{...s.env,...extra},timeout:10000});
|
|
477
496
|
const took=performance.now()-begin;
|
|
478
|
-
assert.equal(result.status,SEND_EXIT.
|
|
497
|
+
assert.equal(result.status,SEND_EXIT.deadline,result.stderr);assert.equal(result.stdout,'');
|
|
479
498
|
assert.equal(result.stderr,'cm-notify: 整次调用超过 1 秒,已放弃\n');
|
|
480
499
|
assert(took<3000,`exited on time (${Math.round(took)} ms)`);
|
|
481
500
|
}
|
|
482
501
|
});
|
|
483
502
|
|
|
503
|
+
test('process-level errors (uncaught exception, unhandled rejection) exit 6 with only the fixed line',t=>{
|
|
504
|
+
const s=sandbox(t);
|
|
505
|
+
s.write('notify-channel.conf','CHANNEL=bark\n');s.write('bark.env',`BARK_KEY=${BARK_SECRET}\n`);
|
|
506
|
+
const sender=new URL('../runtime/js/notify-send.mjs',import.meta.url).href;
|
|
507
|
+
const faults={uncaught:`setImmediate(()=>{throw new Error('boom ${BARK_SECRET}');});`,
|
|
508
|
+
rejection:`Promise.reject(new Error('boom ${BARK_SECRET}'));`};
|
|
509
|
+
for(const [kind,fault] of Object.entries(faults)){
|
|
510
|
+
// The read never settles and the deadline is far away, so only the process-level handler can end it.
|
|
511
|
+
const script=`import {runCli} from ${JSON.stringify(sender)};
|
|
512
|
+
import fsp from 'node:fs/promises';
|
|
513
|
+
runCli({argv:[],deadlineMs:8000,softDeadlineMs:1e9,senderOptions:{fileOps:{open:fsp.open,lstat:()=>{${fault}return new Promise(()=>{});}}}});`;
|
|
514
|
+
const result=spawnSync(process.execPath,['--input-type=module','-e',script],{input:'{}\n',encoding:'utf8',env:s.env,timeout:10000});
|
|
515
|
+
assert.equal(result.status,SEND_EXIT.unexpected,`${kind} ${result.stderr}`);assert.equal(result.stdout,'',kind);
|
|
516
|
+
assert.equal(result.stderr,'cm-notify: 意外错误(详情已隐藏,避免带出密钥)\n',kind);noSecret(result.stderr);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
|
|
484
520
|
test('off restores the previous notify.off.json when moving notify.json fails, and names the backup if that fails too',t=>{
|
|
485
521
|
const s=sandbox(t);
|
|
486
522
|
const on=JSON.stringify({version:1,command:['/bin/true'],waitMinutes:5}),old=JSON.stringify({version:1,command:['/bin/false'],note:'old off'});
|
|
@@ -629,12 +665,12 @@ test('time spent before the sender work counts toward the same 12 s budget',asyn
|
|
|
629
665
|
// The start recorded at entry is honoured: time already spent leaves no budget for an exit 0.
|
|
630
666
|
for(const argv of [['--check'],[]]){
|
|
631
667
|
const result=run(`import {performance} from 'node:perf_hooks';runCli({argv:${JSON.stringify(argv)},startedAt:performance.now()-12050});`,{CM_NOTIFY_DRY_RUN:'1'});
|
|
632
|
-
assert.equal(result.status,SEND_EXIT.
|
|
668
|
+
assert.equal(result.status,SEND_EXIT.deadline,`${argv} ${result.stderr}`);assert.equal(result.stdout,'');assert(result.took<5000);
|
|
633
669
|
}
|
|
634
|
-
// 250 ms already spent, the slow read needs more than the 50 ms left:
|
|
670
|
+
// 250 ms already spent, the slow read needs more than the 50 ms left: 5, never 0.
|
|
635
671
|
const result=run(`import {performance} from 'node:perf_hooks';import fsp from 'node:fs/promises';
|
|
636
672
|
runCli({argv:['--check'],deadlineMs:300,startedAt:performance.now()-250,senderOptions:{fileOps:{open:fsp.open,lstat:async(f,o)=>{await new Promise(r=>setTimeout(r,200));return fsp.lstat(f,o);}}}});`);
|
|
637
|
-
assert.equal(result.status,SEND_EXIT.
|
|
673
|
+
assert.equal(result.status,SEND_EXIT.deadline,result.stderr);assert.equal(result.stdout,'');assert(result.took<3000);
|
|
638
674
|
});
|
|
639
675
|
|
|
640
676
|
test('entry is decided by import.meta.main alone: imported does nothing, unsupported Node exits 3, Windows is refused first',()=>{
|
|
@@ -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]';
|