@modusensus/dsh-mneme 0.2.7 → 0.2.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.
@@ -0,0 +1,290 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { Config } from "../src/config.js";
4
+ import { createStore } from "../src/store.js";
5
+ import { createService } from "../src/service.js";
6
+ import { createDreamScheduler } from "../src/dream.js";
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // conflict freeze (冲突冻结) — 测试用例由 Kimi K2.7 设计,覆盖 config/store/
10
+ // service/dream 单测 + runDream 端到端(mock LLM 输出 conflict)。
11
+ // 核心约定:freeze 默认关闭(自动裁决行为完全不变);开启后 conflict 不自动
12
+ // 裁决、存入 conflict_pending 待人工确认,outcome 标 conflict-pending。
13
+ // ---------------------------------------------------------------------------
14
+
15
+ // ---------------------------------------------------------------- config
16
+
17
+ test("config: conflictFreezeEnabled 默认关闭", () => {
18
+ const cfg = Config({});
19
+ assert.equal(cfg.conflictFreezeEnabled, false, "freeze 默认不开启");
20
+ });
21
+
22
+ test("config: conflictFreezeEnabled 可显式开启", () => {
23
+ const cfg = Config({ conflictFreezeEnabled: true });
24
+ assert.equal(cfg.conflictFreezeEnabled, true);
25
+ });
26
+
27
+ test("config: conflictFreezeMaxPending 默认为 100 且为整数", () => {
28
+ const cfg = Config({});
29
+ assert.equal(cfg.conflictFreezeMaxPending, 100);
30
+ assert.ok(Number.isInteger(cfg.conflictFreezeMaxPending));
31
+ });
32
+
33
+ test("config: conflictFreezeMaxPending 可显式覆盖", () => {
34
+ const cfg = Config({ conflictFreezeMaxPending: 5 });
35
+ assert.equal(cfg.conflictFreezeMaxPending, 5);
36
+ });
37
+
38
+ test("config: freeze 配置项不影响其它字段", () => {
39
+ const base = Config({});
40
+ const tuned = Config({ conflictFreezeEnabled: true, conflictFreezeMaxPending: 7 });
41
+ assert.equal(tuned.rerankEnabled, base.rerankEnabled, "rerank 不受影响");
42
+ assert.equal(tuned.autoDream, base.autoDream, "autoDream 不受影响");
43
+ });
44
+
45
+ // ---------------------------------------------------------------- store
46
+
47
+ function openStore() {
48
+ return createStore(":memory:");
49
+ }
50
+
51
+ test("store: saveConflictPending 插入后 listConflictPending 读回", () => {
52
+ const store = openStore();
53
+ const pending = store.saveConflictPending({ run_id: "run-1", memory_a: "a", memory_b: "b", reason: "日期矛盾" });
54
+ assert.ok(pending.id, "有 id");
55
+ assert.equal(pending.run_id, "run-1");
56
+ assert.equal(pending.reason, "日期矛盾");
57
+ assert.ok(pending.created_at, "有 created_at");
58
+ assert.equal(pending.resolved_at, undefined, "未决行没有 resolved_at");
59
+
60
+ const list = store.listConflictPending();
61
+ assert.equal(list.length, 1);
62
+ assert.ok([list[0].memory_a, list[0].memory_b].includes("a"), "pair 包含双方");
63
+ assert.ok([list[0].memory_a, list[0].memory_b].includes("b"));
64
+ store.close();
65
+ });
66
+
67
+ test("store: 对序归一化去重 —— 同一对不管顺序只存一次", () => {
68
+ const store = openStore();
69
+ const p1 = store.saveConflictPending({ memory_a: "a", memory_b: "b", reason: "r1" });
70
+ const p2 = store.saveConflictPending({ memory_a: "b", memory_b: "a", reason: "r2" });
71
+ assert.equal(p2.id, p1.id, "反序重报返回同一条 pending");
72
+ assert.equal(p2.reason, "r1", "保留首次 reason");
73
+ assert.equal(store.countConflictPending(), 1, "绝不重复入队");
74
+ store.close();
75
+ });
76
+
77
+ test("store: 不同对不去重", () => {
78
+ const store = openStore();
79
+ store.saveConflictPending({ memory_a: "a", memory_b: "b", reason: "ab" });
80
+ store.saveConflictPending({ memory_a: "a", memory_b: "c", reason: "ac" });
81
+ assert.equal(store.countConflictPending(), 2);
82
+ store.close();
83
+ });
84
+
85
+ test("store: resolveConflictPending 标 resolved + winner,默认列表不再返回", () => {
86
+ const store = openStore();
87
+ const pending = store.saveConflictPending({ memory_a: "a", memory_b: "b", reason: "r" });
88
+ const resolved = store.resolveConflictPending(pending.id, { winner: "a" });
89
+ assert.ok(resolved.resolved_at, "resolved_at 已盖章");
90
+ assert.equal(resolved.resolved_winner, "a");
91
+ assert.equal(store.listConflictPending().length, 0, "已解决默认排除");
92
+ const all = store.listConflictPending({ includeResolved: true });
93
+ assert.equal(all.length, 1, "includeResolved 可见");
94
+ assert.equal(all[0].resolved_winner, "a");
95
+ store.close();
96
+ });
97
+
98
+ test("store: resolveConflictPending 未知 id 返回 undefined", () => {
99
+ const store = openStore();
100
+ assert.equal(store.resolveConflictPending("ghost"), undefined);
101
+ store.close();
102
+ });
103
+
104
+ test("store: countConflictPending 只统计未决行", () => {
105
+ const store = openStore();
106
+ store.saveConflictPending({ memory_a: "a", memory_b: "b", reason: "ab" });
107
+ const p2 = store.saveConflictPending({ memory_a: "b", memory_b: "c", reason: "bc" });
108
+ assert.equal(store.countConflictPending(), 2);
109
+ store.resolveConflictPending(p2.id, { winner: "b" });
110
+ assert.equal(store.countConflictPending(), 1, "已解决不再计入");
111
+ store.close();
112
+ });
113
+
114
+ test("store: 已解决的同一对后续可再次 pending", () => {
115
+ const store = openStore();
116
+ const p1 = store.saveConflictPending({ memory_a: "a", memory_b: "b", reason: "r" });
117
+ store.resolveConflictPending(p1.id, { winner: "a" });
118
+ // 去重只看未决行 —— 已解决后再现同一对应产生新 pending
119
+ const p2 = store.saveConflictPending({ memory_a: "b", memory_b: "a", reason: "again" });
120
+ assert.notEqual(p2.id, p1.id, "已解决行不参与去重");
121
+ assert.equal(p2.resolved_at, undefined);
122
+ assert.equal(store.countConflictPending(), 1);
123
+ store.close();
124
+ });
125
+
126
+ // ---------------------------------------------------------------- service passthrough
127
+
128
+ function openService() {
129
+ const store = createStore(":memory:");
130
+ const service = createService({ store, mirror: null, config: {} });
131
+ return { store, service };
132
+ }
133
+
134
+ test("service: 4 个 conflict freeze passthrough 委托到 store", () => {
135
+ const { store, service } = openService();
136
+ const saved = service.saveConflictPending({ run_id: "run-1", memory_a: "a", memory_b: "b", reason: "r" });
137
+ assert.equal(store.countConflictPending(), 1, "save 落到 store");
138
+ assert.equal(service.countConflictPending(), 1, "count 读回一致");
139
+ assert.equal(service.listConflictPending().length, 1, "list 读回一致");
140
+ const resolved = service.resolveConflictPending(saved.id, { winner: "a" });
141
+ assert.ok(resolved.resolved_at, "resolve 落到 store");
142
+ assert.equal(service.listConflictPending().length, 0, "已解决从默认列表消失");
143
+ store.close();
144
+ });
145
+
146
+ test("service: passthrough 透传 store 异常", () => {
147
+ const { store, service } = openService();
148
+ const original = store.countConflictPending;
149
+ store.countConflictPending = () => { throw new Error("db boom"); };
150
+ assert.throws(() => service.countConflictPending(), /db boom/);
151
+ store.countConflictPending = original;
152
+ store.close();
153
+ });
154
+
155
+ // ---------------------------------------------------------------- dream: runDream 端到端
156
+
157
+ function dreamSetup() {
158
+ const store = createStore(":memory:");
159
+ const service = createService({ store, mirror: null, config: {} });
160
+ return { store, service };
161
+ }
162
+
163
+ // mock LLM:第一次调用返回 consolidation decisions,第二次返回 summary。
164
+ function freezeCtx({ conflicts, includes = [], summaryText = "记忆库总览摘要" }) {
165
+ let calls = 0;
166
+ const warnings = [];
167
+ const ctx = {
168
+ warnings,
169
+ llm: {
170
+ stream: async function* () {
171
+ calls++;
172
+ const list = [...includes, ...conflicts];
173
+ yield { type: "text-delta", text: calls === 1 ? JSON.stringify(list) : summaryText };
174
+ yield { type: "finish", reason: { kind: "ok" } };
175
+ }
176
+ },
177
+ logger: { warn: (m) => warnings.push(m) }
178
+ };
179
+ return ctx;
180
+ }
181
+
182
+ const BASE_CONFIG = { dreamProvider: "deepseek", dreamModel: "deepseek-chat" };
183
+
184
+ test("dream: freeze=false(默认)conflict 仍自动裁决(回归)", async () => {
185
+ const { store, service } = dreamSetup();
186
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
187
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
188
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期更新" }] });
189
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
190
+ const result = await dream.runDream(ctx, service, BASE_CONFIG);
191
+ assert.equal(result.ok, true);
192
+ assert.equal(result.applied, 1, "conflict 被自动裁决");
193
+ assert.equal(result.frozen, 0, "无冻结");
194
+ assert.equal(store.getById(l.id).archived, true, "loser 被归档");
195
+ assert.ok(store.getById(w.id).content.includes("已否决旧信息"), "winner 附带来源批注");
196
+ assert.equal(store.listConflictPending().length, 0, "freeze 关闭不产生 pending");
197
+ store.close();
198
+ });
199
+
200
+ test("dream: freeze=true conflict 不自动裁决、存入 pending、outcome 标 conflict-pending", async () => {
201
+ const { store, service } = dreamSetup();
202
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
203
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
204
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期更新,候选取新" }] });
205
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
206
+ const result = await dream.runDream(ctx, service, { ...BASE_CONFIG, conflictFreezeEnabled: true });
207
+ assert.equal(result.ok, true);
208
+ assert.equal(result.applied, 0, "conflict 未被应用");
209
+ assert.equal(result.frozen, 1, "1 个 conflict 被冻结");
210
+ const pending = store.listConflictPending();
211
+ assert.equal(pending.length, 1, "pending 记录写入");
212
+ assert.equal(pending[0].reason, "日期更新,候选取新");
213
+ assert.equal(store.getById(l.id).archived, false, "loser 未归档");
214
+ assert.equal(store.getById(w.id).archived, false, "winner 未归档");
215
+ assert.ok(!store.getById(w.id).content.includes("已否决旧信息"), "无来源批注");
216
+ const run = store.listDreamRuns()[0];
217
+ assert.equal(run.outcome.byId[w.id], "conflict-pending", "audit outcome 标记双方 pending");
218
+ assert.equal(run.outcome.byId[l.id], "conflict-pending");
219
+ assert.equal(store.listReceipts().length, 0, "冻结 conflict 不写 per-record 收据");
220
+ store.close();
221
+ });
222
+
223
+ test("dream: freeze=true 非 conflict 决策照常执行,仅 conflict 冻结", async () => {
224
+ const { store, service } = dreamSetup();
225
+ const { memory: a } = service.saveWithDedupe({ type: "project", title: "插件", content: "旧", importance: 3 });
226
+ const { memory: b } = service.saveWithDedupe({ type: "project", title: "插件2", content: "新细节", importance: 4 });
227
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
228
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
229
+ const ctx = freezeCtx({
230
+ includes: [{ action: "merge", ids: [a.id, b.id], title: "插件总览", content: "合并内容", importance: 5, keepSource: b.id }],
231
+ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期更新" }]
232
+ });
233
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
234
+ const result = await dream.runDream(ctx, service, { ...BASE_CONFIG, conflictFreezeEnabled: true });
235
+ assert.equal(result.applied, 1, "merge 正常应用");
236
+ assert.equal(result.frozen, 1, "conflict 被冻结");
237
+ assert.equal(store.getById(b.id).title, "插件总览", "merge keeper 已更新");
238
+ assert.equal(store.getById(a.id).archived, true, "merge 源已归档");
239
+ assert.equal(store.getById(l.id).archived, false, "conflict loser 未被本次运行触碰");
240
+ assert.equal(store.listConflictPending().length, 1);
241
+ store.close();
242
+ });
243
+
244
+ test("dream: freeze=true 超过 conflictFreezeMaxPending 上限跳过(不抛错)", async () => {
245
+ const { store, service } = dreamSetup();
246
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
247
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
248
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "x" }] });
249
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
250
+ const result = await dream.runDream(ctx, service, {
251
+ ...BASE_CONFIG, conflictFreezeEnabled: true, conflictFreezeMaxPending: 0
252
+ });
253
+ assert.equal(result.frozen, 0, "容量 0 时无冻结");
254
+ assert.equal(store.listConflictPending().length, 0, "无 pending 写入");
255
+ assert.ok(ctx.warnings.some((m) => m.includes("freeze queue full")), "超限警告已记录");
256
+ store.close();
257
+ });
258
+
259
+ test("dream: freeze=true 存 pending 失败 fail-safe 不阻断 run", async () => {
260
+ const { store, service } = dreamSetup();
261
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
262
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
263
+ service.saveConflictPending = () => { throw new Error("pending store boom"); };
264
+ service.countConflictPending = () => { throw new Error("count boom"); };
265
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "x" }] });
266
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
267
+ const result = await dream.runDream(ctx, service, { ...BASE_CONFIG, conflictFreezeEnabled: true });
268
+ assert.equal(result.ok, true, "尽管 pending 存储失败,run 正常完成");
269
+ assert.equal(result.frozen, 0, "无冻结");
270
+ assert.ok(ctx.warnings.length >= 1, "freeze 失败已记录");
271
+ assert.equal(store.getById(l.id).archived, false, "记忆无副作用");
272
+ assert.equal(store.getById(w.id).content, "8月20日", "winner 未被改动");
273
+ store.close();
274
+ });
275
+
276
+ test("dream: freeze=true 同一对跨 run 去重 —— 只保留一条 pending", async () => {
277
+ const { store, service } = dreamSetup();
278
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
279
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
280
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
281
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期矛盾" }] });
282
+ const r1 = await dream.runDream(ctx, service, { ...BASE_CONFIG, conflictFreezeEnabled: true });
283
+ // mock LLM 计数器按 run 重置:每次 runDream 用独立的 ctx
284
+ const ctx2 = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期矛盾" }] });
285
+ const r2 = await dream.runDream(ctx2, service, { ...BASE_CONFIG, conflictFreezeEnabled: true });
286
+ assert.equal(r1.frozen, 1);
287
+ assert.equal(r2.frozen, 1, "每次 run 都检出并上报该对");
288
+ assert.equal(store.countConflictPending(), 1, "但队列只有一条 pending");
289
+ store.close();
290
+ });
@@ -545,3 +545,129 @@ test("applyDecisions merge is atomic: a throwing archive step rolls back the kee
545
545
  assert.ok(warnings.length >= 1, "failure logged");
546
546
  store.close();
547
547
  });
