mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-12-02 00:37:18 +00:00
Step 4 of the legacy executor deletion, third commit: the legacy event
API and every reader of it go, so that the next commits can delete the
event log, its reducer and the types beneath them.
The API:
- `GET /runs/{id}/events` pages the run stream only
(`PaginatedRunStreamList` by `after`); the legacy `since_seq`,
`before_seq` and `order` cursors, the `oneOf` envelope, the legacy
`EventEnvelope`, `PaginatedEventList`, `RunEvent`, `EventSeq`,
`AppendEventResponse` and `RunEventDetailResponse` schemas,
`POST /runs/{id}/events`, `GET /runs/{id}/events/{seq}` and
`GET /runs/{id}/stages/{stageId}/events` are deleted. `GET
/runs/{id}/attach` and `GET /attach` frame `RunStreamItem`s only.
- The Rust and TypeScript clients regenerate; the removed models leave
the TypeScript package.
The readers:
- `fabro-client` drops the legacy run event listing, tail and attach
methods and `RunEventStream`; `list_run_stream_until` bounds a stream
read.
- `fabro-tool`'s `fabro_run_events` lists, searches and details the run
stream: `after` is the exclusive `stream_seq` cursor, `event_id` the
item's id, filters match the item's name and `recorded_at`.
- `fabro-dump` writes the stream to `events.jsonl`; `fabro dump` reads
it.
- The CLI's progress renderer keeps only what the run stream drives:
the legacy event conversion, the sandbox and setup displays and their
styles go. `fabro system events` prints stream items.
- The server's demo mode folds its agent fixture straight into the
session projection and answers the attach stub with a stream item;
the demo stage events endpoint is gone.
- The web app: every run is a Petri run. The legacy event hooks,
renderer props, stage popover summary, run phases derivation and
live-event payload handling are deleted or ported to `RunStreamItem`;
toasts and board refreshes read the stream's platform records.
- Tests: the legacy API round trips and pagination tests are deleted;
the CLI's MCP, attach and system event mocks serve stream pages; the
CLI test helpers read stream items.
Still failing until the later commits: the CLI tests seeded through
`POST /runs/{id}/events`, the server tests over the legacy store, and
the legacy type tests.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
145 lines
4.6 KiB
TypeScript
145 lines
4.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
import TestRenderer, { act } from "react-test-renderer";
|
|
import { MemoryRouter, Route, Routes } from "react-router";
|
|
|
|
import { ApiError } from "../lib/api-client";
|
|
import { setupReactTestEnv } from "../lib/test-utils";
|
|
|
|
let currentGraphData: string | null | undefined;
|
|
let currentGraphError: Error | undefined;
|
|
let currentGraphLoading = false;
|
|
|
|
const graphMutateMock = mock(() => Promise.resolve(currentGraphData));
|
|
|
|
mock.module("../lib/queries", () => ({
|
|
useRun: () => ({ data: undefined }),
|
|
useRunStages: () => ({ data: undefined }),
|
|
useRunGraph: () => ({
|
|
data: currentGraphData,
|
|
error: currentGraphError,
|
|
isLoading: currentGraphLoading,
|
|
mutate: graphMutateMock,
|
|
}),
|
|
useRunGraphSource: () => ({ data: undefined }),
|
|
useRunState: () => ({ data: undefined }),
|
|
useRunStream: () => ({ data: undefined }),
|
|
}));
|
|
|
|
mock.module("../components/run-summary-panel", () => ({
|
|
RunSummaryPanel: () => <div>summary</div>,
|
|
}));
|
|
|
|
mock.module("../components/stage-sidebar", () => ({
|
|
StageSidebar: () => <nav>stages</nav>,
|
|
}));
|
|
|
|
const { default: RunOverview } = await import("./run-overview");
|
|
|
|
const mountedRenderers: TestRenderer.ReactTestRenderer[] = [];
|
|
|
|
function textFromNode(
|
|
node: ReturnType<TestRenderer.ReactTestRenderer["toJSON"]>,
|
|
): string {
|
|
if (!node) return "";
|
|
if (typeof node === "string") return node;
|
|
if (Array.isArray(node)) return node.map(textFromNode).join(" ");
|
|
return (node.children ?? []).map(textFromNode).join(" ");
|
|
}
|
|
|
|
// Zooming writes to useRememberedGraphView's module-scoped store, so tests that
|
|
// change the viewport must each use a run id no other test zooms.
|
|
function renderAt(entry: string): TestRenderer.ReactTestRenderer {
|
|
let renderer!: TestRenderer.ReactTestRenderer;
|
|
act(() => {
|
|
renderer = TestRenderer.create(
|
|
<MemoryRouter initialEntries={[entry]}>
|
|
<Routes>
|
|
<Route path="/runs/:id" element={<RunOverview />} />
|
|
</Routes>
|
|
</MemoryRouter>,
|
|
);
|
|
});
|
|
mountedRenderers.push(renderer);
|
|
return renderer;
|
|
}
|
|
|
|
function render(): TestRenderer.ReactTestRenderer {
|
|
return renderAt("/runs/run-1");
|
|
}
|
|
|
|
// The inner graph node carries `transform: translate(...) scale(...)` reflecting view.zoom/pan.
|
|
function graphTransform(renderer: TestRenderer.ReactTestRenderer): string {
|
|
const node = renderer.root.findAll(
|
|
(n) => (n.props?.style as { transformOrigin?: string })?.transformOrigin === "center center",
|
|
)[0];
|
|
return (node.props.style as { transform: string }).transform;
|
|
}
|
|
|
|
function clickTitle(renderer: TestRenderer.ReactTestRenderer, title: string): void {
|
|
act(() => {
|
|
renderer.root.findAll((n) => n.props?.title === title)[0].props.onClick();
|
|
});
|
|
}
|
|
|
|
let teardownReactTestEnv: () => void;
|
|
|
|
beforeEach(() => {
|
|
teardownReactTestEnv = setupReactTestEnv();
|
|
});
|
|
|
|
afterEach(() => {
|
|
for (const renderer of mountedRenderers.splice(0)) {
|
|
act(() => renderer.unmount());
|
|
}
|
|
currentGraphData = undefined;
|
|
currentGraphError = undefined;
|
|
currentGraphLoading = false;
|
|
graphMutateMock.mockClear();
|
|
teardownReactTestEnv();
|
|
});
|
|
|
|
describe("RunOverview", () => {
|
|
test("shows graph render errors instead of the empty graph state", () => {
|
|
currentGraphError = new ApiError({
|
|
status: 400,
|
|
message: "failed to parse DOT source",
|
|
requestId: "req_123",
|
|
body: null,
|
|
});
|
|
|
|
const renderer = render();
|
|
const text = textFromNode(renderer.toJSON());
|
|
|
|
expect(text).toContain("Couldn't render workflow graph");
|
|
expect(text).toContain("failed to parse DOT source");
|
|
expect(text).not.toContain("No workflow graph");
|
|
});
|
|
|
|
test("restores graph zoom/pan when the route remounts for the same run", () => {
|
|
currentGraphData = "<svg viewBox='0 0 100 100'></svg>";
|
|
|
|
const first = renderAt("/runs/zoom-persist");
|
|
const initial = graphTransform(first);
|
|
clickTitle(first, "Zoom in");
|
|
const zoomed = graphTransform(first);
|
|
expect(zoomed).not.toBe(initial);
|
|
|
|
// Switching tabs unmounts this route; returning remounts it for the same run.
|
|
act(() => first.unmount());
|
|
const second = renderAt("/runs/zoom-persist");
|
|
expect(graphTransform(second)).toBe(zoomed);
|
|
});
|
|
|
|
test("does not carry one run's zoom over to a different run", () => {
|
|
currentGraphData = "<svg viewBox='0 0 100 100'></svg>";
|
|
|
|
const renderer = renderAt("/runs/run-a");
|
|
const initial = graphTransform(renderer);
|
|
clickTitle(renderer, "Zoom in");
|
|
expect(graphTransform(renderer)).not.toBe(initial);
|
|
|
|
act(() => renderer.unmount());
|
|
const other = renderAt("/runs/run-b");
|
|
expect(graphTransform(other)).toBe(initial);
|
|
});
|
|
});
|