import { expect, test } from "./fixtures"; import { seedWorkspace, type SeededWorkspace } from "./helpers/seed-client"; import { buildSchedulesRoute } from "../src/utils/host-routes"; interface ScheduleSeedClient { scheduleCreate(input: { prompt: string; name?: string; cadence: { type: "cron"; expression: string }; target: { type: "new-agent"; config: { provider: "mock"; cwd: string; model: string; modeId: string; title: string; }; }; runOnCreate: boolean; }): Promise<{ schedule: { id: string } | null; error: string | null }>; scheduleDelete(input: { id: string }): Promise<{ error: string | null }>; } async function seedMockSchedule(workspace: SeededWorkspace, name: string): Promise { const client = workspace.client as unknown as ScheduleSeedClient; const result = await client.scheduleCreate({ prompt: "Say hello from the scheduled agent.", name, cadence: { type: "cron", expression: "0 9 * * *" }, target: { type: "new-agent", config: { provider: "mock", cwd: workspace.repoPath, model: "ten-second-stream", modeId: "load-test", title: name, }, }, runOnCreate: false, }); if (!result.schedule) { throw new Error(result.error ?? "Failed to seed schedule"); } return result.schedule.id; } function ignoreScheduleDeleteError(): void {} async function deleteSeededSchedule(workspace: SeededWorkspace, id: string): Promise { await (workspace.client as unknown as ScheduleSeedClient) .scheduleDelete({ id }) .catch(ignoreScheduleDeleteError); } test.describe("Schedules", () => { const cleanupTasks: Array<() => Promise> = []; test.afterEach(async () => { for (const cleanup of cleanupTasks.toReversed()) { await cleanup(); } cleanupTasks.length = 0; }); test("edit form hydrates the scheduled model selection", async ({ page }) => { const workspace = await seedWorkspace({ repoPrefix: "schedule-model-hydration-" }); cleanupTasks.push(() => workspace.cleanup()); const scheduleName = `Hydrate model ${Date.now()}`; const scheduleId = await seedMockSchedule(workspace, scheduleName); cleanupTasks.push(() => deleteSeededSchedule(workspace, scheduleId)); await page.goto(buildSchedulesRoute()); const row = page.getByTestId(`schedule-row-${scheduleId}`); await expect(row).toBeVisible({ timeout: 30_000 }); await expect(row).toContainText(workspace.projectDisplayName, { timeout: 30_000 }); await row.click(); await expect(page.getByTestId("schedule-form-sheet")).toBeVisible({ timeout: 10_000 }); await expect(page.getByTestId("schedule-cwd-trigger")).toHaveCount(0); await expect(page.getByTestId("schedule-project-trigger")).toContainText( workspace.projectDisplayName, { timeout: 30_000 }, ); await expect(page.getByTestId("schedule-model-trigger")).toContainText("Ten second stream", { timeout: 30_000, }); }); });