dsh-notify-say 0.4.63 → 0.4.64
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 +13 -1
- package/package.json +1 -1
- package/test/jobs-api-contract.test.mjs +61 -0
package/CHANGELOG.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -1263,7 +1263,19 @@ function hasVoiceLine(psKind) {
|
|
|
1263
1263
|
let agents = [];
|
|
1264
1264
|
try {
|
|
1265
1265
|
const js = svc('jobs');
|
|
1266
|
-
if (js && typeof js.list === 'function')
|
|
1266
|
+
if (js && typeof js.list === 'function') {
|
|
1267
|
+
// ⚠️ 必须传 **agent.id 字符串**,不能传 agent 对象。
|
|
1268
|
+
// DSH 官方用法是 jobs.list(agent?.id)(见 app.asar 的 updateTaskControl),
|
|
1269
|
+
// 传对象会让它返回空数组 → 空闲门永远判定「没有在飞工作」→
|
|
1270
|
+
// 回合一结束就播报(2026-10-19 用户演示空闲门时实测抓到)。
|
|
1271
|
+
// 单测没发现:测试直接喂 collectInFlight 的假数据,绕过了本函数。
|
|
1272
|
+
//
|
|
1273
|
+
// 另照官方做法补查「无 agent 的全局任务」——有些后台任务不属于任何 agent。
|
|
1274
|
+
const aid = agent && agent.id !== undefined ? agent.id : undefined;
|
|
1275
|
+
const mine = js.list(aid) || [];
|
|
1276
|
+
const glob = aid === undefined ? [] : (js.list(undefined) || []);
|
|
1277
|
+
jobs = mine.concat(glob);
|
|
1278
|
+
}
|
|
1267
1279
|
} catch (e) {
|
|
1268
1280
|
console.warn('[dsh-notify-say] jobs.list failed: ' + String((e && e.message) || e));
|
|
1269
1281
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-say",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.64",
|
|
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,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.4.64:锁住 jobs.list 的调用参数。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么必须单独写这条测试
|
|
5
|
+
*
|
|
6
|
+
* 空闲门(idleGate)从 v0.4.62 起就有一个**静默失效**的 bug:
|
|
7
|
+
*
|
|
8
|
+
* jobs = js.list(agent) // ✗ 传了 agent 对象
|
|
9
|
+
* jobs = js.list(agent?.id) // ✓ 应传 id 字符串(DSH 官方用法)
|
|
10
|
+
*
|
|
11
|
+
* 参数类型不对 → 服务返回空数组 → `collectInFlight` 永远判定没有在飞工作
|
|
12
|
+
* → 空闲门从不挂起,回合一结束就播报。
|
|
13
|
+
*
|
|
14
|
+
* **原有 20+ 条空闲门单测全部通过**,因为它们是直接给 `collectInFlight`
|
|
15
|
+
* 喂假数据的 —— 绕过了 `jobs.list` 这一层。这正是"测试绿但功能坏"的典型:
|
|
16
|
+
* 测了纯函数,没测调用契约。
|
|
17
|
+
*
|
|
18
|
+
* 所以这条测试不看行为,只看**传参形状**(静态断言源码)。丑,但有效。
|
|
19
|
+
*/
|
|
20
|
+
import { test } from 'node:test';
|
|
21
|
+
import assert from 'node:assert/strict';
|
|
22
|
+
import { readFileSync } from 'node:fs';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
import { dirname, join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
27
|
+
const INDEX = readFileSync(join(ROOT, 'lib/index.js'), 'utf8');
|
|
28
|
+
|
|
29
|
+
/** 从 inFlightOf 函数体里切片(到下一个同名缩进级 function 为止)。 */
|
|
30
|
+
function inFlightBody() {
|
|
31
|
+
const start = INDEX.indexOf('function inFlightOf(agent) {');
|
|
32
|
+
assert.ok(start >= 0, '应能找到 inFlightOf');
|
|
33
|
+
const rest = INDEX.slice(start);
|
|
34
|
+
const end = rest.search(/\n {0,4}(?:function |\/\*\*)/);
|
|
35
|
+
return end > 0 ? rest.slice(0, end) : rest.slice(0, 3000);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('J1: jobs.list 必须传 agent.id,不能传 agent 对象', () => {
|
|
39
|
+
const body = inFlightBody();
|
|
40
|
+
// ✗ 绝不能出现 js.list(agent) —— 参数是对象
|
|
41
|
+
assert.doesNotMatch(body, /js\.list\(\s*agent\s*\)/,
|
|
42
|
+
'jobs.list 收到 agent 对象会返回空数组,导致空闲门永不挂起(v0.4.62 起的真 bug)');
|
|
43
|
+
// ✓ 必须取出 id 再传
|
|
44
|
+
assert.match(body, /const aid = agent && agent\.id/,
|
|
45
|
+
'必须先取 agent.id');
|
|
46
|
+
assert.match(body, /js\.list\(aid\)/,
|
|
47
|
+
'必须用 id 字符串调用 jobs.list');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('J2: 还要查「无 agent 的全局任务」', () => {
|
|
51
|
+
const body = inFlightBody();
|
|
52
|
+
// DSH 官方是 [void 0, ...liveAgents],插件对应 jobs.list(undefined)
|
|
53
|
+
assert.match(body, /js\.list\(undefined\)/,
|
|
54
|
+
'有些后台任务不属于任何 agent,只查当前 agent 会漏掉它们');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('J3: jobs.list 抛异常时不能把空闲门打挂', () => {
|
|
58
|
+
const body = inFlightBody();
|
|
59
|
+
assert.match(body, /catch\s*\(e\)\s*\{[\s\S]*?jobs\.list failed/,
|
|
60
|
+
'失败要 catch 住并记录,不能冒泡(否则回合一结束就抛错、通知丢失)');
|
|
61
|
+
});
|