dsh-memu-memory 1.4.4 → 1.4.5
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/CHANGELOG.md +11 -0
- package/README.md +33 -14
- package/README.zh.md +34 -12
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/libraries.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/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +19 -3
- package/docs/contributing.md +4 -2
- package/docs/env-and-commands.md +9 -1
- package/docs/graph-scale.md +214 -0
- package/docs/lexicon-recall.md +100 -0
- package/docs/mcp-porting.md +8 -6
- package/docs/memory-semantics.md +35 -3
- package/docs/pending-work.md +3 -1
- package/docs/retention.md +83 -0
- package/docs/rt-index.md +452 -0
- package/docs/scale-performance.md +101 -0
- package/docs/token-budget.md +92 -0
- package/docs/troubleshooting.md +50 -11
- package/lib/auto-link/apply.js +7 -2
- package/lib/auto-link/candidates.js +32 -10
- package/lib/backup.js +67 -32
- package/lib/binding-diagnostics.js +1 -1
- package/lib/bounded-cache.js +80 -0
- package/lib/client.js +2096 -409
- package/lib/consolidation-ledger.js +21 -4
- package/lib/consolidation-worker.js +14 -1
- package/lib/cycle.js +16 -11
- package/lib/diagnostic-context.js +372 -0
- package/lib/diagnostics.js +147 -61
- package/lib/embedding-download.js +7 -8
- package/lib/engine-sources.js +286 -0
- package/lib/engine.js +23 -10
- package/lib/entity-repair.js +43 -13
- package/lib/entity-review.js +64 -0
- package/lib/environment-check.js +348 -36
- package/lib/feedback.js +25 -0
- package/lib/global-graph.js +46 -2
- package/lib/graph-adjacency-index.js +525 -0
- package/lib/graph-overview.js +293 -0
- package/lib/graph.js +658 -105
- package/lib/inbound.js +44 -15
- package/lib/index-pages.js +57 -0
- package/lib/index.js +44 -6
- package/lib/inject.js +119 -50
- package/lib/lexicon-rt-source.js +25 -0
- package/lib/lexicon-rt-worker.js +26 -0
- package/lib/lexicon-rt.js +224 -0
- package/lib/lexicon-scope.js +56 -5
- package/lib/lexicon.js +143 -54
- package/lib/local-vector-service.js +3 -0
- package/lib/maintenance-ledger.js +542 -12
- package/lib/managed-runtime.js +260 -80
- package/lib/media.js +1 -1
- package/lib/memory.js +564 -131
- package/lib/port-surface.js +96 -11
- package/lib/private.js +47 -21
- package/lib/recall-cache.js +20 -34
- package/lib/retention.js +173 -0
- package/lib/rpc.js +135 -52
- package/lib/rt-index/builder.js +209 -0
- package/lib/rt-index/format.js +231 -0
- package/lib/rt-index/manifest.js +105 -0
- package/lib/rt-index/reader.js +673 -0
- package/lib/rt-index-retention.js +151 -0
- package/lib/rt-index-service.js +283 -0
- package/lib/rt-index-worker.js +21 -0
- package/lib/salient-wake.js +55 -4
- package/lib/state.js +195 -24
- package/lib/temporal.js +39 -13
- package/lib/token-measurement.js +126 -0
- package/lib/tools.js +101 -6
- package/lib/turn-log.js +108 -3
- package/lib/webui/graph-layout-worker.js +68 -0
- package/lib/webui/graph-local-physics.js +390 -0
- package/lib/webui/graph-spatial-grid.js +64 -0
- package/lib/webui/graph-view.bundle.js +6 -1
- package/lib/webui/graph-view.js +478 -135
- package/lib/webui/graph-webgl-renderer.js +74 -0
- package/lib/webui/standalone.js +1 -1
- package/lib/worker-pool.js +30 -4
- package/package.json +3 -2
- package/scripts/acceptance-local.mjs +4 -10
- package/scripts/bench-all-libraries.mjs +47 -0
- package/scripts/check-classic-graph-browser.mjs +189 -0
- package/scripts/check-client-browser.mjs +929 -0
- package/scripts/check-graph-browser.mjs +6 -0
- package/scripts/check-graph-elastic-browser.mjs +139 -0
- package/scripts/check-memory-review-browser.mjs +124 -0
- package/scripts/entity-dedupe.mjs +19 -3
- package/scripts/graph-artifact-provenance.mjs +30 -0
- package/scripts/graph-freeze-manifest.mjs +129 -0
- package/scripts/graph-geometry-fixture.mjs +40 -0
- package/scripts/graph-physics-bench.mjs +218 -0
- package/scripts/graph-scale-bench.mjs +213 -0
- package/scripts/graph-scale-memory.mjs +48 -0
- package/scripts/graph-service-bench.mjs +72 -0
- package/scripts/make-readme-shots.mjs +17 -5
- package/scripts/preview.mjs +1 -0
- package/scripts/rebuild-rt.mjs +18 -0
- package/scripts/scale-bench.mjs +183 -0
- package/scripts/simulate-injection.mjs +47 -8
- package/scripts/verify-host-fixtures.mjs +108 -0
- package/scripts/verify-host-recovery.mjs +565 -0
- package/scripts/verify-vector-recovery.mjs +740 -0
- package/tests/auto-link-candidates.test.mjs +20 -0
- package/tests/browser.test.mjs +16 -2
- package/tests/client-export.test.mjs +16 -1
- package/tests/client-pagination.test.mjs +1495 -0
- package/tests/client-render.test.mjs +223 -28
- package/tests/consolidation-fork.test.mjs +93 -10
- package/tests/consolidation-ledger.test.mjs +17 -1
- package/tests/diagnostic-entity-candidates.test.mjs +54 -0
- package/tests/diagnostic-report.test.mjs +429 -0
- package/tests/diagnostic-wiring.test.mjs +88 -0
- package/tests/diagnostics.test.mjs +27 -0
- package/tests/embedding-download.test.mjs +44 -0
- package/tests/engine-source-settings.test.mjs +69 -0
- package/tests/engine-sources.test.mjs +145 -0
- package/tests/entity-dedupe.test.mjs +143 -0
- package/tests/entity-merge-review.test.mjs +363 -0
- package/tests/entity-merge.test.mjs +12 -4
- package/tests/entity-review.test.mjs +87 -0
- package/tests/environment-check.test.mjs +51 -1
- package/tests/feedback.test.mjs +95 -0
- package/tests/graph-adjacency-index.test.mjs +536 -0
- package/tests/graph-cascade.test.mjs +229 -0
- package/tests/graph-import-diagnostic.test.mjs +25 -0
- package/tests/graph-overview.test.mjs +709 -0
- package/tests/graph-session-authorization.test.mjs +419 -0
- package/tests/graph-view-geometry.test.mjs +426 -0
- package/tests/graph-view-scale.test.mjs +88 -0
- package/tests/graph-view.test.mjs +444 -5
- package/tests/graph.test.mjs +43 -0
- package/tests/help-page.test.mjs +128 -54
- package/tests/inbound.test.mjs +19 -0
- package/tests/index-pagination.test.mjs +113 -0
- package/tests/index-read-view.test.mjs +212 -0
- package/tests/inject-guide.test.mjs +9 -0
- package/tests/injection-dedupe.test.mjs +213 -0
- package/tests/lexicon-recall.test.mjs +641 -0
- package/tests/lexicon-rt-lifecycle.test.mjs +196 -0
- package/tests/lexicon-rt.test.mjs +468 -0
- package/tests/local-embedding-worker.test.mjs +38 -0
- package/tests/local-vector-service.test.mjs +32 -3
- package/tests/maintenance-compat.test.mjs +128 -0
- package/tests/maintenance-settlement.test.mjs +1003 -0
- package/tests/managed-memory.test.mjs +39 -11
- package/tests/managed-runtime.test.mjs +109 -0
- package/tests/memory-fields.test.mjs +24 -12
- package/tests/observed-evidence.test.mjs +52 -0
- package/tests/port-surface.test.mjs +93 -1
- package/tests/recall-cache.test.mjs +56 -3
- package/tests/recall-dedup.test.mjs +63 -2
- package/tests/retention.test.mjs +260 -0
- package/tests/rt-index-cross-library.test.mjs +230 -0
- package/tests/rt-index-integration.test.mjs +194 -0
- package/tests/rt-index-retention.test.mjs +552 -0
- package/tests/rt-index-scale.test.mjs +204 -0
- package/tests/rt-index.test.mjs +705 -0
- package/tests/salient-date-boundaries.test.mjs +121 -0
- package/tests/salient-wake.test.mjs +29 -0
- package/tests/scale-bench.test.mjs +53 -0
- package/tests/settings-plumbing.test.mjs +25 -0
- package/tests/simulate-injection.test.mjs +15 -1
- package/tests/standalone-navigation.test.mjs +44 -0
- package/tests/state.test.mjs +51 -0
- package/tests/temporal-precision.test.mjs +102 -0
- package/tests/temporal.test.mjs +10 -6
- package/tests/token-measurement.test.mjs +98 -0
- package/tests/tool-schema.test.mjs +41 -5
- package/tests/tools.test.mjs +6 -3
- package/tests/turn-token-budget.test.mjs +149 -0
- package/tests/webui-auth.test.mjs +57 -1
- package/tests/webui.test.mjs +40 -15
package/tests/help-page.test.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 帮助页与首次安装引导,以及统一关系管理入口的渲染断言。
|
|
2
2
|
// 沿用 client-render.test.mjs 的最小 React 运行时:一个在渲染期 throw 的页面块就是
|
|
3
3
|
// 白屏,必须在构建期失败而不是静默白板。每一页都渲染,因为块只在选中该页时挂载。
|
|
4
4
|
import test from 'node:test'
|
|
@@ -108,7 +108,7 @@ function fakeCtx(answers = {}) {
|
|
|
108
108
|
rpc: {
|
|
109
109
|
call: async (path, endpoint, payload) => {
|
|
110
110
|
rpcCalls.push({ endpoint, payload })
|
|
111
|
-
return { ok: true, value: merged[endpoint] ?? {} }
|
|
111
|
+
return { ok: true, value: typeof merged[endpoint] === 'function' ? await merged[endpoint](payload) : merged[endpoint] ?? {} }
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
},
|
|
@@ -193,7 +193,7 @@ function settingsComponent() {
|
|
|
193
193
|
return registration.component
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
test('all
|
|
196
|
+
test('all fifteen settings pages render, and the nav carries help and diagnostics', async () => {
|
|
197
197
|
const ctx = fakeCtx()
|
|
198
198
|
globalThis.__dshMemuHelpExports.apply(ctx)
|
|
199
199
|
const component = settingsComponent()
|
|
@@ -202,8 +202,8 @@ test('all thirteen settings pages render, and the nav carries the help entry', a
|
|
|
202
202
|
await mountAndSettle(component, props)
|
|
203
203
|
collectPageHook()
|
|
204
204
|
|
|
205
|
-
const NAV = ['pageOverview', 'pageConnection', 'pageSettings', 'pageFolders', 'pageLibraries', 'pageBrowser', 'pageGlobal', 'pagePrompts', 'pageStats', 'pageMemories', 'pageLogs', 'pageLexicon', 'pageHelp']
|
|
206
|
-
for (let page = 0; page <
|
|
205
|
+
const NAV = ['pageOverview', 'pageConnection', 'pageSettings', 'pageFolders', 'pageLibraries', 'pageBrowser', 'pageGlobal', 'pagePrompts', 'pageStats', 'pageMemories', 'pageGraph', 'pageLogs', 'pageLexicon', 'pageHelp', 'pageDiagnostics']
|
|
206
|
+
for (let page = 0; page < 15; page++) {
|
|
207
207
|
const { tree } = renderAt(component, props, page)
|
|
208
208
|
const text = treeText(tree)
|
|
209
209
|
assert.match(String(tree.props?.className), /dshm-root/, `page ${page} did not render the shell`)
|
|
@@ -232,7 +232,7 @@ test('the deep link #/settings/help lands on the help page when standalone', asy
|
|
|
232
232
|
window.location.hash = ''
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
test('the help page shows
|
|
235
|
+
test('the help page shows seven tutorial steps, eleven FAQ details and the feedback actions', async () => {
|
|
236
236
|
const component = settingsComponent()
|
|
237
237
|
const props = { ctx: fakeCtx(), t: (key) => key }
|
|
238
238
|
await mountAndSettle(component, props)
|
|
@@ -240,7 +240,8 @@ test('the help page shows five steps, eleven FAQ details and the feedback action
|
|
|
240
240
|
|
|
241
241
|
const { tree } = renderAt(component, props, 13)
|
|
242
242
|
const text = treeText(tree)
|
|
243
|
-
for (const step of [1, 2, 3, 4, 5]) assert.ok(text.includes(`helpStep${step}`), `
|
|
243
|
+
for (const step of [1, 2, 3, 4, 5, 6, 7]) assert.ok(text.includes(`helpStep${step}Title`), `tutorial step ${step} is missing`)
|
|
244
|
+
for (const key of ['helpStep1Expected', 'helpStep1Trouble', 'helpTutorialNext', 'helpTutorialDiagnose']) assert.ok(text.includes(key), `tutorial guidance ${key} is missing`)
|
|
244
245
|
for (const n of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) {
|
|
245
246
|
assert.ok(text.includes(`helpFaq${n}`), `FAQ item ${n} is missing`)
|
|
246
247
|
assert.ok(text.includes(`helpFaq${n}A`), `FAQ answer ${n} is missing`)
|
|
@@ -249,23 +250,113 @@ test('the help page shows five steps, eleven FAQ details and the feedback action
|
|
|
249
250
|
assert.ok(text.includes('helpOpenIssue'), 'the issue button is missing')
|
|
250
251
|
assert.ok(text.includes('helpCopyDiagnostics'), 'the copy-diagnostics button is missing')
|
|
251
252
|
assert.ok(text.includes('helpDocs'), 'the docs link is missing')
|
|
252
|
-
//
|
|
253
|
-
//(第 2 步是会话侧动作,只给文案,不带跳转 → 4 个按钮)。
|
|
253
|
+
// Only the selected lesson is expanded; the reference FAQ stays available.
|
|
254
254
|
const details = []
|
|
255
255
|
walkNodes(tree, (node) => {
|
|
256
256
|
if (node.type === 'details') details.push(node)
|
|
257
257
|
})
|
|
258
258
|
assert.equal(details.length, 11, `expected eleven FAQ details, found ${details.length}`)
|
|
259
|
-
assert.equal((text.match(/helpGoTo/g) || []).length,
|
|
260
|
-
// 不新增 RPC:复制诊断只序列化 getSettingsState 的既有快照(state 优先,缺了才补拉)。
|
|
259
|
+
assert.equal((text.match(/helpGoTo/g) || []).length, 1, 'only the selected lesson has its task navigation button')
|
|
261
260
|
const src = clientSource
|
|
262
261
|
assert.ok(src.includes('https://github.com/Tkingxiao/dsh-memu-memory/issues/new'), 'the issue URL is wired')
|
|
263
262
|
assert.ok(src.includes('https://github.com/Tkingxiao/dsh-memu-memory#readme'), 'the docs URL is wired')
|
|
264
|
-
assert.match(src, /
|
|
263
|
+
assert.match(src, /call\('getDiagnosticReport', \{ limit: 100 \}\)/, 'help and diagnostics use the bounded server-redacted report')
|
|
264
|
+
const copy = src.slice(src.indexOf('const copyDiagnostics ='), src.indexOf('// 教程状态'))
|
|
265
|
+
assert.ok(!/snapshot\.settings|snapshot\.libraries|getSettingsState/.test(copy), 'support export cannot serialize raw settings or library paths')
|
|
265
266
|
assert.match(src, /helpStep1[\s\S]*PAGE\.libraries[\s\S]*helpStep3[\s\S]*PAGE\.settings[\s\S]*helpStep4[\s\S]*PAGE\.memories[\s\S]*helpStep5[\s\S]*PAGE\.lexicon/, 'the steps point at the documented pages')
|
|
266
267
|
assert.match(src, /\{ key: 'helpStep2', to: null \}/, 'the bind step stays a text-only step')
|
|
267
268
|
})
|
|
268
269
|
|
|
270
|
+
test('diagnostics show version evidence, layers and complete bounded errors; support copy uses the redacted report', async () => {
|
|
271
|
+
const component = settingsComponent()
|
|
272
|
+
const stack = ' at readIndex (lib/state.js:12:3)\n'.repeat(60) + 'stack-end-sentinel'
|
|
273
|
+
const report = {
|
|
274
|
+
schemaVersion: 1, redacted: true, generatedAt: '2026-11-30T10:00:00.000Z',
|
|
275
|
+
runtime: { host: { version: '0.2.2-rc.5', source: 'running-entry/package.json' }, plugin: { version: '1.4.4' }, node: { version: 'v24.15.0', modules: '137' }, os: { platform: 'win32', arch: 'x64', release: '10.0.1' } },
|
|
276
|
+
components: Object.fromEntries(['host', 'plugin', 'engine', 'vector', 'state', 'rpc', 'workers'].map(key => [key, { status: key === 'engine' ? 'error' : key === 'workers' ? 'unknown' : 'observed', source: key, evidence: { numericCount: 12 }, code: key === 'engine' ? 'ENGINE_FIXTURE' : null, action: 'Inspect evidence first' }])),
|
|
277
|
+
health: { limitations: ['metadata is not an execution test'] },
|
|
278
|
+
text: '{"schemaVersion":1,"redacted":true,"technicalOnly":true}',
|
|
279
|
+
}
|
|
280
|
+
const failure = { id: 'diag-fixture', level: 'error', scope: 'storage', layer: 'state', code: 'INDEX_FIXTURE', message: 'failed to read index', operation: 'read-index', correlationId: 'rpc-fixture-1',
|
|
281
|
+
error: { code: 'EACCES', stack, causes: [{ code: 'EPERM' }] }, context: { attempt: 2 }, detail: { bytes: 64 }, retry: { retryable: true, afterMs: 30000 }, action: 'Inspect file permissions' }
|
|
282
|
+
const props = { ctx: fakeCtx({
|
|
283
|
+
getSettingsState: { ...EMPTY_STATE, settings: { apiKey: 'must-never-export' } },
|
|
284
|
+
getDiagnostics: { items: [failure], stats: { total: 1, counts: { error: 1 } } },
|
|
285
|
+
getDiagnosticReport: report, runEnvironmentCheck: { items: [], autoRepairs: [] },
|
|
286
|
+
}), t: key => key }
|
|
287
|
+
await mountAndSettle(component, props)
|
|
288
|
+
collectPageHook()
|
|
289
|
+
assert.equal(rpcCalls.filter(row => row.endpoint === 'getDiagnosticReport').length, 0, 'unrelated pages do not fetch the diagnostic snapshot')
|
|
290
|
+
const first = renderAt(component, props, 14)
|
|
291
|
+
for (const effect of first.effects) effect.fn()
|
|
292
|
+
await new Promise(resolve => setTimeout(resolve, 0))
|
|
293
|
+
const { tree } = renderAt(component, props, 14)
|
|
294
|
+
const nodes = []
|
|
295
|
+
walkNodes(tree, node => { nodes.push(node) })
|
|
296
|
+
const text = treeText(tree)
|
|
297
|
+
for (const evidence of ['0.2.2-rc.5', '1.4.4', 'v24.15.0', 'win32', 'running-entry/package.json', 'stack-end-sentinel', 'EACCES', 'EPERM', 'rpc-fixture-1', 'read-index', '30000']) assert.ok(text.includes(evidence), `missing diagnostic evidence ${evidence}`)
|
|
298
|
+
assert.deepEqual(nodes.filter(node => node.props?.['data-diag-layer']).map(node => node.props['data-diag-layer']), ['host', 'plugin', 'engine', 'vector', 'state', 'rpc', 'workers'])
|
|
299
|
+
assert.ok(text.includes('diagStatusUnknown'), 'unknown workers must not appear healthy')
|
|
300
|
+
assert.ok(!text.includes('must-never-export'))
|
|
301
|
+
let copied = null
|
|
302
|
+
const previous = Object.getOwnPropertyDescriptor(globalThis, 'navigator')
|
|
303
|
+
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { clipboard: { writeText: async value => { copied = value } } } })
|
|
304
|
+
try {
|
|
305
|
+
await nodes.find(node => node.type === 'button' && node.props.children === 'diagCopyAll').props.onClick()
|
|
306
|
+
assert.equal(copied, report.text)
|
|
307
|
+
const before = rpcCalls.filter(row => row.endpoint === 'clearDiagnostics').length
|
|
308
|
+
await nodes.find(node => node.type === 'button' && node.props.children === 'diagClear').props.onClick()
|
|
309
|
+
assert.equal(rpcCalls.filter(row => row.endpoint === 'clearDiagnostics').length, before, 'diagnostic evidence removal requires a second click')
|
|
310
|
+
} finally {
|
|
311
|
+
if (previous) Object.defineProperty(globalThis, 'navigator', previous)
|
|
312
|
+
else delete globalThis.navigator
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
test('tutorial navigation changes lessons, preserves scope, and routes each action to its real page', async () => {
|
|
317
|
+
const component = settingsComponent()
|
|
318
|
+
const props = { ctx: fakeCtx(), t: key => key }
|
|
319
|
+
await mountAndSettle(component, props)
|
|
320
|
+
collectPageHook()
|
|
321
|
+
const before = rpcCalls.length
|
|
322
|
+
const collect = tree => {
|
|
323
|
+
const nodes = []
|
|
324
|
+
walkNodes(tree, node => { nodes.push(node) })
|
|
325
|
+
return nodes
|
|
326
|
+
}
|
|
327
|
+
const render = () => {
|
|
328
|
+
const { tree } = renderAt(component, props, 13)
|
|
329
|
+
return { tree, nodes: collect(tree) }
|
|
330
|
+
}
|
|
331
|
+
let view = render()
|
|
332
|
+
const button = (label, current = view) => current.nodes.find(node => node.type === 'button' && node.props.children === label)
|
|
333
|
+
assert.equal(button('helpTutorialPrevious').props.disabled, true)
|
|
334
|
+
for (let index = 1; index <= 7; index++) {
|
|
335
|
+
assert.equal(view.nodes.find(node => node.props?.['aria-current'] === 'step').props.title, `helpStep${index}Title`)
|
|
336
|
+
const lesson = view.nodes.find(node => node.props?.['data-help-action'])
|
|
337
|
+
assert.equal(lesson.props['data-help-action'], `helpStep${index}`)
|
|
338
|
+
assert.equal(button('helpGoTo') !== undefined, index !== 2, 'binding remains a host conversation action')
|
|
339
|
+
assert.match(treeText(view.tree), new RegExp(`helpStep${index}Expected[\\s\\S]*helpStep${index}Trouble`))
|
|
340
|
+
assert.equal(button('helpTutorialNext').props.disabled, index === 7)
|
|
341
|
+
if (index < 7) { button('helpTutorialNext').props.onClick(); view = render() }
|
|
342
|
+
}
|
|
343
|
+
button('helpTutorialPrevious').props.onClick()
|
|
344
|
+
view = render()
|
|
345
|
+
assert.equal(view.nodes.find(node => node.props?.['aria-current'] === 'step').props.title, 'helpStep6Title')
|
|
346
|
+
const switches = view.nodes.filter(node => node.type === 'button' && node.props?.['aria-controls'] === 'dshm-help-lesson')
|
|
347
|
+
switches[1].props.onClick()
|
|
348
|
+
view = render()
|
|
349
|
+
assert.equal(button('helpGoTo'), undefined)
|
|
350
|
+
switches[6].props.onClick()
|
|
351
|
+
view = render()
|
|
352
|
+
button('helpGoTo').props.onClick()
|
|
353
|
+
assert.equal(hooks[pageHookIndex], 10, 'the graph lesson opens the graph page')
|
|
354
|
+
view = render()
|
|
355
|
+
button('helpTutorialDiagnose').props.onClick()
|
|
356
|
+
assert.equal(hooks[pageHookIndex], 14, 'troubleshooting opens diagnostics')
|
|
357
|
+
assert.equal(rpcCalls.length, before, 'reading lessons and navigating does not mutate library, scope or settings')
|
|
358
|
+
})
|
|
359
|
+
|
|
269
360
|
test('the detailed help sections and label table render between quick start and FAQ', async () => {
|
|
270
361
|
const component = settingsComponent()
|
|
271
362
|
const props = { ctx: fakeCtx(), t: (key) => key }
|
|
@@ -336,16 +427,14 @@ test('the first-run card shows only when no library exists yet', async () => {
|
|
|
336
427
|
assert.ok(!treeText(loadedRun.tree).includes('firstRunTitle'), 'the first-run card must disappear once a library exists')
|
|
337
428
|
})
|
|
338
429
|
|
|
339
|
-
//
|
|
340
|
-
//
|
|
341
|
-
// 落定后再渲染展开一次。注意最终树只能展开一次——walkNodes 和 treeText 各展开
|
|
342
|
-
// 一遍会让第二次跑在错位的 hook 游标上,读出空状态。
|
|
430
|
+
// Expand the current relations entry once: running nested components twice
|
|
431
|
+
// would consume this minimal renderer's shared hook cursor twice.
|
|
343
432
|
function walkAndText(node, sink, depth = 0) {
|
|
344
433
|
if (node === null || node === undefined || depth > 400) return ''
|
|
345
434
|
if (typeof node === 'string' || typeof node === 'number') return String(node)
|
|
346
435
|
if (Array.isArray(node)) return node.map((child) => walkAndText(child, sink, depth + 1)).join(' ')
|
|
347
436
|
if (typeof node.type === 'function') return walkAndText(node.type(node.props), sink, depth + 1)
|
|
348
|
-
|
|
437
|
+
sink.push(node)
|
|
349
438
|
return `${node.props?.className || ''} ${walkAndText(node.props?.children, sink, depth + 1)}`
|
|
350
439
|
}
|
|
351
440
|
|
|
@@ -364,53 +453,38 @@ async function relationsTree(component, props, pageHook, viewIndex) {
|
|
|
364
453
|
cursor = 0
|
|
365
454
|
forcedList = forced
|
|
366
455
|
const tree = component(props)
|
|
367
|
-
const
|
|
368
|
-
const text = walkAndText(tree,
|
|
369
|
-
return { text,
|
|
456
|
+
const controls = []
|
|
457
|
+
const text = walkAndText(tree, controls)
|
|
458
|
+
return { text, controls }
|
|
370
459
|
}
|
|
371
460
|
|
|
372
|
-
test('
|
|
461
|
+
test('relations routes to the unified studio without mounting the legacy full entity panel', async t => {
|
|
462
|
+
const previousHash = window.location.hash
|
|
463
|
+
t.after(() => { window.location.hash = previousHash })
|
|
464
|
+
window.location.hash = '#/settings/engine'
|
|
373
465
|
const loaded = { ...EMPTY_STATE, libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 0 }] }
|
|
374
466
|
const component = settingsComponent()
|
|
375
|
-
const props = { ctx: fakeCtx({
|
|
467
|
+
const props = { standalone: true, ctx: fakeCtx({
|
|
376
468
|
getState: loaded,
|
|
377
469
|
getSettingsState: loaded,
|
|
378
|
-
listEntities: {
|
|
379
|
-
items: [
|
|
380
|
-
{ id: 'ent-linked', name: 'Linked', kind: 'person', aliases: [], linked: true },
|
|
381
|
-
{ id: 'ent-ghost', name: 'Ghost', kind: 'person', aliases: [], linked: false },
|
|
382
|
-
],
|
|
383
|
-
total: 2,
|
|
384
|
-
},
|
|
470
|
+
listEntities: () => { throw new Error('the relations entry must not load every entity') },
|
|
385
471
|
}), t: (key) => key }
|
|
386
472
|
|
|
473
|
+
rpcCalls.length = 0
|
|
387
474
|
await mountAndSettle(component, props)
|
|
388
475
|
collectPageHook()
|
|
389
476
|
const activeIndexes = hooks.map((value, index) => (value === 'active' ? index : -1)).filter((index) => index >= 0)
|
|
390
477
|
assert.equal(activeIndexes.length, 1, 'expected exactly one "active" state (the browser view)')
|
|
391
|
-
const { text,
|
|
392
|
-
assert.
|
|
393
|
-
|
|
394
|
-
assert.
|
|
395
|
-
assert.
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
assert.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
collectPageHook()
|
|
404
|
-
const cleanIndexes = hooks.map((value, index) => (value === 'active' ? index : -1)).filter((index) => index >= 0)
|
|
405
|
-
assert.equal(cleanIndexes.length, 1)
|
|
406
|
-
const clean = await relationsTree(component, cleanProps, pageHookIndex, cleanIndexes[0])
|
|
407
|
-
assert.equal(clean.orphanDetails.length, 0, 'no orphan group may render when every entity is linked')
|
|
408
|
-
|
|
409
|
-
const noneProps = { ctx: fakeCtx({ getState: loaded, getSettingsState: loaded, listEntities: { items: [], total: 0 } }), t: (key) => key }
|
|
410
|
-
await mountAndSettle(component, noneProps)
|
|
411
|
-
collectPageHook()
|
|
412
|
-
const noneIndexes = hooks.map((value, index) => (value === 'active' ? index : -1)).filter((index) => index >= 0)
|
|
413
|
-
assert.equal(noneIndexes.length, 1)
|
|
414
|
-
const none = await relationsTree(component, noneProps, pageHookIndex, noneIndexes[0])
|
|
415
|
-
assert.match(none.text, /entityEmpty/, 'an empty entity list shows the empty state')
|
|
478
|
+
const { text, controls } = await relationsTree(component, props, pageHookIndex, activeIndexes[0])
|
|
479
|
+
assert.match(text, /openGraphStudio/, 'the unified management entry is visible')
|
|
480
|
+
assert.match(text, /demo/, 'the selected library is named before navigation')
|
|
481
|
+
assert.doesNotMatch(text, /dshm-graph-orphans|entityDelete|entityEmpty/, 'legacy full entity forms must not remain reachable')
|
|
482
|
+
assert.deepEqual(rpcCalls.filter(row => ['listEntities', 'getAnchorCandidates', 'suggestEntityMerges', 'getGraph'].includes(row.endpoint)), [],
|
|
483
|
+
'merely opening relations must not start entity, candidate, anchor or graph scans')
|
|
484
|
+
const open = controls.find(node => node.type === 'button' && node.props?.title === 'openGraphStudioHint')
|
|
485
|
+
assert.ok(open && !open.props.disabled, 'the graph navigation action is enabled')
|
|
486
|
+
open.props.onClick()
|
|
487
|
+
assert.equal(hooks[pageHookIndex], 10, 'standalone navigation selects the actual graph page')
|
|
488
|
+
// Discovery and confirmed deletion of unlinked entities are covered through
|
|
489
|
+
// the reachable bounded GraphStudio manager in client-pagination.test.mjs.
|
|
416
490
|
})
|
package/tests/inbound.test.mjs
CHANGED
|
@@ -185,6 +185,25 @@ test('normal first-step input is acknowledged and not replayed as an external ba
|
|
|
185
185
|
assert.deepEqual((await continueStep(f)).messages, [])
|
|
186
186
|
})
|
|
187
187
|
|
|
188
|
+
test('native admission compares canonical attachment fields while rejecting a changed body', () => {
|
|
189
|
+
const f = fixture('canonical-native')
|
|
190
|
+
const human = { id: 'canonical-image', role: 'user', source: { kind: 'user' }, content: [
|
|
191
|
+
{ type: 'text', text: '部署脚本截图' },
|
|
192
|
+
{ type: 'image', attachment: { name: 'screenshot', height: 8, bytes: 20, width: 8, mediaType: 'image/png', attachmentId: 'image-ref' } },
|
|
193
|
+
] }
|
|
194
|
+
inbound.ingestInboundBatch({ sessionId: f.id, batch: { type: inbound.INBOUND_TYPE, version: 1,
|
|
195
|
+
producer: 'host.user', batchId: 'canonical-batch', messages: [inbound.nativeInboundMessage(human)] } })
|
|
196
|
+
const changed = structuredClone(human)
|
|
197
|
+
changed.content[0].text = 'another message'
|
|
198
|
+
assert.equal(inbound.selectRecallableInbound(state.getSessionBinding(f.id), [changed]).length, 0)
|
|
199
|
+
assert.equal(inbound.selectRecallableInbound(state.getSessionBinding(f.id), [human]).length, 1)
|
|
200
|
+
inbound.noteNativeUserMessages(f.id, [changed], { admitted: true })
|
|
201
|
+
assert.equal(state.getSessionBinding(f.id).inbound.pending[0].nativeAdmitted, undefined)
|
|
202
|
+
inbound.noteNativeUserMessages(f.id, [human], { admitted: true })
|
|
203
|
+
assert.equal(state.getSessionBinding(f.id).inbound.pending[0].nativeAdmitted, true)
|
|
204
|
+
assert.equal(inbound.selectRecallableInbound(state.getSessionBinding(f.id)).length, 1)
|
|
205
|
+
})
|
|
206
|
+
|
|
188
207
|
test('continuation image references are saved and disclosed before the next model step without fabricating a user event', async () => {
|
|
189
208
|
const f = fixture('image')
|
|
190
209
|
const data = await sharp({ create: { width: 16, height: 16, channels: 3, background: '#48996e' } }).png().toBuffer()
|
|
@@ -0,0 +1,113 @@
|
|
|
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-index-pages-'))
|
|
8
|
+
process.env.DSH_MEMU_HOME = home
|
|
9
|
+
const state = await import('../lib/state.js')
|
|
10
|
+
const memory = await import('../lib/memory.js')
|
|
11
|
+
const { dispatch } = await import('../lib/rpc.js')
|
|
12
|
+
|
|
13
|
+
test.after(() => {
|
|
14
|
+
state.flushState()
|
|
15
|
+
fs.rmSync(home, { recursive: true, force: true })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
let sequence = 0
|
|
19
|
+
function fixture(count = 7) {
|
|
20
|
+
const cwd = path.join(home, 'library-' + sequence++)
|
|
21
|
+
const library = state.createLibrary({ name: 'pages', cwd })
|
|
22
|
+
const entries = {}
|
|
23
|
+
for (let i = count - 1; i >= 0; i--) entries[`mem-page-${i}`] = {
|
|
24
|
+
title: `item ${i}`, content: `body ${i}`, domain: i % 2 ? 'coding' : 'general',
|
|
25
|
+
status: 'active', visibility: 'shared', layer: 'long_term',
|
|
26
|
+
createdAt: '2026-11-01T00:00:00.000Z', updatedAt: '2026-11-02T00:00:00.000Z',
|
|
27
|
+
}
|
|
28
|
+
state.savePrivateIndex(library.id, { version: 1, entries })
|
|
29
|
+
return { library, cwd }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test('wall snapshot pages have deterministic ties and no missing or duplicated ids', async () => {
|
|
33
|
+
const { library } = fixture()
|
|
34
|
+
let offset = 0
|
|
35
|
+
let snapshotRevision
|
|
36
|
+
const ids = []
|
|
37
|
+
do {
|
|
38
|
+
const page = await dispatch({}, 'browseWall', { libraryId: library.id, limit: 2, offset, snapshotRevision })
|
|
39
|
+
assert.equal(page.total, 7)
|
|
40
|
+
assert.equal(typeof page.snapshotRevision, 'string')
|
|
41
|
+
snapshotRevision = page.snapshotRevision
|
|
42
|
+
ids.push(...page.items.map(item => item.id))
|
|
43
|
+
offset += page.items.length
|
|
44
|
+
} while (offset < 7)
|
|
45
|
+
assert.deepEqual(ids, Array.from({ length: 7 }, (_, i) => `mem-page-${i}`))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('a write between wall pages rejects the old snapshot instead of shifting offsets', async () => {
|
|
49
|
+
const { library } = fixture()
|
|
50
|
+
const first = await dispatch({}, 'browseWall', { libraryId: library.id, limit: 2 })
|
|
51
|
+
const index = state.loadPrivateIndex(library.id)
|
|
52
|
+
index.entries['mem-page-1'].updatedAt = '2026-11-03T00:00:00.000Z'
|
|
53
|
+
state.savePrivateIndex(library.id, index)
|
|
54
|
+
await assert.rejects(dispatch({}, 'browseWall', { libraryId: library.id, limit: 2, offset: 2, snapshotRevision: first.snapshotRevision }), { code: 'MEMORY_CHANGED' })
|
|
55
|
+
const restarted = await dispatch({}, 'browseWall', { libraryId: library.id, limit: 2 })
|
|
56
|
+
assert.equal(restarted.items[0].id, 'mem-page-1')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('private list and RPC browser slice before hydration, and keep the full total', async () => {
|
|
60
|
+
const { library } = fixture()
|
|
61
|
+
const first = await memory.privateList({ libraryId: library.id, preferIndex: true, limit: 2 })
|
|
62
|
+
assert.equal(first.total, 7)
|
|
63
|
+
const second = await dispatch({}, 'browseLibrary', { libraryId: library.id, limit: 2, offset: 2, snapshotRevision: first.snapshotRevision })
|
|
64
|
+
assert.equal(second.total, 7)
|
|
65
|
+
assert.deepEqual(second.files.map(file => file.id), ['mem-page-2', 'mem-page-3'])
|
|
66
|
+
assert.deepEqual(first.files.map(file => file.name), ['mem-page-0', 'mem-page-1'])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('domain counts list all domains and filtering happens before paging', async () => {
|
|
70
|
+
const { library } = fixture()
|
|
71
|
+
const page = await dispatch({}, 'browseWall', { libraryId: library.id, limit: 2, domain: ' CODING ' })
|
|
72
|
+
assert.equal(page.total, 3)
|
|
73
|
+
assert.deepEqual(page.items.map(item => item.id), ['mem-page-1', 'mem-page-3'])
|
|
74
|
+
assert.deepEqual(page.domains, ['coding', 'general'])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('wall search accepts an exact memory id before pagination', async () => {
|
|
78
|
+
const { library } = fixture()
|
|
79
|
+
const page = await dispatch({}, 'browseWall', { libraryId: library.id, limit: 2, query: 'MEM-PAGE-4' })
|
|
80
|
+
assert.equal(page.total, 1)
|
|
81
|
+
assert.deepEqual(page.items.map(item => item.id), ['mem-page-4'])
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('session/context changes invalidate list snapshots and cannot reuse another visibility set', async () => {
|
|
85
|
+
const { library, cwd } = fixture(3)
|
|
86
|
+
state.ensureSession('page-character', { cwd, libraryId: library.id })
|
|
87
|
+
const index = state.loadPrivateIndex(library.id)
|
|
88
|
+
index.entries['mem-page-0'].context = { characterId: 'alice' }
|
|
89
|
+
state.savePrivateIndex(library.id, index)
|
|
90
|
+
state.setSessionBinding('page-character', { memoryContext: { characterId: 'alice' } })
|
|
91
|
+
const exec = { agent: { session: { header: { id: 'page-character' } } } }
|
|
92
|
+
const first = await memory.privateList({ exec, preferIndex: true, limit: 1 })
|
|
93
|
+
assert.equal(first.total, 3)
|
|
94
|
+
state.setSessionBinding('page-character', { memoryContext: { characterId: 'bob' } })
|
|
95
|
+
await assert.rejects(memory.privateList({ exec, preferIndex: true, limit: 1, offset: 1, snapshotRevision: first.snapshotRevision }), { code: 'MEMORY_CHANGED' })
|
|
96
|
+
const changed = await memory.privateList({ exec, preferIndex: true, limit: 3 })
|
|
97
|
+
assert.equal(changed.total, 2)
|
|
98
|
+
assert.ok(changed.files.every(file => file.name !== 'mem-page-0'))
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('global list pages use the same revision guard', async () => {
|
|
102
|
+
const entries = Object.fromEntries([0, 1, 2].map(i => [`gmem-page-${i}`, {
|
|
103
|
+
title: `global ${i}`, content: 'global body', domain: 'universal', status: 'active',
|
|
104
|
+
createdAt: '2026-11-01T00:00:00.000Z',
|
|
105
|
+
}]))
|
|
106
|
+
state.saveGlobalIndex({ version: 1, entries })
|
|
107
|
+
const first = await dispatch({}, 'listGlobal', { limit: 1 })
|
|
108
|
+
assert.equal(first.total, 3)
|
|
109
|
+
const second = await dispatch({}, 'listGlobal', { limit: 1, offset: 1, snapshotRevision: first.snapshotRevision })
|
|
110
|
+
assert.deepEqual(second.files.map(file => file.id), ['gmem-page-1'])
|
|
111
|
+
state.saveGlobalIndex({ version: 1, entries: {} })
|
|
112
|
+
await assert.rejects(dispatch({}, 'listGlobal', { limit: 1, offset: 2, snapshotRevision: first.snapshotRevision }), { code: 'MEMORY_CHANGED' })
|
|
113
|
+
})
|
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
import { createBoundedCache, cacheDiagnostics, estimateBytes } from '../lib/bounded-cache.js'
|
|
7
|
+
|
|
8
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-p1-'))
|
|
9
|
+
process.env.DSH_MEMU_HOME = home
|
|
10
|
+
const state = await import('../lib/state.js')
|
|
11
|
+
const paths = await import('../lib/paths.js')
|
|
12
|
+
const memory = await import('../lib/memory.js')
|
|
13
|
+
test.after(() => fs.rmSync(home, { recursive: true, force: true }))
|
|
14
|
+
|
|
15
|
+
function fixture(suffix, entries = {}) {
|
|
16
|
+
const lib = state.createLibrary({ name: suffix, cwd: path.join(home, suffix) })
|
|
17
|
+
state.savePrivateIndex(lib.id, { version: 1, entries })
|
|
18
|
+
return lib
|
|
19
|
+
}
|
|
20
|
+
const entry = (title = '海边约定') => ({ title, content: '我们下周一起去海边看星星。', status: 'active', layer: 'long_term', visibility: 'shared', createdAt: '2026-11-01T00:00:00Z', updatedAt: '2026-11-01T00:00:00Z' })
|
|
21
|
+
|
|
22
|
+
test('bounded LRU accounts Map/Set bytes, evicts by bytes and expires without sliding TTL', () => {
|
|
23
|
+
assert.ok(estimateBytes(new Map([['x', new Set(['retained value'])]])) > estimateBytes(new Map()))
|
|
24
|
+
assert.ok(estimateBytes(new Uint8Array(4096)) >= 4096)
|
|
25
|
+
const cyclic = {}
|
|
26
|
+
cyclic.self = cyclic
|
|
27
|
+
assert.ok(Number.isFinite(estimateBytes(cyclic)))
|
|
28
|
+
let now = 100
|
|
29
|
+
const cache = createBoundedCache({ maxBytes: 300, maxEntries: 5, ttlMs: 10, now: () => now, sizeOf: () => 100 })
|
|
30
|
+
cache.set('a', new Map([['x', new Set([1, 2])]]))
|
|
31
|
+
cache.set('b', 2)
|
|
32
|
+
cache.get('a')
|
|
33
|
+
cache.set('c', 3)
|
|
34
|
+
assert.equal(cache.get('b'), undefined)
|
|
35
|
+
assert.equal(cache.stats().evictions, 1)
|
|
36
|
+
now = 110
|
|
37
|
+
assert.equal(cache.get('a'), undefined)
|
|
38
|
+
assert.equal(cache.stats().expirations, 1)
|
|
39
|
+
assert.ok(cache.stats().bytes <= cache.stats().maxBytes)
|
|
40
|
+
cache.set('huge', 'x')
|
|
41
|
+
const tiny = createBoundedCache({ maxBytes: 1 })
|
|
42
|
+
tiny.set('a', 1)
|
|
43
|
+
assert.equal(tiny.stats().oversized, 1)
|
|
44
|
+
assert.equal(tiny.size, 0)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('read-only snapshots share frozen identity but mutable loads and public results remain isolated', async () => {
|
|
48
|
+
const lib = fixture('views', { 'mem-view': entry() })
|
|
49
|
+
const first = state.readPrivateIndex(lib.id)
|
|
50
|
+
assert.equal(first, state.readPrivateIndex(lib.id))
|
|
51
|
+
assert.ok(Object.isFrozen(first.entries['mem-view']))
|
|
52
|
+
assert.throws(() => { first.entries['mem-view'].title = 'bad' }, TypeError)
|
|
53
|
+
assert.throws(() => state.savePrivateIndex(lib.id, first), /read-only/)
|
|
54
|
+
const mutable = state.loadPrivateIndex(lib.id)
|
|
55
|
+
mutable.entries['mem-view'].title = 'edited'
|
|
56
|
+
assert.equal(first.entries['mem-view'].title, '海边约定')
|
|
57
|
+
state.savePrivateIndex(lib.id, mutable)
|
|
58
|
+
assert.equal(state.readPrivateIndex(lib.id).entries['mem-view'].title, 'edited')
|
|
59
|
+
const list = await memory.privateList({ libraryId: lib.id, preferIndex: true, limit: 1 })
|
|
60
|
+
list.files[0].entry.title = 'consumer mutation'
|
|
61
|
+
assert.equal(state.readPrivateIndex(lib.id).entries['mem-view'].title, 'edited')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('view normalization never rewrites real data; ordinary writes still persist legacy upgrades', () => {
|
|
65
|
+
const lib = fixture('legacy')
|
|
66
|
+
const file = path.join(paths.indexDir(), lib.id + '.json')
|
|
67
|
+
paths.writeJson(file, { version: 1, entries: { 'mem-old': { ...entry(), visibility: 'session', sessionId: 'old' } } })
|
|
68
|
+
const before = fs.readFileSync(file, 'utf8')
|
|
69
|
+
assert.equal(state.readPrivateIndex(lib.id).entries['mem-old'].visibility, 'shared')
|
|
70
|
+
assert.equal(fs.readFileSync(file, 'utf8'), before)
|
|
71
|
+
const mutable = state.loadPrivateIndex(lib.id)
|
|
72
|
+
state.savePrivateIndex(lib.id, mutable)
|
|
73
|
+
assert.equal(JSON.parse(fs.readFileSync(file, 'utf8')).entries['mem-old'].visibility, 'shared')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('read revisions change on same-timestamp content/tag/context writes, not injection observations', () => {
|
|
77
|
+
const lib = fixture('revisions', { 'mem-rev': entry() })
|
|
78
|
+
const revision = () => state.indexReadRevision(state.readPrivateIndex(lib.id))
|
|
79
|
+
const original = revision()
|
|
80
|
+
state.updatePrivateIndex(lib.id, index => { index.entries['mem-rev'].injectCount = 1 })
|
|
81
|
+
assert.equal(revision(), original)
|
|
82
|
+
state.updatePrivateIndex(lib.id, index => { index.entries['mem-rev'].tags = ['new token'] })
|
|
83
|
+
assert.notEqual(revision(), original)
|
|
84
|
+
const tags = revision()
|
|
85
|
+
state.updatePrivateIndex(lib.id, index => { index.entries['mem-rev'].context = { characterId: 'hero' } })
|
|
86
|
+
assert.notEqual(revision(), tags)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('same-row concurrent changes still reject while independent rows merge', () => {
|
|
90
|
+
const lib = fixture('concurrent', { 'mem-a': entry('a'), 'mem-b': entry('b') })
|
|
91
|
+
const left = state.loadPrivateIndex(lib.id)
|
|
92
|
+
const right = state.loadPrivateIndex(lib.id)
|
|
93
|
+
left.entries['mem-a'].title = 'left'
|
|
94
|
+
right.entries['mem-b'].title = 'right'
|
|
95
|
+
state.savePrivateIndex(lib.id, left)
|
|
96
|
+
state.savePrivateIndex(lib.id, right)
|
|
97
|
+
assert.equal(state.readPrivateIndex(lib.id).entries['mem-a'].title, 'left')
|
|
98
|
+
const stale = state.loadPrivateIndex(lib.id)
|
|
99
|
+
state.updatePrivateIndex(lib.id, index => { index.entries['mem-a'].title = 'fresh' })
|
|
100
|
+
stale.entries['mem-a'].title = 'stale'
|
|
101
|
+
assert.throws(() => state.savePrivateIndex(lib.id, stale), { code: 'DSH_MEMU_CONCURRENT_MODIFICATION' })
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('COW=0 returns isolated mutable read snapshots and preserves write baseline safety', () => {
|
|
105
|
+
const lib = fixture('fallback', { 'mem-fallback': entry() })
|
|
106
|
+
const previous = process.env.DSH_MEMU_INDEX_COW
|
|
107
|
+
process.env.DSH_MEMU_INDEX_COW = '0'
|
|
108
|
+
try {
|
|
109
|
+
const view = state.readPrivateIndex(lib.id)
|
|
110
|
+
assert.ok(!Object.isFrozen(view))
|
|
111
|
+
view.entries['mem-fallback'].title = 'fallback edit'
|
|
112
|
+
assert.notEqual(state.readPrivateIndex(lib.id).entries['mem-fallback'].title, 'fallback edit')
|
|
113
|
+
state.savePrivateIndex(lib.id, view)
|
|
114
|
+
assert.equal(state.readPrivateIndex(lib.id).entries['mem-fallback'].title, 'fallback edit')
|
|
115
|
+
} finally {
|
|
116
|
+
if (previous === undefined) delete process.env.DSH_MEMU_INDEX_COW
|
|
117
|
+
else process.env.DSH_MEMU_INDEX_COW = previous
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('decay derived cache notices in-place edits and time buckets without mutating facts or expiry gate', () => {
|
|
122
|
+
const originalNow = Date.now
|
|
123
|
+
let now = Date.parse('2026-11-20T12:10:00Z')
|
|
124
|
+
Date.now = () => now
|
|
125
|
+
try {
|
|
126
|
+
const row = { ...entry(), strength: 0.8, expiresAt: '2026-11-20T12:10:01Z' }
|
|
127
|
+
const before = structuredClone(row)
|
|
128
|
+
const first = memory.decayStrength(row)
|
|
129
|
+
now += 500
|
|
130
|
+
assert.equal(memory.decayStrength(row), first)
|
|
131
|
+
row.strength = 0.4
|
|
132
|
+
assert.ok(memory.decayStrength(row) < first)
|
|
133
|
+
now += 1000
|
|
134
|
+
assert.equal(memory.isMemoryEligible(row), false)
|
|
135
|
+
row.strength = before.strength
|
|
136
|
+
now += 3_600_000
|
|
137
|
+
assert.ok(memory.decayStrength(row) < first)
|
|
138
|
+
delete before.expiresAt
|
|
139
|
+
assert.equal(row.updatedAt, before.updatedAt)
|
|
140
|
+
assert.ok(!Object.hasOwn(row, 'strengthAt'))
|
|
141
|
+
const undated = { strength: 0.8 }
|
|
142
|
+
const undatedStrength = memory.decayStrength(undated)
|
|
143
|
+
now += 7_200_000
|
|
144
|
+
assert.equal(memory.decayStrength(undated), undatedStrength, 'an invalid or absent date keeps the original no-age fallback')
|
|
145
|
+
} finally { Date.now = originalNow }
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('corpus cache stays separate across equal-sized character bindings and sceneTime', async () => {
|
|
149
|
+
const rows = { 'mem-needle': { ...entry('zqneedle'), content: 'zqneedle' } }
|
|
150
|
+
for (let i = 0; i < 7; i++) {
|
|
151
|
+
rows[`mem-alpha-${i}`] = { ...entry('unrelated' + i), context: { characterId: 'alpha' } }
|
|
152
|
+
rows[`mem-beta-${i}`] = { ...entry('zqneedle'), content: 'zqneedle', context: { characterId: 'beta' } }
|
|
153
|
+
}
|
|
154
|
+
const lib = fixture('bindings', rows)
|
|
155
|
+
state.ensureSession('p1-bindings', { cwd: lib.scopeKey })
|
|
156
|
+
state.setSessionBinding('p1-bindings', { libraryId: lib.id, memoryContext: { characterId: 'alpha' } })
|
|
157
|
+
const exec = { agent: { session: { header: { id: 'p1-bindings' } } } }
|
|
158
|
+
const query = () => memory.privateRecall({ exec, query: 'zqneedle', relevanceThreshold: 0, purpose: 'automatic', topK: 5 })
|
|
159
|
+
const before = await query()
|
|
160
|
+
assert.deepEqual(before.files.map(file => file.name), ['mem-needle'])
|
|
161
|
+
state.setSessionBinding('p1-bindings', { memoryContext: { characterId: 'beta' }, sceneTime: '2027-01-01T00:00:00Z' })
|
|
162
|
+
const other = await query()
|
|
163
|
+
assert.deepEqual(other.files.map(file => file.name), ['mem-needle'], 'near-duplicate beta hits fold into their canonical row')
|
|
164
|
+
assert.ok(other.files[0].lexical < before.files[0].lexical, 'beta uses its own higher document frequency rather than the equal-sized alpha cache')
|
|
165
|
+
state.setSessionBinding('p1-bindings', { memoryContext: { characterId: 'alpha' }, sceneTime: '2027-01-02T00:00:00Z' })
|
|
166
|
+
const restored = await query()
|
|
167
|
+
assert.deepEqual(restored.files.map(file => file.name), ['mem-needle'])
|
|
168
|
+
assert.equal(restored.files[0].lexical, before.files[0].lexical)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
test('revision keys observe exact expiry and valid-window days without any index write', () => {
|
|
172
|
+
const originalNow = Date.now
|
|
173
|
+
let now = new Date(2026, 10, 20, 23, 59, 59, 0).getTime()
|
|
174
|
+
Date.now = () => now
|
|
175
|
+
try {
|
|
176
|
+
const lib = fixture('time-key', { 'mem-time': { ...entry(), expiresAt: new Date(now + 500).toISOString(), valid_to: '2026-11-20' } })
|
|
177
|
+
const view = state.readPrivateIndex(lib.id)
|
|
178
|
+
const first = state.indexReadRevision(view)
|
|
179
|
+
now += 499
|
|
180
|
+
assert.equal(state.indexReadRevision(view), first)
|
|
181
|
+
now += 1
|
|
182
|
+
const expired = state.indexReadRevision(view)
|
|
183
|
+
assert.notEqual(expired, first)
|
|
184
|
+
now += 500
|
|
185
|
+
assert.notEqual(state.indexReadRevision(view), expired)
|
|
186
|
+
} finally { Date.now = originalNow }
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('global hidden/context entries are filtered before corpus statistics and output mutations stay isolated', async () => {
|
|
190
|
+
const rows = { 'gmem-p1-needle': { ...entry('zqglobal'), content: 'zqglobal', domain: 'general' } }
|
|
191
|
+
for (let i = 0; i < 7; i++) rows[`gmem-p1-filler-${i}`] = { ...entry('unrelated' + i), domain: 'general' }
|
|
192
|
+
state.saveGlobalIndex({ entries: rows })
|
|
193
|
+
const recall = () => memory.globalRecall({ query: 'zqglobal', relevanceThreshold: 0, topK: 5 })
|
|
194
|
+
const before = await recall()
|
|
195
|
+
assert.deepEqual(before.files.map(file => file.name), ['gmem-p1-needle'])
|
|
196
|
+
for (let i = 0; i < 12; i++) rows[`gmem-p1-hidden-${i}`] = { ...entry('zqglobal'), content: 'zqglobal', domain: 'general', context: { characterId: 'hidden' } }
|
|
197
|
+
state.saveGlobalIndex({ entries: rows })
|
|
198
|
+
const after = await recall()
|
|
199
|
+
assert.deepEqual(after.files.map(file => file.name), ['gmem-p1-needle'])
|
|
200
|
+
assert.equal(after.files[0].lexical, before.files[0].lexical)
|
|
201
|
+
after.files[0].entry.content = 'consumer mutation'
|
|
202
|
+
assert.equal(state.readGlobalIndex().entries['gmem-p1-needle'].content, 'zqglobal')
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('cache diagnostics contain bounded counts and no titles, ids or bodies', () => {
|
|
206
|
+
const diagnostic = cacheDiagnostics()
|
|
207
|
+
for (const name of ['index', 'lexicalCorpus', 'recall']) {
|
|
208
|
+
assert.ok(diagnostic[name].maxBytes > 0)
|
|
209
|
+
assert.ok(diagnostic[name].bytes <= diagnostic[name].maxBytes)
|
|
210
|
+
}
|
|
211
|
+
assert.ok(!JSON.stringify(diagnostic).includes('mem-view'))
|
|
212
|
+
})
|