Skip to content

Commit 52dd601

Browse files
committed
test(dream): 补两条边界回归——非法种子与收尾取证失败
Codecov 补丁覆盖 98.21%(src/dream.js 2 行未覆盖)指向的正是两个防御分支,补齐: - 非法种子(只有条数 / 只有字符数 / 负数 / 非整数 / 非对象)一律按「没有基线」处理: 半个基线若被当成「N 条 0 字符」,阈值会按 0 字符起算,比不认更糟; - 收尾取证失败(finish 阶段读库抛错)既不反噬巩固本身(审计行照写、run 仍 ok), 也不写猜出来的基线(落 NULL,下次重启退回零基线)。故障点在「总览出文本之后」才 武装——runDream 前面还要读两次库(候选集与总览输入),过早抛错验的就不是这条路径。 回归集 7 → 9 条,全量 npm test 1449 通过 / 0 失败;测试徽章 1448 → 1450。
1 parent c06165b commit 52dd601

4 files changed

Lines changed: 60 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-3E63DD?style=flat-square" alt="license"></a>
1111
<a href="https://github.com/slow-stack/mneme/actions"><img src="https://img.shields.io/github/actions/workflow/status/slow-stack/mneme/ci.yml?style=flat-square&label=CI" alt="CI"></a>
1212
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-22%2B-3E63DD?style=flat-square&logo=nodedotjs&logoColor=white" alt="node"></a>
13-
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-1448%20passed-3E63DD?style=flat-square" alt="tests"></a>
13+
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-1450%20passed-3E63DD?style=flat-square" alt="tests"></a>
1414
<a href="https://codecov.io/gh/slow-stack/mneme"><img src="https://img.shields.io/codecov/c/github/slow-stack/mneme/main?style=flat-square" alt="coverage"></a>
1515
<a href="https://github.com/awesome-dsh-plugin/awesome-dsh-plugin"><img src="https://awesome-dsh-plugin.com/badge.svg" alt="Awesome"></a>
1616
</p>
@@ -183,7 +183,7 @@ dsh web
183183

184184
```bash
185185
cd dsh-mneme && npm install
186-
npm test # 1448 个测试
186+
npm test # 1450 个测试
187187
npm run stress # 三轴线压测
188188
npm run sync # src → lib 同步
189189
```
@@ -366,7 +366,7 @@ The plugin ships a zero-dependency stdio MCP server (standalone npm package **`m
366366

367367
```bash
368368
cd dsh-mneme && npm install
369-
npm test # 1448 tests
369+
npm test # 1450 tests
370370
npm run stress # three-axis stress test
371371
npm run sync # src → lib sync
372372
```

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 🧹 工程
1010

11-
- **基线持久化回归集 7 条,全量测试 1441 → 1448**:无种子对照组与播种组同库同写入(一个仍触发、一个被拦下——锁的正是这个差异,否则播种被忽略时两条断言同真同假)、阈值照常累积(+10 条仍触发)、run 自报基线优先于现场计算(运行后再长 15 条仍不触发)、成功轮落库 / 失败轮不落、sleep 行不进 auto 基线、半个基线被拒、老库补列幂等、`index.js` 接线源码锁。**变异检验**:把播种改成忽略种子(`toBaseline(baselineSeed)` 恒为空)→ 2 条变红;把「成功轮落基线」分支短路 → 1 条变红。
11+
- **基线持久化回归集 9 条,全量测试 1441 → 1450**:无种子对照组与播种组同库同写入(一个仍触发、一个被拦下——锁的正是这个差异,否则播种被忽略时两条断言同真同假)、阈值照常累积(+10 条仍触发)、run 自报基线优先于现场计算(运行后再长 15 条仍不触发)、成功轮落库 / 失败轮不落、sleep 行不进 auto 基线、半个基线被拒、老库补列幂等、非法种子(半个 / 负数 / 非整数 / 非对象)一律按「没有基线」处理、收尾取证失败既不反噬审计行也不写假基线、`index.js` 接线源码锁。**变异检验**:把播种改成忽略种子(`toBaseline(baselineSeed)` 恒为空)→ 2 条变红;把「成功轮落基线」分支短路 → 1 条变红。
1212

1313
## [0.8.11] - 2026-09-30
1414

‎dsh-mneme/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![npm version](https://img.shields.io/npm/v/@modusensus/dsh-mneme?color=blue&label=npm)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
66
[![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
77
[![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
8-
[![tests](https://img.shields.io/badge/tests-1448%20passed-success)](https://github.com/slow-stack/mneme)
8+
[![tests](https://img.shields.io/badge/tests-1450%20passed-success)](https://github.com/slow-stack/mneme)
99
[![CI](https://img.shields.io/github/actions/workflow/status/slow-stack/mneme/ci.yml)](https://github.com/slow-stack/mneme/actions)
1010
[![node](https://img.shields.io/badge/node-22%2B-blue)](https://nodejs.org)
1111
[![npm downloads](https://img.shields.io/npm/d18m/@modusensus/dsh-mneme.svg?color=blue&label=downloads)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
@@ -584,7 +584,7 @@ src/
584584
├── api.js # HTTP 路由(Web 面板数据通道,含 /conflicts 冲突队列)
585585
└── index.js # 插件接线
586586
lib/ # src 的同步分发产物(npm run sync;发布前由 root prepack 的 check-sync.js 校验一致性;唯一手写例外 lib/client.js——Web 面板 bundle,sync 不覆盖)
587-
test/ # 1448 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
587+
test/ # 1450 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
588588
scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压测 · sync-lib.js 同步 · check-sync.js 发布闸门 · benchmark-recall.js / benchmark-embed.js / benchmark-rerank.js 基准 · sync-test-badge.mjs 测试徽章 · build-runtime-manifest.mjs 运行时清单
589589
```
590590
@@ -593,7 +593,7 @@ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压
593593
```bash
594594
cd dsh-mneme
595595
npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
596-
npm test # 运行 1448 个测试
596+
npm test # 运行 1450 个测试
597597
npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
598598
npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
599599
```

‎dsh-mneme/test/baseline-persist.test.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,59 @@ test("issue#89: legacy dream_runs gains the baseline columns on open (idempotent
181181
}
182182
});
183183

