dsh-notify-say 0.5.7 → 0.5.9
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 +10 -1
- package/README.md +80 -59
- package/dsh-notify.ps1 +72 -7
- package/package.json +78 -80
- package/test/docs-consistency.test.mjs +122 -7
- package/test/fail-voice.test.mjs +2 -1
- package/test/ps-interp.mjs +55 -0
- package/test/ps-runtime-interp.test.mjs +214 -0
- package/test/release-voice-guard.test.mjs +18 -12
- package/test/toast-aumid.test.mjs +121 -0
- package/test/voice-fallback.test.mjs +2 -1
- package/test/voice-label.test.mjs +2 -1
- package/test/wav-gain.test.mjs +2 -1
- package/tools/notify-config.ps1 +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
> 本文件由 `tools/release-build.ps1` 从开发提交自动生成,**请勿手工编辑**。
|
|
4
4
|
> 只列面向使用者的变更(新增功能与修复),不含内部维护提交。
|
|
5
5
|
|
|
6
|
+
## v0.5.8 — 2026-11-24
|
|
7
|
+
|
|
8
|
+
- feat(ps7): 统一到 PowerShell 7 —— 四层防呆 + C7 静态闸(ADR-0015)
|
|
9
|
+
- fix(ps7): 运行时脚本不再带 #Requires 7.0,测试按两解释器分工(踩坑 #494)
|
|
10
|
+
- feat(ps7): 用户 CLI notify-config.ps1 退回 5.1 兼容 —— 它随 npm 包发给用户,而 Windows 出厂只有 5.1
|
|
11
|
+
- fix(release): release.ps1 用 pwsh 启动 release-build.ps1,否则 0.5.8 发版第 3 步必挂
|
|
12
|
+
|
|
6
13
|
## v0.5.7 — 2026-11-23
|
|
7
14
|
|
|
8
15
|
- fix(notify-say): #5 PTC/code-mode 下提问提醒永不触发(v0.5.7)
|
|
16
|
+
- fix(release): 发布包的 scripts 改为继承源,别让 L8 卡死发版
|
|
9
17
|
|
|
10
18
|
## v0.5.6 — 2026-11-23
|
|
11
19
|
|
|
@@ -346,5 +354,6 @@
|
|
|
346
354
|
|
|
347
355
|
## 未发布
|
|
348
356
|
|
|
349
|
-
- fix(
|
|
357
|
+
- fix(ci): Node 20 静态 import globSync 导致 CI 连红四次,加 D20 判据锁住
|
|
358
|
+
- fix(toast): 收录 PR #4 的发通知身份探测,并修其致命顺序 bug
|
|
350
359
|
|
package/README.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# dsh-notify-say
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-notify-say)
|
|
4
|
+
[](https://www.npmjs.com/package/dsh-notify-say)
|
|
5
|
+
[](https://github.com/unifilitence/dsh-notify-say/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/unifilitence/dsh-notify-say)
|
|
7
|
+
[](#安装)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
给 [DeepSeek Harness](https://github.com/deepseek-ai) Desktop 用的语音通知插件:**任务跑完会说话**。
|
|
4
11
|
|
|
5
12
|
> 别的通知插件"叮"一声;这个会喊你"任务完成了"。
|
|
6
13
|
> 而且**子代理还在跑的时候,它不会骗你说完成了**。
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
>
|
|
15
|
+
> *Desktop notifications for DSH Desktop (Windows) that actually speak — Windows TTS out of the box, optional VOICEVOX / Chinese voice packs, and an idle gate that waits for running subagents before saying "done".*
|
|
9
16
|
|
|
10
17
|

|
|
11
18
|
|
|
@@ -15,13 +22,13 @@
|
|
|
15
22
|
|
|
16
23
|
## 目录
|
|
17
24
|
|
|
25
|
+
- [安装(30 秒上手)](#安装)
|
|
26
|
+
- [快速开始](#快速开始)
|
|
18
27
|
- [它解决什么问题](#它解决什么问题)
|
|
19
28
|
- [特性](#特性)
|
|
20
|
-
- [安装](#安装)
|
|
21
|
-
- [快速开始](#快速开始)
|
|
22
29
|
- [配置](#配置)
|
|
23
30
|
- [语音包](#语音包)
|
|
24
|
-
- [关于"跳回会话"](
|
|
31
|
+
- [关于"跳回会话"](#关于跳回会话能做到什么做不到什么)
|
|
25
32
|
- [兼容性与降级](#兼容性与降级)
|
|
26
33
|
- [已知限制](#已知限制)
|
|
27
34
|
- [常见问题](#常见问题)
|
|
@@ -30,56 +37,14 @@
|
|
|
30
37
|
|
|
31
38
|
---
|
|
32
39
|
|
|
33
|
-
## 它解决什么问题
|
|
34
|
-
|
|
35
|
-
你让 AI 跑一个较长任务,然后切去干别的。常见两种通知插件的毛病:
|
|
36
|
-
|
|
37
|
-
1. **该响的时候不响** —— 主会话一轮结束就报"完成",但其实它派出的子代理还在跑,你回来发现没干完。
|
|
38
|
-
2. **不该响的时候一直响** —— 每个子代理结束都弹一次,连环轰炸。
|
|
39
|
-
|
|
40
|
-
本插件的做法:
|
|
41
|
-
|
|
42
|
-
- **空闲门(idle gate)**:主会话这轮结束、但仍有子代理或后台任务在跑时,**先不播**;等全部结束再播**一次**。超时兜底(默认 10 分钟),防子任务卡死导致永不播报。
|
|
43
|
-
- **按会话去抖**:同一会话默认 60 秒内只响一次。
|
|
44
|
-
- **失败单独提醒**:回合出错时播**日语道歉语音**(可选)—— 比"任务完成"更该让你立刻知道。
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## 特性
|
|
49
|
-
|
|
50
|
-
| 特性 | 说明 |
|
|
51
|
-
|---|---|
|
|
52
|
-
| **语音播报** | 播放本地 wav,**不调用云端 TTS**。发布版自带 2 个音色(1 日语 + 1 中文),另 15 个可在设置页按需下载 |
|
|
53
|
-
| **空闲门** | 有在飞工作时不误报"完成",全部结束才播一次 |
|
|
54
|
-
| **五类事件** | 完成 / 出错 / 被拦截 / 待批准 / 要提问,各自独立开关 |
|
|
55
|
-
| **设置页 GUI** | 走官方 `Config` schema,在 DSH 设置页里直接改,**改完立即生效** |
|
|
56
|
-
| **命令行** | `tools/notify-config.ps1`,适合脚本化与排查 |
|
|
57
|
-
| **切回窗口时跳会话** | 通知时你不在前台 → 你切回来时自动跳到那个会话(见[下文](#关于跳回会话)) |
|
|
58
|
-
| **点哪条通知就跳哪条** | 多会话同时完成时,点不同的 Toast 会落到各自的会话(**可选开关**,见[下文](#-能做到点哪条-toast-就跳哪条v0470-起v0483-稳定)) |
|
|
59
|
-
| **不装语音也能用** | 没有语音包 = Toast + 系统提示音,这是正常配置 |
|
|
60
|
-
| **许可先告知** | 下载音色前弹出条款确认,写明署名要求与官方条款链接 |
|
|
61
|
-
| **诊断导出** | 一键导出脱敏日志(用户名/路径已替换),方便提 Issue |
|
|
62
|
-
| **日志隐私分级** | 默认只记元数据,**不记台词正文**;要详细日志需手动开 debug |
|
|
63
|
-
| **检查更新** | 显示当前/最新版本,有新版时给出升级命令(**不自动更新**,见[下文](#有新版本了怎么办)) |
|
|
64
|
-
|
|
65
|
-
> **联网说明**:通知、播放、TTS **完全离线**。
|
|
66
|
-
> 会联网的只有两件事:
|
|
67
|
-
> ① **下载语音包**(访问 GitHub,只有你点「下载」时才发生)
|
|
68
|
-
> ② **检查更新**(访问 npm registry 与 GitHub,**每 24 小时最多一次**)
|
|
69
|
-
>
|
|
70
|
-
> 不想让它检查更新?不点「检查更新」就不会主动查;已缓存的 24 小时内也不会再查。
|
|
71
|
-
> 网络不可用时这两件事都会失败,但**不影响通知和语音**。
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
40
|
## 安装
|
|
76
41
|
|
|
77
42
|
### 前置
|
|
78
43
|
|
|
44
|
+
- **Windows**(Toast 用 WinRT,播放用 MCI,调用系统自带 Windows PowerShell 5.1,无需额外装 PS7)
|
|
79
45
|
- DSH Desktop **0.2.1-rc.2 ~ 0.3.0**(`>=0.2.1-rc.2 <0.3.0`)
|
|
80
46
|
- 实测环境:`0.2.1-rc.2`、`0.2.1-rc.5`、**`0.2.2-rc.1`**(2026-11 最新)。更早版本**未测过**,所以没有声明支持
|
|
81
47
|
- 设了上界 0.3.0:DSH 若有不兼容改动,市场会拦住而不是让你装了才发现
|
|
82
|
-
- Windows(Toast 用 WinRT,播放用 MCI,调用 Windows PowerShell 5.1)
|
|
83
48
|
|
|
84
49
|
### 方式一:插件页(推荐,不用命令行)
|
|
85
50
|
|
|
@@ -93,19 +58,19 @@
|
|
|
93
58
|
|
|
94
59
|
4. 点「**安装**」,装完重启 DSH
|
|
95
60
|
|
|
96
|
-
>
|
|
97
|
-
>
|
|
61
|
+
> 装的时候卡住或报网络错误?在同一个面板里把「**安装源**」切到「**中国大陆镜像源**」再试 —— 官方源在国内经常拉不动。
|
|
62
|
+
> 填 `dsh-notify-say` 是**包名**(不是搜索词)。它也能接受 GitHub 仓库地址或本机目录路径,但包名最简单。
|
|
98
63
|
|
|
99
|
-
>
|
|
100
|
-
>
|
|
64
|
+
<details>
|
|
65
|
+
<summary>方式二(npm)与方式三(本地源码 link 开发)</summary>
|
|
101
66
|
|
|
102
|
-
|
|
67
|
+
#### 方式二:npm
|
|
103
68
|
|
|
104
69
|
```
|
|
105
70
|
npm install dsh-notify-say
|
|
106
71
|
```
|
|
107
72
|
|
|
108
|
-
|
|
73
|
+
#### 方式三:手工 link(本地开发)
|
|
109
74
|
|
|
110
75
|
把本仓库目录链接进 profile:
|
|
111
76
|
|
|
@@ -117,6 +82,8 @@ D:\Program Files (x86)\DSH\profiles\desktop\package.json
|
|
|
117
82
|
|
|
118
83
|
然后在该 profile 目录执行 `pnpm install`,重启 DSH。
|
|
119
84
|
|
|
85
|
+
</details>
|
|
86
|
+
|
|
120
87
|
---
|
|
121
88
|
|
|
122
89
|
## 快速开始
|
|
@@ -137,6 +104,48 @@ D:\Program Files (x86)\DSH\profiles\desktop\package.json
|
|
|
137
104
|
|
|
138
105
|
---
|
|
139
106
|
|
|
107
|
+
## 它解决什么问题
|
|
108
|
+
|
|
109
|
+
你让 AI 跑一个较长任务,然后切去干别的。常见两种通知插件的毛病:
|
|
110
|
+
|
|
111
|
+
1. **该响的时候不响** —— 主会话一轮结束就报"完成",但其实它派出的子代理还在跑,你回来发现没干完。
|
|
112
|
+
2. **不该响的时候一直响** —— 每个子代理结束都弹一次,连环轰炸。
|
|
113
|
+
|
|
114
|
+
本插件的做法:
|
|
115
|
+
|
|
116
|
+
- **空闲门(idle gate)**:主会话这轮结束、但仍有子代理或后台任务在跑时,**先不播**;等全部结束再播**一次**。超时兜底(默认 10 分钟),防子任务卡死导致永不播报。
|
|
117
|
+
- **按会话去抖**:同一会话默认 60 秒内只响一次。
|
|
118
|
+
- **失败单独提醒**:回合出错时播**日语道歉语音**(可选)—— 比"任务完成"更该让你立刻知道。
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 特性
|
|
123
|
+
|
|
124
|
+
| 特性 | 说明 |
|
|
125
|
+
|---|---|
|
|
126
|
+
| **语音播报** | 播放本地 wav,**不调用云端 TTS**。发布版自带 2 个音色(1 日语 + 1 中文),另 15 个可在设置页按需下载 |
|
|
127
|
+
| **空闲门** | 有在飞工作时不误报"完成",全部结束才播一次 |
|
|
128
|
+
| **五类事件** | 完成 / 出错 / 被拦截 / 待批准 / 要提问,各自独立开关 |
|
|
129
|
+
| **设置页 GUI** | 走官方 `Config` schema,在 DSH 设置页里直接改,**改完立即生效** |
|
|
130
|
+
| **命令行** | `tools/notify-config.ps1`,适合脚本化与排查 |
|
|
131
|
+
| **切回窗口时跳会话** | 通知时你不在前台 → 你切回来时自动跳到那个会话(见[下文](#关于跳回会话能做到什么做不到什么)) |
|
|
132
|
+
| **点哪条通知就跳哪条** | 多会话同时完成时,点不同的 Toast 会落到各自的会话(**可选开关**,见[下文](#-能做到点哪条-toast-就跳哪条v0470-起v0483-稳定)) |
|
|
133
|
+
| **不装语音也能用** | 没有语音包 = Toast + 系统提示音,这是正常配置 |
|
|
134
|
+
| **许可先告知** | 下载音色前弹出条款确认,写明署名要求与官方条款链接 |
|
|
135
|
+
| **诊断导出** | 一键导出脱敏日志(用户名/路径已替换),方便提 Issue |
|
|
136
|
+
| **日志隐私分级** | 默认只记元数据,**不记台词正文**;要详细日志需手动开 debug |
|
|
137
|
+
| **检查更新** | 显示当前/最新版本,有新版时给出升级命令(**不自动更新**,见[下文](#常见问题)) |
|
|
138
|
+
|
|
139
|
+
> **联网说明**:通知、播放、TTS **完全离线**。
|
|
140
|
+
> 会联网的只有两件事:
|
|
141
|
+
> ① **下载语音包**(访问 GitHub,只有你点「下载」时才发生)
|
|
142
|
+
> ② **检查更新**(访问 npm registry 与 GitHub,**每 24 小时最多一次**)
|
|
143
|
+
>
|
|
144
|
+
> 不想让它检查更新?不点「检查更新」就不会主动查;已缓存的 24 小时内也不会再查。
|
|
145
|
+
> 网络不可用时这两件事都会失败,但**不影响通知和语音**。
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
140
149
|
## 配置
|
|
141
150
|
|
|
142
151
|
四种来源,**优先级由低到高**(后者覆盖前者):
|
|
@@ -167,7 +176,8 @@ D:\Program Files (x86)\DSH\profiles\desktop\package.json
|
|
|
167
176
|
音色自动归到「中文」(依据是音色名以 `zh-` 开头)。这条只在你的配置里**没有**语音
|
|
168
177
|
语言这个键时生效 —— 自己显式选过的语言永远不会被覆盖。
|
|
169
178
|
|
|
170
|
-
|
|
179
|
+
<details>
|
|
180
|
+
<summary>命令行配置(<code>tools/notify-config.ps1</code>,适合脚本化与排查)</summary>
|
|
171
181
|
|
|
172
182
|
```powershell
|
|
173
183
|
cd <插件目录>\tools
|
|
@@ -183,6 +193,13 @@ cd <插件目录>\tools
|
|
|
183
193
|
|
|
184
194
|
改完**立即生效**,不需要重启 DSH。
|
|
185
195
|
|
|
196
|
+
**PowerShell 版本**:这些命令用 Windows 自带的 PowerShell 5.1 就行,**不需要装
|
|
197
|
+
PowerShell 7**。如果你装了 7,用 `pwsh` 跑也一样。插件的所有脚本都按 5.1 兼容维护 ——
|
|
198
|
+
本插件的运行本来就依赖 5.1(Toast 通知走 WinRT,只有 5.1 有),所以不会出现
|
|
199
|
+
「装了插件还得额外装个 PowerShell 7」的情况。
|
|
200
|
+
|
|
201
|
+
</details>
|
|
202
|
+
|
|
186
203
|
---
|
|
187
204
|
|
|
188
205
|
## 语音包
|
|
@@ -269,8 +286,7 @@ sounds/voice-lines/fail/<key>~1.wav 出错
|
|
|
269
286
|
## 关于"跳回会话":能做到什么,做不到什么
|
|
270
287
|
|
|
271
288
|
这一节把边界写清楚 —— 有些事是**宿主没给接口**,不是本插件偷懒。
|
|
272
|
-
|
|
273
|
-
不能做到「点哪条通知就跳哪条」。**
|
|
289
|
+
结论先给:**默认能在你切回窗口时跳到「离开期间最早完成」的会话;打开显式开关后,也能做到「点哪条 Toast 就跳哪条」。**
|
|
274
290
|
|
|
275
291
|
### ✅ 能做到:切回窗口时跳到那个会话
|
|
276
292
|
|
|
@@ -553,6 +569,9 @@ Windows 自定义协议只能在插件**被加载时**注册/清理,而 DSH
|
|
|
553
569
|
|
|
554
570
|
## 开发
|
|
555
571
|
|
|
572
|
+
<details>
|
|
573
|
+
<summary>展开查看:跑测试(694 条)、测试分层、CI 与发版流程</summary>
|
|
574
|
+
|
|
556
575
|
### 跑测试
|
|
557
576
|
|
|
558
577
|
```powershell
|
|
@@ -562,7 +581,7 @@ npm run test:route # 需要 --import loader 的接线测试
|
|
|
562
581
|
npm run test:audio-wire
|
|
563
582
|
```
|
|
564
583
|
|
|
565
|
-
**
|
|
584
|
+
**705 条测试通过**(`test:all` 两段实测:主套件 651 = 615 passed + 36 skipped 需真实宿主;
|
|
566
585
|
route 注入段 54 = 53 passed + 1 skipped)。
|
|
567
586
|
绝大多数是纯逻辑测试,克隆仓库后 `npm test` 即可跑。
|
|
568
587
|
|
|
@@ -616,6 +635,8 @@ npm test
|
|
|
616
635
|
`CHANGELOG.md` 由 `release-build.ps1` **自动生成**(从开发提交提取标题,
|
|
617
636
|
过滤掉内部资料与 hash),随包发布。**请勿手工编辑**。
|
|
618
637
|
|
|
638
|
+
</details>
|
|
639
|
+
|
|
619
640
|
---
|
|
620
641
|
|
|
621
642
|
## 许可
|
package/dsh-notify.ps1
CHANGED
|
@@ -449,6 +449,60 @@ function Write-NotifyLog([string]$KindTag, [string]$Extra, [string]$Detail) {
|
|
|
449
449
|
# 2026-09-25 样式统一:发通知身份改用官方壳 AUMID com.deepseek.dsh(来源名 "DeepSeek Harness"、
|
|
450
450
|
# 角标随壳图标);备选未采用:desktop\assets\icon.png 做 appLogoOverride 角标(旧 ps1 2026-09-03 做法)。
|
|
451
451
|
$xmlEscape = { param([string]$s) ([string]$s).Replace('&', '&').Replace('<', '<').Replace('>', '>').Replace('"', '"').Replace("'", ''') }
|
|
452
|
+
|
|
453
|
+
# ── 发通知用的 AUMID 解析(2026-10-25)────────────────────────────────────
|
|
454
|
+
#
|
|
455
|
+
# 为什么要探测而不是写死:见调用处的注释 —— AUMID 没注册时 Toast 不报错,
|
|
456
|
+
# 只是把 AUMID 原文当应用名、且没有小图标,属于"静默降级",最难排查的那类。
|
|
457
|
+
#
|
|
458
|
+
# 为什么要缓存:本机实测 Get-StartApps 约 540ms,而 ps1 是**每条通知起一个进程**,
|
|
459
|
+
# 不缓存就等于每条通知都晚半秒出声。缓存文件 %LOCALAPPDATA%\dsh-notify-say\toast-aumid.txt
|
|
460
|
+
# 只有一行;删掉它即强制重新探测(换安装包或换机器后排查用)。
|
|
461
|
+
function Get-ToastAppId {
|
|
462
|
+
$cacheDir = Join-Path $env:LOCALAPPDATA 'dsh-notify-say'
|
|
463
|
+
$cacheFile = Join-Path $cacheDir 'toast-aumid.txt'
|
|
464
|
+
|
|
465
|
+
# 1) 缓存命中:0 成本
|
|
466
|
+
try {
|
|
467
|
+
if (Test-Path -LiteralPath $cacheFile) {
|
|
468
|
+
$cached = (Get-Content -LiteralPath $cacheFile -Raw -ErrorAction Stop).Trim()
|
|
469
|
+
if ($cached) { return @($cached) }
|
|
470
|
+
}
|
|
471
|
+
} catch { }
|
|
472
|
+
|
|
473
|
+
# 2) 探测:开始菜单里注册为「DeepSeek Harness」的那一项,AppID 就是 Windows
|
|
474
|
+
# 用来找图标与显示名的 AUMID。
|
|
475
|
+
$found = @()
|
|
476
|
+
try {
|
|
477
|
+
$hit = Get-StartApps -ErrorAction Stop |
|
|
478
|
+
Where-Object { $_.Name -match 'DeepSeek\s*Harness' -or $_.AppID -match 'deepseek' } |
|
|
479
|
+
Select-Object -First 1
|
|
480
|
+
if ($hit -and $hit.AppID) { $found += [string]$hit.AppID }
|
|
481
|
+
} catch { }
|
|
482
|
+
|
|
483
|
+
# 3) 兜底:历史写死的身份 + 借用身份。探测不到时行为与改动前完全一致。
|
|
484
|
+
$found += @('com.deepseek.dsh', 'Microsoft.Windows.Shell.RunDialog')
|
|
485
|
+
|
|
486
|
+
# 去重保序
|
|
487
|
+
$seen = @{}
|
|
488
|
+
$list = @()
|
|
489
|
+
foreach ($id in $found) {
|
|
490
|
+
if ($id -and -not $seen.ContainsKey($id)) {
|
|
491
|
+
$seen[$id] = $true
|
|
492
|
+
$list += $id
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
# 只缓存"探测成功"的结果;纯兜底不写缓存,避免一次探测失败被永久固化。
|
|
497
|
+
if ($list.Count -gt 2) {
|
|
498
|
+
try {
|
|
499
|
+
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
|
|
500
|
+
Set-Content -LiteralPath $cacheFile -Value $list[0] -Encoding ASCII -NoNewline
|
|
501
|
+
} catch { }
|
|
502
|
+
}
|
|
503
|
+
return $list
|
|
504
|
+
}
|
|
505
|
+
|
|
452
506
|
$titleXml = & $xmlEscape $Title
|
|
453
507
|
$bodyXml = & $xmlEscape $Body
|
|
454
508
|
# 第三行按需拼接:没有 -Detail 就不加 <text>,模板还是两行。
|
|
@@ -478,14 +532,25 @@ if ($SoundOnly -or $Preview) {
|
|
|
478
532
|
$launchXml = (& $xmlEscape $toastLaunch)
|
|
479
533
|
$xml.LoadXml("<toast activationType=`"protocol`" launch=`"$launchXml`"><visual><binding template=`"ToastGeneric`"><text>$titleXml</text><text>$bodyXml</text>$detailXml</binding></visual></toast>")
|
|
480
534
|
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
|
481
|
-
# 2026-
|
|
482
|
-
#
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
535
|
+
# 2026-10-25:发通知身份改成**按本机实际注册的 AUMID 解析**,不再写死 com.deepseek.dsh。
|
|
536
|
+
#
|
|
537
|
+
# 为什么:官方壳的 AUMID 并非处处一致 —— 官方安装包注册 com.deepseek.dsh,
|
|
538
|
+
# 而 Electron 默认身份(开始菜单快捷方式里带的正是它)是 electron.app.<ProductName>。
|
|
539
|
+
# 一旦这里写死的那个没在本机注册,Windows 仍会收下 Toast(**不抛异常**,所以原有
|
|
540
|
+
# try/catch 兜不住),但会把 **AUMID 原文当应用名印上去、且画不出名字旁边的小图标**。
|
|
541
|
+
# 用户实测截图里标题行就是 "com.deepseek.dsh"。
|
|
542
|
+
#
|
|
543
|
+
# 解析顺序见 Get-ToastAppId:磁盘缓存 → Get-StartApps 里注册为「DeepSeek Harness」
|
|
544
|
+
# 的项 → 退回历史行为。缓存是必要的:本机实测 Get-StartApps 约 540ms,
|
|
545
|
+
# 每条通知都跑一次会让提示音明显滞后。
|
|
546
|
+
$toastAumids = @(Get-ToastAppId)
|
|
547
|
+
foreach ($toastAumid in $toastAumids) {
|
|
548
|
+
try {
|
|
549
|
+
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($toastAumid).Show($toast)
|
|
550
|
+
$shown = $true
|
|
551
|
+
break
|
|
552
|
+
} catch { }
|
|
487
553
|
}
|
|
488
|
-
$shown = $true
|
|
489
554
|
} catch { $shown = $false }
|
|
490
555
|
}
|
|
491
556
|
|
package/package.json
CHANGED
|
@@ -1,82 +1,80 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
2
|
+
"name": "dsh-notify-say",
|
|
3
|
+
"version": "0.5.9",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/unifilitence/dsh-notify-say.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/unifilitence/dsh-notify-say#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/unifilitence/dsh-notify-say/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": "unifilitence",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./lib/index.js",
|
|
18
|
+
"./client": "./lib/client.js",
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
"./locale/*.json": "./locale/*.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"locale",
|
|
25
|
+
"sounds",
|
|
26
|
+
"dsh-notify.ps1",
|
|
27
|
+
"tts-speak.ps1",
|
|
28
|
+
"jump-handler.vbs",
|
|
29
|
+
"jump-handler.ps1",
|
|
30
|
+
"cordis.patch.yml",
|
|
31
|
+
"tools",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"THIRD-PARTY-NOTICES.md",
|
|
35
|
+
".gitattributes",
|
|
36
|
+
"CHANGELOG.md",
|
|
37
|
+
"test"
|
|
38
|
+
],
|
|
39
|
+
"keywords": [
|
|
40
|
+
"dsh",
|
|
41
|
+
"dsh-plugin",
|
|
42
|
+
"deepseek",
|
|
43
|
+
"deepseek-harness",
|
|
44
|
+
"plugin",
|
|
45
|
+
"notification",
|
|
46
|
+
"notify",
|
|
47
|
+
"toast",
|
|
48
|
+
"speech",
|
|
49
|
+
"voice",
|
|
50
|
+
"tts",
|
|
51
|
+
"voicevox",
|
|
52
|
+
"desktop",
|
|
53
|
+
"windows",
|
|
54
|
+
"zh"
|
|
55
|
+
],
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=20",
|
|
58
|
+
"dsh": ">=0.2.1-rc.2 <0.3.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"test": "node --import ./test/test-env-setup.mjs --test",
|
|
62
|
+
"test:route": "node --import ./test/test-env-setup.mjs --import ./test/route-loader-register.mjs --test test/fail-route.test.mjs",
|
|
63
|
+
"test:audio-wire": "node --import ./test/test-env-setup.mjs --import ./test/route-loader-register.mjs --test test/audio-wiring.test.mjs",
|
|
64
|
+
"test:toast": "node --import ./test/test-env-setup.mjs --import ./test/route-loader-register.mjs --test test/toast-sound-channels.test.mjs",
|
|
65
|
+
"test:all": "node --import ./test/test-env-setup.mjs --test && node --import ./test/test-env-setup.mjs --import ./test/route-loader-register.mjs --test test/fail-route.test.mjs test/audio-wiring.test.mjs test/toast-sound-channels.test.mjs test/voice-label.test.mjs test/ptc-question.test.mjs",
|
|
66
|
+
"check:client": "node ./test/client-bundle.test.mjs",
|
|
67
|
+
"test:ptc": "node --import ./test/test-env-setup.mjs --import ./test/route-loader-register.mjs --test test/ptc-question.test.mjs"
|
|
68
|
+
},
|
|
69
|
+
"dsh": {
|
|
70
|
+
"manifestVersion": 1,
|
|
71
|
+
"bundle": {
|
|
72
|
+
"patch": "./cordis.patch.yml"
|
|
73
|
+
},
|
|
74
|
+
"client": {
|
|
75
|
+
"platform": "web",
|
|
76
|
+
"immediately": true,
|
|
77
|
+
"inject": []
|
|
78
|
+
}
|
|
79
|
+
}
|
|
82
80
|
}
|
|
@@ -18,14 +18,39 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { test } from 'node:test';
|
|
20
20
|
import assert from 'node:assert/strict';
|
|
21
|
-
import { readFileSync, existsSync, readdirSync, statSync
|
|
21
|
+
import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';
|
|
22
22
|
import { execFileSync } from 'node:child_process';
|
|
23
23
|
import { join, resolve, dirname } from 'node:path';
|
|
24
24
|
import { fileURLToPath } from 'node:url';
|
|
25
|
+
import { createRequire } from 'node:module';
|
|
25
26
|
|
|
26
27
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
27
28
|
const PKG = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 惰性取 fs.globSync —— 它是 Node 22.0 才有的导出。
|
|
32
|
+
*
|
|
33
|
+
* ⚠️ 不能写成静态 import:Node 20 上整个模块会在求值前加载失败
|
|
34
|
+
* (`SyntaxError: The requested module 'node:fs' does not provide an export
|
|
35
|
+
* named 'globSync'`),外层 try/catch 一条断言都拦不住 —— 这正是 0.5.2 起
|
|
36
|
+
* GitHub Actions「单元测试(Node 20)」连红四次的原因(0.5.2 / 0.5.3 /
|
|
37
|
+
* 0.5.7 / 0.5.8 全中;本机 Node 24 看不到,所以一直没被发现)。
|
|
38
|
+
*
|
|
39
|
+
* 与 test/reload-verification.test.mjs 对 registerHooks 的处理同一套做法:
|
|
40
|
+
* 运行时按需取,取不到就落保守分支。
|
|
41
|
+
*/
|
|
42
|
+
let _globSync;
|
|
43
|
+
function getGlobSync() {
|
|
44
|
+
if (_globSync !== undefined) return _globSync;
|
|
45
|
+
try {
|
|
46
|
+
const fsMod = createRequire(import.meta.url)('node:fs');
|
|
47
|
+
_globSync = typeof fsMod.globSync === 'function' ? fsMod.globSync : null;
|
|
48
|
+
} catch {
|
|
49
|
+
_globSync = null;
|
|
50
|
+
}
|
|
51
|
+
return _globSync;
|
|
52
|
+
}
|
|
53
|
+
|
|
29
54
|
/** 磁盘上真实存在的音色 key(从 sounds/voice-lines 推)。 */
|
|
30
55
|
function realVoiceKeys() {
|
|
31
56
|
const base = join(ROOT, 'sounds', 'voice-lines');
|
|
@@ -734,6 +759,82 @@ test('D13: README 的测试条数与实际一致', () => {
|
|
|
734
759
|
`README 声称 ${claimed} 条测试,超出合理范围 —— 数字可能过时`);
|
|
735
760
|
});
|
|
736
761
|
|
|
762
|
+
// ── D20: 静态 import 里不许出现 engines.node 不支持的 API ─────────────────
|
|
763
|
+
//
|
|
764
|
+
// 为什么必须有这条:0.5.2 → 0.5.3 → 0.5.7 → 0.5.8 四次发布,GitHub Actions
|
|
765
|
+
// 的「单元测试(Node 20)」**每次都红**,公开仓库的 CI 徽章一直是 failing。
|
|
766
|
+
// 根因只有一个:`docs-consistency.test.mjs` 静态 import 了 `globSync`
|
|
767
|
+
// —— 它是 Node 22.0 才有的导出。Node 20 上**整个模块在求值前就加载失败**,
|
|
768
|
+
// 外层 try/catch 一条断言都拦不住,所以格外难在本地发现(本机 Node 24 全绿)。
|
|
769
|
+
//
|
|
770
|
+
// 这类问题的共同形状是「能跑通的机器上看不出来」:静态 import 在模块求值
|
|
771
|
+
// **之前**解析,所以任何"运行时降级"都救不了它。判据只能落在**源码文本**上。
|
|
772
|
+
//
|
|
773
|
+
// 同源的先例:`reload-verification.test.mjs` 为 `registerHooks`(22.15+)
|
|
774
|
+
// 写过一次同样的坑(0.4.26~0.4.28 修了三轮),但那次只修了用法,没建判据,
|
|
775
|
+
// 于是同一个坑换了个 API 又踩一遍 —— 这条判据就是那次缺的机制。
|
|
776
|
+
test('D20: 静态 import 不得引用 engines.node 范围内的 Node 没有的导出', () => {
|
|
777
|
+
// 只登记**本仓库真用到过 / 极易误用**的条目,不做全量 API 考古。
|
|
778
|
+
// version 用来说明"为什么它不够老",编译报错时人能看懂。
|
|
779
|
+
const TOO_NEW = [
|
|
780
|
+
{ mod: 'fs', name: 'globSync', version: '22.0.0' },
|
|
781
|
+
{ mod: 'fs/promises', name: 'glob', version: '22.0.0' },
|
|
782
|
+
{ mod: 'module', name: 'registerHooks', version: '22.15.0' },
|
|
783
|
+
{ mod: 'module', name: 'stripTypeScriptTypes', version: '22.13.0' },
|
|
784
|
+
{ mod: 'util', name: 'parseEnv', version: '20.12.0' },
|
|
785
|
+
];
|
|
786
|
+
// engines 说支持的最低版本(写死在这里是刻意的:下限变了就得有人来改判据)
|
|
787
|
+
const MIN_NODE = [20, 0, 0];
|
|
788
|
+
|
|
789
|
+
const isTooNew = (v) => {
|
|
790
|
+
const got = v.split('.').map(Number);
|
|
791
|
+
for (let i = 0; i < 3; i++) {
|
|
792
|
+
if ((got[i] || 0) > MIN_NODE[i]) return true;
|
|
793
|
+
if ((got[i] || 0) < MIN_NODE[i]) return false;
|
|
794
|
+
}
|
|
795
|
+
return false;
|
|
796
|
+
};
|
|
797
|
+
const banned = TOO_NEW.filter((e) => isTooNew(e.version));
|
|
798
|
+
|
|
799
|
+
const files = [];
|
|
800
|
+
const walk = (dir) => {
|
|
801
|
+
for (const e of readdirSync(join(ROOT, dir), { withFileTypes: true })) {
|
|
802
|
+
if (e.name === 'node_modules' || e.name.startsWith('.')) continue;
|
|
803
|
+
const rel = dir + '/' + e.name;
|
|
804
|
+
if (e.isDirectory()) walk(rel);
|
|
805
|
+
else if (/\.(mjs|js)$/.test(e.name)) files.push(rel);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
for (const d of ['test', 'lib']) {
|
|
809
|
+
if (existsSync(join(ROOT, d))) walk(d);
|
|
810
|
+
}
|
|
811
|
+
assert.ok(files.length > 20, `扫描到的源码文件太少(${files.length}),walk 可能坏了`);
|
|
812
|
+
|
|
813
|
+
// 只认**静态** import:`import { x } from 'node:fs'`。
|
|
814
|
+
// 动态 `createRequire(...)('node:fs')` 与 `await import()` 是有意为之的降级,
|
|
815
|
+
// 不在判据范围内(它们的可用性由用到的地方自己的 skip 分支兜住)。
|
|
816
|
+
const STATIC_IMPORT = /^\s*import\s*\{([^}]*)\}\s*from\s*['"]node:([^'"]+)['"]/gm;
|
|
817
|
+
const offenders = [];
|
|
818
|
+
for (const rel of files) {
|
|
819
|
+
const src = readFileSync(join(ROOT, rel), 'utf8');
|
|
820
|
+
for (const m of src.matchAll(STATIC_IMPORT)) {
|
|
821
|
+
const names = m[1].split(',').map((x) => x.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean);
|
|
822
|
+
for (const b of banned) {
|
|
823
|
+
if (m[2] !== b.mod) continue;
|
|
824
|
+
if (names.includes(b.name)) {
|
|
825
|
+
offenders.push(`${rel}: 静态 import {${b.name}} from 'node:${b.mod}'`
|
|
826
|
+
+ `(Node ${b.version}+ 才有,但 engines 说 ${MIN_NODE.join('.')} 起就支持)`);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
assert.deepEqual(offenders, [],
|
|
832
|
+
'这些静态 import 会让 Node 20/22.0 上的模块直接加载失败(不是断言失败,是整文件不跑):\n '
|
|
833
|
+
+ offenders.join('\n ')
|
|
834
|
+
+ '\n改法:用 createRequire(import.meta.url)(...) 或 await import() 运行时按需取,'
|
|
835
|
+
+ '取不到就走跳过/保守分支。');
|
|
836
|
+
});
|
|
837
|
+
|
|
737
838
|
// ── D14: README 必须提到音色下载的许可告知 ──────────────────────────────
|
|
738
839
|
test('D14: README 说明下载前会展示署名与条款', () => {
|
|
739
840
|
// 这是合规要求:用户得知道"用这些语音做的内容要署名"。
|
|
@@ -1413,7 +1514,15 @@ function dirWhitelistProblems(rb, tables = {}) {
|
|
|
1413
1514
|
// 用 fs.globSync 判它到底能匹配到东西;匹配不到才算真错。
|
|
1414
1515
|
if (/[*?[\]]/.test(n)) {
|
|
1415
1516
|
let matched = [];
|
|
1416
|
-
|
|
1517
|
+
const gs = getGlobSync();
|
|
1518
|
+
if (gs) {
|
|
1519
|
+
try { matched = gs(n, { cwd: ROOT }); } catch { matched = []; }
|
|
1520
|
+
} else {
|
|
1521
|
+
// Node 20 没有 globSync,无法真的判它能不能匹配到东西。
|
|
1522
|
+
// 宁可放过(不报警)也不能凭空报 B-不存在 —— 那会把一个跨版本兼容
|
|
1523
|
+
// 问题伪装成"files 白名单写错了"。
|
|
1524
|
+
matched = [n];
|
|
1525
|
+
}
|
|
1417
1526
|
if (matched.length > 0) continue;
|
|
1418
1527
|
add(REASON.B_MISSING, `files 白名单里的通配 ${n} 在源目录匹配不到任何文件`
|
|
1419
1528
|
+ ' → npm pack 不会因此报错,但这一条等于什么也没声明');
|
|
@@ -2078,11 +2187,17 @@ test('D19i: files 条目的格式判据必须与 npm 实测一致', { skip: SKIP
|
|
|
2078
2187
|
assert.ok(blk.includes(" 'lib',\n"), 'files 数组内未命中 lib 条目');
|
|
2079
2188
|
return rb.slice(0, open) + blk.replace(" 'lib',\n", ` 'lib',\n '${entry}',\n`) + rb.slice(close);
|
|
2080
2189
|
};
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2190
|
+
// ③ 的两条断言要靠 fs.globSync 才能判"这个通配到底匹配不匹配得到东西"。
|
|
2191
|
+
// Node 20 没有这个 API(见文件头 getGlobSync 的说明),此时无法验证,
|
|
2192
|
+
// 只能显式跳过 —— 让它在 Node 20 上"看起来绿"是误报,让它红是假红,
|
|
2193
|
+
// 两者都比"写清楚这里没验"更糟。
|
|
2194
|
+
if (getGlobSync()) {
|
|
2195
|
+
assert.deepEqual(dirWhitelistProblems(appendInFiles('*.md')).map((p) => p.code), [],
|
|
2196
|
+
"files 里的 '*.md' 能匹配到文件,npm 正常打包,不该报错");
|
|
2197
|
+
assert.ok(dirWhitelistProblems(appendInFiles('*.nonexistent-ext')).map((p) => p.code)
|
|
2198
|
+
.includes(REASON.B_MISSING),
|
|
2199
|
+
'匹配不到任何文件的通配应当报 B-不存在(等于这一条什么也没声明)');
|
|
2200
|
+
}
|
|
2086
2201
|
});
|
|
2087
2202
|
|
|
2088
2203
|
// ── D19j: 点号段 / 越界段(第五轮只读复核报的两个 P0)─────────────────────
|
package/test/fail-voice.test.mjs
CHANGED
|
@@ -32,6 +32,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
32
32
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
33
33
|
import { fileURLToPath } from 'node:url';
|
|
34
34
|
import { dirname, join } from 'node:path';
|
|
35
|
+
import { RUNTIME_PS } from './ps-interp.mjs';
|
|
35
36
|
|
|
36
37
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
37
38
|
const PLUGIN = join(HERE, '..');
|
|
@@ -43,7 +44,7 @@ const LIB = join(PLUGIN, 'lib', 'index.js');
|
|
|
43
44
|
|
|
44
45
|
/** 跑 ps1 -Preview,返回 stdout / stderr / exit code。用 spawnSync(见文件头踩坑③)。 */
|
|
45
46
|
function runPs1(args) {
|
|
46
|
-
const r = spawnSync(
|
|
47
|
+
const r = spawnSync(RUNTIME_PS,
|
|
47
48
|
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', PS1, ...args],
|
|
48
49
|
{ encoding: 'utf8', timeout: 60_000 });
|
|
49
50
|
return {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PowerShell 解释器选择器(测试专用)
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么需要这个文件(2026-11-24,踩坑 #494)
|
|
5
|
+
*
|
|
6
|
+
* 本项目里有**两类** PowerShell 脚本,它们必须用**不同的解释器**跑:
|
|
7
|
+
*
|
|
8
|
+
* 1. **运行时脚本**(`dsh-notify.ps1` / `tts-speak.ps1` / `jump-handler.ps1` / `lib/wav-gain.ps1`)
|
|
9
|
+
* —— 这些由宿主 `lib/index.js` 的 `POWERSHELL_EXE` 常量以**绝对路径的 Windows PowerShell 5.1**
|
|
10
|
+
* 启动(`WindowsPowerShell\v1.0\powershell.exe`)。原因见 lib/index.js 的注释:Toast 走的
|
|
11
|
+
* WinRT 投影只在 5.1 可用。**测试必须复刻这个解释器**,用 pwsh 7 跑等于测了另一条代码路径。
|
|
12
|
+
* 这几个脚本**不允许**带 `#Requires -Version 7.0`(带了就在 5.1 下 exit 1,且失败是静默的)。
|
|
13
|
+
*
|
|
14
|
+
* 2. **维护者工具**(`tools/release-build.ps1` / `tools/release.ps1` / …)
|
|
15
|
+
* —— 这些带 `#Requires -Version 7.0`(ADR-0015 L3:5.1 会误读无 BOM 的 UTF-8 中文源码)。
|
|
16
|
+
* **测试必须用 pwsh 7 调用它们**,用 5.1 会撞 `ScriptRequiresUnmatchedPSVersion`。
|
|
17
|
+
*
|
|
18
|
+
* ADR-0015 阶段 4 的批量插 `#Requires` 把第 1 类也扫进去了,而当时所有测试都用
|
|
19
|
+
* `'powershell.exe'` 硬编码 → TTS 与增益静默失效 + 13 条测试红,直到下一次发版才暴露。
|
|
20
|
+
* 这个文件把「哪类脚本配哪个解释器」变成**一处显式声明**,避免再次各写各的。
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { existsSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 运行时脚本用的解释器:Windows PowerShell 5.1,与宿主 `POWERSHELL_EXE` 同一条路径。
|
|
28
|
+
*
|
|
29
|
+
* 刻意**不**做成"哪个好用用哪个"——宿主是写死 5.1 的,测试必须复刻真实路径,
|
|
30
|
+
* 否则"在 pwsh 7 下能跑"会伪装成"插件能跑"。
|
|
31
|
+
*/
|
|
32
|
+
export const RUNTIME_PS
|
|
33
|
+
= `${process.env.SystemRoot || 'C:\\Windows'}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 维护者工具用的解释器:PowerShell 7(`#Requires -Version 7.0` 要求 ≥7.0)。
|
|
37
|
+
*
|
|
38
|
+
* 本机没装 pwsh 7 时返回 `null`,调用方应 `skip` 而不是用 5.1 硬跑
|
|
39
|
+
* —— 用 5.1 跑只会得到 `ScriptRequiresUnmatchedPSVersion`,那是**环境缺失**,
|
|
40
|
+
* 不是被测代码的缺陷,不该记成失败。
|
|
41
|
+
*/
|
|
42
|
+
export const TOOLING_PS = (() => {
|
|
43
|
+
const candidates = [
|
|
44
|
+
join(process.env.ProgramFiles || 'C:\\Program Files', 'PowerShell', '7', 'pwsh.exe'),
|
|
45
|
+
join(process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)', 'PowerShell', '7', 'pwsh.exe'),
|
|
46
|
+
join(process.env.LOCALAPPDATA || '', 'Microsoft', 'WindowsApps', 'pwsh.exe'),
|
|
47
|
+
];
|
|
48
|
+
for (const p of candidates) {
|
|
49
|
+
if (p && existsSync(p)) return p;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
})();
|
|
53
|
+
|
|
54
|
+
/** pwsh 7 是否可用(决定工具类测试是跑还是 skip)。 */
|
|
55
|
+
export const HAS_TOOLING_PS = TOOLING_PS !== null;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R 系列:运行时 PowerShell 脚本的解释器契约(fitness function)
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么需要这个文件(2026-11-24,踩坑 #494)
|
|
5
|
+
*
|
|
6
|
+
* ADR-0015 把全仓 .ps1 统一到 PowerShell 7,用 `tools/ps7-add-requires.ps1`
|
|
7
|
+
* 批量给 137 个脚本顶部插 `#Requires -Version 7.0`。但**这个插件有一类脚本不能插**:
|
|
8
|
+
*
|
|
9
|
+
* 宿主 `lib/index.js` 的 `POWERSHELL_EXE` 是**写死绝对路径**的 Windows PowerShell 5.1:
|
|
10
|
+
*
|
|
11
|
+
* const POWERSHELL_EXE =
|
|
12
|
+
* `${process.env.SystemRoot || 'C:\\Windows'}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
13
|
+
*
|
|
14
|
+
* 它是**故意**写死的(Toast 走 WinRT 投影,只有 5.1 可用),不会因为装了 pwsh 7 就换。
|
|
15
|
+
* 所以被它启动的那几个脚本一旦带上 `#Requires -Version 7.0`,在 5.1 下直接
|
|
16
|
+
* `exit 1`(ScriptRequiresUnmatchedPSVersion),表现是:
|
|
17
|
+
*
|
|
18
|
+
* - `tts-speak.ps1` → TTS 静默失效,退化成蜂鸣(audioSource 默认就是 'tts')
|
|
19
|
+
* - `lib/wav-gain.ps1` → 增益被 try/catch 吞掉,音量设置静默失效
|
|
20
|
+
* - `jump-handler.ps1` → 有 .vbs 兜底,暂不炸但埋雷
|
|
21
|
+
*
|
|
22
|
+
* 这三处失败**都不报错给用户**,只能靠日志里的半行提示发现。
|
|
23
|
+
*
|
|
24
|
+
* ## 这条测试守什么
|
|
25
|
+
*
|
|
26
|
+
* 它断言的是**分类**而不是单点:`RUNTIME_SCRIPTS` 里的文件不得带 `#Requires`,
|
|
27
|
+
* `TOOLING_SCRIPTS` 里必须带。这样将来再加脚本时,作者必须显式想清楚它属于哪类
|
|
28
|
+
* —— 而不是"批量插一遍,跑挂了再说"。
|
|
29
|
+
*
|
|
30
|
+
* 为什么不能只靠 `ps7-add-requires.ps1` 的 `$SkipNames`:那是个**可选**清单,
|
|
31
|
+
* 忘了加与"当时没想到这类脚本存在"是同一种失败。这里用正向断言把契约钉在插件自己身上,
|
|
32
|
+
* 不依赖外部工具的配置是否记得更新。
|
|
33
|
+
*/
|
|
34
|
+
import { test } from 'node:test';
|
|
35
|
+
import assert from 'node:assert/strict';
|
|
36
|
+
import { spawnSync } from 'node:child_process';
|
|
37
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
38
|
+
import { dirname, join, resolve } from 'node:path';
|
|
39
|
+
import { fileURLToPath } from 'node:url';
|
|
40
|
+
import { RUNTIME_PS } from './ps-interp.mjs';
|
|
41
|
+
|
|
42
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 宿主用 5.1 启动的运行时脚本(相对插件根)。
|
|
46
|
+
* 新增条目时必须同时确认:调用它的地方走的是 `POWERSHELL_EXE`,而不是 `pwsh`。
|
|
47
|
+
*/
|
|
48
|
+
const RUNTIME_SCRIPTS = [
|
|
49
|
+
'dsh-notify.ps1',
|
|
50
|
+
'tts-speak.ps1',
|
|
51
|
+
'jump-handler.ps1',
|
|
52
|
+
join('lib', 'wav-gain.ps1'),
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* **用户手动运行**、且随 npm 包发出去的脚本(相对插件根)。
|
|
57
|
+
*
|
|
58
|
+
* 与 RUNTIME_SCRIPTS 的区别:它们不是宿主 spawn 的,而是 README 教用户
|
|
59
|
+
* `cd <插件>\tools` 后直接敲的。用户机器上只有 Windows 出厂自带的 5.1 是
|
|
60
|
+
* 常态,所以它们同样**不得**要求 PowerShell 7。
|
|
61
|
+
*
|
|
62
|
+
* 2026-11-24(踩坑 #495):`tools/notify-config.ps1` 被 `ps7-add-requires.ps1`
|
|
63
|
+
* 批量插了 `#Requires -Version 7.0`,0.5.8 若照此发出,README 里那 8 条命令
|
|
64
|
+
* 在 5.1 上会全部 `exit 1`。R1 当时只覆盖「宿主 spawn 的脚本」,没覆盖这一类,
|
|
65
|
+
* 所以没拦住 —— 这个数组就是补上的那道闸。
|
|
66
|
+
*/
|
|
67
|
+
const USER_SCRIPTS = [
|
|
68
|
+
join('tools', 'notify-config.ps1'),
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
/** 维护者工具(不会被插件运行时调用),由 ADR-0015 统一要求 PowerShell 7。 */
|
|
72
|
+
const TOOLING_SCRIPTS = [
|
|
73
|
+
join('tools', 'release-build.ps1'),
|
|
74
|
+
join('tools', 'release.ps1'),
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
// 注意:JS 正则没有 `(?m)` 内联标志(那是 .NET/Python 语法),
|
|
78
|
+
// 多行匹配要用 `/m` 修饰符。写错会在**模块链接阶段**直接抛 SyntaxError,
|
|
79
|
+
// 整个文件一行都跑不了 —— 表现是"只有 1 个失败:文件本身"。
|
|
80
|
+
const REQUIRE_7 = /^\s*#Requires\s+-Version\s+7\.0\s*$/m;
|
|
81
|
+
const REQUIRE_ANY = /^\s*#Requires\s+-Version\s+(\d+)\.(\d+)/gm;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 「必须在 5.1 上跑得起来」的全部脚本 —— 运行时 spawn 的 + 用户手敲的。
|
|
85
|
+
* R1/R2 都遍历这个合集:两类脚本对解释器的约束**完全相同**(都只能 ≤5.1),
|
|
86
|
+
* 区别只在"谁启动它",而"谁启动它"在版本判定上不重要。
|
|
87
|
+
*/
|
|
88
|
+
const MUST_RUN_ON_51 = [...RUNTIME_SCRIPTS, ...USER_SCRIPTS];
|
|
89
|
+
|
|
90
|
+
function read(rel) {
|
|
91
|
+
return readFileSync(join(ROOT, rel), 'utf8');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── R1: 必须在 5.1 上跑的脚本一律不得带 #Requires 7.0 ────────────────────
|
|
95
|
+
test('R1: 宿主用 5.1 启动的运行时脚本,一律不得带 #Requires -Version 7.0', () => {
|
|
96
|
+
const offenders = [];
|
|
97
|
+
for (const rel of MUST_RUN_ON_51) {
|
|
98
|
+
if (!existsSync(join(ROOT, rel))) continue;
|
|
99
|
+
if (REQUIRE_7.test(read(rel))) offenders.push(rel);
|
|
100
|
+
}
|
|
101
|
+
assert.deepEqual(offenders, [],
|
|
102
|
+
'这些脚本由 lib/index.js 的 POWERSHELL_EXE(写死的 5.1)启动,\n'
|
|
103
|
+
+ '带 #Requires -Version 7.0 会让它们在 5.1 下 exit 1,而且失败是静默的:\n '
|
|
104
|
+
+ offenders.join('\n '));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ── R2: 必须在 5.1 上跑的脚本里任意 #Requires 都必须 ≤5.1 ───────────────
|
|
108
|
+
test('R2: 运行时脚本若声明 #Requires,版本必须 ≤5.1', () => {
|
|
109
|
+
const bad = [];
|
|
110
|
+
for (const rel of MUST_RUN_ON_51) {
|
|
111
|
+
if (!existsSync(join(ROOT, rel))) continue;
|
|
112
|
+
for (const m of read(rel).matchAll(REQUIRE_ANY)) {
|
|
113
|
+
if (Number(m[1]) > 5) bad.push(`${rel}: #Requires -Version ${m[1]}.${m[2]}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
assert.deepEqual(bad, [],
|
|
117
|
+
'运行时脚本的解释器由宿主写死为 5.1,任何 >5 的版本要求都会让它在真机上跑不起来:\n '
|
|
118
|
+
+ bad.join('\n '));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// ── R3: 维护者工具必须带 #Requires 7.0(ADR-0015 的正向面)──────────────
|
|
122
|
+
test('R3: 维护者工具脚本必须带 #Requires -Version 7.0', () => {
|
|
123
|
+
const missing = [];
|
|
124
|
+
for (const rel of TOOLING_SCRIPTS) {
|
|
125
|
+
if (!existsSync(join(ROOT, rel))) continue;
|
|
126
|
+
if (!REQUIRE_7.test(read(rel))) missing.push(rel);
|
|
127
|
+
}
|
|
128
|
+
assert.deepEqual(missing, [],
|
|
129
|
+
'ADR-0015 要求维护者工具跑在 PowerShell 7(5.1 会误读无 BOM 的 UTF-8 中文源码):\n '
|
|
130
|
+
+ missing.join('\n '));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ── R4: 宿主确实在用 5.1(契约的另一半,防"改了宿主却没人知道")─────────
|
|
134
|
+
test('R4: lib/index.js 的 POWERSHELL_EXE 仍指向 Windows PowerShell 5.1', () => {
|
|
135
|
+
// ⚠️ 用 `includes` 而不是正则:源码里写的是**转义后的**双反斜杠
|
|
136
|
+
// (模板字符串拼路径),正则要匹配它们得写四层 `\\\\`,极易数错一层。
|
|
137
|
+
// 这里直接比字面量,`'...\\\\v1.0...'` 在 JS 里就等于源码中的 `\\v1.0`。
|
|
138
|
+
const src = read(join('lib', 'index.js'));
|
|
139
|
+
assert.ok(src.includes('WindowsPowerShell\\\\v1.0\\\\powershell.exe'),
|
|
140
|
+
'POWERSHELL_EXE 若改成 pwsh 7,R1 的前提就不成立了 —— '
|
|
141
|
+
+ '那时应同步给 RUNTIME_SCRIPTS 加 #Requires 7.0,并重跑真机验证');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// ── R5: 测试辅助器必须把两类脚本分开 ────────────────────────────────────
|
|
145
|
+
test('R5: test/ps-interp.mjs 导出了 RUNTIME_PS 与 TOOLING_PS 两个解释器', () => {
|
|
146
|
+
const src = read(join('test', 'ps-interp.mjs'));
|
|
147
|
+
assert.match(src, /export const RUNTIME_PS/, '必须有运行时解释器常量');
|
|
148
|
+
assert.match(src, /export const TOOLING_PS/, '必须有工具解释器常量');
|
|
149
|
+
assert.ok(src.includes('WindowsPowerShell\\\\v1.0\\\\powershell.exe'),
|
|
150
|
+
'RUNTIME_PS 必须复刻宿主的 5.1 路径,不能"哪个好用用哪个"');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// ── R6: 用户 CLI 必须在 5.1 下**真的跑起来**(静态断言之外的真跑)───────
|
|
154
|
+
/**
|
|
155
|
+
* R1/R2 只看源码文本。但 `#Requires` 的失败模式是**运行时**才发生的
|
|
156
|
+
* (5.1 读到 `#Requires -Version 7.0` 直接 exit 1,脚本一行都不执行),
|
|
157
|
+
* 所以这里用宿主同款解释器真跑一遍 `-Show`(只读,不写 config)。
|
|
158
|
+
*
|
|
159
|
+
* 这条测试的价值:`-Show` 能读出配置就证明「用户敲 README 第 170 行那条命令不会报错」。
|
|
160
|
+
* 当初 0.5.8 差点把带 `#Requires 7.0` 的 CLI 发出去,静态检查漏了,只有真跑才发现。
|
|
161
|
+
*/
|
|
162
|
+
test('R6: tools/notify-config.ps1 在 5.1 下真跑 -Show 必须成功', () => {
|
|
163
|
+
const rel = join('tools', 'notify-config.ps1');
|
|
164
|
+
if (!existsSync(join(ROOT, rel))) return;
|
|
165
|
+
const r = spawnSync(RUNTIME_PS,
|
|
166
|
+
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', join(ROOT, rel), '-Show'],
|
|
167
|
+
{ encoding: 'utf8', timeout: 60_000 });
|
|
168
|
+
const out = String(r.stdout || '') + String(r.stderr || '');
|
|
169
|
+
assert.equal(r.status, 0,
|
|
170
|
+
'用户 CLI 在 Windows 自带的 5.1 下必须能跑(README:170-181 教用户直接运行它)。\n'
|
|
171
|
+
+ '若报 ScriptRequiresUnmatchedPSVersion,说明有人又给它加了 #Requires 7.0。\n'
|
|
172
|
+
+ `实际输出:\n${out.slice(0, 800)}`);
|
|
173
|
+
assert.match(out, /dsh-notify-say 配置/,
|
|
174
|
+
`-Show 应当打印配置标题,实际输出:\n${out.slice(0, 800)}`);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// ── R7: 维护者工具自己 spawn 的解释器必须也是 pwsh ──────────────────────
|
|
178
|
+
/**
|
|
179
|
+
* R3 只保证 `TOOLING_SCRIPTS`(release.ps1 / release-build.ps1)**自己**带
|
|
180
|
+
* `#Requires 7.0`。但"父进程在 7 下跑"不等于"它 spawn 出去的子进程也在 7 下":
|
|
181
|
+
*
|
|
182
|
+
* · `'powershell'` / `'powershell.exe'` 在任何 PowerShell 里都解析到
|
|
183
|
+
* `System32\WindowsPowerShell\v1.0\powershell.exe`(= 5.1),与 PATH 顺序无关;
|
|
184
|
+
* · 于是 release.ps1(带 Requires 7.0)用裸 `'powershell'` 去启动
|
|
185
|
+
* release-build.ps1(也带 Requires 7.0)时,子进程是 5.1,读到 Requires 直接 exit 1。
|
|
186
|
+
*
|
|
187
|
+
* 2026-11-24 真实代价:0.5.8 发版第 3 步「重建发布包」必挂,报
|
|
188
|
+
* `ScriptRequiresUnmatchedPSVersion`。C7 静态闸拦不住 —— 它只匹配 AST 里的裸命令
|
|
189
|
+
* `& powershell`,不匹配"作为字符串传给 Invoke-Checked 的 `'powershell'`"。
|
|
190
|
+
*
|
|
191
|
+
* 这里用**字符串字面量**判定(不依赖 AST),因此那类间接调用也能抓到。
|
|
192
|
+
*/
|
|
193
|
+
test('R7: 维护者工具不得以字符串形式 spawn powershell(5.1),必须用 pwsh', () => {
|
|
194
|
+
// 只认「作为独立字符串字面量出现」的 powershell / powershell.exe。
|
|
195
|
+
// 不匹配 System32 绝对路径(那是 ADR-0015 允许的 5.1 例外),也不匹配注释里的普通提及。
|
|
196
|
+
const BARE_PS = /(['"])(?:powershell|powershell\.exe)\1/i;
|
|
197
|
+
const bad = [];
|
|
198
|
+
for (const rel of TOOLING_SCRIPTS) {
|
|
199
|
+
const abs = join(ROOT, rel);
|
|
200
|
+
if (!existsSync(abs)) continue;
|
|
201
|
+
const lines = read(rel).split(/\r?\n/);
|
|
202
|
+
lines.forEach((line, i) => {
|
|
203
|
+
const code = line.replace(/#.*$/, ''); // 去掉行尾注释,避免误报
|
|
204
|
+
if (!BARE_PS.test(code)) return;
|
|
205
|
+
// System32\WindowsPowerShell\v1.0\powershell.exe 这类绝对路径是允许的例外
|
|
206
|
+
if (/System32.*WindowsPowerShell/i.test(code)) return;
|
|
207
|
+
bad.push(`${rel}:${i + 1}: ${line.trim()}`);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
assert.deepEqual(bad, [],
|
|
211
|
+
'维护者工具用裸 powershell 字符串启动子进程时,子进程是 5.1,\n'
|
|
212
|
+
+ '而被启动的脚本要求 7.0 → ScriptRequiresUnmatchedPSVersion,发版必挂。\n'
|
|
213
|
+
+ '改法:把字符串换成 \'pwsh\'。命中行:\n ' + bad.join('\n '));
|
|
214
|
+
});
|
|
@@ -27,10 +27,16 @@ import { existsSync, mkdtempSync, readdirSync, statSync } from 'node:fs';
|
|
|
27
27
|
import { tmpdir } from 'node:os';
|
|
28
28
|
import { join, resolve, dirname } from 'node:path';
|
|
29
29
|
import { fileURLToPath } from 'node:url';
|
|
30
|
+
import { TOOLING_PS, HAS_TOOLING_PS } from './ps-interp.mjs';
|
|
30
31
|
|
|
31
32
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
32
33
|
const BUILDER = join(ROOT, 'tools', 'release-build.ps1');
|
|
33
34
|
|
|
35
|
+
// `tools/release-build.ps1` 是**维护者工具**,带 `#Requires -Version 7.0`(ADR-0015 L3),
|
|
36
|
+
// 必须用 pwsh 7 跑;用 5.1 会撞 ScriptRequiresUnmatchedPSVersion,那是环境缺失不是代码缺陷。
|
|
37
|
+
// 本机没装 pwsh 7 时这些用例 skip(见 test/ps-interp.mjs 的两类脚本说明)。
|
|
38
|
+
const SKIP_NO_PS7 = !HAS_TOOLING_PS && '本机没有 PowerShell 7(pwsh.exe),release-build.ps1 需要它';
|
|
39
|
+
|
|
34
40
|
/** 递归找匹配的文件(不引第三方库)。 */
|
|
35
41
|
function findFiles(dir, predicate, out = []) {
|
|
36
42
|
if (!existsSync(dir)) return out;
|
|
@@ -62,7 +68,7 @@ function findBannedAudio(dir, voiceKey) {
|
|
|
62
68
|
/** 跑一次发布包构建,返回目标目录。 */
|
|
63
69
|
function buildRelease(extraArgs) {
|
|
64
70
|
const dest = mkdtempSync(join(tmpdir(), 'rel-guard-'));
|
|
65
|
-
execFileSync(
|
|
71
|
+
execFileSync(TOOLING_PS, [
|
|
66
72
|
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', BUILDER,
|
|
67
73
|
'-Destination', dest, '-Force', ...extraArgs,
|
|
68
74
|
], { encoding: 'utf8', timeout: 300_000 });
|
|
@@ -70,7 +76,7 @@ function buildRelease(extraArgs) {
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
// ── P1: 默认参数下不包含个人声音 ────────────────────────────────────────
|
|
73
|
-
test('P1: 默认参数构建的发布包不含 my-voice 文件', () => {
|
|
79
|
+
test('P1: 默认参数构建的发布包不含 my-voice 文件', { skip: SKIP_NO_PS7 }, () => {
|
|
74
80
|
if (!existsSync(BUILDER)) return;
|
|
75
81
|
const dest = buildRelease([]);
|
|
76
82
|
const leaked = findBannedAudio(dest, 'my-voice');
|
|
@@ -80,7 +86,7 @@ test('P1: 默认参数构建的发布包不含 my-voice 文件', () => {
|
|
|
80
86
|
});
|
|
81
87
|
|
|
82
88
|
// ── P2: -KeepAllVoices 也必须挡住(关键:原实现会漏)────────────────────
|
|
83
|
-
test('P2: -KeepAllVoices 也无法带出 my-voice(黑名单优先于一切参数)', () => {
|
|
89
|
+
test('P2: -KeepAllVoices 也无法带出 my-voice(黑名单优先于一切参数)', { skip: SKIP_NO_PS7 }, () => {
|
|
84
90
|
if (!existsSync(BUILDER)) return;
|
|
85
91
|
const dest = buildRelease(['-KeepAllVoices']);
|
|
86
92
|
const leaked = findBannedAudio(dest, 'my-voice');
|
|
@@ -90,7 +96,7 @@ test('P2: -KeepAllVoices 也无法带出 my-voice(黑名单优先于一切参
|
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
// ── P3: 防护不能误伤其它音色 ────────────────────────────────────────────
|
|
93
|
-
test('P3: 防护只挡 my-voice,其它音色照常保留', () => {
|
|
99
|
+
test('P3: 防护只挡 my-voice,其它音色照常保留', { skip: SKIP_NO_PS7 }, () => {
|
|
94
100
|
if (!existsSync(BUILDER)) return;
|
|
95
101
|
const dest = buildRelease(['-KeepAllVoices']);
|
|
96
102
|
const wavs = findFiles(dest, (n) => n.toLowerCase().endsWith('.wav'));
|
|
@@ -100,9 +106,9 @@ test('P3: 防护只挡 my-voice,其它音色照常保留', () => {
|
|
|
100
106
|
});
|
|
101
107
|
|
|
102
108
|
// ── P4: 源码里必须有这道防护的声明 ──────────────────────────────────────
|
|
103
|
-
test('P4: release-build.ps1 里有明确的 NeverShip 黑名单', () => {
|
|
109
|
+
test('P4: release-build.ps1 里有明确的 NeverShip 黑名单', { skip: SKIP_NO_PS7 }, () => {
|
|
104
110
|
if (!existsSync(BUILDER)) return;
|
|
105
|
-
const src = execFileSync(
|
|
111
|
+
const src = execFileSync(TOOLING_PS, [
|
|
106
112
|
'-NoProfile', '-Command',
|
|
107
113
|
`Get-Content -LiteralPath '${BUILDER.replace(/'/g, "''")}' -Raw`,
|
|
108
114
|
], { encoding: 'utf8' });
|
|
@@ -113,7 +119,7 @@ test('P4: release-build.ps1 里有明确的 NeverShip 黑名单', () => {
|
|
|
113
119
|
});
|
|
114
120
|
|
|
115
121
|
// ── P5: mochiko 必须被阻断(许可明确禁止再分发)──────────────────────────
|
|
116
|
-
test('P5: mochiko 不进发布包(官方规约禁止无偿配发音声素材)', () => {
|
|
122
|
+
test('P5: mochiko 不进发布包(官方规约禁止无偿配发音声素材)', { skip: SKIP_NO_PS7 }, () => {
|
|
117
123
|
if (!existsSync(BUILDER)) return;
|
|
118
124
|
const dest = buildRelease(['-KeepAllVoices']);
|
|
119
125
|
const leaked = findBannedAudio(dest, 'mochiko');
|
|
@@ -123,7 +129,7 @@ test('P5: mochiko 不进发布包(官方规约禁止无偿配发音声素材
|
|
|
123
129
|
});
|
|
124
130
|
|
|
125
131
|
// ── P6: Mixkit mp3 不得重新出现(许可禁止再分发素材本身)─────────────────
|
|
126
|
-
test('P6: 发布包不含任何 .mp3(Mixkit 已移除,且禁止再分发)', () => {
|
|
132
|
+
test('P6: 发布包不含任何 .mp3(Mixkit 已移除,且禁止再分发)', { skip: SKIP_NO_PS7 }, () => {
|
|
127
133
|
if (!existsSync(BUILDER)) return;
|
|
128
134
|
const dest = buildRelease(['-KeepAllVoices']);
|
|
129
135
|
const mp3 = findFiles(dest, (n) => n.toLowerCase().endsWith('.mp3'));
|
|
@@ -133,12 +139,12 @@ test('P6: 发布包不含任何 .mp3(Mixkit 已移除,且禁止再分发)'
|
|
|
133
139
|
});
|
|
134
140
|
|
|
135
141
|
// ── P7: npm files 白名单必须包含第三方声明 ──────────────────────────────
|
|
136
|
-
test('P7: 发布包 package.json 的 files 含 THIRD-PARTY-NOTICES.md', async () => {
|
|
142
|
+
test('P7: 发布包 package.json 的 files 含 THIRD-PARTY-NOTICES.md', { skip: SKIP_NO_PS7 }, async () => {
|
|
137
143
|
if (!existsSync(BUILDER)) return;
|
|
138
144
|
const dest = buildRelease([]);
|
|
139
145
|
const pkgPath = join(dest, 'package.json');
|
|
140
146
|
if (!existsSync(pkgPath)) return;
|
|
141
|
-
const pkg = JSON.parse(execFileSync(
|
|
147
|
+
const pkg = JSON.parse(execFileSync(TOOLING_PS, [
|
|
142
148
|
'-NoProfile', '-Command',
|
|
143
149
|
`Get-Content -LiteralPath '${pkgPath.replace(/'/g, "''")}' -Raw`,
|
|
144
150
|
], { encoding: 'utf8' }));
|
|
@@ -148,7 +154,7 @@ test('P7: 发布包 package.json 的 files 含 THIRD-PARTY-NOTICES.md', async ()
|
|
|
148
154
|
+ '这正是 2026-10-18 外部审阅发现的问题');
|
|
149
155
|
});
|
|
150
156
|
// ── P8: kasukabe-tsumugi 必须阻断(规约禁止「二次配布」)────────────────
|
|
151
|
-
test('P8: kasukabe-tsumugi 不进发布包(官方规约禁止二次配布)', () => {
|
|
157
|
+
test('P8: kasukabe-tsumugi 不进发布包(官方规约禁止二次配布)', { skip: SKIP_NO_PS7 }, () => {
|
|
152
158
|
if (!existsSync(BUILDER)) return;
|
|
153
159
|
const dest = buildRelease(['-KeepAllVoices']);
|
|
154
160
|
const leaked = findBannedAudio(dest, 'kasukabe-tsumugi');
|
|
@@ -159,7 +165,7 @@ test('P8: kasukabe-tsumugi 不进发布包(官方规约禁止二次配布)',
|
|
|
159
165
|
});
|
|
160
166
|
|
|
161
167
|
// ── P9: yurei-chan 必须阻断(身份未确认)────────────────────────────────
|
|
162
|
-
test('P9: yurei-chan 不进发布包(角色身份未确认)', () => {
|
|
168
|
+
test('P9: yurei-chan 不进发布包(角色身份未确认)', { skip: SKIP_NO_PS7 }, () => {
|
|
163
169
|
if (!existsSync(BUILDER)) return;
|
|
164
170
|
const dest = buildRelease(['-KeepAllVoices']);
|
|
165
171
|
const leaked = findBannedAudio(dest, 'yurei-chan');
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 发通知用的 AUMID 必须是「本机真的注册过的那一个」(v0.5.4 提议)。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么这个文件必须存在
|
|
5
|
+
*
|
|
6
|
+
* 2026-10-25 用户实测截图:Toast 标题行印的是 **`com.deepseek.dsh`** 这串原始
|
|
7
|
+
* AUMID,名字旁边没有小图标。而 `Show()` **不抛异常** —— 旧实现的 try/catch
|
|
8
|
+
* 完全兜不住这类"静默降级",界面难看但日志全绿。
|
|
9
|
+
*
|
|
10
|
+
* 根因:官方壳的 AUMID 并非处处一致。官方安装包注册 `com.deepseek.dsh`,
|
|
11
|
+
* 而 Electron 默认身份(开始菜单快捷方式里带的正是它)是
|
|
12
|
+
* `electron.app.<ProductName>`。写死的那个没注册时,Windows 只好把 AUMID
|
|
13
|
+
* 原文当应用名,并从快捷方式拿不到图标。
|
|
14
|
+
*
|
|
15
|
+
* ## 关键契约
|
|
16
|
+
*
|
|
17
|
+
* | 项 | 要求 |
|
|
18
|
+
* |---|---|
|
|
19
|
+
* | 探测来源 | `Get-StartApps` 里名字/AppID 命中 DeepSeek Harness 的项 |
|
|
20
|
+
* | 缓存 | 落盘到 `%LOCALAPPDATA%\dsh-notify-say\toast-aumid.txt`,避免每条通知都付 ~540ms |
|
|
21
|
+
* | 纯兜底不写缓存 | 探测失败时不能把兜底值固化,否则一次网络/时序抖动永久生效 |
|
|
22
|
+
* | 兜底 | 仍是 `com.deepseek.dsh` → `Microsoft.Windows.Shell.RunDialog`,行为可回退 |
|
|
23
|
+
* | `$shown` | 只在**成功 Show** 之后置 true(旧实现无条件置 true,兜底链形同虚设) |
|
|
24
|
+
* | BOM | 文件必须以 UTF-8 BOM 开头,否则 PowerShell 5.1 按 ANSI 解析中文注释 → 语法错 |
|
|
25
|
+
*
|
|
26
|
+
* 只读源码文本,不启动 PowerShell:CI 上没有 DSH 安装,Get-StartApps 探测必然为空,
|
|
27
|
+
* 跑真进程只会得到"环境缺失"的假失败。
|
|
28
|
+
*/
|
|
29
|
+
import { test } from 'node:test';
|
|
30
|
+
import assert from 'node:assert/strict';
|
|
31
|
+
import { readFileSync } from 'node:fs';
|
|
32
|
+
import { join } from 'node:path';
|
|
33
|
+
|
|
34
|
+
const ROOT = new URL('..', import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1');
|
|
35
|
+
const PS1 = readFileSync(join(ROOT, 'dsh-notify.ps1'), 'utf8');
|
|
36
|
+
|
|
37
|
+
test('A1 定义了 Get-ToastAppId,并且用 Get-StartApps 探测', () => {
|
|
38
|
+
assert.match(PS1, /function\s+Get-ToastAppId/, '必须存在 Get-ToastAppId');
|
|
39
|
+
assert.match(PS1, /Get-StartApps/, '必须用 Get-StartApps 找"真的注册过"的 AUMID');
|
|
40
|
+
assert.ok(PS1.includes('DeepSeek\\s*Harness'), '要按显示名匹配 DeepSeek Harness');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('A2 探测结果落盘缓存,且路径在 LOCALAPPDATA 下', () => {
|
|
44
|
+
assert.match(PS1, /toast-aumid\.txt/, '缓存文件名应为 toast-aumid.txt');
|
|
45
|
+
assert.match(PS1, /LOCALAPPDATA/, '缓存必须放在用户可写目录,不能放安装目录');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('A3 纯兜底不写缓存(一次失败不能被永久固化)', () => {
|
|
49
|
+
// 形如:if ($list.Count -gt 2) { ... Set-Content ... }
|
|
50
|
+
assert.match(
|
|
51
|
+
PS1,
|
|
52
|
+
/if\s*\(\s*\$list\.Count\s*-gt\s*2\s*\)/,
|
|
53
|
+
'只有探测成功(列表里有第 3 个候选)才写缓存',
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('A4 兜底链保持不变:com.deepseek.dsh → RunDialog', () => {
|
|
58
|
+
const a = PS1.indexOf("'com.deepseek.dsh'");
|
|
59
|
+
const b = PS1.indexOf("'Microsoft.Windows.Shell.RunDialog'");
|
|
60
|
+
assert.ok(a > 0, '兜底里必须保留 com.deepseek.dsh');
|
|
61
|
+
assert.ok(b > a, 'RunDialog 应排在 com.deepseek.dsh 之后(更晚兜底)');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('A5 Show 走候选循环,而不是写死一个 AUMID', () => {
|
|
65
|
+
assert.match(PS1, /foreach\s*\(\s*\$toastAumid\s+in\s+\$toastAumids\s*\)/, '按候选逐个 Show');
|
|
66
|
+
assert.match(
|
|
67
|
+
PS1,
|
|
68
|
+
/CreateToastNotifier\(\$toastAumid\)/,
|
|
69
|
+
'Show 的入参必须是循环变量,不能是字面量',
|
|
70
|
+
);
|
|
71
|
+
assert.ok(
|
|
72
|
+
!/CreateToastNotifier\('com\.deepseek\.dsh'\)\s*\.Show/.test(PS1),
|
|
73
|
+
'不允许再出现写死 com.deepseek.dsh 的直接 Show(那正是回归点)',
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('A6 $shown 只在成功 Show 之后置 true', () => {
|
|
78
|
+
// 旧实现:try/catch 之后无条件 $shown = $true,兜底链等于没生效
|
|
79
|
+
const loop = PS1.slice(PS1.indexOf('foreach ($toastAumid in $toastAumids)'));
|
|
80
|
+
const shownIdx = loop.indexOf('$shown = $true');
|
|
81
|
+
const breakIdx = loop.indexOf('break');
|
|
82
|
+
assert.ok(shownIdx > 0, '循环里必须设置 $shown');
|
|
83
|
+
assert.ok(shownIdx < breakIdx, '$shown 必须在 break 之前(即 Show 成功之后)');
|
|
84
|
+
assert.ok(
|
|
85
|
+
!/\}\s*\r?\n\s*\$shown = \$true\s*\r?\n/.test(PS1),
|
|
86
|
+
'不允许在 try/catch 之外无条件置 $shown = $true',
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('A8 Get-ToastAppId 必须在**调用点之前**定义(PowerShell 不 hoist 函数)', () => {
|
|
91
|
+
// PR 原作者把 Get-ToastAppId 写在调用点**之后**。PowerShell 不会 hoist 函数定义,
|
|
92
|
+
// 于是 @(Get-ToastAppId) 抛 CommandNotFoundException —— 而那个调用点在 try 块里,
|
|
93
|
+
// 异常被 `catch { $shown = $false }` 吞掉,表现是**每一条通知都不弹 + 走兜底提示音**。
|
|
94
|
+
//
|
|
95
|
+
// 实测(真 5.1,-Kind done):PR 原样 → "(Toast 不可用,走兜底)",修复后 → "OK Toast"。
|
|
96
|
+
// 这是"改动看起来只是换个 AppID、实际把功能整个关掉"的典型,必须由判据钉住,
|
|
97
|
+
// 否则以后谁再搬动这段代码都会重演一次。
|
|
98
|
+
const defIdx = PS1.indexOf('function Get-ToastAppId');
|
|
99
|
+
assert.ok(defIdx > 0, '必须定义 Get-ToastAppId');
|
|
100
|
+
const callIdx = PS1.indexOf('Get-ToastAppId)', defIdx);
|
|
101
|
+
// 调用形态是 @(Get-ToastAppId) —— 找的是**定义之前**有没有调用
|
|
102
|
+
const firstCall = PS1.indexOf('@(Get-ToastAppId)');
|
|
103
|
+
assert.ok(firstCall > 0, '必须真的调用 Get-ToastAppId');
|
|
104
|
+
assert.ok(
|
|
105
|
+
defIdx < firstCall,
|
|
106
|
+
`定义在第 ${PS1.slice(0, defIdx).split('\n').length} 行,但第 `
|
|
107
|
+
+ `${PS1.slice(0, firstCall).split('\n').length} 行就调用了 —— `
|
|
108
|
+
+ 'PowerShell 不会 hoist 函数,调用点会抛 CommandNotFoundException,'
|
|
109
|
+
+ '而它在 try 块里会被 catch 静默吞掉,结果是所有 Toast 都不弹',
|
|
110
|
+
);
|
|
111
|
+
assert.ok(callIdx !== -1 || firstCall !== -1, '调用点写法应与本判据一致');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('A7 文件以 UTF-8 BOM 开头(PowerShell 5.1 解析中文注释的前提)', () => {
|
|
115
|
+
const head = readFileSync(join(ROOT, 'dsh-notify.ps1')).subarray(0, 3);
|
|
116
|
+
assert.deepEqual(
|
|
117
|
+
[...head],
|
|
118
|
+
[0xef, 0xbb, 0xbf],
|
|
119
|
+
'BOM 被编辑器吃掉后,PS 5.1 会按 ANSI 读中文注释,直接语法错(实测过一次)',
|
|
120
|
+
);
|
|
121
|
+
});
|
|
@@ -44,6 +44,7 @@ import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, exis
|
|
|
44
44
|
import { tmpdir } from 'node:os';
|
|
45
45
|
import { fileURLToPath } from 'node:url';
|
|
46
46
|
import { dirname, join } from 'node:path';
|
|
47
|
+
import { RUNTIME_PS } from './ps-interp.mjs';
|
|
47
48
|
|
|
48
49
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
49
50
|
const PLUGIN = join(HERE, '..');
|
|
@@ -88,7 +89,7 @@ function makeShippedVoiceRoot() {
|
|
|
88
89
|
function runPs1(args, logDir) {
|
|
89
90
|
const env = { ...process.env };
|
|
90
91
|
if (logDir) env.DSH_NOTIFY_SAY_LOG_DIR = logDir;
|
|
91
|
-
const r = spawnSync(
|
|
92
|
+
const r = spawnSync(RUNTIME_PS,
|
|
92
93
|
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', PS1, ...args],
|
|
93
94
|
{ encoding: 'utf8', timeout: 60_000, env });
|
|
94
95
|
return {
|
|
@@ -25,6 +25,7 @@ import { readFileSync, existsSync, mkdtempSync, mkdirSync, writeFileSync, rmSync
|
|
|
25
25
|
import { tmpdir } from 'node:os';
|
|
26
26
|
import { resolve, dirname, join } from 'node:path';
|
|
27
27
|
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { RUNTIME_PS } from './ps-interp.mjs';
|
|
28
29
|
|
|
29
30
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
30
31
|
const CLIENT = readFileSync(join(ROOT, 'lib', 'client.js'), 'utf8');
|
|
@@ -83,7 +84,7 @@ const PS1 = join(ROOT, 'dsh-notify.ps1');
|
|
|
83
84
|
// 惰性导入后,只有真正调 runPs1 时才解析,而 route 段里 L2b 是 skip 的。
|
|
84
85
|
async function runPs1(args) {
|
|
85
86
|
const { spawnSync } = await import('node:child_process');
|
|
86
|
-
const r = spawnSync(
|
|
87
|
+
const r = spawnSync(RUNTIME_PS,
|
|
87
88
|
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', PS1, ...args],
|
|
88
89
|
{ encoding: 'utf8', timeout: 60_000 });
|
|
89
90
|
return {
|
package/test/wav-gain.test.mjs
CHANGED
|
@@ -25,6 +25,7 @@ import { existsSync, unlinkSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
|
25
25
|
import { tmpdir } from 'node:os';
|
|
26
26
|
import { join, resolve, dirname } from 'node:path';
|
|
27
27
|
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { RUNTIME_PS } from './ps-interp.mjs';
|
|
28
29
|
|
|
29
30
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
30
31
|
const GAIN_LIB = join(ROOT, 'lib', 'wav-gain.ps1');
|
|
@@ -38,7 +39,7 @@ function ps(code) {
|
|
|
38
39
|
// 中文全变乱码并报语法错(本项目踩过)。
|
|
39
40
|
writeFileSync(file, '\uFEFF' + code, 'utf8');
|
|
40
41
|
try {
|
|
41
|
-
return execFileSync(
|
|
42
|
+
return execFileSync(RUNTIME_PS, [
|
|
42
43
|
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', file,
|
|
43
44
|
], { encoding: 'utf8', timeout: 120_000 });
|
|
44
45
|
} finally {
|
package/tools/notify-config.ps1
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
#Requires -Version 5.1
|
|
2
|
+
# 最低 PowerShell 5.1 —— 本文件随 npm 包发给用户、README 教用户直接运行,Windows 出厂只有 5.1。
|
|
3
|
+
# 它带 UTF-8 BOM 且不含 PS7 独有语法(ADR-0015 L3 担心的「5.1 误读无 BOM 中文」不成立),
|
|
4
|
+
# 5.1 下 JSON 往返实测无损(20/20 键含中文)。不要改成 7.0 —— 见踩坑 #495。
|
|
5
|
+
|
|
6
|
+
<#
|
|
2
7
|
.SYNOPSIS
|
|
3
8
|
dsh-notify-say 配置命令行(v0.4.0 的「第 4 层」运行时覆盖)。
|
|
4
9
|
|
|
@@ -104,7 +109,7 @@ $ErrorActionPreference = 'Stop'
|
|
|
104
109
|
|
|
105
110
|
# ── 路径解析 ────────────────────────────────────────────────────────────────
|
|
106
111
|
# 本脚本位于 <plugin>/tools/,插件根 = 上一级。
|
|
107
|
-
# ⚠️ 不能用 $MyInvocation.MyCommand.Path —— 经 `
|
|
112
|
+
# ⚠️ 不能用 $MyInvocation.MyCommand.Path —— 经 `pwsh -File` 启动时它可能为空,
|
|
108
113
|
# 导致 $pluginRoot 变成 $null、进而 Join-Path 拼出错误路径(实测踩到)。
|
|
109
114
|
# 用 $PSScriptRoot(-File 与点源两种方式都可靠)+ $MyInvocation.MyCommand.Definition 兜底。
|
|
110
115
|
$scriptPath = $PSScriptRoot
|