diff --git a/client/e2e/dataflow.spec.ts b/client/e2e/dataflow.spec.ts index ca181920..454e60cb 100644 --- a/client/e2e/dataflow.spec.ts +++ b/client/e2e/dataflow.spec.ts @@ -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 = 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((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"; diff --git a/client/src/App.tsx b/client/src/App.tsx index ab00b77f..d8f58d85 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -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; @@ -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. */ @@ -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(); @@ -414,7 +434,7 @@ function AppContent(props: { active: boolean }) { Srcly @@ -472,7 +492,7 @@ function AppContent(props: { active: boolean }) { - + 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 (
@@ -678,10 +682,7 @@ export default function FlowView(props: {
- - {(message) => } - - + } /> - + {(what) => } - + } /> - + {(u) => ( )} - - {(e) => } + + {(message) => }