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
6 changes: 3 additions & 3 deletions packages/app/src/features/runs/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export function RunHistory({ jobId }: { jobId: string }) {
const runs = useQuery(historyQuery(jobId, search.cursor, search.sort, search.direction));
const previous = search.previous === undefined ? [] : search.previous.split(",");
const pageClasses = `inline-flex min-h-10 items-center rounded-lg border px-3 py-2 text-sm font-semibold ${buttonClasses.secondary}`;
const columns: Array<[HistorySort, string]> = [["run", "Run"], ["status", "Status"], ["created", "Created"], ["agent", "Agent"]];
const columns: Array<[HistorySort, string]> = [["status", "Status"], ["run", "Run"], ["created", "Created"], ["agent", "Agent"]];
const sortColumn = (column: HistorySort) => {
const direction = search.sort === column && search.direction === "asc" ? "desc" : "asc";
void navigate({ to: "/jobs/$jobId", params: { jobId }, search: { sort: column, direction, cursor: undefined, previous: undefined } });
};
const sortLabel = (column: HistorySort) => search.sort === column ? (search.direction === "desc" ? "sorted descending" : "sorted ascending") : "not sorted";
return <section aria-label="Runs" className="my-6 min-w-0">
{runs.isPending && <p role="status">Loading run history…</p>}{runs.error && <p role="alert">{runs.error.message} <Button onClick={() => void runs.refetch()}>Retry</Button></p>}
{runs.data && <><Table className="min-w-[36rem] table-fixed" shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><caption className="sr-only">Job runs{search.sort ? "" : ", newest first"}</caption><colgroup><col className="w-[38%] sm:w-[42%]" /><col className="w-16 sm:w-20" /><col className="w-[30%] sm:w-[26%]" /><col className="w-[20%] sm:w-[16%]" /></colgroup>
{runs.data && <><Table className="min-w-[36rem] table-fixed" shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><caption className="sr-only">Job runs{search.sort ? "" : ", newest first"}</caption><colgroup><col className="w-16 sm:w-20" /><col className="w-[38%] sm:w-[42%]" /><col className="w-[30%] sm:w-[26%]" /><col className="w-[20%] sm:w-[16%]" /></colgroup>
<thead className={tableHeadClasses}><tr>{columns.map(([column, label]) => <SortableHeader key={column} label={label} active={search.sort === column} direction={search.direction} ariaLabel={`${label}, ${sortLabel(column)}`} onSort={() => sortColumn(column)} />)}</tr></thead>
<tbody>{runs.data.items.map(run => <tr className={tableRowClasses} key={run.id}>
<td className={tableCellClasses}><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} title={run.run_name || run.issue_title || "Run"} className="block truncate font-semibold hover:text-factorize-700 focus-visible:rounded-sm dark:hover:text-factorize-500">{run.run_name || run.issue_title || "Run"}</Link></td>
<td className={`whitespace-nowrap ${tableCellClasses}`}><RunStatusDot state={run.state} /></td>
<td className={tableCellClasses}><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} title={run.run_name || run.issue_title || "Run"} className="block truncate font-semibold hover:text-factorize-700 focus-visible:rounded-sm dark:hover:text-factorize-500">{run.run_name || run.issue_title || "Run"}</Link></td>
<td className={`whitespace-nowrap ${tableCellClasses}`}><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td><td className={`${tableCellClasses} truncate`} title={run.agent_kind}>{run.agent_kind}</td>
</tr>)}{runs.data.items.length === 0 && <tr><td colSpan={4} className="px-3 py-6 text-center">No runs found.</td></tr>}</tbody>
</Table></>}
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/features/runs/queries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api } from "factorize-api-client";
import { queryOptions } from "@tanstack/react-query";
import { keepPreviousData, queryOptions } from "@tanstack/react-query";
import { messageOf } from "../auth/session";
export const runStatusQuery = (runId: string) => queryOptions({
queryKey: ["runs", runId, "status"],
Expand All @@ -23,4 +23,4 @@ export const runPageQuery = ({ jobId, cursor, limit, sort, direction }: { jobId?
queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, limit, sort, direction } } }); if (!data || error) throw new Error(messageOf(error)); return data; },
staleTime: 0, refetchInterval: 2_000, refetchIntervalInBackground: false,
});
export const historyQuery = (jobId: string, cursor?: string, sort?: "run" | "status" | "created" | "agent", direction?: "asc" | "desc") => queryOptions({ queryKey: ["runs", "history", jobId, cursor, sort, direction], queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, sort, direction: direction ?? (sort ? "asc" : undefined), limit: 30 } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, staleTime: 10_000 });
export const historyQuery = (jobId: string, cursor?: string, sort?: "run" | "status" | "created" | "agent", direction?: "asc" | "desc") => queryOptions({ queryKey: ["runs", "history", jobId, cursor, sort, direction], queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, sort, direction: direction ?? (sort ? "asc" : undefined), limit: 30 } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, placeholderData: keepPreviousData, staleTime: 10_000 });
2 changes: 1 addition & 1 deletion packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ test("run table headers sort every column accessibly and persist in the URL", as
await page.goto(origin + `/jobs/${jobId}`);
const table = page.getByRole("table");
await table.getByRole("columnheader").nth(0).getByRole("button").waitFor();
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Run", "Status", "Created", "Agent"]);
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Status", "Run", "Created", "Agent"]);
assert.equal(await table.getByRole("columnheader", { name: /Agent/ }).count(), 1);
for (const index of [0, 1, 2, 3]) assert.equal(await table.getByRole("columnheader").nth(index).getByRole("button").count(), 1);
const runButton = page.getByRole("button", { name: "Run job", exact: true }), optionsButton = page.getByRole("button", { name: "More run options", exact: true });
Expand Down
17 changes: 17 additions & 0 deletions packages/app/test/runs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ test("job run history restores its cursor on direct refresh and ignores legacy f
await page.goto(origin + `/jobs/${jobId}?state=succeeded&contextQuery=needle`); await page.getByRole("link", { name: "First run", exact: true }).waitFor(); await page.getByRole("link", { name: "Next page" }).click(); await page.getByRole("link", { name: "Second run", exact: true }).waitFor(); await page.reload(); await page.getByRole("link", { name: "Second run", exact: true }).waitFor();
assert.equal(new URL(page.url()).searchParams.get("cursor"), "next-cursor"); assert.ok(requests.every(url => url.searchParams.get("jobId") === jobId && url.searchParams.get("limit") === "30" && !url.searchParams.has("contextQuery") && !url.searchParams.has("state"))); await context.close();
});
test("job run history keeps the table visible while sorting and puts status first", async () => {
const { context, page } = await setup(); let releaseSorted;
const sorted = new Promise(resolve => { releaseSorted = resolve; });
await page.route(`**/api/v1/jobs/${jobId}`, route => route.fulfill({ json: { id: jobId, name: "Job", enabled: true, model: "", agentKind: "codex", concurrencyLimit: 1, runningCount: 0, promptTemplate: "Prompt", triggers: [] } }));
await page.route("**/api/v1/runs?**", async route => {
const url = new URL(route.request().url());
if (url.searchParams.has("sort")) { await sorted; return route.fulfill({ json: { items: [{ id: runId, run_name: "Sorted run", state: "failed", created_at: time, agent_kind: "codex" }], nextCursor: null } }); }
return route.fulfill({ json: { items: [{ id: runId, run_name: "Initial run", state: "succeeded", created_at: time, agent_kind: "codex" }], nextCursor: null } });
});
await page.goto(origin + `/jobs/${jobId}`); const table = page.getByRole("region", { name: "Runs table" });
await table.getByRole("link", { name: "Initial run", exact: true }).waitFor();
assert.equal(await table.locator("thead th").first().textContent(), "Status");
await table.getByRole("button", { name: /Run, not sorted/ }).click(); await page.waitForURL(`**/jobs/${jobId}?sort=run&direction=asc`);
assert.equal(await page.getByText("Loading run history…", { exact: true }).count(), 0);
assert.equal(await table.getByRole("link", { name: "Initial run", exact: true }).count(), 1);
releaseSorted(); await table.getByRole("link", { name: "Sorted run", exact: true }).waitFor(); await context.close();
});
test("prompt/provenance and diagnostics are lazy, terminal replay retries reuse a stable key and reset the visible trace", async () => {
const { context, page } = await setup(); let revision = "old", detailReads = 0, diagnosticReads = 0; const replays = [];
await page.route(`**/api/v1/runs/${runId}/status`, route => route.fulfill({ json: { id: runId, job_id: jobId, job_name: "Job", run_name: "Run", state: "succeeded", finalizing: false, trace_revision: revision, artifact_state: "stored", created_at: time, updated_at: time, started_at: time, destination_url: null } }));
Expand Down
Loading