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
2 changes: 1 addition & 1 deletion packages/app/src/features/auth/account-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function AccountBar() {
<nav aria-label="Main navigation" className="mx-auto flex min-h-16 max-w-6xl flex-wrap items-center justify-between gap-3 px-4 py-3 sm:px-6 lg:px-8">
<Link to="/" className="flex items-center gap-2 text-lg font-bold tracking-tight"><img src={beeMark} alt="" className="size-8 object-contain dark:invert" />Factorize</Link>
<div className="flex flex-wrap items-center gap-2 sm:gap-4">
{authenticated && <><Link to="/jobs" search={{ q: "" }} activeProps={{ className: "text-factorize-700 dark:text-factorize-500" }} className="rounded-lg px-2 py-2 text-sm font-semibold">Jobs</Link><SearchLauncher /></>}
{authenticated && <><Link to="/jobs" search={{ q: "" }} activeProps={{ className: "text-factorize-700 dark:text-factorize-500" }} className="rounded-lg px-2 py-2 text-sm font-semibold">Jobs</Link><Link to="/job-runs" activeProps={{ className: "text-factorize-700 dark:text-factorize-500" }} className="rounded-lg px-2 py-2 text-sm font-semibold">Runs</Link><SearchLauncher /></>}
<ThemeToggle />
{authenticated ? <div ref={menu} className="relative">
<Button ref={trigger} aria-expanded={open} aria-controls="profile-menu" onClick={() => setOpen(!open)} aria-label="Your account"><span className="flex size-6 items-center justify-center rounded-full bg-factorize-100 text-xs text-slate-950">{(session.data?.user.email ?? "").slice(0, 1).toUpperCase()}</span><span className="hidden sm:inline">Account</span><span aria-hidden="true">⌄</span></Button>
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/features/runs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Page, PageHeader } from "../../shared/ui";
import { RunList } from "./list";
export function RunsIndex() { return <Page><PageHeader title="Runs" /><RunList limit={20} /></Page>; }
31 changes: 31 additions & 0 deletions packages/app/src/features/runs/list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Badge, Button, buttonClasses } from "../../shared/ui";
import { Link, useSearch } from "@tanstack/react-router";
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { runPageQuery } from "./queries";

export type RunListSearch = { cursor?: string; previous?: string };
const activeStates = new Set(["queued", "starting", "running", "blocked", "stopping"]);
const elapsed = (startedAt: string | null, createdAt: string) => { const start = Date.parse(startedAt ?? createdAt), seconds = Math.max(0, Math.floor((Date.now() - start) / 1000)); if (seconds < 60) return `${seconds}s`; const minutes = Math.floor(seconds / 60); return minutes < 60 ? `${minutes}m ${seconds % 60}s` : `${Math.floor(minutes / 60)}h ${minutes % 60}m`; };

