dsh-memu-memory 1.2.2 → 1.2.3
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 +12 -4
- package/README.zh.md +13 -5
- package/docs/client-conventions.md +1 -0
- package/docs/contributing.md +7 -6
- package/docs/emotion-model-spec.md +2 -2
- package/docs/env-and-commands.md +20 -0
- package/docs/host-api.md +19 -0
- package/docs/memory-semantics.md +10 -1
- package/docs/troubleshooting.md +36 -3
- package/lib/activity-log.js +1 -1
- package/lib/binding-diagnostics.js +1 -1
- package/lib/client.js +152 -9
- package/lib/cycle.js +9 -1
- package/lib/freshness.js +97 -0
- package/lib/graph.js +244 -2
- package/lib/inject.js +119 -8
- package/lib/memory.js +83 -17
- package/lib/rpc.js +13 -2
- package/lib/salient-wake.js +402 -0
- package/lib/state.js +92 -1
- package/package.json +1 -1
- package/scripts/drive-session.mjs +853 -0
- package/scripts/mock-llm.mjs +903 -0
- package/tests/client-render.test.mjs +13 -1
- package/tests/entity-merge.test.mjs +261 -0
- package/tests/fixtures/mock-llm/reply.txt +1 -0
- package/tests/freshness.test.mjs +140 -0
- package/tests/help-page.test.mjs +4 -4
- package/tests/injection-chain.test.mjs +176 -0
- package/tests/mock-llm.test.mjs +225 -0
- package/tests/open-loop-date.test.mjs +406 -0
- package/tests/salient-wake.test.mjs +362 -0
- package/tests/settings-plumbing.test.mjs +76 -0
- package/tests/sidebar.test.mjs +5 -1
- package/tests/stubs/dsh-schedule.js +105 -0
- package/tests/webui-auth.test.mjs +4 -0
|
@@ -267,6 +267,15 @@ test('the sidebar context-scope card cannot be flex-shrunk and keeps a two-colum
|
|
|
267
267
|
assert.match(src, /\.dshm-scope-form\{[^}]*grid-template-columns:repeat\(2,minmax\(0,1fr\)\)/, 'four scope fields must wrap into two readable columns')
|
|
268
268
|
})
|
|
269
269
|
|
|
270
|
+
test('the memory UI renders the read-only arousal/dominance/emotionSource line', () => {
|
|
271
|
+
const src = fs.readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
272
|
+
for (const key of ['arousalLabel', 'dominanceLabel', 'emotionSourceLabel', 'emotionSourceModel', 'emotionSourceSession', 'emotionSourceContent', 'emotionSourceUnknown']) {
|
|
273
|
+
assert.ok(src.includes(key), `missing ${key}`)
|
|
274
|
+
}
|
|
275
|
+
assert.match(src, /emotionMetaText\(f, t\)/, 'the card tag must expose affect metadata in its title')
|
|
276
|
+
assert.match(src, /emotionMetaText\(shown, t\)/, 'the drawer must render the read-only affect line')
|
|
277
|
+
})
|
|
278
|
+
|
|
270
279
|
test('the sidebar run log keeps five rows and links its header to the WebUI logs page', () => {
|
|
271
280
|
const src = fs.readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
272
281
|
assert.match(src, /runLog\.slice\(0, 5\)/, 'the sidebar shows the five newest runs, not an unbounded list')
|
|
@@ -318,7 +327,10 @@ test('the memory browser badges what a memory is allowed to say', async () => {
|
|
|
318
327
|
disclosure: 'never_say',
|
|
319
328
|
visibility: 'secret',
|
|
320
329
|
owner: 'about_user',
|
|
321
|
-
|
|
330
|
+
// 相对时间,不写死当天某一刻:短条目一旦过期就变成 inactive,行内编辑器不再渲染,
|
|
331
|
+
// 这条测试就会在下午闪红(曾经 pin 在 2026-11-01T09:30Z)。它要断言的是「草稿看得到
|
|
332
|
+
// 自己什么时候死」,所以留出 6 小时余量即可。
|
|
333
|
+
expiresAt: new Date(Date.now() + 6 * 3600 * 1000).toISOString(),
|
|
322
334
|
},
|
|
323
335
|
{ id: 'mem-loud', title: 'shared fact', content: 'anything', layer: 'long_term', status: 'active', decay: 0.9, disclosure: 'can_tell', visibility: 'shared', owner: 'me' },
|
|
324
336
|
],
|
|
@@ -0,0 +1,261 @@
|
|
|
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
|
+
// 工单 F:实体主节点合并(§9)。断言针对库内实体文件与私有索引的真实落盘状态,
|
|
8
|
+
// 不 mock 存储层——合并的价值就在于两个文件一起收敛,且中途失败不能留下悬空边。
|
|
9
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-entity-merge-'))
|
|
10
|
+
process.env.DSH_MEMU_HOME = home
|
|
11
|
+
const state = await import('../lib/state.js')
|
|
12
|
+
const graph = await import('../lib/graph.js')
|
|
13
|
+
const { indexDir } = await import('../lib/paths.js')
|
|
14
|
+
const { listEvents } = await import('../lib/activity-log.js')
|
|
15
|
+
|
|
16
|
+
test.after(() => { state.flushState(); fs.rmSync(home, { recursive: true, force: true }) })
|
|
17
|
+
|
|
18
|
+
function newLibrary(name) {
|
|
19
|
+
return state.ensureSession(name, { cwd: path.join(home, name), agentPreset: 'rp' }).libraryId
|
|
20
|
+
}
|
|
21
|
+
const entitiesFile = (libraryId) => path.join(indexDir(), `${libraryId}.entities.json`)
|
|
22
|
+
const readStore = (libraryId) => JSON.parse(fs.readFileSync(entitiesFile(libraryId), 'utf8'))
|
|
23
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
24
|
+
|
|
25
|
+
test('mergeEntities remaps every link to the target, dedupes (to, kind) and deletes the sources', () => {
|
|
26
|
+
const libraryId = newLibrary('merge-core')
|
|
27
|
+
const target = graph.createEntity({ libraryId, name: 'Lin Mian', kind: 'person', aliases: ['Mian'] })
|
|
28
|
+
const source1 = graph.createEntity({ libraryId, name: 'Lin', kind: 'person', aliases: ["Mian'er"] })
|
|
29
|
+
const source2 = graph.createEntity({ libraryId, name: 'Mian', kind: 'person', aliases: ['Lin Mian'] })
|
|
30
|
+
state.savePrivateIndex(libraryId, { entries: {
|
|
31
|
+
'mem-merge-a': { title: 'a', content: 'a scene', status: 'active', visibility: 'shared', links: [
|
|
32
|
+
{ to: source1.id, kind: 'person', note: 'Lin is the person this scene is about.', confidence: 0.9 },
|
|
33
|
+
{ to: target.id, kind: 'person', note: 'The pre-existing target edge wins the dedupe.', confidence: 0.4 },
|
|
34
|
+
{ to: source1.id, kind: 'relation', note: 'Lin is related to the events in this scene.', confidence: 0.5 },
|
|
35
|
+
{ to: 'mem-merge-b', kind: 'event', note: 'The same event seen from another side.', confidence: 0.6 },
|
|
36
|
+
] },
|
|
37
|
+
'mem-merge-b': { title: 'b', content: 'b scene', status: 'active', visibility: 'shared', links: [
|
|
38
|
+
{ to: source2.id, kind: 'person', note: 'Mian is the person this scene is about.', confidence: 0.8, source: 'auto' },
|
|
39
|
+
{ to: source1.id, kind: 'person', note: 'The same person named Lin again.', confidence: 0.7 },
|
|
40
|
+
] },
|
|
41
|
+
} })
|
|
42
|
+
|
|
43
|
+
const result = graph.mergeEntities({ libraryId, targetId: target.id, sourceIds: [source1.id, source2.id] })
|
|
44
|
+
assert.equal(result.targetId, target.id)
|
|
45
|
+
assert.deepEqual(result.merged, [source1.id, source2.id])
|
|
46
|
+
assert.equal(result.remappedLinks, 4, 'every link that pointed at a source is redirected')
|
|
47
|
+
assert.equal(result.duplicateLinks, 2, 'the second (to, kind) pair per entry is dropped')
|
|
48
|
+
assert.deepEqual(result.relationships, { moved: 0, conflicts: [] })
|
|
49
|
+
assert.deepEqual(result.droppedAliases, [])
|
|
50
|
+
assert.deepEqual(result.aliases, ['Mian', 'Lin', "Mian'er", 'Lin Mian'])
|
|
51
|
+
|
|
52
|
+
const index = state.loadPrivateIndex(libraryId)
|
|
53
|
+
const allLinks = Object.values(index.entries).flatMap(entry => entry.links || [])
|
|
54
|
+
assert.ok(allLinks.every(link => link.to !== source1.id && link.to !== source2.id), 'no link survives pointing at a merged source')
|
|
55
|
+
const aLinks = index.entries['mem-merge-a'].links
|
|
56
|
+
assert.equal(aLinks.filter(link => link.to === target.id && link.kind === 'person').length, 1)
|
|
57
|
+
assert.equal(aLinks.find(link => link.to === target.id && link.kind === 'person').note, 'The pre-existing target edge wins the dedupe.')
|
|
58
|
+
assert.equal(aLinks.find(link => link.to === target.id && link.kind === 'relation').confidence, 0.5)
|
|
59
|
+
const bLinks = index.entries['mem-merge-b'].links
|
|
60
|
+
assert.equal(bLinks.length, 1, 'the duplicate source edge is dropped')
|
|
61
|
+
assert.equal(bLinks[0].to, target.id)
|
|
62
|
+
assert.equal(bLinks[0].source, 'auto', 'auto metadata survives the merge')
|
|
63
|
+
|
|
64
|
+
const store = graph.graphExport(libraryId)
|
|
65
|
+
assert.equal(store.entities[source1.id], undefined)
|
|
66
|
+
assert.equal(store.entities[source2.id], undefined)
|
|
67
|
+
assert.equal(store.entities[target.id].name, 'Lin Mian', 'the target name stays the display name')
|
|
68
|
+
assert.deepEqual(store.entities[target.id].aliases, ['Mian', 'Lin', "Mian'er", 'Lin Mian'])
|
|
69
|
+
|
|
70
|
+
const view = graph.getGraph({ libraryId, focusId: 'mem-merge-b', depth: 1 })
|
|
71
|
+
assert.ok(view.nodes.some(node => node.id === target.id && node.title === 'Lin Mian'))
|
|
72
|
+
assert.ok(!view.nodes.some(node => node.id === source1.id || node.id === source2.id), 'getGraph resolves the merged ids, not placeholders')
|
|
73
|
+
|
|
74
|
+
const events = listEvents({ limit: 100, kind: 'write' })
|
|
75
|
+
const event = events.find(item => item.detail?.op === 'entity-merge' && item.detail?.targetId === target.id)
|
|
76
|
+
assert.ok(event, 'the merge is recorded in the activity log')
|
|
77
|
+
assert.deepEqual(event.refs, [target.id, source1.id, source2.id])
|
|
78
|
+
assert.equal(event.ok, true)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('mergeEntities unions aliases, caps at 30 and reports the dropped tail', () => {
|
|
82
|
+
const libraryId = newLibrary('merge-aliases')
|
|
83
|
+
const targetAliases = Array.from({ length: 10 }, (_, index) => `target-alias-${index}`)
|
|
84
|
+
const source1Aliases = Array.from({ length: 25 }, (_, index) => `source-one-alias-${index}`)
|
|
85
|
+
const source2Aliases = Array.from({ length: 10 }, (_, index) => `source-two-alias-${index}`)
|
|
86
|
+
const target = graph.createEntity({ libraryId, name: 'Alias Target', kind: 'person', aliases: targetAliases })
|
|
87
|
+
const source1 = graph.createEntity({ libraryId, name: 'Alias Source One', kind: 'person', aliases: source1Aliases })
|
|
88
|
+
const source2 = graph.createEntity({ libraryId, name: 'Alias Source Two', kind: 'person', aliases: source2Aliases })
|
|
89
|
+
const union = [...targetAliases, 'Alias Source One', ...source1Aliases, 'Alias Source Two', ...source2Aliases]
|
|
90
|
+
|
|
91
|
+
const result = graph.mergeEntities({ libraryId, targetId: target.id, sourceIds: [source1.id, source2.id] })
|
|
92
|
+
assert.equal(result.aliases.length, 30)
|
|
93
|
+
assert.deepEqual(result.aliases, union.slice(0, 30))
|
|
94
|
+
assert.deepEqual(result.droppedAliases, union.slice(30))
|
|
95
|
+
assert.equal(result.droppedAliases.length, union.length - 30)
|
|
96
|
+
const stored = readStore(libraryId).entities[target.id]
|
|
97
|
+
assert.ok(stored, 'the merge target is never collected by the safety-net prune, even while unreferenced')
|
|
98
|
+
assert.equal(stored.name, 'Alias Target')
|
|
99
|
+
assert.deepEqual(stored.aliases, union.slice(0, 30))
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('mergeEntities rejects kind mismatches, self-sources, empty lists and unknown ids without writing', () => {
|
|
103
|
+
const libraryId = newLibrary('merge-validation')
|
|
104
|
+
const otherLibraryId = newLibrary('merge-validation-other')
|
|
105
|
+
const keep = graph.createEntity({ libraryId, name: 'Keep', kind: 'person' })
|
|
106
|
+
const otherKind = graph.createEntity({ libraryId, name: 'Keep Place', kind: 'place' })
|
|
107
|
+
const peer = graph.createEntity({ libraryId, name: 'Peer', kind: 'person' })
|
|
108
|
+
const foreign = graph.createEntity({ libraryId: otherLibraryId, name: 'Foreign', kind: 'person' })
|
|
109
|
+
state.savePrivateIndex(libraryId, { entries: {
|
|
110
|
+
'mem-validation': { title: 'validation', content: 'validation scene', status: 'active', visibility: 'shared', links: [
|
|
111
|
+
{ to: peer.id, kind: 'person', note: 'Peer is the person this scene is about.', confidence: 0.9 },
|
|
112
|
+
] },
|
|
113
|
+
} })
|
|
114
|
+
const before = fs.readFileSync(entitiesFile(libraryId), 'utf8')
|
|
115
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: keep.id, sourceIds: [otherKind.id] }), /different kinds/)
|
|
116
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: keep.id, sourceIds: [keep.id] }), /own sources/)
|
|
117
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: keep.id, sourceIds: [] }), /non-empty array/)
|
|
118
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: keep.id }), /non-empty array/)
|
|
119
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: keep.id, sourceIds: [peer.id, 'ent-ghost'] }), /unknown entity/)
|
|
120
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: keep.id, sourceIds: [foreign.id] }), /unknown entity/, 'an id that lives in another library is not mergeable here')
|
|
121
|
+
assert.throws(() => graph.mergeEntities({ libraryId, targetId: 'ent-ghost', sourceIds: [peer.id] }), /unknown entity/)
|
|
122
|
+
assert.throws(() => graph.mergeEntities({ targetId: keep.id, sourceIds: [peer.id] }), /no bound session/)
|
|
123
|
+
assert.equal(fs.readFileSync(entitiesFile(libraryId), 'utf8'), before, 'a rejected merge never rewrites the entity store')
|
|
124
|
+
const links = state.loadPrivateIndex(libraryId).entries['mem-validation'].links
|
|
125
|
+
assert.deepEqual(links.map(link => link.to), [peer.id])
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('mergeEntities re-keys relationship snapshots, preserves the target side and reports conflicts', () => {
|
|
129
|
+
const libraryId = newLibrary('merge-relationships')
|
|
130
|
+
const target = graph.createEntity({ libraryId, name: 'Target', kind: 'person' })
|
|
131
|
+
const source1 = graph.createEntity({ libraryId, name: 'Source One', kind: 'person' })
|
|
132
|
+
const source2 = graph.createEntity({ libraryId, name: 'Source Two', kind: 'person' })
|
|
133
|
+
const buddy = graph.createEntity({ libraryId, name: 'Buddy', kind: 'person' })
|
|
134
|
+
const companion = graph.createEntity({ libraryId, name: 'Companion', kind: 'person' })
|
|
135
|
+
const orphan = graph.createEntity({ libraryId, name: 'Orphan', kind: 'person' })
|
|
136
|
+
state.savePrivateIndex(libraryId, { entries: {
|
|
137
|
+
'mem-rel-evidence': { title: 'evidence', content: 'evidence scene', status: 'active', visibility: 'shared' },
|
|
138
|
+
} })
|
|
139
|
+
graph.updateRelationship({ libraryId, fromId: target.id, toId: buddy.id, state: { trust: 0.2 }, evidenceIds: ['mem-rel-evidence'], reason: 'The target-side snapshot is the older evidence.' })
|
|
140
|
+
graph.updateRelationship({ libraryId, fromId: source1.id, toId: buddy.id, state: { trust: 0.9 }, evidenceIds: ['mem-rel-evidence'], reason: 'The source-side snapshot is the newer evidence.' })
|
|
141
|
+
graph.updateRelationship({ libraryId, fromId: buddy.id, toId: source1.id, state: { warmth: 0.4 }, evidenceIds: ['mem-rel-evidence'], reason: 'The reverse direction is its own snapshot.' })
|
|
142
|
+
graph.updateRelationship({ libraryId, fromId: buddy.id, toId: source1.id, state: { warmth: 0.5 }, evidenceIds: ['mem-rel-evidence'], reason: 'A second revision gives the snapshot history.' })
|
|
143
|
+
graph.updateRelationship({ libraryId, fromId: source1.id, toId: source2.id, state: { trust: 0.3 }, evidenceIds: ['mem-rel-evidence'], reason: 'A source-only snapshot becomes a self loop.' })
|
|
144
|
+
graph.updateRelationship({ libraryId, fromId: source2.id, toId: companion.id, state: { familiarity: 0.6 }, evidenceIds: ['mem-rel-evidence'], reason: 'A source behind the relationship moves with it.' })
|
|
145
|
+
|
|
146
|
+
const result = graph.mergeEntities({ libraryId, targetId: target.id, sourceIds: [source1.id, source2.id] })
|
|
147
|
+
assert.deepEqual(result.relationships, {
|
|
148
|
+
moved: 2,
|
|
149
|
+
conflicts: [
|
|
150
|
+
{ key: JSON.stringify([source1.id, buddy.id]), reason: 'existing-target', keptKey: JSON.stringify([target.id, buddy.id]) },
|
|
151
|
+
{ key: JSON.stringify([source1.id, source2.id]), reason: 'self' },
|
|
152
|
+
],
|
|
153
|
+
})
|
|
154
|
+
const kept = graph.getRelationship({ libraryId, fromId: target.id, toId: buddy.id }).relationship
|
|
155
|
+
assert.equal(kept.state.trust, 0.2, 'the existing target-side snapshot is not overwritten')
|
|
156
|
+
assert.equal(kept.revision, 1)
|
|
157
|
+
const moved = graph.getRelationship({ libraryId, fromId: buddy.id, toId: target.id }).relationship
|
|
158
|
+
assert.equal(moved.fromId, buddy.id)
|
|
159
|
+
assert.equal(moved.toId, target.id)
|
|
160
|
+
assert.equal(moved.state.warmth, 0.5)
|
|
161
|
+
assert.equal(moved.history.length, 1, 'history moves with the snapshot')
|
|
162
|
+
assert.equal(moved.revision, 2)
|
|
163
|
+
const movedOut = graph.getRelationship({ libraryId, fromId: target.id, toId: companion.id }).relationship
|
|
164
|
+
assert.equal(movedOut.state.familiarity, 0.6)
|
|
165
|
+
assert.equal(graph.getRelationship({ libraryId, fromId: source1.id, toId: buddy.id }).relationship, null, 'no old source key survives')
|
|
166
|
+
const store = graph.graphExport(libraryId)
|
|
167
|
+
assert.ok(Object.keys(store.relationships).every(key => !key.includes(source1.id) && !key.includes(source2.id)))
|
|
168
|
+
assert.equal(store.entities[orphan.id], undefined, 'the prune safety net collected the unrelated orphan')
|
|
169
|
+
assert.ok(store.entities[target.id], 'the target itself stays')
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('suggestEntityMerges: containment and normalization produce shorter→longer pairs', () => {
|
|
173
|
+
const libraryId = newLibrary('suggest-names')
|
|
174
|
+
const lin = graph.createEntity({ libraryId, name: 'Lin', kind: 'person' })
|
|
175
|
+
const linMian = graph.createEntity({ libraryId, name: 'Lin Mian', kind: 'person' })
|
|
176
|
+
const lower = graph.createEntity({ libraryId, name: 'lin', kind: 'person' })
|
|
177
|
+
const yuike = graph.createEntity({ libraryId, name: 'YUIKE', kind: 'person' })
|
|
178
|
+
const tanaka = graph.createEntity({ libraryId, name: 'yuike tanaka', kind: 'person' })
|
|
179
|
+
const place = graph.createEntity({ libraryId, name: 'Lin Road', kind: 'place' })
|
|
180
|
+
|
|
181
|
+
const { items } = graph.suggestEntityMerges({ libraryId })
|
|
182
|
+
const pair = (source, target) => items.find(item => item.sourceId === source.id && item.targetId === target.id)
|
|
183
|
+
assert.ok(pair(lin, linMian), 'the shorter normalized name folds into the longer one')
|
|
184
|
+
assert.ok(pair(lower, linMian))
|
|
185
|
+
assert.equal(pair(lin, linMian).reason, 'containment')
|
|
186
|
+
assert.ok(pair(yuike, tanaka), 'NFKC/case folding finds the full-width variant')
|
|
187
|
+
assert.ok(!items.some(item => (item.sourceId === lin.id && item.targetId === lower.id) || (item.sourceId === lower.id && item.targetId === lin.id)),
|
|
188
|
+
'identical normalized names are not a candidate')
|
|
189
|
+
assert.ok(!items.some(item => (item.sourceId === place.id && item.targetId === lin.id) || (item.sourceId === lin.id && item.targetId === place.id)),
|
|
190
|
+
'different kinds never pair up')
|
|
191
|
+
assert.ok(!items.some(item => item.sourceId === place.id || item.targetId === place.id), 'the place has no same-kind candidate')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('suggestEntityMerges: near-miss spellings within two edits are candidates, with a stable direction', async () => {
|
|
195
|
+
const libraryId = newLibrary('suggest-edit')
|
|
196
|
+
const kyle = graph.createEntity({ libraryId, name: 'Kyle', kind: 'person' })
|
|
197
|
+
await sleep(5)
|
|
198
|
+
const kile = graph.createEntity({ libraryId, name: 'Kile', kind: 'person' })
|
|
199
|
+
await sleep(5)
|
|
200
|
+
const marcus = graph.createEntity({ libraryId, name: 'Marcus', kind: 'person' })
|
|
201
|
+
await sleep(5)
|
|
202
|
+
const marcos = graph.createEntity({ libraryId, name: 'Marcos', kind: 'person' })
|
|
203
|
+
|
|
204
|
+
const first = graph.suggestEntityMerges({ libraryId })
|
|
205
|
+
const second = graph.suggestEntityMerges({ libraryId })
|
|
206
|
+
assert.deepEqual(first, second, 'suggestion order is deterministic')
|
|
207
|
+
assert.equal(first.items.length, 2)
|
|
208
|
+
assert.ok(first.items.every(item => item.reason === 'edit-distance'))
|
|
209
|
+
assert.deepEqual(first.items.find(item => [item.sourceId, item.targetId].includes(kyle.id)),
|
|
210
|
+
{ sourceId: kile.id, targetId: kyle.id, reason: 'edit-distance' }, 'equal length folds into the older id')
|
|
211
|
+
assert.deepEqual(first.items.find(item => [item.sourceId, item.targetId].includes(marcus.id)),
|
|
212
|
+
{ sourceId: marcos.id, targetId: marcus.id, reason: 'edit-distance' })
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('suggestEntityMerges: kind mismatch and identical folded names yield no candidates', () => {
|
|
216
|
+
const libraryId = newLibrary('suggest-filter')
|
|
217
|
+
graph.createEntity({ libraryId, name: 'Aria', kind: 'person' })
|
|
218
|
+
graph.createEntity({ libraryId, name: 'Ariadne', kind: 'place' })
|
|
219
|
+
graph.createEntity({ libraryId, name: 'Mika', kind: 'person' })
|
|
220
|
+
graph.createEntity({ libraryId, name: 'MIKA', kind: 'person' })
|
|
221
|
+
assert.deepEqual(graph.suggestEntityMerges({ libraryId }), { items: [] })
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('suggestEntityMerges: unrelated names yield an empty list', () => {
|
|
225
|
+
const libraryId = newLibrary('suggest-none')
|
|
226
|
+
graph.createEntity({ libraryId, name: 'Zephyr', kind: 'person' })
|
|
227
|
+
graph.createEntity({ libraryId, name: 'Quartz', kind: 'person' })
|
|
228
|
+
assert.deepEqual(graph.suggestEntityMerges({ libraryId }).items, [])
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('suggestEntityMerges caps the list at 20 and never writes', () => {
|
|
232
|
+
const libraryId = newLibrary('suggest-cap')
|
|
233
|
+
for (let index = 0; index < 25; index += 1) {
|
|
234
|
+
const suffix = String(index).padStart(2, '0')
|
|
235
|
+
graph.createEntity({ libraryId, name: `NestBase${suffix}`, kind: 'person' })
|
|
236
|
+
graph.createEntity({ libraryId, name: `NestBase${suffix}Extra`, kind: 'person' })
|
|
237
|
+
}
|
|
238
|
+
const file = entitiesFile(libraryId)
|
|
239
|
+
const before = fs.readFileSync(file, 'utf8')
|
|
240
|
+
const first = graph.suggestEntityMerges({ libraryId })
|
|
241
|
+
const second = graph.suggestEntityMerges({ libraryId })
|
|
242
|
+
assert.equal(fs.readFileSync(file, 'utf8'), before, 'suggesting is a pure read')
|
|
243
|
+
assert.deepEqual(second, first)
|
|
244
|
+
assert.equal(first.items.length, 20)
|
|
245
|
+
assert.ok(first.items.every(item => item.sourceId && item.targetId && item.sourceId !== item.targetId))
|
|
246
|
+
assert.ok(first.items.every(item => item.reason === 'containment' || item.reason === 'edit-distance'))
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
test('the RPC cases take exactly the payload the graph panel sends', async () => {
|
|
250
|
+
const libraryId = newLibrary('rpc-shape')
|
|
251
|
+
const target = graph.createEntity({ libraryId, name: '林眠儿', kind: 'person' })
|
|
252
|
+
const source = graph.createEntity({ libraryId, name: '林眠', kind: 'person' })
|
|
253
|
+
const rpc = await import('../lib/rpc.js')
|
|
254
|
+
const suggested = await rpc.dispatch({}, 'suggestEntityMerges', { libraryId })
|
|
255
|
+
assert.deepEqual(suggested.items, [{ sourceId: source.id, targetId: target.id, reason: 'containment' }])
|
|
256
|
+
// 面板一次只确认一对:sourceIds 是数组,但 UI 传的就是单个来源。
|
|
257
|
+
const merged = await rpc.dispatch({}, 'mergeEntities', { libraryId, targetId: target.id, sourceIds: [source.id] })
|
|
258
|
+
assert.equal(merged.targetId, target.id)
|
|
259
|
+
assert.deepEqual(merged.merged, [source.id])
|
|
260
|
+
assert.ok(merged.aliases.includes('林眠'), 'the source name becomes an alias of the main node')
|
|
261
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(测试回复)好的,我记得这件事。
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { freshnessSignals } from '../lib/freshness.js'
|
|
5
|
+
|
|
6
|
+
const DAY_MS = 86_400_000
|
|
7
|
+
// Local noon on 2026-11-15, so "today" is unambiguous in every timezone.
|
|
8
|
+
const NOW = new Date(2026, 10, 15, 12, 0, 0)
|
|
9
|
+
const daysAgo = (days) => new Date(NOW.getTime() - days * DAY_MS).toISOString()
|
|
10
|
+
|
|
11
|
+
function entry(patch = {}) {
|
|
12
|
+
return { title: '普通记忆', content: '窗外的雨停了。', updatedAt: daysAgo(0), ...patch }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test('a one-off date is stale only after its local day has passed', () => {
|
|
16
|
+
const cases = [
|
|
17
|
+
['2026-11-14', true, 'dated-past:2026-11-14'],
|
|
18
|
+
['2025-12-31', true, 'dated-past:2025-12-31'],
|
|
19
|
+
['2026-11-15', false],
|
|
20
|
+
['2026-11-16', false],
|
|
21
|
+
// Annual MM-DD is a birthday, not an expiry — even when that day already passed.
|
|
22
|
+
['10-29', false],
|
|
23
|
+
['02-29', false],
|
|
24
|
+
// Impossible or non-date-only values are ignored, never "expired".
|
|
25
|
+
['2026-02-30', false],
|
|
26
|
+
['2026-13-01', false],
|
|
27
|
+
['2026-11-14T00:00:00', false],
|
|
28
|
+
['', false],
|
|
29
|
+
[null, false],
|
|
30
|
+
[undefined, false],
|
|
31
|
+
]
|
|
32
|
+
for (const [salientDate, stale, reason] of cases) {
|
|
33
|
+
const result = freshnessSignals(entry({ salientDate }), { now: NOW })
|
|
34
|
+
assert.equal(result.stale, stale, `salientDate=${String(salientDate)}`)
|
|
35
|
+
if (stale) assert.deepEqual(result.reasons, [reason])
|
|
36
|
+
else assert.deepEqual(result.reasons, [])
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('the fixed freshness vocabulary matches title and content', () => {
|
|
41
|
+
const terms = ['最新', '最近', '现在', '目前', '今年', '版本', '价格', '天气', '新闻', '比分', '汇率']
|
|
42
|
+
for (const term of terms) {
|
|
43
|
+
const inTitle = freshnessSignals(entry({ title: `关于${term}的记录` }), { now: NOW })
|
|
44
|
+
assert.equal(inTitle.stale, true, `${term} in title`)
|
|
45
|
+
assert.deepEqual(inTitle.reasons, [`freshness-term:${term}`])
|
|
46
|
+
|
|
47
|
+
const inContent = freshnessSignals(entry({ title: '记录', content: `这条提到${term}。` }), { now: NOW })
|
|
48
|
+
assert.equal(inContent.stale, true, `${term} in content`)
|
|
49
|
+
assert.deepEqual(inContent.reasons, [`freshness-term:${term}`])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const both = freshnessSignals(entry({ title: '最新价格' }), { now: NOW })
|
|
53
|
+
assert.deepEqual(both.reasons, ['freshness-term:最新', 'freshness-term:价格'])
|
|
54
|
+
|
|
55
|
+
assert.deepEqual(freshnessSignals(entry({ title: 'latest price' }), { now: NOW }), { stale: false, reasons: [] })
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('age comes from updatedAt first and ignores project facts', () => {
|
|
59
|
+
assert.deepEqual(
|
|
60
|
+
freshnessSignals(entry({ updatedAt: daysAgo(45) }), { now: NOW }).reasons,
|
|
61
|
+
['age-days:45'],
|
|
62
|
+
)
|
|
63
|
+
// updatedAt wins over an older createdAt: an edited entry is current again.
|
|
64
|
+
assert.deepEqual(
|
|
65
|
+
freshnessSignals(entry({ updatedAt: daysAgo(1), createdAt: daysAgo(400) }), { now: NOW }).reasons,
|
|
66
|
+
[],
|
|
67
|
+
)
|
|
68
|
+
assert.deepEqual(
|
|
69
|
+
freshnessSignals(entry({ updatedAt: undefined, createdAt: daysAgo(45) }), { now: NOW }).reasons,
|
|
70
|
+
['age-days:45'],
|
|
71
|
+
)
|
|
72
|
+
// Project conclusions may age too, but a coding library where every card says
|
|
73
|
+
// "old" is noise; the age leg stays off for them.
|
|
74
|
+
assert.deepEqual(
|
|
75
|
+
freshnessSignals(entry({ owner: 'about_project', updatedAt: daysAgo(400) }), { now: NOW }).reasons,
|
|
76
|
+
[],
|
|
77
|
+
)
|
|
78
|
+
// Only the age leg is excluded: time-sensitive wording still counts.
|
|
79
|
+
assert.deepEqual(
|
|
80
|
+
freshnessSignals(entry({ owner: 'about_project', title: '版本', updatedAt: daysAgo(400) }), { now: NOW }).reasons,
|
|
81
|
+
['freshness-term:版本'],
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('missing, invalid and future timestamps are not age signals', () => {
|
|
86
|
+
const cases = [
|
|
87
|
+
{ updatedAt: undefined, createdAt: undefined },
|
|
88
|
+
{ updatedAt: null, createdAt: null },
|
|
89
|
+
{ updatedAt: '', createdAt: '' },
|
|
90
|
+
{ updatedAt: 'not-a-date', createdAt: 'also-not-a-date' },
|
|
91
|
+
{ updatedAt: NaN, createdAt: NaN },
|
|
92
|
+
{ updatedAt: daysAgo(-10), createdAt: daysAgo(-10) },
|
|
93
|
+
]
|
|
94
|
+
for (const patch of cases) {
|
|
95
|
+
assert.deepEqual(freshnessSignals(entry(patch), { now: NOW }), { stale: false, reasons: [] })
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('the age boundary is inclusive at freshnessDays', () => {
|
|
100
|
+
const exact = freshnessSignals({ updatedAt: new Date(NOW.getTime() - 30 * DAY_MS).toISOString() }, { now: NOW })
|
|
101
|
+
assert.equal(exact.stale, true)
|
|
102
|
+
assert.deepEqual(exact.reasons, ['age-days:30'])
|
|
103
|
+
|
|
104
|
+
const justUnder = freshnessSignals({ updatedAt: new Date(NOW.getTime() - (30 * DAY_MS - 1)).toISOString() }, { now: NOW })
|
|
105
|
+
assert.deepEqual(justUnder, { stale: false, reasons: [] })
|
|
106
|
+
|
|
107
|
+
assert.equal(freshnessSignals({ updatedAt: daysAgo(89) }, { now: NOW, freshnessDays: 90 }).stale, false)
|
|
108
|
+
assert.equal(freshnessSignals({ updatedAt: daysAgo(90) }, { now: NOW, freshnessDays: 90 }).stale, true)
|
|
109
|
+
|
|
110
|
+
// An unusable threshold falls back to 30, not to "everything is stale".
|
|
111
|
+
assert.equal(freshnessSignals({ updatedAt: daysAgo(31) }, { now: NOW, freshnessDays: NaN }).stale, true)
|
|
112
|
+
assert.equal(freshnessSignals({ updatedAt: daysAgo(29) }, { now: NOW, freshnessDays: 'nope' }).stale, false)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('signals compose and the reasons list names every one of them', () => {
|
|
116
|
+
const all = freshnessSignals({
|
|
117
|
+
title: '最新价格',
|
|
118
|
+
content: '汇率也变了。',
|
|
119
|
+
salientDate: '2026-11-01',
|
|
120
|
+
updatedAt: daysAgo(60),
|
|
121
|
+
}, { now: NOW })
|
|
122
|
+
assert.equal(all.stale, true)
|
|
123
|
+
assert.deepEqual(all.reasons, [
|
|
124
|
+
'dated-past:2026-11-01',
|
|
125
|
+
'freshness-term:最新',
|
|
126
|
+
'freshness-term:价格',
|
|
127
|
+
'freshness-term:汇率',
|
|
128
|
+
'age-days:60',
|
|
129
|
+
])
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('bad entries and bad clocks never throw', () => {
|
|
133
|
+
for (const value of [null, undefined, 42, 'memory']) {
|
|
134
|
+
assert.deepEqual(freshnessSignals(value), { stale: false, reasons: [] })
|
|
135
|
+
}
|
|
136
|
+
for (const now of [NaN, 'not-a-date', new Date(NaN)]) {
|
|
137
|
+
const result = freshnessSignals({ updatedAt: '2000-01-01T00:00:00Z' }, { now })
|
|
138
|
+
assert.equal(result.stale, true, `now=${String(now)} must fall back to the wall clock`)
|
|
139
|
+
}
|
|
140
|
+
})
|
package/tests/help-page.test.mjs
CHANGED
|
@@ -231,7 +231,7 @@ test('the deep link #/settings/help lands on the help page when standalone', asy
|
|
|
231
231
|
window.location.hash = ''
|
|
232
232
|
})
|
|
233
233
|
|
|
234
|
-
test('the help page shows five steps,
|
|
234
|
+
test('the help page shows five steps, eleven FAQ details and the feedback actions', async () => {
|
|
235
235
|
const component = settingsComponent()
|
|
236
236
|
const props = { ctx: fakeCtx(), t: (key) => key }
|
|
237
237
|
await mountAndSettle(component, props)
|
|
@@ -240,7 +240,7 @@ test('the help page shows five steps, ten FAQ details and the feedback actions',
|
|
|
240
240
|
const { tree } = renderAt(component, props, 12)
|
|
241
241
|
const text = treeText(tree)
|
|
242
242
|
for (const step of [1, 2, 3, 4, 5]) assert.ok(text.includes(`helpStep${step}`), `quick start step ${step} is missing`)
|
|
243
|
-
for (const n of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) {
|
|
243
|
+
for (const n of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) {
|
|
244
244
|
assert.ok(text.includes(`helpFaq${n}`), `FAQ item ${n} is missing`)
|
|
245
245
|
assert.ok(text.includes(`helpFaq${n}A`), `FAQ answer ${n} is missing`)
|
|
246
246
|
}
|
|
@@ -248,13 +248,13 @@ test('the help page shows five steps, ten FAQ details and the feedback actions',
|
|
|
248
248
|
assert.ok(text.includes('helpOpenIssue'), 'the issue button is missing')
|
|
249
249
|
assert.ok(text.includes('helpCopyDiagnostics'), 'the copy-diagnostics button is missing')
|
|
250
250
|
assert.ok(text.includes('helpDocs'), 'the docs link is missing')
|
|
251
|
-
// FAQ 用
|
|
251
|
+
// FAQ 用 11 个 <details> 折叠;quick start 的每一步都带「前往 →」跳转按钮
|
|
252
252
|
//(第 2 步是会话侧动作,只给文案,不带跳转 → 4 个按钮)。
|
|
253
253
|
const details = []
|
|
254
254
|
walkNodes(tree, (node) => {
|
|
255
255
|
if (node.type === 'details') details.push(node)
|
|
256
256
|
})
|
|
257
|
-
assert.equal(details.length,
|
|
257
|
+
assert.equal(details.length, 11, `expected eleven FAQ details, found ${details.length}`)
|
|
258
258
|
assert.equal((text.match(/helpGoTo/g) || []).length, 4, 'four of the five steps jump, the bind step cannot')
|
|
259
259
|
// 不新增 RPC:复制诊断只序列化 getSettingsState 的既有快照(state 优先,缺了才补拉)。
|
|
260
260
|
const src = clientSource
|