Skip to content
Merged
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
53 changes: 53 additions & 0 deletions client/e2e/dataflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,59 @@ const box = (page: Page, label: string) => page.locator("[data-box]").filter({ h
/** A drawn box by the start of its full label: the drawn text truncates to the font's width, which differs by platform. */
const boxLabelled = (page: Page, label: string) => page.locator(`[data-box][data-label^="${label}"]`).first();

test.describe("Flow across folders", () => {
const otherRepo = path.resolve(here, "../../engine/examples/bad-ish-solid");
const originalAnchor = "src/components/ViewerCard.tsx@ViewerCard:3";

for (const mode of ["route", "anchor"] as const) {
test(`folder switch drops the old ${mode}; Back restores it`, async ({ page }) => {
const compare: Record<string, string> = mode === "route" ? { flow: "/records", lens: "components" } : { anchor: originalAnchor, dir: "backward" };
const graphEndpoint = mode === "route" ? "route-graph" : "anchor-graph";
const requests: { root: string | null; endpoint: string }[] = [];
page.on("request", (request) => {
const target = new URL(request.url());
const endpoint = target.pathname.split("/").at(-1)!;
if (!target.pathname.startsWith("/api/dataflow/") || !["routes", "route-surface", "route-graph", "anchor-graph"].includes(endpoint)) return;
const root = request.method() === "POST" ? request.postDataJSON()?.path ?? null : target.searchParams.get("path");
requests.push({ root, endpoint });
});
// Hold the old root's first graph reply until the new root has settled.
let release!: () => void;
const held = new Promise<void>((resolve) => { release = resolve; });
const graphPattern = `**/api/dataflow/${graphEndpoint}*`;
await page.route(graphPattern, async (route) => {
await held;
await route.fulfill({ status: 503, json: { detail: "late old-root test response" } });
}, { times: 1 });
const oldGraph = page.waitForRequest((r) => new URL(r.url()).pathname.endsWith(`/dataflow/${graphEndpoint}`));
await page.goto(url({ view: "graph", ...compare }));
await oldGraph;
const folder = page.getByRole("button", { name: "Switch folder, rescan, or open a recent one" });
await folder.click();
await page.getByRole("textbox", { name: "Folder to analyze" }).fill(otherRepo);
await page.getByRole("button", { name: "Analyze", exact: true }).click();
await expect(page).toHaveURL((u) => u.searchParams.get("repo") === otherRepo && u.searchParams.get("flow") === "" && !u.searchParams.has("anchor") && !u.searchParams.has("lens"));
const empty = page.getByRole("heading", { name: "No routes here" });
await expect(empty).toBeVisible();
const oldReply = page.waitForResponse((r) => new URL(r.url()).pathname.endsWith(`/dataflow/${graphEndpoint}`) && r.status() === 503);
release();
await (await oldReply).finished();
await expect(empty).toHaveCount(1);
await expect(page.getByText("late old-root test response", { exact: false })).toHaveCount(0);
await expect(page.locator("[data-box]")).toHaveCount(0);
await expect(page.getByLabel("Data flow inspector")).toHaveCount(0);
expect(requests.filter((r) => r.root === otherRepo).map((r) => r.endpoint)).toEqual(["routes"]);

await page.goBack();
await expect(page).toHaveURL((u) => u.searchParams.get("repo") === REPO && Object.entries(compare).every(([k, v]) => u.searchParams.get(k) === v));
await expect(status(page)).toContainText(mode === "route" ? "4 origins" : "upstream", { timeout: 90_000 });
await page.goForward();
await expect(empty).toBeVisible();
await expect(page.locator("[data-box]")).toHaveCount(0);
});
}
});

test.describe("Data flow on solid-route", () => {
test("a failed new anchor request does not redisplay the previous graph", async ({ page }) => {
const originalAnchor = "src/components/ViewerCard.tsx@ViewerCard:3";
Expand Down
32 changes: 26 additions & 6 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ function AppContent(props: { active: boolean }) {
let resolveTreemapPaint: (() => void) | null = null;
let pendingNotice: string | null = null;

// A URL change can precede the scan effect. Never apply the new location to the old tree.
const scanOwnsLocation = () => !location().repo || location().repo === scannedPath();

// The scan root's absolute path; locations are relative to it.
const rootPath = () => visualizationData()?.path ?? "";
// Where the treemap is zoomed, read from the location.
const resolved = createMemo(() => {
const data = visualizationData();
const data = scanOwnsLocation() ? visualizationData() : null;
return data ? resolveTreeAt(data, rootPath(), location().at) : null;
});
const currentRoot = () => resolved()?.node ?? null;
Expand Down Expand Up @@ -294,7 +297,10 @@ function AppContent(props: { active: boolean }) {
createEffect(() => {
const repo = location().repo;
if (!props.active || !repo || repo === untrack(scannedPath)) return;
untrack(() => analyze(repo));
untrack(() => {
setIsCodeModalOpen(false);
analyze(repo);
});
});

/** A codebase chosen in the picker or on the landing page. */
Expand All @@ -304,7 +310,21 @@ function AppContent(props: { active: boolean }) {
if (target === location().repo) return analyze(target);
// A different codebase starts at its root. A URL that had a place but no
// repo yet (an old link) keeps that place.
go(location().repo ? { repo: target, at: "" } : { repo: target });
const here = location();
go(here.repo ? {
repo: target,
at: "",
open: undefined,
flow: isDataFlow(here) ? "" : undefined,
anchor: undefined,
field: undefined,
dest: undefined,
lens: undefined,
dir: undefined,
model: undefined,
depth: undefined,
links: undefined,
} : { repo: target });
};

const handleCancelScan = () => scanStore.cancel();
Expand Down Expand Up @@ -414,7 +434,7 @@ function AppContent(props: { active: boolean }) {
Srcly
</h1>
<Show
when={visualizationData()}
when={scanOwnsLocation() && visualizationData()}
fallback={
<div class="min-w-0 flex-1">
<FilePickerWithExternal onSelect={handleFileSelect} externalPath={analysisPath()} />
Expand Down Expand Up @@ -472,7 +492,7 @@ function AppContent(props: { active: boolean }) {
</DialogShell>

<Show
when={visualizationData()}
when={scanOwnsLocation() && visualizationData()}
fallback={
<div class="h-full w-full">
<Show
Expand Down Expand Up @@ -617,7 +637,7 @@ function AppContent(props: { active: boolean }) {
<Show when={showToast()}>
<Toast message={toastMessage()} type={toastType()} duration={4000} />
</Show>
<Show when={isCodeModalOpen()}>
<Show when={scanOwnsLocation() && isCodeModalOpen()}>
<CodeModal
isOpen={true}
filePath={selectedFilePath()}
Expand Down
21 changes: 11 additions & 10 deletions client/src/viz/deps/flow/FlowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ export default function FlowView(props: {
return null;
};

const requestError = () => startError() ?? graphFetch.error()?.message ?? anchorFetch.error()?.message ??
exportsFetch.error()?.message ?? expansionFetch.error()?.message ?? routesFetch.error()?.message;
const noRoutes = () => !requestError() && !routeKey() && !anchorKey() && routes()?.outcome === "ok" && routeList().length === 0;

return (
<div class="flex h-full flex-col bg-[var(--plc-surface)]">
<ViewTools>
Expand Down Expand Up @@ -678,33 +682,30 @@ export default function FlowView(props: {

<div class="flex min-h-0 flex-1">
<div ref={host} class="relative min-h-0 flex-1">
<Show when={startError()}>
{(message) => <ErrorState message={message()} class="absolute inset-0" />}
</Show>
<Show when={availability() === "na"}>
<Show when={!requestError() && availability() === "na"}>
<EmptyState
class="absolute inset-0"
title="Data flow N/A"
description={`${reasonText(status()?.reason, status()?.message)}. ${status()?.message ?? ""}`.trim()}
actions={<PythonApps root={root()} apps={status()?.pythonApps} class="justify-center" />}
/>
</Show>
<Show when={!startError() && availability() !== "na" && waitingOn()}>
<Show when={!requestError() && availability() !== "na" && waitingOn()}>
{(what) => <FlowProgress title={what()} progress={status()?.progress} class="absolute inset-0" />}
</Show>
<Show when={routes()?.outcome === "ok" && routeList().length === 0 && !anchorKey()}>
<Show when={noRoutes()}>
<EmptyState
class="absolute inset-0"
title="No routes here"
description={
python()
? "Data flow found no FastAPI or Flask route here. Trace any value instead: open a file, right-click a line, and pick Trace where it goes."
: "Data flow starts from a route: a file under a routes/ folder that default-exports a component. Open a folder that has one."
: "No route components were found here. Trace a value instead: open a file, right-click a line, and pick Trace where it goes."
}
actions={<PythonApps root={root()} apps={status()?.pythonApps} class="justify-center" />}
/>
</Show>
<Show when={unanswered()}>
<Show when={!requestError() && !noRoutes() && unanswered()}>
{(u) => (
<EmptyState
class="absolute inset-0"
Expand All @@ -719,8 +720,8 @@ export default function FlowView(props: {
/>
)}
</Show>
<Show when={graphFetch.error() ?? anchorFetch.error() ?? exportsFetch.error() ?? expansionFetch.error() ?? routesFetch.error()}>
{(e) => <ErrorState message={e().message} class="absolute inset-0" />}
<Show when={requestError()}>
{(message) => <ErrorState message={message()} class="absolute inset-0" />}
</Show>
<Show when={(stale() || refreshing() || refreshError()) && availability() === "ready"}>
<div
Expand Down
Loading