@aibyzero/cm-workflow 0.16.8 → 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 +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- 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 +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- 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 +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- 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 +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- 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/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- 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 +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -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 +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- 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 +54 -0
- 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 +30 -5
- 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 +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- 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 +95 -13
- 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 +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- 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 +489 -51
- 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 +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- 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 +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- 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-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +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 +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -4,7 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {spawn,spawnSync} from 'node:child_process';
|
|
7
|
-
import {notify,readNotifyConfig,buildNotifyMessage,driveNotice,NOTIFY_LIMITS,NOTIFY_WORKFLOWS} from '../runtime/js/notify.mjs';
|
|
7
|
+
import {notify,readNotifyConfig,parseNotifyConfig,buildNotifyMessage,normalizeNotifyText,driveNotice,NOTIFY_LIMITS,NOTIFY_WORKFLOWS,DEFAULT_NOTIFY_TEXT} from '../runtime/js/notify.mjs';
|
|
8
8
|
|
|
9
9
|
const NOW=Date.parse('2026-10-08T08:00:00.000Z');
|
|
10
10
|
const DRIVE_CORE=new URL('../runtime/js/cm-ai/drive-core.mjs',import.meta.url).href;
|
|
@@ -50,6 +50,65 @@ test('invalid config turns the feature off: relative command, bad version, bad w
|
|
|
50
50
|
assert.deepEqual(readNotifyConfig(h.env),{command:['/bin/true'],waitMs:30000,checkWaitMs:2700000,idleMs:2700000});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
// The runtime reads notify.json through the same safe boundary as /cm:notify:
|
|
54
|
+
// no symlink, regular file only, 64 KiB cap, non-blocking open. Every refusal
|
|
55
|
+
// turns notices off with one notify.log line; nothing throws or waits.
|
|
56
|
+
// Each probe runs in its own process: the log line is once per process, and a
|
|
57
|
+
// build that blocks on a FIFO fails by timeout instead of hanging the suite.
|
|
58
|
+
const posix=process.platform!=='win32';
|
|
59
|
+
const CONFIG={version:1,command:['/bin/true']},PARSED={command:['/bin/true'],waitMs:600000,checkWaitMs:2700000,idleMs:2700000};
|
|
60
|
+
const NOTIFY_URL=new URL('../runtime/js/notify.mjs',import.meta.url).href;
|
|
61
|
+
function probe(h){
|
|
62
|
+
const child=spawnSync(process.execPath,['--input-type=module','-e',
|
|
63
|
+
`import {readNotifyConfig,notify} from ${JSON.stringify(NOTIFY_URL)};
|
|
64
|
+
console.log(JSON.stringify({config:readNotifyConfig(process.env),sent:notify({key:'k'},{env:process.env})}));`],
|
|
65
|
+
{env:{...process.env,CM_WORKFLOW_HOME:h.dir},encoding:'utf8',timeout:5000,killSignal:'SIGKILL'});
|
|
66
|
+
assert.equal(child.error,undefined,'reading notify.json made the runtime wait');
|
|
67
|
+
assert.equal(child.status,0,child.stderr);
|
|
68
|
+
return JSON.parse(child.stdout);
|
|
69
|
+
}
|
|
70
|
+
const OFF={config:null,sent:{sent:false,reason:'off'}};
|
|
71
|
+
const unreadable=(h,reason)=>assert.match(h.log(),new RegExp(`config - key=- off invalid_config unreadable_${reason}\\n$`));
|
|
72
|
+
|
|
73
|
+
test('runtime read: notify.json that is a symlink is never read, even to a valid config; a normal file still is',{skip:!posix},t=>{
|
|
74
|
+
const h=home(t);const file=path.join(h.dir,'notify.json'),real=path.join(h.dir,'real-config.json');
|
|
75
|
+
fs.writeFileSync(real,JSON.stringify(CONFIG));fs.rmSync(file);fs.symlinkSync(real,file);
|
|
76
|
+
assert.deepEqual(probe(h),OFF);unreadable(h,'not_regular_file');assert.equal(h.rows().length,0);
|
|
77
|
+
// A dangling link is a link too: refused and logged, not treated as "missing".
|
|
78
|
+
const dangling=home(t);fs.rmSync(path.join(dangling.dir,'notify.json'));fs.symlinkSync(path.join(dangling.dir,'nowhere.json'),path.join(dangling.dir,'notify.json'));
|
|
79
|
+
assert.deepEqual(probe(dangling),OFF);unreadable(dangling,'not_regular_file');
|
|
80
|
+
// The same content as a regular file reads exactly as before.
|
|
81
|
+
fs.rmSync(file);fs.writeFileSync(file,JSON.stringify(CONFIG));
|
|
82
|
+
assert.deepEqual(probe(h).config,PARSED);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('runtime read: a FIFO at notify.json is refused at once, never waited on',{skip:!posix},t=>{
|
|
86
|
+
const h=home(t);const file=path.join(h.dir,'notify.json');
|
|
87
|
+
fs.rmSync(file);assert.equal(spawnSync('mkfifo',['-m','600',file]).status,0);
|
|
88
|
+
assert.deepEqual(probe(h),OFF);unreadable(h,'not_regular_file');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('runtime read: notify.json over 64 KiB is refused; exactly 64 KiB is still read',{skip:!posix},t=>{
|
|
92
|
+
const json=JSON.stringify(CONFIG),pad=n=>json+' '.repeat(n-Buffer.byteLength(json));
|
|
93
|
+
const over=home(t);fs.writeFileSync(path.join(over.dir,'notify.json'),pad(64*1024+1));
|
|
94
|
+
assert.deepEqual(probe(over),OFF);unreadable(over,'too_large');
|
|
95
|
+
const exact=home(t);fs.writeFileSync(path.join(exact.dir,'notify.json'),pad(64*1024));
|
|
96
|
+
assert.deepEqual(probe(exact).config,PARSED);assert.equal(exact.log(),'');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('runtime read: a missing file stays silent, a directory is a logged off, a BOM file behaves as before (not_json)',{skip:!posix},t=>{
|
|
100
|
+
const missing=home(t);fs.rmSync(path.join(missing.dir,'notify.json'));
|
|
101
|
+
assert.deepEqual(probe(missing),OFF);assert.equal(missing.log(),'');
|
|
102
|
+
const dir=home(t);fs.rmSync(path.join(dir.dir,'notify.json'));fs.mkdirSync(path.join(dir.dir,'notify.json'));
|
|
103
|
+
assert.deepEqual(probe(dir),OFF);unreadable(dir,'not_regular_file');
|
|
104
|
+
// Same as the plain read it replaces: the BOM is not stripped, JSON.parse rejects it.
|
|
105
|
+
const bom=home(t);fs.writeFileSync(path.join(bom.dir,'notify.json'),'\uFEFF'+JSON.stringify(CONFIG));
|
|
106
|
+
assert.deepEqual(probe(bom),OFF);assert.match(bom.log(),/config - key=- off invalid_config not_json\n$/);
|
|
107
|
+
// Invalid UTF-8 never throws; it is just an invalid file.
|
|
108
|
+
const bad=home(t);fs.writeFileSync(path.join(bad.dir,'notify.json'),Buffer.from([0x7b,0xff,0xfe,0x7d]));
|
|
109
|
+
assert.deepEqual(probe(bad),OFF);assert.match(bad.log(),/off invalid_config not_json\n$/);
|
|
110
|
+
});
|
|
111
|
+
|
|
53
112
|
test('message is bounded and built only from the structured fields',()=>{
|
|
54
113
|
const long='x'.repeat(2000);
|
|
55
114
|
const message=buildNotifyMessage({...fields('k'),workflow:long,project:'/very/secret/path/'+long,runId:long,task:long,
|
|
@@ -60,10 +119,168 @@ test('message is bounded and built only from the structured fields',()=>{
|
|
|
60
119
|
for(const forbidden of ['DIFF-CONTENT','LOG-CONTENT','SECRET','push.env','/srv/','/very/secret','~/secret','\0'])
|
|
61
120
|
assert(!message.body.includes(forbidden)&&!message.title.includes(forbidden),forbidden);
|
|
62
121
|
assert.match(message.body,/<路径>/);
|
|
63
|
-
const short=buildNotifyMessage(fields('k'),{now:NOW});
|
|
122
|
+
const short=buildNotifyMessage(fields('k'),{now:NOW,timeZone:'Asia/Shanghai'});
|
|
64
123
|
assert.equal(short.title,'CM cm-fix 需要人处理 · demo-app');
|
|
65
|
-
assert.
|
|
66
|
-
assert.
|
|
124
|
+
assert.equal(short.body,'下一步:核对 reason 后恢复原运行\n项目:demo-app\n流程:cm-fix\n任务:T-001\n阶段:blocked\n原因:checks_not_passed\n时间:16:00');
|
|
125
|
+
assert.doesNotMatch(short.body,/运行:|run-1|CM 不会自动继续/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('done shows only project, task and local time; empty fields are left out',()=>{
|
|
129
|
+
const done=buildNotifyMessage(fields('k',{event:'done',stage:'run_done',code:'run_done',nextAction:'建议在新会话里开始下一个任务'}),
|
|
130
|
+
{now:NOW,timeZone:'Asia/Shanghai'});
|
|
131
|
+
assert.equal(done.title,'CM cm-fix 流程已结束 · demo-app');
|
|
132
|
+
assert.equal(done.body,'项目:demo-app\n任务:T-001\n时间:16:00');
|
|
133
|
+
assert.equal(buildNotifyMessage(fields('k',{event:'done',task:null}),{now:NOW,timeZone:'UTC'}).body,'项目:demo-app\n时间:08:00');
|
|
134
|
+
assert.equal(buildNotifyMessage({workflow:'cm-ai',event:'waiting'},{now:NOW,timeZone:'America/New_York'}).body,'流程:cm-ai\n时间:04:00');
|
|
135
|
+
assert.equal(buildNotifyMessage({workflow:'cm-ai'},{now:Date.parse('2026-10-08T16:05:00.000Z'),timeZone:'Asia/Shanghai'}).body,'流程:cm-ai\n时间:00:05');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('without an injected time zone the clock follows the process TZ',()=>{
|
|
139
|
+
const script=`import {buildNotifyMessage} from ${JSON.stringify(new URL('../runtime/js/notify.mjs',import.meta.url).href)};
|
|
140
|
+
process.stdout.write(buildNotifyMessage({workflow:'cm-ai',event:'done',project:'/p/demo'},{now:${NOW}}).body);`;
|
|
141
|
+
for(const [tz,clock] of [['Asia/Shanghai','16:00'],['UTC','08:00'],['America/Los_Angeles','01:00']]){
|
|
142
|
+
const run=spawnSync(process.execPath,['--input-type=module','-e',script],{encoding:'utf8',env:{...process.env,TZ:tz}});
|
|
143
|
+
assert.equal(run.status,0,run.stderr);assert.equal(run.stdout,`项目:demo\n时间:${clock}`);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Optional notify.json `text`. Expected strings below are written out by hand
|
|
148
|
+
// from the default layout, not computed by the code under test.
|
|
149
|
+
const EVENTS=[['done','流程已结束'],['waiting','等待会话应答'],['idle','疑似空转'],['idle_waiting','在等你'],
|
|
150
|
+
['dead','宿主已退出未收尾'],['stuck','需要人处理'],[undefined,'需要人处理']];
|
|
151
|
+
test('custom text: without `text` (or with an empty one) every event is byte-identical to the default',()=>{
|
|
152
|
+
const at={now:NOW,timeZone:'Asia/Shanghai'};
|
|
153
|
+
for(const [event,headline] of EVENTS){
|
|
154
|
+
const base=buildNotifyMessage(fields('k',{event}),at);
|
|
155
|
+
assert.equal(base.title,`CM cm-fix ${headline} · demo-app`,String(event));
|
|
156
|
+
assert.equal(base.body,event==='done'?'项目:demo-app\n任务:T-001\n时间:16:00'
|
|
157
|
+
:'下一步:核对 reason 后恢复原运行\n项目:demo-app\n流程:cm-fix\n任务:T-001\n阶段:blocked\n原因:checks_not_passed\n时间:16:00');
|
|
158
|
+
for(const text of [{},DEFAULT_NOTIFY_TEXT,null,normalizeNotifyText({}).text])
|
|
159
|
+
assert.deepEqual(buildNotifyMessage(fields('k',{event}),{...at,text}),base,`${event} ${JSON.stringify(text)}`);
|
|
160
|
+
}
|
|
161
|
+
const plainConfig=parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true']}));
|
|
162
|
+
assert.deepEqual(plainConfig,{config:{command:['/bin/true'],waitMs:600000,checkWaitMs:2700000,idleMs:2700000}});
|
|
163
|
+
assert.equal(Object.hasOwn(plainConfig.config,'text'),false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('custom text: prefix, headlines, field order (runId included) and labels',()=>{
|
|
167
|
+
const at={now:NOW,timeZone:'Asia/Shanghai'};
|
|
168
|
+
const text={titlePrefix:'【工作流】',headlines:{done:'完工',waiting:'等你回话',idle:'没动静',idle_waiting:'该你了',dead:'宿主没了',default:'卡住了'},
|
|
169
|
+
fields:{default:['code','runId','time'],done:['time','task']},labels:{code:'代码',runId:'编号',time:'时刻',task:'工单'}};
|
|
170
|
+
const parsed=parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true'],text}));
|
|
171
|
+
assert.equal(parsed.textReason,undefined);
|
|
172
|
+
const custom=parsed.config.text;
|
|
173
|
+
const want={done:'完工',waiting:'等你回话',idle:'没动静',idle_waiting:'该你了',dead:'宿主没了',stuck:'卡住了'};
|
|
174
|
+
for(const [event,headline] of Object.entries(want)){
|
|
175
|
+
const message=buildNotifyMessage(fields('k',{event}),{...at,text:custom});
|
|
176
|
+
assert.equal(message.title,`【工作流】 cm-fix ${headline} · demo-app`);
|
|
177
|
+
assert.equal(message.body,event==='done'?'时刻:16:00\n工单:T-001':'代码:checks_not_passed\n编号:run-1\n时刻:16:00');
|
|
178
|
+
}
|
|
179
|
+
// Partial text: only what is given changes; an empty prefix drops it from the title.
|
|
180
|
+
const partial=buildNotifyMessage(fields('k'),{...at,text:{titlePrefix:'',labels:{nextAction:'先做'}}});
|
|
181
|
+
assert.equal(partial.title,'cm-fix 需要人处理 · demo-app');
|
|
182
|
+
assert.equal(partial.body,'先做:核对 reason 后恢复原运行\n项目:demo-app\n流程:cm-fix\n任务:T-001\n阶段:blocked\n原因:checks_not_passed\n时间:16:00');
|
|
183
|
+
assert.equal(buildNotifyMessage(fields('k',{event:'waiting'}),{...at,text:{headlines:{waiting:'等'}}}).title,'CM cm-fix 等 · demo-app');
|
|
184
|
+
assert.equal(buildNotifyMessage(fields('k',{event:'idle'}),{...at,text:{headlines:{waiting:'等'}}}).title,'CM cm-fix 疑似空转 · demo-app');
|
|
185
|
+
// Empty field values are still left out under a custom order.
|
|
186
|
+
assert.equal(buildNotifyMessage({workflow:'cm-ai'},{...at,text:{fields:{default:['runId','workflow','time']}}}).body,'流程:cm-ai\n时间:16:00');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('custom text strings are cleaned like field values: paths redacted, control characters removed, each capped',()=>{
|
|
190
|
+
const at={now:NOW,timeZone:'UTC'};
|
|
191
|
+
const text=normalizeNotifyText({titlePrefix:'CM\u0007/Users/example/secret',
|
|
192
|
+
headlines:{default:'卡住\n见/srv/private/push.env\u001b[31m'},labels:{nextAction:'C:\\Users\\example\\a.txt\u0000下一步',project:'~/proj',code:'\\\\srv\\share\\x'}}).text;
|
|
193
|
+
const message=buildNotifyMessage(fields('k'),{...at,text});
|
|
194
|
+
for(const forbidden of ['/Users','example\\','secret','/srv/','push.env','~/proj','\\\\srv','\u0007','\u001b','\u0000','\n见'])
|
|
195
|
+
assert(!message.title.includes(forbidden)&&!message.body.split('\n').map(line=>line.split(':')[0]).join('|').includes(forbidden),JSON.stringify(forbidden));
|
|
196
|
+
assert.equal(message.title,'CM <路径> cm-fix 卡住 见<路径> [31m · demo-app');
|
|
197
|
+
assert.equal(message.body.split('\n')[0],'<路径> 下一步:核对 reason 后恢复原运行');
|
|
198
|
+
assert.match(message.body,/\n<路径>:demo-app\n/);
|
|
199
|
+
assert.match(message.body,/\n<路径>:checks_not_passed\n/);
|
|
200
|
+
// Caps: prefix 16, headline 24, label 12 characters (… included); title 60, body 500.
|
|
201
|
+
const long=normalizeNotifyText({titlePrefix:'前'.repeat(40),headlines:{default:'标'.repeat(40)},labels:{nextAction:'签'.repeat(40)}}).text;
|
|
202
|
+
assert.equal(long.titlePrefix,'前'.repeat(15)+'…');assert.equal(long.headlines.default,'标'.repeat(23)+'…');
|
|
203
|
+
assert.equal(long.labels.nextAction,'签'.repeat(11)+'…');
|
|
204
|
+
const huge='x'.repeat(2000);
|
|
205
|
+
const big=buildNotifyMessage({...fields('k'),workflow:huge,project:huge,runId:huge,task:huge,stage:huge,code:huge,nextAction:huge},
|
|
206
|
+
{...at,text:{...long,fields:{default:['nextAction','runId','project','workflow','task','stage','code','time']}}});
|
|
207
|
+
assert.equal(Array.from(big.title).length,NOTIFY_LIMITS.titleChars);
|
|
208
|
+
assert(Array.from(big.body).length<=NOTIFY_LIMITS.bodyChars);
|
|
209
|
+
assert.match(big.body,/^签{11}…:x{199}…\n/);
|
|
210
|
+
assert.match(big.body,/\n运行:x{63}…\n/);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('custom text loses bidi and zero-width characters; a string left with nothing visible is invalid',()=>{
|
|
214
|
+
const at={now:NOW,timeZone:'UTC'};
|
|
215
|
+
const hidden=['','','','','','','','','','','','',
|
|
216
|
+
'','','','','','','\u{e0041}'];
|
|
217
|
+
const text=normalizeNotifyText({titlePrefix:`C${hidden.join('')}M`,headlines:{default:`卡住了`},
|
|
218
|
+
labels:{code:'原因',task:'工单'}}).text;
|
|
219
|
+
const message=buildNotifyMessage(fields('k'),{...at,text});
|
|
220
|
+
for(const char of hidden)assert(!message.title.includes(char)&&!message.body.includes(char),`U+${char.codePointAt(0).toString(16)}`);
|
|
221
|
+
assert.equal(message.title,'CM cm-fix 卡住了 · demo-app');
|
|
222
|
+
assert.match(message.body,/\n工单:T-001\n/);assert.match(message.body,/\n原因:checks_not_passed\n/);
|
|
223
|
+
// Nothing visible left: the whole text is invalid and the default text is used.
|
|
224
|
+
for(const [value,reason] of [[{headlines:{default:''}},'headlines'],[{labels:{code:' '}},'labels'],
|
|
225
|
+
[{titlePrefix:''},'title_prefix'],[{titlePrefix:' '},'title_prefix'],[{headlines:{done:'̀'}},'headlines']]){
|
|
226
|
+
assert.equal(normalizeNotifyText(value).reason,reason,JSON.stringify(value));
|
|
227
|
+
assert.equal(parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true'],text:value})).textReason,reason);
|
|
228
|
+
assert.deepEqual(buildNotifyMessage(fields('k'),{...at,text:value}),buildNotifyMessage(fields('k'),at));
|
|
229
|
+
}
|
|
230
|
+
// Field values are not part of the text layer: the default path is unchanged.
|
|
231
|
+
assert.equal(buildNotifyMessage(fields('k',{task:'T-1'}),at).body.split('\n')[3],'任务:T-1');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('custom text redacts absolute paths even when letters touch them; field values keep the shared rule',()=>{
|
|
235
|
+
const at={now:NOW,timeZone:'UTC'};
|
|
236
|
+
for(const [raw,want] of [['see/Users/example/key','see<路径>'],['seeC:\\Users\\example\\key','see<路径>'],['seeC:/Users/example/key','see<路径>'],
|
|
237
|
+
['see\\\\srv\\share\\key','see<路径>'],['see~/proj/key','see<路径>'],['卡在/srv/a,再看','卡在<路径>,再看'],
|
|
238
|
+
['x1/etc/passwd y','x1<路径> y'],['CI/CD','CI<路径>'],['停\u0007/tmp/a','停 <路径>'],['停\u200b/tmp/a','停<路径>'],
|
|
239
|
+
['相对 a\\b 保留','相对 a\\b 保留']]){
|
|
240
|
+
const text=normalizeNotifyText({headlines:{default:raw},labels:{code:raw}}).text;
|
|
241
|
+
assert.equal(text.headlines.default,want,raw);assert.equal(text.labels.code,want.slice(0,12),raw);
|
|
242
|
+
const message=buildNotifyMessage(fields('k'),{...at,text});
|
|
243
|
+
assert.equal(message.title,`CM cm-fix ${want} · demo-app`,raw);
|
|
244
|
+
for(const leak of ['/Users','Users\\','\\\\srv','/srv','~/proj','/etc','/tmp'])assert(!message.title.includes(leak)&&!message.body.includes(leak),`${raw} ${leak}`);
|
|
245
|
+
}
|
|
246
|
+
// The shared rule for field values (and so the default text) is unchanged.
|
|
247
|
+
assert.equal(buildNotifyMessage(fields('k',{task:'see/Users/example/key'}),at).body.split('\n')[3],'任务:see/Users/example/key');
|
|
248
|
+
assert.equal(buildNotifyMessage(fields('k',{task:'见 /Users/example/key'}),at).body.split('\n')[3],'任务:见 <路径>');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('invalid text falls back to the default text with one text_config log line; notices stay on',async t=>{
|
|
252
|
+
const bad=[[null,'text'],['标题','text'],[[],'text'],[{subject:'x'},'text_key'],[{titlePrefix:7},'title_prefix'],
|
|
253
|
+
[{titlePrefix:'\u0007'},'title_prefix'],[{headlines:{stuck:'x'}},'headlines'],[{headlines:{done:''}},'headlines'],
|
|
254
|
+
[{headlines:{done:'\u0001\u0002'}},'headlines'],[{headlines:'x'},'headlines'],[{labels:{secret:'x'}},'labels'],
|
|
255
|
+
[{labels:{task:3}},'labels'],[{fields:{default:['nextAction','diff']}},'fields'],[{fields:{default:[]}},'fields'],
|
|
256
|
+
[{fields:{default:['task','task']}},'fields'],[{fields:{stuck:['task']}},'fields'],[{fields:{done:'task'}},'fields'],
|
|
257
|
+
[{fields:{done:['toString']}},'fields']];
|
|
258
|
+
for(const [text,reason] of bad){
|
|
259
|
+
const parsed=parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true'],text}));
|
|
260
|
+
assert.equal(parsed.reason,undefined,JSON.stringify(text));assert.equal(parsed.textReason,reason,JSON.stringify(text));
|
|
261
|
+
assert.equal(parsed.config.text,undefined);assert.deepEqual(parsed.config.command,['/bin/true']);
|
|
262
|
+
assert.deepEqual(buildNotifyMessage(fields('k'),{now:NOW,timeZone:'UTC',text}),buildNotifyMessage(fields('k'),{now:NOW,timeZone:'UTC'}));
|
|
263
|
+
}
|
|
264
|
+
// End to end: the typo does not silence the notice, it goes out in the default text, and notify.log says why once.
|
|
265
|
+
const h=home(t,{config:{text:{fields:{default:['nextAction','diff']}}}});
|
|
266
|
+
assert.equal(readNotifyConfig(h.env).text,undefined);
|
|
267
|
+
assert.deepEqual(notify(fields('typo'),{env:h.env,now:NOW}),{sent:true,reason:'launched'});
|
|
268
|
+
assert(await h.until(()=>h.rows().length===1));
|
|
269
|
+
assert.equal(h.rows()[0].title,'CM cm-fix 需要人处理 · demo-app');
|
|
270
|
+
assert.match(h.rows()[0].body,/^下一步:核对 reason 后恢复原运行\n项目:demo-app\n/);
|
|
271
|
+
readNotifyConfig(h.env);
|
|
272
|
+
const lines=h.log().split('\n').filter(line=>line.includes('text_config'));
|
|
273
|
+
assert.equal(lines.length,1,h.log());assert.match(lines[0],/ config - key=- default_text text_config fields$/);
|
|
274
|
+
assert.doesNotMatch(h.log(),/off invalid_config/);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('custom text reaches the command in CM_NOTIFY_TITLE/BODY and the stdin JSON',async t=>{
|
|
278
|
+
const h=home(t,{config:{text:{titlePrefix:'提醒',headlines:{default:'卡住了'},fields:{default:['task','code']},labels:{task:'工单'}}}});
|
|
279
|
+
assert.equal(notify(fields('custom'),{env:h.env,now:NOW}).sent,true);
|
|
280
|
+
assert(await h.until(()=>h.rows().length===1));
|
|
281
|
+
const [row]=h.rows();
|
|
282
|
+
assert.equal(row.title,'提醒 cm-fix 卡住了 · demo-app');assert.equal(row.body,'工单:T-001\n原因:checks_not_passed');
|
|
283
|
+
assert.equal(row.stdin.title,row.title);assert.equal(row.stdin.body,row.body);assert.equal(row.stdin.runId,'run-1');
|
|
67
284
|
});
|
|
68
285
|
|
|
69
286
|
test('sends through env and stdin once per key; the same key within 6 hours is skipped',async t=>{
|
|
@@ -112,6 +329,78 @@ test('command failure, timeout and broken state never throw; they log one line w
|
|
|
112
329
|
for(const h of [failing,slow,missing,broken])assert(!/demo-app|T-001|核对|run-1/.test(h.log()));
|
|
113
330
|
});
|
|
114
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
|
+
|
|
115
404
|
// Lock contention never waits; only a provably stale lock is reclaimed, and
|
|
116
405
|
// a live lock is never removed.
|
|
117
406
|
test('lock: a live lock skips at once and is kept; a stale lock is reclaimed safely',async t=>{
|
|
@@ -373,48 +662,48 @@ await serveCmAiHost({host,input:process.stdin,output:process.stdout});`);
|
|
|
373
662
|
const op=(n,answer,extra={})=>({requestId:`r${n}`,operation:'advance',answer,...extra});
|
|
374
663
|
|
|
375
664
|
test('host session idle after a finished step notifies once: 疑似空转 for progress, 在等你 for a person',async t=>{
|
|
376
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
377
|
-
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]]);
|
|
378
667
|
assert.equal(progress.code,0);
|
|
379
668
|
assert(await h.until(()=>h.rows().length===1));
|
|
380
669
|
const [idle]=h.rows();
|
|
381
670
|
assert.equal(idle.title,'CM cm-prd 疑似空转 · '+path.basename(process.cwd()));
|
|
382
671
|
assert.equal(idle.stdin.event,'idle');assert.equal(idle.stdin.code,'no_next_step');
|
|
383
672
|
assert.equal(idle.stdin.runId,'prd-1');assert.equal(idle.stdin.stage,'requirements_analysis');
|
|
384
|
-
const waiting=home(t,{config:{idleMinutes:0.
|
|
385
|
-
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]]);
|
|
386
675
|
assert.equal(review.code,0);
|
|
387
676
|
assert(await waiting.until(()=>waiting.rows().length===1));
|
|
388
677
|
assert.equal(waiting.rows()[0].title,'CM cm-prd 在等你 · '+path.basename(process.cwd()));
|
|
389
678
|
assert.equal(waiting.rows()[0].stdin.event,'idle_waiting');assert.equal(waiting.rows()[0].stdin.code,'waiting_for_you');
|
|
390
|
-
await new Promise(resolve=>setTimeout(resolve,
|
|
679
|
+
await new Promise(resolve=>setTimeout(resolve,900));
|
|
391
680
|
assert.equal(h.rows().length,1);assert.equal(waiting.rows().length,1);
|
|
392
681
|
});
|
|
393
682
|
|
|
394
683
|
test('host session idle: next step, in-flight step and session end clear it; status polls do not',async t=>{
|
|
395
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
684
|
+
const h=home(t,{config:{idleMinutes:0.009}}),run=idleHost(h);
|
|
396
685
|
// Steady progress: each next operation arrives before the threshold.
|
|
397
|
-
const steady=[];for(let n=1;n<=6;n++)steady.push([n===1?0:
|
|
398
|
-
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);
|
|
399
688
|
// A long in-flight operation is not idleness; ending right after its reply clears the timer.
|
|
400
|
-
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);
|
|
401
690
|
// A slow next operation: its arrival clears the timer armed by the previous reply.
|
|
402
|
-
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);
|
|
403
692
|
// A cancel reply while another operation is still in flight does not arm it.
|
|
404
|
-
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);
|
|
405
694
|
// Driver shape: EOF right after the reply arrived.
|
|
406
695
|
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],['reply:r1',null]])).code,0);
|
|
407
696
|
// A line the host rejects (not JSON, unknown operation) is still the session's next step.
|
|
408
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[
|
|
409
|
-
assert.equal((await run([[0,op(1,{stage:'requirements_analysis'})],[
|
|
410
|
-
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));
|
|
411
700
|
assert.equal(h.rows().length,0,h.log());
|
|
412
701
|
// Polls (status via the control path, fix_status via the normal path) neither
|
|
413
702
|
// hold the timer off nor replace the last real step's result.
|
|
414
703
|
for(const poll of ['status','fix_status']){
|
|
415
704
|
const polls=[[0,op(1,{stage:'requirements_analysis',runId:`run-${poll}`})]];
|
|
416
|
-
for(let n=0;n<12;n++)polls.push([
|
|
417
|
-
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);
|
|
418
707
|
assert(await h.until(()=>h.rows().some(row=>row.stdin.runId===`run-${poll}`)));
|
|
419
708
|
const row=h.rows().find(row=>row.stdin.runId===`run-${poll}`);
|
|
420
709
|
assert.equal(row.stdin.event,'idle');assert.equal(row.stdin.stage,'requirements_analysis');
|
|
@@ -425,8 +714,8 @@ test('host session idle: next step, in-flight step and session end clear it; sta
|
|
|
425
714
|
// A poll that is still running when the deadline passes holds the notice; it
|
|
426
715
|
// goes out right after the poll replies, not during it.
|
|
427
716
|
test('host session idle: a slow status in flight holds the notice until it replies',async t=>{
|
|
428
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
429
|
-
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]]);
|
|
430
719
|
assert.equal(result.code,0);
|
|
431
720
|
const doneAt=JSON.parse(result.stdout.split('\n').find(line=>line.includes('"requestId":"s1"'))).result.doneAt;
|
|
432
721
|
assert(await h.until(()=>h.rows().length===1));
|
|
@@ -436,7 +725,7 @@ test('host session idle: a slow status in flight holds the notice until it repli
|
|
|
436
725
|
|
|
437
726
|
// Tool-bridge sessions end with host_close from the driver: exit 0, no notice.
|
|
438
727
|
test('host session idle: host_close ends the session cleanly without a notice',async t=>{
|
|
439
|
-
const h=home(t,{config:{idleMinutes:0.
|
|
728
|
+
const h=home(t,{config:{idleMinutes:0.009}});
|
|
440
729
|
const script=path.join(h.dir,'cm-demo-host.mjs');
|
|
441
730
|
fs.writeFileSync(script,`import {serveCmAiHost} from ${JSON.stringify(HOST_SESSION)};
|
|
442
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);
|