dsh-notify-say 0.4.69 → 0.4.71

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-notify-say",
3
- "version": "0.4.69",
3
+ "version": "0.4.71",
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",
@@ -1,43 +1,51 @@
1
- /**
2
- * ESM loader stub:把 `node:child_process` 换成记录型假实现。
3
- *
4
- * 用途:`test/fail-route.test.mjs` 要断言 **lib/index.js 运行时到底给 ps1 传了什么参数**
5
- * (例如 error 回合是否真的传 `-Kind fail`)。若真去 spawn PowerShell:
6
- * ① 会弹 Toast / 出声,污染用户桌面;② 需要真实 SystemRoot,与同目录其他测试的
7
- * 隔离手法冲突(见踩坑 #424)。故在加载 lib 之前把这个模块注册为 loader,
8
- * 让 `spawn()` 只把参数记进 `globalThis.__SPAWN_CALLS`,不起任何进程。
9
- *
10
- * 为什么不用 monkey-patch:lib 用的是 ESM 具名导入
11
- * (`import { spawn } from 'node:child_process'`),导入绑定只读、不可重新赋值;
12
- * 只有 loader 层能在模块解析阶段替换它。
13
- *
14
- * 该文件**不是测试文件**(不以 .test. 命名),不会被 `node --test` 当用例执行。
15
- */
16
- export async function resolve(specifier, context, nextResolve) {
17
- if (specifier === 'node:child_process') {
18
- return { url: 'stub:child_process', shortCircuit: true };
19
- }
20
- return nextResolve(specifier, context);
21
- }
22
-
23
- export async function load(url, context, nextLoad) {
24
- if (url === 'stub:child_process') {
25
- const source = `
26
- // 记录每一次 spawn 的 (file, args) 供断言;返回一个不会真的启动进程的假句柄。
27
- export function spawn(file, args, options) {
28
- globalThis.__SPAWN_CALLS = globalThis.__SPAWN_CALLS || [];
29
- globalThis.__SPAWN_CALLS.push({ file, args: Array.isArray(args) ? args.slice() : args, options });
30
- return {
31
- pid: 424242,
32
- once() { return this; },
33
- on() { return this; },
34
- kill() { return true; },
35
- unref() { return this; },
36
- };
37
- }
38
- export default { spawn };
39
- `;
40
- return { format: 'module', shortCircuit: true, source };
41
- }
42
- return nextLoad(url, context);
43
- }
1
+ /**
2
+ * ESM loader stub:把 `node:child_process` 换成记录型假实现。
3
+ *
4
+ * 用途:`test/fail-route.test.mjs` 要断言 **lib/index.js 运行时到底给 ps1 传了什么参数**
5
+ * (例如 error 回合是否真的传 `-Kind fail`)。若真去 spawn PowerShell:
6
+ * ① 会弹 Toast / 出声,污染用户桌面;② 需要真实 SystemRoot,与同目录其他测试的
7
+ * 隔离手法冲突(见踩坑 #424)。故在加载 lib 之前把这个模块注册为 loader,
8
+ * 让 `spawn()` 只把参数记进 `globalThis.__SPAWN_CALLS`,不起任何进程。
9
+ *
10
+ * 为什么不用 monkey-patch:lib 用的是 ESM 具名导入
11
+ * (`import { spawn } from 'node:child_process'`),导入绑定只读、不可重新赋值;
12
+ * 只有 loader 层能在模块解析阶段替换它。
13
+ *
14
+ * 该文件**不是测试文件**(不以 .test. 命名),不会被 `node --test` 当用例执行。
15
+ */
16
+ export async function resolve(specifier, context, nextResolve) {
17
+ if (specifier === 'node:child_process') {
18
+ return { url: 'stub:child_process', shortCircuit: true };
19
+ }
20
+ return nextResolve(specifier, context);
21
+ }
22
+
23
+ export async function load(url, context, nextLoad) {
24
+ if (url === 'stub:child_process') {
25
+ const source = `
26
+ // 记录每一次 spawn 的 (file, args) 供断言;返回一个不会真的启动进程的假句柄。
27
+ export function spawn(file, args, options) {
28
+ globalThis.__SPAWN_CALLS = globalThis.__SPAWN_CALLS || [];
29
+ globalThis.__SPAWN_CALLS.push({ file, args: Array.isArray(args) ? args.slice() : args, options });
30
+ return {
31
+ pid: 424242,
32
+ once() { return this; },
33
+ on() { return this; },
34
+ kill() { return true; },
35
+ unref() { return this; },
36
+ };
37
+ }
38
+ // v0.4.70:插件新增 execFileSync(注册自定义协议时同步调 PowerShell)。
39
+ // 桩里也要提供,否则 import { execFileSync } 会在模块链接阶段报
40
+ // "does not provide an export named execFileSync"。同样只记录、不起进程。
41
+ export function execFileSync(file, args, options) {
42
+ globalThis.__SPAWN_CALLS = globalThis.__SPAWN_CALLS || [];
43
+ globalThis.__SPAWN_CALLS.push({ file, args: Array.isArray(args) ? args.slice() : args, options, sync: true });
44
+ return Buffer.from('');
45
+ }
46
+ export default { spawn, execFileSync };
47
+ `;
48
+ return { format: 'module', shortCircuit: true, source };
49
+ }
50
+ return nextLoad(url, context);
51
+ }
@@ -99,21 +99,31 @@ test('T9: consume 取走整个队列并清空,同时保留旧字段', () => {
99
99
  });
100
100
 
101
101
  // ══ T10-T12:规则选择 ═══════════════════════════════════════════════════
