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
33 changes: 20 additions & 13 deletions packages/app/src/features/jobs/list.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { Card, PageHeader, Badge, buttonClasses, Button, Input, Select, Label, Page } from "../../shared/ui";
import { Link, useSearch, useNavigate } from "@tanstack/react-router";
import { Card, Badge, buttonClasses, Page } from "../../shared/ui";
import { Link, useSearch } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { jobsQuery, type JobsSearch } from "./queries";
export function JobsList() {
const search = useSearch({ strict: false }) as JobsSearch;
const navigate = useNavigate();
const query = useQuery(jobsQuery(search));
return <Page >
<PageHeader title="Jobs" description="Your software factory. Configure prompts, connect triggers, and follow every run."><Link to="/jobs/new" className={`rounded-lg border px-4 py-2.5 text-sm font-semibold ${buttonClasses.primary}`}>Create job</Link></PageHeader>
<form onSubmit={event => { event.preventDefault(); const form = new FormData(event.currentTarget); const enabled = form.get("enabled"); void navigate({ to: "/jobs", search: { q: String(form.get("q") ?? ""), enabled: enabled === "true" || enabled === "false" ? enabled : undefined, cursor: undefined } }); }} className="mb-6 flex flex-wrap items-end gap-3 rounded-xl border border-stone-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900">
<Label>Search jobs <Input name="q" defaultValue={search.q} maxLength={120} /></Label>
<Label>Status <Select name="enabled" defaultValue={search.enabled ?? ""}><option value="">All</option><option value="true">Enabled</option><option value="false">Disabled</option></Select></Label>
<Button>Search</Button>
</form>
<div className="mb-5 flex min-w-0 items-center justify-between gap-3">
<h1 className="text-3xl font-bold tracking-tight">Jobs</h1>
<Link to="/jobs/new" className={`shrink-0 whitespace-nowrap rounded-lg border px-4 py-2.5 text-sm font-semibold ${buttonClasses.primary}`}>Create job</Link>
</div>
{query.isPending && <p role="status">Loading jobs…</p>}
{query.error && <p role="alert">{query.error.message}</p>}
{query.data && <>
{!query.data.items.length && <Card className="py-12 text-center"><h2>No jobs found</h2><p className="text-sm text-slate-600 dark:text-slate-400">Create your first job or adjust your search.</p></Card>}
<ul className="grid gap-3">{query.data.items.map(job => <li key={job.id} className="min-w-0 rounded-xl border border-stone-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<Link to="/jobs/$jobId" params={{ jobId: job.id }} className="block break-words text-lg font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">{job.name}</Link>
<div className="mt-3 flex flex-wrap items-center gap-3 text-xs text-slate-600 dark:text-slate-400"><Badge active={job.enabled}>{job.enabled ? "Enabled" : "Disabled"}</Badge><span>{job.agentKind} · {job.model || "Default model"}</span><span>{job.runningCount}/{job.concurrencyLimit} running</span><Badge active={job.lastRunState === "running"}>{job.lastRunState ?? "No runs yet"}</Badge></div>
</li>)}</ul>
{!!query.data.items.length && <div className="overflow-hidden rounded-xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
<table className="w-full table-fixed text-left text-sm" aria-label="Jobs">
<thead className="bg-stone-100 text-xs text-slate-600 dark:bg-slate-800 dark:text-slate-400"><tr>
<th scope="col" className="w-24 px-2 py-2 sm:px-3">Status</th>
<th scope="col" className="w-20 px-2 py-2 sm:px-3">Running</th>
<th scope="col" className="px-2 py-2 sm:px-3">Title</th>
</tr></thead>
<tbody>{query.data.items.map(job => <tr key={job.id} className="group relative border-t border-stone-200 transition-colors hover:bg-factorize-50 focus-within:bg-factorize-50 focus-within:shadow-[inset_3px_0_0_var(--color-factorize-500)] dark:border-slate-800 dark:hover:bg-factorize-500/10 dark:focus-within:bg-factorize-500/10">
<td className="whitespace-nowrap px-2 py-2 sm:px-3"><Badge active={job.enabled}>{job.enabled ? "Enabled" : "Disabled"}</Badge></td>
<td className={`whitespace-nowrap px-2 py-2 font-mono tabular-nums sm:px-3 ${job.runningCount > 0 ? "font-semibold text-factorize-700 dark:text-factorize-500" : "text-slate-600 dark:text-slate-400"}`}>{job.runningCount}/{job.concurrencyLimit}</td>
<td className="px-2 py-2 sm:px-3"><Link to="/jobs/$jobId" params={{ jobId: job.id }} title={job.name} className="block truncate font-semibold outline-none after:absolute after:inset-0 focus-visible:after:rounded-sm focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-factorize-500">{job.name}</Link></td>
</tr>)}</tbody>
</table>
</div>}
<nav aria-label="Job pages" className="mt-6 flex gap-4 text-sm font-semibold">
{search.cursor && <Link to="/jobs" search={{ ...search, cursor: undefined }}>First page</Link>}
{query.data.nextCursor && <Link to="/jobs" search={{ ...search, cursor: query.data.nextCursor }}>Next page</Link>}
Expand Down
22 changes: 19 additions & 3 deletions packages/app/src/features/jobs/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@ import { queryOptions } from "@tanstack/react-query";
import { messageOf } from "../auth/session";
export type JobsSearch = { q: string; cursor?: string; enabled?: "true" | "false" };
export const jobsQuery = (search: JobsSearch) => queryOptions({
queryKey: ["jobs", "summaries", search],
queryKey: ["jobs", "summaries", { q: search.q, enabled: search.enabled }],
queryFn: async ({ signal }) => {
const { data, error } = await api.GET("/api/v1/job-summaries", { signal, params: { query: { ...search, limit: 30 } } });
if (!data || error) throw new Error(messageOf(error)); return data;
// The API's UUID pages do not reflect running/title order. Collect lightweight
// summaries before paginating so active jobs on later API pages come first.
const items = [];
let cursor: string | undefined;
do {
const { data, error } = await api.GET("/api/v1/job-summaries", { signal, params: { query: { q: search.q, enabled: search.enabled, cursor, limit: 100 } } });
if (!data || error) throw new Error(messageOf(error));
items.push(...data.items);
cursor = data.nextCursor ?? undefined;
} while (cursor);
items.sort((a, b) => Number(b.runningCount > 0) - Number(a.runningCount > 0) || a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
return items;
},
select: items => {
const cursorIndex = search.cursor ? items.findIndex(job => job.id === search.cursor) : -1;
const start = cursorIndex + 1;
const page = items.slice(start, start + 30);
return { items: page, nextCursor: start + 30 < items.length ? page.at(-1)!.id : null };
}, staleTime: 10_000,
});
export const jobQuery = (jobId: string) => queryOptions({
Expand Down
45 changes: 33 additions & 12 deletions packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,45 @@ async function contextFor(options) {
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("job search/cursors survive direct refresh and mobile keyboard navigation", async () => {
const { page, context } = await contextFor({ viewport: { width: 390, height: 844 } });
for (const width of [1280, 390, 320]) for (const theme of ["light", "dark"]) test(`compact jobs grouping, pagination, focus and long titles at ${width} ${theme}`, async () => {
const { page, context } = await contextFor({ viewport: { width, height: 844 }, colorScheme: theme });
const longTitle = "Zulu " + "long title ".repeat(30);
const fixtures = Array.from({ length: 31 }, (_, index) => ({ ...summary, id: `00000000-0000-4000-8000-${String(index + 1).padStart(12, "0")}`, name: `Idle ${String(index).padStart(2, "0")}`, enabled: index % 2 === 0 }));
fixtures[0] = { ...fixtures[0], name: longTitle, enabled: true, runningCount: 1, concurrencyLimit: 10 };
fixtures[30] = { ...fixtures[30], name: "Alpha running", enabled: false, runningCount: 2, concurrencyLimit: 10 };
const requests = [];
await page.route("**/api/v1/job-summaries?**", route => {
const url = new URL(route.request().url()); requests.push(url);
return route.fulfill({ json: { items: [{ ...summary, name: url.searchParams.has("cursor") ? "Second job" : "Review builds" }], nextCursor: url.searchParams.has("cursor") ? null : jobId } });
return route.fulfill({ json: { items: url.searchParams.has("cursor") ? fixtures.slice(30) : fixtures.slice(0, 30), nextCursor: url.searchParams.has("cursor") ? null : fixtures[29].id } });
});
await page.route(`**/api/v1/jobs/${fixtures[30].id}`, route => route.fulfill({ json: { ...fixtures[30], promptTemplate: "Template", runNameTemplate: "", executionTargetId: "local", executionTarget: { connectionId: "local", workspace: "ephemeral", cwd: "/workspace", agentKind: "codex" }, triggers: [], currentRuns: 2, maxConcurrency: 10 } }));
await page.goto(origin + "/jobs?q=Review");
await page.getByRole("link", { name: "Review builds", exact: true }).waitFor();
await page.getByRole("link", { name: "Next page" }).click();
await page.getByRole("link", { name: "Second job" }).waitFor();
assert.equal(new URL(page.url()).searchParams.get("cursor"), jobId);
await page.reload(); await page.getByRole("link", { name: "Second job" }).waitFor();
await page.getByLabel("Search jobs", { exact: true }).fill("builds"); await page.getByLabel("Search jobs", { exact: true }).press("Enter");
await page.waitForURL("**/jobs?q=builds*");
assert.equal(new URL(page.url()).searchParams.has("cursor"), false);
assert.ok(requests.every(url => url.searchParams.get("limit") === "30"));
const table = page.getByRole("table", { name: "Jobs", exact: true });
await table.getByRole("link", { name: "Alpha running", exact: true }).waitFor();
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Status", "Running", "Title"]);
assert.deepEqual(await table.locator("tbody td:last-child").allTextContents(), ["Alpha running", longTitle, ...fixtures.slice(1, 29).map(job => job.name)]);
assert.deepEqual(await table.locator("tbody tr").first().locator("td").allTextContents(), ["Disabled", "2/10", "Alpha running"]);
assert.deepEqual(await table.locator("tbody tr").nth(2).locator("td").allTextContents(), ["Disabled", "0/2", "Idle 01"]);
assert.equal(await page.getByLabel("Search jobs", { exact: true }).count(), 0);
assert.equal(await page.getByText("Your software factory. Configure prompts, connect triggers, and follow every run.").count(), 0);
const heading = await page.getByRole("heading", { name: "Jobs", exact: true }).boundingBox(), create = await page.getByRole("link", { name: "Create job", exact: true }).boundingBox();
assert.ok(create.x > heading.x + heading.width && Math.abs(create.y - heading.y) < 12);
const longLink = table.getByRole("link", { name: longTitle, exact: true });
assert.equal(await longLink.evaluate(el => el.scrollWidth > el.clientWidth && getComputedStyle(el).whiteSpace === "nowrap"), true);
const first = table.locator("tbody tr").first(), idleColor = await first.evaluate(el => getComputedStyle(el).backgroundColor);
await first.hover(); await page.waitForFunction(() => getComputedStyle(document.querySelector("tbody tr")).backgroundColor !== "rgba(0, 0, 0, 0)"); assert.notEqual(await first.evaluate(el => getComputedStyle(el).backgroundColor), idleColor);
await page.mouse.move(0, 0); const link = first.getByRole("link"); await link.focus();
assert.equal(await link.evaluate(el => el === document.activeElement), true);
await page.waitForFunction(() => getComputedStyle(document.querySelector("tbody tr")).backgroundColor !== "rgba(0, 0, 0, 0)");
assert.notEqual(await first.evaluate(el => getComputedStyle(el).backgroundColor), idleColor);
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
await page.getByRole("link", { name: "Next page" }).click(); await table.getByRole("link", { name: "Idle 29", exact: true }).waitFor();
await page.reload(); await table.getByRole("link", { name: "Idle 29", exact: true }).waitFor();
await page.getByRole("link", { name: "First page" }).click(); await table.getByRole("link", { name: "Alpha running", exact: true }).waitFor();
assert.ok(requests.every(url => url.searchParams.get("limit") === "100" && url.searchParams.get("q") === "Review"));
await table.getByRole("link", { name: "Alpha running", exact: true }).focus(); await page.keyboard.press("Enter");
await page.waitForURL(`**/jobs/${fixtures[30].id}`);
await page.getByRole("heading", { name: "Alpha running", exact: true }).waitFor();
await context.close();
});
test("invocation validates JSON, preserves retry idempotency and navigates to lightweight run/trace", async () => {
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/jobs-dark-1280.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-empty.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-1280.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/search-error-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/search-error-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/search-loading-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/search-loading-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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading