Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 73 additions & 42 deletions ui/e2e/budgets.spec.ts

Large diffs are not rendered by default.

40 changes: 28 additions & 12 deletions ui/e2e/graph-errors.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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();
Expand Down
30 changes: 30 additions & 0 deletions ui/e2e/group-run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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())!;
Expand Down
74 changes: 64 additions & 10 deletions ui/e2e/real/lineage-fit-folders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
// 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.
Expand Down Expand Up @@ -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<string>[] = [];
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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
});
});
9 changes: 6 additions & 3 deletions ui/src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions ui/src/lib/api/mock/tangled-project.ts
Original file line number Diff line number Diff line change
@@ -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<ApiClient['listCatalogNodes']>) => {
const real = await target.listCatalogNodes(...args);
const template = real.find((n) => n.kind === 'table') ?? real[0];
return template ? tangledProjectNodes(template) : real;
};
}
});
}
3 changes: 2 additions & 1 deletion ui/src/lib/build-area/kind-tabs.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
27 changes: 0 additions & 27 deletions ui/src/lib/build-area/labels.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -91,21 +79,6 @@ export function nodeIconKey(node: Pick<CatalogNode, 'kind' | 'materialization'>)
return node.kind;
}

export const nodeIcon: Record<string, typeof Table2> = {
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<CatalogNode, 'kind' | 'materialization'>): string {
return node.materialization ?? nodeKindLabel[node.kind].toLowerCase();
Expand Down
30 changes: 30 additions & 0 deletions ui/src/lib/build-area/node-icons.ts
Original file line number Diff line number Diff line change
@@ -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<string, typeof Table2> = {
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
};
3 changes: 2 additions & 1 deletion ui/src/lib/components/build-area/folder-tree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading
Loading