|
| 1 | +import type { AutomationInfo } from "@opencode/client/promise" |
| 2 | +import { expect, test } from "@playwright/test" |
| 3 | +import { project, provider, REMOTE_SERVER, seed, SERVER, sessionHref } from "../utils/app" |
| 4 | +import { mockServers } from "../utils/mock-server" |
| 5 | +import { mockWorkspace } from "../utils/workspace" |
| 6 | + |
| 7 | +test("inspects event and timer automations and manages the selected row", async ({ page }) => { |
| 8 | + await page.setViewportSize({ width: 1440, height: 900 }) |
| 9 | + const directory = "C:/OpenCode/Atlas" |
| 10 | + const now = Date.UTC(2026, 10, 17, 9, 10) |
| 11 | + |
| 12 | + const base = { |
| 13 | + projectID: "proj_atlas", |
| 14 | + directory: `${directory}/release`, |
| 15 | + tz: "UTC", |
| 16 | + sessionID: "ses_release", |
| 17 | + status: "active", |
| 18 | + runCount: 3, |
| 19 | + time: { created: now, updated: now }, |
| 20 | + } as const |
| 21 | + |
| 22 | + const automations: AutomationInfo[] = [ |
| 23 | + { |
| 24 | + ...base, |
| 25 | + id: "aut_deploy", |
| 26 | + name: "Release health watch", |
| 27 | + trigger: { type: "event", server: "deployments", event: "deployment.finished", args: { environment: "staging" } }, |
| 28 | + action: { |
| 29 | + type: "code", |
| 30 | + code: 'console.log(`Deployment status: ${event.data.status}`)\nif (event.data.status === "failed")\n return { send: { prompt: "Review the failed deployment." } }', |
| 31 | + }, |
| 32 | + lastRunAt: now, |
| 33 | + lastOutcome: "fired", |
| 34 | + lastOutput: "Deployment status: succeeded", |
| 35 | + }, |
| 36 | + { |
| 37 | + ...base, |
| 38 | + id: "aut_brief", |
| 39 | + name: "Morning release brief", |
| 40 | + trigger: { type: "cron", cron: "0 9 * * 1-5" }, |
| 41 | + action: { type: "prompt", prompt: "Summarize release activity since yesterday.", to: { session: "ses_brief" } }, |
| 42 | + nextDueAt: now + 86_400_000, |
| 43 | + }, |
| 44 | + { |
| 45 | + ...base, |
| 46 | + id: "aut_smoke", |
| 47 | + name: "Nightly smoke test", |
| 48 | + trigger: { type: "cron", cron: "0 2 * * *" }, |
| 49 | + action: { type: "shell", command: "bun run test:smoke --reporter=dot" }, |
| 50 | + nextDueAt: now + 2 * 86_400_000, |
| 51 | + lastRunAt: now, |
| 52 | + lastOutcome: "fired", |
| 53 | + lastOutput: "Exit code: 0\n42 pass, 0 fail", |
| 54 | + }, |
| 55 | + { |
| 56 | + ...base, |
| 57 | + id: "aut_docs", |
| 58 | + name: "Documentation review", |
| 59 | + status: "paused", |
| 60 | + trigger: { type: "every", every: "1 day" }, |
| 61 | + action: { type: "prompt", prompt: "Review the documentation changes.", to: { subagent: "reviewer" } }, |
| 62 | + }, |
| 63 | + ] |
| 64 | + |
| 65 | + await mockWorkspace(page, { |
| 66 | + name: "Atlas", |
| 67 | + directory, |
| 68 | + project: { name: "Atlas (sample)" }, |
| 69 | + hostname: "release-runner-03", |
| 70 | + commands: [{ name: "automation" }], |
| 71 | + sessions: [ |
| 72 | + { id: "ses_release", title: "Release planning" }, |
| 73 | + { id: "ses_brief", title: "Release notes" }, |
| 74 | + ], |
| 75 | + automations, |
| 76 | + seed: { |
| 77 | + theme: { id: "oc-2", scheme: "dark" }, |
| 78 | + settings: { general: { automations: true }, appearance: { tabLayout: "vertical", sidebarOpen: true } }, |
| 79 | + }, |
| 80 | + }) |
| 81 | + await page.goto(sessionHref("ses_release")) |
| 82 | + const nav = page.getByRole("button", { name: "Automations", exact: true }) |
| 83 | + await nav.click() |
| 84 | + await expect(page.getByRole("button", { name: /Morning release brief/ })).toContainText("Weekdays at 9:00 AM") |
| 85 | + const detail = page.getByRole("article") |
| 86 | + await page.getByRole("button", { name: /Release health watch/ }).click() |
| 87 | + await expect(detail.getByRole("heading", { name: "Release health watch" })).toBeVisible() |
| 88 | + await expect(detail.getByText("deployment.finished from deployments", { exact: true })).toBeVisible() |
| 89 | + await expect( |
| 90 | + detail |
| 91 | + .getByRole("term") |
| 92 | + .filter({ hasText: /^Runs on$/ }) |
| 93 | + .locator("+ dd"), |
| 94 | + ).toHaveText("release-runner-03") |
| 95 | + await expect(detail.getByText('environment = "staging"', { exact: true })).toBeVisible() |
| 96 | + await expect(detail.getByText("Next run")).toHaveCount(0) |
| 97 | + await expect( |
| 98 | + detail.getByText("Wakes the creating session only when the code returns send", { exact: false }), |
| 99 | + ).toBeVisible() |
| 100 | + await expect(detail.getByText(`${directory}/release`, { exact: true })).toBeVisible() |
| 101 | + await expect(detail.getByText("Deployment status: succeeded", { exact: true })).toBeVisible() |
| 102 | + await page.screenshot({ path: test.info().outputPath("automation-inspector.png"), animations: "disabled" }) |
| 103 | + await detail.getByRole("button", { name: "Pause", exact: true }).click() |
| 104 | + await expect(nav).toContainText("2") |
| 105 | + await detail.getByRole("button", { name: "Resume", exact: true }).click() |
| 106 | + await expect(nav).toContainText("3") |
| 107 | + await detail.getByRole("button", { name: "Delete", exact: true }).click() |
| 108 | + await page.getByRole("dialog").getByRole("button", { name: "Delete", exact: true }).click() |
| 109 | + await expect(page.getByRole("button", { name: /Release health watch/ })).toHaveCount(0) |
| 110 | + await expect(detail.getByText("Next run")).toBeVisible() |
| 111 | + await expect(detail.getByRole("button", { name: "Release planning" })).toBeVisible() |
| 112 | + await expect(detail.getByRole("button", { name: "Release notes" })).toBeVisible() |
| 113 | + await page.getByRole("button", { name: /Nightly smoke test/ }).click() |
| 114 | + await expect(detail.getByText("bun run test:smoke --reporter=dot", { exact: true })).toBeVisible() |
| 115 | + await expect(detail.getByText("Doesn’t wake a session", { exact: false })).toBeVisible() |
| 116 | + await page.getByRole("button", { name: /Documentation review/ }).click() |
| 117 | + await expect(detail.getByText("Send a prompt to a new reviewer subagent")).toBeVisible() |
| 118 | + await page.getByRole("button", { name: "New automation" }).click() |
| 119 | + await expect(page.locator('[data-component="composer-editor"]')).toHaveText(/\/automation/) |
| 120 | +}) |
| 121 | + |
| 122 | +test("hides every automation entry point while the experimental setting is off", async ({ page }) => { |
| 123 | + await mockWorkspace(page, { name: "Off", commands: [{ name: "automation" }] }) |
| 124 | + await page.goto("/automations") |
| 125 | + await expect(page.getByText("Turn on Automations in Settings → Experimental.")).toBeVisible() |
| 126 | + await expect(page.getByRole("button", { name: "Automations", exact: true })).toHaveCount(0) |
| 127 | + await expect(page.getByRole("button", { name: "New automation" })).toHaveCount(0) |
| 128 | +}) |
| 129 | + |
| 130 | +test("keeps the entry for an empty server and withdraws New automation when the server removes its command", async ({ |
| 131 | + page, |
| 132 | +}) => { |
| 133 | + let enabled = true |
| 134 | + |
| 135 | + const { push, directory } = await mockWorkspace(page, { |
| 136 | + name: "Empty", |
| 137 | + commands: () => (enabled ? [{ name: "automation" }] : []), |
| 138 | + seed: { settings: { general: { automations: true } } }, |
| 139 | + }) |
| 140 | + |
| 141 | + await page.goto("/automations") |
| 142 | + await expect(page.getByRole("heading", { name: "No automations yet" })).toBeVisible() |
| 143 | + enabled = false |
| 144 | + await push([ |
| 145 | + { id: "evt_automation_disabled", created: 1, type: "command.updated", location: { directory }, data: {} }, |
| 146 | + ]) |
| 147 | + await expect(page.getByRole("button", { name: "New automation" })).toHaveCount(0) |
| 148 | + await expect(page.getByRole("heading", { name: "No automations yet" })).toBeVisible() |
| 149 | + await expect(page.getByRole("button", { name: "Automations", exact: true })).toBeVisible() |
| 150 | +}) |
| 151 | + |
| 152 | +test("manages a watch outside open locations and opens the recipient instead of its last viewed child", async ({ |
| 153 | + page, |
| 154 | +}) => { |
| 155 | + const directory = "/projects/repo" |
| 156 | + const docs = `${directory}/docs` |
| 157 | + await mockWorkspace(page, { |
| 158 | + name: "Repo", |
| 159 | + directory, |
| 160 | + commands: (dir) => (dir === docs ? [{ name: "automation" }] : []), |
| 161 | + automations: [ |
| 162 | + { |
| 163 | + id: "aut_docs", |
| 164 | + projectID: "proj_repo", |
| 165 | + directory: docs, |
| 166 | + name: "Review docs", |
| 167 | + tz: "UTC", |
| 168 | + trigger: { type: "every", every: "1 day" }, |
| 169 | + action: { type: "prompt", prompt: "Review new documentation.", to: { session: "ses_parent" } }, |
| 170 | + status: "active", |
| 171 | + runCount: 0, |
| 172 | + time: { created: 1, updated: 1 }, |
| 173 | + }, |
| 174 | + ], |
| 175 | + sessions: [ |
| 176 | + { id: "ses_parent", title: "Docs planning" }, |
| 177 | + { id: "ses_child", title: "Research notes", parentID: "ses_parent" }, |
| 178 | + ], |
| 179 | + seed: { |
| 180 | + settings: { general: { automations: true } }, |
| 181 | + storage: { |
| 182 | + "opencode.window.browser.dat:tabs": [ |
| 183 | + { |
| 184 | + type: "session", |
| 185 | + sessionId: "ses_parent", |
| 186 | + server: SERVER, |
| 187 | + routeSessionId: "ses_child", |
| 188 | + routeParentId: "ses_parent", |
| 189 | + }, |
| 190 | + ], |
| 191 | + }, |
| 192 | + }, |
| 193 | + }) |
| 194 | + await page.goto(sessionHref("ses_child")) |
| 195 | + await expect(page.getByRole("heading", { name: "Research notes", exact: true })).toBeVisible() |
| 196 | + await page.getByRole("button", { name: "Automations", exact: true }).click() |
| 197 | + const detail = page.getByRole("article") |
| 198 | + await expect(detail.getByRole("heading", { name: "Review docs" })).toBeVisible() |
| 199 | + await expect(detail.getByText(docs, { exact: true })).toBeVisible() |
| 200 | + await expect(page.getByRole("button", { name: "New automation" })).toBeVisible() |
| 201 | + await detail.getByRole("button", { name: /Docs planning|ses_parent/ }).click() |
| 202 | + await expect(page).toHaveURL(sessionHref("ses_parent")) |
| 203 | + await expect(page.locator('[data-component="composer-editor"]')).toBeEditable() |
| 204 | +}) |
| 205 | + |
| 206 | +test("keeps identically keyed automations on separate servers and starts the draft in the row’s saved directory", async ({ |
| 207 | + page, |
| 208 | +}) => { |
| 209 | + const servers = [SERVER, REMOTE_SERVER] as const |
| 210 | + const creates: unknown[] = [] |
| 211 | + const commands: unknown[] = [] |
| 212 | + await mockServers( |
| 213 | + page, |
| 214 | + Object.fromEntries( |
| 215 | + servers.map((server) => { |
| 216 | + const name = server === SERVER ? "Local" : "Remote" |
| 217 | + const directory = `/projects/${name.toLowerCase()}` |
| 218 | + |
| 219 | + const row: AutomationInfo = { |
| 220 | + id: "aut_brief", |
| 221 | + name: `${name} brief`, |
| 222 | + projectID: "proj_shared", |
| 223 | + directory: `${directory}/worktrees/docs`, |
| 224 | + status: "active", |
| 225 | + runCount: 0, |
| 226 | + trigger: { type: "at", at: "2027-01-04T09:00" }, |
| 227 | + tz: "UTC", |
| 228 | + action: { type: "prompt", prompt: "Review the release notes.", to: { session: "ses_notes" } }, |
| 229 | + time: { created: 1, updated: 1 }, |
| 230 | + } |
| 231 | + |
| 232 | + return [ |
| 233 | + server, |
| 234 | + { |
| 235 | + directory, |
| 236 | + project: project({ id: row.projectID, directory, name: `${name} project` }), |
| 237 | + provider: provider(), |
| 238 | + pageMessages: () => ({ items: [] }), |
| 239 | + onSessionCreate: (body: { location?: unknown }) => void creates.push({ server, location: body.location }), |
| 240 | + onCommand: (input: { body: unknown }) => void commands.push({ server, body: input.body }), |
| 241 | + sessions: [], |
| 242 | + commands: [{ name: "automation" }], |
| 243 | + automations: [row], |
| 244 | + }, |
| 245 | + ] |
| 246 | + }), |
| 247 | + ), |
| 248 | + ) |
| 249 | + await seed(page, { |
| 250 | + settings: { general: { automations: true } }, |
| 251 | + servers: [REMOTE_SERVER], |
| 252 | + usedProjects: { local: ["proj_shared"], [REMOTE_SERVER]: ["proj_shared"] }, |
| 253 | + }) |
| 254 | + await page.goto("/automations") |
| 255 | + await page.getByRole("button", { name: /Remote brief/ }).click() |
| 256 | + const detail = page.getByRole("article") |
| 257 | + await expect(detail.getByText("Remote project", { exact: true })).toBeVisible() |
| 258 | + await expect(detail.getByText("Created by")).toHaveCount(0) |
| 259 | + await expect(detail.getByRole("button", { name: "ses_notes" })).toBeVisible() |
| 260 | + const directory = "/projects/remote/worktrees/docs" |
| 261 | + await expect(detail.getByText(directory, { exact: true })).toBeVisible() |
| 262 | + await page.getByRole("button", { name: "New automation" }).click() |
| 263 | + const editor = page.locator('[data-component="composer-editor"]') |
| 264 | + await expect(editor).toHaveText(/\/automation/) |
| 265 | + await editor.fill("/automation Review the release notes on Friday") |
| 266 | + await editor.press("Enter") |
| 267 | + await expect.poll(() => creates).toEqual([{ server: REMOTE_SERVER, location: { directory } }]) |
| 268 | + await expect |
| 269 | + .poll(() => commands) |
| 270 | + .toMatchObject([ |
| 271 | + { server: REMOTE_SERVER, body: { name: "automation", text: "Review the release notes on Friday" } }, |
| 272 | + ]) |
| 273 | +}) |
0 commit comments