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
|
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
|
|
|
3
3
|
import vm from 'node:vm'
|
|
4
4
|
import fs from 'node:fs'
|
|
5
5
|
import { createForceLayout, createGraphView, DEFAULT_OPTIONS, fitCamera, zoomCamera, placeLabels } from '../lib/webui/graph-view.js'
|
|
6
|
+
import { denseGraph, graphGeometry } from '../scripts/graph-geometry-fixture.mjs'
|
|
6
7
|
|
|
7
8
|
const graph = (count, connected = true) => ({
|
|
8
9
|
nodes: Array.from({ length: count }, (_, i) => ({ id: `n${String(i).padStart(3, '0')}`, title: `Memory ${i}`, kind: 'memory', strength: .5 })),
|
|
@@ -25,6 +26,23 @@ test('layout preserves object identity, positions and cooling on equivalent refr
|
|
|
25
26
|
layout.dispose()
|
|
26
27
|
})
|
|
27
28
|
|
|
29
|
+
test('a mostly-fresh classic refresh cannot reset an active local drag position or journal', () => {
|
|
30
|
+
const layout = createForceLayout({ workerThreshold: 5 })
|
|
31
|
+
layout.update({ ...graph(5), mode: 'classic' })
|
|
32
|
+
const session = layout.beginLocalDrag('n000')
|
|
33
|
+
layout.moveLocalDrag(500, 350)
|
|
34
|
+
const root = layout.nodeById('n000')
|
|
35
|
+
assert.deepEqual([root.x, root.y], [500, 350])
|
|
36
|
+
layout.update({ ...graph(25), mode: 'classic' })
|
|
37
|
+
assert.equal(layout.localSession, session)
|
|
38
|
+
assert.deepEqual([root.x, root.y, root.fx, root.fy], [500, 350, 500, 350],
|
|
39
|
+
'the incoming snapshot must not rerun layoutFlower over the held node')
|
|
40
|
+
layout.cancelLocalDrag()
|
|
41
|
+
assert.equal(root.x, session.saved.get(root).x)
|
|
42
|
+
assert.equal(root.y, session.saved.get(root).y)
|
|
43
|
+
layout.dispose()
|
|
44
|
+
})
|
|
45
|
+
|
|
28
46
|
test('disconnected 200-node layout stays finite, separated and framed without boundary clamping', () => {
|
|
29
47
|
const layout = createForceLayout()
|
|
30
48
|
layout.update(graph(200, false)); layout.settle(300)
|
|
@@ -64,6 +82,49 @@ test('zoom keeps the cursor world point fixed and clamps extreme scales', () =>
|
|
|
64
82
|
}
|
|
65
83
|
})
|
|
66
84
|
|
|
85
|
+
test('classic graphs above the worker threshold use the original circular layout and keep every node at minimum zoom', () => {
|
|
86
|
+
const data = { ...graph(3405, false), mode: 'classic' }
|
|
87
|
+
const h = harness()
|
|
88
|
+
h.view.update(data); h.flush()
|
|
89
|
+
const positions = h.view.snapshot()
|
|
90
|
+
assert.equal(positions.length, data.nodes.length)
|
|
91
|
+
assert.ok(new Set(positions.map(node => node.worldX)).size > 1000, 'positions must not form the new rectangular grid')
|
|
92
|
+
assert.equal(h.view.diagnostics().workerPending, false, 'the grid prelayout worker must not overwrite the circular layout')
|
|
93
|
+
assert.ok(positions.every(node => node.x > 10 && node.x < 590 && node.y > 10 && node.y < 390))
|
|
94
|
+
h.view.zoom(1e-9); h.flush()
|
|
95
|
+
assert.equal(h.view.snapshot().length, data.nodes.length)
|
|
96
|
+
assert.equal(h.arcs.length, data.nodes.length, 'distant nodes remain visible circular points')
|
|
97
|
+
h.view.update(structuredClone(data)); h.flush()
|
|
98
|
+
assert.deepEqual(h.view.snapshot().map(node => [node.worldX, node.worldY]), positions.map(node => [node.worldX, node.worldY]))
|
|
99
|
+
h.view.dispose()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('classic fit and minimum zoom can frame a graph larger than the old fixed zoom floor', () => {
|
|
103
|
+
const h = harness(), data = { mode: 'classic', nodes: [
|
|
104
|
+
{ id: 'left', kind: 'memory', x: -100000, y: 0 }, { id: 'right', kind: 'person', x: 100000, y: 0 },
|
|
105
|
+
], edges: [] }
|
|
106
|
+
h.view.update(data); h.flush()
|
|
107
|
+
const fitted = h.view.snapshot(), saved = h.view.viewport()
|
|
108
|
+
assert.ok(saved.zoom < .06)
|
|
109
|
+
assert.ok(fitted.every(node => node.x >= 40 && node.x <= 560))
|
|
110
|
+
h.view.zoom(1e-9); h.flush()
|
|
111
|
+
assert.ok(h.view.snapshot().every(node => node.x > 100 && node.x < 500))
|
|
112
|
+
assert.equal(h.view.setViewport(saved), true)
|
|
113
|
+
assert.deepEqual(h.view.snapshot(), fitted)
|
|
114
|
+
h.emit('pointerdown', fitted[0].x + 5, fitted[0].y)
|
|
115
|
+
h.emit('pointerup', fitted[0].x + 5, fitted[0].y)
|
|
116
|
+
assert.deepEqual(h.focuses, ['left'], 'screen hit targets remain usable below the old zoom floor')
|
|
117
|
+
h.view.dispose()
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('small classic graphs retain the original flower layout and settling behavior', () => {
|
|
121
|
+
const data = graph(30), old = harness(), classic = harness()
|
|
122
|
+
old.view.update(data); classic.view.update({ ...data, overview: true, mode: 'classic' })
|
|
123
|
+
old.flush(); classic.flush()
|
|
124
|
+
assert.deepEqual(classic.view.snapshot(), old.view.snapshot())
|
|
125
|
+
old.view.dispose(); classic.view.dispose()
|
|
126
|
+
})
|
|
127
|
+
|
|
67
128
|
test('labels neither overlap each other nor node obstacles and remain inside canvas', () => {
|
|
68
129
|
const candidates = Array.from({ length: 50 }, (_, i) => ({
|
|
69
130
|
x: 40 + i % 8 * 40, y: 40 + Math.floor(i / 8) * 40, radius: 5, textWidth: 90,
|
|
@@ -187,7 +248,7 @@ test('drag scope freezes other clusters and repels the dragged one from them', (
|
|
|
187
248
|
layout.dispose()
|
|
188
249
|
})
|
|
189
250
|
|
|
190
|
-
function harness(reducedMotion = true) {
|
|
251
|
+
function harness(reducedMotion = true, controllerOptions = {}, createView = createGraphView) {
|
|
191
252
|
const handlers = new Map(), windowHandlers = new Map(), frames = new Map(), arcs = [], focuses = [], texts = []
|
|
192
253
|
let id = 0, paints = 0
|
|
193
254
|
const ctx = new Proxy({
|
|
@@ -215,15 +276,17 @@ function harness(reducedMotion = true) {
|
|
|
215
276
|
addEventListener(type, fn) { handlers.set(type, fn) },
|
|
216
277
|
removeEventListener(type) { handlers.delete(type) },
|
|
217
278
|
}
|
|
218
|
-
const view =
|
|
219
|
-
|
|
279
|
+
const view = createView(canvas, { onFocus: id => focuses.push(id), reducedMotion, ...controllerOptions })
|
|
280
|
+
let frameTime = 0
|
|
281
|
+
const flush = (elapsed = 1000 / 60) => {
|
|
220
282
|
const pending = [...frames.values()]; frames.clear()
|
|
221
|
-
|
|
283
|
+
frameTime += elapsed
|
|
284
|
+
for (const fn of pending) fn(frameTime)
|
|
222
285
|
}
|
|
223
286
|
const emit = (type, x, y, extra = {}) => handlers.get(type)?.({
|
|
224
287
|
type, clientX: x, clientY: y, button: 0, pointerId: 1, pointerType: 'mouse', preventDefault() {}, ...extra,
|
|
225
288
|
})
|
|
226
|
-
return { view, flush, emit, arcs, texts, frames, focuses, handlers, windowHandlers, getPaints: () => paints }
|
|
289
|
+
return { view, flush, emit, arcs, texts, frames, focuses, handlers, windowHandlers, canvas, getPaints: () => paints }
|
|
227
290
|
}
|
|
228
291
|
|
|
229
292
|
test('view snapshots retain multiple clusters and entities beyond the first 200 nodes', () => {
|
|
@@ -290,6 +353,77 @@ test('left drag never locks the node; right click toggles the pin; refresh prese
|
|
|
290
353
|
assert.equal(h.handlers.size, 0); assert.equal(h.frames.size, 0); assert.equal(h.windowHandlers.size, 0)
|
|
291
354
|
})
|
|
292
355
|
|
|
356
|
+
test('ordinary node drag elastically moves its flower component and anchors only the grabbed node', () => {
|
|
357
|
+
const h = harness(true)
|
|
358
|
+
h.view.update(graph(30)); h.flush()
|
|
359
|
+
const before = h.view.snapshot(), root = before.find(node => node.id === 'n000')
|
|
360
|
+
h.emit('pointerdown', root.x, root.y)
|
|
361
|
+
h.emit('pointermove', root.x + 46, root.y + 24)
|
|
362
|
+
h.flush()
|
|
363
|
+
h.emit('pointerup', root.x + 46, root.y + 24); h.flush()
|
|
364
|
+
const after = new Map(h.view.snapshot().map(node => [node.id, node]))
|
|
365
|
+
const moved = before.filter(node => node.id !== 'n000'
|
|
366
|
+
&& Math.hypot(after.get(node.id).worldX - node.worldX, after.get(node.id).worldY - node.worldY) > .01)
|
|
367
|
+
assert.ok(moved.length > 0, 'connected neighbors should follow through their springs')
|
|
368
|
+
assert.equal(after.get('n000').anchored, true)
|
|
369
|
+
assert.equal(after.get('n000').pinned, false, 'left drag is an anchor, not an explicit right-click pin')
|
|
370
|
+
assert.equal(after.get('n000').positionFixed, true)
|
|
371
|
+
assert.ok(after.size > 1 && [...after.values()].filter(node => node.positionFixed).length === 1,
|
|
372
|
+
'the component remains flexible and only the drop is fixed')
|
|
373
|
+
h.view.dispose()
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
test('lost pointer capture does not cancel a held drag before pointerup', () => {
|
|
377
|
+
const h = harness(true)
|
|
378
|
+
h.view.update(graph(20)); h.flush()
|
|
379
|
+
const root = h.view.snapshot().find(node => node.id === 'n000')
|
|
380
|
+
h.emit('pointerdown', root.x, root.y)
|
|
381
|
+
h.emit('pointermove', root.x + 20, root.y + 10)
|
|
382
|
+
h.emit('lostpointercapture', root.x + 20, root.y + 10, { buttons: 1, pressure: .5 })
|
|
383
|
+
h.emit('pointermove', root.x + 42, root.y + 18)
|
|
384
|
+
h.emit('pointerup', root.x + 42, root.y + 18)
|
|
385
|
+
const drop = h.view.snapshot().find(node => node.id === 'n000')
|
|
386
|
+
assert.equal(drop.x, root.x + 42)
|
|
387
|
+
assert.equal(drop.y, root.y + 18)
|
|
388
|
+
assert.equal(drop.anchored, true)
|
|
389
|
+
assert.deepEqual(h.focuses, [])
|
|
390
|
+
h.view.dispose()
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
test('window pointer fallback completes a drag when recapturing the pointer fails', () => {
|
|
394
|
+
const h = harness(true)
|
|
395
|
+
h.view.update(graph(600)); h.flush()
|
|
396
|
+
const root = h.view.snapshot().find(node => node.id === 'n000')
|
|
397
|
+
h.emit('pointerdown', root.x, root.y)
|
|
398
|
+
h.emit('pointermove', root.x + 20, root.y + 10)
|
|
399
|
+
h.canvas.setPointerCapture = () => { throw new Error('capture unavailable') }
|
|
400
|
+
h.canvas.releasePointerCapture(1)
|
|
401
|
+
h.emit('lostpointercapture', root.x + 20, root.y + 10, { buttons: 1, pressure: .5 })
|
|
402
|
+
const event = (type, x, y) => ({ type, clientX: x, clientY: y, button: 0, buttons: 1, pointerId: 1,
|
|
403
|
+
pointerType: 'mouse', pressure: .5, preventDefault() {} })
|
|
404
|
+
h.windowHandlers.get('pointermove')(event('pointermove', root.x + 38, root.y + 16))
|
|
405
|
+
h.windowHandlers.get('pointerup')(event('pointerup', root.x + 38, root.y + 16))
|
|
406
|
+
const drop = h.view.snapshot().find(node => node.id === 'n000')
|
|
407
|
+
assert.equal(drop.x, root.x + 38)
|
|
408
|
+
assert.equal(drop.y, root.y + 16)
|
|
409
|
+
assert.equal(drop.anchored, true)
|
|
410
|
+
h.flush()
|
|
411
|
+
assert.equal(h.frames.size, 0, 'reduced-motion local physics completes synchronously without a frame loop')
|
|
412
|
+
h.view.dispose()
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
test('changing graph position scope cancels the old gesture before same-id nodes are replaced', () => {
|
|
416
|
+
const h = harness(true), first = { ...graph(30), positionScope: 'scope-a' }
|
|
417
|
+
h.view.update(first); h.flush()
|
|
418
|
+
const root = h.view.snapshot().find(node => node.id === 'n000')
|
|
419
|
+
h.emit('pointerdown', root.x, root.y); h.emit('pointermove', root.x + 60, root.y + 30)
|
|
420
|
+
h.view.update({ ...graph(30), positionScope: 'scope-b' }); h.flush()
|
|
421
|
+
const fresh = h.view.snapshot()
|
|
422
|
+
h.emit('keydown', 0, 0, { key: 'Escape' }); h.flush()
|
|
423
|
+
assert.deepEqual(h.view.snapshot(), fresh, 'Escape must not replay a prior scope journal into the new graph')
|
|
424
|
+
h.view.dispose()
|
|
425
|
+
})
|
|
426
|
+
|
|
293
427
|
test('dragging an already pinned node keeps the lock at the new position', () => {
|
|
294
428
|
const h = harness()
|
|
295
429
|
h.view.update(graph(1)); h.flush()
|
|
@@ -319,6 +453,164 @@ test('pan/zoom and equivalent refresh never re-fit the camera; cancelled pointer
|
|
|
319
453
|
h.view.dispose()
|
|
320
454
|
})
|
|
321
455
|
|
|
456
|
+
test('setViewport restores a real camera snapshot silently and preserves scoped pins and anchors', () => {
|
|
457
|
+
const events = [], zooms = [], h = harness(true, { onViewport: value => events.push(value), onZoom: value => zooms.push(value) })
|
|
458
|
+
const data = { ...graph(3, false), positionScope: 'camera-scope' }
|
|
459
|
+
data.nodes.forEach((node, i) => { node.x = i * 100; node.y = 0 })
|
|
460
|
+
h.view.update(data); h.flush()
|
|
461
|
+
const [pin, anchor] = h.view.snapshot()
|
|
462
|
+
h.emit('contextmenu', pin.x, pin.y); h.flush()
|
|
463
|
+
h.emit('pointerdown', anchor.x, anchor.y); h.emit('pointermove', anchor.x + 30, anchor.y + 10)
|
|
464
|
+
h.emit('pointerup', anchor.x + 30, anchor.y + 10)
|
|
465
|
+
for (let i = 0; i < 60 && h.frames.size; i++) h.flush()
|
|
466
|
+
const saved = h.view.viewport(), expected = h.view.snapshot()
|
|
467
|
+
assert.equal(expected[0].pinned, true); assert.equal(expected[1].anchored, true)
|
|
468
|
+
h.view.update({ ...data, nodes: data.nodes.slice(0, 1) }); h.view.fit(); h.flush()
|
|
469
|
+
h.view.update(data); h.view.zoom(.5); h.flush()
|
|
470
|
+
const before = h.view.snapshot(), diagnostics = h.view.diagnostics(), count = events.length, paints = h.getPaints()
|
|
471
|
+
assert.equal(h.view.setViewport(saved), true)
|
|
472
|
+
assert.deepEqual(h.view.diagnostics(), diagnostics, 'camera restore cannot reset or reheat physics')
|
|
473
|
+
assert.equal(events.length, count, 'restore cannot echo onViewport and refetch the graph')
|
|
474
|
+
assert.equal(zooms.at(-1), saved.zoom)
|
|
475
|
+
const restored = h.view.snapshot()
|
|
476
|
+
restored.forEach((node, i) => {
|
|
477
|
+
assert.ok(Math.hypot(node.x - expected[i].x, node.y - expected[i].y) < 1e-8)
|
|
478
|
+
for (const key of ['worldX', 'worldY', 'positionFixed', 'anchored', 'pinned']) assert.equal(node[key], before[i][key])
|
|
479
|
+
})
|
|
480
|
+
assert.equal(h.frames.size, 1); h.flush()
|
|
481
|
+
assert.equal(h.getPaints(), paints + 1); assert.equal(h.frames.size, 0)
|
|
482
|
+
assert.equal(h.view.setViewport(h.view.viewport()), true)
|
|
483
|
+
assert.equal(h.frames.size, 0, 'an identical snapshot is a no-op')
|
|
484
|
+
h.view.update(data); h.flush()
|
|
485
|
+
assert.deepEqual(h.view.snapshot(), restored, 'same-scope refresh retains positions after restoring the camera')
|
|
486
|
+
h.view.update({ ...data, positionScope: 'different-permission' }); h.flush()
|
|
487
|
+
assert.equal(h.view.pinnedCount(), 0, 'camera restore cannot carry pins into another position scope')
|
|
488
|
+
h.view.dispose()
|
|
489
|
+
assert.equal(h.view.setViewport(saved), false); assert.equal(h.frames.size, 0)
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
test('setViewport validates finite coordinates and zoom atomically, including overflow and degenerate extents', () => {
|
|
493
|
+
const events = [], zooms = [], h = harness(true, { onViewport: value => events.push(value), onZoom: value => zooms.push(value) })
|
|
494
|
+
h.view.update(graph(1)); h.flush()
|
|
495
|
+
const bbox = { minX: -10, minY: -20, maxX: 590, maxY: 380 }
|
|
496
|
+
for (const bad of [null, undefined, [], {}, { zoom: 1 }, { x: 0, y: 0, zoom: '1' },
|
|
497
|
+
...[NaN, Infinity, -Infinity, 0, -.1, .059, 5.001].map(zoom => ({ x: 0, y: 0, zoom })),
|
|
498
|
+
...[NaN, Infinity, -Infinity, '0', null, undefined].flatMap(n => [{ x: n, y: 0, zoom: 1 }, { x: 0, y: n, zoom: 1 }]),
|
|
499
|
+
{ bbox: null, zoom: 1 }, { bbox: [], zoom: 1 }, { bbox: {}, zoom: 1 },
|
|
500
|
+
{ bbox: { ...bbox, minX: NaN }, zoom: 1 }, { bbox: { ...bbox, maxY: Infinity }, zoom: 1 },
|
|
501
|
+
{ bbox: { ...bbox, minY: '0' }, zoom: 1 }, { bbox: { ...bbox, maxX: -10 }, zoom: 1 },
|
|
502
|
+
{ bbox: { ...bbox, maxY: -30 }, zoom: 1 }, { bbox, x: 0, y: 0, zoom: 1 },
|
|
503
|
+
{ bbox: { minX: 1e308, minY: 0, maxX: 1.1e308, maxY: 1 }, zoom: 5 },
|
|
504
|
+
{ x: 1e308, y: 0, zoom: .06 }, { x: 1e300, y: 0, zoom: 1 }]) {
|
|
505
|
+
const viewport = h.view.viewport(), nodes = h.view.snapshot(), diagnostics = h.view.diagnostics()
|
|
506
|
+
const eventCount = events.length, zoomCount = zooms.length
|
|
507
|
+
assert.equal(h.view.setViewport(bad), false, `must reject ${JSON.stringify(bad)}`)
|
|
508
|
+
assert.deepEqual(h.view.viewport(), viewport); assert.deepEqual(h.view.snapshot(), nodes)
|
|
509
|
+
assert.deepEqual(h.view.diagnostics(), diagnostics); assert.equal(h.frames.size, 0)
|
|
510
|
+
assert.equal(events.length, eventCount); assert.equal(zooms.length, zoomCount)
|
|
511
|
+
}
|
|
512
|
+
for (const zoom of [.06, 5]) {
|
|
513
|
+
assert.equal(h.view.setViewport({ x: 15, y: -25, zoom }), true)
|
|
514
|
+
assert.equal(h.view.viewport().zoom, zoom)
|
|
515
|
+
assert.equal(h.view.viewport().bbox.minX, -15 / zoom); assert.equal(h.view.viewport().bbox.minY, 25 / zoom)
|
|
516
|
+
h.flush(); assert.equal(h.frames.size, 0)
|
|
517
|
+
}
|
|
518
|
+
const saved = h.view.viewport()
|
|
519
|
+
h.canvas.getBoundingClientRect = () => ({ left: 0, top: 0, width: 900, height: 700 })
|
|
520
|
+
h.windowHandlers.get('resize')(); h.flush()
|
|
521
|
+
assert.equal(h.view.setViewport(saved), true); h.flush()
|
|
522
|
+
const resized = h.view.viewport()
|
|
523
|
+
assert.equal(resized.zoom, saved.zoom); assert.equal(resized.bbox.minX, saved.bbox.minX); assert.equal(resized.bbox.minY, saved.bbox.minY)
|
|
524
|
+
assert.equal(resized.bbox.maxX - resized.bbox.minX, 900 / saved.zoom)
|
|
525
|
+
assert.equal(resized.bbox.maxY - resized.bbox.minY, 700 / saved.zoom)
|
|
526
|
+
h.view.dispose()
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
test('setViewport rebases active local and rigid drags without changing their physics scope or drop', () => {
|
|
530
|
+
for (const rigid of [false, true]) {
|
|
531
|
+
const h = harness(false), data = denseGraph(500)
|
|
532
|
+
h.view.update(data); h.flush()
|
|
533
|
+
const p = h.view.snapshot().find(node => node.degree >= 20 && node.x > 50 && node.y > 50 && node.x < 500 && node.y < 300)
|
|
534
|
+
assert.ok(p)
|
|
535
|
+
h.emit('pointerdown', p.x, p.y, { shiftKey: rigid }); h.emit('pointermove', p.x + 20, p.y + 10); h.flush()
|
|
536
|
+
const before = h.view.snapshot(), diagnostics = h.view.diagnostics(), root = before.find(node => node.id === p.id)
|
|
537
|
+
assert.equal(h.view.setViewport({ x: 35, y: -15, zoom: .8 }), true)
|
|
538
|
+
assert.deepEqual(h.view.diagnostics().localPhysics, diagnostics.localPhysics)
|
|
539
|
+
const after = h.view.snapshot()
|
|
540
|
+
after.forEach((node, i) => {
|
|
541
|
+
for (const key of ['worldX', 'worldY', 'positionFixed', 'anchored', 'pinned']) assert.equal(node[key], before[i][key])
|
|
542
|
+
})
|
|
543
|
+
h.emit('pointermove', p.x + 20, p.y + 10)
|
|
544
|
+
let moved = h.view.snapshot().find(node => node.id === p.id)
|
|
545
|
+
assert.ok(Math.hypot(moved.worldX - root.worldX, moved.worldY - root.worldY) < 1e-8, 'the same pointer must not teleport the root')
|
|
546
|
+
h.emit('pointermove', p.x + 28, p.y + 14)
|
|
547
|
+
moved = h.view.snapshot().find(node => node.id === p.id)
|
|
548
|
+
assert.ok(Math.abs(moved.worldX - root.worldX - 10) < 1e-8); assert.ok(Math.abs(moved.worldY - root.worldY - 5) < 1e-8)
|
|
549
|
+
h.emit('pointerup', p.x + 28, p.y + 14)
|
|
550
|
+
const released = h.view.diagnostics().localPhysics
|
|
551
|
+
assert.equal(h.view.setViewport({ x: 10, y: 20, zoom: 1 }), true)
|
|
552
|
+
assert.deepEqual(h.view.diagnostics().localPhysics, released, 'released collision relaxation must retain its session')
|
|
553
|
+
for (let i = 0; i < 240 && h.frames.size; i++) h.flush()
|
|
554
|
+
const drop = h.view.snapshot().find(node => node.id === p.id)
|
|
555
|
+
assert.equal(drop.worldX, moved.worldX); assert.equal(drop.worldY, moved.worldY); assert.equal(drop.anchored, true)
|
|
556
|
+
assert.equal(h.frames.size, 0); h.view.dispose()
|
|
557
|
+
}
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
test('setViewport rebases active pan and pinch cameras without a jump or viewport echo', () => {
|
|
561
|
+
const events = [], h = harness(true, { onViewport: value => events.push(value) })
|
|
562
|
+
h.view.update(graph(1)); h.flush()
|
|
563
|
+
h.emit('pointerdown', 10, 10); h.emit('pointermove', 30, 25)
|
|
564
|
+
let count = events.length
|
|
565
|
+
assert.equal(h.view.setViewport({ x: 60, y: 40, zoom: 1 }), true)
|
|
566
|
+
assert.equal(events.length, count)
|
|
567
|
+
const panned = h.view.viewport()
|
|
568
|
+
h.emit('pointermove', 30, 25); assert.deepEqual(h.view.viewport(), panned)
|
|
569
|
+
h.emit('pointermove', 42, 34)
|
|
570
|
+
assert.equal(h.view.viewport().bbox.minX, -72); assert.equal(h.view.viewport().bbox.minY, -49)
|
|
571
|
+
h.emit('pointerup', 42, 34)
|
|
572
|
+
h.emit('pointerdown', 0, 0, { pointerType: 'touch' })
|
|
573
|
+
h.emit('pointerdown', 100, 0, { pointerType: 'touch', pointerId: 2 })
|
|
574
|
+
h.emit('pointermove', 120, 0, { pointerType: 'touch', pointerId: 2 })
|
|
575
|
+
count = events.length
|
|
576
|
+
assert.equal(h.view.setViewport({ x: 10, y: 20, zoom: .7 }), true)
|
|
577
|
+
assert.equal(events.length, count)
|
|
578
|
+
const pinched = h.view.viewport()
|
|
579
|
+
h.emit('pointermove', 120, 0, { pointerType: 'touch', pointerId: 2 })
|
|
580
|
+
assert.deepEqual(h.view.viewport(), pinched)
|
|
581
|
+
h.emit('pointerup', 0, 0); h.emit('pointerup', 120, 0, { pointerId: 2 }); h.flush()
|
|
582
|
+
assert.equal(h.frames.size, 0); assert.deepEqual(h.focuses, [])
|
|
583
|
+
h.view.dispose()
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
test('setViewport cancels stale prelayout refits, while invalid restoration leaves the pending worker intact', () => {
|
|
587
|
+
const h = harness(), win = h.canvas.ownerDocument.defaultView, timers = new Map()
|
|
588
|
+
let worker, request, timerId = 0
|
|
589
|
+
win.Worker = class {
|
|
590
|
+
constructor() { worker = this }
|
|
591
|
+
postMessage(value) { request = value }
|
|
592
|
+
terminate() {}
|
|
593
|
+
}
|
|
594
|
+
win.Blob = class {}
|
|
595
|
+
win.URL = { createObjectURL: () => 'blob:layout-test', revokeObjectURL() {} }
|
|
596
|
+
win.setTimeout = fn => { timers.set(++timerId, fn); return timerId }
|
|
597
|
+
win.clearTimeout = id => timers.delete(id)
|
|
598
|
+
h.view.update(graph(501)); h.flush()
|
|
599
|
+
assert.equal(h.view.diagnostics().workerPending, true); assert.equal(timers.size, 1)
|
|
600
|
+
assert.equal(h.view.setViewport({ zoom: 0, x: 1, y: 1 }), false)
|
|
601
|
+
assert.equal(h.view.diagnostics().workerPending, true); assert.equal(timers.size, 1)
|
|
602
|
+
assert.equal(h.view.setViewport({ zoom: 1, x: 1, y: 1 }), true); h.flush()
|
|
603
|
+
const viewport = h.view.viewport(), nodes = h.view.snapshot()
|
|
604
|
+
assert.equal(h.view.diagnostics().workerPending, false); assert.equal(timers.size, 0)
|
|
605
|
+
worker.onmessage({ data: { serial: request.serial, positions: new Float64Array(1002).fill(10000) } })
|
|
606
|
+
assert.deepEqual(h.view.viewport(), viewport); assert.deepEqual(h.view.snapshot(), nodes); assert.equal(h.frames.size, 0)
|
|
607
|
+
h.view.update(graph(502)); h.flush()
|
|
608
|
+
assert.equal(h.view.diagnostics().workerPending, true)
|
|
609
|
+
assert.equal(h.view.setViewport(h.view.viewport()), true)
|
|
610
|
+
assert.equal(h.view.diagnostics().workerPending, false); assert.equal(timers.size, 0); assert.equal(h.frames.size, 0)
|
|
611
|
+
h.view.dispose()
|
|
612
|
+
})
|
|
613
|
+
|
|
322
614
|
test('dense hit targets choose the closest node, not the last node in draw order', () => {
|
|
323
615
|
const h = harness()
|
|
324
616
|
h.view.update(graph(2)); h.view.zoom(.04); h.flush()
|
|
@@ -363,6 +655,23 @@ test('a cooled layout stops requesting frames even while motion is enabled', ()
|
|
|
363
655
|
h.view.dispose()
|
|
364
656
|
})
|
|
365
657
|
|
|
658
|
+
test('elastic drag uses the same simulation clock at 60Hz and 120Hz', () => {
|
|
659
|
+
const results = []
|
|
660
|
+
for (const hz of [60, 120]) {
|
|
661
|
+
const h = harness(false)
|
|
662
|
+
h.view.update({ nodes: Array.from({ length: 25 }, (_, i) => ({ id: `clock-${i}`, x: -i * 30, y: 0, kind: 'memory' })),
|
|
663
|
+
edges: Array.from({ length: 24 }, (_, i) => ({ from: `clock-${i}`, to: `clock-${i + 1}` })) })
|
|
664
|
+
h.flush()
|
|
665
|
+
const root = h.view.snapshot().find(node => node.id === 'clock-0')
|
|
666
|
+
h.emit('pointerdown', root.x, root.y); h.emit('pointermove', root.x + 50, root.y + 10)
|
|
667
|
+
for (let frame = 0; frame < hz * .4; frame++) h.flush(1000 / hz)
|
|
668
|
+
results.push(h.view.diagnostics().localPhysics.steps)
|
|
669
|
+
h.view.dispose()
|
|
670
|
+
}
|
|
671
|
+
assert.ok(results[0] >= 23)
|
|
672
|
+
assert.ok(Math.abs(results[0] - results[1]) <= 1, `refresh rate must not speed up the springs: ${results}`)
|
|
673
|
+
})
|
|
674
|
+
|
|
366
675
|
// 极小缩放下两颗节点可能只差 2-3px:纯最近邻会随鼠标 1px 抖动来回换人,
|
|
367
676
|
// 高亮反复切换就是用户看到的「节点互相打架闪现」。
|
|
368
677
|
test('hover keeps its target through 1px jitter at minimum zoom', () => {
|
|
@@ -394,6 +703,91 @@ test('Escape cancels a drag and clears the focus; toolbar actions do not throw',
|
|
|
394
703
|
h.view.dispose()
|
|
395
704
|
})
|
|
396
705
|
|
|
706
|
+
test('overview keeps authoritative coordinates, readable counts and world viewport notifications', () => {
|
|
707
|
+
const viewports = [], tooltip = { hidden: true, style: {} }
|
|
708
|
+
const h = harness(true, { onViewport: value => viewports.push(value), tooltip })
|
|
709
|
+
const data = { overview: true, nodes: [
|
|
710
|
+
{ id: 'c1', clusterId: 'c1', kind: 'cluster', count: 1000, title: 'First cluster', x: -1000, y: 50 },
|
|
711
|
+
{ id: 'c2', clusterId: 'c2', kind: 'cluster', count: 1000, title: 'Second cluster', x: 1000, y: 50 },
|
|
712
|
+
], edges: [] }
|
|
713
|
+
h.view.update(data); h.flush()
|
|
714
|
+
assert.equal(h.frames.size, 0)
|
|
715
|
+
assert.ok(h.texts.includes('1000'), 'cluster counts must remain visible at overview zoom')
|
|
716
|
+
const [a, b] = h.view.snapshot(), before = h.view.viewport()
|
|
717
|
+
assert.ok(a.x < b.x)
|
|
718
|
+
h.emit('pointermove', a.x, a.y); h.flush()
|
|
719
|
+
assert.equal(tooltip.hidden, false); assert.match(tooltip.textContent, /1000/)
|
|
720
|
+
h.emit('keydown', 0, 0, { key: 'ArrowRight' }); h.flush()
|
|
721
|
+
assert.notEqual(h.view.viewport().bbox.minX, before.bbox.minX)
|
|
722
|
+
assert.ok(viewports.length >= 2)
|
|
723
|
+
assert.deepEqual(h.view.viewport(), viewports.at(-1))
|
|
724
|
+
assert.equal(h.frames.size, 0); h.view.dispose()
|
|
725
|
+
})
|
|
726
|
+
|
|
727
|
+
test('3k near view culls drawing without dropping hit data and exposes Worker fallback', () => {
|
|
728
|
+
const signals = [], h = harness(true, { onDiagnostic: value => signals.push(value) })
|
|
729
|
+
h.view.update(graph(3000, false)); h.flush()
|
|
730
|
+
assert.equal(h.view.diagnostics().workerFallback, 'worker-unavailable')
|
|
731
|
+
assert.equal(signals.filter(signal => signal.code === 'GRAPH_LAYOUT_FALLBACK').length, 1)
|
|
732
|
+
h.view.zoom(10); h.flush()
|
|
733
|
+
assert.ok(h.arcs.length > 0 && h.arcs.length < 3000)
|
|
734
|
+
assert.equal(h.view.snapshot().length, 3000)
|
|
735
|
+
assert.equal(h.frames.size, 0)
|
|
736
|
+
h.view.dispose()
|
|
737
|
+
})
|
|
738
|
+
|
|
739
|
+
test('20k drag runs bounded local physics, anchors its drop and stops after relaxation', () => {
|
|
740
|
+
const viewports = [], h = harness(false, { onViewport: value => viewports.push(value) }), data = denseGraph(20001)
|
|
741
|
+
h.view.update(data); h.flush()
|
|
742
|
+
assert.equal(h.view.diagnostics().fixedNodeDrag, false, 'a fixed-node shortcut cannot stand in for physics')
|
|
743
|
+
const viewportEvents = viewports.length
|
|
744
|
+
const before = h.view.snapshot(), p = before.find(node => node.x > 60 && node.y > 60 && node.x < 530 && node.y < 330)
|
|
745
|
+
h.emit('pointerdown', p.x, p.y); h.emit('pointermove', p.x + 24, p.y + 14); h.flush()
|
|
746
|
+
for (let i = 0; i < 8; i++) h.flush()
|
|
747
|
+
const moved = h.view.snapshot(), target = moved.find(node => node.id === p.id)
|
|
748
|
+
assert.ok(Math.abs(target.x - p.x - 24) < 1e-8); assert.ok(Math.abs(target.y - p.y - 14) < 1e-8)
|
|
749
|
+
const changed = moved.filter((node, i) => node.id !== p.id && Math.hypot(node.worldX - before[i].worldX, node.worldY - before[i].worldY) > .01)
|
|
750
|
+
assert.ok(changed.length > 1 && changed.length < 384, 'nearby nodes move while distant rows stay frozen')
|
|
751
|
+
assert.equal(viewports.length, viewportEvents, 'node dragging must not trigger viewport RPC refreshes')
|
|
752
|
+
h.emit('pointerup', p.x + 24, p.y + 14); h.flush()
|
|
753
|
+
for (let i = 0; i < 240 && h.frames.size; i++) h.flush()
|
|
754
|
+
assert.equal(h.view.isPinned(p.id), false)
|
|
755
|
+
const settled = h.view.snapshot(), drop = settled.find(node => node.id === p.id)
|
|
756
|
+
assert.equal(drop.x, target.x); assert.equal(drop.y, target.y); assert.equal(drop.anchored, true)
|
|
757
|
+
assert.equal(graphGeometry(settled).overlaps, 0, JSON.stringify(h.view.diagnostics().localPhysics))
|
|
758
|
+
assert.equal(h.frames.size, 0)
|
|
759
|
+
h.emit('pointerdown', target.x, target.y); h.emit('pointermove', target.x + 15, target.y + 10)
|
|
760
|
+
h.emit('keydown', 0, 0, { key: 'Escape' }); h.flush()
|
|
761
|
+
assert.deepEqual(h.view.snapshot(), settled, 'cancel restores every affected local node')
|
|
762
|
+
assert.equal(h.frames.size, 0); h.view.dispose()
|
|
763
|
+
})
|
|
764
|
+
|
|
765
|
+
test('local physics redraws moving members over a bounded background and invalidates it on view changes', () => {
|
|
766
|
+
const h = harness(false), data = graph(3000)
|
|
767
|
+
let captures = 0
|
|
768
|
+
h.canvas.ownerDocument.createElement = () => ({ width: 0, height: 0, getContext: () => ({ drawImage() { captures++ } }) })
|
|
769
|
+
h.canvas.getBoundingClientRect = () => ({ left: 0, top: 0, width: 2400, height: 1600 })
|
|
770
|
+
h.windowHandlers.get('resize')()
|
|
771
|
+
data.nodes.forEach((node, i) => { node.x = i % 60 * 28; node.y = Math.floor(i / 60) * 28 })
|
|
772
|
+
h.view.update(data); h.flush()
|
|
773
|
+
const p = h.view.snapshot().find(node => node.x > 100 && node.y > 100 && node.x < 2000 && node.y < 1300)
|
|
774
|
+
h.emit('pointerdown', p.x, p.y); h.emit('pointermove', p.x + 30, p.y + 20); h.flush()
|
|
775
|
+
assert.ok(captures >= 1)
|
|
776
|
+
const first = h.view.diagnostics()
|
|
777
|
+
assert.ok(first.dragCacheBytes > 0 && first.dragCacheBytes <= 16 * 1024 * 1024)
|
|
778
|
+
h.emit('pointermove', p.x + 40, p.y + 25); h.flush()
|
|
779
|
+
for (let i = 0; i < 10; i++) h.flush()
|
|
780
|
+
assert.ok(h.view.diagnostics().dragCachedFrames > 0)
|
|
781
|
+
let prior = captures
|
|
782
|
+
h.view.configure({ labels: false }); h.flush(); assert.ok(captures > prior); prior = captures
|
|
783
|
+
h.view.zoom(1.01); h.flush(); assert.ok(captures > prior); prior = captures
|
|
784
|
+
h.view.update(data); h.flush(); assert.ok(captures > prior)
|
|
785
|
+
h.emit('pointerup', p.x + 40, p.y + 25); h.flush()
|
|
786
|
+
for (let i = 0; i < 240 && h.frames.size; i++) h.flush()
|
|
787
|
+
assert.equal(h.view.diagnostics().dragCacheBytes, 0)
|
|
788
|
+
assert.equal(h.frames.size, 0); h.view.dispose()
|
|
789
|
+
})
|
|
790
|
+
|
|
397
791
|
test('shipped browser bundle exposes the controller with no runtime npm imports', () => {
|
|
398
792
|
const source = fs.readFileSync(new URL('../lib/webui/graph-view.bundle.js', import.meta.url), 'utf8')
|
|
399
793
|
assert.doesNotMatch(source, /d3-force|forceSimulation|forceManyBody|require\(/)
|
|
@@ -411,4 +805,49 @@ test('shipped browser bundle exposes the controller with no runtime npm imports'
|
|
|
411
805
|
layout.update(graph(251, false))
|
|
412
806
|
assert.equal(layout.nodes.length, 251, 'the shipped browser bundle must retain nodes beyond 200')
|
|
413
807
|
layout.dispose()
|
|
808
|
+
const h = harness(true, {}, api.createGraphView)
|
|
809
|
+
h.view.update(graph(1)); h.flush()
|
|
810
|
+
assert.equal(typeof h.view.setViewport, 'function')
|
|
811
|
+
const saved = h.view.viewport(), point = h.view.snapshot()[0]
|
|
812
|
+
h.view.zoom(.5); h.flush()
|
|
813
|
+
assert.equal(h.view.setViewport(saved), true); h.flush()
|
|
814
|
+
const restored = h.view.snapshot()[0]
|
|
815
|
+
assert.ok(Math.hypot(point.x - restored.x, point.y - restored.y) < 1e-8)
|
|
816
|
+
assert.equal(h.frames.size, 0); h.view.dispose()
|
|
817
|
+
})
|
|
818
|
+
|
|
819
|
+
test('holding a node still after a drag must not pull the stragglers over and snap them back', () => {
|
|
820
|
+
// 现象:拖完之后按住同一节点不动,边弹簧把落后的枝拉过来;一松手(没有移动 = 单击)
|
|
821
|
+
// 走 restoreGesture → cancelLocalDrag,把整段 saved 位置还原,于是"弹回原位"。
|
|
822
|
+
// 修法:手势还没真正移动时不要积分局部物理,拉不动也就没有可回滚的东西。
|
|
823
|
+
const h = harness(false)
|
|
824
|
+
h.view.update(graph(30)); h.flush()
|
|
825
|
+
const start = h.view.snapshot()
|
|
826
|
+
const root = start.find(node => node.id === 'n000')
|
|
827
|
+
|
|
828
|
+
// 先真拖一次,把链尾留在后面。
|
|
829
|
+
h.emit('pointerdown', root.x, root.y)
|
|
830
|
+
h.emit('pointermove', root.x + 120, root.y + 80)
|
|
831
|
+
for (let i = 0; i < 6; i++) h.flush()
|
|
832
|
+
h.emit('pointerup', root.x + 120, root.y + 80); h.flush()
|
|
833
|
+
|
|
834
|
+
const dropped = h.view.snapshot()
|
|
835
|
+
const grabbed = dropped.find(node => node.id === 'n000')
|
|
836
|
+
|
|
837
|
+
// 再按住同一节点,全程不动指针。
|
|
838
|
+
h.emit('pointerdown', grabbed.x, grabbed.y)
|
|
839
|
+
for (let i = 0; i < 30; i++) h.flush()
|
|
840
|
+
const held = new Map(h.view.snapshot().map(node => [node.id, node]))
|
|
841
|
+
const pulled = dropped.filter(node => node.id !== 'n000'
|
|
842
|
+
&& Math.hypot(held.get(node.id).worldX - node.worldX, held.get(node.id).worldY - node.worldY) > .5)
|
|
843
|
+
assert.equal(pulled.length, 0, 'a press that has not moved yet must not run the local solve')
|
|
844
|
+
|
|
845
|
+
const beforeRelease = h.view.snapshot()
|
|
846
|
+
h.emit('pointerup', grabbed.x, grabbed.y); h.flush()
|
|
847
|
+
const released = new Map(h.view.snapshot().map(node => [node.id, node]))
|
|
848
|
+
for (const node of beforeRelease) {
|
|
849
|
+
assert.ok(Math.hypot(released.get(node.id).worldX - node.worldX, released.get(node.id).worldY - node.worldY) < .5,
|
|
850
|
+
`${node.id} must keep its position: releasing a still press restores nothing`)
|
|
851
|
+
}
|
|
852
|
+
h.view.dispose()
|
|
414
853
|
})
|
package/tests/graph.test.mjs
CHANGED
|
@@ -369,3 +369,46 @@ test('listEntities: with a session only visible references count, and relationsh
|
|
|
369
369
|
}
|
|
370
370
|
assert.equal(linkedMap[lonely.id], false, 'the untouched entity stays unlinked')
|
|
371
371
|
})
|
|
372
|
+
|
|
373
|
+
test('listEntities exact entityId returns one real management row without writing either source', () => {
|
|
374
|
+
const lib = state.ensureSession('entity-exact-management', { cwd: path.join(home, 'entity-exact-management') }).libraryId
|
|
375
|
+
state.savePrivateIndex(lib, { entries: {} })
|
|
376
|
+
graph.createEntity({ libraryId: lib, name: 'Other entity' })
|
|
377
|
+
const chosen = graph.createEntity({ libraryId: lib, name: 'Exact target', aliases: ['Precise alias'] })
|
|
378
|
+
graph.createEntity({ libraryId: lib, name: 'Exact target suffix' })
|
|
379
|
+
const sourceFiles = [path.join(home, 'index', `${lib}.json`), path.join(home, 'index', `${lib}.entities.json`)]
|
|
380
|
+
const before = sourceFiles.map(file => fs.readFileSync(file))
|
|
381
|
+
const result = graph.listEntities({ libraryId: lib, entityId: chosen.id })
|
|
382
|
+
assert.equal(result.total, 1)
|
|
383
|
+
assert.deepEqual(result.items.map(row => row.id), [chosen.id])
|
|
384
|
+
assert.deepEqual(result.items[0].aliases, ['Precise alias'])
|
|
385
|
+
assert.equal(result.items[0].linked, false, 'an unlinked management row remains editable')
|
|
386
|
+
assert.equal(graph.listEntities({ libraryId: lib }).total, 3, 'omitting entityId keeps the existing list contract')
|
|
387
|
+
for (const id of ['ent-not-present', '__proto__', 'constructor']) {
|
|
388
|
+
assert.deepEqual(graph.listEntities({ libraryId: lib, entityId: id }), { items: [], total: 0 })
|
|
389
|
+
}
|
|
390
|
+
assert.deepEqual(sourceFiles.map(file => fs.readFileSync(file)), before, 'exact reads do not rewrite source data')
|
|
391
|
+
for (const entityId of ['', ' ', null, 1, [], {}, 'x'.repeat(257)]) {
|
|
392
|
+
assert.throws(() => graph.listEntities({ libraryId: lib, entityId }), /entityId/)
|
|
393
|
+
}
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
test('listEntities exact entityId preserves session reference and cross-library boundaries', () => {
|
|
397
|
+
const sessionId = 'entity-exact-scoped'
|
|
398
|
+
const lib = state.ensureSession(sessionId, { cwd: path.join(home, sessionId), agentPreset: 'rp' }).libraryId
|
|
399
|
+
const scopedExec = { agent: { session: { header: { id: sessionId } } } }
|
|
400
|
+
const visible = graph.createEntity({ libraryId: lib, name: 'Exact visible', aliases: ['Visible alias'] })
|
|
401
|
+
const hidden = graph.createEntity({ libraryId: lib, name: 'Exact hidden', aliases: ['Private alias'] })
|
|
402
|
+
const orphan = graph.createEntity({ libraryId: lib, name: 'Exact orphan' })
|
|
403
|
+
state.savePrivateIndex(lib, { entries: {
|
|
404
|
+
open: { status: 'active', visibility: 'shared', links: [{ to: visible.id, kind: 'person' }] },
|
|
405
|
+
hidden: { status: 'active', visibility: 'secret', context: { characterId: 'another' }, links: [{ to: hidden.id, kind: 'person' }] },
|
|
406
|
+
} })
|
|
407
|
+
assert.deepEqual(graph.listEntities({ exec: scopedExec, libraryId: lib, entityId: visible.id }).items.map(row => row.id), [visible.id])
|
|
408
|
+
for (const entityId of [hidden.id, orphan.id, 'ent-not-present']) {
|
|
409
|
+
assert.deepEqual(graph.listEntities({ exec: scopedExec, libraryId: lib, entityId }), { items: [], total: 0 }, 'hidden and missing rows have the same empty response')
|
|
410
|
+
}
|
|
411
|
+
assert.deepEqual(graph.listEntities({ libraryId: lib, entityId: hidden.id }).items.map(row => row.id), [hidden.id], 'explicit management retains its existing authority')
|
|
412
|
+
const other = state.ensureSession('entity-exact-foreign', { cwd: path.join(home, 'entity-exact-foreign') }).libraryId
|
|
413
|
+
assert.throws(() => graph.listEntities({ exec: scopedExec, libraryId: other, entityId: visible.id }), /not bound|current session|different library|cross-library/i)
|
|
414
|
+
})
|