548
+
549
+ // --- conflict freeze: manual review instead of auto-adjudication ----------
550
+
551
+ function freezeCtx({ conflicts, includes = [], summaryText = "记忆库总览摘要" }) {
552
+ let calls = 0;
553
+ const warnings = [];
554
+ const ctx = {
555
+ warnings,
556
+ llm: {
557
+ stream: async function* () {
558
+ calls++;
559
+ const list = [...includes, ...conflicts];
560
+ yield { type: "text-delta", text: calls === 1 ? JSON.stringify(list) : summaryText };
561
+ yield { type: "finish", reason: { kind: "ok" } };
562
+ }
563
+ },
564
+ logger: { warn: (m) => warnings.push(m) }
565
+ };
566
+ return ctx;
567
+ }
568
+
569
+ test("runDream with conflictFreezeEnabled parks conflicts instead of adjudicating", async () => {
570
+ const { store, service } = dreamSetup();
571
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
572
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
573
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期更新,候选取新" }] });
574
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
575
+ const result = await dream.runDream(ctx, service, {
576
+ dreamProvider: "deepseek", dreamModel: "deepseek-chat", conflictFreezeEnabled: true
577
+ });
578
+ assert.equal(result.ok, true);
579
+ assert.equal(result.applied, 0, "no conflict applied");
580
+ assert.equal(result.frozen, 1, "one conflict frozen");
581
+ // pending row recorded for human review
582
+ const pending = store.listConflictPending();
583
+ assert.equal(pending.length, 1);
584
+ assert.equal(pending[0].reason, "日期更新,候选取新");
585
+ // neither side was auto-adjudicated
586
+ assert.equal(store.getById(l.id).archived, false, "loser NOT archived");
587
+ assert.equal(store.getById(w.id).archived, false, "winner NOT archived");
588
+ assert.ok(!store.getById(w.id).content.includes("已否决旧信息"), "no provenance note appended");
589
+ // audit outcome marks both sides pending
590
+ const run = store.listDreamRuns()[0];
591
+ assert.equal(run.outcome.byId[w.id], "conflict-pending");
592
+ assert.equal(run.outcome.byId[l.id], "conflict-pending");
593
+ assert.equal(run.status, "ok", "summary stored + freeze landed → ok");
594
+ assert.equal(store.listReceipts().length, 0, "no conflict receipt for a frozen (unapplied) conflict");
595
+ store.close();
596
+ });
597
+
598
+ test("runDream freeze keeps auto-adjudication when disabled (default)", async () => {
599
+ const { store, service } = dreamSetup();
600
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
601
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
602
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "更新" }] });
603
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
604
+ const result = await dream.runDream(ctx, service, { dreamProvider: "deepseek", dreamModel: "deepseek-chat" });
605
+ assert.equal(result.ok, true);
606
+ assert.equal(result.applied, 1, "conflict auto-adjudicated when freeze is off");
607
+ assert.equal(result.frozen, 0);
608
+ assert.equal(store.getById(l.id).archived, true, "loser archived");
609
+ assert.ok(store.getById(w.id).content.includes("已否决旧信息"), "provenance note appended");
610
+ assert.equal(store.listConflictPending().length, 0, "no pending rows in auto mode");
611
+ store.close();
612
+ });
613
+
614
+ test("runDream freeze applies non-conflict decisions while parking conflicts", async () => {
615
+ const { store, service } = dreamSetup();
616
+ const { memory: a } = service.saveWithDedupe({ type: "project", title: "插件", content: "旧", importance: 3 });
617
+ const { memory: b } = service.saveWithDedupe({ type: "project", title: "插件2", content: "新细节", importance: 4 });
618
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
619
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
620
+ const ctx = freezeCtx({
621
+ includes: [{ action: "merge", ids: [a.id, b.id], title: "插件总览", content: "合并内容", importance: 5, keepSource: b.id }],
622
+ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "日期更新" }]
623
+ });
624
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
625
+ const result = await dream.runDream(ctx, service, {
626
+ dreamProvider: "deepseek", dreamModel: "deepseek-chat", conflictFreezeEnabled: true
627
+ });
628
+ assert.equal(result.ok, true);
629
+ assert.equal(result.applied, 1, "merge applied normally");
630
+ assert.equal(result.frozen, 1, "conflict frozen");
631
+ assert.equal(store.getById(b.id).title, "插件总览", "merge keeper updated");
632
+ assert.equal(store.getById(a.id).archived, true, "merge source archived");
633
+ assert.equal(store.getById(l.id).archived, false, "conflict loser untouched by the merge run");
634
+ const pending = store.listConflictPending();
635
+ assert.equal(pending.length, 1);
636
+ assert.ok(pending[0].reason.includes("日期更新"));
637
+ store.close();
638
+ });
639
+
640
+ test("runDream freeze respects conflictFreezeMaxPending cap and skips overflow", async () => {
641
+ const { store, service } = dreamSetup();
642
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
643
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
644
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "x" }] });
645
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
646
+ const result = await dream.runDream(ctx, service, {
647
+ dreamProvider: "deepseek", dreamModel: "deepseek-chat",
648
+ conflictFreezeEnabled: true, conflictFreezeMaxPending: 0
649
+ });
650
+ assert.equal(result.frozen, 0, "nothing frozen at capacity");
651
+ assert.equal(store.listConflictPending().length, 0, "no pending rows");
652
+ assert.ok(ctx.warnings.some((m) => m.includes("freeze queue full")), "capacity warning logged");
653
+ store.close();
654
+ });
655
+
656
+ test("runDream freeze store failure never blocks the run (fail-safe)", async () => {
657
+ const { store, service } = dreamSetup();
658
+ const { memory: w } = service.saveWithDedupe({ type: "decision", title: "截止", content: "8月20日", importance: 4 });
659
+ const { memory: l } = service.saveWithDedupe({ type: "decision", title: "截止旧", content: "8月15日", importance: 4 });
660
+ service.saveConflictPending = () => { throw new Error("pending store boom"); };
661
+ service.countConflictPending = () => { throw new Error("count boom"); };
662
+ const ctx = freezeCtx({ conflicts: [{ action: "conflict", winner: w.id, loser: l.id, reason: "x" }] });
663
+ const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0 });
664
+ const result = await dream.runDream(ctx, service, {
665
+ dreamProvider: "deepseek", dreamModel: "deepseek-chat", conflictFreezeEnabled: true
666
+ });
667
+ assert.equal(result.ok, true, "run completes despite freeze store failure");
668
+ assert.equal(result.frozen, 0, "nothing frozen");
669
+ assert.ok(ctx.warnings.length >= 1, "freeze failure logged");
670
+ assert.equal(store.getById(l.id).archived, false, "no side effects on memories");
671
+ assert.equal(store.getById(w.id).content, "8月20日", "winner untouched");
672
+ store.close();
673
+ });