Files
opencode/packages/app/e2e/regression/session-timeline-tool-projection.spec.ts

95 lines
3.9 KiB
TypeScript

import { expect, test } from "@playwright/test"
import { timelinePresets } from "@opencode/session-ui/timeline/detail"
import { assistantMessage, partUpdated, setupTimeline, textPart, toolPart, userMessage } from "../utils/timeline"
test("keeps shell and question failures in their Used group", async ({ page }) => {
const shellID = "prt_transition_error_shell"
const questionID = "prt_transition_error_question"
const timeline = await setupTimeline(page, {
settings: { timelineDetail: timelinePresets[2].value },
messages: [
userMessage(),
assistantMessage(
[
toolPart(shellID, "shell", "streaming", { command: "exit 1" }),
toolPart(questionID, "question", "streaming", questionInput()),
],
{ completed: false },
),
],
})
const group = page.locator('[data-component="collapsed-tool-group"]')
const used = group.locator(':scope > [data-component="collapsible"] > [data-slot="collapsible-trigger"]')
await used.click()
await expect(page.locator(`[data-timeline-part-id="${questionID}"]`)).toHaveCount(0)
await timeline.send(partUpdated(toolPart(shellID, "shell", "running", { command: "exit 1" })))
await expect(page.locator(`[data-timeline-part-id="${shellID}"]`)).toContainText("exit 1")
await timeline.send(partUpdated(toolPart(questionID, "question", "running", questionInput())))
await expect(page.locator(`[data-timeline-part-id="${questionID}"]`)).toHaveCount(0)
await timeline.send(
partUpdated(
toolPart(
shellID,
"shell",
"completed",
{ command: "exit 1" },
{ output: "Command exited 1", metadata: { exit: 1 } },
),
),
)
await timeline.send(
partUpdated(
toolPart(questionID, "question", "error", questionInput(), { error: "The user dismissed this question" }),
),
)
await expect(group).toHaveAttribute("data-timeline-part-ids", `${shellID},${questionID}`)
await expect(used).toHaveAttribute("aria-expanded", "true")
const shell = group.locator(`[data-timeline-part-id="${shellID}"]`)
await expect(shell.locator('[data-slot="collapsible-trigger"]')).toHaveAttribute("aria-expanded", "false")
await shell.locator('[data-slot="collapsible-trigger"]').click()
await expect(shell).toContainText("Command exited 1")
const question = group.locator(`[data-timeline-part-id="${questionID}"]`)
await expect(question).toContainText(/dismissed/i)
})
test("keeps rendering when a plugin tool reports progress metadata that is not an object", async ({ page }) => {
const toolID = "prt_plugin_progress"
const input = { prompt: "a cat" }
const timeline = await setupTimeline(page, {
messages: [
userMessage(),
assistantMessage([toolPart(toolID, "plugin_imagegen", "running", input)], { completed: false }),
],
})
await page
.locator(
'[data-component="collapsed-tool-group"] > [data-component="collapsible"] > [data-slot="collapsible-trigger"]',
)
.click()
await timeline.waitForPart(toolID)
const progress = partUpdated(
toolPart(toolID, "plugin_imagegen", "running", input, { metadata: { status: "x" } }),
).find((event) => event.type === "session.tool.progress")!
// Plugin tools are untyped at runtime, and the server forwards progress metadata as sent, so the
// frame is written raw to skip the harness's event validation.
await timeline.transport.writeRaw(
`data: ${JSON.stringify({ ...progress, data: { ...progress.data, metadata: "polling" } })}\n\n`,
)
await timeline.send(partUpdated(textPart("prt_plugin_progress_text", "Still polling the image task.")))
await expect(page.getByText("Still polling the image task.")).toBeVisible()
await expect(page.locator(`[data-timeline-part-id="${toolID}"]`)).toBeVisible()
await expect(page.getByRole("heading", { name: "Something went wrong" })).toHaveCount(0)
})
function questionInput() {
return { questions: [{ header: "Stability", question: "Keep it stable?", options: [] }] }
}