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
|
@@ -10,6 +10,7 @@ import path from 'node:path'
|
|
|
10
10
|
|
|
11
11
|
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-graph-cascade-'))
|
|
12
12
|
process.env.DSH_MEMU_HOME = home
|
|
13
|
+
process.env.DSH_MEMU_MEMORY_HOME = home
|
|
13
14
|
const state = await import('../lib/state.js')
|
|
14
15
|
const graph = await import('../lib/graph.js')
|
|
15
16
|
const memory = await import('../lib/memory.js')
|
|
@@ -263,6 +264,102 @@ const repairLibrary = (name, entries, entities) => {
|
|
|
263
264
|
}
|
|
264
265
|
const scene = (title, content) => ({ title, content, status: 'active', visibility: 'shared', layer: 'long_term' })
|
|
265
266
|
|
|
267
|
+
test('repair defers above 256 entity rows before any corpus, pair or name work', () => {
|
|
268
|
+
let exports = 0
|
|
269
|
+
const entities = Object.fromEntries(Array.from({ length: 257 }, (_, i) => {
|
|
270
|
+
const id = `ent-budget-${i}`
|
|
271
|
+
return [id, { id, status: i < 255 ? 'archived' : 'confirmed', kind: 'person',
|
|
272
|
+
get name() { assert.fail('large plans must not normalize or reconstruct a name') } }]
|
|
273
|
+
}))
|
|
274
|
+
const plan = repair.planLibraryRepair('large', { graph: {
|
|
275
|
+
graphExport(id) { exports++; assert.equal(id, 'large'); return { entities } },
|
|
276
|
+
listEntities() { assert.fail('the linked listing would read the corpus') },
|
|
277
|
+
suggestEntityMerges() { assert.fail('large plans must not request pair comparisons') },
|
|
278
|
+
}, loadPrivateIndex() { assert.fail('large plans must not load the corpus') } })
|
|
279
|
+
assert.equal(exports, 1)
|
|
280
|
+
assert.deepEqual(plan, { libraryId: 'large', groups: [], ambiguous: [], totalEntities: 257,
|
|
281
|
+
entityLimit: 256, scanned: 0, partial: true, deferred: true, reason: 'entity-limit' })
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
test('repair accepts exactly 256 rows and retains the injected listing contract', () => {
|
|
285
|
+
let corpusReads = 0, candidateReads = 0
|
|
286
|
+
const items = Array.from({ length: 256 }, (_, i) => ({ id: `ent-boundary-${i}`,
|
|
287
|
+
name: `entity-${String(i).padStart(3, '0')}`, kind: 'thing', status: 'confirmed' }))
|
|
288
|
+
const plan = repair.planLibraryRepair('boundary', { graph: {
|
|
289
|
+
listEntities: () => ({ items }),
|
|
290
|
+
suggestEntityMerges() { candidateReads++; return { items: [] } },
|
|
291
|
+
}, loadPrivateIndex() { corpusReads++; return { entries: {} } } })
|
|
292
|
+
assert.equal(plan.totalEntities, 256)
|
|
293
|
+
assert.equal(plan.scanned, 256)
|
|
294
|
+
assert.equal(plan.partial, false)
|
|
295
|
+
assert.equal(plan.deferred, false)
|
|
296
|
+
assert.equal(corpusReads, 1)
|
|
297
|
+
assert.equal(candidateReads, 1)
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
test('an incomplete merge-candidate batch defers proof instead of reading the corpus', () => {
|
|
301
|
+
const items = [{ id: 'ent-fragment-a', name: '南宫晚', kind: 'person' },
|
|
302
|
+
{ id: 'ent-fragment-b', name: '宫晚晴', kind: 'person' }]
|
|
303
|
+
const plan = repair.planLibraryRepair('candidate-partial', { graph: {
|
|
304
|
+
listEntities: () => ({ items }),
|
|
305
|
+
suggestEntityMerges: () => ({ items: [{ sourceId: items[0].id, targetId: items[1].id }],
|
|
306
|
+
scanComplete: false, totalExact: false, nextCursor: 'opaque-next-batch' }),
|
|
307
|
+
}, loadPrivateIndex() { assert.fail('an incomplete candidate batch cannot authorize corpus proof') } })
|
|
308
|
+
assert.equal(plan.reason, 'candidate-scan-incomplete')
|
|
309
|
+
assert.equal(plan.partial, true)
|
|
310
|
+
assert.equal(plan.deferred, true)
|
|
311
|
+
assert.equal(plan.scanned, 0)
|
|
312
|
+
assert.deepEqual(plan.groups, [])
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('a corpus above the proof cap is deferred without reading partial memory bodies', () => {
|
|
316
|
+
const entries = Object.fromEntries(Array.from({ length: 3001 }, (_, i) => [i, {
|
|
317
|
+
get content() { assert.fail('a truncated corpus must not be turned into proof') },
|
|
318
|
+
}]))
|
|
319
|
+
const plan = repair.planLibraryRepair('corpus-partial', { graph: {
|
|
320
|
+
listEntities: () => ({ items: [{ id: 'ent-a', name: '化学', kind: 'thing' },
|
|
321
|
+
{ id: 'ent-b', name: '化学式', kind: 'thing' }] }),
|
|
322
|
+
suggestEntityMerges: () => ({ items: [] }),
|
|
323
|
+
}, loadPrivateIndex: () => ({ entries }) })
|
|
324
|
+
assert.equal(plan.reason, 'corpus-limit')
|
|
325
|
+
assert.equal(plan.partial, true)
|
|
326
|
+
assert.equal(plan.deferred, true)
|
|
327
|
+
assert.deepEqual(plan.groups, [])
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
test('overlap reconstruction has both a member cap and a recursive work cap', () => {
|
|
331
|
+
for (const count of [9, 7]) {
|
|
332
|
+
const items = Array.from({ length: count }, (_, i) => ({ id: `ent-overlap-${i}`, name: `a${i}a`, kind: 'person' }))
|
|
333
|
+
const plan = repair.planLibraryRepair(`overlap-${count}`, { graph: {
|
|
334
|
+
listEntities: () => ({ items }),
|
|
335
|
+
suggestEntityMerges: () => ({ items: items.slice(1).map((row, i) => ({ sourceId: items[i].id, targetId: row.id })) }),
|
|
336
|
+
}, loadPrivateIndex: () => ({ entries: {} }) })
|
|
337
|
+
assert.equal(plan.reason, 'rebuild-limit', `${count} overlapping names must have bounded reconstruction`)
|
|
338
|
+
assert.equal(plan.partial, true)
|
|
339
|
+
assert.equal(plan.deferred, true)
|
|
340
|
+
assert.deepEqual(plan.groups, [])
|
|
341
|
+
}
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
test('all-library repair preserves deferred and unreadable plans instead of reporting a clean aggregate', () => {
|
|
345
|
+
const items = Array.from({ length: 257 }, (_, i) => ({ id: `ent-deferred-${i}` }))
|
|
346
|
+
const plan = repair.planAllRepairs({
|
|
347
|
+
listLibraries: () => [{ id: 'large' }, { id: 'broken' }, { id: 'archived', archivedAt: '2026-01-01' }],
|
|
348
|
+
graph: { listEntities({ libraryId: id }) { if (id === 'broken') throw new Error('unreadable entity fixture'); return { items } },
|
|
349
|
+
suggestEntityMerges() { assert.fail('no heavy comparisons for deferred or unreadable libraries') } },
|
|
350
|
+
loadPrivateIndex() { assert.fail('no corpus read for deferred or unreadable libraries') },
|
|
351
|
+
})
|
|
352
|
+
assert.equal(plan.plans.length, 1)
|
|
353
|
+
assert.equal(plan.failures.length, 1)
|
|
354
|
+
assert.equal(plan.partial, true)
|
|
355
|
+
assert.equal(plan.deferred, true)
|
|
356
|
+
assert.equal(plan.totalEntities, 257)
|
|
357
|
+
assert.equal(plan.totalEntitiesExact, false, 'unreadable libraries must not disappear from the count contract')
|
|
358
|
+
assert.equal(plan.scanned, 0)
|
|
359
|
+
assert.equal(plan.attested, 0)
|
|
360
|
+
assert.equal(plan.similar, 0)
|
|
361
|
+
})
|
|
362
|
+
|
|
266
363
|
test('the fragment plan separates provable windows from merely similar names', () => {
|
|
267
364
|
const attestedRebuild = repairLibrary('repair-rebuild',
|
|
268
365
|
{ 'mem-1': scene('南宫晚晴的午后', '南宫晚晴坐在窗边讲这件事。') },
|
|
@@ -332,6 +429,23 @@ test('the merge cascade never deletes an entity the repair did not plan to touch
|
|
|
332
429
|
|
|
333
430
|
test('the upgrade pass merges provable fragments once, leaves similar names for a human, and says so', async () => {
|
|
334
431
|
const { runEntityRepairPass } = await import('../lib/index.js')
|
|
432
|
+
// The earlier corruption fixture is intentionally unreadable. It is outside
|
|
433
|
+
// this complete-plan fixture, rather than silently counted as repaired.
|
|
434
|
+
const corruptLibrary = state.getSessionBinding('sweep-bad')?.libraryId
|
|
435
|
+
if (corruptLibrary) {
|
|
436
|
+
state.setCycleState({ entityRepairVersion: 0 })
|
|
437
|
+
const corruptFile = path.join(indexDir(), `${corruptLibrary}.entities.json`)
|
|
438
|
+
const beforeCorrupt = fs.readFileSync(corruptFile, 'utf8')
|
|
439
|
+
const blockedEvents = []
|
|
440
|
+
const blocked = await runEntityRepairPass({ diagnose: row => blockedEvents.push(row) })
|
|
441
|
+
assert.equal(blocked.partial, true, 'the deliberately unreadable library must remain incomplete')
|
|
442
|
+
assert.equal(blocked.deferred, true)
|
|
443
|
+
assert.ok(blocked.failures.some(row => row.libraryId === corruptLibrary))
|
|
444
|
+
assert.equal(state.getCycleState().entityRepairVersion, 0, 'an unreadable plan must never mark the upgrade done')
|
|
445
|
+
assert.equal(fs.readFileSync(corruptFile, 'utf8'), beforeCorrupt, 'failure is preserved, never replaced with empty entities')
|
|
446
|
+
assert.ok(blockedEvents.some(row => row.code === 'ENTITY_REPAIR_DEFERRED'))
|
|
447
|
+
state.archiveLibrary(corruptLibrary)
|
|
448
|
+
}
|
|
335
449
|
const provable = repairLibrary('upgrade-provable',
|
|
336
450
|
{ 'mem-1': scene('南宫晚晴的午后', '南宫晚晴坐在窗边讲这件事。') },
|
|
337
451
|
['南宫晚', '宫晚晴'])
|
|
@@ -348,6 +462,8 @@ test('the upgrade pass merges provable fragments once, leaves similar names for
|
|
|
348
462
|
assert.ok(events.some((row) => row.code === 'ENTITY_FRAGMENT_REPAIRED'), 'what got folded is recorded, not silent')
|
|
349
463
|
assert.ok(events.some((row) => row.code === 'ENTITY_FRAGMENT_SUSPECTED' && row.manual === true),
|
|
350
464
|
'the leftover is recorded as needing confirmation')
|
|
465
|
+
assert.ok(events.filter((row) => row.code === 'ENTITY_FRAGMENT_SUSPECTED')
|
|
466
|
+
.every(row => row.hint.includes('图管理') && !row.repair), 'similar candidates point to graph review, not a bulk repair')
|
|
351
467
|
assert.ok(state.getCycleState().entityRepairVersion >= 1, 'the pass marks itself done so it never repeats')
|
|
352
468
|
|
|
353
469
|
const second = await runEntityRepairPass({ diagnose: (row) => events.push(row) })
|
|
@@ -361,3 +477,116 @@ test('the upgrade pass merges provable fragments once, leaves similar names for
|
|
|
361
477
|
assert.deepEqual(third, { skipped: 'setting' }, 'off means even the provable class waits for a human')
|
|
362
478
|
assert.equal(graph.listEntities({ libraryId: provable }).items.map((entity) => entity.name).join(','), before)
|
|
363
479
|
})
|
|
480
|
+
|
|
481
|
+
test('a real large library defers startup repair without reading its corpus or marking the version done', async (t) => {
|
|
482
|
+
const { runEntityRepairPass } = await import('../lib/index.js')
|
|
483
|
+
const id = state.createLibrary({ name: 'upgrade-large-deferred', cwd: path.join(home, 'upgrade-large-deferred') }).id
|
|
484
|
+
const file = path.join(indexDir(), `${id}.entities.json`)
|
|
485
|
+
const corpusFile = path.join(indexDir(), `${id}.json`)
|
|
486
|
+
const entities = Object.fromEntries(Array.from({ length: 257 }, (_, i) => {
|
|
487
|
+
const entityId = `ent-large-${i}`
|
|
488
|
+
return [entityId, { id: entityId, name: `Person ${String(i).padStart(4, '0')}`, kind: 'person', status: 'confirmed' }]
|
|
489
|
+
}))
|
|
490
|
+
fs.writeFileSync(file, JSON.stringify({ version: 1, entities, relationships: {} }))
|
|
491
|
+
state.savePrivateIndex(id, { entries: { 'mem-large': scene('proof', '南宫晚晴坐在窗边。') } })
|
|
492
|
+
state.updateSettings({ autoRepairEntityFragments: true })
|
|
493
|
+
state.setCycleState({ entityRepairVersion: 0, entityRepairAt: 'not-complete', entityRepairMerged: 42 })
|
|
494
|
+
const before = fs.readFileSync(file, 'utf8')
|
|
495
|
+
const read = fs.readFileSync.bind(fs)
|
|
496
|
+
let corpusReads = 0
|
|
497
|
+
t.mock.method(fs, 'readFileSync', (target, ...args) => {
|
|
498
|
+
if (typeof target === 'string' && path.resolve(target) === path.resolve(corpusFile)) { corpusReads++; assert.fail('large startup repair must not read the corpus') }
|
|
499
|
+
return read(target, ...args)
|
|
500
|
+
})
|
|
501
|
+
try {
|
|
502
|
+
const events = [], warnings = []
|
|
503
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
504
|
+
const result = await runEntityRepairPass({ diagnose: row => events.push(row), warn: row => warnings.push(row) })
|
|
505
|
+
assert.equal(result.partial, true)
|
|
506
|
+
assert.equal(result.deferred, true)
|
|
507
|
+
assert.equal(result.merged, 0)
|
|
508
|
+
assert.ok(result.totalEntities >= 257)
|
|
509
|
+
assert.equal(result.entityLimit, 256)
|
|
510
|
+
assert.equal(state.getCycleState().entityRepairVersion, 0)
|
|
511
|
+
assert.equal(state.getCycleState().entityRepairAt, 'not-complete')
|
|
512
|
+
assert.equal(state.getCycleState().entityRepairMerged, 42)
|
|
513
|
+
}
|
|
514
|
+
assert.equal(fs.readFileSync(file, 'utf8'), before)
|
|
515
|
+
assert.equal(corpusReads, 0)
|
|
516
|
+
assert.ok(warnings.some(row => row.includes('incomplete plan')))
|
|
517
|
+
assert.ok(events.some(row => row.code === 'ENTITY_REPAIR_DEFERRED' && row.hint.includes('图管理') && row.detail.partial))
|
|
518
|
+
assert.ok(!events.some(row => row.code === 'ENTITY_FRAGMENT_REPAIRED'))
|
|
519
|
+
} finally {
|
|
520
|
+
state.archiveLibrary(id)
|
|
521
|
+
state.updateSettings({ autoRepairEntityFragments: false })
|
|
522
|
+
}
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
test('a complete small candidate scan with a truncated result defers proof and never marks repair done', async (t) => {
|
|
526
|
+
const { runEntityRepairPass } = await import('../lib/index.js')
|
|
527
|
+
const id = repairLibrary('repair-truncated-candidates',
|
|
528
|
+
{ 'mem-proof': scene('proof', 'Each Person is an independent identity.') },
|
|
529
|
+
Array.from({ length: 8 }, (_, i) => `Person ${String(i).padStart(4, '0')}`))
|
|
530
|
+
const file = path.join(indexDir(), `${id}.entities.json`)
|
|
531
|
+
const corpusFile = path.join(indexDir(), `${id}.json`)
|
|
532
|
+
const previousSetting = state.getSettings().autoRepairEntityFragments
|
|
533
|
+
try {
|
|
534
|
+
const candidates = graph.suggestEntityMerges({ libraryId: id })
|
|
535
|
+
assert.equal(candidates.pairSpace, 28)
|
|
536
|
+
assert.equal(candidates.scanComplete, true)
|
|
537
|
+
assert.equal(candidates.totalExact, true)
|
|
538
|
+
assert.equal(candidates.nextCursor, null)
|
|
539
|
+
assert.equal(candidates.truncated, true)
|
|
540
|
+
assert.equal(candidates.items.length, 20)
|
|
541
|
+
assert.equal(candidates.total, 28)
|
|
542
|
+
console.log('truncated-candidate-fixture: ' + JSON.stringify({ entities: 8,
|
|
543
|
+
pairSpace: candidates.pairSpace, scanComplete: candidates.scanComplete,
|
|
544
|
+
totalExact: candidates.totalExact, truncated: candidates.truncated,
|
|
545
|
+
total: candidates.total, returned: candidates.items.length }))
|
|
546
|
+
|
|
547
|
+
for (const truncated of [true, false]) {
|
|
548
|
+
const plan = repair.planLibraryRepair(id, { graph: {
|
|
549
|
+
graphExport: graph.graphExport,
|
|
550
|
+
suggestEntityMerges: () => ({ ...candidates, truncated }),
|
|
551
|
+
}, loadPrivateIndex() { assert.fail('a top-20 projection must defer before corpus proof') } })
|
|
552
|
+
assert.equal(plan.reason, 'candidate-scan-incomplete')
|
|
553
|
+
assert.equal(plan.partial, true)
|
|
554
|
+
assert.equal(plan.deferred, true)
|
|
555
|
+
assert.equal(plan.scanned, 0)
|
|
556
|
+
assert.deepEqual(plan.groups, [])
|
|
557
|
+
assert.deepEqual(plan.ambiguous, [])
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
state.updateSettings({ autoRepairEntityFragments: true })
|
|
561
|
+
state.setCycleState({ entityRepairVersion: 0, entityRepairAt: 'truncated-not-complete', entityRepairMerged: 42 })
|
|
562
|
+
const before = fs.readFileSync(file)
|
|
563
|
+
const beforeCorpus = fs.readFileSync(corpusFile)
|
|
564
|
+
const backups = state.listBackups().map(row => row.name)
|
|
565
|
+
const read = fs.readFileSync.bind(fs)
|
|
566
|
+
let corpusReads = 0
|
|
567
|
+
t.mock.method(fs, 'readFileSync', (target, ...args) => {
|
|
568
|
+
if (typeof target === 'string' && path.resolve(target) === path.resolve(corpusFile)) {
|
|
569
|
+
corpusReads++
|
|
570
|
+
assert.fail('a truncated candidate result must not read its corpus in the upgrade pass')
|
|
571
|
+
}
|
|
572
|
+
return read(target, ...args)
|
|
573
|
+
})
|
|
574
|
+
const events = []
|
|
575
|
+
const result = await runEntityRepairPass({ diagnose: row => events.push(row) })
|
|
576
|
+
assert.equal(result.partial, true)
|
|
577
|
+
assert.equal(result.deferred, true)
|
|
578
|
+
assert.equal(result.merged, 0)
|
|
579
|
+
assert.equal(state.getCycleState().entityRepairVersion, 0)
|
|
580
|
+
assert.equal(state.getCycleState().entityRepairAt, 'truncated-not-complete')
|
|
581
|
+
assert.equal(state.getCycleState().entityRepairMerged, 42)
|
|
582
|
+
assert.equal(corpusReads, 0)
|
|
583
|
+
assert.deepEqual(read(file), before)
|
|
584
|
+
assert.deepEqual(read(corpusFile), beforeCorpus)
|
|
585
|
+
assert.deepEqual(state.listBackups().map(row => row.name), backups)
|
|
586
|
+
assert.ok(events.some(row => row.code === 'ENTITY_REPAIR_DEFERRED'))
|
|
587
|
+
assert.ok(!events.some(row => row.code === 'ENTITY_FRAGMENT_REPAIRED'))
|
|
588
|
+
} finally {
|
|
589
|
+
state.archiveLibrary(id)
|
|
590
|
+
state.updateSettings({ autoRepairEntityFragments: previousSetting })
|
|
591
|
+
}
|
|
592
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
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-graph-import-diag-'))
|
|
8
|
+
process.env.DSH_MEMU_HOME = home
|
|
9
|
+
const state = await import('../lib/state.js')
|
|
10
|
+
const { restoreGraphData } = await import('../lib/graph.js')
|
|
11
|
+
const { listEvents } = await import('../lib/activity-log.js')
|
|
12
|
+
test.after(() => { state.flushState(); fs.rmSync(home, { recursive: true, force: true }) })
|
|
13
|
+
|
|
14
|
+
test('graph import cap emits a bounded numeric diagnostic without private entity labels', () => {
|
|
15
|
+
const binding = state.ensureSession('graph-import-diag', { cwd: path.join(home, 'project'), agentPreset: 'coding' })
|
|
16
|
+
// Invalid identifiers skip entity IO; this test isolates the existing import cap.
|
|
17
|
+
const entities = Object.fromEntries(Array.from({ length: 2001 }, (_, i) => ['invalid-' + i, { name: 'private-synthetic-name-' + i }]))
|
|
18
|
+
const result = restoreGraphData(binding.libraryId, { entities, relationships: {} }, {})
|
|
19
|
+
assert.deepEqual(result.createdEntityIds, [])
|
|
20
|
+
const event = listEvents({}).find(row => row.detail?.code === 'GRAPH_IMPORT_TRUNCATED')
|
|
21
|
+
assert.ok(event)
|
|
22
|
+
assert.equal(event.level, 'warn')
|
|
23
|
+
assert.deepEqual(event.detail, { code: 'GRAPH_IMPORT_TRUNCATED', received: 2001, limit: 2000, dropped: 1 })
|
|
24
|
+
assert.equal(JSON.stringify(event).includes('private-synthetic-name'), false)
|
|
25
|
+
})
|