@modusensus/dsh-mneme 0.8.14 → 0.8.16

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.
Files changed (279) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +660 -654
  3. package/assets/icon.svg +3 -3
  4. package/bin/cli.mjs +691 -689
  5. package/bin/dsh-mneme-mcp.mjs +510 -510
  6. package/bin/dsh-mneme-serve.mjs +151 -151
  7. package/cordis.patch.yml +21 -21
  8. package/docs/CONFIGURATION.md +275 -0
  9. package/docs/CONTINUITY.md +124 -0
  10. package/docs/DAEMON.md +46 -0
  11. package/docs/DISTILL.md +162 -0
  12. package/docs/ENTITIES.md +245 -0
  13. package/docs/LOCAL_MODEL.md +222 -0
  14. package/docs/SEMANTIC.md +256 -0
  15. package/docs/SLEEP.md +164 -0
  16. package/docs/STORAGE.md +98 -0
  17. package/lib/api-standalone.js +656 -673
  18. package/lib/api.js +1605 -1433
  19. package/lib/bootstrap.js +211 -211
  20. package/lib/client.js +6354 -5296
  21. package/lib/commands.js +95 -95
  22. package/lib/config.js +947 -843
  23. package/lib/content-hash.js +54 -54
  24. package/lib/continuity.js +220 -220
  25. package/lib/document-index.js +94 -94
  26. package/lib/document.js +303 -303
  27. package/lib/dream/clustering.js +118 -118
  28. package/lib/dream/decisions.js +694 -674
  29. package/lib/dream/narratives.js +44 -44
  30. package/lib/dream/sleep.js +819 -819
  31. package/lib/dream.js +1503 -1501
  32. package/lib/embedding.js +177 -177
  33. package/lib/entities/extractor.js +252 -252
  34. package/lib/graph/anchoring.js +179 -179
  35. package/lib/guide.js +74 -74
  36. package/lib/heat.js +144 -144
  37. package/lib/hot-memory.js +108 -46
  38. package/lib/index.js +552 -503
  39. package/lib/inject.js +428 -450
  40. package/lib/lang.js +248 -229
  41. package/lib/local-embedder.js +358 -358
  42. package/lib/maintenance.js +162 -142
  43. package/lib/mirror.js +330 -330
  44. package/lib/organize.js +450 -450
  45. package/lib/peak-hours.js +117 -117
  46. package/lib/placement.js +13 -0
  47. package/lib/pre-inject-gate.js +340 -0
  48. package/lib/quality-filter.js +126 -126
  49. package/lib/recall-stats.js +190 -175
  50. package/lib/reclaim-http.js +150 -0
  51. package/lib/reranker.js +269 -269
  52. package/lib/runtime/adopt.js +176 -176
  53. package/lib/runtime/closure.js +172 -172
  54. package/lib/runtime/download.js +247 -247
  55. package/lib/runtime/layout.js +265 -265
  56. package/lib/runtime/loader.js +252 -252
  57. package/lib/runtime/model-fetch.js +361 -361
  58. package/lib/runtime/provision.js +237 -237
  59. package/lib/runtime/tarball.js +130 -130
  60. package/lib/runtime/verify.js +223 -204
  61. package/lib/safe-slice.js +18 -0
  62. package/lib/scope.js +146 -146
  63. package/lib/search/adaptive.js +60 -60
  64. package/lib/search/bm25.js +96 -96
  65. package/lib/semantic.js +229 -229
  66. package/lib/sensitive-scan.js +209 -209
  67. package/lib/serve.js +215 -215
  68. package/lib/service.js +2688 -2605
  69. package/lib/settings.js +528 -511
  70. package/lib/store.js +3196 -3007
  71. package/lib/summarize.js +1039 -856
  72. package/lib/tools.js +743 -737
  73. package/lib/vector-index.js +110 -110
  74. package/lib/version-check.js +122 -122
  75. package/lib/write-admission.js +402 -402
  76. package/locale/en.json +6 -6
  77. package/locale/zh.json +6 -6
  78. package/package.json +118 -118
  79. package/runtime-manifest.json +526 -526
  80. package/scripts/benchmark-embed.js +201 -201
  81. package/scripts/benchmark-recall.js +249 -249
  82. package/scripts/benchmark-rerank.js +166 -166
  83. package/scripts/build-runtime-manifest.mjs +224 -224
  84. package/scripts/changelog-prep.mjs +36 -36
  85. package/scripts/check-sync.js +42 -42
  86. package/scripts/e2e-dsh.js +220 -220
  87. package/scripts/mneme-runtime.mjs +277 -277
  88. package/scripts/stress-dsh.js +255 -255
  89. package/scripts/sync-lib.js +47 -47
  90. package/scripts/sync-test-badge.mjs +69 -69
  91. package/scripts/test-count-sync.mjs +44 -44
  92. package/src/api-standalone.js +656 -673
  93. package/src/api.js +1605 -1433
  94. package/src/bootstrap.js +211 -211
  95. package/src/commands.js +95 -95
  96. package/src/config.js +947 -843
  97. package/src/content-hash.js +54 -54
  98. package/src/continuity.js +220 -220
  99. package/src/document-index.js +94 -94
  100. package/src/document.js +303 -303
  101. package/src/dream/clustering.js +118 -118
  102. package/src/dream/decisions.js +694 -674
  103. package/src/dream/narratives.js +44 -44
  104. package/src/dream/sleep.js +819 -819
  105. package/src/dream.js +1503 -1501
  106. package/src/embedding.js +177 -177
  107. package/src/entities/extractor.js +252 -252
  108. package/src/graph/anchoring.js +179 -179
  109. package/src/guide.js +74 -74
  110. package/src/heat.js +144 -144
  111. package/src/hot-memory.js +108 -46
  112. package/src/index.js +552 -503
  113. package/src/inject.js +428 -450
  114. package/src/lang.js +248 -229
  115. package/src/local-embedder.js +358 -358
  116. package/src/maintenance.js +162 -142
  117. package/src/mirror.js +330 -330
  118. package/src/organize.js +450 -450
  119. package/src/peak-hours.js +117 -117
  120. package/src/placement.js +13 -0
  121. package/src/pre-inject-gate.js +340 -0
  122. package/src/quality-filter.js +126 -126
  123. package/src/recall-stats.js +190 -175
  124. package/src/reclaim-http.js +150 -0
  125. package/src/reranker.js +269 -269
  126. package/src/runtime/adopt.js +176 -176
  127. package/src/runtime/closure.js +172 -172
  128. package/src/runtime/download.js +247 -247
  129. package/src/runtime/layout.js +265 -265
  130. package/src/runtime/loader.js +252 -252
  131. package/src/runtime/model-fetch.js +361 -361
  132. package/src/runtime/provision.js +237 -237
  133. package/src/runtime/tarball.js +130 -130
  134. package/src/runtime/verify.js +223 -204
  135. package/src/safe-slice.js +18 -0
  136. package/src/scope.js +146 -146
  137. package/src/search/adaptive.js +60 -60
  138. package/src/search/bm25.js +96 -96
  139. package/src/semantic.js +229 -229
  140. package/src/sensitive-scan.js +209 -209
  141. package/src/serve.js +215 -215
  142. package/src/service.js +2688 -2605
  143. package/src/settings.js +528 -511
  144. package/src/store.js +3196 -3007
  145. package/src/summarize.js +1039 -856
  146. package/src/tools.js +743 -737
  147. package/src/vector-index.js +110 -110
  148. package/src/version-check.js +122 -122
  149. package/src/write-admission.js +402 -402
  150. package/test/adaptive-inject-budget.test.js +85 -85
  151. package/test/api-routes-gaps.test.js +899 -218
  152. package/test/api.test.js +1725 -1690
  153. package/test/audit.test.js +448 -448
  154. package/test/baseline-persist.test.js +248 -248
  155. package/test/benchmark.test.js +94 -94
  156. package/test/bootstrap.test.js +220 -220
  157. package/test/changelog-prep.test.js +60 -60
  158. package/test/client.test.js +1582 -1169
  159. package/test/clustering.test.js +100 -100
  160. package/test/commands.test.js +106 -106
  161. package/test/config.test.js +66 -66
  162. package/test/conflict-freeze.test.js +300 -300
  163. package/test/content-hash.test.js +204 -204
  164. package/test/continuity.test.js +333 -333
  165. package/test/contrast.test.js +314 -0
  166. package/test/document-dir.test.js +233 -233
  167. package/test/document.test.js +671 -671
  168. package/test/dream-archive-guardrail.test.js +116 -116
  169. package/test/dream-candidate-hybrid.test.js +281 -281
  170. package/test/dream-coverage-degrade.test.js +86 -86
  171. package/test/dream-failure-backoff.test.js +173 -173
  172. package/test/dream-merge-guardrail.test.js +219 -0
  173. package/test/dream-peak-hours.test.js +194 -194
  174. package/test/dream.test.js +1385 -1383
  175. package/test/embedding-ready.test.js +196 -196
  176. package/test/entities.test.js +627 -547
  177. package/test/entity-recall.test.js +179 -179
  178. package/test/epistemic.test.js +325 -325
  179. package/test/fnew-0112.test.js +311 -311
  180. package/test/fnew-03.test.js +422 -422
  181. package/test/graph-anchoring.test.js +184 -184
  182. package/test/graph-api.test.js +175 -175
  183. package/test/graph-inject-budget.test.js +103 -103
  184. package/test/graph-passive-confirm.test.js +91 -91
  185. package/test/graph-weight-evolution.test.js +104 -104
  186. package/test/heat.test.js +175 -175
  187. package/test/helpers/dream-mock.js +82 -82
  188. package/test/helpers/peer-worker.mjs +25 -25
  189. package/test/helpers/runtime-source.js +60 -60
  190. package/test/helpers/tar-builder.js +80 -80
  191. package/test/helpers/write-admission-samples.js +308 -308
  192. package/test/hot-memory.test.js +211 -145
  193. package/test/inject-content-cap.test.js +91 -91
  194. package/test/inject-first-round-bm25.test.js +89 -89
  195. package/test/inject-heat.test.js +77 -77
  196. package/test/inject-parent-gate.test.js +106 -106
  197. package/test/inject-pools.test.js +194 -194
  198. package/test/inject-recall.test.js +144 -105
  199. package/test/inject-rotation.test.js +161 -161
  200. package/test/inject.test.js +443 -420
  201. package/test/lang.test.js +87 -87
  202. package/test/lastrunat-persist.test.js +101 -101
  203. package/test/lib-smoke.test.js +96 -96
  204. package/test/llm-audit.test.js +696 -598
  205. package/test/llm-message-source.test.js +207 -207
  206. package/test/local-embedder.test.js +292 -292
  207. package/test/maintenance.test.js +501 -391
  208. package/test/mcp-stdio.test.js +385 -385
  209. package/test/mirror-dirty.test.js +424 -424
  210. package/test/mirror-edit-digest.test.js +187 -187
  211. package/test/mirror-generation.test.js +499 -499
  212. package/test/mirror-types.test.js +208 -208
  213. package/test/mirror.test.js +249 -249
  214. package/test/narrative-bars.test.js +162 -162
  215. package/test/organize.test.js +418 -418
  216. package/test/peer-blockers.test.js +193 -193
  217. package/test/placement.test.js +36 -0
  218. package/test/policy-epoch.test.js +259 -259
  219. package/test/pre-inject-gate.test.js +444 -0
  220. package/test/quality-filter.test.js +186 -186
  221. package/test/reasoning-effort.test.js +752 -752
  222. package/test/recall-anti-update.test.js +82 -82
  223. package/test/recall-evals.test.js +253 -253
  224. package/test/recall-layer.test.js +326 -326
  225. package/test/recall-stats.test.js +274 -189
  226. package/test/receipt-chain.test.js +451 -451
  227. package/test/reclaim-http.test.js +209 -0
  228. package/test/reflection.test.js +226 -226
  229. package/test/reindex-backfill.test.js +62 -62
  230. package/test/reranker-single-logit.test.js +73 -73
  231. package/test/reranker.test.js +197 -197
  232. package/test/resident-status.test.js +83 -83
  233. package/test/runtime-adopt.test.js +206 -206
  234. package/test/runtime-cli.test.js +89 -89
  235. package/test/runtime-closure.test.js +193 -193
  236. package/test/runtime-download.test.js +302 -302
  237. package/test/runtime-layout.test.js +163 -163
  238. package/test/runtime-loader.test.js +255 -255
  239. package/test/runtime-manifest.test.js +159 -159
  240. package/test/runtime-model-fetch.test.js +348 -348
  241. package/test/runtime-provision.test.js +101 -101
  242. package/test/runtime-tarball.test.js +81 -81
  243. package/test/runtime-verify.test.js +319 -279
  244. package/test/scope-candidates.test.js +239 -239
  245. package/test/scope-explicit.test.js +452 -452
  246. package/test/scope-inject-soft.test.js +106 -106
  247. package/test/scope-retrieval.test.js +197 -197
  248. package/test/scope-storage.test.js +255 -255
  249. package/test/scope-strict.test.js +367 -367
  250. package/test/search-fusion.test.js +90 -90
  251. package/test/semantic.test.js +124 -124
  252. package/test/sensitive-scan.test.js +207 -207
  253. package/test/serve-bin.test.js +121 -121
  254. package/test/serve.test.js +196 -196
  255. package/test/service-search.test.js +174 -174
  256. package/test/service.test.js +410 -405
  257. package/test/settings.test.js +269 -261
  258. package/test/skip-invalid-restore.test.js +262 -262
  259. package/test/sleep-action-set.test.js +422 -422
  260. package/test/sleep-heat.test.js +126 -126
  261. package/test/sleep-scheduler-rearm.test.js +89 -89
  262. package/test/sleep.test.js +527 -527
  263. package/test/standalone-api.test.js +751 -751
  264. package/test/store-vector-cache.test.js +98 -98
  265. package/test/store.test.js +504 -396
  266. package/test/stress.test.js +209 -209
  267. package/test/summarize-occurred-at.test.js +127 -0
  268. package/test/summarize-reasoning-effort.test.js +189 -189
  269. package/test/summarize.test.js +1639 -1465
  270. package/test/supersede-state-tracking.test.js +394 -0
  271. package/test/test-count-sync.test.js +60 -60
  272. package/test/tools-dto-schema-matrix.test.js +325 -325
  273. package/test/tools-memory-get-schema.test.js +65 -65
  274. package/test/tools.test.js +428 -374
  275. package/test/updated-at-semantics.test.js +113 -113
  276. package/test/vector-index.test.js +221 -221
  277. package/test/version-check.test.js +152 -152
  278. package/test/webServer-optional.test.js +82 -82
  279. package/test/write-admission.test.js +668 -668
