@myrialabs/clopen 0.4.49 → 0.4.50
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/backend/chat/background-wait.test.ts +28 -0
- package/backend/chat/message-pages.test.ts +17 -0
- package/backend/chat/message-pages.ts +6 -2
- package/backend/chat/stream-manager.ts +73 -14
- package/backend/database/migrations/088_create_messages_fts_map.ts +52 -0
- package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
- package/backend/database/migrations/index.ts +14 -0
- package/backend/database/queries/graph-queries.ts +392 -135
- package/backend/database/queries/message-fts.test.ts +120 -0
- package/backend/database/queries/message-queries.ts +45 -9
- package/backend/database/queries/session-queries.ts +3 -2
- package/backend/database/queries/utils-queries.ts +3 -0
- package/backend/engine/adapters/claude/environment.ts +4 -0
- package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
- package/backend/engine/adapters/claude/input-gate.ts +74 -0
- package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
- package/backend/engine/adapters/claude/message-converter.ts +8 -0
- package/backend/engine/adapters/claude/stream.ts +15 -0
- package/backend/git/identity/scope-config.test.ts +7 -4
- package/backend/index.ts +35 -8
- package/backend/memory/README.md +7 -4
- package/backend/memory/layout.test.ts +377 -0
- package/backend/memory/layout.ts +1029 -265
- package/backend/memory/view.ts +257 -386
- package/backend/project/status-manager.ts +4 -2
- package/backend/ws/chat/stream.ts +19 -10
- package/backend/ws/memory/crud.ts +118 -81
- package/backend/ws/messages/crud.ts +3 -1
- package/bin/clopen.ts +3 -2
- package/dist/assets/{index-DD0-3EWg.js → index-By6KdSLT.js} +1 -1
- package/dist/assets/index-By6KdSLT.js.br +0 -0
- package/dist/assets/index-By6KdSLT.js.gz +0 -0
- package/dist/assets/{index-CrVWZH_D.js → index-DV4TiDn1.js} +1 -1
- package/dist/assets/index-DV4TiDn1.js.br +0 -0
- package/dist/assets/index-DV4TiDn1.js.gz +0 -0
- package/dist/assets/main-DIESTGTD.css +1 -0
- package/dist/assets/main-DIESTGTD.css.br +0 -0
- package/dist/assets/main-DIESTGTD.css.gz +0 -0
- package/dist/assets/{main-D2_TmcwQ.js → main-Da3JKoua.js} +612 -612
- package/dist/assets/main-Da3JKoua.js.br +0 -0
- package/dist/assets/main-Da3JKoua.js.gz +0 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/package.json +3 -3
- package/shared/types/memory.ts +96 -73
- package/shared/types/unified/index.ts +1 -0
- package/shared/types/unified/stream.ts +22 -1
- package/shared/utils/process-supervisor.test.ts +71 -1
- package/shared/utils/process-supervisor.ts +134 -29
- package/shared/utils/process-tree.ts +99 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +0 -1
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +0 -1
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory graph layout + tile tests.
|
|
3
|
+
*
|
|
4
|
+
* Run against a REAL in-memory SQLite database with the graph migrations
|
|
5
|
+
* applied, because what is under test is the arrangement the pass leaves in the
|
|
6
|
+
* table and what the tile queries read back out of it.
|
|
7
|
+
*
|
|
8
|
+
* The regression these exist for: warm passes used to re-settle the whole map
|
|
9
|
+
* from its own previous result, which inflated it by ~1.4× per pass until the
|
|
10
|
+
* coordinates overflowed to NaN and every pass failed on the NOT NULL
|
|
11
|
+
* constraint. Stability across passes is therefore asserted EXACTLY, not
|
|
12
|
+
* approximately.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
16
|
+
import { Database } from 'bun:sqlite';
|
|
17
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
18
|
+
import * as migration005 from '$backend/database/migrations/005_create_settings_table';
|
|
19
|
+
import * as migration066 from '$backend/database/migrations/066_create_memory_graph';
|
|
20
|
+
import * as migration067 from '$backend/database/migrations/067_add_memory_graph_layout';
|
|
21
|
+
import * as migration076 from '$backend/database/migrations/076_remove_memory_code_graph';
|
|
22
|
+
import * as migration089 from '$backend/database/migrations/089_add_memory_layout_tiles';
|
|
23
|
+
|
|
24
|
+
let db: Database;
|
|
25
|
+
|
|
26
|
+
// The whole module surface, not just `getDatabase` — see retrieval.test.ts.
|
|
27
|
+
mock.module('$backend/database', () => ({
|
|
28
|
+
getDatabase: () => db,
|
|
29
|
+
initializeDatabase: async () => db,
|
|
30
|
+
closeDatabase: () => {},
|
|
31
|
+
resetDatabase: async () => {},
|
|
32
|
+
getDatabaseInfo: async () => ({}),
|
|
33
|
+
vacuumDatabase: async () => {}
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
// The pass announces its result over the WebSocket, which has no server here.
|
|
37
|
+
mock.module('$backend/memory/notify', () => ({
|
|
38
|
+
notifyGraphChanged: () => {},
|
|
39
|
+
broadcastGraphChanged: () => {},
|
|
40
|
+
notifyMemoryStatus: () => {},
|
|
41
|
+
notifyMemoryReadiness: () => {}
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
const { graphQueries, graphLayoutQueries } = await import('$backend/database/queries/graph-queries');
|
|
45
|
+
const { runGraphLayout, resetGraphLayoutState, getLayoutState, alignTo } = await import('./layout');
|
|
46
|
+
const { buildGraphMeta, buildGraphTiles, locateNodes } = await import('./view');
|
|
47
|
+
|
|
48
|
+
const PROJECT = 'project-a';
|
|
49
|
+
|
|
50
|
+
function resetDatabase(): void {
|
|
51
|
+
db = new Database(':memory:');
|
|
52
|
+
db.exec('PRAGMA foreign_keys = ON');
|
|
53
|
+
const connection = db as unknown as DatabaseConnection;
|
|
54
|
+
migration005.up(connection);
|
|
55
|
+
migration066.up(connection);
|
|
56
|
+
migration067.up(connection);
|
|
57
|
+
migration076.up(connection);
|
|
58
|
+
migration089.up(connection);
|
|
59
|
+
resetGraphLayoutState();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A store with structure: subjects that group memories, a few stored edges, and loners. */
|
|
63
|
+
function seed(subjects = 6, perSubject = 12, loners = 8): string[] {
|
|
64
|
+
const ids: string[] = [];
|
|
65
|
+
for (let s = 0; s < subjects; s++) {
|
|
66
|
+
const members: string[] = [];
|
|
67
|
+
for (let m = 0; m < perSubject; m++) {
|
|
68
|
+
const node = graphQueries.upsert({
|
|
69
|
+
subkind: 'decision',
|
|
70
|
+
projectId: PROJECT,
|
|
71
|
+
label: `Subject ${s} decision ${m}`
|
|
72
|
+
});
|
|
73
|
+
graphQueries.setEntities(node.id, [{ key: `subject-${s}`, name: `Subject ${s}` }]);
|
|
74
|
+
members.push(node.id);
|
|
75
|
+
}
|
|
76
|
+
// A stored edge between neighbouring subjects, so the graph is one mass
|
|
77
|
+
// with lobes rather than six islands.
|
|
78
|
+
if (s > 0) graphQueries.link({ srcId: ids[ids.length - 1], dstId: members[0], rel: 'relates_to' });
|
|
79
|
+
ids.push(...members);
|
|
80
|
+
}
|
|
81
|
+
for (let l = 0; l < loners; l++) {
|
|
82
|
+
ids.push(graphQueries.upsert({ subkind: 'observation', projectId: PROJECT, label: `Loner ${l}` }).id);
|
|
83
|
+
}
|
|
84
|
+
return ids;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function positions(): Map<string, { x: number; y: number; community: number }> {
|
|
88
|
+
const rows = db.prepare('SELECT node_id AS id, x, y, community FROM graph_layout').all() as {
|
|
89
|
+
id: string;
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
community: number;
|
|
93
|
+
}[];
|
|
94
|
+
return new Map(rows.map(row => [row.id, { x: row.x, y: row.y, community: row.community }]));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Force the next pass to do real work rather than skip on an unchanged fingerprint. */
|
|
98
|
+
async function pass(): Promise<void> {
|
|
99
|
+
resetGraphLayoutState();
|
|
100
|
+
await runGraphLayout();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
beforeEach(() => {
|
|
104
|
+
resetDatabase();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('memory layout', () => {
|
|
108
|
+
it('lays out every live memory with finite positions inside the world', async () => {
|
|
109
|
+
const ids = seed();
|
|
110
|
+
await pass();
|
|
111
|
+
|
|
112
|
+
const placed = positions();
|
|
113
|
+
const state = getLayoutState();
|
|
114
|
+
expect(placed.size).toBe(ids.length);
|
|
115
|
+
expect(state.world).not.toBeNull();
|
|
116
|
+
expect(state.coldNodes).toBe(ids.length);
|
|
117
|
+
// What the view sizes nodes by: the median room a memory has.
|
|
118
|
+
expect(state.spacing).toBeGreaterThan(0);
|
|
119
|
+
expect(Number.isFinite(state.spacing)).toBe(true);
|
|
120
|
+
|
|
121
|
+
const world = state.world!;
|
|
122
|
+
for (const point of placed.values()) {
|
|
123
|
+
expect(Number.isFinite(point.x) && Number.isFinite(point.y)).toBe(true);
|
|
124
|
+
expect(point.x).toBeGreaterThanOrEqual(world.minX);
|
|
125
|
+
expect(point.y).toBeGreaterThanOrEqual(world.minY);
|
|
126
|
+
expect(point.x).toBeLessThan(world.minX + world.size);
|
|
127
|
+
expect(point.y).toBeLessThan(world.minY + world.size);
|
|
128
|
+
}
|
|
129
|
+
// Derived edges are kept for the view to draw.
|
|
130
|
+
const derived = (db.prepare('SELECT COUNT(*) AS c FROM graph_layout_edges').get() as { c: number }).c;
|
|
131
|
+
expect(derived).toBeGreaterThan(0);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('leaves the map exactly where it was across passes over unchanged data', async () => {
|
|
135
|
+
seed();
|
|
136
|
+
await pass();
|
|
137
|
+
const first = positions();
|
|
138
|
+
const epoch = getLayoutState().epoch;
|
|
139
|
+
|
|
140
|
+
for (let i = 0; i < 4; i++) await pass();
|
|
141
|
+
|
|
142
|
+
const later = positions();
|
|
143
|
+
for (const [id, point] of first) expect(later.get(id)).toEqual(point);
|
|
144
|
+
expect(getLayoutState().epoch).toBe(epoch);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('places arrivals next to what they connect to without moving anything else', async () => {
|
|
148
|
+
seed(6, 12, 8);
|
|
149
|
+
await pass();
|
|
150
|
+
const before = positions();
|
|
151
|
+
const stamp = getLayoutState().stamp;
|
|
152
|
+
|
|
153
|
+
// Two arrivals about an existing subject — under the re-arrangement threshold.
|
|
154
|
+
const arrivals = [0, 1].map(i => {
|
|
155
|
+
const node = graphQueries.upsert({ subkind: 'decision', projectId: PROJECT, label: `Arrival ${i}` });
|
|
156
|
+
graphQueries.setEntities(node.id, [{ key: 'subject-0', name: 'Subject 0' }]);
|
|
157
|
+
return node.id;
|
|
158
|
+
});
|
|
159
|
+
await pass();
|
|
160
|
+
|
|
161
|
+
const after = positions();
|
|
162
|
+
for (const [id, point] of before) expect(after.get(id)).toEqual(point);
|
|
163
|
+
for (const id of arrivals) {
|
|
164
|
+
const point = after.get(id);
|
|
165
|
+
expect(point).toBeDefined();
|
|
166
|
+
expect(Number.isFinite(point!.x) && Number.isFinite(point!.y)).toBe(true);
|
|
167
|
+
// Next to what it connects to, not flung across the map: at the centre
|
|
168
|
+
// of the memories its edges lead to, within a neighbour's distance or
|
|
169
|
+
// two. Measured against its EDGES rather than its subject's members,
|
|
170
|
+
// because Louvain is free to split one subject across several lobes.
|
|
171
|
+
const partners = (
|
|
172
|
+
db
|
|
173
|
+
.prepare(
|
|
174
|
+
`SELECT CASE WHEN src_id = ? THEN dst_id ELSE src_id END AS id FROM graph_layout_edges
|
|
175
|
+
WHERE src_id = ? OR dst_id = ?`
|
|
176
|
+
)
|
|
177
|
+
.all(id, id, id) as { id: string }[]
|
|
178
|
+
)
|
|
179
|
+
.map(row => row.id)
|
|
180
|
+
.filter(partner => !arrivals.includes(partner))
|
|
181
|
+
.map(partner => before.get(partner)!);
|
|
182
|
+
expect(partners.length).toBeGreaterThan(0);
|
|
183
|
+
const cx = partners.reduce((sum, partner) => sum + partner.x, 0) / partners.length;
|
|
184
|
+
const cy = partners.reduce((sum, partner) => sum + partner.y, 0) / partners.length;
|
|
185
|
+
expect(Math.hypot(point!.x - cx, point!.y - cy)).toBeLessThan(getLayoutState().spacing * 2);
|
|
186
|
+
|
|
187
|
+
// And it takes the colour most of them carry.
|
|
188
|
+
const votes = new Map<number, number>();
|
|
189
|
+
for (const partner of partners) votes.set(partner.community, (votes.get(partner.community) ?? 0) + 1);
|
|
190
|
+
const top = Math.max(...votes.values());
|
|
191
|
+
expect(votes.get(point!.community)).toBe(top);
|
|
192
|
+
}
|
|
193
|
+
expect(getLayoutState().arrivals).toBe(2);
|
|
194
|
+
// The stamp is what tells a client its tiles are out of date.
|
|
195
|
+
expect(getLayoutState().stamp).toBeGreaterThan(stamp);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('recovers from a diverged arrangement by laying out from scratch', async () => {
|
|
199
|
+
seed();
|
|
200
|
+
await pass();
|
|
201
|
+
const epoch = getLayoutState().epoch;
|
|
202
|
+
|
|
203
|
+
// What the old warm passes compounded to: coordinates near the float range.
|
|
204
|
+
db.exec('UPDATE graph_layout SET x = x * 1e34, y = y * 1e34');
|
|
205
|
+
await pass();
|
|
206
|
+
|
|
207
|
+
const bounds = graphLayoutQueries.bounds();
|
|
208
|
+
expect(bounds).not.toBeNull();
|
|
209
|
+
expect(bounds!.magnitude).toBeLessThan(1e6);
|
|
210
|
+
expect(getLayoutState().epoch).toBeGreaterThan(epoch);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('re-arranges once the store outgrows its arrangement, keeping its colours', async () => {
|
|
214
|
+
const ids = seed(6, 12, 8);
|
|
215
|
+
await pass();
|
|
216
|
+
const before = positions();
|
|
217
|
+
const epoch = getLayoutState().epoch;
|
|
218
|
+
|
|
219
|
+
// Well past a fifth of the store, all joining existing subjects.
|
|
220
|
+
for (let i = 0; i < 24; i++) {
|
|
221
|
+
const node = graphQueries.upsert({ subkind: 'pattern', projectId: PROJECT, label: `Growth ${i}` });
|
|
222
|
+
graphQueries.setEntities(node.id, [{ key: `subject-${i % 6}`, name: `Subject ${i % 6}` }]);
|
|
223
|
+
}
|
|
224
|
+
await pass();
|
|
225
|
+
|
|
226
|
+
const state = getLayoutState();
|
|
227
|
+
expect(state.epoch).toBeGreaterThan(epoch);
|
|
228
|
+
expect(state.arrivals).toBe(0);
|
|
229
|
+
expect(state.coldNodes).toBe(ids.length + 24);
|
|
230
|
+
|
|
231
|
+
// Most memories keep the community NUMBER they had, so their colour holds
|
|
232
|
+
// even though Louvain numbered the new communities however it liked.
|
|
233
|
+
const after = positions();
|
|
234
|
+
let sameColour = 0;
|
|
235
|
+
for (const [id, point] of before) if (after.get(id)?.community === point.community) sameColour++;
|
|
236
|
+
expect(sameColour / before.size).toBeGreaterThan(0.6);
|
|
237
|
+
|
|
238
|
+
const bounds = graphLayoutQueries.bounds();
|
|
239
|
+
expect(bounds!.magnitude).toBeLessThan(1e6);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('turns a fresh arrangement to face the way the previous one did, without scaling it', () => {
|
|
243
|
+
const old = new Map<string, { nodeId: string; community: number; x: number; y: number; placed: number; degree: number }>();
|
|
244
|
+
const fresh: { nodeId: string; community: number; x: number; y: number; placed: number; degree: number }[] = [];
|
|
245
|
+
const angle = 1.27;
|
|
246
|
+
for (let i = 0; i < 40; i++) {
|
|
247
|
+
const x = Math.cos(i * 0.7) * (100 + i * 13);
|
|
248
|
+
const y = Math.sin(i * 1.3) * (60 + i * 7);
|
|
249
|
+
old.set(`n${i}`, { nodeId: `n${i}`, community: 0, x, y, placed: 1, degree: 0 });
|
|
250
|
+
// The same arrangement mirrored, rotated and moved — what a fresh
|
|
251
|
+
// simulation of the same graph is free to come back as.
|
|
252
|
+
const mx = x;
|
|
253
|
+
const my = -y;
|
|
254
|
+
fresh.push({
|
|
255
|
+
nodeId: `n${i}`,
|
|
256
|
+
community: 0,
|
|
257
|
+
x: Math.cos(angle) * mx - Math.sin(angle) * my + 5_000,
|
|
258
|
+
y: Math.sin(angle) * mx + Math.cos(angle) * my - 3_000,
|
|
259
|
+
placed: 1,
|
|
260
|
+
degree: 0
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
alignTo(fresh, old);
|
|
265
|
+
|
|
266
|
+
for (const row of fresh) {
|
|
267
|
+
const target = old.get(row.nodeId)!;
|
|
268
|
+
expect(Math.abs(row.x - target.x)).toBeLessThan(1e-6);
|
|
269
|
+
expect(Math.abs(row.y - target.y)).toBeLessThan(1e-6);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('gives archived memories a place so "show archived" can draw them', async () => {
|
|
274
|
+
const ids = seed();
|
|
275
|
+
graphQueries.archive(ids[3]);
|
|
276
|
+
await pass();
|
|
277
|
+
|
|
278
|
+
expect(positions().has(ids[3])).toBe(true);
|
|
279
|
+
const meta = buildGraphMeta({ includeArchived: true });
|
|
280
|
+
expect(meta.total).toBe(ids.length);
|
|
281
|
+
expect(meta.unplaced).toBe(0);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe('graph tiles', () => {
|
|
286
|
+
const allTiles = (z: number) => {
|
|
287
|
+
const tiles: { x: number; y: number }[] = [];
|
|
288
|
+
for (let x = 0; x < 2 ** z; x++) for (let y = 0; y < 2 ** z; y++) tiles.push({ x, y });
|
|
289
|
+
return tiles;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
it('serves every memory individually when the screen can afford them', async () => {
|
|
293
|
+
const ids = seed();
|
|
294
|
+
await pass();
|
|
295
|
+
const meta = buildGraphMeta({});
|
|
296
|
+
|
|
297
|
+
for (const z of [0, 1, 2]) {
|
|
298
|
+
const response = buildGraphTiles({ epoch: meta.epoch, z, tiles: allTiles(z), budget: 12_000 });
|
|
299
|
+
expect(response.stale).toBe(false);
|
|
300
|
+
const nodes = response.tiles.flatMap(tile => tile.nodes.map(node => node.id));
|
|
301
|
+
expect(new Set(nodes).size).toBe(ids.length);
|
|
302
|
+
expect(response.tiles.every(tile => tile.clusters.length === 0)).toBe(true);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('folds crowded tiles when the budget is small, without losing a memory', async () => {
|
|
307
|
+
const ids = seed(8, 40, 10);
|
|
308
|
+
await pass();
|
|
309
|
+
const meta = buildGraphMeta({});
|
|
310
|
+
|
|
311
|
+
const response = buildGraphTiles({ epoch: meta.epoch, z: 0, tiles: [{ x: 0, y: 0 }], budget: 256 });
|
|
312
|
+
const [tile] = response.tiles;
|
|
313
|
+
expect(tile.cells).toBeGreaterThan(0);
|
|
314
|
+
expect(tile.clusters.length).toBeGreaterThan(0);
|
|
315
|
+
expect(tile.nodes.length + tile.clusters.length).toBeLessThanOrEqual(256);
|
|
316
|
+
|
|
317
|
+
const covered = tile.nodes.length + tile.clusters.reduce((sum, cluster) => sum + cluster.members, 0);
|
|
318
|
+
expect(covered).toBe(ids.length);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('answers stale instead of serving tiles from another map', async () => {
|
|
322
|
+
seed();
|
|
323
|
+
await pass();
|
|
324
|
+
const meta = buildGraphMeta({});
|
|
325
|
+
|
|
326
|
+
const response = buildGraphTiles({ epoch: meta.epoch + 1, z: 0, tiles: [{ x: 0, y: 0 }], budget: 12_000 });
|
|
327
|
+
expect(response.stale).toBe(true);
|
|
328
|
+
expect(response.tiles).toHaveLength(0);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('sends each edge once per request, with where its far end is', async () => {
|
|
332
|
+
seed();
|
|
333
|
+
await pass();
|
|
334
|
+
const meta = buildGraphMeta({});
|
|
335
|
+
|
|
336
|
+
const response = buildGraphTiles({ epoch: meta.epoch, z: 2, tiles: allTiles(2), budget: 12_000 });
|
|
337
|
+
const pairs = response.tiles.flatMap(tile =>
|
|
338
|
+
tile.edges.map(edge => (edge.source < edge.target ? `${edge.source}|${edge.target}` : `${edge.target}|${edge.source}`))
|
|
339
|
+
);
|
|
340
|
+
expect(pairs.length).toBeGreaterThan(0);
|
|
341
|
+
expect(new Set(pairs).size).toBe(pairs.length);
|
|
342
|
+
|
|
343
|
+
const placed = positions();
|
|
344
|
+
for (const tile of response.tiles) {
|
|
345
|
+
for (const edge of tile.edges) {
|
|
346
|
+
const far = placed.get(edge.target)!;
|
|
347
|
+
expect(Math.abs(edge.targetX - far.x)).toBeLessThan(0.1);
|
|
348
|
+
expect(Math.abs(edge.targetY - far.y)).toBeLessThan(0.1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('narrows tiles and counts by the filter', async () => {
|
|
354
|
+
seed();
|
|
355
|
+
const other = graphQueries.upsert({ subkind: 'decision', projectId: 'project-b', label: 'Elsewhere' });
|
|
356
|
+
await pass();
|
|
357
|
+
|
|
358
|
+
const meta = buildGraphMeta({ projectIds: ['project-b'] });
|
|
359
|
+
expect(meta.total).toBe(1);
|
|
360
|
+
const response = buildGraphTiles({
|
|
361
|
+
epoch: meta.epoch,
|
|
362
|
+
z: 0,
|
|
363
|
+
tiles: [{ x: 0, y: 0 }],
|
|
364
|
+
budget: 12_000,
|
|
365
|
+
projectIds: ['project-b']
|
|
366
|
+
});
|
|
367
|
+
expect(response.tiles[0].nodes.map(node => node.id)).toEqual([other.id]);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('locates memories by id for going to one that is not drawn', async () => {
|
|
371
|
+
const ids = seed();
|
|
372
|
+
await pass();
|
|
373
|
+
const located = locateNodes([ids[5], 'missing-id']);
|
|
374
|
+
expect(located.map(node => node.id)).toEqual([ids[5]]);
|
|
375
|
+
expect(Number.isFinite(located[0].x)).toBe(true);
|
|
376
|
+
});
|
|
377
|
+
});
|