+21







![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)
![opencode-agent[bot]](/assets/img/avatar_default.png)
opencode-agent[bot]
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Aiden Cline
usrnk1
Aarav Sareen
Luke Parker
Brendan Allan
Kit Langton
James Long
Adam
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Jay
Simon Klee
Jay
Jack
David Hill
Brendan Allan
opencode
Aiden Cline
James Long
Dustin Deus
冯基魁
Frank
Aiden Cline
Victor Navarro
Dax Raad
Dax
Nabs
Vladimir Glafirov
AidenGeunGeun
Mark
634386fe0f
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: James Long <jlongster@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: 冯基魁 <56265583+fengjikui@users.noreply.github.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: Victor Navarro <vn4varro@gmail.com> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Nabs <nabil@instafork.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: AidenGeunGeun <eastlandwyvern@gmail.com> Co-authored-by: Mark <geraint0923@users.noreply.github.com>
218 lines
7.9 KiB
TypeScript
218 lines
7.9 KiB
TypeScript
import { base64Encode } from "@opencode-ai/core/util/encode"
|
|
import { expect, test, type Page } from "@playwright/test"
|
|
import { mockOpenCodeServer } from "../utils/mock-server"
|
|
import { installSseTransport } from "../utils/sse-transport"
|
|
import { expectSessionTitle } from "../utils/waits"
|
|
|
|
const directory = "C:/OpenCode/RequestDocks"
|
|
const projectID = "proj_request_docks"
|
|
const sessionID = "ses_request_docks"
|
|
const title = "Request dock regression"
|
|
|
|
test("shows a pending question dock", async ({ page }) => {
|
|
await mockServer(page, {
|
|
questions: [
|
|
{
|
|
id: "question-request",
|
|
sessionID,
|
|
questions: [
|
|
{
|
|
header: "Implementation",
|
|
question: "Which implementation should be used?",
|
|
options: [
|
|
{ label: "Minimal", description: "Use the smallest correct change" },
|
|
{ label: "Extended", description: "Include additional behavior" },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
|
|
await page.goto(`/${base64Encode(directory)}/session/${sessionID}`)
|
|
await expectSessionTitle(page, title)
|
|
|
|
const question = page.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
await expect(question).toBeVisible()
|
|
await expect(question.getByText("Which implementation should be used?")).toBeVisible()
|
|
await expect(question.getByRole("radio", { name: /Minimal/ })).toBeVisible()
|
|
await expect(question.getByRole("radio", { name: /Extended/ })).toBeVisible()
|
|
await expect(page.locator('[data-component="session-composer"]')).toHaveCount(0)
|
|
|
|
const rejectRequests: string[] = []
|
|
page.on("request", (request) => {
|
|
if (request.method() !== "POST") return
|
|
if (new URL(request.url()).pathname === "/question/question-request/reject") rejectRequests.push(request.url())
|
|
})
|
|
|
|
await question.locator('[data-component="icon-button"][data-icon="chevron-down"]').click()
|
|
await expect(question).toBeVisible()
|
|
await expect(question.getByText("Which implementation should be used?")).toBeVisible()
|
|
await expect(question.getByText("Select one answer")).toBeHidden()
|
|
await expect(question.getByRole("radio", { name: /Minimal/ })).toBeHidden()
|
|
await expect(question.getByRole("radio", { name: /Extended/ })).toBeHidden()
|
|
await expect(question.getByRole("button", { name: "Dismiss" })).toBeVisible()
|
|
await expect(question.getByRole("button", { name: "Submit" })).toBeVisible()
|
|
await expect(page.locator('[data-component="question-minimized-dock"]')).toHaveCount(0)
|
|
expect(rejectRequests).toEqual([])
|
|
|
|
await question.locator('[data-component="icon-button"][data-icon="chevron-down"]').click()
|
|
await expect(question).toBeVisible()
|
|
await expect(question.getByText("Which implementation should be used?")).toBeVisible()
|
|
await expect(question.getByRole("radio", { name: /Minimal/ })).toBeVisible()
|
|
expect(rejectRequests).toEqual([])
|
|
|
|
await question.getByRole("radio", { name: /Minimal/ }).click()
|
|
const reply = page.waitForRequest(
|
|
(request) => request.method() === "POST" && new URL(request.url()).pathname === "/question/question-request/reply",
|
|
)
|
|
await question.getByRole("button", { name: "Submit" }).click()
|
|
expect((await reply).postDataJSON()).toEqual({ answers: [["Minimal"]] })
|
|
})
|
|
|
|
test("shows a pending permission dock", async ({ page }) => {
|
|
await mockServer(page, {
|
|
permissions: [
|
|
{
|
|
id: "permission-request",
|
|
sessionID,
|
|
permission: "bash",
|
|
patterns: ["git status", "git diff"],
|
|
metadata: {},
|
|
always: [],
|
|
},
|
|
],
|
|
})
|
|
|
|
await page.goto(`/${base64Encode(directory)}/session/${sessionID}`)
|
|
await expectSessionTitle(page, title)
|
|
|
|
const permission = page.locator('[data-component="dock-prompt"][data-kind="permission"]')
|
|
await expect(permission).toBeVisible()
|
|
await expect(permission.getByText("git status")).toBeVisible()
|
|
await expect(permission.getByText("git diff")).toBeVisible()
|
|
await expect(permission.locator('[data-slot="permission-footer-actions"] button')).toHaveCount(3)
|
|
await expect(page.locator('[data-component="session-composer"]')).toHaveCount(0)
|
|
|
|
const reply = page.waitForRequest((request) => request.method() === "POST")
|
|
await permission.getByRole("button", { name: "Allow once" }).click()
|
|
const request = await reply
|
|
expect(new URL(request.url()).pathname).toBe(`/session/${sessionID}/permissions/permission-request`)
|
|
expect(request.postDataJSON()).toEqual({ response: "once" })
|
|
})
|
|
|
|
test("restores the draft caret before typing after a request dock closes", async ({ page }) => {
|
|
const transport = await installSseTransport(page, {
|
|
server: `http://${process.env.PLAYWRIGHT_SERVER_HOST ?? "127.0.0.1"}:${process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"}`,
|
|
retry: 20,
|
|
})
|
|
await mockServer(page, { questions: [] })
|
|
await page.goto(`/${base64Encode(directory)}/session/${sessionID}`)
|
|
await transport.waitForConnection()
|
|
await expectSessionTitle(page, title)
|
|
|
|
const editor = page.locator('[data-component="prompt-input"][contenteditable="true"]')
|
|
const draft = "keep the caret at the end"
|
|
await editor.fill(draft)
|
|
await page.evaluate(() => new Promise<void>((resolve) => requestAnimationFrame(() => resolve())))
|
|
for (let index = 0; index < 4; index++) await page.keyboard.press("ArrowLeft")
|
|
const cursor = draft.length - 4
|
|
await expect
|
|
.poll(() =>
|
|
editor.evaluate((element) => {
|
|
const selection = window.getSelection()
|
|
if (!selection?.rangeCount || !element.contains(selection.anchorNode)) return -1
|
|
const range = selection.getRangeAt(0).cloneRange()
|
|
range.selectNodeContents(element)
|
|
range.setEnd(selection.anchorNode!, selection.anchorOffset)
|
|
return range.toString().length
|
|
}),
|
|
)
|
|
.toBe(cursor)
|
|
await transport.send({
|
|
directory,
|
|
payload: {
|
|
type: "question.asked",
|
|
properties: {
|
|
id: "question-caret",
|
|
sessionID,
|
|
questions: [
|
|
{
|
|
header: "Continue",
|
|
question: "Continue?",
|
|
options: [{ label: "Yes", description: "Continue the session" }],
|
|
},
|
|
],
|
|
tool: { messageID: "message-caret", callID: "call-caret" },
|
|
},
|
|
},
|
|
})
|
|
const question = page.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
await expect(question).toBeVisible()
|
|
await expect(editor).toHaveCount(0)
|
|
|
|
await transport.send({
|
|
directory,
|
|
payload: { type: "question.rejected", properties: { sessionID, requestID: "question-caret" } },
|
|
})
|
|
await expect(question).toHaveCount(0)
|
|
await expect(editor).toBeVisible()
|
|
await page.keyboard.press("x")
|
|
|
|
await expect(editor).toHaveText(`${draft.slice(0, cursor)}x${draft.slice(cursor)}`)
|
|
})
|
|
|
|
async function mockServer(
|
|
page: Page,
|
|
requests: {
|
|
permissions?: unknown[] | (() => unknown[])
|
|
questions?: unknown[] | (() => unknown[])
|
|
},
|
|
) {
|
|
await mockOpenCodeServer(page, {
|
|
directory,
|
|
project: {
|
|
id: projectID,
|
|
worktree: directory,
|
|
vcs: "git",
|
|
name: "request-docks",
|
|
time: { created: 1700000000000, updated: 1700000000000 },
|
|
sandboxes: [],
|
|
},
|
|
provider: {
|
|
all: [
|
|
{
|
|
id: "opencode",
|
|
name: "OpenCode",
|
|
models: {
|
|
"claude-opus-4-6": {
|
|
id: "claude-opus-4-6",
|
|
name: "Claude Opus 4.6",
|
|
limit: { context: 200_000 },
|
|
},
|
|
},
|
|
},
|
|
],
|
|
connected: ["opencode"],
|
|
default: { providerID: "opencode", modelID: "claude-opus-4-6" },
|
|
},
|
|
sessions: [
|
|
{
|
|
id: sessionID,
|
|
slug: "request-docks",
|
|
projectID,
|
|
directory,
|
|
title,
|
|
version: "dev",
|
|
time: { created: 1700000000000, updated: 1700000000000 },
|
|
},
|
|
],
|
|
pageMessages: () => ({ items: [] }),
|
|
permissions: requests.permissions,
|
|
questions: requests.questions,
|
|
})
|
|
await page.addInitScript(() => {
|
|
localStorage.setItem("settings.v3", JSON.stringify({ general: { newLayoutDesigns: true } }))
|
|
})
|
|
}
|