@@ -0,0 +1,219 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { createStore } from "../src/store.js";
4
+ import { createService } from "../src/service.js";
5
+ import { Config } from "../src/config.js";
6
+ import { createSettings } from "../src/settings.js";
7
+ import { createDreamScheduler, validateDecisions } from "../src/dream.js";
8
+ import { mockCtx } from "./helpers/dream-mock.js";
9
+
10
+ // 回归(#135 成本审计派生):merge 决策的单轮数量闸 dreamMaxMergePerRun。
11
+ //
12
+ // 为什么需要这道闸:merge 是巩固里唯一**回吐正文**的动作——每条 merge 都要求模型
13
+ // 重新写出合并后的 content(实测 2113 条 merge 平均 550 字符/条),而 keep /
14
+ // archive / conflict 都不带正文。单轮 merge 数因此是「输出里正文占比」唯一可控的
15
+ // 杠杆。此前 update(2) / create(5) / archive(8) 都有上限,唯独 merge 没有。
16
+ //
17
+ // 闸门形态与现有三道**完全一致**:全局信号,skipInvalid 也不豁免,超限整单拒绝。
18
+ // 这一点是本文件的锁点之一——若有人把 merge 闸改成「逐条跳过」,就与另外三道闸
19
+ // 的语义分叉了,而超限(模型一轮要合并几十条)恰恰是整体失控信号,必须整单拒绝。
20
+ //
21
+ // 默认值 40 的校准依据(只读探针:全库 246 轮 / 近 10 天 88 轮 dream_runs.decisions):
22
+ // 每轮 merge 数 全库 p50 7 / p90 15 / p99 28 / max 39
23
+ // 近 10 天 p50 9 / p90 20 / p99 39 / max 39
24
+ // 取 40 = 观测分布上沿(历史命中 0/246),与 archive 闸默认 8 恰为其 p90=max 同
25
+ // 一校准法:面向未来的尾险护栏,不是成本削减工具。刻意保守的理由是代价不对称:
26
+ // 整单拒绝 = run 记 failed = 调度器不刷新 baseline(src/dream.js:905-915)=
27
+ // 下一次写入用同一批输入重跑,一次误伤约等于该轮成本 ×2。
28
+ //
29
+ // 相关但**不是**本闸目标的实测事实(防后人误用本闸去省 token):dream_consolidate
30
+ // 的输出 token 里只有约 11.8% 是决策正文,其余是推理与 JSON 骨架,那部分由
31
+ // dreamReasoningEffort / 模型选择决定,调 merge 上限影响不到。
32
+
33
+ function snap(entries) {
34
+ return new Map(
35
+ entries.map(([id, type]) => [
36
+ id,
37
+ { id, type, title: `t-${id}`, content: `c-${id}`, importance: 3, archived: false, forgotten: false }
38
+ ])
39
+ );
40
+ }
41
+
42
+ /** 造 n 条互不相干的普通类型记忆,配对成 merge(每条 merge 需要 title+content)。 */
43
+ function mergeDecisions(n) {
44
+ const entries = Array.from({ length: n * 2 }, (_, i) => [`m${i}`, "project"]);
45
+ const decisions = [];
46
+ for (let i = 0; i < n; i += 1) {
47
+ decisions.push({
48
+ action: "merge",
49
+ ids: [`m${2 * i}`, `m${2 * i + 1}`],
50
+ title: `merged-${i}`,
51
+ content: `合并后的正文 ${i}`,
52
+ keepSource: `m${2 * i}`
53
+ });
54
+ }
55
+ return { entries, decisions };
56
+ }
57
+
58
+ // ---------------------------------------------------------- 数量闸(纯函数)
59
+
60
+ test("#135-cost: merge count above the cap rejects the whole batch (global gate)", () => {
61
+ const { entries, decisions } = mergeDecisions(41);
62
+ const s = snap(entries);
63
+ const { ok, errors } = validateDecisions(decisions, s, { skipInvalid: true });
64
+ assert.equal(ok, false, "41 merges > default cap 40 → reject even under skipInvalid");
65
+ assert.ok(
66
+ errors.some((e) => e.includes("too many merge decisions")),
67
+ `cap error present, got: ${errors.join("; ")}`
68
+ );
69
+ });
70
+
71
+ test("#135-cost: merge count at the cap passes (boundary is inclusive)", () => {
72
+ const { entries, decisions } = mergeDecisions(40);
73
+ const s = snap(entries);
74
+ const { ok, errors } = validateDecisions(decisions, s, { skipInvalid: true });
75
+ assert.equal(ok, true, `exactly 40 merges is allowed, got: ${errors.join("; ")}`);
76
+ });
77
+
78
+ test("#135-cost: merge cap is configurable and defaults to the observed upper bound (40)", () => {
79
+ const { entries, decisions } = mergeDecisions(41);
80
+ const s = snap(entries);
81
+ // 默认值本身是本次改动的契约:实测分布上沿 39 → 闸门取 40。
82
+ const raised = validateDecisions(structuredClone(decisions), s, { skipInvalid: true, maxMergePerRun: 60 });
83
+ assert.equal(raised.ok, true, `raised cap lets the batch through, got: ${raised.errors.join("; ")}`);
84
+ const lowered = validateDecisions(structuredClone(decisions), s, { skipInvalid: true, maxMergePerRun: 20 });
85
+ assert.equal(lowered.ok, false, "lowered cap catches the same batch");
86
+ });
87
+
88
+ test("#135-cost: merge cap does not fire on ordinary runs (calibrated to the tail, not the median)", () => {
89
+ // p90 = 15、p99 = 28:常态与「偏大但正常」的轮都不该被拦。若有人把默认值调到
90
+ // p90 附近(用覆盖换成本),这条用例会红——这是刻意的:默认值必须落在尾险区。
91
+ for (const n of [7, 15, 28, 39]) {
92
+ const { entries, decisions } = mergeDecisions(n);
93
+ const { ok, errors } = validateDecisions(decisions, snap(entries), { skipInvalid: true });
94
+ assert.equal(ok, true, `${n} merges (within observed distribution) must pass, got: ${errors.join("; ")}`);
95
+ }
96
+ });
97
+
98
+ test("#135-cost: merge cap is independent of the other three caps", () => {
99
+ // 31 条 merge + 1 条 update + 1 条 archive:三道老闸都在限内,只有 merge 超限时
100
+ // 才应该报 merge 的错——确认新闸不是被别的计数顺带触发的。
101
+ const { entries, decisions } = mergeDecisions(41);
102
+ const s = snap([...entries, ["u1", "project"], ["a1", "decision"]]);
103
+ const all = [
104
+ ...decisions,
105
+ { action: "update", ids: ["u1"], changes: { title: "改标题" } },
106
+ { action: "archive", ids: ["a1"], reason: "重复或过时" }
107
+ ];
108
+ const { ok, errors } = validateDecisions(all, s, { skipInvalid: true });
109
+ assert.equal(ok, false);
110
+ assert.ok(errors.some((e) => e.includes("too many merge decisions")));
111
+ assert.equal(errors.some((e) => e.includes("too many update decisions")), false, "update cap must not fire");
112
+ assert.equal(errors.some((e) => e.includes("too many archive decisions")), false, "archive cap must not fire");
113
+ });
114
+
115
+ // ---------------------------------------------------------- 配置面(schema + 白名单成对)
116
+
117
+ test("#135-cost: dreamMaxMergePerRun defaults to 40 and clamps to [1, 200]", () => {
118
+ assert.equal(Config({}).dreamMaxMergePerRun, 40, "default = observed upper bound of merge-per-run distribution");
119
+ assert.equal(Config({ dreamMaxMergePerRun: 1 }).dreamMaxMergePerRun, 1, "lower bound accepted");
120
+ assert.equal(Config({ dreamMaxMergePerRun: 200 }).dreamMaxMergePerRun, 200, "upper bound accepted");
121
+ assert.throws(() => Config({ dreamMaxMergePerRun: 0 }), "zero rejected");
122
+ assert.throws(() => Config({ dreamMaxMergePerRun: 201 }), "above max rejected");
123
+ });
124
+
125
+ test("#135-cost: dreamMaxMergePerRun is in the settings whitelist with the same bounds as the schema", () => {
126
+ // 新配置键必须 config.js schema 与 settings.js 白名单成对出现(AGENTS.md 自查清单 2)。
127
+ // 走公开的 setFeatureFlags 路径:validateFlag 是 settings.js 的模块内私有函数,
128
+ // 而「键不在白名单 → 静默丢弃、不报错」正是这条用例要防的失败模式。
129
+ const store = createStore(":memory:");
130
+ const settings = createSettings(store.db);
131
+ assert.deepEqual(settings.getFeatureFlags(), {}, "nothing stored initially");
132
+ assert.equal(settings.setFeatureFlags({ dreamMaxMergePerRun: 40 }).dreamMaxMergePerRun, 40, "whitelisted");
133
+ assert.equal(settings.getFeatureFlags().dreamMaxMergePerRun, 40, "persisted and re-read");
134
+ assert.throws(
135
+ () => settings.setFeatureFlags({ dreamMaxMergePerRun: 0 }),
136
+ /must be an integer in \[1, 200\]/
137
+ );
138
+ assert.throws(
139
+ () => settings.setFeatureFlags({ dreamMaxMergePerRun: 201 }),
140
+ /must be an integer in \[1, 200\]/
141
+ );
142
+ assert.throws(() => settings.setFeatureFlags({ dreamMaxMergePerRun: 1.5 }), /must be an integer/);
143
+ // 越界被拒后不得留下脏值。
144
+ assert.equal(settings.getFeatureFlags().dreamMaxMergePerRun, 40, "rejected write did not corrupt the stored value");
145
+ store.close();
146
+ });
147
+
148
+ // ---------------------------------------------------------- 端到端(runDream)
149
+
150
+ test("#135-cost: runDream rejects a runaway merge batch and leaves the memories untouched", async () => {
151
+ const store = createStore(":memory:");
152
+ const service = createService({ store, mirror: null, config: {} });
153
+ // 84 条普通记忆 → 42 对 merge,超过默认闸 40。
154
+ for (let i = 0; i < 84; i += 1) {
155
+ service.saveWithDedupe({ type: "project", title: `记忆 ${i}`, content: `正文 ${i}`, importance: 3 });
156
+ }
157
+ const ctx = mockCtx({
158
+ onConsolidation: (listText) => {
159
+ const ids = [...listText.matchAll(/id=([^\s|]+)/g)].map((m) => m[1]);
160
+ const decisions = [];
161
+ for (let i = 0; i + 1 < ids.length; i += 2) {
162
+ decisions.push({
163
+ action: "merge",
164
+ ids: [ids[i], ids[i + 1]],
165
+ title: `合并 ${i}`,
166
+ content: `合并后的正文 ${i}`,
167
+ keepSource: ids[i]
168
+ });
169
+ }
170
+ return JSON.stringify(decisions);
171
+ }
172
+ });
173
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
174
+ const result = await dream.runDream(ctx, service, { dreamProvider: "deepseek", dreamModel: "deepseek-chat" });
175
+ assert.equal(result.ok, false, "42 merges > cap 40 → run fails as a whole");
176
+ assert.match(result.error, /invalid decisions/);
177
+ // 整单拒绝 = 一条都没落:merge 不得半途生效(这正是「全局闸门」与「逐条跳过」的区别)。
178
+ // 注意 service.all() 含已归档行,所以必须数「未归档」的条数:merge 生效会把 source
179
+ // 置 archived,84 条里若有任何一条落了,未归档数就会掉下来。
180
+ assert.equal(service.all().filter((m) => !m.archived).length, 84, "no memory was merged away");
181
+ const audit = store.listDreamRuns().at(-1);
182
+ assert.equal(audit.status, "failed");
183
+ // decisions 是 store 层已 JSON.parse 的列,序列化后查错误串(_validationFailed 哨兵)。
184
+ assert.match(JSON.stringify(audit.decisions), /too many merge decisions/);
185
+ store.close();
186
+ });
187
+
188
+ test("#135-cost: runDream lands a merge batch below the cap", async () => {
189
+ const store = createStore(":memory:");
190
+ const service = createService({ store, mirror: null, config: {} });
191
+ for (let i = 0; i < 20; i += 1) {
192
+ service.saveWithDedupe({ type: "project", title: `记忆 ${i}`, content: `正文 ${i}`, importance: 3 });
193
+ }
194
+ const ctx = mockCtx({
195
+ onConsolidation: (listText) => {
196
+ const ids = [...listText.matchAll(/id=([^\s|]+)/g)].map((m) => m[1]);
197
+ const decisions = [];
198
+ for (let i = 0; i + 1 < ids.length; i += 2) {
199
+ decisions.push({
200
+ action: "merge",
201
+ ids: [ids[i], ids[i + 1]],
202
+ title: `合并 ${i}`,
203
+ content: `合并后的正文 ${i}`,
204
+ keepSource: ids[i]
205
+ });
206
+ }
207
+ return JSON.stringify(decisions);
208
+ }
209
+ });
210
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
211
+ const result = await dream.runDream(ctx, service, { dreamProvider: "deepseek", dreamModel: "deepseek-chat" });
212
+ assert.equal(result.status, "ok", `10 merges must pass, got: ${result.error ?? ""}`);
213
+ // 10 对 merge → 10 个 keeper 留下,其余 10 条被归档;再加上本轮落库的 summary
214
+ // 记忆(未归档),未归档数应为 11。这条断言同时证明「闸门放行」与「merge 真的
215
+ // 生效了」——只断言 notEqual(failed) 会被「什么都没做」蒙混过去。
216
+ assert.equal(service.all().filter((m) => !m.archived).length, 11, "10 keepers + 1 summary survived");
217
+ assert.equal(result.applied, 10, "all 10 merges committed");
218
+ store.close();
219
+ });
@@ -1,194 +1,194 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
- import { createDreamScheduler } from "../src/dream.js";
4
- import { createStore } from "../src/store.js";
5
- import { createService } from "../src/service.js";
6
-
7
- // Issue #239(第 4 项,错峰队列)镜像到巩固:dreamPeakHours / dreamPeakMaxDeferMinutes。
8
- //
9
- // 这些用例锁的是「排程语义」,不是实现细节——它们防的回归是:
10
- // ① 错峰闸门被写反/失效 → 高峰期又开始做梦(省钱能力静默消失);
11
- // ② 顺延路径把 skip 做成静默 → 用户看到「不再巩固了」却查不出原因;
12
- // ③ 顺延没有上限 → 长高峰(如全天)把巩固永久饿死;
13
- // ④ 非法时段串被当成「全天高峰」→ 一个笔误把功能整个停掉;
14
- // ⑤ dispose 漏清顺延定时器 → 进程关掉后仍触发一次巩固。
15
- //
16
- // 时钟与定时器全部注入(同 src/dream/sleep.js 的房型):排程不绑死真实时钟,
17
- // 「高峰顺延 → 非高峰补跑」才能被确定性覆盖,也不会在 CI 上留下真实等待。
18
- function dreamSetup() {
19
- const store = createStore(":memory:");
20
- const service = createService({ store, mirror: null, config: {} });
21
- return { store, service };
22
- }
23
-
24
- /** 本地墙钟时间:用本地时区构造,getHours() 在 ubuntu/windows CI 上都等于入参。 */
25
- function at(hour, minute = 0) {
26
- return new Date(2026, 5, 15, hour, minute, 0, 0).getTime();
27
- }
28
-
29
- function fakeClock(startMs) {
30
- let nowMs = startMs;
31
- const timers = [];
32
- let seq = 1;
33
- return {
34
- now: () => nowMs,
35
- setNow: (v) => { nowMs = v; },
36
- timers,
37
- setTimeoutFn: (fn, delay) => { const t = { id: seq++, at: nowMs + delay, fn }; timers.push(t); return t.id; },
38
- clearTimeoutFn: (id) => { const i = timers.findIndex((t) => t.id === id); if (i >= 0) timers.splice(i, 1); }
39
- };
40
- }
41
-
42
- /** 造出「超过阈值」的写入量(thresholdCount=2)。 */
43
- function fill(service, n = 2) {
44
- for (let i = 0; i < n; i++) service.saveWithDedupe({ type: "project", title: `m${i}`, content: "x".repeat(50) });
45
- }
46
-
47
- test("dreamPeakHours: 命中高峰不调模型,登记 skip 审计并顺延", () => {
48
- const { store, service } = dreamSetup();
49
- const clock = fakeClock(at(10, 0)); // 本地 10:00,落在 09:00-18:00 内
50
- let runs = 0;
51
- const audits = [];
52
- const dream = createDreamScheduler({
53
- onRun: async () => { runs++; return { ok: true }; },
54
- thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
55
- peakHours: "09:00-18:00",
56
- peakMaxDeferMinutes: 0, // 不设上限:顺延应落在真正的高峰结束时刻
57
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
58
- auditPeakSkip: (info) => audits.push(info)
59
- });
60
- fill(service);
61
- assert.equal(dream.maybeSchedule(service), false, "高峰内不排「马上跑」");
62
- assert.equal(runs, 0, "高峰内绝不调 LLM");
63
- assert.equal(audits.length, 1, "skip 必须留痕,否则「为什么不再巩固」不可观测");
64
- assert.equal(audits[0].count, 2, "审计带上窗口里积了多少(阈值继续累积,不是丢弃)");
65
- assert.equal(clock.timers.length, 1, "挂了一个顺延定时器");
66
- assert.equal(clock.timers[0].at, at(18, 0), "顺延到最近的高峰结束时刻");
67
- store.close();
68
- });
69
-
70
- test("dreamPeakHours: 顺延到点后补跑(非高峰真的会跑)", async () => {
71
- const { store, service } = dreamSetup();
72
- const clock = fakeClock(at(10, 0));
73
- let runs = 0;
74
- const dream = createDreamScheduler({
75
- onRun: async () => { runs++; return { ok: true }; },
76
- thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
77
- peakHours: "09:00-18:00",
78
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
79
- auditPeakSkip: () => {}
80
- });
81
- fill(service);
82
- dream.maybeSchedule(service);
83
- const deferred = clock.timers[0];
84
- clock.setNow(deferred.at); // 走到 18:00
85
- await deferred.fn();
86
- assert.equal(runs, 1, "出高峰后补跑一次");
87
- store.close();
88
- });
89
-
90
- test("dreamPeakHours: 重复触发不叠加顺延定时器", () => {
91
- const { store, service } = dreamSetup();
92
- const clock = fakeClock(at(10, 0));
93
- let audits = 0;
94
- const dream = createDreamScheduler({
95
- onRun: async () => ({ ok: true }),
96
- thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
97
- peakHours: "09:00-18:00",
98
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
99
- auditPeakSkip: () => { audits++; }
100
- });
101
- fill(service);
102
- dream.maybeSchedule(service);
103
- dream.maybeSchedule(service); // 顺延期间又来一次写入触发
104
- assert.equal(clock.timers.length, 1, "同一时刻只有一个顺延定时器");
105
- assert.equal(audits, 1, "不重复刷审计行");
106
- store.close();
107
- });
108
-
109
- test("dreamPeakMaxDeferMinutes: 上限截断后到点照跑,长高峰不饿死巩固", async () => {
110
- const { store, service } = dreamSetup();
111
- const clock = fakeClock(at(10, 0));
112
- let runs = 0;
113
- const dream = createDreamScheduler({
114
- onRun: async () => { runs++; return { ok: true }; },
115
- thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
116
- peakHours: "00:00-23:59", // 全天高峰:不设上限就会顺延到 23:59
117
- peakMaxDeferMinutes: 120,
118
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
119
- auditPeakSkip: () => {}
120
- });
121
- fill(service);
122
- dream.maybeSchedule(service);
123
- const t = clock.timers[0];
124
- assert.equal(t.at, at(12, 0), "被上限截断到 120 分钟后(而不是等到 23:59)");
125
- clock.setNow(t.at);
126
- await t.fn();
127
- assert.equal(runs, 1, "截断放行:仍在高峰也照跑,避免无限顺延");
128
- store.close();
129
- });
130
-
131
- test("dreamPeakHours: 非法时段串按「未配置」处理(宁可不省,也不能误停)", async () => {
132
- const { store, service } = dreamSetup();
133
- const clock = fakeClock(at(10, 0));
134
- let runs = 0;
135
- let audits = 0;
136
- const dream = createDreamScheduler({
137
- onRun: async () => { runs++; return { ok: true }; },
138
- thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
139
- peakHours: "10:00-99:00", // 非法:解析失败必须回落成「关闭」
140
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
141
- auditPeakSkip: () => { audits++; }
142
- });
143
- fill(service);
144
- assert.equal(dream.maybeSchedule(service), true, "非法串 = 未配置 → 走原有触发路径");
145
- assert.equal(audits, 0, "不写 skip 审计");
146
- const t = clock.timers[0];
147
- clock.setNow(t.at);
148
- await t.fn();
149
- assert.equal(runs, 1, "巩固照常进行");
150
- store.close();
151
- });
152
-
153
- test("dreamPeakHours: 非高峰时段不受影响(行为与现状一致)", async () => {
154
- const { store, service } = dreamSetup();
155
- const clock = fakeClock(at(20, 0)); // 本地 20:00,在 09:00-18:00 之外
156
- let runs = 0;
157
- const dream = createDreamScheduler({
158
- onRun: async () => { runs++; return { ok: true }; },
159
- thresholdCount: 2, thresholdChars: 5000, delayMs: 5,
160
- peakHours: "09:00-18:00",
161
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
162
- auditPeakSkip: () => { throw new Error("非高峰不该写 skip 审计"); }
163
- });
164
- fill(service);
165
- assert.equal(dream.maybeSchedule(service), true, "非高峰照常排程");
166
- const t = clock.timers[0];
167
- assert.equal(t.at, at(20, 0) + 5, "走的是 delayMs 的「马上跑」路径,不是顺延路径");
168
- clock.setNow(t.at);
169
- await t.fn();
170
- assert.equal(runs, 1);
171
- store.close();
172
- });
173
-
174
- test("dreamPeakHours: dispose 清掉顺延定时器,进程关闭后不再触发巩固", async () => {
175
- const { store, service } = dreamSetup();
176
- const clock = fakeClock(at(10, 0));
177
- let runs = 0;
178
- const dream = createDreamScheduler({
179
- onRun: async () => { runs++; return { ok: true }; },
180
- thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
181
- peakHours: "09:00-18:00",
182
- now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
183
- auditPeakSkip: () => {}
184
- });
185
- fill(service);
186
- dream.maybeSchedule(service);
187
- const t = clock.timers[0];
188
- await dream.dispose();
189
- assert.equal(clock.timers.length, 0, "顺延定时器已清");
190
- clock.setNow(t.at);
191
- await t.fn(); // 模拟「定时器已经进了事件队列,清不掉」的那一帧
192
- assert.equal(runs, 0, "disposed 守卫拦住补跑");
193
- store.close();
194
- });
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { createDreamScheduler } from "../src/dream.js";
4
+ import { createStore } from "../src/store.js";
5
+ import { createService } from "../src/service.js";
6
+
7
+ // Issue #239(第 4 项,错峰队列)镜像到巩固:dreamPeakHours / dreamPeakMaxDeferMinutes。
8
+ //
9
+ // 这些用例锁的是「排程语义」,不是实现细节——它们防的回归是:
10
+ // ① 错峰闸门被写反/失效 → 高峰期又开始做梦(省钱能力静默消失);
11
+ // ② 顺延路径把 skip 做成静默 → 用户看到「不再巩固了」却查不出原因;
12
+ // ③ 顺延没有上限 → 长高峰(如全天)把巩固永久饿死;
13
+ // ④ 非法时段串被当成「全天高峰」→ 一个笔误把功能整个停掉;
14
+ // ⑤ dispose 漏清顺延定时器 → 进程关掉后仍触发一次巩固。
15
+ //
16
+ // 时钟与定时器全部注入(同 src/dream/sleep.js 的房型):排程不绑死真实时钟,
17
+ // 「高峰顺延 → 非高峰补跑」才能被确定性覆盖,也不会在 CI 上留下真实等待。
18
+ function dreamSetup() {
19
+ const store = createStore(":memory:");
20
+ const service = createService({ store, mirror: null, config: {} });
21
+ return { store, service };
22
+ }
23
+
24
+ /** 本地墙钟时间:用本地时区构造,getHours() 在 ubuntu/windows CI 上都等于入参。 */
25
+ function at(hour, minute = 0) {
26
+ return new Date(2026, 5, 15, hour, minute, 0, 0).getTime();
27
+ }
28
+
29
+ function fakeClock(startMs) {
30
+ let nowMs = startMs;
31
+ const timers = [];
32
+ let seq = 1;
33
+ return {
34
+ now: () => nowMs,
35
+ setNow: (v) => { nowMs = v; },
36
+ timers,
37
+ setTimeoutFn: (fn, delay) => { const t = { id: seq++, at: nowMs + delay, fn }; timers.push(t); return t.id; },
38
+ clearTimeoutFn: (id) => { const i = timers.findIndex((t) => t.id === id); if (i >= 0) timers.splice(i, 1); }
39
+ };
40
+ }
41
+
42
+ /** 造出「超过阈值」的写入量(thresholdCount=2)。 */
43
+ function fill(service, n = 2) {
44
+ for (let i = 0; i < n; i++) service.saveWithDedupe({ type: "project", title: `m${i}`, content: "x".repeat(50) });
45
+ }
46
+
47
+ test("dreamPeakHours: 命中高峰不调模型,登记 skip 审计并顺延", () => {
48
+ const { store, service } = dreamSetup();
49
+ const clock = fakeClock(at(10, 0)); // 本地 10:00,落在 09:00-18:00 内
50
+ let runs = 0;
51
+ const audits = [];
52
+ const dream = createDreamScheduler({
53
+ onRun: async () => { runs++; return { ok: true }; },
54
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
55
+ peakHours: "09:00-18:00",
56
+ peakMaxDeferMinutes: 0, // 不设上限:顺延应落在真正的高峰结束时刻
57
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
58
+ auditPeakSkip: (info) => audits.push(info)
59
+ });
60
+ fill(service);
61
+ assert.equal(dream.maybeSchedule(service), false, "高峰内不排「马上跑」");
62
+ assert.equal(runs, 0, "高峰内绝不调 LLM");
63
+ assert.equal(audits.length, 1, "skip 必须留痕,否则「为什么不再巩固」不可观测");
64
+ assert.equal(audits[0].count, 2, "审计带上窗口里积了多少(阈值继续累积,不是丢弃)");
65
+ assert.equal(clock.timers.length, 1, "挂了一个顺延定时器");
66
+ assert.equal(clock.timers[0].at, at(18, 0), "顺延到最近的高峰结束时刻");
67
+ store.close();
68
+ });
69
+
70
+ test("dreamPeakHours: 顺延到点后补跑(非高峰真的会跑)", async () => {
71
+ const { store, service } = dreamSetup();
72
+ const clock = fakeClock(at(10, 0));
73
+ let runs = 0;
74
+ const dream = createDreamScheduler({
75
+ onRun: async () => { runs++; return { ok: true }; },
76
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
77
+ peakHours: "09:00-18:00",
78
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
79
+ auditPeakSkip: () => {}
80
+ });
81
+ fill(service);
82
+ dream.maybeSchedule(service);
83
+ const deferred = clock.timers[0];
84
+ clock.setNow(deferred.at); // 走到 18:00
85
+ await deferred.fn();
86
+ assert.equal(runs, 1, "出高峰后补跑一次");
87
+ store.close();
88
+ });
89
+
90
+ test("dreamPeakHours: 重复触发不叠加顺延定时器", () => {
91
+ const { store, service } = dreamSetup();
92
+ const clock = fakeClock(at(10, 0));
93
+ let audits = 0;
94
+ const dream = createDreamScheduler({
95
+ onRun: async () => ({ ok: true }),
96
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
97
+ peakHours: "09:00-18:00",
98
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
99
+ auditPeakSkip: () => { audits++; }
100
+ });
101
+ fill(service);
102
+ dream.maybeSchedule(service);
103
+ dream.maybeSchedule(service); // 顺延期间又来一次写入触发
104
+ assert.equal(clock.timers.length, 1, "同一时刻只有一个顺延定时器");
105
+ assert.equal(audits, 1, "不重复刷审计行");
106
+ store.close();
107
+ });
108
+
109
+ test("dreamPeakMaxDeferMinutes: 上限截断后到点照跑,长高峰不饿死巩固", async () => {
110
+ const { store, service } = dreamSetup();
111
+ const clock = fakeClock(at(10, 0));
112
+ let runs = 0;
113
+ const dream = createDreamScheduler({
114
+ onRun: async () => { runs++; return { ok: true }; },
115
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
116
+ peakHours: "00:00-23:59", // 全天高峰:不设上限就会顺延到 23:59
117
+ peakMaxDeferMinutes: 120,
118
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
119
+ auditPeakSkip: () => {}
120
+ });
121
+ fill(service);
122
+ dream.maybeSchedule(service);
123
+ const t = clock.timers[0];
124
+ assert.equal(t.at, at(12, 0), "被上限截断到 120 分钟后(而不是等到 23:59)");
125
+ clock.setNow(t.at);
126
+ await t.fn();
127
+ assert.equal(runs, 1, "截断放行:仍在高峰也照跑,避免无限顺延");
128
+ store.close();
129
+ });
130
+
131
+ test("dreamPeakHours: 非法时段串按「未配置」处理(宁可不省,也不能误停)", async () => {
132
+ const { store, service } = dreamSetup();
133
+ const clock = fakeClock(at(10, 0));
134
+ let runs = 0;
135
+ let audits = 0;
136
+ const dream = createDreamScheduler({
137
+ onRun: async () => { runs++; return { ok: true }; },
138
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
139
+ peakHours: "10:00-99:00", // 非法:解析失败必须回落成「关闭」
140
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
141
+ auditPeakSkip: () => { audits++; }
142
+ });
143
+ fill(service);
144
+ assert.equal(dream.maybeSchedule(service), true, "非法串 = 未配置 → 走原有触发路径");
145
+ assert.equal(audits, 0, "不写 skip 审计");
146
+ const t = clock.timers[0];
147
+ clock.setNow(t.at);
148
+ await t.fn();
149
+ assert.equal(runs, 1, "巩固照常进行");
150
+ store.close();
151
+ });
152
+
153
+ test("dreamPeakHours: 非高峰时段不受影响(行为与现状一致)", async () => {
154
+ const { store, service } = dreamSetup();
155
+ const clock = fakeClock(at(20, 0)); // 本地 20:00,在 09:00-18:00 之外
156
+ let runs = 0;
157
+ const dream = createDreamScheduler({
158
+ onRun: async () => { runs++; return { ok: true }; },
159
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 5,
160
+ peakHours: "09:00-18:00",
161
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
162
+ auditPeakSkip: () => { throw new Error("非高峰不该写 skip 审计"); }
163
+ });
164
+ fill(service);
165
+ assert.equal(dream.maybeSchedule(service), true, "非高峰照常排程");
166
+ const t = clock.timers[0];
167
+ assert.equal(t.at, at(20, 0) + 5, "走的是 delayMs 的「马上跑」路径,不是顺延路径");
168
+ clock.setNow(t.at);
169
+ await t.fn();
170
+ assert.equal(runs, 1);
171
+ store.close();
172
+ });
173
+
174
+ test("dreamPeakHours: dispose 清掉顺延定时器,进程关闭后不再触发巩固", async () => {
175
+ const { store, service } = dreamSetup();
176
+ const clock = fakeClock(at(10, 0));
177
+ let runs = 0;
178
+ const dream = createDreamScheduler({
179
+ onRun: async () => { runs++; return { ok: true }; },
180
+ thresholdCount: 2, thresholdChars: 5000, delayMs: 0,
181
+ peakHours: "09:00-18:00",
182
+ now: clock.now, setTimeoutFn: clock.setTimeoutFn, clearTimeoutFn: clock.clearTimeoutFn,
183
+ auditPeakSkip: () => {}
184
+ });
185
+ fill(service);
186
+ dream.maybeSchedule(service);
187
+ const t = clock.timers[0];
188
+ await dream.dispose();
189
+ assert.equal(clock.timers.length, 0, "顺延定时器已清");
190
+ clock.setNow(t.at);
191
+ await t.fn(); // 模拟「定时器已经进了事件队列,清不掉」的那一帧
192
+ assert.equal(runs, 0, "disposed 守卫拦住补跑");
193
+ store.close();
194
+ });