diff --git a/client/e2e/dataflow.spec.ts b/client/e2e/dataflow.spec.ts index b96d54c8..4bdd63b2 100644 --- a/client/e2e/dataflow.spec.ts +++ b/client/e2e/dataflow.spec.ts @@ -135,6 +135,34 @@ test.describe("Data flow on solid-route", () => { await shot(page, "anchor-from-code"); }); + test("whole-file code waits for a function selection before requesting effects", async ({ page }) => { + const requests: number[] = []; + page.on("request", (request) => { + if (request.url().endsWith("/api/dataflow/function-effects")) requests.push(request.postDataJSON().line); + }); + await page.goto(url({ view: "treemap", at: "src/components" })); + await page.getByRole("treeitem", { name: /ViewerCard\.tsx/ }).click(); + const dialog = page.getByRole("dialog"); + const effects = dialog.getByLabel("Function effects"); + await expect(effects).toHaveAttribute("data-effects-state", "unselected"); + await expect(effects).toContainText("Choose a function from the outline"); + expect(requests).toEqual([]); + + await dialog.getByRole("button", { name: "Outline", exact: true }).click(); + await page.getByPlaceholder("Go to symbol…").fill("ViewerCard"); + await page.getByRole("listbox").locator('[data-row="0"]').click(); + await expect(effects).toContainText(/Closed|known effect/); + await expect(effects).toContainText("ViewerCard"); + expect(requests).toEqual([3]); + + await dialog.getByRole("button", { name: "Outline", exact: true }).click(); + // Reopening clears the search, so row 0 is the whole-file entry again. + await expect(page.getByPlaceholder("Go to symbol…")).toHaveValue(""); + await page.getByRole("listbox").locator('[data-row="0"]').click(); + await expect(effects).toHaveAttribute("data-effects-state", "unselected"); + expect(requests).toEqual([3]); + }); + test("a selected box in anchor mode shows what its function touches", async ({ page }) => { await page.goto(url({ view: "graph", anchor: "src/components/ViewerCard.tsx@ViewerCard:3" })); await expect(status(page)).toContainText("upstream", { timeout: 90_000 }); diff --git a/client/src/components/CodeModal/CodeModal.tsx b/client/src/components/CodeModal/CodeModal.tsx index 87ff3d8b..ad4e041b 100644 --- a/client/src/components/CodeModal/CodeModal.tsx +++ b/client/src/components/CodeModal/CodeModal.tsx @@ -225,11 +225,17 @@ export default function CodeModal(props: CodeModalProps) { /** The ledger's rows are marked through the metric overlay while this is on. */ const [ledgerMarked, setLedgerMarked] = createSignal(false); // What the selected scope touches (M6): keyed on the scope's start line; nothing at a git ref. - // With no scope picked, the function enclosing the line the viewer opened at (the engine finds it). - const effectsLine = () => coerceLine(selectedScopeNode()?.start_line) ?? targetStartLine() ?? cursorLine(); + // With no scope picked, use the function enclosing an explicit source line. + // A whole-file selection has no position (file nodes use a start line of 0). + const effectsLine = () => { + const scope = selectedScopeNode(); + return [scope?.type === "file" ? null : coerceLine(scope?.start_line), targetStartLine(), cursorLine()] + .find((line): line is number => line !== null && Number.isInteger(line) && line > 0); + }; + const effectsFile = () => !props.gitRef && props.rootPath && props.filePath && /\.(tsx?|mts|cts|jsx?)$/.test(props.filePath); const effects = createEffectsQuery(() => { const line = effectsLine(); - if (props.gitRef || !props.rootPath || !props.filePath || line === null || !/\.(tsx?|mts|cts|jsx?)$/.test(props.filePath)) return null; + if (!effectsFile() || line === undefined || !props.rootPath || !props.filePath) return null; return { root: props.rootPath, file: props.filePath, line }; }); const ledgerRows = createMemo(() => { @@ -454,7 +460,14 @@ export default function CodeModal(props: CodeModalProps) { gitRef={props.gitRef} onJumpToFinding={jumpToFinding} effects={ - + +
+

Effects

+

Choose a function from the outline to see what it touches.

+
+
+ }> {(state) => (
{ if (absPath === props.filePath) jumpToLedgerRow(line); }} /> diff --git a/docs/CODE_MAP.md b/docs/CODE_MAP.md index dbdb3956..29e1f885 100644 --- a/docs/CODE_MAP.md +++ b/docs/CODE_MAP.md @@ -113,7 +113,7 @@ Browser | `POST /api/dataflow/refresh` | `routers/dataflow.py:refresh` | Rebuild tier 1 from the sources as they are now; replies with the new generation's routes. A query naming an older generation gets `outcome: stale` | | `DELETE /api/dataflow?path=` | `routers/dataflow.py:close` | Close the engine for a root | | `GET /api/dataflow/route-path?path=&route=&edge=&source=` | `routers/dataflow.py:get_route_path` | One lit edge explained in order (`path`: the edge, ledger rows from the origin to where it ends, the proof, a frontier when the lineage stops); field edges need `source`; 404 for an edge the totality does not carry | -| `POST /api/dataflow/function-effects` | `routers/dataflow.py:function_effects` | What the function enclosing `{file, line[, column]}` touches (`effects`: facts with witnesses, frontiers, promise handling, assumptions); `outcome: unsupported`, `reason: no-callable` outside any function | +| `POST /api/dataflow/function-effects` | `routers/dataflow.py:function_effects` | What the function enclosing `{file, line[, column]}` touches (`effects`: facts with witnesses, frontiers, promise handling, assumptions); 422 if the 1-based line is less than 1; `outcome: unsupported`, `reason: no-callable` outside any function | | `POST /api/dataflow/anchor-graph` | `routers/dataflow.py:anchor_graph` | A value's neighbourhood from any expression (`span` + `text`, or `name` + `line`), `direction` backward / forward / both; 404 for a name not on its line | | `GET /api/files/content` | `routers/files.py:get_file_content` | Raw file text; `ref=` reads it from a git commit (`git show`) | | `GET /api/files/markers` | `routers/files.py:get_file_markers` → `services/markers.py` | Lines behind each metric (`{metric: [{line, end_line, note}]}`) for the code viewer overlay; `ref=` as above | diff --git a/server/app/routers/dataflow.py b/server/app/routers/dataflow.py index 1581b8d6..d3b9d987 100644 --- a/server/app/routers/dataflow.py +++ b/server/app/routers/dataflow.py @@ -13,7 +13,7 @@ from typing import Literal from fastapi import APIRouter, HTTPException, Response -from pydantic import BaseModel +from pydantic import BaseModel, Field from app.services.dataflow import engine as dataflow_engine from app.services.dataflow.engine import EngineCrashed, EngineError @@ -220,7 +220,7 @@ class FunctionEffectsRequest(BaseModel): path: str file: str - line: int + line: int = Field(ge=1) column: int | None = None expectedGeneration: int | None = None diff --git a/server/tests/test_dataflow_router.py b/server/tests/test_dataflow_router.py index 6ffd2cc6..53a628c6 100644 --- a/server/tests/test_dataflow_router.py +++ b/server/tests/test_dataflow_router.py @@ -37,6 +37,18 @@ def client(): return TestClient(app) +@pytest.mark.parametrize("line", [0, -1]) +def test_function_effects_rejects_nonpositive_lines_before_starting_engine(client, use_fake, tmp_path, line): + registry = use_fake() + (tmp_path / "file.ts").write_text("export function f() {}\n") + response = client.post( + "/api/dataflow/function-effects", json={"path": str(tmp_path), "file": "file.ts", "line": line} + ) + assert response.status_code == 422 + assert response.json()["detail"][0]["loc"] == ["body", "line"] + assert registry.live_count() == 0 + + def test_status_never_spawns(client, use_fake, tmp_path): registry = use_fake() body = client.get("/api/dataflow/status", params={"path": str(tmp_path)}).json()