102
- test('T10: pickJumpTarget 三种规则 + 单会话不受规则影响', () => {
102
+ test('T10: pickJumpTarget 规则 + 单会话不受规则影响', () => {
103
103
  const fn = grab(CLIENT, 'function pickJumpTarget(list, rule) {', '\n }\n');
104
104
  assert.match(fn, /if \(list\.length === 1\) return list\[0\]/, '单会话必须直接返回它');
105
105
  assert.match(fn, /if \(rule === 'none'\) return null/, 'none 返回 null');
106
106
  assert.match(fn, /if \(rule === 'latest'\) return sorted\[sorted\.length - 1\]/, 'latest 取末尾');
107
- assert.match(fn, /return sorted\[0\]/, '默认(含未知规则)取最早');
107
+ assert.match(fn, /return sorted\[0\]/, 'earliest 取最早(也是 clicked 没命中时的兜底)');
108
108
  });
109
109
 
110
- test('T11: 默认规则是 earliest(服务端与客户端一致)', () => {
111
- assert.match(SCHEMA, /multiJumpRule: 'earliest'/, 'FIELD_DEFAULTS 必须是 earliest');
110
+ test('T11: 默认规则是 clicked(点哪个跳哪个)', () => {
111
+ // v0.4.70:默认从 earliest 改为 clicked —— 多会话时用户点的是具体某个 Toast,
112
+ // 按时间排序猜必然猜错。clicked 用 Toast 自带的 session id,精确。
113
+ assert.match(SCHEMA, /multiJumpRule: 'clicked'/, 'FIELD_DEFAULTS 必须是 clicked');
112
114
  // ⚠️ schemastery 没有 z.enum,必须是 union+const(踩坑:z.enum 直接 TypeError)
113
- assert.match(SCHEMA, /\.union\(\[z\.const\('earliest'\), z\.const\('latest'\), z\.const\('none'\)\]\)/, '三值用 union+const');
115
+ assert.match(SCHEMA, /\.union\(\[z\.const\('clicked'\), z\.const\('earliest'\), z\.const\('latest'\), z\.const\('none'\)\]\)/, '四值用 union+const');
114
116
  assert.doesNotMatch(SCHEMA, /z\.enum\(/, 'schemastery 不支持 z.enum');
115
- assert.match(CLIENT, /typeof v\.multiJumpRule === 'string' \? v\.multiJumpRule : 'earliest'/, '客户端兜底也得是 earliest');
116
- assert.match(CLIENT, /var curRule = typeof v\.multiJumpRule === 'string' \? v\.multiJumpRule : 'earliest'/, 'GUI 兜底也得是 earliest');
117
+ assert.match(CLIENT, /var curRule = typeof v\.multiJumpRule === 'string' \? v\.multiJumpRule : 'clicked'/, 'GUI 兜底也得是 clicked');
118
+ });
119
+
120
+ test('T11b: clicked 必须排在选项第一位(默认项)', () => {
121
+ const m = CLIENT.match(/var JUMP_RULES = \[([\s\S]*?)\]/);
122
+ assert.ok(m, '要有 JUMP_RULES');
123
+ assert.match(m[1], /\['clicked'/, 'clicked 要出现在选项里');
124
+ // 第一位 = 默认选中项
125
+ const first = m[1].match(/\['([a-z]+)'/);
126
+ assert.equal(first[1], 'clicked', 'clicked 必须在第一位');
117
127
  });
118
128
 
119
129
  test('T12: 客户端能同时吃新队列和旧单条响应', () => {
@@ -130,3 +140,29 @@ test('T13: multiJumpRule 在 schema/store/index 三处白名单与透传都在',
130
140
  assert.match(store, /multiJumpRule: cfg\.multiJumpRule,/, 'config-store 透传');
131
141
  assert.match(INDEX, /multiJumpRule: g\.multiJumpRule,/, 'effectiveForClient 透传');
132
142
  });
143
+
144
+ // ══ v0.4.71:前台点 Toast 也要跳 ════════════════════════════════════════
145
+ test('T14: 必须有 tryTopJump(不依赖 visibilitychange)', () => {
146
+ // 用户 2026-10-19 指出:窗口一直在前台时点 Toast,visibilitychange 不触发,
147
+ // 于是跳不过去。而"在前台点 Toast 直接过去看结果"恰恰是最省事的用法。
148
+ assert.match(CLIENT, /function tryTopJump\(\)/, '要有前台跳转入口');
149
+ const m = CLIENT.match(/function tryTopJump\(\)([\s\S]{0,900})/);
150
+ assert.ok(m, '能读到函数体');
151
+ assert.match(m[1], /fetchPendingJump\(\)/, '要读 pending-jump');
152
+ assert.match(m[1], /openSession\(/, '要真的跳');
153
+ assert.match(m[1], /lastTopJumpCheck/, '要有节流,避免 focus 抖动打爆请求');
154
+ });
155
+
156
+ test('T15: focus 与 mousedown 监听都要注册且要能移除', () => {
157
+ assert.match(CLIENT, /addEventListener\('focus', tryTopJump\)/, 'window focus 要监听');
158
+ assert.match(CLIENT, /addEventListener\('mousedown', tryTopJump/, 'document mousedown 要监听');
159
+ // 闭环:卸载时必须移除,否则热重载会叠监听
160
+ assert.match(CLIENT, /removeEventListener\('focus', tryTopJump\)/, '卸载要移除 focus');
161
+ assert.match(CLIENT, /removeEventListener\('mousedown', tryTopJump\)/, '卸载要移除 mousedown');
162
+ });
163
+
164
+ test('T16: 前台跳转必须有 120 秒过期保护', () => {
165
+ const m = CLIENT.match(/function tryTopJump\(\)([\s\S]{0,900})/);
166
+ assert.ok(m);
167
+ assert.match(m[1], /120000/, '超过 120 秒的点击不该跳(避免久等后突然跳走)');
168
+ });