dsh-notify-say 0.4.65 → 0.4.67
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/CHANGELOG.md +4 -0
- package/lib/index.js +2793 -2578
- package/package.json +1 -1
- package/test/error-notify-contract.test.mjs +154 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-say",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.67",
|
|
4
4
|
"description": "Desktop notifications for DSH Desktop that actually speak: Windows TTS out of the box (zero download), VOICEVOX voice packs optional, a selectable system-sound fallback, and an idle gate that waits for running subagents before saying the turn is done. Includes a settings-page GUI (sound source, per-event overrides, jump-back-to-session, cooldowns) and a self hot-reload for development.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 第 2 批 P0 的契约测试(2026-10-19 外部审查发现的错误漏播缺陷)。
|
|
3
|
+
*
|
|
4
|
+
* 三个 P0:
|
|
5
|
+
* ① 失败通知被完成的 60 秒去抖压制
|
|
6
|
+
* ② 后台 job failed 无独立播报路径
|
|
7
|
+
* ③ 缺 reason 默认 completed + 复用旧 reason
|
|
8
|
+
*
|
|
9
|
+
* 这些是**判定协议**(谁该播、谁不该播、播成什么等级),
|
|
10
|
+
* 按纪律必须断言 exact state + exact reason code + negative path,
|
|
11
|
+
* 不能用「多个可接受结果之一」的宽松断言。
|
|
12
|
+
*/
|
|
13
|
+
import { test } from 'node:test';
|
|
14
|
+
import assert from 'node:assert/strict';
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { dirname, join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
20
|
+
const INDEX = readFileSync(join(ROOT, 'lib/index.js'), 'utf8');
|
|
21
|
+
|
|
22
|
+
function fnBody(sig) {
|
|
23
|
+
const lines = INDEX.split(/\r?\n/);
|
|
24
|
+
const i = lines.findIndex((l) => l.includes(sig));
|
|
25
|
+
assert.ok(i >= 0, '找不到函数: ' + sig);
|
|
26
|
+
const indent = (lines[i].match(/^(\s*)/) || ['', ''])[1];
|
|
27
|
+
let j = -1;
|
|
28
|
+
for (let k = i + 1; k < lines.length; k++) {
|
|
29
|
+
if (lines[k] === indent + '}') { j = k; break; }
|
|
30
|
+
}
|
|
31
|
+
assert.ok(j > i, '找不到函数终点: ' + sig);
|
|
32
|
+
return lines.slice(i, j + 1).join('\n');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ══ P0-① 去抖按等级分桶 ═════════════════════════════════════════════════
|
|
36
|
+
test('P1: 去抖必须按通知等级分桶(fail 不被 done 压制)', () => {
|
|
37
|
+
const body = fnBody('function emitDone(');
|
|
38
|
+
assert.match(body, /const tier = psKind === 'fail' \? 'fail' : 'done'/,
|
|
39
|
+
'必须从 psKind 推导等级');
|
|
40
|
+
assert.match(body, /const tierKey = key \+/,
|
|
41
|
+
'必须有桶键');
|
|
42
|
+
assert.match(body, /isRecent\(lastTurnNotify, tierKey,/,
|
|
43
|
+
'去抖判定必须用桶键,不能用裸 key(裸 key 会让失败被完成吞掉)');
|
|
44
|
+
// 负路径:不得再出现用裸 key 做判定
|
|
45
|
+
assert.doesNotMatch(body, /isRecent\(lastTurnNotify, key, now/,
|
|
46
|
+
'不能退回用裸 session key 去抖');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('P2: 去抖记录也必须用桶键', () => {
|
|
50
|
+
const body = fnBody('function emitDone(');
|
|
51
|
+
assert.match(body, /rememberAt\(lastTurnNotify, tierKey, now\)/,
|
|
52
|
+
'记录必须用桶键,否则分桶不生效');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// ══ P0-② 后台 job failed 独立提醒 ═══════════════════════════════════════
|
|
56
|
+
test('P3: 必须有 handleJobFailure 且只处理 status=failed', () => {
|
|
57
|
+
const body = fnBody('function handleJobFailure(');
|
|
58
|
+
assert.match(body, /!== 'failed'/, '只处理 failed');
|
|
59
|
+
assert.match(body, /failedJobNotified/, '必须按 job 去重');
|
|
60
|
+
assert.match(body, /jobfail:/, 'evKey 要用 job 粒度');
|
|
61
|
+
// 必须是 fail 等级(走失败语音),不是 done
|
|
62
|
+
assert.match(body, /'fail'/, '必须用 fail 等级播报');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('P4: jobs 事件回调必须调用 handleJobFailure', () => {
|
|
66
|
+
const idx = INDEX.indexOf("js.events.subscribe({ owners: 'all' }");
|
|
67
|
+
assert.ok(idx > 0, '找不到 jobs 订阅');
|
|
68
|
+
const seg = INDEX.slice(idx, idx + 1200);
|
|
69
|
+
assert.match(seg, /handleJobFailure\(event\)/,
|
|
70
|
+
'订阅回调必须检查 job 失败,否则后台失败没有声音');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('P5: job 失败不受空闲门约束(直接 emitDone)', () => {
|
|
74
|
+
const body = fnBody('function handleJobFailure(');
|
|
75
|
+
assert.match(body, /emitDone\(/, 'job 失败要直接播报');
|
|
76
|
+
assert.doesNotMatch(body, /scheduleOrNotify\(/,
|
|
77
|
+
'不能走空闲门 —— 错误必须立刻提醒,不能等工作树空了');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// ══ P0-③ reason 完整性 ═════════════════════════════════════════════════
|
|
81
|
+
test('P6: 缺 reason 不得默认 completed', () => {
|
|
82
|
+
assert.doesNotMatch(INDEX, /rec && rec\.kind \? rec\.kind : 'completed'/,
|
|
83
|
+
'「取不到 reason 就当完成」会把错误播成成功,方向性错误');
|
|
84
|
+
const idx = INDEX.indexOf('reason-missing');
|
|
85
|
+
assert.ok(idx > 0, '缺 reason 时必须留痕');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('P7: reason 消费后必须删除(防跨轮复用)', () => {
|
|
89
|
+
const idx = INDEX.indexOf('lastTurnEnd.delete(');
|
|
90
|
+
assert.ok(idx > 0, 'lastTurnEnd 必须消费即删除,否则下一轮会复用旧 reason');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('P8: reason 的读写必须用同一个键', () => {
|
|
94
|
+
// 2026-10-19 回归实测:写入用 sessionKey(session),读取用 agent.id,
|
|
95
|
+
// 两者不等时(测试环境 agent-1 / sess-1)rec 永远 undefined。
|
|
96
|
+
const writeIdx = INDEX.indexOf('rememberBounded(lastTurnEnd');
|
|
97
|
+
assert.ok(writeIdx > 0);
|
|
98
|
+
const wseg = INDEX.slice(writeIdx, writeIdx + 300);
|
|
99
|
+
assert.match(wseg, /sessionKey\(session\)/, '写入用 sessionKey(session)');
|
|
100
|
+
|
|
101
|
+
// 按行检查:调用参数里必须出现 sessionKey(agent.session)
|
|
102
|
+
const callLines = INDEX.split(/\r?\n/).filter((l) => /lastTurnEnd\.(get|delete)\(/.test(l));
|
|
103
|
+
assert.ok(callLines.length >= 2, '至少有读取与删除');
|
|
104
|
+
for (const ln of callLines) {
|
|
105
|
+
assert.ok(ln.includes('sessionKey(agent.session)'),
|
|
106
|
+
'读写键必须一致(写入侧用 sessionKey(session),读取侧必须对应),实际: ' + ln.trim());
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('P9: 轮次校验拿不到时按放行处理(不能丢通知)', () => {
|
|
111
|
+
assert.match(INDEX, /canVerifyTurn/,
|
|
112
|
+
'要区分「能校验」和「拿不到轮次」两种情况');
|
|
113
|
+
// 必须有明确的「拿不到就放行」逻辑
|
|
114
|
+
assert.match(INDEX, /turnOk === false/,
|
|
115
|
+
'只有明确判定为过时才拒绝;undefined 要放行');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// ══ P1 播放层可观测(2.4 / 2.6)══════════════════════════════════════════
|
|
119
|
+
test('P10: spawn 必须记录退出码(不能把"启动了"当"播成了")', () => {
|
|
120
|
+
const body = fnBody('function spawnNotify(args, psKind) {');
|
|
121
|
+
assert.match(body, /child\.once\('exit', \(code, signal\)/, '要接退出码与信号');
|
|
122
|
+
assert.match(body, /play-ok/, '成功要留痕');
|
|
123
|
+
assert.match(body, /play-fail/, '失败必须留痕');
|
|
124
|
+
assert.match(body, /exit=/, '失败日志要含退出码');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('P11: spawn 必须收 stderr(否则不知道为什么失败)', () => {
|
|
128
|
+
const body = fnBody('function spawnNotify(args, psKind) {');
|
|
129
|
+
assert.match(body, /'pipe'/, 'stderr 必须 pipe,不能全 ignore');
|
|
130
|
+
assert.match(body, /stderrTail/, '要收集 stderr 尾部');
|
|
131
|
+
assert.match(body, /stderr=/, '失败日志要带 stderr');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('P12: 播放失败要有**一次**蜂鸣降级(且绝不重试)', () => {
|
|
135
|
+
assert.match(INDEX, /beepFallbackUsed/, '要有防重入标志');
|
|
136
|
+
const body = fnBody('function fallbackBeep(which) {');
|
|
137
|
+
assert.match(body, /if \(beepFallbackUsed\) return;/, '只降级一次');
|
|
138
|
+
assert.match(body, /beepFallbackUsed = true;/, '用了就置位');
|
|
139
|
+
// 负路径:不得出现重试循环
|
|
140
|
+
assert.doesNotMatch(body, /setTimeout|setInterval|for \(|while \(/, '不得重试(防通知风暴)');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('P13: 并发丢弃必须能定位是哪条通知', () => {
|
|
144
|
+
const body = fnBody('function spawnNotify(args, psKind) {');
|
|
145
|
+
const idx = body.indexOf('spawn-drop');
|
|
146
|
+
assert.ok(idx > 0, '要有 spawn-drop 留痕');
|
|
147
|
+
const seg = body.slice(idx, idx + 300);
|
|
148
|
+
assert.match(seg, /kind=/, 'spawn-drop 必须带 psKind,否则无法定位丢了什么');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('P14: spawnTts 要透传 psKind(TTS 失败也要能定位)', () => {
|
|
152
|
+
const body = fnBody('function spawnTts(args, psKind) {');
|
|
153
|
+
assert.match(body, /spawnNotify\(args, psKind\)/, 'spawnTts 必须透传 psKind');
|
|
154
|
+
});
|