export function RunList({ jobId, limit = 30 }: { jobId?: string; limit?: number }) {
const search = useSearch({ strict: false }) as RunListSearch, runs = useQuery(runPageQuery({ jobId, cursor: search.cursor, limit }));
const [now, setNow] = useState(Date.now());
useEffect(() => { if (!runs.data?.items.some(run => activeStates.has(run.state))) return; const timer = window.setInterval(() => setNow(Date.now()), 1_000); return () => window.clearInterval(timer); }, [runs.data?.items]);
const previous = search.previous?.split(",") ?? [], pageClasses = `inline-flex min-h-10 items-center rounded-lg border px-3 py-2 text-sm font-semibold ${buttonClasses.secondary}`;
const pagination = jobId ? <nav aria-label="Run pages" className="mt-4 flex flex-wrap items-center gap-2">
{search.cursor && <Link className={pageClasses} to="/jobs/$jobId" params={{ jobId }} search={{}}>First page</Link>}
{search.cursor && previous.length > 0 ? <Link className={pageClasses} to="/jobs/$jobId" params={{ jobId }} search={{ cursor: previous.at(-1) || undefined, previous: previous.length > 1 ? previous.slice(0, -1).join(",") : undefined }}>Previous page</Link> : <Button disabled>Previous page</Button>}
{runs.data?.nextCursor ? <Link className={pageClasses} to="/jobs/$jobId" params={{ jobId }} search={{ cursor: runs.data.nextCursor, previous: [...previous, search.cursor ?? ""].join(",") }}>Next page</Link> : <Button disabled>Next page</Button>}
</nav> : <nav aria-label="Run pages" className="mt-4 flex flex-wrap items-center gap-2">
{search.cursor && <Link className={pageClasses} to="/job-runs" search={{}}>First page</Link>}
{search.cursor && previous.length > 0 ? <Link className={pageClasses} to="/job-runs" search={{ cursor: previous.at(-1), previous: previous.length > 1 ? previous.slice(0, -1).join(",") : undefined }}>Previous page</Link> : <Button disabled>Previous page</Button>}
{runs.data?.nextCursor ? <Link className={pageClasses} to="/job-runs" search={{ cursor: runs.data.nextCursor, previous: [...previous, search.cursor ?? ""].join(",") }}>Next page</Link> : <Button disabled>Next page</Button>}
</nav>;
return <section aria-label="Runs" className="my-6 min-w-0">
{runs.isPending && <p role="status">Loading runs…</p>}{runs.error && <p role="alert">{runs.error.message} <Button onClick={() => void runs.refetch()}>Retry</Button></p>}
{runs.data && <>{runs.data.items.length === 0 && jobId ? <div role="region" aria-label="Runs table" tabIndex={0} className="overflow-x-auto rounded-lg border border-stone-200 dark:border-slate-700"><table className="w-full text-left text-sm"><tbody><tr><td colSpan={4} className="px-3 py-6 text-center">No runs found.</td></tr></tbody></table></div> : runs.data.items.length === 0 ? <p className="py-8 text-center text-sm text-slate-600 dark:text-slate-400">No runs yet</p> : <div role="region" aria-label="Runs table" tabIndex={0} className="overflow-x-auto rounded-lg border border-stone-200 dark:border-slate-700"><table className="w-full text-left text-sm"><caption className="sr-only">Runs, newest first</caption><thead className="bg-stone-100 dark:bg-slate-800"><tr><th scope="col" className="px-3 py-2">Run</th><th scope="col" className="px-3 py-2">Status</th><th scope="col" className="px-3 py-2">Created</th>{jobId ? <th scope="col" className="px-3 py-2">Agent</th> : <th scope="col" className="px-3 py-2">Elapsed</th>}</tr></thead><tbody>{runs.data.items.map(run => <tr className="border-t border-stone-200 dark:border-slate-700" key={run.id}><td className="min-w-40 max-w-sm break-words px-3 py-2"><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} className="font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">{run.run_name || "Run"}</Link></td><td className="whitespace-nowrap px-3 py-2"><Badge active={activeStates.has(run.state)}>{run.state}</Badge></td><td className="whitespace-nowrap px-3 py-2"><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td>{jobId ? <td className="px-3 py-2">{run.agent_kind}</td> : <td className="whitespace-nowrap px-3 py-2">{activeStates.has(run.state) ? elapsed(run.started_at, run.created_at) : "—"}</td>}</tr>)}</tbody></table></div>}</>}
{pagination}
<span className="sr-only" aria-live="polite">{now}</span>
</section>;
}
5 changes: 5 additions & 0 deletions packages/app/src/features/runs/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ export const runTraceQuery = (runId: string, revision: string, after: number, po
});
export const runDetailQuery = (runId: string) => queryOptions({ queryKey: ["runs", runId, "detail"], queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs/{runId}", { signal, params: { path: { runId } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, staleTime: 60_000 });
export const diagnosticsQuery = (runId: string) => queryOptions({ queryKey: ["runs", runId, "diagnostics"], queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs/{runId}/diagnostics", { signal, params: { path: { runId } } }); if (!data || error) throw new Error(messageOf(error)); return data; }, staleTime: 30_000 });
export const runPageQuery = ({ jobId, cursor, limit }: { jobId?: string; cursor?: string; limit: number }) => queryOptions({
queryKey: ["runs", "page", jobId, cursor, limit],
queryFn: async ({ signal }) => { const { data, error } = await api.GET("/api/v1/runs", { signal, params: { query: { jobId, cursor, limit } } }); 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 });
11 changes: 9 additions & 2 deletions packages/app/src/features/runs/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { createRoute, lazyRouteComponent, redirect, type AnyRootRoute } from "@tanstack/react-router";
import { sessionQuery } from "../auth/session";
import { queryClient } from "../../shared/query-client";
import { runStatusQuery } from "./queries";
import { runPageQuery, runStatusQuery } from "./queries";
export function runRoutes(root: AnyRootRoute) {
const list = createRoute({ getParentRoute: () => root, path: "/job-runs",
validateSearch: (s: Record<string, unknown>) => ({ cursor: typeof s.cursor === "string" ? s.cursor : undefined, previous: typeof s.previous === "string" ? s.previous.slice(0, 20_000) : undefined }),
beforeLoad: async ({ location }) => { if (!(await queryClient.ensureQueryData(sessionQuery)).authenticated) throw redirect({ to: "/auth/login", search: { returnTo: location.href, token: undefined } }); },
loaderDeps: ({ search }) => search,
loader: ({ deps }) => queryClient.ensureQueryData(runPageQuery({ cursor: deps.cursor, limit: 20 })),
component: lazyRouteComponent(() => import("./index"), "RunsIndex"),
});
const validateSearch = (s: Record<string, unknown>) => ({ after: Number.isSafeInteger(Number(s.after)) && Number(s.after) >= 0 ? Number(s.after) : 0 });
const beforeLoad = async ({ location }: { location: { href: string } }) => { if (!(await queryClient.ensureQueryData(sessionQuery)).authenticated) throw redirect({ to: "/auth/login", search: { returnTo: location.href, token: undefined } }); };
const loader = ({ params }: { params: { runId: string } }) => queryClient.ensureQueryData(runStatusQuery(params.runId));
Expand All @@ -16,5 +23,5 @@ export function runRoutes(root: AnyRootRoute) {
const contextCompatibility = createRoute({ getParentRoute: () => root, path: "/job-runs/$runId/context",
validateSearch, beforeLoad: ({ params, search }) => { throw redirect({ to: "/job-runs/$runId/info", params, search }); },
});
return [base, tab("/trace"), tab("/info"), tab("/settings"), contextCompatibility];
return [list, base, tab("/trace"), tab("/info"), tab("/settings"), contextCompatibility];
}
11 changes: 11 additions & 0 deletions packages/app/test/runs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ const jobId = "00000000-0000-4000-8000-000000000001", runId = "00000000-0000-400
before(async () => { server = createServer(async (req, res) => { const path = new URL(req.url, "http://local").pathname, file = (/^(\/assets\/|\/theme-init.js$|\/bee-mark-monochrome.png$|\/favicon.ico$)/.test(path)) ? path : "/index.html"; try { const body = await readFile(new URL("../dist" + file, import.meta.url)); res.setHeader("Content-Type", file.endsWith(".js") ? "application/javascript" : file.endsWith(".css") ? "text/css" : "text/html"); res.end(body); } catch { res.statusCode = 404; res.end(); } }); await new Promise(resolve => server.listen(0, "127.0.0.1", resolve)); origin = "http://127.0.0.1:" + server.address().port; browser = await chromium.launch({ headless: true }); });
after(async () => { await browser?.close(); if (server) await new Promise(resolve => server.close(resolve)); });
async function setup() { const context = await browser.newContext(), page = await context.newPage(); page.setDefaultTimeout(10000); await page.route("**/api/v1/session", route => route.fulfill({ json: { authenticated: true, user: { id: "owner", email: "owner@example.test" }, workspace: { id: "tenant", name: "Workspace" }, capabilities: [], expiresAt: "2026-10-10T00:00:00Z" } })); return { context, page }; }
test("all-jobs runs index uses a tenant-scoped page, navigation, refresh, and elapsed time", async () => {
const { context, page } = await setup(); const requests = []; let refreshes = 0;
const runs = Array.from({ length: 21 }, (_, index) => ({ id: `00000000-0000-4000-8000-${String(index + 1).padStart(12, "0")}`, run_name: `Run ${index}`, state: index === 0 ? "running" : "succeeded", created_at: time, updated_at: time, started_at: index === 0 ? time : null, agent_kind: "codex" }));
await page.route("**/api/v1/runs?**", route => { const url = new URL(route.request().url()); requests.push(url); refreshes++; const second = url.searchParams.has("cursor"); return route.fulfill({ json: { items: second ? [runs[20]] : runs.slice(0, 20), nextCursor: second ? null : "page-2" } }); });
await page.goto(origin + "/job-runs"); await page.getByRole("heading", { name: "Runs", exact: true }).waitFor(); await page.getByRole("link", { name: "Run 0", exact: true }).waitFor();
assert.equal(await page.getByRole("link", { name: "Jobs", exact: true }).getAttribute("href"), "/jobs?q="); assert.equal(await page.getByRole("link", { name: "Runs", exact: true }).evaluate(el => el.className.includes("text-factorize-700")), true);
assert.equal(await page.getByText("Run 0", { exact: true }).count(), 1); assert.match(await page.getByRole("cell", { name: /\d+(?:s|m \d+s|h \d+m)$/ }).first().textContent(), /\d+(?:s|m \d+s|h \d+m)$/);
assert.ok(requests.every(url => url.searchParams.get("limit") === "20" && !url.searchParams.has("jobId")));
await page.getByRole("link", { name: "Next page" }).click(); await page.getByRole("link", { name: "Run 20", exact: true }).waitFor(); await page.reload(); await page.getByRole("link", { name: "Run 20", exact: true }).waitFor(); assert.ok(refreshes >= 2);
await context.close();
});
test("job run history restores its cursor on direct refresh and ignores legacy filters", async () => {
const { context, page } = await setup(); const requests = [];
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: [] } }));
Expand Down
Binary file modified packages/app/test/visual/baselines/chunk-recovery-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/chunk-recovery-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/clients-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/clients-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/consent-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/consent-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/device-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/device-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/editor-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/editor-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/index-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/index-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/job-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/job-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-error-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-loading-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/keys-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/keys-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/long-job-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/not-found-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/not-found-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/password-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/password-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/run-context-dark-390.png
Binary file modified packages/app/test/visual/baselines/run-dialog-validation-mobile.png
Binary file modified packages/app/test/visual/baselines/run-settings-dark-390.png
Binary file modified packages/app/test/visual/baselines/run-settings-light-390.png
Binary file modified packages/app/test/visual/baselines/search-empty-mobile.png
Binary file modified packages/app/test/visual/baselines/search-error-dark-390.png
Binary file modified packages/app/test/visual/baselines/search-error-light-390.png
Binary file modified packages/app/test/visual/baselines/search-loading-dark-390.png
Binary file modified packages/app/test/visual/baselines/search-loading-light-390.png
Binary file modified packages/app/test/visual/baselines/search-no-results-dark-390.png
Binary file modified packages/app/test/visual/baselines/search-no-results-light-390.png
Binary file modified packages/app/test/visual/baselines/search-results-mobile.png
Binary file modified packages/app/test/visual/baselines/settings-dark-390.png
Binary file modified packages/app/test/visual/baselines/settings-light-390.png
Binary file modified packages/app/test/visual/baselines/signup-mobile.png
Binary file modified packages/app/test/visual/baselines/trace-dark-390.png
Binary file modified packages/app/test/visual/baselines/trace-light-390.png
Loading