dsh-memu-memory 1.2.4 → 1.2.6
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 +3 -1
- package/README.md +9 -9
- package/README.zh.md +6 -6
- package/docs/binding-lifecycle.md +1 -1
- package/docs/env-and-commands.md +4 -1
- package/docs/host-adaptation.md +318 -0
- package/docs/host-api.md +29 -5
- package/docs/memory-semantics.md +45 -9
- package/docs/troubleshooting.md +27 -8
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +246 -56
- package/lib/consolidation-ledger.js +46 -1
- package/lib/consolidation-worker.js +1 -0
- package/lib/cycle.js +51 -17
- package/lib/embedding-catalog.js +14 -0
- package/lib/embedding-runtime.js +202 -25
- package/lib/global-graph.js +99 -1
- package/lib/index.js +8 -0
- package/lib/inject.js +71 -33
- package/lib/lexicon-scope.js +143 -0
- package/lib/lexicon.js +31 -4
- package/lib/local-vector-service.js +82 -6
- package/lib/memory.js +186 -12
- package/lib/memu.js +318 -3
- package/lib/private.js +310 -67
- package/lib/rpc.js +183 -23
- package/lib/salient-wake.js +38 -2
- package/lib/state.js +7 -5
- package/lib/tools.js +40 -17
- package/lib/vector-migration.js +13 -1
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +4 -1
- package/package.json +1 -1
- package/tests/absorb-review.test.mjs +2 -1
- package/tests/backend-compensation.test.mjs +1 -1
- package/tests/browser.test.mjs +58 -1
- package/tests/client-render.test.mjs +39 -0
- package/tests/consolidation-fork.test.mjs +81 -6
- package/tests/cross-library-recall.test.mjs +113 -0
- package/tests/curator-absorb.test.mjs +2 -1
- package/tests/curator-clusters.test.mjs +2 -1
- package/tests/curator-commit.test.mjs +2 -1
- package/tests/curator-link.test.mjs +2 -1
- package/tests/curator-review-mode.test.mjs +2 -1
- package/tests/cycle.test.mjs +2 -2
- package/tests/embedding-runtime.test.mjs +53 -1
- package/tests/global-graph.test.mjs +90 -0
- package/tests/lexicon-scope.test.mjs +256 -0
- package/tests/lexicon-ui.test.mjs +23 -0
- package/tests/managed-memory.test.mjs +1 -1
- package/tests/recall-dedup.test.mjs +1 -1
- package/tests/salient-wake.test.mjs +28 -1
- package/tests/settings-plumbing.test.mjs +1 -0
- package/tests/stubs/dsh-schedule.js +35 -0
- package/tests/ui-defaults.test.mjs +1 -1
- package/tests/vector-migration.test.mjs +20 -0
- package/tests/webui-auth.test.mjs +28 -0
package/tests/cycle.test.mjs
CHANGED
|
@@ -224,7 +224,7 @@ test('a conversation the host says is gone is marked once and never retried', as
|
|
|
224
224
|
assert.equal(binding.sleepRetryAt, null, 'nothing to retry later')
|
|
225
225
|
assert.ok(logs.some((m) => /no longer exists/.test(m)), 'explained once: ' + logs.join(' | '))
|
|
226
226
|
const quiet = await cycle.runSleepPass(fakeCtx({ live: ['cycle-ghost'] }))
|
|
227
|
-
assert.equal(quiet.
|
|
227
|
+
assert.equal(quiet.ran, 0, 'the next sweep does not consolidate a deleted session again')
|
|
228
228
|
})
|
|
229
229
|
|
|
230
230
|
test('a policy greeting skip does not claim a completed worker check', async () => {
|
|
@@ -238,7 +238,7 @@ test('a policy greeting skip does not claim a completed worker check', async ()
|
|
|
238
238
|
const out = await cycle.runSleepPass(ctx)
|
|
239
239
|
assert.equal(out.ran, 0, 'a policy skip is not a verified worker receipt')
|
|
240
240
|
assert.equal(ctx.created.length, 0, 'no fork for small talk')
|
|
241
|
-
assert.
|
|
241
|
+
assert.ok(state.getLastSleepAt('cycle-smalltalk'), 'a terminal skip is recorded so the same greetings are not re-read every sweep')
|
|
242
242
|
})
|
|
243
243
|
|
|
244
244
|
test('auto curation stays off unless an interval is set', async () => {
|
|
@@ -42,6 +42,10 @@ function fixtureEntry(overrides = {}) {
|
|
|
42
42
|
name: 'onnxruntime-node',
|
|
43
43
|
version: '9.9.9',
|
|
44
44
|
url: 'https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-9.9.9.tgz',
|
|
45
|
+
sources: [
|
|
46
|
+
{ id: 'npmjs', label: 'npmjs', url: 'https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-9.9.9.tgz' },
|
|
47
|
+
{ id: 'npmmirror', label: 'npmmirror', url: 'https://registry.npmmirror.com/onnxruntime-node/-/onnxruntime-node-9.9.9.tgz' },
|
|
48
|
+
],
|
|
45
49
|
bytes: TARBALL.length,
|
|
46
50
|
sha256: sha256(TARBALL),
|
|
47
51
|
extract: ['package.json', 'lib', 'bin/napi-v6/<platform>'],
|
|
@@ -280,7 +284,55 @@ test('a tampered runtime on disk is not reused as ready', async () => {
|
|
|
280
284
|
await assert.rejects(installer.ensure({ reuseOnly: true }), /not installed yet/)
|
|
281
285
|
const repair = await installer.ensure({ confirmed: true })
|
|
282
286
|
assert.equal(repair.status, 'installed')
|
|
283
|
-
|
|
287
|
+
// The verified artifact cache is reused for the repair: the tampered tree is
|
|
288
|
+
// rebuilt from the pinned bytes without another network download.
|
|
289
|
+
assert.equal(fetch.calls.length, 1)
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
test('an interrupted download resumes from the stable cache and can switch source', async () => {
|
|
293
|
+
const root = path.join(home, 'resume')
|
|
294
|
+
const firstCalls = []
|
|
295
|
+
const firstFetch = async (url, init = {}) => {
|
|
296
|
+
firstCalls.push({ url: String(url), range: init.headers?.Range || null })
|
|
297
|
+
const half = TARBALL.subarray(0, 8)
|
|
298
|
+
return {
|
|
299
|
+
ok: true,
|
|
300
|
+
status: 200,
|
|
301
|
+
headers: { get: name => (name === 'content-length' ? String(TARBALL.length) : null) },
|
|
302
|
+
body: (async function* () { yield half; throw new Error('network lost') })(),
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const first = makeInstaller(root, { fetch: { fetchImpl: firstFetch, calls: firstCalls } })
|
|
306
|
+
await assert.rejects(first.installer.ensure({ confirmed: true }), /network lost/i)
|
|
307
|
+
const cacheDir = path.join(root, '.cache')
|
|
308
|
+
const parts = fs.readdirSync(cacheDir).filter(name => name.endsWith('.part'))
|
|
309
|
+
assert.equal(parts.length, 1)
|
|
310
|
+
assert.equal(fs.statSync(path.join(cacheDir, parts[0])).size, 8)
|
|
311
|
+
|
|
312
|
+
const secondCalls = []
|
|
313
|
+
const secondFetch = async (url, init = {}) => {
|
|
314
|
+
const range = init.headers?.Range || null
|
|
315
|
+
const start = Number(/^bytes=(\d+)-$/.exec(range || '')?.[1] || 0)
|
|
316
|
+
secondCalls.push({ url: String(url), range })
|
|
317
|
+
return {
|
|
318
|
+
ok: true,
|
|
319
|
+
status: start > 0 ? 206 : 200,
|
|
320
|
+
headers: {
|
|
321
|
+
get: name => {
|
|
322
|
+
if (name === 'content-range') return `bytes ${start}-${TARBALL.length - 1}/${TARBALL.length}`
|
|
323
|
+
if (name === 'content-length') return String(TARBALL.length - start)
|
|
324
|
+
return null
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
body: (async function* () { yield TARBALL.subarray(start) })(),
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const second = makeInstaller(root, { fetch: { fetchImpl: secondFetch, calls: secondCalls } })
|
|
331
|
+
const installed = await second.installer.ensure({ confirmed: true, source: 'npmmirror' })
|
|
332
|
+
assert.equal(installed.status, 'installed')
|
|
333
|
+
assert.equal(secondCalls.length, 1)
|
|
334
|
+
assert.equal(secondCalls[0].range, 'bytes=8-')
|
|
335
|
+
assert.match(secondCalls[0].url, /npmmirror\.com/)
|
|
284
336
|
})
|
|
285
337
|
|
|
286
338
|
test('the real tarball extractor drops everything the allow-list did not pin', async () => {
|
|
@@ -0,0 +1,90 @@
|
|
|
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-global-graph-'))
|
|
8
|
+
process.env.DSH_MEMU_HOME = home
|
|
9
|
+
|
|
10
|
+
const state = await import('../lib/state.js')
|
|
11
|
+
const { getGlobalGraph } = await import('../lib/global-graph.js')
|
|
12
|
+
const { dispatch } = await import('../lib/rpc.js')
|
|
13
|
+
|
|
14
|
+
test.after(() => {
|
|
15
|
+
try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
function seed() {
|
|
19
|
+
state.saveGlobalIndex({
|
|
20
|
+
entries: {
|
|
21
|
+
g1: {
|
|
22
|
+
title: '部署窗口', domain: 'coding', status: 'active', confidence: 0.9,
|
|
23
|
+
links: [{ id: 'lnk_1', opId: 'op1', to: 'g2', kind: 'related', note: '同一发布约定', confidence: 0.8 }],
|
|
24
|
+
},
|
|
25
|
+
g2: {
|
|
26
|
+
title: '回滚规则', domain: 'coding', status: 'active', confidence: 0.7,
|
|
27
|
+
links: [{ id: 'lnk_1', opId: 'op1', to: 'g1', kind: 'related', note: '同一发布约定', confidence: 0.8 }],
|
|
28
|
+
},
|
|
29
|
+
g3: {
|
|
30
|
+
title: '已压制', domain: 'coding', status: 'suppressed', confidence: 0.5,
|
|
31
|
+
links: [],
|
|
32
|
+
},
|
|
33
|
+
g4: {
|
|
34
|
+
title: '指向已归档', domain: 'coding', status: 'active', confidence: 0.6,
|
|
35
|
+
links: [{ id: 'lnk_2', opId: 'op2', to: 'g5', kind: 'refines', note: '更细的规则', confidence: 0.7 }],
|
|
36
|
+
},
|
|
37
|
+
g5: { title: '归档条目', domain: 'coding', status: 'archived', confidence: 0.5, links: [] },
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
test('global graph exposes global entries and their links without private entities', () => {
|
|
43
|
+
seed()
|
|
44
|
+
const graph = getGlobalGraph({ limit: 200 })
|
|
45
|
+
assert.deepEqual(graph.nodes.map((node) => node.id).sort(), ['g1', 'g2', 'g4', 'g5'])
|
|
46
|
+
assert.ok(!graph.nodes.some((node) => node.id === 'g3'), 'suppressed entries are hidden')
|
|
47
|
+
assert.equal(graph.scope, 'global')
|
|
48
|
+
for (const node of graph.nodes) {
|
|
49
|
+
assert.equal(node.kind, 'global')
|
|
50
|
+
assert.equal(node.missing, false)
|
|
51
|
+
}
|
|
52
|
+
assert.deepEqual(
|
|
53
|
+
graph.edges.map((edge) => [edge.from, edge.to, edge.kind]).sort(),
|
|
54
|
+
[['g1', 'g2', 'related'], ['g4', 'g5', 'refines']],
|
|
55
|
+
)
|
|
56
|
+
assert.equal(graph.nodes.find((node) => node.id === 'g1').degree, 1)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('focus and depth bound the global graph, and a dangling target stays as a placeholder', () => {
|
|
60
|
+
seed()
|
|
61
|
+
const focused = getGlobalGraph({ focusId: 'g4', depth: 0 })
|
|
62
|
+
assert.deepEqual(focused.nodes.map((node) => node.id), ['g4'])
|
|
63
|
+
assert.deepEqual(focused.edges, [])
|
|
64
|
+
|
|
65
|
+
state.saveGlobalIndex({
|
|
66
|
+
entries: {
|
|
67
|
+
only: {
|
|
68
|
+
title: '只剩来源', domain: 'coding', status: 'active',
|
|
69
|
+
links: [{ id: 'lnk_gone', to: 'gone', kind: 'supports', note: '目标已删', confidence: 0.6 }],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
const dangling = getGlobalGraph({})
|
|
74
|
+
assert.deepEqual(dangling.nodes.map((node) => [node.id, node.missing]).sort(), [['gone', true], ['only', false]])
|
|
75
|
+
assert.equal(dangling.nodes.find((node) => node.id === 'gone').title, '[deleted]')
|
|
76
|
+
assert.equal(dangling.edges.length, 1)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('getGraph routes scope=global through the RPC without adding a new method', async () => {
|
|
80
|
+
seed()
|
|
81
|
+
const graph = await dispatch({}, 'getGraph', { scope: 'global', depth: 1, limit: 200 })
|
|
82
|
+
assert.equal(graph.scope, 'global')
|
|
83
|
+
assert.ok(graph.nodes.some((node) => node.id === 'g1'))
|
|
84
|
+
assert.ok(graph.edges.length > 0)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('an unknown global focus is rejected instead of returning an empty graph', () => {
|
|
88
|
+
seed()
|
|
89
|
+
assert.throws(() => getGlobalGraph({ focusId: 'nonexistent' }), /unknown or inaccessible global graph focus/)
|
|
90
|
+
})
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// 词典读取作用域(§8.15 的词典半边):全局词典 + 同域跨库。
|
|
2
|
+
//
|
|
3
|
+
// 记忆侧的 crossLibraryRecall 管 privateRecall/privateList;本文件管词典的另一条链——
|
|
4
|
+
// 锚点摘要(buildLexiconAnchor)、B 通道匹配(injectLexiconTurn/commitLexiconTurn)、
|
|
5
|
+
// 模型检索(memu_lexicon_search)与词典 RPC 的全局存储。断言的是「看得见哪些词条」
|
|
6
|
+
// 与「计数落在哪本词典」,不锁内部实现。
|
|
7
|
+
//
|
|
8
|
+
// 末尾两条是「读失败」用例:它们会把文件写成坏 JSON,词典核心在读失败后拒绝写入,
|
|
9
|
+
// 所以必须留在最后,且只碰自己新建的库。
|
|
10
|
+
import test from 'node:test'
|
|
11
|
+
import assert from 'node:assert/strict'
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
import os from 'node:os'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
|
|
16
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-lexicon-scope-'))
|
|
17
|
+
process.env.DSH_MEMU_HOME = home
|
|
18
|
+
|
|
19
|
+
const state = await import('../lib/state.js')
|
|
20
|
+
const lexicon = await import('../lib/lexicon.js')
|
|
21
|
+
const scope = await import('../lib/lexicon-scope.js')
|
|
22
|
+
const inject = await import('../lib/inject.js')
|
|
23
|
+
const { registerTools } = await import('../lib/tools.js')
|
|
24
|
+
const { dispatch } = await import('../lib/rpc.js')
|
|
25
|
+
const backup = await import('../lib/backup.js')
|
|
26
|
+
const { dataDir } = await import('../lib/paths.js')
|
|
27
|
+
|
|
28
|
+
test.after(() => {
|
|
29
|
+
state.flushState()
|
|
30
|
+
try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const GLOBAL_ID = lexicon.GLOBAL_LEXICON_ID
|
|
34
|
+
const lexiconFile = (libraryId) => path.join(dataDir(), 'lexicon', `${libraryId}.json`)
|
|
35
|
+
const readStore = (libraryId) => JSON.parse(fs.readFileSync(lexiconFile(libraryId), 'utf8'))
|
|
36
|
+
const entryOf = (libraryId, term) => Object.entries(readStore(libraryId).terms || {})
|
|
37
|
+
.find(([, e]) => e.term === term)?.[1] || null
|
|
38
|
+
const countsOf = (libraryId, term) => entryOf(libraryId, term)?.hitCounts || { candidate: 0, injection: 0, query: 0 }
|
|
39
|
+
|
|
40
|
+
const dir = (name) => path.join(home, name)
|
|
41
|
+
function bind(sessionId, folder, libraryId, domain) {
|
|
42
|
+
state.ensureSession(sessionId, { cwd: folder, libraryId })
|
|
43
|
+
state.setSessionBinding(sessionId, { domainOverride: domain })
|
|
44
|
+
return state.getSessionBinding(sessionId)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addTerm(libraryId, term, extra = {}) {
|
|
48
|
+
return lexicon.upsertLexiconTerm({
|
|
49
|
+
libraryId, term, kind: 'term', meaning: `${term} 的释义`, context: {}, source: 'user', ...extra,
|
|
50
|
+
}).term
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toolByName(name) {
|
|
54
|
+
const tools = []
|
|
55
|
+
registerTools({ tools: { register(tool) { tools.push(tool) } }, logger: { warn() {} } })
|
|
56
|
+
return tools.find((tool) => tool.name === name)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 四本库:当前库、同域其它库、异域库、关掉私有记忆的文件夹;外加全局词典。
|
|
60
|
+
function world() {
|
|
61
|
+
const current = state.ensureLibraryForCwd(dir('lex-current'))
|
|
62
|
+
const other = state.ensureLibraryForCwd(dir('lex-other'))
|
|
63
|
+
const rp = state.ensureLibraryForCwd(dir('lex-rp'))
|
|
64
|
+
const off = state.ensureLibraryForCwd(dir('lex-off'))
|
|
65
|
+
bind('lex-current', dir('lex-current'), current.id, 'coding')
|
|
66
|
+
bind('lex-other', dir('lex-other'), other.id, 'coding')
|
|
67
|
+
bind('lex-rp', dir('lex-rp'), rp.id, 'rp')
|
|
68
|
+
bind('lex-off', dir('lex-off'), off.id, 'coding')
|
|
69
|
+
state.setWorkspacePolicy(dir('lex-off'), { useLibrary: false })
|
|
70
|
+
addTerm(current.id, '当前词')
|
|
71
|
+
addTerm(other.id, '同域词')
|
|
72
|
+
addTerm(rp.id, '异域词')
|
|
73
|
+
addTerm(off.id, '关库词')
|
|
74
|
+
addTerm(GLOBAL_ID, '全局词')
|
|
75
|
+
return { current, other, rp, off }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const bindingOf = (sessionId) => state.getSessionBinding(sessionId)
|
|
79
|
+
|
|
80
|
+
test('lexiconSources: 默认是当前库 + 全局词典,开关打开才并入同域其它库', () => {
|
|
81
|
+
const libs = world()
|
|
82
|
+
const binding = bindingOf('lex-current')
|
|
83
|
+
state.updateSettings({ crossLibraryRecall: false })
|
|
84
|
+
assert.deepEqual(scope.lexiconSources(binding).map((s) => [s.libraryId, s.primary, s.scope]), [
|
|
85
|
+
[libs.current.id, true, 'private'],
|
|
86
|
+
[GLOBAL_ID, false, 'global'],
|
|
87
|
+
])
|
|
88
|
+
state.updateSettings({ crossLibraryRecall: true })
|
|
89
|
+
const ids = scope.lexiconSources(binding).map((s) => s.libraryId)
|
|
90
|
+
assert.ok(ids.includes(libs.other.id), '同域库应进入候选')
|
|
91
|
+
assert.ok(!ids.includes(libs.rp.id), '异域库不该进入候选')
|
|
92
|
+
assert.ok(!ids.includes(libs.off.id), '文件夹关掉私有记忆的库不该进入候选')
|
|
93
|
+
assert.equal(scope.lexiconSources(binding).at(-1).libraryId, GLOBAL_ID, '全局词典排在私有库之后(私有优先、全局补充)')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('lexiconSources: 全局词典受 useGlobal 天花板约束,私有记忆关掉时只剩全局', () => {
|
|
97
|
+
const libs = world()
|
|
98
|
+
state.updateSettings({ crossLibraryRecall: false })
|
|
99
|
+
state.setSessionBinding('lex-current', { useGlobal: false })
|
|
100
|
+
assert.deepEqual(scope.lexiconSources(bindingOf('lex-current')).map((s) => s.libraryId), [libs.current.id])
|
|
101
|
+
state.setSessionBinding('lex-current', { useGlobal: true, useLibrary: false })
|
|
102
|
+
assert.deepEqual(scope.lexiconSources(bindingOf('lex-current')).map((s) => s.libraryId), [GLOBAL_ID])
|
|
103
|
+
assert.equal(scope.lexiconScopeAllowed(bindingOf('lex-current')), true)
|
|
104
|
+
state.setSessionBinding('lex-current', { useLibrary: true, useGlobal: true })
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('锚点摘要读得到全局词典,即使没开跨库开关', () => {
|
|
108
|
+
world()
|
|
109
|
+
state.updateSettings({ crossLibraryRecall: false })
|
|
110
|
+
const text = inject.buildLexiconAnchor(bindingOf('lex-current'), 'lex-anchor-off', 300).text
|
|
111
|
+
assert.match(text, /全局词/)
|
|
112
|
+
assert.match(text, /当前词/)
|
|
113
|
+
assert.doesNotMatch(text, /同域词/)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('锚点摘要在开关打开后并入同域库,异域库与异域文件夹的词仍不进', () => {
|
|
117
|
+
world()
|
|
118
|
+
state.updateSettings({ crossLibraryRecall: true })
|
|
119
|
+
const text = inject.buildLexiconAnchor(bindingOf('lex-current'), 'lex-anchor-on', 300).text
|
|
120
|
+
assert.match(text, /同域词/)
|
|
121
|
+
assert.doesNotMatch(text, /关库词/)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('跨库词条按自己的 domain 戳过滤,没有戳的旧词条随库放行', () => {
|
|
125
|
+
const libs = world()
|
|
126
|
+
// 同域库里再放一条明确写着 rp 的词:库资格过了,条目级 domain 必须拦住它。
|
|
127
|
+
addTerm(libs.other.id, '伪装词', { domain: 'rp' })
|
|
128
|
+
state.updateSettings({ crossLibraryRecall: true })
|
|
129
|
+
const text = inject.buildLexiconAnchor(bindingOf('lex-current'), 'lex-entry-domain', 300).text
|
|
130
|
+
assert.match(text, /同域词/)
|
|
131
|
+
assert.doesNotMatch(text, /伪装词/)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('全局词条按 appliesToDomain 过滤:universal 恒可见,异领域隐藏', () => {
|
|
135
|
+
world()
|
|
136
|
+
const binding = bindingOf('lex-current')
|
|
137
|
+
addTerm(GLOBAL_ID, '通用词', { domain: 'universal' })
|
|
138
|
+
addTerm(GLOBAL_ID, '剧情词', { domain: 'rp' })
|
|
139
|
+
const text = inject.buildLexiconAnchor(binding, 'lex-global-domain', 300).text
|
|
140
|
+
assert.match(text, /通用词/)
|
|
141
|
+
assert.doesNotMatch(text, /剧情词/)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('B 通道命中全局词条,计数落在词条所属的词典而不是当前库', () => {
|
|
145
|
+
const libs = world()
|
|
146
|
+
state.updateSettings({ crossLibraryRecall: false })
|
|
147
|
+
const binding = bindingOf('lex-current')
|
|
148
|
+
lexicon.lexiconCooldownStore.clear()
|
|
149
|
+
const turn = inject.injectLexiconTurn({ binding, sessionId: 'lex-accounting', userTexts: ['刚看到全局词'], tokenBudget: 800 })
|
|
150
|
+
assert.match(turn.text, /全局词/)
|
|
151
|
+
inject.commitLexiconTurn({ libraryId: libs.current.id, sessionId: 'lex-accounting', hits: turn.hits, selected: turn.selected })
|
|
152
|
+
assert.equal(countsOf(GLOBAL_ID, '全局词').injection, 1)
|
|
153
|
+
assert.equal(countsOf(GLOBAL_ID, '全局词').candidate, 1)
|
|
154
|
+
assert.equal(countsOf(libs.current.id, '当前词').injection, 0)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('B 通道在开关打开后命中同域库词条,candidate 记到那本库', () => {
|
|
158
|
+
const libs = world()
|
|
159
|
+
state.updateSettings({ crossLibraryRecall: true })
|
|
160
|
+
const binding = bindingOf('lex-current')
|
|
161
|
+
lexicon.lexiconCooldownStore.clear()
|
|
162
|
+
const turn = inject.injectLexiconTurn({ binding, sessionId: 'lex-cross-turn', userTexts: ['同域词出现了'], tokenBudget: 800 })
|
|
163
|
+
assert.match(turn.text, /同域词/)
|
|
164
|
+
inject.commitLexiconTurn({ libraryId: libs.current.id, sessionId: 'lex-cross-turn', hits: turn.hits, selected: [] })
|
|
165
|
+
assert.equal(countsOf(libs.other.id, '同域词').candidate, 1)
|
|
166
|
+
assert.equal(countsOf(libs.current.id, '当前词').candidate, 0)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('同词面去重:私有库那份压过全局词典那份,一行不重复', () => {
|
|
170
|
+
const libs = world()
|
|
171
|
+
addTerm(libs.current.id, '全局词', { meaning: '私有库的解释优先' })
|
|
172
|
+
const text = inject.buildLexiconAnchor(bindingOf('lex-current'), 'lex-dedupe', 300).text
|
|
173
|
+
assert.equal(text.split('「全局词」').length - 1, 1, '同一个词面只该出现一行')
|
|
174
|
+
assert.match(text, /私有库的解释优先/)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('memu_lexicon_search 跨全局与同域库,并把外来命中报成只读', async () => {
|
|
178
|
+
const libs = world()
|
|
179
|
+
state.updateSettings({ crossLibraryRecall: true })
|
|
180
|
+
addTerm(GLOBAL_ID, '检索专用全局词', { meaning: '只给检索用例用' })
|
|
181
|
+
addTerm(libs.other.id, '检索专用同域词', { meaning: '只给检索用例用' })
|
|
182
|
+
const search = toolByName('memu_lexicon_search')
|
|
183
|
+
const exec = { agent: { session: { header: { id: 'lex-current' } } } }
|
|
184
|
+
const globalHit = await search.execute({ query: '检索专用全局词' }, exec)
|
|
185
|
+
assert.match(globalHit, /home=全局词典/)
|
|
186
|
+
assert.match(globalHit, /只读/)
|
|
187
|
+
const crossHit = await search.execute({ query: '检索专用同域词' }, exec)
|
|
188
|
+
assert.match(crossHit, new RegExp(`home=${libs.other.name}`))
|
|
189
|
+
const foreignDomain = await search.execute({ query: '异域词' }, exec)
|
|
190
|
+
assert.match(foreignDomain, /没有命中/)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('memu_lexicon_propose 给私有词条打上当前领域戳', async () => {
|
|
194
|
+
const libs = world()
|
|
195
|
+
const propose = toolByName('memu_lexicon_propose')
|
|
196
|
+
const exec = { agent: { session: { header: { id: 'lex-current' } } } }
|
|
197
|
+
await propose.execute({ term: '新戳词', kind: 'term', meaning: '带领域戳', evidence: [{ quote: '新戳词' }] }, exec)
|
|
198
|
+
assert.equal(entryOf(libs.current.id, '新戳词').domain, 'coding')
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test('词典 RPC 把全局词典当一本可读可管的词典,且不给它打领域戳', async () => {
|
|
202
|
+
const libs = world()
|
|
203
|
+
const list = await dispatch({}, 'lexiconList', { libraryId: GLOBAL_ID })
|
|
204
|
+
assert.equal(list.scope, 'global')
|
|
205
|
+
assert.ok(list.items.some((item) => item.term === '全局词'))
|
|
206
|
+
const added = await dispatch({}, 'lexiconAdd', { libraryId: GLOBAL_ID, sessionId: 'lex-current', term: '手写全局词', kind: 'term', meaning: '用户手写' })
|
|
207
|
+
assert.equal(added.term.status, 'active')
|
|
208
|
+
assert.equal(added.term.domain, undefined, '全局词条不继承写入时的领域')
|
|
209
|
+
// 会话视角的检索跨到全局词典;显式选库的检索仍只看那一本。
|
|
210
|
+
// 归档放在这两步之后:archived 词条按 §2.1 永不出现在检索里。
|
|
211
|
+
const sessionSearch = await dispatch({}, 'lexiconSearch', { sessionId: 'lex-current', q: '手写全局词' })
|
|
212
|
+
assert.ok(sessionSearch.items.some((item) => item.term === '手写全局词' && item.lexiconScope === 'global'))
|
|
213
|
+
// 显式选库不跨库:全局词典里那条只在会话视角出现。当前库的「全局词」会因为
|
|
214
|
+
// 词面包含关系被查到(searchLexicon 的 contains 层),这不代表跨库。
|
|
215
|
+
const librarySearch = await dispatch({}, 'lexiconSearch', { libraryId: libs.current.id, sessionId: 'lex-current', q: '手写全局词' })
|
|
216
|
+
assert.ok(librarySearch.items.every((item) => item.lexiconScope === undefined), '显式选库不该带来源标记')
|
|
217
|
+
assert.ok(!librarySearch.items.some((item) => item.term === '手写全局词'))
|
|
218
|
+
const archived = await dispatch({}, 'lexiconArchive', { libraryId: GLOBAL_ID, termId: added.term.termId })
|
|
219
|
+
assert.equal(archived.term.status, 'archived')
|
|
220
|
+
const afterArchive = await dispatch({}, 'lexiconSearch', { sessionId: 'lex-current', q: '手写全局词' })
|
|
221
|
+
assert.ok(!afterArchive.items.some((item) => item.term === '手写全局词'), 'archived 词条不进检索')
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('lexiconAdd 带会话时给私有词条打领域戳', async () => {
|
|
225
|
+
const libs = world()
|
|
226
|
+
const added = await dispatch({}, 'lexiconAdd', {
|
|
227
|
+
libraryId: libs.current.id, sessionId: 'lex-current', term: '面板词', kind: 'term', meaning: '从面板写入',
|
|
228
|
+
})
|
|
229
|
+
assert.equal(added.term.domain, 'coding')
|
|
230
|
+
assert.equal(entryOf(libs.current.id, '面板词').domain, 'coding')
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('全局词典与私有词典同权进自动备份清单', () => {
|
|
234
|
+
world()
|
|
235
|
+
const created = backup.createBackup({ label: 'lexicon-scope-global' })
|
|
236
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(created.dir, 'manifest.json'), 'utf8'))
|
|
237
|
+
assert.ok(manifest.files[`lexicon/${GLOBAL_ID}.json`], 'global.json 是词典数据,必须在备份里')
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
test('坏掉的辅源词典只降级并留信号,当前库照常注入', () => {
|
|
241
|
+
const libs = world()
|
|
242
|
+
state.updateSettings({ crossLibraryRecall: true })
|
|
243
|
+
fs.writeFileSync(lexiconFile(libs.other.id), '{ not a lexicon', 'utf8')
|
|
244
|
+
const anchor = inject.buildLexiconAnchor(bindingOf('lex-current'), 'lex-broken-secondary', 300)
|
|
245
|
+
assert.match(anchor.text, /当前词/, '主源照常参与')
|
|
246
|
+
assert.equal(anchor.errors.length, 1)
|
|
247
|
+
assert.match(anchor.errors[0], new RegExp(libs.other.id))
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
test('主源(当前绑定库)读失败继续抛错,由调用方按 fail-open 留可观测信号', () => {
|
|
251
|
+
const solo = state.ensureLibraryForCwd(dir('lex-solo'))
|
|
252
|
+
bind('lex-solo', dir('lex-solo'), solo.id, 'coding')
|
|
253
|
+
addTerm(solo.id, '独库词')
|
|
254
|
+
fs.writeFileSync(lexiconFile(solo.id), '{ broken', 'utf8')
|
|
255
|
+
assert.throws(() => scope.lexiconVisibleTerms(bindingOf('lex-solo')), /LEXICON_CORRUPT|could not be read/)
|
|
256
|
+
})
|
|
@@ -541,7 +541,30 @@ test('the lexicon panel is a two-tab card flow with no review/pending surface; a
|
|
|
541
541
|
// 来源记忆跳转与命中三计数 tooltip 保留。
|
|
542
542
|
assert.match(panel, /onFocusMemory/)
|
|
543
543
|
assert.match(panel, /lexiconHitsDetail/)
|
|
544
|
+
// 作用域选择器:全局词典是选择器里的第一项,不是一个私有库(与记忆墙节点图的
|
|
545
|
+
// 「全局记忆」同一款做法);口径说明用设置页同一种 note 样式。
|
|
546
|
+
assert.match(panel, /lexiconGlobalScope/)
|
|
547
|
+
assert.match(panel, /lexiconGlobalHint/)
|
|
548
|
+
assert.match(panel, /lexiconBrowseScopeHint/)
|
|
549
|
+
assert.match(panel, /dshm-settings-note/)
|
|
550
|
+
// 全局词条跳记忆墙时 libraryId 必须落回 null(全局页),不能把保留字当库 id。
|
|
551
|
+
assert.match(panel, /isGlobalLib \? null : activeLib/)
|
|
552
|
+
// 没有私有库时这一页照样可用:全局词典由用户手写,不依赖任何库。
|
|
553
|
+
assert.ok(!/h\(Empty, null, t\('lexiconNoLibrary'\)\)/.test(panel), 'no private library must not blank the whole page')
|
|
544
554
|
// 自动关联边带小 Tag,手动边不受影响(只认 source === 'auto')。
|
|
545
555
|
assert.match(src, /edge\.source === 'auto'/)
|
|
546
556
|
assert.match(src, /t\('graphAutoLink'\)/)
|
|
547
557
|
})
|
|
558
|
+
|
|
559
|
+
// 全局词典的保留存储名由服务端定义、由前端复写一遍(client.js 是浏览器侧脚本,
|
|
560
|
+
// 不能 import lib/)。两边漂移一次,前端就会把 `global` 当成一本不存在的私有库。
|
|
561
|
+
test('the client and the server spell the global lexicon id the same way', () => {
|
|
562
|
+
const core = fs.readFileSync(new URL('../lib/lexicon.js', import.meta.url), 'utf8')
|
|
563
|
+
const client = fs.readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
564
|
+
const server = /export const GLOBAL_LEXICON_ID = '([^']+)'/.exec(core)?.[1]
|
|
565
|
+
const browser = /const GLOBAL_LEXICON_ID = '([^']+)'/.exec(client)?.[1]
|
|
566
|
+
assert.ok(server, 'lib/lexicon.js must define GLOBAL_LEXICON_ID')
|
|
567
|
+
assert.equal(browser, server)
|
|
568
|
+
assert.ok(state.listLibraries().every((lib) => lib.id !== server), 'a library id may never be the reserved global id')
|
|
569
|
+
})
|
|
570
|
+
|
|
@@ -48,7 +48,7 @@ globalThis.__managedMemoryTest = {
|
|
|
48
48
|
},
|
|
49
49
|
async listFiles() { throw new Error('unexpected list engine call') },
|
|
50
50
|
}
|
|
51
|
-
const engineSource = 'const bridge = globalThis.__managedMemoryTest; export const commit = bridge.commit, retrieve = bridge.retrieve, forget = bridge.forget, listFiles = bridge.listFiles;'
|
|
51
|
+
const engineSource = 'const bridge = globalThis.__managedMemoryTest; export const commit = bridge.commit, retrieve = bridge.retrieve, forget = bridge.forget, listFiles = bridge.listFiles, closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
|
|
52
52
|
const hooks = registerHooks({
|
|
53
53
|
resolve(specifier, context, nextResolve) {
|
|
54
54
|
if (specifier === './memu.js') {
|
|
@@ -22,7 +22,7 @@ globalThis.__recallDedupTest = {
|
|
|
22
22
|
async forget() { return { deleted: 1, segments: 1 } },
|
|
23
23
|
async listFiles() { return { recall_files: [], resources: [], raw: null } },
|
|
24
24
|
}
|
|
25
|
-
const engineSource = 'const bridge = globalThis.__recallDedupTest; export const commit = bridge.commit, retrieve = bridge.retrieve, forget = bridge.forget, listFiles = bridge.listFiles;'
|
|
25
|
+
const engineSource = 'const bridge = globalThis.__recallDedupTest; export const commit = bridge.commit, retrieve = bridge.retrieve, forget = bridge.forget, listFiles = bridge.listFiles, closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
|
|
26
26
|
const hooks = registerHooks({
|
|
27
27
|
resolve(specifier, context, nextResolve) {
|
|
28
28
|
if (specifier === './memu.js') {
|
|
@@ -10,7 +10,7 @@ process.env.DSH_MEMU_HOME = home
|
|
|
10
10
|
const state = await import('../lib/state.js')
|
|
11
11
|
const wake = await import('../lib/salient-wake.js')
|
|
12
12
|
const activity = await import('../lib/activity-log.js')
|
|
13
|
-
const { fakeScheduleService, wakeContext, scheduleError } = await import('./stubs/dsh-schedule.js')
|
|
13
|
+
const { fakeScheduleService, fakeSessionScheduleService, wakeContext, scheduleError } = await import('./stubs/dsh-schedule.js')
|
|
14
14
|
|
|
15
15
|
test.after(() => {
|
|
16
16
|
try { state.flushState() } catch {}
|
|
@@ -105,6 +105,33 @@ test('a host without a schedule service warns once and does not throw', async ()
|
|
|
105
105
|
state.updateSettings({ salientWake: 'off' })
|
|
106
106
|
})
|
|
107
107
|
|
|
108
|
+
test('a session-scoped schedule API is skipped with one warning, never called', async () => {
|
|
109
|
+
state.updateSettings({ salientWake: 'schedule' })
|
|
110
|
+
const { binding } = newSession('wake-session-api')
|
|
111
|
+
putEntry(binding.libraryId, 'mem-session-api', { salientDate: '2026-11-02' })
|
|
112
|
+
const schedule = fakeSessionScheduleService()
|
|
113
|
+
const logs = []
|
|
114
|
+
const log = (message) => logs.push(String(message))
|
|
115
|
+
assert.deepEqual(await run(schedule, local(2026, 11, 2), log), { skipped: 'schedule-api' })
|
|
116
|
+
assert.equal(schedule.calls.list.length, 0, 'the old list needs a sessionId; calling it with { limit } would be a wrong-shaped request')
|
|
117
|
+
assert.equal(schedule.calls.create.length, 0)
|
|
118
|
+
assert.equal(schedule.calls.delete.length, 0)
|
|
119
|
+
assert.equal(logs.length, 1)
|
|
120
|
+
assert.match(logs[0], /host-wide schedule API/)
|
|
121
|
+
|
|
122
|
+
const events = activity.listEvents({ limit: 50 })
|
|
123
|
+
assert.ok(events.some((event) => event.detail?.trigger === 'wake' && event.detail?.stage === 'schedule-api' && event.level === 'warn'))
|
|
124
|
+
state.updateSettings({ salientWake: 'off' })
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('scheduleFlavor distinguishes the host-wide and session-scoped APIs structurally', () => {
|
|
128
|
+
assert.equal(wake.scheduleFlavor(null), null)
|
|
129
|
+
assert.equal(wake.scheduleFlavor({}), null)
|
|
130
|
+
assert.equal(wake.scheduleFlavor({ create() {}, list() {} }), null)
|
|
131
|
+
assert.equal(wake.scheduleFlavor(fakeScheduleService()), 'global')
|
|
132
|
+
assert.equal(wake.scheduleFlavor(fakeSessionScheduleService()), 'session')
|
|
133
|
+
})
|
|
134
|
+
|
|
108
135
|
test('today and tomorrow each get one task whose prompt is self-contained', async () => {
|
|
109
136
|
state.updateSettings({ salientWake: 'schedule', salientWakeHour: '09:00', salientWakeTimeZone: '' })
|
|
110
137
|
const { sessionId, binding } = newSession('wake-main')
|
|
@@ -103,3 +103,38 @@ export function wakeContext(schedule) {
|
|
|
103
103
|
},
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The 0.2.0 / 0.2.1 session-scoped reminder API: every task belongs to one
|
|
109
|
+
* Session, `list` needs that Session, and there is no `edit` method. The wake
|
|
110
|
+
* pass probes for `edit` to tell this shape from the 0.2.2 host-wide task table,
|
|
111
|
+
* so this fake exists to pin that the old API is skipped instead of being
|
|
112
|
+
* called with the wrong argument shape.
|
|
113
|
+
*/
|
|
114
|
+
export function fakeSessionScheduleService() {
|
|
115
|
+
const tasks = []
|
|
116
|
+
const calls = { create: [], list: [], delete: [] }
|
|
117
|
+
let seq = 0
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
tasks,
|
|
121
|
+
calls,
|
|
122
|
+
async create(sessionId, request) {
|
|
123
|
+
calls.create.push({ sessionId, request })
|
|
124
|
+
const entry = { id: `sess-sched-${++seq}`, sessionId, title: request.title, status: 'active' }
|
|
125
|
+
tasks.push(entry)
|
|
126
|
+
return entry
|
|
127
|
+
},
|
|
128
|
+
async list(request) {
|
|
129
|
+
calls.list.push(request)
|
|
130
|
+
return tasks.filter((task) => task.sessionId === request.sessionId)
|
|
131
|
+
},
|
|
132
|
+
async delete(request) {
|
|
133
|
+
calls.delete.push(request)
|
|
134
|
+
const index = tasks.findIndex((task) => task.id === request.id && task.sessionId === request.sessionId)
|
|
135
|
+
if (index < 0) return { id: request.id, deleted: false }
|
|
136
|
+
tasks.splice(index, 1)
|
|
137
|
+
return { id: request.id, deleted: true }
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -49,7 +49,7 @@ test('the audited numeric fields are covered by that gate', () => {
|
|
|
49
49
|
['dedupeTurns', 16],
|
|
50
50
|
['globalEveryNTurns', 6],
|
|
51
51
|
['randomCueChance', 0.02],
|
|
52
|
-
['sleepAfterIdleMinutes',
|
|
52
|
+
['sleepAfterIdleMinutes', 2],
|
|
53
53
|
]) {
|
|
54
54
|
assert.equal(fallbacks.get(key), expected, 'settings.' + key + ' fallback')
|
|
55
55
|
assert.equal(state.DEFAULT_SETTINGS[key], expected, 'DEFAULT_SETTINGS.' + key)
|
|
@@ -159,11 +159,31 @@ test('prepareShadow allocates a brand-new generation path and never switches by
|
|
|
159
159
|
const resumed = await migrator.prepareShadow({ profile: BGE })
|
|
160
160
|
assert.equal(resumed.generation, first.generation)
|
|
161
161
|
assert.equal(resumed.resumed, true)
|
|
162
|
+
|
|
162
163
|
const fresh = await migrator.prepareShadow({ profile: BGE, fresh: true })
|
|
163
164
|
assert.notEqual(fresh.generation, first.generation)
|
|
164
165
|
assert.notEqual(fresh.databases.global, first.databases.global)
|
|
165
166
|
})
|
|
166
167
|
|
|
168
|
+
test('a pending generation with a stale manifest is discarded instead of resumed', async () => {
|
|
169
|
+
resetAll()
|
|
170
|
+
const fx = createFixture()
|
|
171
|
+
const migrator = fx.migrator()
|
|
172
|
+
const first = await migrator.prepareShadow({ profile: BGE })
|
|
173
|
+
// A catalog manifest change (for example adding a download source) must not be
|
|
174
|
+
// resumed under the same fingerprint: the old journal profile no longer verifies.
|
|
175
|
+
vp.updatePendingJournal(journal => ({
|
|
176
|
+
...journal,
|
|
177
|
+
status: 'failed',
|
|
178
|
+
profile: { ...journal.profile, manifestDigest: '0'.repeat(64) },
|
|
179
|
+
error: { code: 'VECTOR_STALE_TEST', message: 'old manifest' },
|
|
180
|
+
}))
|
|
181
|
+
const replacement = await migrator.prepareShadow({ profile: BGE })
|
|
182
|
+
assert.notEqual(replacement.generation, first.generation, 'a stale pending generation must be discarded')
|
|
183
|
+
assert.equal(replacement.resumed, false)
|
|
184
|
+
assert.ok(vp.manifestDigestAccepted(vp.pendingJournal().profile.manifestDigest, catalog.getEmbeddingModel(BGE)))
|
|
185
|
+
})
|
|
186
|
+
|
|
167
187
|
// ---------------------------------------------------------------- syncShadow
|
|
168
188
|
|
|
169
189
|
test('migration passes the verified profile and generation to list/read cleanup calls', async () => {
|
|
@@ -613,6 +613,34 @@ test('operation matrix: every library route denies A→B, allows A→A, and gate
|
|
|
613
613
|
}
|
|
614
614
|
})
|
|
615
615
|
|
|
616
|
+
// 全局词典(lib/lexicon.js 的 GLOBAL_LEXICON_ID)不是私有库:宿主不该被叫去授权一本
|
|
617
|
+
// 根本不存在的库,绑定中的会话也不该因为点名「全局」而不是自己的库就被判成越权。
|
|
618
|
+
// 会话侧仍要认凭证(会话存在 + 全局层没被天花板关掉);standalone 与 listGlobal 一样
|
|
619
|
+
// 只由 HTTP 边界把关。
|
|
620
|
+
test('the global lexicon is a shared store, not a library route', async () => {
|
|
621
|
+
const { GLOBAL_LEXICON_ID } = await import('../lib/lexicon.js')
|
|
622
|
+
for (const prefix of prefixes) {
|
|
623
|
+
const post = (payload) => send(prefix.route, prefix.base + '/lexiconList', { method: 'POST', body: envelope('lexiconList', payload) })
|
|
624
|
+
auth.callbackMode = 'present'
|
|
625
|
+
auth.libraryDecision = false
|
|
626
|
+
auth.libraryCalls = 0
|
|
627
|
+
const bound = await post({ libraryId: GLOBAL_LEXICON_ID, sessionId })
|
|
628
|
+
assert.equal(bound.res.status, 200, `${prefix.name}: a bound session may address the global lexicon`)
|
|
629
|
+
assert.equal(auth.libraryCalls, 0, `${prefix.name}: the host must not be asked about a library that does not exist`)
|
|
630
|
+
const ghost = await post({ libraryId: GLOBAL_LEXICON_ID, sessionId: 'auth-session-ghost' })
|
|
631
|
+
assert.equal(ghost.res.status, 403, `${prefix.name}: a dangling session id is never a credential`)
|
|
632
|
+
state.setSessionBinding(sessionId, { useGlobal: false })
|
|
633
|
+
const blocked = await post({ libraryId: GLOBAL_LEXICON_ID, sessionId })
|
|
634
|
+
state.setSessionBinding(sessionId, { useGlobal: true })
|
|
635
|
+
assert.equal(blocked.res.status, 403, `${prefix.name}: useGlobal=false means there is no global lexicon for that conversation`)
|
|
636
|
+
auth.libraryDecision = false
|
|
637
|
+
auth.libraryCalls = 0
|
|
638
|
+
const solo = await post({ libraryId: GLOBAL_LEXICON_ID })
|
|
639
|
+
assert.equal(solo.res.status, 200, `${prefix.name}: the management plane is governed by the HTTP boundary`)
|
|
640
|
+
assert.equal(auth.libraryCalls, 0)
|
|
641
|
+
}
|
|
642
|
+
})
|
|
643
|
+
|
|
616
644
|
test('removed lexiconReview is no longer a library route and does not dispatch', async () => {
|
|
617
645
|
for (const prefix of prefixes) {
|
|
618
646
|
auth.callbackMode = 'present'
|