dsh-memu-memory 1.3.2 → 1.3.4
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/AGENTS.md +11 -3
- package/CHANGELOG.md +57 -3
- package/README.md +6 -11
- package/README.zh.md +6 -11
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/stats.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +21 -0
- package/docs/contributing.md +5 -2
- package/docs/memory-semantics.md +17 -0
- package/docs/troubleshooting.md +44 -0
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +125 -18
- package/lib/consolidation-snapshot.js +101 -5
- package/lib/consolidation-worker.js +1 -1
- package/lib/cycle.js +19 -1
- package/lib/index.js +83 -2
- package/lib/private.js +450 -165
- package/lib/rpc.js +14 -1
- package/lib/state.js +11 -1
- package/lib/turn-log.js +522 -0
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +53 -25
- package/lib/webui/standalone.css +4 -29
- package/lib/worker-pool.js +741 -0
- package/package.json +1 -1
- package/scripts/acceptance-local.mjs +6 -5
- package/scripts/build-graph.mjs +32 -4
- package/scripts/check-all.mjs +2 -0
- package/scripts/check-idle-compositing.mjs +61 -0
- package/scripts/make-readme-shots.mjs +59 -0
- package/scripts/prune-turnlogs.mjs +30 -0
- package/tests/browser.test.mjs +27 -0
- package/tests/client-render.test.mjs +171 -0
- package/tests/consolidation-snapshot.test.mjs +89 -1
- package/tests/graph-view.test.mjs +60 -3
- package/tests/loader.mjs +2 -0
- package/tests/salience-domain.test.mjs +139 -0
- package/tests/settings-coverage.test.mjs +97 -0
- package/tests/stubs/dsh-session-query.js +26 -0
- package/tests/turn-log.test.mjs +474 -0
- package/tests/webui.test.mjs +19 -0
- package/tests/worker-lifecycle.test.mjs +1046 -0
- package/docs/recall-benchmark.md +0 -238
|
@@ -102,6 +102,31 @@ test('pin/unpin/relayout/unpinAll keep the physics state coherent', () => {
|
|
|
102
102
|
layout.dispose()
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
+
test('relayout cools down and separates instead of shoving nodes forever', () => {
|
|
106
|
+
// 「缩到最小 → 重新布局 → 打架」的回归:硬分离阈值以前写成 24 / viewScale,
|
|
107
|
+
// k≈.06 时等于要求 400 世界像素间距,每帧互推、永不收敛。现在只看半径,
|
|
108
|
+
// 物理也拿不到相机(setScale 已删),缩放再小也不会改变力的量级。
|
|
109
|
+
assert.equal('setScale' in createForceLayout(), false, 'the physics must never be handed the camera scale')
|
|
110
|
+
const layout = createForceLayout()
|
|
111
|
+
layout.update(graph(60))
|
|
112
|
+
layout.relayout()
|
|
113
|
+
let previous = Infinity
|
|
114
|
+
for (let window = 0; window < 6; window++) {
|
|
115
|
+
const before = layout.nodes.map(node => [node.x, node.y])
|
|
116
|
+
for (let i = 0; i < 20; i++) layout.tick()
|
|
117
|
+
let maxMove = 0
|
|
118
|
+
layout.nodes.forEach((node, i) => { maxMove = Math.max(maxMove, Math.hypot(node.x - before[i][0], node.y - before[i][1])) })
|
|
119
|
+
assert.ok(maxMove < previous, `window ${window} must move less than the one before (${maxMove} >= ${previous})`)
|
|
120
|
+
previous = maxMove
|
|
121
|
+
}
|
|
122
|
+
assert.ok(previous < 4, `a cooled relayout must stop shoving, saw ${previous}px per window`)
|
|
123
|
+
for (let i = 0; i < layout.nodes.length; i++) for (let j = i + 1; j < layout.nodes.length; j++) {
|
|
124
|
+
const a = layout.nodes[i], b = layout.nodes[j]
|
|
125
|
+
assert.ok(Math.hypot(a.x - b.x, a.y - b.y) > a.radius + b.radius, 'relayout must not leave nodes overlapping')
|
|
126
|
+
}
|
|
127
|
+
layout.dispose()
|
|
128
|
+
})
|
|
129
|
+
|
|
105
130
|
test('configure maps all three force sliders and reheats without ever going non-finite', () => {
|
|
106
131
|
assert.equal(DEFAULT_OPTIONS.center, 0, 'center force is off by default')
|
|
107
132
|
assert.equal(DEFAULT_OPTIONS.clusterScope, true)
|
|
@@ -164,11 +189,11 @@ test('drag scope freezes other clusters and repels the dragged one from them', (
|
|
|
164
189
|
|
|
165
190
|
function harness(reducedMotion = true) {
|
|
166
191
|
const handlers = new Map(), windowHandlers = new Map(), frames = new Map(), arcs = [], focuses = [], texts = []
|
|
167
|
-
let id = 0
|
|
192
|
+
let id = 0, paints = 0
|
|
168
193
|
const ctx = new Proxy({
|
|
169
194
|
arc(x, y, radius) { arcs.push({ x, y, radius }) },
|
|
170
195
|
measureText(text) { return { width: text.length * 7 } },
|
|
171
|
-
clearRect() { arcs.length = 0; texts.length = 0 },
|
|
196
|
+
clearRect() { paints++; arcs.length = 0; texts.length = 0 },
|
|
172
197
|
fillText(text) { texts.push(String(text)) },
|
|
173
198
|
}, { get(target, key) { return key in target ? target[key] : () => {} } })
|
|
174
199
|
const win = {
|
|
@@ -198,7 +223,7 @@ function harness(reducedMotion = true) {
|
|
|
198
223
|
const emit = (type, x, y, extra = {}) => handlers.get(type)?.({
|
|
199
224
|
type, clientX: x, clientY: y, button: 0, pointerId: 1, pointerType: 'mouse', preventDefault() {}, ...extra,
|
|
200
225
|
})
|
|
201
|
-
return { view, flush, emit, arcs, texts, frames, focuses, handlers, windowHandlers }
|
|
226
|
+
return { view, flush, emit, arcs, texts, frames, focuses, handlers, windowHandlers, getPaints: () => paints }
|
|
202
227
|
}
|
|
203
228
|
|
|
204
229
|
test('the detailed layer actually paints labels and the label switch silences them', () => {
|
|
@@ -298,6 +323,38 @@ test('pinch does not trigger focus and reduced-motion/paused views do not run an
|
|
|
298
323
|
paused.view.dispose()
|
|
299
324
|
})
|
|
300
325
|
|
|
326
|
+
// GPU 守卫:动效开着也不能在冷却后空转重绘(曾经的实现是 30fps 永久整幅重绘)。
|
|
327
|
+
test('a cooled layout stops requesting frames even while motion is enabled', () => {
|
|
328
|
+
const h = harness(false)
|
|
329
|
+
h.view.update(graph(60))
|
|
330
|
+
for (let i = 0; i < 900 && h.frames.size; i++) h.flush()
|
|
331
|
+
assert.equal(h.frames.size, 0, 'a settled layout must not keep a rAF loop alive')
|
|
332
|
+
const painted = h.getPaints()
|
|
333
|
+
for (let i = 0; i < 200; i++) h.flush()
|
|
334
|
+
assert.equal(h.getPaints(), painted, 'idle time must not repaint the canvas')
|
|
335
|
+
h.view.zoom(1.2)
|
|
336
|
+
assert.equal(h.frames.size, 1, 'an interaction schedules exactly one repaint')
|
|
337
|
+
h.flush()
|
|
338
|
+
assert.equal(h.frames.size, 0, 'that repaint must not restart the loop')
|
|
339
|
+
h.view.dispose()
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
// 极小缩放下两颗节点可能只差 2-3px:纯最近邻会随鼠标 1px 抖动来回换人,
|
|
343
|
+
// 高亮反复切换就是用户看到的「节点互相打架闪现」。
|
|
344
|
+
test('hover keeps its target through 1px jitter at minimum zoom', () => {
|
|
345
|
+
const h = harness()
|
|
346
|
+
h.view.update(graph(2)); h.flush()
|
|
347
|
+
h.view.zoom(.05); h.flush()
|
|
348
|
+
const p = { ...h.arcs[0] }
|
|
349
|
+
const before = h.getPaints()
|
|
350
|
+
h.emit('pointermove', p.x, p.y); h.flush()
|
|
351
|
+
const first = h.getPaints()
|
|
352
|
+
assert.ok(first > before, 'hovering a node must repaint once')
|
|
353
|
+
h.emit('pointermove', p.x + 1, p.y + 1); h.flush()
|
|
354
|
+
assert.equal(h.getPaints(), first, 'a 1px nudge must not flip the hover target')
|
|
355
|
+
h.view.dispose()
|
|
356
|
+
})
|
|
357
|
+
|
|
301
358
|
test('Escape cancels a drag and clears the focus; toolbar actions do not throw', () => {
|
|
302
359
|
const h = harness()
|
|
303
360
|
h.view.update(graph(3)); h.flush()
|
package/tests/loader.mjs
CHANGED
|
@@ -3,6 +3,8 @@ const map = {
|
|
|
3
3
|
'@deepseek-ai/dsh-tools': new URL('dsh-tools.js', stubs),
|
|
4
4
|
'@deepseek-ai/dsh-llm': new URL('dsh-llm.js', stubs),
|
|
5
5
|
'@deepseek-ai/dsh-session': new URL('dsh-session.js', stubs),
|
|
6
|
+
// 外部追加恢复(consolidation-snapshot.js 的冷日志交叉核对)动态 import 的宿主 peer。
|
|
7
|
+
'@deepseek-ai/dsh-session-query': new URL('dsh-session-query.js', stubs),
|
|
6
8
|
// 整理 fork 自定义模型 route(lib/fork-model.js)动态 import 的宿主 peer:测试进程
|
|
7
9
|
// 装不上真包,桩只提供可构造的 PiAiAdapter 让生产接线走通成功路径。
|
|
8
10
|
'@deepseek-ai/dsh-llm-pi-ai': new URL('dsh-llm-pi-ai.js', stubs),
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
|
|
7
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-salience-'))
|
|
8
|
+
process.env.DSH_MEMU_HOME = home
|
|
9
|
+
|
|
10
|
+
const { salienceScore, mustCoverCandidates, candidateSeedEvents } = await import('../lib/private.js')
|
|
11
|
+
|
|
12
|
+
test.after(() => {
|
|
13
|
+
try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
// —— §6.1 回归:general/rp/默认参数下,中文文本得分与旧全域表逐条一致 ——
|
|
17
|
+
test('Chinese text scores identically to the legacy global table (general/rp/default)', () => {
|
|
18
|
+
const legacy = new Map([
|
|
19
|
+
['说好周末拿给阿兰换伞骨,记得带过去。', 5],
|
|
20
|
+
['今天天气不错。', 2],
|
|
21
|
+
['她讨厌被叫错名字,更喜欢被称作阿兰。', 4],
|
|
22
|
+
['我欠你一顿饭,月底之前还。', 6],
|
|
23
|
+
['明天下午三点到期的账单别忘了。', 6],
|
|
24
|
+
['阿兰说他下周要接手这份工作。', 4],
|
|
25
|
+
['你好。', 0],
|
|
26
|
+
])
|
|
27
|
+
for (const [text, expected] of legacy) {
|
|
28
|
+
assert.equal(salienceScore(text), expected, `default: ${text}`)
|
|
29
|
+
assert.equal(salienceScore(text, 'general'), expected, `general: ${text}`)
|
|
30
|
+
assert.equal(salienceScore(text, 'rp'), expected, `rp: ${text}`)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// —— §6.1 验收:同一段中英混排 coding 文本得分 ≥3 ——
|
|
35
|
+
test('mixed-script coding text clears the must-cover bar', () => {
|
|
36
|
+
const text = '修复了 login bug 并部署到 staging,shipped v2.3.1'
|
|
37
|
+
assert.ok(salienceScore(text, 'coding') >= 3)
|
|
38
|
+
assert.ok(salienceScore(text, 'mixed') >= 3)
|
|
39
|
+
assert.ok(salienceScore(text, 'mixed') >= salienceScore(text, 'coding'), 'mixed covers coding signals')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// —— §6.1 匹配规则:Latin 必须 \b 词边界,fix 不命中 fixture/prefix ——
|
|
43
|
+
test('Latin words respect word boundaries', () => {
|
|
44
|
+
assert.equal(salienceScore('fixture list and prefix tree', 'coding'), 0)
|
|
45
|
+
assert.equal(salienceScore('the environment and database', 'coding'), 0, 'env must not hit environment')
|
|
46
|
+
assert.equal(salienceScore('fix the typo', 'coding'), 2, 'bare fix still hits')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// —— §6.1 匹配规则:大小写不敏感(FIX/Fixed 要命中)——
|
|
50
|
+
test('Latin patterns are case-insensitive', () => {
|
|
51
|
+
assert.equal(salienceScore('FIX the fixture', 'coding'), 2, 'FIX hits, fixture does not')
|
|
52
|
+
assert.equal(salienceScore('FIXED and shipped v2.3.1', 'coding'), 4)
|
|
53
|
+
assert.equal(salienceScore('OPTIMIZE the build, renamed the config', 'coding'), 4)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// —— §6.1 验收:英文 coding 文本得分 ——
|
|
57
|
+
test('plain-English coding turns score above the must-cover bar', () => {
|
|
58
|
+
assert.ok(salienceScore('fixed the login bug and shipped v2.3.1', 'coding') >= 3)
|
|
59
|
+
assert.equal(salienceScore('Deployed the hotfix after a crash', 'coding'), 6)
|
|
60
|
+
assert.ok(salienceScore('breaking change in the API config, root cause was a migration', 'coding') >= 3)
|
|
61
|
+
assert.equal(salienceScore('we are still discussing the refactor plan', 'coding'), 1, 'weak-only signal scores 1')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// —— §6.1 rp 行:剧情词/英文同人词只属于 rp,general 不受影响 ——
|
|
65
|
+
test('rp extras score in rp and mixed but stay out of general', () => {
|
|
66
|
+
assert.equal(salienceScore('人设和世界观都更新了', 'rp'), 2)
|
|
67
|
+
assert.equal(salienceScore('人设和世界观都更新了', 'general'), 0)
|
|
68
|
+
assert.equal(salienceScore('her persona is canon, out of character moment', 'rp'), 3)
|
|
69
|
+
assert.equal(salienceScore('人设更新:她讨厌甜食,设定里不吃辣。', 'mixed'), 4, 'mixed keeps rp weak words')
|
|
70
|
+
assert.ok(salienceScore('修复了人设相关的 bug,明天发布', 'mixed') >= salienceScore('修复了人设相关的 bug,明天发布', 'coding'), 'mixed keeps coding strong words')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// —— §6.1 匹配规则:未知域回退 general ——
|
|
74
|
+
test('unknown domains fall back to general', () => {
|
|
75
|
+
const text = '生日快乐,记得还书。'
|
|
76
|
+
assert.equal(salienceScore(text, 'totally-new-domain'), salienceScore(text, 'general'))
|
|
77
|
+
assert.equal(salienceScore(text, 'totally-new-domain'), 6)
|
|
78
|
+
assert.notEqual(salienceScore(text, 'coding'), salienceScore(text, 'general'), 'domains separate real signals')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
// —— 回归:mustCoverCandidates 不传 domain 时与旧代码一致 ——
|
|
82
|
+
test('mustCoverCandidates without domain behaves like the legacy code', () => {
|
|
83
|
+
const events = [
|
|
84
|
+
{ seq: 0, type: 'turn/start', data: {} },
|
|
85
|
+
{ seq: 1, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '说好周末拿给阿兰换伞骨,记得带过去。' }] } },
|
|
86
|
+
{ seq: 2, type: 'turn/end', data: {} },
|
|
87
|
+
{ seq: 3, type: 'turn/start', data: {} },
|
|
88
|
+
{ seq: 4, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '今天天气不错。' }] } },
|
|
89
|
+
{ seq: 5, type: 'turn/end', data: {} },
|
|
90
|
+
]
|
|
91
|
+
const rows = mustCoverCandidates(events)
|
|
92
|
+
assert.equal(rows.length, 1, 'a turn below minScore is not a must-cover candidate')
|
|
93
|
+
assert.equal(rows[0].fromSeq, 0)
|
|
94
|
+
assert.equal(rows[0].throughSeq, 2)
|
|
95
|
+
assert.equal(rows[0].score, 5)
|
|
96
|
+
assert.equal(rows[0].tag, '人物/关系')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// —— §6.1 缺口修复:英文 coding 会话的必写候选不再塌方 ——
|
|
100
|
+
test('English coding turns produce must-cover candidates under the coding domain', () => {
|
|
101
|
+
const events = [
|
|
102
|
+
{ seq: 0, type: 'turn/start', data: {} },
|
|
103
|
+
{ seq: 1, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: 'fixed the login bug and shipped v2.3.1' }] } },
|
|
104
|
+
{ seq: 2, type: 'turn/end', data: {} },
|
|
105
|
+
{ seq: 3, type: 'turn/start', data: {} },
|
|
106
|
+
{ seq: 4, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: 'deploying to staging now, hotfix for the crash' }] } },
|
|
107
|
+
{ seq: 5, type: 'turn/end', data: {} },
|
|
108
|
+
]
|
|
109
|
+
const rows = mustCoverCandidates(events, { domain: 'coding' })
|
|
110
|
+
assert.equal(rows.length, 2)
|
|
111
|
+
assert.ok(rows.every((row) => row.score >= 3))
|
|
112
|
+
assert.deepEqual(rows.map((row) => row.fromSeq), [0, 3])
|
|
113
|
+
assert.deepEqual(mustCoverCandidates(events), [], 'without domain the legacy gap still applies')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// —— 签名透传:candidateSeedEvents 按域保留回合,默认行为不变 ——
|
|
117
|
+
test('candidateSeedEvents honours domain without changing defaults', () => {
|
|
118
|
+
const events = [
|
|
119
|
+
{ seq: 0, type: 'turn/start', data: {} },
|
|
120
|
+
{ seq: 1, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '今天天气不错。' }] } },
|
|
121
|
+
{ seq: 2, type: 'turn/end', data: {} },
|
|
122
|
+
{ seq: 3, type: 'turn/start', data: {} },
|
|
123
|
+
{ seq: 4, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: 'fixed the login bug and shipped v2.3.1' }] } },
|
|
124
|
+
{ seq: 5, type: 'turn/end', data: {} },
|
|
125
|
+
{ seq: 6, type: 'turn/start', data: {} },
|
|
126
|
+
{ seq: 7, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '嗯。' }] } },
|
|
127
|
+
{ seq: 8, type: 'turn/end', data: {} },
|
|
128
|
+
{ seq: 9, type: 'turn/start', data: {} },
|
|
129
|
+
{ seq: 10, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '先这样。' }] } },
|
|
130
|
+
{ seq: 11, type: 'turn/end', data: {} },
|
|
131
|
+
{ seq: 12, type: 'turn/start', data: {} },
|
|
132
|
+
{ seq: 13, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '回头再说。' }] } },
|
|
133
|
+
{ seq: 14, type: 'turn/end', data: {} },
|
|
134
|
+
]
|
|
135
|
+
const general = candidateSeedEvents(events)
|
|
136
|
+
assert.deepEqual(general.map((event) => event.seq), [0, 1, 2, 3, 4, 5], 'general keeps only the Chinese turn and its neighbour')
|
|
137
|
+
const coding = candidateSeedEvents(events, { domain: 'coding' })
|
|
138
|
+
assert.deepEqual(coding.map((event) => event.seq), [0, 1, 2, 3, 4, 5, 6, 7, 8], 'coding keeps the English turn and its neighbours')
|
|
139
|
+
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// 设置面全覆盖守卫(设计文档 §11 第 6 项):防止"新增设置键 + 多处白名单"漂移。
|
|
2
|
+
// 四条断言:
|
|
3
|
+
// 1. state.js 枚举表(:425 附近的 enums 对象)里的每个键必须出现在 setSettings
|
|
4
|
+
// 白名单里——枚举校验为可设置的键而存在,校验了却不可设置 = 死键。
|
|
5
|
+
// (注意:resetSettings 是产品 curated 名单——backend 类选择如 vectorSource
|
|
6
|
+
// 有意不参与"重置调参",故 reset 不做全量断言。)
|
|
7
|
+
// 2. resetSettings 名单的每个键必须在 DEFAULT_SETTINGS 里——reset 的实现是
|
|
8
|
+
// `patch[key] = DEFAULT_SETTINGS[key]`,键缺默认就会把 undefined 写进 state。
|
|
9
|
+
// 3. 每个枚举键的 DEFAULT_SETTINGS 默认值必须是该枚举的合法值——默认值越界等于
|
|
10
|
+
// 出厂即非法。
|
|
11
|
+
// 4. 三个新键(consolidationRunner / consolidationTurnLog / consolidationTurnLogTools)
|
|
12
|
+
// 必须在两张名单里(本设计的回归锚点)。
|
|
13
|
+
// 实现取源码文本解析而非 import(enums 表未导出,且解析即守卫源码形态本身——
|
|
14
|
+
// 与 check-doc-drift / binding-diagnostics 的行号契约同款思路)。
|
|
15
|
+
import test from 'node:test'
|
|
16
|
+
import assert from 'node:assert/strict'
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
import { fileURLToPath } from 'node:url'
|
|
20
|
+
import { DEFAULT_SETTINGS } from '../lib/state.js'
|
|
21
|
+
|
|
22
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
23
|
+
const stateSrc = fs.readFileSync(path.join(HERE, '..', 'lib', 'state.js'), 'utf8')
|
|
24
|
+
const rpcSrc = fs.readFileSync(path.join(HERE, '..', 'lib', 'rpc.js'), 'utf8')
|
|
25
|
+
|
|
26
|
+
function enumBlock(src) {
|
|
27
|
+
const marker = src.indexOf('const enums = {')
|
|
28
|
+
assert.notEqual(marker, -1, 'state.js 的 enums 表必须存在(校验函数被移动后请更新本测试的定位标记)')
|
|
29
|
+
let depth = 0, end = -1
|
|
30
|
+
for (let i = marker; i < src.length; i++) {
|
|
31
|
+
if (src[i] === '{') depth += 1
|
|
32
|
+
else if (src[i] === '}') { depth -= 1; if (depth === 0) { end = i; break } }
|
|
33
|
+
}
|
|
34
|
+
assert.notEqual(end, -1, 'enums 表右括号配平失败')
|
|
35
|
+
return src.slice(marker, end + 1)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function extractEnumKeys(src) {
|
|
39
|
+
const keys = [...enumBlock(src).matchAll(/(?:^|[,{\s])([A-Za-z_][A-Za-z0-9_]*):\s*\[/g)].map((m) => m[1])
|
|
40
|
+
assert.ok(keys.length >= 10, `enums 表解析出 ${keys.length} 个键,明显过少——解析器或表结构变了`)
|
|
41
|
+
return keys
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function extractWhitelist(src, caseName, terminator) {
|
|
45
|
+
const label = `case '${caseName}'`
|
|
46
|
+
const start = src.indexOf(label)
|
|
47
|
+
assert.notEqual(start, -1, `rpc.js 缺少 case '${caseName}'(结构变了请更新本测试定位)`)
|
|
48
|
+
const stop = src.indexOf(terminator, start)
|
|
49
|
+
// 从 case 标签之后起切 + 剥离行注释——注释里的引号词(如 "'fork'")与标签本身不是名单项
|
|
50
|
+
let block = src.slice(start + label.length, stop === -1 ? src.length : stop)
|
|
51
|
+
block = block.replace(/\/\/[^\n]*/g, '')
|
|
52
|
+
const items = [...block.matchAll(/'([A-Za-z_][A-Za-z0-9_]*)'/g)].map((m) => m[1]).filter((k) => k !== caseName)
|
|
53
|
+
assert.ok(items.length >= 20, `${caseName} 白名单解析出 ${items.length} 项,明显过少`)
|
|
54
|
+
return new Set(items)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const enumKeys = extractEnumKeys(stateSrc)
|
|
58
|
+
const resetList = extractWhitelist(rpcSrc, 'resetSettings', "case 'setSettings'")
|
|
59
|
+
const setList = extractWhitelist(rpcSrc, 'setSettings', 'const clean = {}')
|
|
60
|
+
|
|
61
|
+
// 有意不走通用 setSettings 的枚举键(专用 RPC 路径,自带校验):
|
|
62
|
+
// vectorSource → setEmbeddingSource(memu-config.js,切源有副作用需专门处理,
|
|
63
|
+
// 源值校验在专用函数内:local|api,'remote'→'api' 归一化)。
|
|
64
|
+
// 新增豁免必须在此登记 + 注明专用路径,否则视为漂移。
|
|
65
|
+
const SET_WHITELIST_EXCEPTIONS = new Set(['vectorSource'])
|
|
66
|
+
|
|
67
|
+
test('enums 表的每个键都在 setSettings 白名单里(可设置,否则是死键;豁免见 SET_WHITELIST_EXCEPTIONS)', () => {
|
|
68
|
+
const missing = enumKeys.filter((k) => !setList.has(k) && !SET_WHITELIST_EXCEPTIONS.has(k))
|
|
69
|
+
assert.deepEqual(missing, [], `以下枚举键缺出 setSettings 白名单(既不在名单也不在豁免表):${missing.join(', ')}`)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('resetSettings 名单的每个键都有 DEFAULT_SETTINGS 默认值(否则 reset 写入 undefined)', () => {
|
|
73
|
+
const missing = [...resetList].filter((k) => !(k in DEFAULT_SETTINGS))
|
|
74
|
+
assert.deepEqual(missing, [], `以下 reset 键缺默认值(重置会写 undefined):${missing.join(', ')}`)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('每个枚举键的默认值都是该枚举的合法值', () => {
|
|
78
|
+
const block = enumBlock(stateSrc)
|
|
79
|
+
const problems = []
|
|
80
|
+
for (const key of enumKeys) {
|
|
81
|
+
const m = block.match(new RegExp(`${key}:\\s*\\[([^\\]]+)\\]`))
|
|
82
|
+
if (!m) continue
|
|
83
|
+
const values = [...m[1].matchAll(/'([^']+)'/g)].map((v) => v[1])
|
|
84
|
+
const def = DEFAULT_SETTINGS[key]
|
|
85
|
+
if (def !== undefined && values.length && !values.includes(def)) {
|
|
86
|
+
problems.push(`${key}: 默认 '${def}' 不在枚举 [${values.join(', ')}] 里`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
assert.deepEqual(problems, [], `默认值越界:\n${problems.join('\n')}`)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('三个新键(runner/turnLog/turnLogTools)都在两张名单里(本设计回归锚点)', () => {
|
|
93
|
+
for (const key of ['consolidationRunner', 'consolidationTurnLog', 'consolidationTurnLogTools']) {
|
|
94
|
+
assert.ok(resetList.has(key), `${key} 缺出 resetSettings`)
|
|
95
|
+
assert.ok(setList.has(key), `${key} 缺出 setSettings`)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Host `@deepseek-ai/dsh-session-query` stand-in for the external-append recovery tests.
|
|
2
|
+
// The real package is a host peer and is not installed in this repo. Tests put the cold
|
|
3
|
+
// log on the fake persistence object (`persistence.__coldLogs[sessionId]`), so the
|
|
4
|
+
// production `reconcilePersistedAhead` path can be exercised without the host.
|
|
5
|
+
export async function readColdSessionLog(persistence, sessionId) {
|
|
6
|
+
const log = persistence?.__coldLogs?.[String(sessionId)]
|
|
7
|
+
if (!log) {
|
|
8
|
+
const error = new Error(`session "${sessionId}" not found`)
|
|
9
|
+
error.name = 'SessionPersistenceNotFoundError'
|
|
10
|
+
throw error
|
|
11
|
+
}
|
|
12
|
+
return log
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function assertSessionHeadersCompatible(a, b) {
|
|
16
|
+
if (
|
|
17
|
+
a.id !== b.id
|
|
18
|
+
|| a.createdAt !== b.createdAt
|
|
19
|
+
|| a.cwd !== b.cwd
|
|
20
|
+
|| a.parentSession !== b.parentSession
|
|
21
|
+
|| a.isSeeded !== b.isSeeded
|
|
22
|
+
|| (a.delegationDepth ?? 0) !== (b.delegationDepth ?? 0)
|
|
23
|
+
) {
|
|
24
|
+
throw new Error(`session source headers conflict for session "${a.id}"`)
|
|
25
|
+
}
|
|
26
|
+
}
|