dsh-memu-memory 1.3.2 → 1.3.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.
@@ -230,6 +230,99 @@ test('the settings page renders every page instead of a blank panel', async () =
230
230
  }
231
231
  })
232
232
 
233
+ test('the immersive graph shell stays with the standalone WebUI', async () => {
234
+ // 点「关系图谱」把宿主页面的导航条掰成 158px 竖排,是 is-graph-wide 没分外壳造成的:
235
+ // 那套样式是为独立 WebUI 的全屏画布写的,宿主设置页只需要普通横排导航 + 一个入口按钮。
236
+ const ctx = fakeCtx()
237
+ globalThis.__dshMemuExports.apply(ctx)
238
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
239
+ assert.ok(settings?.component, 'settings.section was not registered')
240
+ const GRAPH_PAGE = 10
241
+
242
+ // The standalone shell resolves its page from the hash, so there is no
243
+ // numeric-zero page state to force on; the host shell has one.
244
+ const shell = async (props, { fromHash = false } = {}) => {
245
+ const first = await renderPage(settings.component, props, undefined, { remount: true })
246
+ if (!fromHash) collectPageHook()
247
+ for (const effect of first.effects) effect.fn()
248
+ await new Promise((resolve) => setTimeout(resolve, 0))
249
+ return (await renderPage(settings.component, props, fromHash ? undefined : GRAPH_PAGE)).tree
250
+ }
251
+
252
+ const inHost = await shell({ ctx, t: (key) => key })
253
+ assert.match(String(inHost.props?.className), /dshm-root/, 'the host graph page lost its shell')
254
+ assert.ok(!/is-graph-wide/.test(String(inHost.props?.className)),
255
+ `the host settings page must keep its horizontal rail, saw "${inHost.props?.className}"`)
256
+ const buttons = []
257
+ walkNodes(inHost, (node) => { if (node.type === 'button' && node.props?.children === 'openGraphStudio') buttons.push(node) })
258
+ assert.equal(buttons.length, 1, 'the host graph page should offer exactly one entry into the studio')
259
+ assert.equal(typeof buttons[0].props.onClick, 'function', 'the entry button has no handler')
260
+
261
+ const inWebUi = await withHash('#/settings/graph', () => shell({ ctx, t: (key) => key, standalone: true }, { fromHash: true }))
262
+ assert.match(String(inWebUi.props?.className), /is-graph-wide/, 'the standalone graph page lost its immersive shell')
263
+ })
264
+
265
+ test('the manual consolidation button rides the sidebar channel, not a new RPC', async () => {
266
+ // 「立即整理」刻意不新增方法:它查 listSessions 的库绑定,再对每个绑定会话调用
267
+ // 侧边栏同一个 generatePrivate。多一个只给 UI 用的整理方法,就等于多一条模型也能
268
+ // 调用的写路径。
269
+ const rpcCalls = []
270
+ const ctx = fakeCtx({
271
+ rpcCalls,
272
+ answers: {
273
+ getState: { ...RPC_ANSWERS.getState, libraries: [{ id: 'lib-1', name: 'L1', privateCount: 3, pinnedCount: 0, boundSessions: 2 }] },
274
+ getSettingsState: { ...RPC_ANSWERS.getSettingsState, libraries: [{ id: 'lib-1', name: 'L1', privateCount: 3, pinnedCount: 0, boundSessions: 2 }] },
275
+ listSessions: { sessions: [
276
+ { id: 's1', libraryId: 'lib-1' }, { id: 's2', libraryId: 'lib-1' }, { id: 's3', libraryId: 'lib-2' },
277
+ ] },
278
+ generatePrivate: { ok: true },
279
+ },
280
+ })
281
+ globalThis.__dshMemuExports.apply(ctx)
282
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
283
+ const props = { ctx, t: (key) => key }
284
+ const LIBRARIES_PAGE = 4
285
+ const render = async (page, remount = false) => renderPage(settings.component, props, page, { remount })
286
+ const first = await render(undefined, true)
287
+ collectPageHook()
288
+ for (const effect of first.effects) effect.fn()
289
+ await new Promise((resolve) => setTimeout(resolve, 0))
290
+ const second = await render(LIBRARIES_PAGE)
291
+ for (const effect of second.effects) effect.fn()
292
+ await new Promise((resolve) => setTimeout(resolve, 0))
293
+ const tree = (await render(LIBRARIES_PAGE)).tree
294
+
295
+ const buttons = []
296
+ walkNodes(tree, (node) => { if (node.type === 'button' && node.props?.children === 'consolidateNow') buttons.push(node) })
297
+ assert.equal(buttons.length, 1, 'the library row lost its 立即整理 button')
298
+ rpcCalls.length = 0
299
+ await buttons[0].props.onClick()
300
+ assert.deepEqual(rpcCalls, [], 'the first click must only arm the confirmation')
301
+ const armed = []
302
+ walkNodes((await render(LIBRARIES_PAGE)).tree, (node) => { if (node.type === 'button' && node.props?.children === 'confirmAction') armed.push(node) })
303
+ assert.equal(armed.length, 1, 'the arming state did not reach the button label')
304
+ await armed[0].props.onClick()
305
+ for (let i = 0; i < 4; i++) await new Promise((resolve) => setTimeout(resolve, 0))
306
+ assert.deepEqual(rpcCalls.map((c) => [c.endpoint, c.payload]), [
307
+ ['listSessions', { limit: 200 }],
308
+ ['generatePrivate', { sessionId: 's1' }],
309
+ ['generatePrivate', { sessionId: 's2' }],
310
+ ], 'consolidation must hit only the sessions bound to that library')
311
+ })
312
+
313
+ // The standalone shell reads `window.location.hash` to pick its page and rewrites
314
+ // it as the user navigates, which the host-side fixture never provides.
315
+ async function withHash(hash, run) {
316
+ const original = globalThis.window.location
317
+ const originalHistory = globalThis.window.history
318
+ globalThis.window.location = { ...original, hash }
319
+ globalThis.window.history = { ...originalHistory, replaceState: () => {} }
320
+ try { return await run() } finally {
321
+ globalThis.window.location = original
322
+ globalThis.window.history = originalHistory
323
+ }
324
+ }
325
+
233
326
  test('the sidebar tab renders with the two-layer header', async () => {
234
327
  const ctx = fakeCtx()
235
328
  const tab = registrations.find((r) => r.slot === 'sidebar.right.pane.tab')
@@ -397,6 +490,84 @@ test('the memory browser badges what a memory is allowed to say', async () => {
397
490
  }
398
491
  })
399
492
 
493
+ test('the browse search box filters the loaded library in place', async () => {
494
+ // 搜索是纯前端的:它只过滤已经拉回来的那一页,不新发 RPC。库一切换就清空,
495
+ // 否则上一个库的关键词会把当前库筛成「空库」。
496
+ const originalGetState = RPC_ANSWERS.getState
497
+ const originalSettingsState = RPC_ANSWERS.getSettingsState
498
+ const loaded = { ...EMPTY_STATE, libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 2 }] }
499
+ RPC_ANSWERS.getState = loaded
500
+ RPC_ANSWERS.getSettingsState = loaded
501
+ RPC_ANSWERS.browseLibrary = {
502
+ source: 'engine',
503
+ files: [
504
+ { id: 'mem-attic', title: 'the attic', content: 'he never told his brother', layer: 'long_term', status: 'active', decay: .5 },
505
+ { id: 'mem-loud', title: 'shared fact', content: 'anything', layer: 'long_term', status: 'active', decay: .9 },
506
+ ],
507
+ }
508
+ try {
509
+ const rpcCalls = []
510
+ const ctx = fakeCtx({ rpcCalls })
511
+ globalThis.__dshMemuExports.apply(ctx)
512
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
513
+ const props = { ctx, t: (key) => key }
514
+ const render = (page, remount = false) => renderPage(settings.component, props, page, { remount })
515
+ const first = await render(undefined, true)
516
+ collectPageHook()
517
+ for (const effect of first.effects) effect.fn()
518
+ await new Promise((resolve) => setTimeout(resolve, 0))
519
+ let tree = (await render(5)).tree
520
+ const picker = []
521
+ walkNodes(tree, (node) => {
522
+ const options = Array.isArray(node.props?.children) ? node.props.children : []
523
+ if (node.type === 'select' && options.some((option) => option?.props?.value === 'lib-1')) picker.push(node)
524
+ })
525
+ picker[0].props.onChange({ target: { value: 'lib-1' } })
526
+ tree = (await render(5)).tree
527
+ const reload = []
528
+ walkNodes(tree, (node) => { if (node.type === 'button' && node.props?.children === 'reload') reload.push(node) })
529
+ reload[0].props.onClick()
530
+ for (let i = 0; i < 3; i++) await new Promise((resolve) => setTimeout(resolve, 0))
531
+ tree = (await render(5)).tree
532
+
533
+ // Rows carry their title in an editor input, so counting rendered values beats
534
+ // grepping the flattened tree.
535
+ const snapshot = (node) => {
536
+ const titles = []
537
+ let rows = 0
538
+ walkNodes(node, (n) => {
539
+ if (n.type === 'button' && n.props?.children === 'archive') rows++
540
+ if (n.type === 'input' && (n.props?.value === 'the attic' || n.props?.value === 'shared fact')) titles.push(n.props.value)
541
+ })
542
+ return { rows, titles }
543
+ }
544
+
545
+ const before = snapshot(tree)
546
+ assert.deepEqual(before, { rows: 2, titles: ['the attic', 'shared fact'] }, 'both rows render before filtering')
547
+ rpcCalls.length = 0
548
+ const box = []
549
+ walkNodes(tree, (node) => { if (node.type === 'input' && node.props?.placeholder === 'browseSearchPlaceholder') box.push(node) })
550
+ assert.equal(box.length, 1, 'no search box under 当前记忆库')
551
+ box[0].props.onChange({ target: { value: 'attic' } })
552
+ const filteredTree = (await render(5)).tree
553
+ assert.deepEqual(snapshot(filteredTree), { rows: 1, titles: ['the attic'] }, 'the filter keeps only the matching row')
554
+ assert.match(treeText(filteredTree), /1 \/ 2/, 'the counter says how much of the library the filter kept')
555
+ assert.match(treeText(filteredTree), /browseActiveTab \(1\)/, 'the tab counts follow the filter, not the whole library')
556
+ assert.deepEqual(rpcCalls, [], 'filtering an already loaded library must not re-fetch it')
557
+ box[0].props.onChange({ target: { value: 'no-such-memory' } })
558
+ assert.match(treeText((await render(5)).tree), /browseActiveTab \(0\)/, 'a query that matches nothing empties the tab counts')
559
+ const clear = []
560
+ walkNodes((await render(5)).tree, (node) => { if (node.type === 'button' && node.props?.children === 'browseSearchClear') clear.push(node) })
561
+ assert.equal(clear.length, 1, 'no way to clear the query')
562
+ clear[0].props.onClick()
563
+ assert.deepEqual(snapshot((await render(5)).tree), before, 'clearing the query brings the library back')
564
+ } finally {
565
+ RPC_ANSWERS.getState = originalGetState
566
+ RPC_ANSWERS.getSettingsState = originalSettingsState
567
+ delete RPC_ANSWERS.browseLibrary
568
+ }
569
+ })
570
+
400
571
  test('the WebUI buttons open a new tab and never navigate this one', async () => {
401
572
  const opened = []
402
573
  const navigated = []
@@ -102,6 +102,31 @@ test('pin/unpin/relayout/unpinAll keep the physics state coherent', () => {
102
102
  layout.dispose()
103
103
  })
104
104
 
105
+ test('relayout cools down and separates instead of shoving nodes forever', () => {
106
+ // 「缩到最小 → 重新布局 → 打架」的回归:硬分离阈值以前写成 24 / viewScale,
107
+ // k≈.06 时等于要求 400 世界像素间距,每帧互推、永不收敛。现在只看半径,
108
+ // 物理也拿不到相机(setScale 已删),缩放再小也不会改变力的量级。
109
+ assert.equal('setScale' in createForceLayout(), false, 'the physics must never be handed the camera scale')
110
+ const layout = createForceLayout()
111
+ layout.update(graph(60))
112
+ layout.relayout()
113
+ let previous = Infinity
114
+ for (let window = 0; window < 6; window++) {
115
+ const before = layout.nodes.map(node => [node.x, node.y])
116
+ for (let i = 0; i < 20; i++) layout.tick()
117
+ let maxMove = 0
118
+ layout.nodes.forEach((node, i) => { maxMove = Math.max(maxMove, Math.hypot(node.x - before[i][0], node.y - before[i][1])) })
119
+ assert.ok(maxMove < previous, `window ${window} must move less than the one before (${maxMove} >= ${previous})`)
120
+ previous = maxMove
121
+ }
122
+ assert.ok(previous < 4, `a cooled relayout must stop shoving, saw ${previous}px per window`)
123
+ for (let i = 0; i < layout.nodes.length; i++) for (let j = i + 1; j < layout.nodes.length; j++) {
124
+ const a = layout.nodes[i], b = layout.nodes[j]
125
+ assert.ok(Math.hypot(a.x - b.x, a.y - b.y) > a.radius + b.radius, 'relayout must not leave nodes overlapping')
126
+ }
127
+ layout.dispose()
128
+ })
129
+
105
130
  test('configure maps all three force sliders and reheats without ever going non-finite', () => {
106
131
  assert.equal(DEFAULT_OPTIONS.center, 0, 'center force is off by default')
107
132
  assert.equal(DEFAULT_OPTIONS.clusterScope, true)
@@ -164,11 +189,11 @@ test('drag scope freezes other clusters and repels the dragged one from them', (
164
189
 
165
190
  function harness(reducedMotion = true) {
166
191
  const handlers = new Map(), windowHandlers = new Map(), frames = new Map(), arcs = [], focuses = [], texts = []
167
- let id = 0
192
+ let id = 0, paints = 0
168
193
  const ctx = new Proxy({
169
194
  arc(x, y, radius) { arcs.push({ x, y, radius }) },
170
195
  measureText(text) { return { width: text.length * 7 } },
171
- clearRect() { arcs.length = 0; texts.length = 0 },
196
+ clearRect() { paints++; arcs.length = 0; texts.length = 0 },
172
197
  fillText(text) { texts.push(String(text)) },
173
198
  }, { get(target, key) { return key in target ? target[key] : () => {} } })
174
199
  const win = {
@@ -198,7 +223,7 @@ function harness(reducedMotion = true) {
198
223
  const emit = (type, x, y, extra = {}) => handlers.get(type)?.({
199
224
  type, clientX: x, clientY: y, button: 0, pointerId: 1, pointerType: 'mouse', preventDefault() {}, ...extra,
200
225
  })
201
- return { view, flush, emit, arcs, texts, frames, focuses, handlers, windowHandlers }
226
+ return { view, flush, emit, arcs, texts, frames, focuses, handlers, windowHandlers, getPaints: () => paints }
202
227
  }
203
228
 
204
229
  test('the detailed layer actually paints labels and the label switch silences them', () => {
@@ -298,6 +323,38 @@ test('pinch does not trigger focus and reduced-motion/paused views do not run an
298
323
  paused.view.dispose()
299
324
  })
300
325
 
326
+ // GPU 守卫:动效开着也不能在冷却后空转重绘(曾经的实现是 30fps 永久整幅重绘)。
327
+ test('a cooled layout stops requesting frames even while motion is enabled', () => {
328
+ const h = harness(false)
329
+ h.view.update(graph(60))
330
+ for (let i = 0; i < 900 && h.frames.size; i++) h.flush()
331
+ assert.equal(h.frames.size, 0, 'a settled layout must not keep a rAF loop alive')
332
+ const painted = h.getPaints()
333
+ for (let i = 0; i < 200; i++) h.flush()
334
+ assert.equal(h.getPaints(), painted, 'idle time must not repaint the canvas')
335
+ h.view.zoom(1.2)
336
+ assert.equal(h.frames.size, 1, 'an interaction schedules exactly one repaint')
337
+ h.flush()
338
+ assert.equal(h.frames.size, 0, 'that repaint must not restart the loop')
339
+ h.view.dispose()
340
+ })
341
+
342
+ // 极小缩放下两颗节点可能只差 2-3px:纯最近邻会随鼠标 1px 抖动来回换人,
343
+ // 高亮反复切换就是用户看到的「节点互相打架闪现」。
344
+ test('hover keeps its target through 1px jitter at minimum zoom', () => {
345
+ const h = harness()
346
+ h.view.update(graph(2)); h.flush()
347
+ h.view.zoom(.05); h.flush()
348
+ const p = { ...h.arcs[0] }
349
+ const before = h.getPaints()
350
+ h.emit('pointermove', p.x, p.y); h.flush()
351
+ const first = h.getPaints()
352
+ assert.ok(first > before, 'hovering a node must repaint once')
353
+ h.emit('pointermove', p.x + 1, p.y + 1); h.flush()
354
+ assert.equal(h.getPaints(), first, 'a 1px nudge must not flip the hover target')
355
+ h.view.dispose()
356
+ })
357
+
301
358
  test('Escape cancels a drag and clears the focus; toolbar actions do not throw', () => {
302
359
  const h = harness()
303
360
  h.view.update(graph(3)); h.flush()