Skip to content

Commit 0a1bb6e

Browse files
steipetemvanhorn
andcommitted
fix(cron): show saved automation descriptions in dashboard
Co-authored-by: Matt Van Horn <[email protected]>
1 parent 0cad023 commit 0a1bb6e

8 files changed

Lines changed: 388 additions & 102 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { expect, it } from "vitest";
2+
import { installMockGateway } from "../test-helpers/control-ui-e2e.ts";
3+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
4+
5+
const suite = createControlUiE2eSuite({
6+
name: "Control UI cron saved descriptions E2E",
7+
unavailableMessage: (executablePath) =>
8+
`Playwright Chromium is not installed or cannot start at ${executablePath}.`,
9+
});
10+
11+
function cronJob(id: string, name: string) {
12+
return {
13+
id,
14+
name,
15+
enabled: true,
16+
createdAtMs: Date.parse("2026-05-29T08:00:00.000Z"),
17+
updatedAtMs: Date.parse("2026-05-29T08:05:00.000Z"),
18+
schedule: { kind: "every", everyMs: 60_000 },
19+
sessionTarget: "main",
20+
wakeMode: "next-heartbeat",
21+
payload: { kind: "systemEvent", text: `${name} fired` },
22+
state: {},
23+
};
24+
}
25+
26+
suite.define(() => {
27+
it("shows saved descriptions in compact rows and task details for every payload kind", async () => {
28+
const jobs = [
29+
{
30+
...cronJob("described-event", "System reminder"),
31+
description: " Explain the system reminder without opening advanced settings ",
32+
payload: { kind: "systemEvent", text: "Run the system reminder" },
33+
},
34+
{
35+
...cronJob("described-agent", "Agent digest"),
36+
description: "Summarize the overnight activity",
37+
payload: { kind: "agentTurn", message: "List overnight deployment activity" },
38+
},
39+
{
40+
...cronJob("described-command", "Command check"),
41+
description: "Run the infrastructure health check",
42+
payload: { kind: "command", argv: ["echo", "healthy"] },
43+
},
44+
{
45+
...cronJob("described-script", "Script check"),
46+
description: "Inspect the scripted health check",
47+
payload: { kind: "script", script: "return 'healthy'" },
48+
},
49+
{
50+
...cronJob("described-heartbeat", "Heartbeat check"),
51+
description: "Explain the system-owned heartbeat",
52+
payload: { kind: "heartbeat" },
53+
},
54+
] as const;
55+
const undescribedJob = cronJob("without-description", "Plain task");
56+
const context = await suite.newBrowserContext({
57+
locale: "en-US",
58+
serviceWorkers: "block",
59+
viewport: { height: 900, width: 1_280 },
60+
});
61+
const page = await context.newPage();
62+
await installMockGateway(page, {
63+
methodResponses: {
64+
"cron.list": {
65+
jobs: [...jobs, undescribedJob],
66+
total: jobs.length + 1,
67+
offset: 0,
68+
limit: 50,
69+
hasMore: false,
70+
nextOffset: null,
71+
},
72+
"cron.runs": { entries: [], total: 0, offset: 0, hasMore: false },
73+
"cron.status": { enabled: true, jobs: jobs.length + 1, nextWakeAtMs: null },
74+
},
75+
});
76+
77+
try {
78+
await page.goto(`${suite.server.baseUrl}cron`);
79+
await page.locator(`[data-test-id="cron-row-${jobs[0].id}"]`).waitFor({ timeout: 10_000 });
80+
81+
for (const job of jobs) {
82+
const description = page.locator(`[data-test-id="cron-row-description-${job.id}"]`);
83+
expect((await description.textContent())?.trim()).toBe(`· ${job.description.trim()}`);
84+
expect(await description.getAttribute("title")).toBe(
85+
`Description: ${job.description.trim()}`,
86+
);
87+
}
88+
expect(
89+
await page.locator(`[data-test-id="cron-row-description-${undescribedJob.id}"]`).count(),
90+
).toBe(0);
91+
92+
const describedRow = await page
93+
.locator(`[data-test-id="cron-row-${jobs[1].id}"]`)
94+
.boundingBox();
95+
const undescribedRow = await page
96+
.locator(`[data-test-id="cron-row-${undescribedJob.id}"]`)
97+
.boundingBox();
98+
expect(describedRow?.height).toBe(undescribedRow?.height);
99+
100+
for (const job of jobs) {
101+
const row = page.locator(`[data-test-id="cron-row-${job.id}"]`);
102+
await row.locator(".cron-table__name-text").click();
103+
const detailDescription = page.locator('[data-test-id="cron-detail-description"]');
104+
await detailDescription.waitFor({ state: "visible" });
105+
expect((await detailDescription.textContent())?.replace(/\s+/g, " ").trim()).toBe(
106+
`Description: ${job.description.trim()}`,
107+
);
108+
109+
await page.locator('[data-test-id="cron-detail-tab-history"]').click();
110+
expect((await detailDescription.textContent())?.replace(/\s+/g, " ").trim()).toBe(
111+
`Description: ${job.description.trim()}`,
112+
);
113+
await page.locator('[data-test-id="cron-back"]').click();
114+
await row.waitFor({ timeout: 10_000 });
115+
}
116+
} finally {
117+
await suite.closeBrowserContext(context);
118+
}
119+
});
120+
});

