dsh-memu-memory 1.4.3 → 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 +15 -0
- package/README.md +34 -15
- package/README.zh.md +35 -13
- 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/preset-mount.js +13 -7
- 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 +38 -7
- 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 +97 -13
- 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/preset-mount.test.mjs +12 -4
- package/tests/recall-cache.test.mjs +56 -3
- package/tests/recall-dedup.test.mjs +63 -2
- package/tests/retention.test.mjs +260 -0
- package/tests/rt-index-cross-library.test.mjs +230 -0
- package/tests/rt-index-integration.test.mjs +194 -0
- package/tests/rt-index-retention.test.mjs +552 -0
- package/tests/rt-index-scale.test.mjs +204 -0
- package/tests/rt-index.test.mjs +705 -0
- package/tests/salient-date-boundaries.test.mjs +121 -0
- package/tests/salient-wake.test.mjs +29 -0
- package/tests/scale-bench.test.mjs +53 -0
- package/tests/settings-plumbing.test.mjs +25 -0
- package/tests/simulate-injection.test.mjs +15 -1
- package/tests/standalone-navigation.test.mjs +44 -0
- package/tests/state.test.mjs +51 -0
- package/tests/temporal-precision.test.mjs +102 -0
- package/tests/temporal.test.mjs +10 -6
- package/tests/token-measurement.test.mjs +98 -0
- package/tests/tool-schema.test.mjs +41 -5
- package/tests/tools.test.mjs +6 -3
- package/tests/turn-token-budget.test.mjs +149 -0
- package/tests/webui-auth.test.mjs +57 -1
- package/tests/webui.test.mjs +40 -15
- package/tests/worker-lifecycle.test.mjs +2 -1
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { createForceLayout, fitCamera } from '../lib/webui/graph-view.js'
|
|
4
|
+
import { createLocalPhysics } from '../lib/webui/graph-local-physics.js'
|
|
5
|
+
import { createMutableSpatialGrid } from '../lib/webui/graph-spatial-grid.js'
|
|
6
|
+
import { denseGraph, graphGeometry } from '../scripts/graph-geometry-fixture.mjs'
|
|
7
|
+
|
|
8
|
+
test('mutable numeric cells move and remove nodes without duplicate or stale obstacles', () => {
|
|
9
|
+
const grid = createMutableSpatialGrid(1), a = { x: 0, y: 8192 }, b = { x: -1, y: -8192 }, c = { x: 0, y: 8192 }
|
|
10
|
+
grid.reset([a, b, c]); a.x = 8192; a.y = 0; grid.update(a); grid.update(a)
|
|
11
|
+
const old = [], moved = []
|
|
12
|
+
grid.visit(0, 8192, 0, node => old.push(node)); grid.visit(8192, 0, 0, node => moved.push(node))
|
|
13
|
+
assert.deepEqual(old, [c]); assert.deepEqual(moved, [a])
|
|
14
|
+
grid.remove(c); grid.remove(a); grid.remove(b); grid.dispose()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
for (const count of [3000, 20001]) test(`${count} multi-cluster local springs move neighbors and separate collisions with a fixed drop`, () => {
|
|
18
|
+
const data = denseGraph(count), original = structuredClone(data), layout = createForceLayout()
|
|
19
|
+
layout.update(data)
|
|
20
|
+
assert.equal(graphGeometry(layout.nodes).overlaps, 0)
|
|
21
|
+
const root = layout.nodes[0], before = new Map(layout.nodes.map(node => [node.id, [node.x, node.y]]))
|
|
22
|
+
layout.beginLocalDrag(root.id)
|
|
23
|
+
for (let i = 1; i <= 30; i++) { layout.moveLocalDrag(i * 5, i * 2); layout.stepLocal() }
|
|
24
|
+
const drop = [root.x, root.y]
|
|
25
|
+
assert.equal(drop[0], 150); assert.equal(drop[1], 60)
|
|
26
|
+
layout.releaseLocalDrag()
|
|
27
|
+
for (let i = 0; i < 240 && layout.localActive; i++) layout.stepLocal()
|
|
28
|
+
assert.equal(layout.localActive, false)
|
|
29
|
+
assert.equal(root.x, drop[0]); assert.equal(root.y, drop[1]); assert.equal(root.anchored, true)
|
|
30
|
+
const moved = layout.nodes.filter(node => Math.hypot(node.x - before.get(node.id)[0], node.y - before.get(node.id)[1]) > .01)
|
|
31
|
+
assert.ok(moved.length > 8, 'the dragged node must move actual spring/collision neighbors')
|
|
32
|
+
assert.ok(moved.length <= 384, 'distant components must not receive whole-graph integration')
|
|
33
|
+
const geometry = graphGeometry(layout.nodes)
|
|
34
|
+
assert.equal(geometry.overlaps, 0, JSON.stringify({ geometry, physics: layout.localDiagnostics() }))
|
|
35
|
+
assert.ok(layout.localDiagnostics().steps >= 30)
|
|
36
|
+
assert.equal(layout.localDiagnostics().saturated, false)
|
|
37
|
+
layout.update(data)
|
|
38
|
+
assert.deepEqual([root.x, root.y], drop, 'a refreshed server snapshot must not erase the anchored drop')
|
|
39
|
+
assert.deepEqual(data, original)
|
|
40
|
+
layout.dispose()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('local collisions wake a neighboring component but preserve remote rows and existing pins', () => {
|
|
44
|
+
const data = denseGraph(3000), layout = createForceLayout()
|
|
45
|
+
layout.update(data)
|
|
46
|
+
const root = layout.nodes[0], obstacle = layout.nodes[250], pinned = layout.nodes[251]
|
|
47
|
+
layout.pin(pinned.id, pinned.x, pinned.y); layout.cool()
|
|
48
|
+
const pin = [pinned.x, pinned.y], far = layout.nodes.at(-1), remote = [far.x, far.y]
|
|
49
|
+
layout.beginLocalDrag(root.id); layout.moveLocalDrag(obstacle.x, obstacle.y)
|
|
50
|
+
for (let i = 0; i < 30; i++) layout.stepLocal()
|
|
51
|
+
layout.releaseLocalDrag()
|
|
52
|
+
for (let i = 0; i < 240 && layout.localActive; i++) layout.stepLocal()
|
|
53
|
+
assert.equal(graphGeometry(layout.nodes).overlaps, 0, JSON.stringify(layout.localDiagnostics()))
|
|
54
|
+
assert.deepEqual([pinned.x, pinned.y], pin); assert.deepEqual([far.x, far.y], remote)
|
|
55
|
+
const held = [root.x, root.y]
|
|
56
|
+
layout.beginLocalDrag(root.id); layout.moveLocalDrag(pin[0], pin[1]); layout.stepLocal()
|
|
57
|
+
assert.ok(layout.localDiagnostics().blockedByPins > 0)
|
|
58
|
+
assert.deepEqual([pinned.x, pinned.y], pin)
|
|
59
|
+
layout.cancelLocalDrag(); assert.deepEqual([root.x, root.y], held)
|
|
60
|
+
layout.dispose()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('a paused held drag can settle without losing its session, then resumes on the next pointer move', () => {
|
|
64
|
+
const layout = createForceLayout(), data = denseGraph(3000)
|
|
65
|
+
layout.update(data); layout.settle(80)
|
|
66
|
+
const root = layout.nodes[0], session = layout.beginLocalDrag(root.id)
|
|
67
|
+
layout.moveLocalDrag(root.x + 35, root.y + 18)
|
|
68
|
+
for (let i = 0; i < 180 && layout.localActive; i++) layout.stepLocal()
|
|
69
|
+
assert.equal(layout.localSession, session, 'settling while the button is held must preserve the gesture journal')
|
|
70
|
+
assert.equal(layout.localActive, false, 'a stable held drag must stop requesting frames')
|
|
71
|
+
const resumed = [root.x + 24, root.y - 12]
|
|
72
|
+
layout.moveLocalDrag(...resumed)
|
|
73
|
+
assert.equal(layout.localSession, session, 'resuming must not create a second physics session')
|
|
74
|
+
assert.equal(layout.localActive, true)
|
|
75
|
+
assert.deepEqual([root.x, root.y], resumed)
|
|
76
|
+
layout.releaseLocalDrag()
|
|
77
|
+
for (let i = 0; i < 240 && layout.localActive; i++) layout.stepLocal()
|
|
78
|
+
assert.equal(layout.localActive, false)
|
|
79
|
+
assert.deepEqual([root.x, root.y], resumed, 'release relaxation cannot pull the drop away')
|
|
80
|
+
layout.dispose()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('drag expansion follows graph edges, not merely nearby disconnected clusters', () => {
|
|
84
|
+
const physics = createLocalPhysics()
|
|
85
|
+
const nodes = Array.from({ length: 8 }, (_, i) => ({ id: String(i), x: (i < 4 ? 0 : 70) + i % 4 * 20,
|
|
86
|
+
y: Math.floor(i % 4 / 2) * 20, radius: 6, vx: 0, vy: 0, fx: null, fy: null }))
|
|
87
|
+
const edge = (from, to) => ({ from: String(from), to: String(to), source: nodes[from], target: nodes[to], baseLen: 20 })
|
|
88
|
+
const edges = [edge(0, 1), edge(1, 2), edge(2, 3), edge(4, 5), edge(5, 6), edge(6, 7)]
|
|
89
|
+
physics.update(nodes, edges); physics.begin('0')
|
|
90
|
+
assert.ok(physics.session.ids.has('3'), 'the complete component fits in the bounded drag neighborhood')
|
|
91
|
+
assert.equal(physics.session.ids.has('4'), false, 'a nearby but disconnected cluster is not pulled by its springs')
|
|
92
|
+
assert.equal(physics.session.edgeSet.has(edges[3]), false)
|
|
93
|
+
physics.cancel(); physics.dispose()
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('elastic branches lag behind the pointer, bound link extension and damp around the fixed drop', () => {
|
|
97
|
+
const nodes = Array.from({ length: 20 }, (_, i) => ({ id: `elastic-${i}`, x: -i * 30, y: 0,
|
|
98
|
+
radius: 4, vx: 0, vy: 0, fx: null, fy: null, degree: 2 }))
|
|
99
|
+
const edges = nodes.slice(1).map((target, i) => ({ from: nodes[i].id, to: target.id, source: nodes[i], target, baseLen: 30 }))
|
|
100
|
+
const before = nodes.map(node => node.x), physics = createLocalPhysics()
|
|
101
|
+
physics.update(nodes, edges); physics.begin(nodes[0].id); physics.move(120, 0)
|
|
102
|
+
assert.deepEqual(nodes.slice(1).map(node => node.x), before.slice(1), 'pointer input only moves the grabbed node')
|
|
103
|
+
physics.step()
|
|
104
|
+
assert.ok(nodes[1].x - before[1] > nodes.at(-1).x - before.at(-1) + 20, 'the near branch leads the far branch')
|
|
105
|
+
physics.release()
|
|
106
|
+
const near = [], far = []
|
|
107
|
+
for (let step = 0; physics.active && step < 240; step++) {
|
|
108
|
+
physics.step(); near.push(nodes[1].x); far.push(nodes.at(-1).x)
|
|
109
|
+
assert.deepEqual([nodes[0].x, nodes[0].y], [120, 0], 'spring energy cannot rebound the leader')
|
|
110
|
+
assert.ok(edges.every(edge => Math.hypot(edge.source.x - edge.target.x, edge.source.y - edge.target.y) <= 42.1), 'no overlong tether during release')
|
|
111
|
+
}
|
|
112
|
+
assert.equal(physics.active, false)
|
|
113
|
+
assert.ok(Math.max(...near) > before[1] + 120 + .1, 'a free branch has a small elastic overshoot')
|
|
114
|
+
// 契约变更(2026-12-01,用户要求「像流苏一样展开,不是固定形状」):拖拽不再把每个
|
|
115
|
+
// 节点精确平移到「原位置 + 位移」。深支按深度保留有界松弛,松手后停在该松弛里,形状
|
|
116
|
+
// 因此会变。这里断言的是「跟住大部分 + 松弛有界」,不再是「精确追到刚性目标」。
|
|
117
|
+
const farLag = before.at(-1) + 120 - far.at(-1)
|
|
118
|
+
assert.ok(farLag > 10, `a deep branch must keep some slack instead of a rigid cutout (lag ${farLag})`)
|
|
119
|
+
assert.ok(farLag < 70, `that slack must stay bounded so the branch still follows (lag ${farLag})`)
|
|
120
|
+
assert.ok(far.at(-1) - before.at(-1) > 60, 'the far branch still travels most of the pull')
|
|
121
|
+
assert.ok(Math.abs(near.at(-1) - near.at(-2)) < .2, 'the oscillation damps before idling')
|
|
122
|
+
assert.equal(physics.diagnostics().convergenceLimited, false)
|
|
123
|
+
physics.dispose()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('rapid regrabs keep the original tether limit at every distance setting', () => {
|
|
127
|
+
for (const distance of [40, 100, 220]) {
|
|
128
|
+
const root = { id: 'regrab-root', x: 0, y: 0, radius: 2, vx: 0, vy: 0 }
|
|
129
|
+
const child = { id: 'regrab-child', x: 30, y: 0, radius: 2, vx: 0, vy: 0 }
|
|
130
|
+
const edge = { from: root.id, to: child.id, source: root, target: child, baseLen: 30 }
|
|
131
|
+
const physics = createLocalPhysics(), rest = edge.baseLen * distance / 100
|
|
132
|
+
const limit = rest + Math.max(12, Math.min(64, rest * .4))
|
|
133
|
+
physics.update([root, child], [edge])
|
|
134
|
+
for (let drag = 0; drag < 10; drag++) {
|
|
135
|
+
physics.begin(root.id)
|
|
136
|
+
physics.move(root.x - 100, root.y - 20)
|
|
137
|
+
const drop = [root.x, root.y]
|
|
138
|
+
physics.step({ distance })
|
|
139
|
+
assert.ok(Math.hypot(root.x - child.x, root.y - child.y) <= limit + .1,
|
|
140
|
+
`drag ${drag + 1} cannot accumulate slack at distance ${distance}`)
|
|
141
|
+
physics.release()
|
|
142
|
+
assert.deepEqual([root.x, root.y], drop)
|
|
143
|
+
}
|
|
144
|
+
while (physics.active) physics.step({ distance })
|
|
145
|
+
assert.ok(physics.diagnostics().maxExtension < 1)
|
|
146
|
+
assert.equal(edge.baseLen, 30, 'a drag must not rewrite the original spring length')
|
|
147
|
+
physics.dispose()
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('all connected branches and more than 8192 edges participate without saturation', () => {
|
|
152
|
+
const count = 700, nodes = [{ id: 'leader', x: 0, y: 0, radius: 4, vx: 0, vy: 0 }]
|
|
153
|
+
for (let i = 0; i < count; i++) nodes.push({ id: `leaf-${i}`, x: Math.cos(i / count * Math.PI * 2) * 1600,
|
|
154
|
+
y: Math.sin(i / count * Math.PI * 2) * 1600, radius: 3, vx: 0, vy: 0 })
|
|
155
|
+
const edge = (source, target) => ({ from: source.id, to: target.id, source, target, baseLen: Math.hypot(target.x - source.x, target.y - source.y) })
|
|
156
|
+
const edges = nodes.slice(1).map(node => edge(nodes[0], node))
|
|
157
|
+
for (let i = 1; i < nodes.length; i++) for (let j = 1; j <= 12; j++) edges.push(edge(nodes[i], nodes[(i + j - 1) % count + 1]))
|
|
158
|
+
const before = nodes.map(node => [node.x, node.y]), physics = createLocalPhysics()
|
|
159
|
+
physics.update(nodes, edges); physics.begin('leader')
|
|
160
|
+
assert.equal(physics.session.topology.size, count + 1)
|
|
161
|
+
assert.equal(physics.session.edgeSet.size, edges.length)
|
|
162
|
+
assert.ok(edges.length > 8192)
|
|
163
|
+
physics.move(80, 25); physics.release()
|
|
164
|
+
for (let step = 0; physics.active && step < 240; step++) physics.step()
|
|
165
|
+
assert.equal(physics.active, false)
|
|
166
|
+
assert.ok(nodes.every((node, i) => Math.hypot(node.x - before[i][0], node.y - before[i][1]) > 75), 'every connected member follows')
|
|
167
|
+
assert.equal(physics.diagnostics().saturated, false)
|
|
168
|
+
assert.equal(physics.diagnostics().convergenceLimited, false)
|
|
169
|
+
physics.dispose()
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('a new leader can pull an earlier soft anchor while explicit pins and cancellation remain intact', () => {
|
|
173
|
+
const nodes = Array.from({ length: 4 }, (_, i) => ({ id: `anchor-${i}`, x: -i * 40, y: 0, radius: 4,
|
|
174
|
+
vx: 0, vy: 0, fx: i === 3 ? -120 : null, fy: i === 3 ? 0 : null, locked: i === 3, anchored: false }))
|
|
175
|
+
const edges = nodes.slice(1).map((target, i) => ({ from: nodes[i].id, to: target.id, source: nodes[i], target, baseLen: 40 }))
|
|
176
|
+
const physics = createLocalPhysics()
|
|
177
|
+
physics.update(nodes, edges); physics.begin(nodes[0].id); physics.move(20, 10); physics.release()
|
|
178
|
+
while (physics.active) physics.step()
|
|
179
|
+
const drop = [nodes[0].x, nodes[0].y], before = structuredClone(nodes)
|
|
180
|
+
physics.begin(nodes[1].id)
|
|
181
|
+
assert.equal(nodes[0].fx, null, 'an earlier left-drag drop is compliant during the next gesture')
|
|
182
|
+
physics.move(80, 60)
|
|
183
|
+
for (let i = 0; i < 12; i++) physics.step()
|
|
184
|
+
assert.ok(Math.hypot(nodes[0].x - drop[0], nodes[0].y - drop[1]) > 5)
|
|
185
|
+
assert.deepEqual([nodes[3].x, nodes[3].y], [-120, 0], 'right-click locks remain fixed')
|
|
186
|
+
physics.cancel()
|
|
187
|
+
assert.deepEqual(nodes, before, 'cancel restores soft anchors as well as positions')
|
|
188
|
+
physics.dispose()
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('topology expansion crosses fixed points and wakes an entire contacted branch', () => {
|
|
192
|
+
const nodes = [
|
|
193
|
+
{ id: 'root', x: 0, y: 0, radius: 8, vx: 0, vy: 0 },
|
|
194
|
+
{ id: 'pin', x: 30, y: 0, fx: 30, fy: 0, locked: true, radius: 8, vx: 0, vy: 0 },
|
|
195
|
+
{ id: 'branch', x: 12, y: 0, radius: 8, vx: 0, vy: 0 },
|
|
196
|
+
{ id: 'tail', x: 90, y: 0, radius: 8, vx: 0, vy: 0 },
|
|
197
|
+
]
|
|
198
|
+
const edge = (a, b) => ({ from: a.id, to: b.id, source: a, target: b, baseLen: 30 })
|
|
199
|
+
const edges = [edge(nodes[0], nodes[1]), edge(nodes[1], nodes[2]), edge(nodes[2], nodes[3])]
|
|
200
|
+
const physics = createLocalPhysics()
|
|
201
|
+
physics.update(nodes, edges); physics.begin('root')
|
|
202
|
+
assert.ok(physics.session.ids.has('branch'), 'initial expansion crosses a fixed bridge')
|
|
203
|
+
assert.ok(physics.session.ids.has('tail'))
|
|
204
|
+
physics.move(-5, 0); physics.step()
|
|
205
|
+
assert.ok(physics.session.ids.has('tail'), 'contact wake-up retains the full connected branch')
|
|
206
|
+
assert.deepEqual([nodes[1].x, nodes[1].y], [30, 0], 'the existing fixed point remains fixed')
|
|
207
|
+
physics.cancel(); physics.dispose()
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('reduced-motion release continues the spring solve synchronously until the chain follows', () => {
|
|
211
|
+
const nodes = Array.from({ length: 8 }, (_, i) => ({ id: `reduced-${i}`, x: -i * 20, y: 0,
|
|
212
|
+
radius: 4, vx: 0, vy: 0, fx: null, fy: null, degree: i === 0 || i === 7 ? 1 : 2 }))
|
|
213
|
+
const edges = Array.from({ length: nodes.length - 1 }, (_, i) => ({ from: nodes[i].id, to: nodes[i + 1].id,
|
|
214
|
+
source: nodes[i], target: nodes[i + 1], baseLen: 20 }))
|
|
215
|
+
const remoteStart = nodes.at(-1).x
|
|
216
|
+
const physics = createLocalPhysics()
|
|
217
|
+
physics.update(nodes, edges); physics.begin(nodes[0].id); physics.move(300, 0); physics.release(true)
|
|
218
|
+
let steps = 0
|
|
219
|
+
while (physics.active && steps < 240) { physics.step(); steps++ }
|
|
220
|
+
assert.equal(physics.active, false)
|
|
221
|
+
assert.ok(nodes.at(-1).x - remoteStart > 100, 'the far member follows even without requestAnimationFrame')
|
|
222
|
+
assert.equal(physics.diagnostics().convergenceLimited, false)
|
|
223
|
+
physics.dispose()
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
test('fast released drag keeps carrying the far spring members until the cluster settles', () => {
|
|
227
|
+
const nodes = Array.from({ length: 8 }, (_, i) => ({ id: `n${i}`, x: -i * 20, y: 0,
|
|
228
|
+
radius: 4, vx: 0, vy: 0, fx: null, fy: null, degree: i === 0 || i === 7 ? 1 : 2 }))
|
|
229
|
+
const collision = { id: 'collision', x: 700, y: 0, radius: 8, vx: 0, vy: 0, fx: null, fy: null }
|
|
230
|
+
const pinned = { id: 'pinned', x: 500, y: 500, radius: 8, vx: 0, vy: 0,
|
|
231
|
+
fx: 500, fy: 500, locked: true }
|
|
232
|
+
const allNodes = [...nodes, collision, pinned]
|
|
233
|
+
const edges = Array.from({ length: nodes.length - 1 }, (_, i) => ({ from: nodes[i].id, to: nodes[i + 1].id,
|
|
234
|
+
source: nodes[i], target: nodes[i + 1], baseLen: 20 }))
|
|
235
|
+
const physics = createLocalPhysics()
|
|
236
|
+
physics.update(allNodes, edges)
|
|
237
|
+
physics.begin(nodes[0].id)
|
|
238
|
+
const remote = nodes.at(-1), remoteStart = remote.x
|
|
239
|
+
physics.move(300, 0)
|
|
240
|
+
const drop = [nodes[0].x, nodes[0].y]
|
|
241
|
+
physics.release()
|
|
242
|
+
|
|
243
|
+
const samples = []
|
|
244
|
+
for (let i = 0; i < 20 && physics.active; i++) {
|
|
245
|
+
physics.step()
|
|
246
|
+
samples.push(remote.x)
|
|
247
|
+
}
|
|
248
|
+
assert.ok(samples.length >= 16, 'the released local solve must remain active across several frames')
|
|
249
|
+
assert.ok(samples.slice(12, 16).some((x, i, row) => i > 0 && Math.abs(x - row[i - 1]) > .01),
|
|
250
|
+
'the far member keeps its damped motion after the initial release frames')
|
|
251
|
+
|
|
252
|
+
let steps = samples.length
|
|
253
|
+
while (physics.active && steps < 240) { physics.step(); steps++ }
|
|
254
|
+
assert.equal(physics.active, false, 'the release solve must settle within a bounded number of steps')
|
|
255
|
+
assert.ok(remote.x - remoteStart > 100, 'a fast root pull must propagate substantially to the far end')
|
|
256
|
+
assert.deepEqual([nodes[0].x, nodes[0].y], drop, 'the released root stays fixed at its drop point')
|
|
257
|
+
assert.equal(nodes[0].anchored, true)
|
|
258
|
+
assert.deepEqual([pinned.x, pinned.y], [500, 500], 'pre-existing fixed nodes remain untouched')
|
|
259
|
+
assert.equal(graphGeometry(allNodes).overlaps, 0, JSON.stringify(physics.diagnostics()))
|
|
260
|
+
const maxEdgeLength = Math.max(...edges.map(edge => Math.hypot(edge.source.x - edge.target.x, edge.source.y - edge.target.y)))
|
|
261
|
+
assert.ok(maxEdgeLength < 100, `spring chain should catch up before settling (max edge ${maxEdgeLength})`)
|
|
262
|
+
assert.equal(physics.diagnostics().convergenceLimited, false)
|
|
263
|
+
physics.dispose()
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
for (const width of [1440, 390]) test(`20k browser hub path at width ${width} finishes with collision-only convergence`, () => {
|
|
267
|
+
const layout = createForceLayout(), data = denseGraph(20001)
|
|
268
|
+
layout.update(data)
|
|
269
|
+
const camera = fitCamera(layout.nodes, width, 900)
|
|
270
|
+
const root = layout.nodes.filter(node => node.degree >= 20 && node.x * camera.k + camera.x > 50
|
|
271
|
+
&& node.y * camera.k + camera.y > 50 && node.x * camera.k + camera.x < width - 120
|
|
272
|
+
&& node.y * camera.k + camera.y < 800).sort((a, b) => b.degree - a.degree)[0]
|
|
273
|
+
assert.ok(root)
|
|
274
|
+
const start = [root.x, root.y]
|
|
275
|
+
layout.beginLocalDrag(root.id)
|
|
276
|
+
for (let i = 1; i <= 45; i++) {
|
|
277
|
+
layout.moveLocalDrag(start[0] + 60 / camera.k * i / 45, start[1] + 35 / camera.k * i / 45)
|
|
278
|
+
for (let frame = 0; frame < 4; frame++) layout.stepLocal()
|
|
279
|
+
}
|
|
280
|
+
const drop = [root.x, root.y]
|
|
281
|
+
layout.releaseLocalDrag()
|
|
282
|
+
for (let i = 0; i < 240 && layout.localActive; i++) layout.stepLocal()
|
|
283
|
+
assert.equal(layout.localActive, false)
|
|
284
|
+
assert.deepEqual([root.x, root.y], drop)
|
|
285
|
+
assert.equal(graphGeometry(layout.nodes).overlaps, 0, JSON.stringify(layout.localDiagnostics()))
|
|
286
|
+
assert.equal(layout.localDiagnostics().hardOverlaps, 0)
|
|
287
|
+
assert.equal(layout.localDiagnostics().convergenceLimited, false)
|
|
288
|
+
layout.dispose()
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
for (const frames of [1, 3]) test(`20k narrow regular-grid drop recycles settled contacts with ${frames} frames per pointer move`, () => {
|
|
292
|
+
const layout = createForceLayout(), id = i => `mem-${String(i).padStart(6, '0')}`
|
|
293
|
+
layout.update({ overview: true,
|
|
294
|
+
nodes: Array.from({ length: 20001 }, (_, i) => ({ id: id(i), kind: 'memory', strength: .6, x: i % 150 * 20, y: Math.floor(i / 150) * 20 })),
|
|
295
|
+
edges: Array.from({ length: 20001 }, (_, i) => i % 1000 ? { from: id(i - 1), to: id(i), source: 'auto' } : null).filter(Boolean) })
|
|
296
|
+
const camera = fitCamera(layout.nodes, 390, 844)
|
|
297
|
+
const root = layout.nodes.find(node => node.x * camera.k + camera.x > 30 && node.y * camera.k + camera.y > 30
|
|
298
|
+
&& node.x * camera.k + camera.x < 360 && node.y * camera.k + camera.y < 814)
|
|
299
|
+
assert.equal(root.id, 'mem-000000', 'use the original scale-final-r4 visible hit target')
|
|
300
|
+
const start = [root.x, root.y]
|
|
301
|
+
layout.beginLocalDrag(root.id)
|
|
302
|
+
for (let i = 1; i <= 45; i++) {
|
|
303
|
+
layout.moveLocalDrag(start[0] + 60 / camera.k * i / 45, start[1] + 35 / camera.k * i / 45)
|
|
304
|
+
for (let frame = 0; frame < frames; frame++) layout.stepLocal()
|
|
305
|
+
}
|
|
306
|
+
const session = layout.localSession, drop = [root.x, root.y]
|
|
307
|
+
assert.equal(session.topology.size, 1000, 'all connected branches participate beyond the old 384-node cutoff')
|
|
308
|
+
assert.ok(session.members.length < layout.nodes.length, 'unrelated remote components stay frozen')
|
|
309
|
+
assert.ok(session.edgeSet.size < 8192, 'the fixture stays below the unrelated-contact spring budget')
|
|
310
|
+
layout.releaseLocalDrag()
|
|
311
|
+
let steps = 0
|
|
312
|
+
while (layout.localActive) {
|
|
313
|
+
layout.stepLocal()
|
|
314
|
+
assert.ok(++steps <= 240, 'elastic release remains bounded while distant members catch up')
|
|
315
|
+
assert.ok(session.members.length < layout.nodes.length)
|
|
316
|
+
}
|
|
317
|
+
assert.deepEqual([root.x, root.y], drop, 'cleanup must not move the fixed drop')
|
|
318
|
+
assert.equal(graphGeometry(layout.nodes).overlaps, 0, JSON.stringify(layout.localDiagnostics()))
|
|
319
|
+
const diagnostics = layout.localDiagnostics()
|
|
320
|
+
assert.equal(diagnostics.unresolved, 0, JSON.stringify(diagnostics))
|
|
321
|
+
assert.equal(diagnostics.convergenceLimited, false)
|
|
322
|
+
assert.ok(diagnostics.activeNodes < layout.nodes.length)
|
|
323
|
+
assert.ok(diagnostics.movedNodes > 20, 'the topological neighborhood and collision contacts really moved')
|
|
324
|
+
layout.dispose()
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
test('worker coordinate patches and native holds refresh collision obstacles before a local solve', () => {
|
|
328
|
+
const layout = createForceLayout(), data = denseGraph(3000)
|
|
329
|
+
layout.update(data)
|
|
330
|
+
const coordinates = Float64Array.from(layout.nodes.flatMap(node => [node.x + 10000, node.y - 10000]))
|
|
331
|
+
assert.equal(layout.applyPositions(coordinates), true)
|
|
332
|
+
const root = layout.nodes[0], obstacle = layout.nodes[250]
|
|
333
|
+
layout.beginLocalDrag(root.id); layout.moveLocalDrag(obstacle.x, obstacle.y)
|
|
334
|
+
layout.releaseLocalDrag()
|
|
335
|
+
while (layout.localActive) layout.stepLocal()
|
|
336
|
+
assert.equal(graphGeometry(layout.nodes).overlaps, 0, JSON.stringify(layout.localDiagnostics()))
|
|
337
|
+
layout.dispose()
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
test('prepositioned edge rest lengths preserve the supplied geometry and an anchor survives force settings', () => {
|
|
341
|
+
const layout = createForceLayout(), data = denseGraph(3000)
|
|
342
|
+
layout.update(data)
|
|
343
|
+
const long = layout.edges.find(edge => Math.hypot(edge.source.x - edge.target.x, edge.source.y - edge.target.y) > 300)
|
|
344
|
+
assert.ok(long)
|
|
345
|
+
assert.equal(long.baseLen, Math.hypot(long.source.x - long.target.x, long.source.y - long.target.y))
|
|
346
|
+
const root = layout.nodes[0]
|
|
347
|
+
layout.beginLocalDrag(root.id); layout.moveLocalDrag(150, 60); layout.releaseLocalDrag()
|
|
348
|
+
while (layout.localActive) layout.stepLocal()
|
|
349
|
+
const drop = [root.x, root.y]
|
|
350
|
+
layout.configure({ distance: 110 }); layout.settle(1)
|
|
351
|
+
assert.deepEqual([root.x, root.y], drop, 'native collision passes cannot move an anchored fixed point')
|
|
352
|
+
layout.dispose()
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
test('impossible fixed obstacles exhaust a bounded solve with explicit collision diagnostics', () => {
|
|
356
|
+
const physics = createLocalPhysics({ maxNodes: 2 })
|
|
357
|
+
const root = { id: 'root', x: 0, y: 0, radius: 10, vx: 0, vy: 0 }
|
|
358
|
+
const a = { id: 'a', x: 0, y: 0, fx: 0, fy: 0, radius: 10, vx: 0, vy: 0 }
|
|
359
|
+
const b = { ...a, id: 'b' }
|
|
360
|
+
physics.update([root, a, b], []); physics.begin(root.id); physics.release()
|
|
361
|
+
let steps = 0
|
|
362
|
+
while (physics.active) { physics.step(); assert.ok(++steps <= 120) }
|
|
363
|
+
// The solver reports constraints it owns; unrelated pre-existing pin-pin
|
|
364
|
+
// intersections remain in the full graph geometry audit, never silently fixed.
|
|
365
|
+
assert.equal(graphGeometry([root, a, b]).overlaps, 3)
|
|
366
|
+
assert.equal(physics.diagnostics().hardOverlaps, 2)
|
|
367
|
+
assert.equal(physics.diagnostics().convergenceLimited, true)
|
|
368
|
+
assert.deepEqual([a.x, a.y, b.x, b.y], [0, 0, 0, 0])
|
|
369
|
+
physics.dispose()
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
test('dense contact saturation is explicit and cancelling a refreshed session cannot resurrect removed obstacles', () => {
|
|
373
|
+
const physics = createLocalPhysics({ maxNodes: 2, maxEdges: 1 })
|
|
374
|
+
const nodes = Array.from({ length: 6 }, (_, i) => ({ id: String(i), x: i * 20, y: 0, vx: 0, vy: 0, radius: 8 }))
|
|
375
|
+
physics.update(nodes, []); physics.begin('0'); physics.move(10, 0); physics.step()
|
|
376
|
+
assert.equal(physics.diagnostics().saturated, true)
|
|
377
|
+
assert.equal(physics.diagnostics().activeNodes, 2)
|
|
378
|
+
const saved = [nodes[1].x, nodes[1].y]
|
|
379
|
+
physics.update([nodes[0]], []); physics.cancel()
|
|
380
|
+
nodes[0].x = saved[0]; nodes[0].y = saved[1]
|
|
381
|
+
physics.updatePosition(nodes[0]); physics.begin('0'); physics.release()
|
|
382
|
+
while (physics.active) physics.step()
|
|
383
|
+
assert.equal(physics.diagnostics().unresolved, 0, 'the removed node is not a ghost obstacle')
|
|
384
|
+
physics.dispose()
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
test('contact retirement invalidates the drag layer and cancellation restores its entire movement journal', () => {
|
|
388
|
+
const physics = createLocalPhysics({ maxNodes: 4 })
|
|
389
|
+
const nodes = Array.from({ length: 30 }, (_, i) => ({ id: String(i), x: i ? 400 + (i % 5 - 2) * 3 : 0,
|
|
390
|
+
y: i ? Math.floor(i / 5) * 3 : 0, vx: 0, vy: 0, radius: 8,
|
|
391
|
+
fx: null, fy: null, locked: false, anchored: false }))
|
|
392
|
+
nodes[23].fx = nodes[23].x; nodes[23].fy = nodes[23].y
|
|
393
|
+
const before = structuredClone(nodes)
|
|
394
|
+
physics.update(nodes, []); physics.begin('0'); physics.move(400, 0); physics.step(); physics.release()
|
|
395
|
+
const session = physics.session, version = session.version
|
|
396
|
+
for (let frame = 0; frame < 36; frame++) physics.step()
|
|
397
|
+
assert.ok(session.retiredNodes > 0)
|
|
398
|
+
assert.ok(session.version > version, 'the cached background must be rebuilt when membership retires')
|
|
399
|
+
assert.ok(physics.session, 'exercise cancellation while contact propagation is still in progress')
|
|
400
|
+
assert.ok(session.saved.size > 4, 'the cancellation journal includes retired and newly awakened nodes')
|
|
401
|
+
assert.deepEqual([nodes[23].x, nodes[23].y], [before[23].x, before[23].y], 'pre-existing pins stay fixed')
|
|
402
|
+
physics.update(nodes.filter(node => node.id !== '1'), [])
|
|
403
|
+
physics.cancel()
|
|
404
|
+
for (const node of nodes) assert.deepEqual(node, before[Number(node.id)])
|
|
405
|
+
assert.equal(physics.active, false)
|
|
406
|
+
physics.begin('0'); physics.release()
|
|
407
|
+
while (physics.active) physics.step()
|
|
408
|
+
assert.equal(physics.diagnostics().hardOverlaps, 0, 'removed retired nodes do not return as ghost obstacles')
|
|
409
|
+
physics.dispose()
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
test('fixed coordinates survive eviction and returning viewport pages, with scope isolation', () => {
|
|
413
|
+
const layout = createForceLayout(), data = denseGraph(3000)
|
|
414
|
+
layout.update(data); const node = layout.nodes[0]
|
|
415
|
+
layout.beginLocalDrag(node.id); layout.moveLocalDrag(-100, -100); layout.releaseLocalDrag()
|
|
416
|
+
while (layout.localActive) layout.stepLocal()
|
|
417
|
+
layout.update({ ...data, nodes: data.nodes.slice(1000), edges: [] })
|
|
418
|
+
assert.ok(layout.localDiagnostics().fixedPositionCache > 0)
|
|
419
|
+
layout.update(data)
|
|
420
|
+
assert.equal(layout.nodeById(node.id).x, -100); assert.equal(layout.nodeById(node.id).y, -100)
|
|
421
|
+
assert.equal(layout.nodeById(node.id).anchored, true)
|
|
422
|
+
layout.update({ ...data, positionScope: 'different-permission-context' })
|
|
423
|
+
assert.equal(layout.nodeById(node.id).anchored, false)
|
|
424
|
+
assert.equal(layout.nodeById(node.id).x, data.nodes[0].x)
|
|
425
|
+
layout.dispose()
|
|
426
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { createSpatialGrid } from '../lib/webui/graph-spatial-grid.js'
|
|
4
|
+
import { prelayoutGraph, createLayoutWorker } from '../lib/webui/graph-layout-worker.js'
|
|
5
|
+
import { createForceLayout } from '../lib/webui/graph-view.js'
|
|
6
|
+
import { createWebGLRenderer } from '../lib/webui/graph-webgl-renderer.js'
|
|
7
|
+
|
|
8
|
+
test('numeric spatial cells never alias with negative or large coordinates and reset safely', () => {
|
|
9
|
+
const grid = createSpatialGrid(1)
|
|
10
|
+
const a = { id: 'a', x: 1, y: 0 }, b = { id: 'b', x: 0, y: 8192 }, c = { id: 'c', x: -1, y: -8192 }
|
|
11
|
+
for (const node of [a, b, c]) grid.insert(node)
|
|
12
|
+
assert.deepEqual(grid.get(1, 0), [a]); assert.deepEqual(grid.get(0, 8192), [b]); assert.deepEqual(grid.get(-1, -8192), [c])
|
|
13
|
+
grid.reset(); assert.equal(grid.get(1, 0), undefined)
|
|
14
|
+
grid.insert(c); assert.deepEqual(grid.get(-1, -8192), [c]); grid.dispose()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('large prelayout is deterministic, finite, input-preserving and accepts authoritative world coordinates', () => {
|
|
18
|
+
const graph = { nodes: Array.from({ length: 3000 }, (_, i) => ({ id: `n${i}` })), edges: [] }
|
|
19
|
+
const original = structuredClone(graph), positions = prelayoutGraph(graph)
|
|
20
|
+
assert.deepEqual(positions, prelayoutGraph(graph)); assert.ok(positions.every(Number.isFinite))
|
|
21
|
+
assert.equal(new Set(Array.from({ length: 3000 }, (_, i) => JSON.stringify([positions[i * 2], positions[i * 2 + 1]]))).size, 3000)
|
|
22
|
+
assert.deepEqual(graph, original)
|
|
23
|
+
assert.deepEqual([...prelayoutGraph({ nodes: [{ id: 'fixed', x: -12999, y: 20 }], edges: [] })], [-12999, 20])
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('Worker absence and CSP constructor rejection report a bounded fallback once', () => {
|
|
27
|
+
for (const win of [{}, { Blob: class {}, URL: { createObjectURL: () => 'blob:test', revokeObjectURL() {} }, Worker: class { constructor() { throw new Error('CSP') } } }]) {
|
|
28
|
+
const signals = [], worker = createLayoutWorker(win, { onResult() {}, onFallback: signal => signals.push(signal) })
|
|
29
|
+
assert.equal(worker.request({ nodes: [], edges: [] }), false)
|
|
30
|
+
assert.equal(worker.request({ nodes: [], edges: [] }), false)
|
|
31
|
+
assert.equal(signals.length, 1); worker.dispose()
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('Worker transfers positions, ignores stale messages, cancels and releases object URLs', () => {
|
|
36
|
+
let instance, revoked = 0, terminated = 0
|
|
37
|
+
const timers = new Map(), received = []
|
|
38
|
+
const win = { Blob: class {}, URL: { createObjectURL: () => 'blob:test', revokeObjectURL: () => revoked++ },
|
|
39
|
+
setTimeout(fn) { timers.set(1, fn); return 1 }, clearTimeout(id) { timers.delete(id) },
|
|
40
|
+
Worker: class { constructor() { instance = this } postMessage(message) { this.message = message } terminate() { terminated++ } } }
|
|
41
|
+
const worker = createLayoutWorker(win, { onResult: value => received.push(value) })
|
|
42
|
+
const graph = { nodes: [{ id: 'a' }], edges: [] }
|
|
43
|
+
worker.request(graph); const old = instance.message.serial
|
|
44
|
+
worker.request(graph); const current = instance.message.serial
|
|
45
|
+
instance.onmessage({ data: { serial: old, positions: new Float64Array(2) } }); assert.equal(received.length, 0)
|
|
46
|
+
instance.onmessage({ data: { serial: current, positions: new Float64Array([1, 2]) } }); assert.equal(received.length, 1)
|
|
47
|
+
worker.request(graph); worker.cancel()
|
|
48
|
+
instance.onmessage({ data: { serial: instance.message.serial, positions: new Float64Array(2) } }); assert.equal(received.length, 1)
|
|
49
|
+
worker.dispose(); assert.equal(revoked, 1); assert.equal(terminated, 1); assert.equal(timers.size, 0)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('Worker timeouts are observable and clean up the pending instance', () => {
|
|
53
|
+
let timeout, terminated = 0
|
|
54
|
+
const reasons = []
|
|
55
|
+
const worker = createLayoutWorker({ Blob: class {}, URL: { createObjectURL: () => 'blob:test', revokeObjectURL() {} },
|
|
56
|
+
setTimeout(fn) { timeout = fn; return 1 }, clearTimeout() {}, Worker: class { postMessage() {} terminate() { terminated++ } } },
|
|
57
|
+
{ onResult() {}, onFallback: reason => reasons.push(reason) })
|
|
58
|
+
worker.request({ nodes: [], edges: [] }); timeout()
|
|
59
|
+
assert.deepEqual(reasons, ['worker-timeout']); assert.equal(terminated, 1); worker.dispose()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('malformed Worker coordinates fail over instead of poisoning the canvas', () => {
|
|
63
|
+
let instance
|
|
64
|
+
const reasons = [], worker = createLayoutWorker({ Blob: class {}, URL: { createObjectURL: () => 'blob:test', revokeObjectURL() {} },
|
|
65
|
+
setTimeout: () => 1, clearTimeout() {}, Worker: class { constructor() { instance = this } postMessage(message) { this.message = message } terminate() {} } },
|
|
66
|
+
{ onResult() { assert.fail('invalid coordinates must never be applied') }, onFallback: reason => reasons.push(reason) })
|
|
67
|
+
worker.request({ nodes: [{ id: 'a' }], edges: [] })
|
|
68
|
+
instance.onmessage({ data: { serial: instance.message.serial, positions: new Float64Array([NaN, 2]) } })
|
|
69
|
+
assert.deepEqual(reasons, ['worker-invalid-output']); worker.dispose()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('coordinate patches preserve pins, cool the large layout and reject corrupt worker output', () => {
|
|
73
|
+
const layout = createForceLayout(), graph = { nodes: Array.from({ length: 3000 }, (_, i) => ({ id: `n${i}` })), edges: [] }
|
|
74
|
+
layout.update(graph)
|
|
75
|
+
assert.equal(layout.active, false)
|
|
76
|
+
layout.pin(layout.nodes[0].id, 4, 8)
|
|
77
|
+
const positions = prelayoutGraph({ nodes: layout.nodes.map(node => ({ id: node.id })), edges: [] })
|
|
78
|
+
assert.equal(layout.applyPositions(positions), true)
|
|
79
|
+
assert.equal(layout.nodes[0].x, 4); assert.equal(layout.nodes[0].y, 8); assert.equal(layout.active, false)
|
|
80
|
+
positions[3] = NaN; assert.equal(layout.applyPositions(positions), false)
|
|
81
|
+
assert.equal(layout.applyPositions(new Float64Array(2)), false); layout.dispose()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('WebGL is a capability-detected optional layer', () => {
|
|
85
|
+
assert.equal(createWebGLRenderer({}), null)
|
|
86
|
+
assert.equal(createWebGLRenderer({ createElement: () => ({ getContext: () => null }) }), null)
|
|
87
|
+
assert.equal(createWebGLRenderer({ createElement() { throw new Error('unsupported') } }), null)
|
|
88
|
+
})
|