diff --git a/ui/e2e/budgets.spec.ts b/ui/e2e/budgets.spec.ts index 045bd6035b..8a37301716 100644 --- a/ui/e2e/budgets.spec.ts +++ b/ui/e2e/budgets.spec.ts @@ -17,9 +17,9 @@ import { fileURLToPath } from 'node:url'; // on how many frames the machine draws. Budgets sit just above the measured values; the breakdown next // to each says where the count comes from. -type Cost = { restyles: number; relayouts: number; forced: number; widest: number; animations: number; animated: number; mutations: number; nodes: number; head: number; drawn: number; reads: number; calls: number }; -// Only some gestures budget their calls, restyles and relayouts; the rest report them. -type Budget = Omit & Partial>; +type Cost = { restyles: number; relayouts: number; forced: number; widest: number; animations: number; animated: number; mutations: number; nodes: number; head: number; drawn: number; reads: number; calls: number; layout: number }; +// Only some gestures budget their calls, restyles and relayouts, and the page thread's layout calls; the rest report them. +type Budget = Omit & Partial>; const RATE = Number(process.env.BUDGET_CPU_RATE ?? '1'); const TRACE = !!process.env.BUDGET_TRACE; @@ -191,26 +191,28 @@ async function open(page: Page, path: string, ready: string): Promise boolean>(); +/** The graph layout's own code and dagre's: a layout run on the page's thread calls into these. */ +const LAYOUT_SOURCES = ['/src/lib/lineage/layout.ts', '/@dagrejs/dagre/']; +const sources = new Map string>(); /** Whether the build has source maps: its route modules each have one. */ let mapped: boolean | undefined; const buildHasMaps = () => (mapped ??= readdirSync(fileURLToPath(new URL('../build/_app/immutable/nodes', import.meta.url))).some((f) => f.endsWith('.js.map'))); /** - * Whether the function starting at `offset` of the built script at `pathname` is the mock client's, from - * the build's source maps (`vite build --sourcemap`). The mock answers every read in the page, as the - * server would outside it, so its calls are the server's work, not the UI's. + * The source file of the function starting at `offset` of the built script at `pathname`, from the build's + * source maps (`vite build --sourcemap`); empty when the script has no source of its own. The mock answers + * every read in the page, as the server would outside it, so its calls are the server's work, not the UI's. */ -function mockAt(pathname: string): (offset: number) => boolean { - const known = inMock.get(pathname); +function sourceAt(pathname: string): (offset: number) => string { + const known = sources.get(pathname); if (known) return known; const file = fileURLToPath(new URL(`../build${pathname}`, import.meta.url)); const source = readFileSync(file, 'utf8'); // A script the bundler wrote with no source of its own, such as its module preload helper, has no map // and holds none of the mock's code; in a build with maps, every other script names its map. if (!source.includes('//# sourceMappingURL=') && buildHasMaps()) { - const none = () => false; - inMock.set(pathname, none); + const none = () => ''; + sources.set(pathname, none); return none; } let map: TraceMap; @@ -221,33 +223,42 @@ function mockAt(pathname: string): (offset: number) => boolean { } const lineStarts = [0]; for (let i = 0; i < source.length; i++) if (source.charCodeAt(i) === 10) lineStarts.push(i + 1); - const test = (offset: number) => { + const at = (offset: number) => { let line = 0; for (let step = 1 << 20; step > 0; step >>= 1) if (line + step < lineStarts.length && lineStarts[line + step] <= offset) line += step; - return originalPositionFor(map, { line: line + 1, column: offset - lineStarts[line] }).source?.includes(MOCK_SOURCE) ?? false; + return originalPositionFor(map, { line: line + 1, column: offset - lineStarts[line] }).source ?? ''; }; - inMock.set(pathname, test); - return test; + sources.set(pathname, at); + return at; } /** The function call counts since the last take, which resets them. */ const takeCalls = async (cdp: CDPSession) => (await cdp.send('Profiler.takePreciseCoverage')).result; /** - * The UI's function calls in a take. Only the app's own scripts count: Playwright's injected scripts poll - * locators on a timer, so their calls depend on how fast the machine runs. Of those, the mock client's - * are left out (`mockAt`), which reads source maps, so it runs after the gesture's other counts are read. + * The UI's function calls in a take on the page's thread, and how many of them are the graph layout's. Only + * the app's own scripts count: Playwright's injected scripts poll locators on a timer, so their calls depend + * on how fast the machine runs. Of those, the mock client's are left out (`sourceAt`), which reads source + * maps, so it runs after the gesture's other counts are read. A worker's calls are its own, outside the page. */ -function uiCalls(page: Page, result: Awaited>): number { +function uiCalls(page: Page, result: Awaited>): { calls: number; layout: number } { const origin = new URL(page.url()).origin; let calls = 0; + let layout = 0; for (const script of result) { if (!script.url.startsWith(origin)) continue; const { pathname } = new URL(script.url); - const mock = pathname.endsWith('.js') ? mockAt(pathname) : () => false; - for (const fn of script.functions) if (fn.ranges[0].count > 0 && !mock(fn.ranges[0].startOffset)) calls += fn.ranges[0].count; + const source = pathname.endsWith('.js') ? sourceAt(pathname) : () => ''; + for (const fn of script.functions) { + const count = fn.ranges[0].count; + if (!count) continue; + const from = source(fn.ranges[0].startOffset); + if (from.includes(MOCK_SOURCE)) continue; + calls += count; + if (LAYOUT_SOURCES.some((s) => from.includes(s))) layout += count; + } } - return calls; + return { calls, layout }; } /** The cost of `act`, which ends with the page settled; `drawn` counts `drawnSelector` afterwards. */ @@ -272,7 +283,7 @@ async function cost(page: Page, cdp: CDPSession, drawnSelector: string, act: () const took = await takeCalls(cdp); const after = await counters(page, cdp); await counting(page, false); - const calls = uiCalls(page, took); + const { calls, layout } = uiCalls(page, took); const readNames = Object.entries(after.readsByName) .map(([name, n]) => [name, n - (before.readsByName[name] ?? 0)] as const) .filter(([, n]) => n > 0) @@ -292,7 +303,8 @@ async function cost(page: Page, cdp: CDPSession, drawnSelector: string, act: () head: after.head, drawn: await page.locator(drawnSelector).count(), reads: after.reads - before.reads, - calls + calls, + layout }; } @@ -386,6 +398,20 @@ for (const { name, path } of GRAPHS) { }); } +// Expand all on a project whose folders all wait on each other, at every depth: it opens what fits in +// the 600 cards drawn, about 590, and lays them out on the compound path. The layout's own work, and +// dagre's, is the worker's; the page's thread only draws what it sends back. +test('Lineage: Expand all on a project whose folders all wait on each other', async ({ page }) => { + test.setTimeout(240_000); + const cdp = await open(page, '/lineage?mock&tangled&still', `.graph-canvas:not(.unfitted) ${CARD}`); + const measured = await cost(page, cdp, CARD, async () => { + await page.getByRole('button', { name: 'Expand all' }).click(); + await page.locator('.expand-note').waitFor(); + await page.locator('.graph-canvas:not(.laying):not(.unfitted) .svelte-flow__node-folderBox:not(.unplaced)').first().waitFor({ timeout: 120_000 }); + }); + judge('Lineage Expand all', measured, BUDGETS['Lineage Expand all']); +}); + const ROW = 'table.sb-table tbody tr:not(.spacer)'; test('Checks: second visit with thousands of checks, then scrolling the list', async ({ page }) => { @@ -594,48 +620,53 @@ const BUDGETS: Record = { // The group as it opens, every job flat: the same gesture as by folder below, with 42 cards in view // instead of 9, so the settle starts 168 fades on 42 cards (the widest recalculation, 1,304 elements). // Measured restyles 118, relayouts 275, forced 0, mutations 108, 5,692 nodes, 42 cards. - 'large group wheel zoom': { restyles: 120, relayouts: 277, forced: 2, widest: 1306, animations: 170, animated: 44, mutations: 110, nodes: 5966, head: 138, drawn: 45, reads: 0 }, + 'large group wheel zoom': { restyles: 120, relayouts: 277, forced: 2, widest: 1306, animations: 170, animated: 44, mutations: 110, nodes: 5966, head: 144, drawn: 45, reads: 0 }, // 40 pointer moves across denser cards: one transform write each, plus the cards panned into view. // Measured restyles 110, relayouts 22, forced 1, widest 419, animations 4, animated 1, mutations 105. - 'large group drag-pan': { restyles: 112, relayouts: 24, forced: 3, widest: 421, animations: 6, animated: 3, mutations: 107, nodes: 5966, head: 138, drawn: 45, reads: 0 }, + 'large group drag-pan': { restyles: 112, relayouts: 24, forced: 3, widest: 421, animations: 6, animated: 3, mutations: 107, nodes: 5966, head: 144, drawn: 45, reads: 0 }, // 60 wheel steps: the viewport transform is written once per step that moves (35; the rest stop at // the zoom limit), the zoom buttons toggle 3 times, and the settle restyles 7 edge paths, redraws the // grid, sets the canvas classes and starts the cards' 36 fades (the widest recalculation, 223 // elements, 9 animated). Measured restyles 68, relayouts 64, forced 0, mutations 56, 2,380 nodes, 9 cards. - 'large group by folder wheel zoom': { restyles: 70, relayouts: 66, forced: 2, widest: 225, animations: 38, animated: 11, mutations: 56, nodes: 2466, head: 138, drawn: 12, reads: 0 }, + 'large group by folder wheel zoom': { restyles: 70, relayouts: 66, forced: 2, widest: 225, animations: 38, animated: 11, mutations: 56, nodes: 2466, head: 144, drawn: 12, reads: 0 }, // 40 pointer moves: one transform write each, plus the settle. // Measured restyles 58, relayouts 2, forced 0–1, widest 62, animations 4, animated 1, mutations 51. - 'large group by folder drag-pan': { restyles: 60, relayouts: 4, forced: 3, widest: 64, animations: 6, animated: 3, mutations: 53, nodes: 2466, head: 138, drawn: 12, reads: 0 }, + 'large group by folder drag-pan': { restyles: 60, relayouts: 4, forced: 3, widest: 64, animations: 6, animated: 3, mutations: 53, nodes: 2466, head: 144, drawn: 12, reads: 0 }, // 45 moving steps, then the settle: canvas classes, the grid redraw and the compact level. // Measured restyles 67, relayouts 92, forced 0, widest 319, animations 52, animated 13, mutations 59, // 2,900 nodes, 13 cards. - 'Lineage overview wheel zoom': { restyles: 69, relayouts: 94, forced: 2, widest: 321, animations: 54, animated: 15, mutations: 59, nodes: 3267, head: 137, drawn: 16, reads: 0 }, + 'Lineage overview wheel zoom': { restyles: 69, relayouts: 94, forced: 2, widest: 321, animations: 54, animated: 15, mutations: 59, nodes: 3267, head: 143, drawn: 16, reads: 0 }, // 40 transform writes, 2 card classes and the settle. Measured restyles 48, relayouts 0, forced 0–1, // widest 50, mutations 44. - 'Lineage overview drag-pan': { restyles: 50, relayouts: 2, forced: 3, widest: 52, animations: 2, animated: 2, mutations: 46, nodes: 3267, head: 137, drawn: 16, reads: 0 }, + // About 590 cards opened and laid out in the worker: none of the layout's calls on the page's thread + // (44.6 million of its 54.5 million calls before the worker). New cards are drawn hidden until placed, + // which restyles each card's contents as it shows. Measured restyles 9592, relayouts 41655, forced 2, + // widest 17735, mutations 9611, nodes 59091, drawn 594, calls 10,346,521. + 'Lineage Expand all': { restyles: 9690, relayouts: 42080, forced: 2, widest: 17920, animations: 339, animated: 86, mutations: 9710, nodes: 59700, head: 143, drawn: 600, reads: 0, calls: 10_450_000, layout: 0 }, + 'Lineage overview drag-pan': { restyles: 50, relayouts: 2, forced: 3, widest: 52, animations: 2, animated: 2, mutations: 46, nodes: 3267, head: 143, drawn: 16, reads: 0 }, // One listChecks read (filter counts come from it), 20 rows drawn: 72 row insertions and each new // cell's classes written once, the rest the navigation. Measured restyles 57 (79 at 6×), relayouts // 1,715 (2,789), forced 3, widest 986, animated 3, mutations 238–256, 3,203–3,633 nodes (as garbage // collection finds them). Calls 290,983 (327,138 at 6×, where the Overview's late work lands in the // gesture): the shell's problem banner picks its lead in one pass over the thousands of open problems, // where sorting them cost 880,000. - 'Checks second visit': { forced: 5, widest: 988, animations: 2, animated: 5, mutations: 276, nodes: 3676, head: 128, drawn: 24, reads: 1, calls: 330_500 }, + 'Checks second visit': { forced: 5, widest: 988, animations: 2, animated: 5, mutations: 276, nodes: 3676, head: 131, drawn: 24, reads: 1, calls: 330_500 }, // 40 scroll steps of 400 px: the window keeps 29 rows (the view and 8 either side); each step swaps // rows in and out (1,822 insertions and removals), gives only the new rows' cells their classes and // sets the two spacers' heights (78). Rewriting every drawn cell's classes on each step costs about // 8,700 more. Measured restyles 1,055, relayouts 33,393, forced 0, widest 357, mutations 4,672; // 3,364–4,310 nodes; calls 932,616, Svelte swapping the rows (each column's classes are worked out once, // and only added or redrawn rows are styled). - 'Checks list scroll': { restyles: 1057, relayouts: 33395, forced: 2, widest: 359, animations: 2, animated: 2, mutations: 4685, nodes: 4476, head: 128, drawn: 32, reads: 0, calls: 942_000 }, + 'Checks list scroll': { restyles: 1057, relayouts: 33395, forced: 2, widest: 359, animations: 2, animated: 2, mutations: 4685, nodes: 4476, head: 131, drawn: 32, reads: 0, calls: 942_000 }, // Each section switch replaces the 50 rows it shows (100 row insertions and removals) and reads its // first page once; Changed came with the page, so it reads nothing. Measured the same in every run: // restyles 69/73/66, relayouts 1,050/781/1,011, forced 0, widest 268/251/324, mutations 115/116/112. - 'Plan section first_run': { restyles: 71, relayouts: 1052, forced: 2, widest: 270, animations: 2, animated: 2, mutations: 117, nodes: 2382, head: 122, drawn: 50, reads: 1 }, - 'Plan section unchanged': { restyles: 75, relayouts: 783, forced: 2, widest: 253, animations: 2, animated: 2, mutations: 117, nodes: 2382, head: 122, drawn: 50, reads: 1 }, - 'Plan section changed': { restyles: 68, relayouts: 1013, forced: 2, widest: 326, animations: 2, animated: 2, mutations: 113, nodes: 2732, head: 122, drawn: 50, reads: 0 }, + 'Plan section first_run': { restyles: 71, relayouts: 1052, forced: 2, widest: 270, animations: 2, animated: 2, mutations: 117, nodes: 2382, head: 128, drawn: 50, reads: 1 }, + 'Plan section unchanged': { restyles: 75, relayouts: 783, forced: 2, widest: 253, animations: 2, animated: 2, mutations: 117, nodes: 2382, head: 128, drawn: 50, reads: 1 }, + 'Plan section changed': { restyles: 68, relayouts: 1013, forced: 2, widest: 326, animations: 2, animated: 2, mutations: 113, nodes: 2732, head: 128, drawn: 50, reads: 0 }, // Show more reads the next page once and adds its 50 rows. Measured restyles 68, relayouts 366, // forced 0, widest 251, mutations 54. - 'Plan show more': { restyles: 70, relayouts: 368, forced: 2, widest: 253, animations: 2, animated: 2, mutations: 56, nodes: 3282, head: 122, drawn: 100, reads: 1 }, + 'Plan show more': { restyles: 70, relayouts: 368, forced: 2, widest: 253, animations: 2, animated: 2, mutations: 56, nodes: 3282, head: 128, drawn: 100, reads: 1 }, // The 10,000-node project (`?huge`), measured the same way: DOM changes, nodes, rows and reads the // same in every run. The folder tree windows its rows like any long list; drawing every folder or node // instead adds thousands of rows. @@ -646,26 +677,26 @@ const BUDGETS: Record = { // Opening the folder view reads the selection vocabulary once and draws 40 rows: their cells' classes, // 40 rows' label and wrap classes, the rest the tab switch. Measured restyles 530, relayouts 2,210, // forced 4–5, widest 1,058, animations 1, mutations 274, calls 575,934. - '10K open the folder view': { restyles: 532, relayouts: 2212, forced: 7, widest: 1060, animations: 3, animated: 3, mutations: 276, nodes: 7177, head: 127, drawn: 44, reads: 1, calls: 581_700 }, + '10K open the folder view': { restyles: 532, relayouts: 2212, forced: 7, widest: 1060, animations: 3, animated: 3, mutations: 276, nodes: 7177, head: 135, drawn: 44, reads: 1, calls: 581_700 }, // Expand all swaps the window's rows for the expanded tree's (316 row insertions and removals) and // gives the new rows' cells their classes; each folder's nodes were sorted when the tree was built. // Measured restyles 141, relayouts 1,542, forced 0, widest 362, animations 5, mutations 583, calls 52,379. - '10K expand all': { restyles: 143, relayouts: 1544, forced: 2, widest: 364, animations: 7, animated: 5, mutations: 585, nodes: 5577, head: 127, drawn: 28, reads: 0, calls: 52_900 }, + '10K expand all': { restyles: 143, relayouts: 1544, forced: 2, widest: 364, animations: 7, animated: 5, mutations: 585, nodes: 5577, head: 135, drawn: 28, reads: 0, calls: 52_900 }, // Opening one folder inserts its 20 subfolder rows and gives their cells their classes; the rows already // drawn keep theirs. Measured restyles 36, relayouts 119, forced 1, widest 100, animations 3, mutations 51, // calls 27,928. - '10K open one folder': { restyles: 38, relayouts: 121, forced: 3, widest: 102, animations: 5, animated: 5, mutations: 53, nodes: 7377, head: 127, drawn: 48, reads: 0, calls: 28_200 }, + '10K open one folder': { restyles: 38, relayouts: 121, forced: 3, widest: 102, animations: 5, animated: 5, mutations: 53, nodes: 7377, head: 135, drawn: 48, reads: 0, calls: 28_200 }, // 20 wheel steps of 400 px over the expanded tree: like the Checks list, each step swaps rows in and out // of the window (2,142) and gives only the new rows' cells their classes. Measured restyles 846, // relayouts 6,354, forced 21–24, widest 167, animations 2, mutations 4,284, calls 281,331. - '10K opened tree scroll': { restyles: 848, relayouts: 6356, forced: 26, widest: 169, animations: 4, animated: 5, mutations: 4286, nodes: 5577, head: 127, drawn: 28, reads: 0, calls: 284_200 }, + '10K opened tree scroll': { restyles: 848, relayouts: 6356, forced: 26, widest: 169, animations: 4, animated: 5, mutations: 4286, nodes: 5577, head: 135, drawn: 28, reads: 0, calls: 284_200 }, // Reads the Overview, its timeline and the cost summary once each, and draws the attention card's 9 // items and the timeline; the nodes' folders, folder counts and selections were worked out once for the // listing, and the Overview's answer is kept as it came rather than made reactive node by node. // Measured restyles 91, relayouts 1,502, forced 1, widest 358, animations 5, mutations 106, calls 104,152. - '10K back to the Overview': { restyles: 93, relayouts: 1504, forced: 3, widest: 360, animations: 7, animated: 7, mutations: 108, nodes: 4476, head: 128, drawn: 12, reads: 3, calls: 105_200 }, + '10K back to the Overview': { restyles: 93, relayouts: 1504, forced: 3, widest: 360, animations: 7, animated: 7, mutations: 108, nodes: 4476, head: 136, drawn: 12, reads: 3, calls: 105_200 }, // The acknowledgement and the Overview's read that follows it; the item leaves the list at once (the // test holds that read back to check), so 6 DOM changes; the read keeps the listing's folder counts. // Measured restyles 18, relayouts 56, forced 0, widest 8, animations 6, calls 11,722. - '10K acknowledge nodes out of date': { restyles: 20, relayouts: 58, forced: 2, widest: 10, animations: 8, animated: 2, mutations: 8, nodes: 4576, head: 128, drawn: 11, reads: 2, calls: 11_850 } + '10K acknowledge nodes out of date': { restyles: 20, relayouts: 58, forced: 2, widest: 10, animations: 8, animated: 2, mutations: 8, nodes: 4576, head: 136, drawn: 11, reads: 2, calls: 11_850 } }; diff --git a/ui/e2e/graph-errors.spec.ts b/ui/e2e/graph-errors.spec.ts index 727e709823..f0a40691a8 100644 --- a/ui/e2e/graph-errors.spec.ts +++ b/ui/e2e/graph-errors.spec.ts @@ -1,16 +1,23 @@ -import { expect, test } from '@playwright/test'; +import { expect, test, type Page } from '@playwright/test'; // A graph that cannot be laid out says so in place of the graph, with its error and a way back, and -// the rest of the page stays usable. The failure is injected: every folder layout groups with Map.groupBy. +// the rest of the page stays usable. The layout runs in the layout worker, so the failure is injected +// into the worker's script, the first time it loads; Reset view starts a worker of its own. -test('a graph whose layout fails shows why in its place, and Reset view draws it again', async ({ page }) => { - await page.addInitScript(() => { - const w = window as unknown as { __groupBy: typeof Map.groupBy }; - w.__groupBy = Map.groupBy; - Map.groupBy = () => { - throw new Error('injected layout failure'); - }; +/** Serves the layout worker with `prefix` before its own code the first time it loads, then as built. */ +async function failFirstWorker(page: Page, prefix: string) { + let served = false; + await page.route('**/layout.worker*.js', async (route) => { + if (served) return route.continue(); + served = true; + const response = await route.fetch(); + await route.fulfill({ response, body: `${prefix}\n${await response.text()}` }); }); +} + +test('a graph whose layout fails shows why in its place, and Reset view draws it again', async ({ page }) => { + // Every folder layout groups with Map.groupBy. + await failFirstWorker(page, "Map.groupBy = () => { throw new Error('injected layout failure'); };"); const logged: string[] = []; page.on('console', (m) => m.type() === 'error' && logged.push(m.text())); await page.goto('/jobs/warehouse_nightly?mock'); @@ -22,9 +29,18 @@ test('a graph whose layout fails shows why in its place, and Reset view draws it expect(logged.some((t) => t.includes("Couldn't lay out this graph"))).toBe(true); await page.screenshot({ path: test.info().outputPath('graph-failed.png') }); - await page.evaluate(() => { - Map.groupBy = (window as unknown as { __groupBy: typeof Map.groupBy }).__groupBy; - }); + await failed.getByRole('button', { name: 'Reset view' }).click(); + await expect(failed).toHaveCount(0); + await expect(page.locator('.svelte-flow__node[data-id^="member:"]').first()).toBeVisible(); +}); + +test('a layout worker that fails outside a layout shows why in its place', async ({ page }) => { + // A worker whose own code throws as it answers, rather than a layout that throws inside it. + await failFirstWorker(page, "self.addEventListener('message', (e) => { e.stopImmediatePropagation(); throw new Error('injected worker failure'); });"); + await page.goto('/jobs/warehouse_nightly?mock'); + const failed = page.getByTestId('graph-failed'); + await expect(failed).toContainText("Couldn't lay out this graph. The layout worker failed: Uncaught Error: injected worker failure", { timeout: 20_000 }); + await expect(page.locator('.svelte-flow')).toHaveCount(0); await failed.getByRole('button', { name: 'Reset view' }).click(); await expect(failed).toHaveCount(0); await expect(page.locator('.svelte-flow__node[data-id^="member:"]').first()).toBeVisible(); diff --git a/ui/e2e/group-run.spec.ts b/ui/e2e/group-run.spec.ts index 2c2f8d1a5f..ab0373a6cd 100644 --- a/ui/e2e/group-run.spec.ts +++ b/ui/e2e/group-run.spec.ts @@ -668,6 +668,34 @@ test("a group run's graph redraws a job's card as the job moves", async ({ page await expect(card('stage_orders')).toHaveText(/running/i); }); +test("a live update while a job run's graph lays out keeps the cards still waiting for their places hidden", async ({ page }) => { + // Every layout answers eight seconds late, so the update lands while one runs. + await page.route('**/layout.worker*.js', async (route) => { + const response = await route.fetch(); + await route.fulfill({ response, body: `const post = self.postMessage.bind(self); self.postMessage = (m) => setTimeout(() => post(m), 8000);\n${await response.text()}` }); + }); + const { fake, run } = server(['load_orders', 'stage_orders'], 8); + const member = run.members[0]; + await fake.install(page); + await page.goto(`/runs/${member.id}`); + await page.getByRole('tab', { name: 'Graph' }).click(); + const waiting = page.locator('.svelte-flow__node.unplaced'); + await expect(page.locator('.svelte-flow__node[data-id="model:load_orders_1"]')).toBeVisible({ timeout: 20_000 }); + await expect(page.locator('.graph-canvas.laying')).toHaveCount(0, { timeout: 20_000 }); + // Closing a folder draws its card, hidden until the layout places it. + await page.getByTitle(/^Close .*part_1;/).click(); + await expect(waiting).not.toHaveCount(0); + const hidden = await waiting.count(); + // The run's first node starts, in the folder still open. + fake.advance(member); + await expect(page.locator('.svelte-flow__node[data-id="model:load_orders_0"]')).toContainText(/running/i); + await expect(page.locator('.graph-canvas.laying')).toHaveCount(1); + await expect(waiting).toHaveCount(hidden); + await expect(waiting.first()).toBeHidden(); + // Then the layout places them. + await expect(waiting).toHaveCount(0, { timeout: 15_000 }); +}); + test("a live update to a group run's graph costs what the jobs it moved hold, not what the whole group holds", async ({ browser, baseURL }) => { // As above, with the Graph tab open: the same five jobs move in a run of 20 jobs and in one of 40. const cost = async (jobs: number) => { @@ -818,6 +846,8 @@ test("an opened job's folder cards count its waiting nodes beside those done, an await expect(boxes).toHaveCount(2); // A person clicks the header by its chevron: there, not under the selected job's box, the inner box closes. const heads = boxes.locator('.folder-head'); + // Once the inner box is laid out and shown. + await expect(heads.last()).toBeVisible(); // The outer box resizes as an inner one closes; a locator click waits for the header to settle and land on it. const press = async (head: Locator) => { const at = (await head.boundingBox())!; diff --git a/ui/e2e/real/lineage-fit-folders.spec.ts b/ui/e2e/real/lineage-fit-folders.spec.ts index 3324f6ea49..0c5192db55 100644 --- a/ui/e2e/real/lineage-fit-folders.spec.ts +++ b/ui/e2e/real/lineage-fit-folders.spec.ts @@ -10,12 +10,17 @@ test.describe.configure({ mode: 'serial' }); test.use({ viewport: { width: 1440, height: 900 } }); const MAX_DRAWN = 600; +/** The cards Expand all draws on the tangled project: what fits in the cap. */ +const EXPANDED = 593; const sql = (from: string) => `MODEL (\n description "Orders by region",\n columns (\n order_id (type BIGINT),\n ),\n);\n\nSELECT order_id FROM __ref("${from}")\n`; const cards = (page: Page) => page.locator('.svelte-flow__node'); const tooMany = (page: Page) => page.getByRole('status').filter({ hasText: 'Too many nodes to draw at once' }); /** Waits for the graph to settle, then checks it draws something, within the cap, with no "too many" card. */ async function drawnWithinCap(page: Page): Promise { + // Laid out: no card waiting for its place or kept in sight from the drawing before. + await expect(page.locator('.svelte-flow__node:is(.unplaced, .leaving)')).toHaveCount(0, { timeout: 60_000 }); + await expect(page.locator('.graph-canvas.laying')).toHaveCount(0, { timeout: 60_000 }); await expect(page.locator('.graph-canvas.moving')).toHaveCount(0, { timeout: 60_000 }); await expect(cards(page).first()).toBeVisible({ timeout: 60_000 }); // Something to look at: a card inside the canvas, not only somewhere off the view. @@ -69,6 +74,16 @@ test.describe('a deep project whose folders all wait on each other', () => { test('every way of opening folders draws within the cap, and a loop never opens a folder', async ({ page }) => { test.setTimeout(300_000); + // Every layout answers two seconds late, as on a slow machine, so a click lands while one runs. + await page.route('**/layout.worker*.js', async (route) => { + const response = await route.fetch(); + await route.fulfill({ response, body: `const post = self.postMessage.bind(self); self.postMessage = (m) => setTimeout(() => post(m), 2000);\n${await response.text()}` }); + }); + // The page's own scripts, not the layout worker's. + const scripts: Promise[] = []; + page.on('response', (r) => { + if (r.request().resourceType() === 'script' && !r.url().includes('layout.worker')) scripts.push(r.text()); + }); await page.goto(`${server.uiUrl}/lineage`); // The first draw: tangled top-level folders stay closed, waits both ways drawn as one edge each. const first = await drawnWithinCap(page); @@ -100,19 +115,42 @@ test.describe('a deep project whose folders all wait on each other', () => { await expect(page.locator('.svelte-flow__node[data-id="group:north"]')).toHaveCount(1); await drawnWithinCap(page); - // Expand all opens what fits and says what it left closed. - // Long tasks while it lays out, for the record: the layout runs on the page's thread. - await page.evaluate(() => { - (window as unknown as { longest: number }).longest = 0; - new PerformanceObserver((list) => { - for (const e of list.getEntries()) (window as unknown as { longest: number }).longest = Math.max((window as unknown as { longest: number }).longest, e.duration); - }).observe({ type: 'longtask' }); - }); + // Expand all opens what fits and says what it left closed. The layout runs in the layout worker: no + // script on the page holds layout code, and the page answers a second click while the worker lays out. + await page.getByRole('button', { name: 'Expand all' }).click(); + await expect(page.getByRole('status').filter({ hasText: 'Laying out…' })).toBeVisible(); + // Meanwhile the drawing before stays in sight, and nothing new shows until it is placed. + for (const top of TOPS) await expect(page.locator(`.svelte-flow__node.leaving[data-id="group:${top}"]`)).toBeVisible(); + await expect(page.locator('.svelte-flow__node.unplaced').first()).toBeHidden(); + await page.screenshot({ path: test.info().outputPath('laying-out.png') }); + // Collapse all while Expand all lays out: the page draws the collapse, and the expand never lands. + await page.getByRole('button', { name: 'Collapse all' }).click(); + expect(await drawnWithinCap(page)).toBe(first); + // Past when the expand's layout would have answered. + await page.waitForTimeout(2_500); + expect(await drawnWithinCap(page)).toBe(first); + for (const top of TOPS) await expect(page.locator(`.svelte-flow__node[data-id="group:${top}"]:not(.unplaced)`)).toHaveCount(1); + await expect(page.locator('.expand-note')).toHaveCount(0); + await page.getByRole('button', { name: 'Expand all' }).click(); await expect(page.locator('.expand-note')).toContainText('left closed · limit 600 cards'); - await drawnWithinCap(page); + expect(await drawnWithinCap(page)).toBe(EXPANDED); await page.screenshot({ path: test.info().outputPath('expand-all.png') }); - console.log('expand-all longest task ms', await page.evaluate(() => (window as unknown as { longest: number }).longest), 'cards', await cards(page).count()); + // Dagre's own error text marks its code: it ships in the worker's script, which the page never loads. + expect(scripts.length).toBeGreaterThan(0); + expect((await Promise.all(scripts)).filter((s) => s.includes('Not possible to find intersection inside of the rectangle'))).toEqual([]); + + // Expand all while opening a folder still lays out places the view as Expand all does, rather than keeping + // that folder where it was clicked. + const view = () => page.locator('.svelte-flow__viewport').evaluate((v) => (v as HTMLElement).style.transform); + const expandedView = await view(); + await page.getByRole('button', { name: 'Collapse all' }).click(); + expect(await drawnWithinCap(page)).toBe(first); + await page.locator('.svelte-flow__node[data-id="group:north"]').click(); + await expect(page.locator('.graph-canvas.laying')).toHaveCount(1); + await page.getByRole('button', { name: 'Expand all' }).click(); + expect(await drawnWithinCap(page)).toBe(EXPANDED); + await expect.poll(view).toBe(expandedView); // A link to one node, deep inside the last folder the chain reaches, draws that node. const deepest = name(leaves.at(-1)!, PER_LEAF - 1); @@ -183,5 +221,21 @@ test.describe('a small project', () => { await expect(page.locator('.svelte-flow__node[data-id="more:folders"]')).toHaveCount(0); await expect(page.locator('.svelte-flow__node[data-id^="model:"]').first()).toBeVisible(); await expect(page.locator('.expand-note')).toHaveCount(0); + + // Backspace and Delete on a selected card leave it and its edges in place: no page offers removing a card. + const card = page.locator('.svelte-flow__node[data-id^="model:"]').first(); + const id = await card.getAttribute('data-id'); + const edges = page.locator('.svelte-flow__edge'); + const [cardCount, edgeCount] = [await cards(page).count(), await edges.count()]; + expect(edgeCount).toBeGreaterThan(0); + await card.click(); + await expect(card).toHaveClass(/selected/); + for (const key of ['Backspace', 'Delete']) { + await page.keyboard.press(key); + await drawnWithinCap(page); + await expect(page.locator(`.svelte-flow__node[data-id="${id}"]`)).toHaveCount(1); + await expect(cards(page)).toHaveCount(cardCount); + await expect(edges).toHaveCount(edgeCount); + } }); }); diff --git a/ui/src/lib/api/index.ts b/ui/src/lib/api/index.ts index 640ea3bb3c..21b8e9c4d0 100644 --- a/ui/src/lib/api/index.ts +++ b/ui/src/lib/api/index.ts @@ -5,6 +5,7 @@ import { largeProject } from "./mock/large-project"; import { deepGroup } from "./mock/deep-group"; import { costProject } from "./mock/cost-project"; import { hugeProject } from "./mock/huge-project"; +import { tangledProject } from "./mock/tangled-project"; import { awkward } from "./mock/awkward"; import { missingSecrets } from "./mock/missing-secrets"; import { calm } from "./mock/calm"; @@ -102,9 +103,11 @@ export function createClient( const costed = search.has("costs") ? costProject(mock) : mock; const sized = search.has("huge") ? hugeProject(costed, Number(search.get("huge")) || undefined) - : search.has("large") || summary - ? largeProject(costed, { summary }) - : costed; + : search.has("tangled") + ? tangledProject(costed) + : search.has("large") || summary + ? largeProject(costed, { summary }) + : costed; const secrets = search.has("secrets") ? missingSecrets(sized, { sink: search.get("secrets") === "sink" }) : sized; diff --git a/ui/src/lib/api/mock/tangled-project.ts b/ui/src/lib/api/mock/tangled-project.ts new file mode 100644 index 0000000000..9a168c61f8 --- /dev/null +++ b/ui/src/lib/api/mock/tangled-project.ts @@ -0,0 +1,42 @@ +// A project whose folders all wait on each other, for the work budget of Lineage's Expand all: six top-level +// folders, each with four subfolders of four folders of 36 models, 3,456 in all. One chain visits every leaf +// folder in turn at each step, so every folder waits on every other at every depth, both ways, and its +// layout takes the compound path. The same shape as the real-server stress project. Turned on with +// `?mock&tangled`. Pure apart from wrapping the client it is given. + +import type { ApiClient } from '../client'; +import type { CatalogNode } from '../types'; + +const TOPS = ['north', 'south', 'east', 'west', 'central', 'coastal']; +const SUBS = ['a', 'b', 'c', 'd']; +const LEAVES = ['p', 'q', 'r', 's']; +const PER_LEAF = 36; + +/** The tangled project's nodes, copies of `template`; deterministic. */ +export function tangledProjectNodes(template: CatalogNode): CatalogNode[] { + const leaves = SUBS.flatMap((s) => LEAVES.flatMap((l) => TOPS.map((t) => [t, s, l] as const))); + const nodes: CatalogNode[] = []; + let previous: string | null = null; + for (let i = 0; i < PER_LEAF; i++) + for (const [t, s, l] of leaves) { + const key = `${t}_${s}${l}_${String(i).padStart(2, '0')}`; + nodes.push({ ...template, key, group: `${t}/${s}/${l}`, path: `sql/models/${t}/${s}/${l}/${key}.sql`, upstream: previous ? [previous] : [], description: 'Orders by region' }); + previous = key; + } + return nodes; +} + +/** The client with its catalog replaced by the tangled project. */ +export function tangledProject(client: ApiClient): ApiClient { + return new Proxy(client, { + get(target, prop, receiver) { + const value = Reflect.get(target, prop, receiver); + if (prop !== 'listCatalogNodes') return typeof value === 'function' ? value.bind(target) : value; + return async (...args: Parameters) => { + const real = await target.listCatalogNodes(...args); + const template = real.find((n) => n.kind === 'table') ?? real[0]; + return template ? tangledProjectNodes(template) : real; + }; + } + }); +} diff --git a/ui/src/lib/build-area/kind-tabs.test.ts b/ui/src/lib/build-area/kind-tabs.test.ts index 8a637d61a5..0b6e76b7a7 100644 --- a/ui/src/lib/build-area/kind-tabs.test.ts +++ b/ui/src/lib/build-area/kind-tabs.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { NODE_KINDS, kindTabOf, nodeIcon, nodeIconKey, parseKindTab } from './labels'; +import { NODE_KINDS, kindTabOf, nodeIconKey, parseKindTab } from './labels'; +import { nodeIcon } from './node-icons'; describe('catalog kind tabs', () => { it('puts Python nodes and functions in their own tabs', () => { diff --git a/ui/src/lib/build-area/labels.ts b/ui/src/lib/build-area/labels.ts index 21c134a14c..4057425853 100644 --- a/ui/src/lib/build-area/labels.ts +++ b/ui/src/lib/build-area/labels.ts @@ -1,17 +1,5 @@ // Labels, tones and small mappings for the BUILD area's vocabulary. Pure; no side effects. -import Database from '@lucide/svelte/icons/database'; -import Download from '@lucide/svelte/icons/download'; -import Eye from '@lucide/svelte/icons/eye'; -import GitMerge from '@lucide/svelte/icons/git-merge'; -import Layers from '@lucide/svelte/icons/layers'; -import ChartGantt from '@lucide/svelte/icons/chart-gantt'; -import Repeat from '@lucide/svelte/icons/repeat'; -import Package from '@lucide/svelte/icons/package'; -import SquareFunction from '@lucide/svelte/icons/square-function'; -import TableProperties from '@lucide/svelte/icons/table-properties'; -import Sprout from '@lucide/svelte/icons/sprout'; -import Table2 from '@lucide/svelte/icons/table-2'; import type { BuiltDefinition, CatalogNode, @@ -91,21 +79,6 @@ export function nodeIconKey(node: Pick) return node.kind; } -export const nodeIcon: Record = { - source: Database, - loader: Download, - seed: Sprout, - view: Eye, - table: Table2, - incremental: Layers, - merge: GitMerge, - delete_insert: Repeat, - microbatch: ChartGantt, - asset: Package, - udf: SquareFunction, - table_fn: TableProperties -}; - /** `incremental · merge` style kind line, falling back to the node kind. */ export function kindLine(node: Pick): string { return node.materialization ?? nodeKindLabel[node.kind].toLowerCase(); diff --git a/ui/src/lib/build-area/node-icons.ts b/ui/src/lib/build-area/node-icons.ts new file mode 100644 index 0000000000..436b651f51 --- /dev/null +++ b/ui/src/lib/build-area/node-icons.ts @@ -0,0 +1,30 @@ +// Each node kind's icon, a Svelte component: kept apart from the labels, which the layout worker also reads. + +import Database from '@lucide/svelte/icons/database'; +import Download from '@lucide/svelte/icons/download'; +import Eye from '@lucide/svelte/icons/eye'; +import GitMerge from '@lucide/svelte/icons/git-merge'; +import Layers from '@lucide/svelte/icons/layers'; +import ChartGantt from '@lucide/svelte/icons/chart-gantt'; +import Repeat from '@lucide/svelte/icons/repeat'; +import Package from '@lucide/svelte/icons/package'; +import SquareFunction from '@lucide/svelte/icons/square-function'; +import TableProperties from '@lucide/svelte/icons/table-properties'; +import Sprout from '@lucide/svelte/icons/sprout'; +import Table2 from '@lucide/svelte/icons/table-2'; + +/** Icons by `nodeIconKey`. */ +export const nodeIcon: Record = { + source: Database, + loader: Download, + seed: Sprout, + view: Eye, + table: Table2, + incremental: Layers, + merge: GitMerge, + delete_insert: Repeat, + microbatch: ChartGantt, + asset: Package, + udf: SquareFunction, + table_fn: TableProperties +}; diff --git a/ui/src/lib/components/build-area/folder-tree.svelte b/ui/src/lib/components/build-area/folder-tree.svelte index 6ba9805311..88cf4ae4cf 100644 --- a/ui/src/lib/components/build-area/folder-tree.svelte +++ b/ui/src/lib/components/build-area/folder-tree.svelte @@ -7,7 +7,8 @@ import { folderPaths, folderTree, visibleTreeRows, type FolderNode, type FolderSort, type TreeRow } from '$lib/build-area/folder-tree'; import { needsAttention } from '$lib/build-area/overview-panels'; import { statusLabel } from '$lib/build-area/node-status'; - import { nodeIcon, nodeIconKey, shortName } from '$lib/build-area/labels'; + import { nodeIconKey, shortName } from '$lib/build-area/labels'; + import { nodeIcon } from '$lib/build-area/node-icons'; import DataTable from '$lib/components/list/data-table.svelte'; import type { TableColumn } from '$lib/components/list/table-columns'; import Button from '$lib/components/ui/button/button.svelte'; diff --git a/ui/src/lib/components/graph/graph-canvas.svelte b/ui/src/lib/components/graph/graph-canvas.svelte index fc8e7677f9..8df9489662 100644 --- a/ui/src/lib/components/graph/graph-canvas.svelte +++ b/ui/src/lib/components/graph/graph-canvas.svelte @@ -1,7 +1,7 @@ -
0} data-compact={level || undefined} data-stage={stage} style:--sb-inv={1 / settledZoom} style:--sb-title-unzoom={titleUnzoom} style:--sb-unzoom={controlScale} bind:this={element} onpointerdowncapture={onpointerdown} onpointermovecapture={onpointermove} onclickcapture={onclick}> - +
0} class:laying={graph?.laying} data-compact={level || undefined} data-stage={stage} style:--sb-inv={1 / settledZoom} style:--sb-title-unzoom={titleUnzoom} style:--sb-unzoom={controlScale} bind:this={element} onpointerdowncapture={onpointerdown} onpointermovecapture={onpointermove} onclickcapture={onclick}> + @@ -166,6 +167,7 @@ {#if controls === 'fit'} fit?.()} {showLock} label={fitLabel} />{:else if controls === 'full'}{/if} {@render children?.()} + {#if graph?.laying}
Laying out…
{/if}