‎ui/src/e2e/cron-filters.e2e.test.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,15 @@ describeControlUiE2e("Control UI cron mocked Gateway E2E", () => {
299299
});
300300

301301
it("keeps read-only operators on Cron browse and history surfaces", async () => {
302-
const readOnlyJob = cronJob(
303-
"read-only-job",
304-
"Read-only nightly digest",
305-
{ kind: "cron", expr: "0 1 * * *", tz: "UTC" },
306-
{ lastRunStatus: "ok", lastRunAtMs: Date.parse("2026-05-29T08:10:00.000Z") },
307-
);
302+
const readOnlyJob = {
303+
...cronJob(
304+
"read-only-job",
305+
"Read-only nightly digest",
306+
{ kind: "cron", expr: "0 1 * * *", tz: "UTC" },
307+
{ lastRunStatus: "ok", lastRunAtMs: Date.parse("2026-05-29T08:10:00.000Z") },
308+
),
309+
description: "Explain the nightly digest without granting write access",
310+
};
308311
const context = await browser.newContext({
309312
locale: "en-US",
310313
serviceWorkers: "block",
@@ -332,6 +335,9 @@ describeControlUiE2e("Control UI cron mocked Gateway E2E", () => {
332335
await page.goto(`${server.baseUrl}cron`);
333336
await jobTitle(page, readOnlyJob.name).waitFor({ timeout: 10_000 });
334337
await page.getByRole("note").filter({ hasText: "Browsing only" }).waitFor();
338+
expect(
339+
await page.locator(`[data-test-id="cron-row-description-${readOnlyJob.id}"]`).textContent(),
340+
).toContain(readOnlyJob.description);
335341

336342
await expect.poll(() => page.locator('[data-test-id="cron-new-task"]').count()).toBe(0);
337343
await expect
@@ -346,12 +352,18 @@ describeControlUiE2e("Control UI cron mocked Gateway E2E", () => {
346352

347353
await jobTitle(page, readOnlyJob.name).click();
348354
await page.locator("fieldset.cron-editor:disabled").waitFor();
355+
expect(
356+
await page.locator('[data-test-id="cron-detail-description"]').textContent(),
357+
).toContain(readOnlyJob.description);
349358
await expect.poll(() => page.locator('[data-test-id="cron-run-now"]').count()).toBe(0);
350359
await expect.poll(() => page.locator('[data-test-id="cron-submit"]').count()).toBe(0);
351360
await expect.poll(() => page.locator(".cron-editor-actions").count()).toBe(0);
352361

353362
await page.locator('[data-test-id="cron-detail-tab-history"]').click();
354363
await page.getByText("Read-only history remains available", { exact: true }).waitFor();
364+
expect(
365+
await page.locator('[data-test-id="cron-detail-description"]').textContent(),
366+
).toContain(readOnlyJob.description);
355367

356368
const mutationMethods = new Set(["cron.add", "cron.remove", "cron.run", "cron.update"]);
357369
expect(

‎ui/src/pages/cron/cron-page.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ describe("CronPage editor state sync", () => {
169169
const job: CronJob = {
170170
id: "access-job",
171171
name: "Readably scheduled task",
172+
description: "Inspect this task without changing its permissions",
172173
enabled: true,
173174
createdAtMs: 0,
174175
updatedAtMs: 0,
@@ -205,6 +206,9 @@ describe("CronPage editor state sync", () => {
205206
await waitForCronPage(() =>
206207
expect(page.querySelector('[data-test-id="cron-row-access-job"]')).not.toBeNull(),
207208
);
209+
expect(
210+
page.querySelector('[data-test-id="cron-row-description-access-job"]')?.textContent,
211+
).toContain(job.description);
208212
expect(Boolean(page.querySelector('[data-test-id="cron-new-task"]'))).toBe(canManage);
209213
expect(Boolean(page.querySelector('[data-test-id="cron-row-run-access-job"]'))).toBe(canManage);
210214
expect(Boolean(page.querySelector('[data-test-id="cron-row-toggle-access-job"]'))).toBe(
@@ -216,6 +220,9 @@ describe("CronPage editor state sync", () => {
216220
await waitForCronPage(() =>
217221
expect(page.querySelector('[data-test-id="cron-detail-tab-history"]')).not.toBeNull(),
218222
);
223+
expect(page.querySelector('[data-test-id="cron-detail-description"]')?.textContent).toContain(
224+
job.description,
225+
);
219226
expect(Boolean(page.querySelector('[data-test-id="cron-run-now"]'))).toBe(canManage);
220227
expect(Boolean(page.querySelector('[data-test-id="cron-toggle-enabled"]'))).toBe(canManage);
221228

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import type { CronJob } from "../../api/types.ts";
3+
import { DEFAULT_CRON_FORM } from "../../test-helpers/cron.ts";
4+
import { createCronViewJob, renderCronView } from "./view.test-support.ts";
5+
6+
const payloadCases = [
7+
{ kind: "systemEvent", payload: { kind: "systemEvent", text: "check status" } },
8+
{ kind: "agentTurn", payload: { kind: "agentTurn", message: "Summarize updates" } },
9+
{ kind: "command", payload: { kind: "command", argv: ["echo", "ready"] } },
10+
{ kind: "script", payload: { kind: "script", script: "return 'ready'" } },
11+
{ kind: "heartbeat", payload: { kind: "heartbeat" } },
12+
] satisfies Array<{ kind: CronJob["payload"]["kind"]; payload: CronJob["payload"] }>;
13+
14+
describe("cron view saved descriptions", () => {
15+
it.each(payloadCases)(
16+
"shows the saved description inline for $kind tasks without changing row selection",
17+
({ kind, payload }) => {
18+
const onSelectJob = vi.fn();
19+
const job = createCronViewJob(`described-${kind}`, {
20+
description: " Summarize overnight deployment activity ",
21+
payload,
22+
});
23+
const container = renderCronView({ jobs: [job], onSelectJob });
24+
const description = container.querySelector<HTMLSpanElement>(
25+
`[data-test-id="cron-row-description-${job.id}"]`,
26+
);
27+
28+
expect(description).toBeInstanceOf(HTMLSpanElement);
29+
expect(description?.textContent?.trim()).toBe("· Summarize overnight deployment activity");
30+
expect(description?.title).toBe("Description: Summarize overnight deployment activity");
31+
description?.click();
32+
expect(onSelectJob).toHaveBeenCalledWith(job);
33+
},
34+
);
35+
36+
it.each([undefined, "", " \n\t "])(
37+
"omits the inline description when the saved description is %j",
38+
(description) => {
39+
const job = createCronViewJob("without-description", { description });
40+
const container = renderCronView({ jobs: [job] });
41+
42+
expect(container.querySelector(".cron-table__description")).toBeNull();
43+
},
44+
);
45+
46+
it("renders saved descriptions as escaped text", () => {
47+
const description = '<img src="x" onerror="alert(1)"> & <script>alert(1)</script>';
48+
const job = createCronViewJob("escaped-description", { description });
49+
const container = renderCronView({ jobs: [job] });
50+
51+
expect(container.querySelector(".cron-table__description")?.textContent).toContain(description);
52+
expect(container.querySelector(".cron-table__name img")).toBeNull();
53+
expect(container.querySelector(".cron-table__name script")).toBeNull();
54+
});
55+
56+
it.each(payloadCases)(
57+
"shows the saved $kind task description instead of unsaved form edits",
58+
({ kind, payload }) => {
59+
const job = createCronViewJob(`saved-${kind}`, {
60+
description: " Saved description for the selected task ",
61+
payload,
62+
});
63+
const container = renderCronView({
64+
jobs: [job],
65+
editingJobId: job.id,
66+
form: { ...DEFAULT_CRON_FORM, description: "Unsaved description edit" },
67+
});
68+
const description = container.querySelector('[data-test-id="cron-detail-description"]');
69+
70+
expect(description).toBeInstanceOf(HTMLDivElement);
71+
expect(description?.textContent?.replace(/\s+/g, " ").trim()).toBe(
72+
"Description: Saved description for the selected task",
73+
);
74+
expect(description?.textContent).not.toContain("Unsaved description edit");
75+
},
76+
);
77+
78+
it.each([undefined, "", " \n\t "])(
79+
"omits the detail description when the saved description is %j",
80+
(description) => {
81+
const job = createCronViewJob("without-description", { description });
82+
const container = renderCronView({ jobs: [job], editingJobId: job.id });
83+
84+
expect(container.querySelector('[data-test-id="cron-detail-description"]')).toBeNull();
85+
},
86+
);
87+
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { render } from "lit";
2+
import type { CronJob } from "../../api/types.ts";
3+
import { DEFAULT_CRON_FORM } from "../../test-helpers/cron.ts";
4+
import { renderCron } from "./view.ts";
5+
6+
type CronProps = Parameters<typeof renderCron>[0];
7+
8+
export function createCronViewJob(id: string, overrides: Partial<CronJob> = {}): CronJob {
9+
return {
10+
id,
11+
name: "Daily ping",
12+
enabled: true,
13+
createdAtMs: 0,
14+
updatedAtMs: 0,
15+
schedule: { kind: "cron", expr: "0 9 * * *" },
16+
sessionTarget: "main",
17+
wakeMode: "next-heartbeat",
18+
payload: { kind: "systemEvent", text: "ping" },
19+
...overrides,
20+
} as CronJob;
21+
}
22+
23+
function createCronViewProps(overrides: Partial<CronProps> = {}): CronProps {
24+
return {
25+
basePath: "",
26+
agentId: "main",
27+
loading: false,
28+
canManage: true,
29+
jobsLoadingMore: false,
30+
status: null,
31+
failingCount: null,
32+
agentScoped: false,
33+
scopedTotal: null,
34+
scopedNextWakeAtMs: null,
35+
jobs: [],
36+
jobsTotal: 0,
37+
jobsHasMore: false,
38+
jobsQuery: "",
39+
jobsEnabledFilter: "all",
40+
jobsScheduleKindFilter: "all",
41+
jobsLastStatusFilter: "all",
42+
jobsSortBy: "nextRunAtMs",
43+
jobsSortDir: "asc",
44+
error: null,
45+
busy: false,
46+
form: { ...DEFAULT_CRON_FORM },
47+
fieldErrors: {},
48+
canSubmit: true,
49+
editingJobId: null,
50+
createOpen: false,
51+
listTab: "tasks",
52+
detailTab: "settings",
53+
channels: [],
54+
channelLabels: {},
55+
runs: [],
56+
runsTotal: 0,
57+
runsHasMore: false,
58+
runsLoadingMore: false,
59+
runsStatuses: [],
60+
runsDeliveryStatuses: [],
61+
runsQuery: "",
62+
runsSortDir: "desc",
63+
agentSuggestions: [],
64+
modelSuggestions: [],
65+
thinkingSuggestions: [],
66+
timezoneSuggestions: [],
67+
deliveryToSuggestions: [],
68+
accountSuggestions: [],
69+
onListTabChange: () => undefined,
70+
onDetailTabChange: () => undefined,
71+
onFormChange: () => undefined,
72+
onRefresh: () => undefined,
73+
onSubmit: () => undefined,
74+
onSubmitRunNow: () => undefined,
75+
onSelectJob: () => undefined,
76+
onOpenCreate: () => undefined,
77+
onClosePanel: () => undefined,
78+
onClone: () => undefined,
79+
onToggle: () => undefined,
80+
onRun: () => undefined,
81+
onRemove: () => undefined,
82+
onLoadMoreJobs: () => undefined,
83+
onJobsFiltersChange: () => undefined,
84+
onJobsFiltersReset: () => undefined,
85+
onLoadMoreRuns: () => undefined,
86+
onRunsFiltersChange: () => undefined,
87+
...overrides,
88+
};
89+
}
90+
91+
export function renderCronView(overrides: Partial<CronProps> = {}) {
92+
const container = document.createElement("div");
93+
render(renderCron(createCronViewProps(overrides)), container);
94+
return container;
95+
}

0 commit comments

Comments
 (0)