184+
test("issue#89: an unusable seed is treated as no baseline at all", () => {
185+
const store = createStore(":memory:");
186+
const service = createService({ store, mirror: null, config: {} });
187+
seedMemories(service, 12);
188+
const opts = { onRun: async () => ({ ok: false }), thresholdCount: 10, thresholdChars: 5000, delayMs: 0, logger: { warn: () => {} } };
189+
// 库里的持久化值可能是老库的 NULL、或手工改坏的库:半个基线(只有条数)若被当成
190+
// 「12 条 0 字符」,阈值会按 0 字符起算——比不认还糟。非法种子一律退回零基线。
191+
for (const bad of [{ count: 12 }, { chars: 2000 }, { count: -1, chars: 2000 }, { count: 1.5, chars: 10 }, "nope"]) {
192+
const sched = createDreamScheduler({ ...opts, baselineSeed: bad });
193+
assert.equal(sched.maybeSchedule(service), true, `unusable seed ${JSON.stringify(bad)} falls back to the zero baseline`);
194+
sched.dispose();
195+
}
196+
store.close();
197+
});
198+
199+
test("issue#89: a failing baseline read never breaks the run nor fakes a baseline", async () => {
200+
const store = createStore(":memory:");
201+
const service = createService({ store, mirror: null, config: {} });
202+
const a = service.saveWithDedupe({ type: "project", title: "旧1", content: "第一段内容" });
203+
// finish 阶段读库失败(关库 / IO 故障):必须不反噬巩固本身(审计行照写),也不
204+
// 写一个猜出来的基线(落 NULL → 下次重启退回零基线,而不是拿假基线抬高阈值)。
205+
// 故障点在「总览出文本之后」才武装:runDream 前面还要读两次库(候选集与总览输入),
206+
// 过早抛错会把整轮打成 failed,验的就不是收尾取证这条路了。
207+
const realAll = service.all.bind(service);
208+
let armed = false;
209+
let calls = 0;
210+
service.all = () => {
211+
if (armed) throw new Error("store closed");
212+
return realAll();
213+
};
214+
const ctx = {
215+
llm: {
216+
stream: async function* () {
217+
if (calls++ === 0) {
218+
yield { type: "text-delta", text: JSON.stringify([{ action: "keep", ids: [a.memory.id] }]) };
219+
} else {
220+
armed = true;
221+
yield { type: "text-delta", text: "记忆库总览摘要文本" };
222+
}
223+
yield { type: "finish", reason: { kind: "ok" } };
224+
}
225+
},
226+
logger: { warn: () => {} }
227+
};
228+
const dream = createDreamScheduler({ thresholdCount: 1, thresholdChars: 0, delayMs: 0, logger: { warn: () => {} } });
229+
const ok = await dream.runDream(ctx, service, { dreamProvider: "deepseek", dreamModel: "deepseek-chat" });
230+
assert.equal(ok.ok, true, "the run still completes when the baseline read fails");
231+
assert.equal(ok.baseline, undefined, "no made-up baseline is reported");
232+
assert.ok(store.listDreamRuns({ limit: 1 })[0], "the audit row is still written");
233+
assert.equal(store.listDreamRuns({ limit: 1 })[0].store_count, undefined, "the audit row carries no baseline");
234+
store.close();
235+
});
236+
184237
// --- CodeRabbit 在 #291 上的同类要求:index.js 的 seed 是单行无分支接线,仓库没有
185238
// 插件级挂载 harness(apply 需要完整宿主 ctx),改为源码级锁——删掉该注入行即红。
186239
// import 用 URL 相对本文件解析,不依赖测试进程 CWD。

0 commit comments

Comments
 (0)