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
28 changes: 28 additions & 0 deletions client/e2e/dataflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
21 changes: 17 additions & 4 deletions client/src/components/CodeModal/CodeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -454,7 +460,14 @@ export default function CodeModal(props: CodeModalProps) {
gitRef={props.gitRef}
onJumpToFinding={jumpToFinding}
effects={
<Show when={effects()}>
<Show when={effects()} fallback={
<Show when={effectsFile() && effectsLine() === undefined}>
<section aria-label="Function effects" data-effects-state="unselected" class="mt-3 text-[12px]">
<h3 class="pb-0.5 pt-2 text-[10.5px] font-semibold uppercase tracking-wide text-[var(--plc-on-subtle)]">Effects</h3>
<p class="pl-1.5 text-[11px] text-[var(--plc-on-muted)]">Choose a function from the outline to see what it touches.</p>
</section>
</Show>
}>
{(state) => (
<div class="mt-3">
<EffectsPanel state={state()} title={selectedScopeNode()?.name ? `Effects of ${selectedScopeNode().name}` : `Effects of the function at line ${effectsLine()}`} onOpen={(absPath, line) => { if (absPath === props.filePath) jumpToLedgerRow(line); }} />
Expand Down
2 changes: 1 addition & 1 deletion docs/CODE_MAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<sha>` 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 |
Expand Down
4 changes: 2 additions & 2 deletions server/app/routers/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions server/tests/test_dataflow_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading