dsh-notify-say 0.6.0 → 0.6.1
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/client.js +58 -2
- package/lib/index.js +39 -0
- package/package.json +1 -1
- package/test/boot-selfcheck.test.mjs +51 -0
- package/test/client-bundle.test.mjs +124 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
> 本文件由 `tools/release-build.ps1` 从开发提交自动生成,**请勿手工编辑**。
|
|
4
4
|
> 只列面向使用者的变更(新增功能与修复),不含内部维护提交。
|
|
5
5
|
|
|
6
|
+
## v0.6.1 — 2026-11-27
|
|
7
|
+
|
|
8
|
+
- fix(notify-say): 启动守卫 + 前端启动自检,修重启时被同批插件连累成致命框 (v0.6.1)
|
|
9
|
+
|
|
6
10
|
## v0.6.0 — 2026-11-27
|
|
7
11
|
|
|
8
12
|
- feat(notify-say): 播放通道改为渲染进程 WebAudio,修 powershell.exe 应用音量被拉低即静音 (v0.6.0)
|
package/lib/client.js
CHANGED
|
@@ -26,7 +26,31 @@
|
|
|
26
26
|
// - route 不可达 → 不跳转,不报错
|
|
27
27
|
//
|
|
28
28
|
// 任何一环失败都只是"少一个增强",绝不拖累页面。
|
|
29
|
-
|
|
29
|
+
// ── 启动守卫(v0.6.1)──────────────────────────────────────────────────────
|
|
30
|
+
//
|
|
31
|
+
// ## 为什么需要这层 try/catch
|
|
32
|
+
//
|
|
33
|
+
// DSH 桌面端把多个插件的 client 打成一个 batch combo,用一个 classic script
|
|
34
|
+
// 下发(形如 `plugins/??a/client.js,b/client.js,…,dsh-notify-say/client.js,…`)。
|
|
35
|
+
// 那个脚本里**任何一个包**解析失败或中途抛错,排在后面的所有
|
|
36
|
+
// `__ModuleLoader__.load()` 都不会执行;web-boot 随后会把「没有 fiber」的每个
|
|
37
|
+
// entry 都记成 `import failed`,只要有 1 个就弹致命框。
|
|
38
|
+
//
|
|
39
|
+
// 2026-11-27 18:45 实测:同批的 dsh-light-guard 因为一行 TS 残留
|
|
40
|
+
// (`Unexpected token ':'`)解析失败,整批注册作废,弹窗点名的却是我们。
|
|
41
|
+
//
|
|
42
|
+
// 所以我们至少要保证两件事:
|
|
43
|
+
//
|
|
44
|
+
// 1. **我们自己不抛。** 同一个 realm 内 bundle 被执行第二次时,loader 会抛
|
|
45
|
+
// `client-modules: duplicate factory registration …`(见 DSH
|
|
46
|
+
// ClientModuleSystem.register)。那是正常的重复启动/热重载,吞掉即可。
|
|
47
|
+
// 2. **我们的其他错误不连累邻居。** 用 queueMicrotask 重新抛出:错误照样
|
|
48
|
+
// 进 console(不掩盖真问题),但 batch 里后面的包还能继续注册。
|
|
49
|
+
//
|
|
50
|
+
// ⚠️ 刻意**不用**全局布尔锁(如 `if (booted) return`):锁死会让真正的热重载
|
|
51
|
+
// (invalidate 之后重新执行 bundle)失效。只按错误文案判断。
|
|
52
|
+
try {
|
|
53
|
+
window.__ModuleLoader__.load({
|
|
30
54
|
id: 'dsh-notify-say',
|
|
31
55
|
factory: (require) => {
|
|
32
56
|
var module = { exports: {} }
|
|
@@ -3491,7 +3515,27 @@ window.__ModuleLoader__.load({
|
|
|
3491
3515
|
}
|
|
3492
3516
|
}
|
|
3493
3517
|
|
|
3518
|
+
/**
|
|
3519
|
+
* 出口兜底(v0.6.1)。
|
|
3520
|
+
*
|
|
3521
|
+
* 为什么:apply 里任何**未预料**的异常都会让 cordis 把这个 fiber 记成
|
|
3522
|
+
* failed → web-boot 判定「entry 没激活」→ 弹致命框。本函数内部的三段
|
|
3523
|
+
* 早已各自 try/catch,但出口本身没有兜底:以后在 apply 里加一行新代码,
|
|
3524
|
+
* 就可能把整个前端启动拖垮。
|
|
3525
|
+
*
|
|
3526
|
+
* 口径:只兜底、不掩盖 —— 记一条 `[apply] failed: …` 进 notify.log,
|
|
3527
|
+
* 然后返回空 disposer(少一个增强,页面照常)。
|
|
3528
|
+
*/
|
|
3494
3529
|
function apply(ctx) {
|
|
3530
|
+
try {
|
|
3531
|
+
return applyInner(ctx)
|
|
3532
|
+
} catch (e) {
|
|
3533
|
+
try { uiLog('[apply] failed: ' + String((e && e.message) || e)) } catch (x) { /* ignore */ }
|
|
3534
|
+
return function () { /* 降级路径:没有任何东西需要清理 */ }
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
function applyInner(ctx) {
|
|
3495
3539
|
// v0.4.76:**启动即上报**。刷新页面后应立刻看到这条 ——
|
|
3496
3540
|
// 它是判断「前端跑的是哪一版代码」最可靠的方法。
|
|
3497
3541
|
// (2026-10-20 排查「自动跳转」时,因为没有任何启动标记,
|
|
@@ -3548,4 +3592,16 @@ window.__ModuleLoader__.load({
|
|
|
3548
3592
|
exports.name = name
|
|
3549
3593
|
return module.exports
|
|
3550
3594
|
},
|
|
3551
|
-
})
|
|
3595
|
+
})
|
|
3596
|
+
} catch (err) {
|
|
3597
|
+
// 文案匹配刻意放宽(/duplicate|already/i):宿主改了措辞也不至于让守卫失效。
|
|
3598
|
+
const msg = String((err && err.message) || err || '')
|
|
3599
|
+
if (!/duplicate|already/i.test(msg)) {
|
|
3600
|
+
// 不是重复注册 → 这是真问题,必须让人看见;但用 microtask 抛出,
|
|
3601
|
+
// 避免打断同批其他包的注册(batch 是同步顺序执行的)。
|
|
3602
|
+
try {
|
|
3603
|
+
if (typeof queueMicrotask === 'function') queueMicrotask(function () { throw err })
|
|
3604
|
+
else setTimeout(function () { throw err }, 0)
|
|
3605
|
+
} catch (e) { /* 连抛出都失败就放弃,绝不因此再抛一次 */ }
|
|
3606
|
+
}
|
|
3607
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -3434,8 +3434,39 @@ function hasVoiceLine(psKind) {
|
|
|
3434
3434
|
console.warn('[dsh-notify-say] 订阅 jobs 变化抛错: ' + String((e && e.message) || e));
|
|
3435
3435
|
}
|
|
3436
3436
|
|
|
3437
|
+
// ── 前端启动自检(v0.6.1)──────────────────────────────────────────────
|
|
3438
|
+
//
|
|
3439
|
+
// 为什么需要:DSH 的 web-boot 若判定「有 entry 没激活」,会弹致命框;而失败
|
|
3440
|
+
// 的那一方**可能一条日志都发不出来**(bundle 根本没执行)。于是 notify.log
|
|
3441
|
+
// 里会是「什么都没有」——事后无法区分「前端没起来」和「起来了但没干活」。
|
|
3442
|
+
//
|
|
3443
|
+
// 这条自检让「什么都没有」本身变成一条可检索的证据:
|
|
3444
|
+
// 宿主启动 45s 内没收到任何 `[ui] CLIENT-BOOT` → 记 [boot] client never booted。
|
|
3445
|
+
//
|
|
3446
|
+
// ⚠️ 为什么不是 10s:用户可能启动后很久才开窗口(宿主常驻托盘)。
|
|
3447
|
+
// 所以只在启动时判一次,且判据是「一条 CLIENT-BOOT 都没有」,不是「最近一条太旧」。
|
|
3448
|
+
//
|
|
3449
|
+
// ⚠️ 为什么要挂在 globalThis 上:热重载会**重新 import 本模块**,模块级变量
|
|
3450
|
+
// 会清零;而页面并没有重新加载,CLIENT-BOOT 也不会再来一次 —— 于是每次热重载
|
|
3451
|
+
// 都会在 45s 后误报一次「前端没起来」。用进程级标记,热重载前后共享。
|
|
3452
|
+
const BOOT_SEEN_KEY = '__dshNotifySayClientBootSeen';
|
|
3453
|
+
let clientBootSeen = false;
|
|
3454
|
+
try { clientBootSeen = globalThis[BOOT_SEEN_KEY] === true; } catch { /* ignore */ }
|
|
3455
|
+
const BOOT_SELFCHECK_MS = 45000;
|
|
3456
|
+
let bootCheckTimer = null;
|
|
3457
|
+
if (!clientBootSeen) {
|
|
3458
|
+
bootCheckTimer = setTimeout(() => {
|
|
3459
|
+
if (clientBootSeen) return;
|
|
3460
|
+
appendNotifyLog('[boot] client never booted within 45s —— 前端 bundle 可能没执行'
|
|
3461
|
+
+ '(web-boot 失败;常见原因:同批其他插件的 client.js 解析失败,见 DSH crash-*-web-boot.log。'
|
|
3462
|
+
+ '若你是稍后才打开窗口,忽略本条)');
|
|
3463
|
+
}, BOOT_SELFCHECK_MS);
|
|
3464
|
+
if (bootCheckTimer && typeof bootCheckTimer.unref === 'function') bootCheckTimer.unref();
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3437
3467
|
// ── 卸载清理:挂起计时器与状态(监听器由插件 fiber 自动回收)──────────────
|
|
3438
3468
|
ctx.effect(() => () => {
|
|
3469
|
+
clearTimeout(bootCheckTimer);
|
|
3439
3470
|
for (const p of pendingDone.values()) {
|
|
3440
3471
|
clearTimeout(p.timer);
|
|
3441
3472
|
// v0.5.11:静默期定时器必须一起清 —— 热重载时旧实例若留着它会
|
|
@@ -3662,6 +3693,14 @@ function hasVoiceLine(psKind) {
|
|
|
3662
3693
|
const o = JSON.parse(rawBody || '{}');
|
|
3663
3694
|
const msg = String(o.msg || '').slice(0, 500);
|
|
3664
3695
|
if (msg) appendNotifyLog(`[ui] ${msg}`);
|
|
3696
|
+
// v0.6.1:看到前端自报启动,就说明 bundle 执行过了。
|
|
3697
|
+
// 置位后启动自检不再告警(见 BOOT_SELFCHECK_MS)。
|
|
3698
|
+
// 同时写进 globalThis:热重载后模块级变量会清零,但页面不会重新加载。
|
|
3699
|
+
if (msg && msg.indexOf('CLIENT-BOOT') >= 0) {
|
|
3700
|
+
clientBootSeen = true;
|
|
3701
|
+
try { globalThis[BOOT_SEEN_KEY] = true; } catch { /* ignore */ }
|
|
3702
|
+
if (bootCheckTimer) { clearTimeout(bootCheckTimer); bootCheckTimer = null; }
|
|
3703
|
+
}
|
|
3665
3704
|
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
3666
3705
|
res.end(JSON.stringify({ ok: true }));
|
|
3667
3706
|
} catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-say",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 前端启动自检(v0.6.1)的源码契约测试。
|
|
3
|
+
*
|
|
4
|
+
* 背景:DSH web-boot 失败时,前端可能一条日志都发不出来,notify.log 里会是
|
|
5
|
+
* 「什么都没有」——事后无法区分「前端没起来」与「起来了但没干活」。
|
|
6
|
+
*
|
|
7
|
+
* 这条自检把「什么都没有」变成一条可检索的证据:宿主启动 45s 内收不到任何
|
|
8
|
+
* `[ui] CLIENT-BOOT` 就记 `[boot] client never booted …`。
|
|
9
|
+
*
|
|
10
|
+
* 为什么用源码断言而不是跑真宿主:自检逻辑嵌在 `apply(ctx, config)` 内部,
|
|
11
|
+
* 直接跑需要伪造 cordis + webServer + 45s 时钟,成本远高于收益;
|
|
12
|
+
* 这里钉住「判定条件、进程级标记、清理」三个易漂移点。
|
|
13
|
+
*/
|
|
14
|
+
import { test } from 'node:test';
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { dirname, join, resolve } from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
|
|
20
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
|
+
const INDEX = readFileSync(join(ROOT, 'lib', 'index.js'), 'utf8');
|
|
22
|
+
|
|
23
|
+
test('B1: 启动自检存在,判据是 45s 内没收到 CLIENT-BOOT', () => {
|
|
24
|
+
assert.match(INDEX, /BOOT_SELFCHECK_MS\s*=\s*45000/, '自检窗口应为 45s');
|
|
25
|
+
assert.match(INDEX, /\[boot\] client never booted within 45s/,
|
|
26
|
+
'超时日志必须可检索(诊断导出时靠它判断前端是否起来)');
|
|
27
|
+
// 必须在超时回调里再判一次,避免定时器与 CLIENT-BOOT 的竞态
|
|
28
|
+
assert.match(INDEX, /bootCheckTimer\s*=\s*setTimeout\(\(\)\s*=>\s*\{\s*\n\s*if \(clientBootSeen\) return;/,
|
|
29
|
+
'超时回调必须先复查 clientBootSeen');
|
|
30
|
+
// 定时器不应拖住进程退出
|
|
31
|
+
assert.match(INDEX, /bootCheckTimer\.unref\(\)/, '定时器必须 unref');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('B2: 用进程级标记,热重载不会误报', () => {
|
|
35
|
+
// 热重载会重新 import 本模块(模块级变量清零),但页面不会重新加载、
|
|
36
|
+
// CLIENT-BOOT 也不会再来一次 → 若只用模块级变量,每次热重载都会误报。
|
|
37
|
+
assert.match(INDEX, /__dshNotifySayClientBootSeen/,
|
|
38
|
+
'必须用 globalThis 上的进程级标记,热重载前后共享');
|
|
39
|
+
assert.match(INDEX, /globalThis\[BOOT_SEEN_KEY\]\s*=\s*true/,
|
|
40
|
+
'收到 CLIENT-BOOT 时必须写进程级标记');
|
|
41
|
+
assert.match(INDEX, /globalThis\[BOOT_SEEN_KEY\]\s*===\s*true/,
|
|
42
|
+
'apply 时必须读进程级标记,已启动过就不再起窗');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('B3: 收到 CLIENT-BOOT 时置位并清掉定时器;dispose 也要清', () => {
|
|
46
|
+
assert.match(INDEX, /msg\.indexOf\('CLIENT-BOOT'\)\s*>=\s*0/,
|
|
47
|
+
'必须按日志内容识别前端启动');
|
|
48
|
+
assert.match(INDEX, /if \(bootCheckTimer\) \{ clearTimeout\(bootCheckTimer\); bootCheckTimer = null; \}/,
|
|
49
|
+
'置位后要立刻清定时器,别让 45s 到点再打一遍日志');
|
|
50
|
+
assert.match(INDEX, /clearTimeout\(bootCheckTimer\)/, 'dispose 必须清定时器');
|
|
51
|
+
});
|
|
@@ -721,3 +721,127 @@ test('C27: 设置页必须提供「点击通知跳到对应会话」开关', ()
|
|
|
721
721
|
'设置页注释里还留着"点通知才跳做不到"的旧结论(未标注更正)');
|
|
722
722
|
});
|
|
723
723
|
|
|
724
|
+
// ══════════════════════════════════════════════════════════════════════════
|
|
725
|
+
// v0.6.1 启动守卫(C28–C32)
|
|
726
|
+
//
|
|
727
|
+
// 背景:DSH 把多个插件的 client 打进同一个 classic script batch。同批里任一
|
|
728
|
+
// 包解析失败或抛错,排在后面的 `__ModuleLoader__.load()` 全都不会执行,随后
|
|
729
|
+
// web-boot 把「没有 fiber」的每个 entry 都记成 import failed 并弹致命框
|
|
730
|
+
// (2026-11-27 18:45 实测:dsh-light-guard 有一行 TS 残留,弹窗却点名我们)。
|
|
731
|
+
//
|
|
732
|
+
// 这些用例钉住三件事:①我们的产物自己必须能当 classic script 解析;
|
|
733
|
+
// ②顶层注册必须容错且**不能**用全局布尔锁(否则热重载失效);
|
|
734
|
+
// ③真错误仍要被抛出(异步),不能被静默吞掉。
|
|
735
|
+
// ══════════════════════════════════════════════════════════════════════════
|
|
736
|
+
|
|
737
|
+
// ── C28: 产物必须能被 classic script 解析 ──────────────────────────────────
|
|
738
|
+
test('C28: client.js 能被 new Function 解析(classic script 门)', () => {
|
|
739
|
+
const src = readClient();
|
|
740
|
+
// 这一条就是 18:45 那次事故的镜像:同批的别的插件在这里炸了,
|
|
741
|
+
// 我们被连坐。我们自己的产物必须永远过这道门。
|
|
742
|
+
assert.doesNotThrow(() => { /* eslint-disable-next-line no-new-func */
|
|
743
|
+
new Function(src);
|
|
744
|
+
}, 'client.js 必须能被当作 classic script 解析(出现 TS 语法/顶层 await 就会整批作废)');
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// ── C29: 顶层注册必须包在 try/catch 里,且不用全局布尔锁 ────────────────────
|
|
748
|
+
test('C29: 顶层 load() 被 try/catch 包住,duplicate 匹配宽松,且无全局布尔锁', () => {
|
|
749
|
+
const src = readClient();
|
|
750
|
+
|
|
751
|
+
// ① load 调用必须在 try 块里
|
|
752
|
+
assert.match(src, /try\s*\{[\s\S]{0,400}?window\.__ModuleLoader__\.load\s*\(\s*\{/,
|
|
753
|
+
'window.__ModuleLoader__.load(...) 必须被 try 包住 —— 否则重复注册会整批拖垮');
|
|
754
|
+
|
|
755
|
+
// ② catch 里必须按文案识别「重复注册」,且文案匹配要宽松
|
|
756
|
+
// (宿主改措辞也不该让守卫失效;对应 DSH ClientModuleSystem.register 的报错)
|
|
757
|
+
assert.match(src, /\}\s*catch\s*\(\s*err\s*\)\s*\{/,
|
|
758
|
+
'顶层必须有 catch (err) 分支');
|
|
759
|
+
assert.match(src, /\/duplicate\|already\/i/,
|
|
760
|
+
'duplicate 判定必须用宽松正则 /duplicate|already/i,不要精确匹配宿主文案');
|
|
761
|
+
|
|
762
|
+
// ③ 反面断言:不许用全局布尔锁把二次执行直接挡掉 —— 那会让真正的热重载失效
|
|
763
|
+
assert.doesNotMatch(src, /if\s*\(\s*(?:window\.)?__?[A-Za-z]*[Bb]ooted\s*\)\s*return/,
|
|
764
|
+
'不得用全局 booted 布尔锁短路(会让热重载后 bundle 拒绝重新注册)');
|
|
765
|
+
assert.doesNotMatch(src, /^\s*(?:var|let|const)\s+booted\s*=/m,
|
|
766
|
+
'不得引入模块级 booted 标志');
|
|
767
|
+
|
|
768
|
+
// ④ 真错误不能被吞:必须异步重抛(microtask 优先,setTimeout 兜底)
|
|
769
|
+
assert.match(src, /queueMicrotask\s*\(\s*function\s*\(\s*\)\s*\{\s*throw\s+err/,
|
|
770
|
+
'非 duplicate 错误必须用 queueMicrotask 重新抛出,让 console 看得见');
|
|
771
|
+
assert.match(src, /setTimeout\s*\(\s*function\s*\(\s*\)\s*\{\s*throw\s+err\s*\}/,
|
|
772
|
+
'queueMicrotask 不可用时要有 setTimeout 兜底');
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// ── C30: 重复执行时 duplicate 被吞掉(真实执行,不只是文本断言)─────────────
|
|
776
|
+
test('C30: 同 realm 内重复执行两次不抛错(duplicate 被吞)', () => {
|
|
777
|
+
const src = readClient();
|
|
778
|
+
let calls = 0;
|
|
779
|
+
const fakeWindow = {
|
|
780
|
+
__ModuleLoader__: {
|
|
781
|
+
load() {
|
|
782
|
+
calls += 1;
|
|
783
|
+
if (calls > 1) {
|
|
784
|
+
throw new Error('client-modules: duplicate factory registration for "dsh-notify-say" '
|
|
785
|
+
+ '(bundle executed twice without invalidate?)');
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
},
|
|
789
|
+
addEventListener() {},
|
|
790
|
+
removeEventListener() {},
|
|
791
|
+
};
|
|
792
|
+
// eslint-disable-next-line no-new-func
|
|
793
|
+
const run = new Function('window', 'document', src);
|
|
794
|
+
assert.doesNotThrow(() => run(fakeWindow, undefined), '第一次执行应成功');
|
|
795
|
+
assert.doesNotThrow(() => run(fakeWindow, undefined),
|
|
796
|
+
'第二次执行撞 duplicate 时必须静默 —— 否则会打断同批其他插件的注册');
|
|
797
|
+
assert.equal(calls, 2, '两次都应真的调用到 load(守卫是 catch,不是提前 return)');
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
// ── C31: 非 duplicate 错误改为异步抛出(不阻断同批邻居)────────────────────
|
|
801
|
+
test('C31: 非 duplicate 的启动错误异步重抛,不同步抛出', () => {
|
|
802
|
+
const src = readClient();
|
|
803
|
+
const fakeWindow = {
|
|
804
|
+
__ModuleLoader__: {
|
|
805
|
+
load() { throw new Error('boom: 这是真错误,不能被吞'); },
|
|
806
|
+
},
|
|
807
|
+
addEventListener() {},
|
|
808
|
+
removeEventListener() {},
|
|
809
|
+
};
|
|
810
|
+
const queued = [];
|
|
811
|
+
// eslint-disable-next-line no-new-func
|
|
812
|
+
const run = new Function('window', 'document', 'queueMicrotask', src);
|
|
813
|
+
|
|
814
|
+
assert.doesNotThrow(() => run(fakeWindow, undefined, (fn) => { queued.push(fn); }),
|
|
815
|
+
'真错误也不能同步抛 —— 同步抛会打断 batch 里后面插件的注册');
|
|
816
|
+
assert.equal(queued.length, 1, '真错误必须被排队重抛(不能静默吞掉)');
|
|
817
|
+
assert.throws(() => queued[0](), /boom: 这是真错误/,
|
|
818
|
+
'排队的那次执行必须真的抛出原错误,让 console 留痕');
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
// ── C32: apply 出口兜底(任何未预料异常都不该让 fiber failed)───────────────
|
|
822
|
+
test('C32: apply 有出口兜底,主体在 applyInner 里', () => {
|
|
823
|
+
const src = readClient();
|
|
824
|
+
|
|
825
|
+
assert.match(src, /function applyInner\s*\(\s*ctx\s*\)\s*\{/,
|
|
826
|
+
'apply 主体应拆到 applyInner,外层只负责兜底');
|
|
827
|
+
assert.match(src, /function apply\s*\(\s*ctx\s*\)\s*\{[\s\S]{0,600}?return applyInner\s*\(\s*ctx\s*\)/,
|
|
828
|
+
'外层 apply 必须把调用转发给 applyInner');
|
|
829
|
+
assert.match(src, /catch\s*\(\s*e\s*\)\s*\{[\s\S]{0,300}?\[apply\] failed/,
|
|
830
|
+
'兜底必须记一条 [apply] failed 日志(不掩盖问题)');
|
|
831
|
+
assert.match(src, /return function\s*\(\s*\)\s*\{\s*(?:\/\*[\s\S]{0,80}?\*\/)?\s*\}/,
|
|
832
|
+
'兜底路径必须返回空 disposer,cordis 才不会认为 fiber 失败');
|
|
833
|
+
|
|
834
|
+
// 运行时:apply 仍可正常调用(兜底不该影响正常路径)
|
|
835
|
+
let captured = null;
|
|
836
|
+
const fakeWindow = {
|
|
837
|
+
__ModuleLoader__: { load(def) { captured = def; } },
|
|
838
|
+
addEventListener() {},
|
|
839
|
+
removeEventListener() {},
|
|
840
|
+
};
|
|
841
|
+
// eslint-disable-next-line no-new-func
|
|
842
|
+
new Function('window', 'document', src)(fakeWindow, undefined);
|
|
843
|
+
const mod = captured.factory(requireWithReact(fakeReact()));
|
|
844
|
+
const dispose = mod.apply({ get() { return undefined; } });
|
|
845
|
+
assert.equal(typeof dispose, 'function', '正常路径仍应返回可调用的 disposer');
|
|
846
|
+
assert.doesNotThrow(() => dispose());
|
|
847
|
+
});
|