diff options
| author | Kit Langton <[email protected]> | 2026-04-01 13:43:19 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-01 17:43:19 +0000 |
| commit | f3f728ec27b2b2fc67470a2acec0072a5f1badd0 (patch) | |
| tree | d8d36b7721d3e48965cc6fd84587fc533a0349b5 /packages/app/e2e/session | |
| parent | c619caefdd1d184cae549749240c5f77f63b150a (diff) | |
| download | opencode-f3f728ec27b2b2fc67470a2acec0072a5f1badd0.tar.gz opencode-f3f728ec27b2b2fc67470a2acec0072a5f1badd0.zip | |
test(app): fix isolated backend follow-ups (#20513)
Diffstat (limited to 'packages/app/e2e/session')
4 files changed, 352 insertions, 287 deletions
diff --git a/packages/app/e2e/session/session-child-navigation.spec.ts b/packages/app/e2e/session/session-child-navigation.spec.ts index 616f694a3..fa366e515 100644 --- a/packages/app/e2e/session/session-child-navigation.spec.ts +++ b/packages/app/e2e/session/session-child-navigation.spec.ts @@ -1,5 +1,6 @@ import { seedSessionTask, withSession } from "../actions" import { test, expect } from "../fixtures" +import { promptSelector } from "../selectors" test("task tool child-session link does not trigger stale show errors", async ({ page, withBackendProject }) => { test.setTimeout(120_000) @@ -10,17 +11,16 @@ test("task tool child-session link does not trigger stale show errors", async ({ } page.on("pageerror", onError) - await withBackendProject(async ({ gotoSession, trackSession, sdk }) => { - await withSession(sdk, `e2e child nav ${Date.now()}`, async (session) => { - trackSession(session.id) - const child = await seedSessionTask(sdk, { - sessionID: session.id, - description: "Open child session", - prompt: "Search the repository for AssistantParts and then reply with exactly CHILD_OK.", - }) - trackSession(child.sessionID) + try { + await withBackendProject(async ({ gotoSession, trackSession, sdk }) => { + await withSession(sdk, `e2e child nav ${Date.now()}`, async (session) => { + const child = await seedSessionTask(sdk, { + sessionID: session.id, + description: "Open child session", + prompt: "Search the repository for AssistantParts and then reply with exactly CHILD_OK.", + }) + trackSession(child.sessionID) - try { await gotoSession(session.id) const link = page @@ -31,11 +31,11 @@ test("task tool child-session link does not trigger stale show errors", async ({ await link.click() await expect(page).toHaveURL(new RegExp(`/session/${child.sessionID}(?:[/?#]|$)`), { timeout: 30_000 }) - await page.waitForTimeout(1000) - expect(errs).toEqual([]) - } finally { - page.off("pageerror", onError) - } + await expect(page.locator(promptSelector)).toBeVisible({ timeout: 30_000 }) + await expect.poll(() => errs, { timeout: 5_000 }).toEqual([]) + }) }) - }) + } finally { + page.off("pageerror", onError) + } }) diff --git a/packages/app/e2e/session/session-composer-dock.spec.ts b/packages/app/e2e/session/session-composer-dock.spec.ts index 9d44683c8..2c87a309d 100644 --- a/packages/app/e2e/session/session-composer-dock.spec.ts +++ b/packages/app/e2e/session/session-composer-dock.spec.ts @@ -22,12 +22,13 @@ async function withDockSession<T>( sdk: Sdk, title: string, fn: (session: { id: string; title: string }) => Promise<T>, - opts?: { permission?: PermissionRule[] }, + opts?: { permission?: PermissionRule[]; trackSession?: (sessionID: string) => void }, ) { const session = await sdk.session .create(opts?.permission ? { title, permission: opts.permission } : { title }) .then((r) => r.data) if (!session?.id) throw new Error("Session create did not return an id") + opts?.trackSession?.(session.id) try { return await fn(session) } finally { @@ -258,17 +259,22 @@ async function withMockPermission<T>( test("default dock shows prompt input", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock default", async (session) => { - await project.gotoSession(session.id) + await withDockSession( + project.sdk, + "e2e composer dock default", + async (session) => { + await project.gotoSession(session.id) - await expect(page.locator(sessionComposerDockSelector)).toBeVisible() - await expect(page.locator(promptSelector)).toBeVisible() - await expect(page.locator(questionDockSelector)).toHaveCount(0) - await expect(page.locator(permissionDockSelector)).toHaveCount(0) + await expect(page.locator(sessionComposerDockSelector)).toBeVisible() + await expect(page.locator(promptSelector)).toBeVisible() + await expect(page.locator(questionDockSelector)).toHaveCount(0) + await expect(page.locator(permissionDockSelector)).toHaveCount(0) - await page.locator(promptSelector).click() - await expect(page.locator(promptSelector)).toBeFocused() - }) + await page.locator(promptSelector).click() + await expect(page.locator(promptSelector)).toBeFocused() + }, + { trackSession: project.trackSession }, + ) }) }) @@ -287,190 +293,220 @@ test("auto-accept toggle works before first submit", async ({ page, withBackendP test("blocked question flow unblocks after submit", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock question", async (session) => { - await withDockSeed(project.sdk, session.id, async () => { - await project.gotoSession(session.id) + await withDockSession( + project.sdk, + "e2e composer dock question", + async (session) => { + await withDockSeed(project.sdk, session.id, async () => { + await project.gotoSession(session.id) - await seedSessionQuestion(project.sdk, { - sessionID: session.id, - questions: [ - { - header: "Need input", - question: "Pick one option", - options: [ - { label: "Continue", description: "Continue now" }, - { label: "Stop", description: "Stop here" }, - ], - }, - ], - }) + await seedSessionQuestion(project.sdk, { + sessionID: session.id, + questions: [ + { + header: "Need input", + question: "Pick one option", + options: [ + { label: "Continue", description: "Continue now" }, + { label: "Stop", description: "Stop here" }, + ], + }, + ], + }) - const dock = page.locator(questionDockSelector) - await expectQuestionBlocked(page) + const dock = page.locator(questionDockSelector) + await expectQuestionBlocked(page) - await dock.locator('[data-slot="question-option"]').first().click() - await dock.getByRole("button", { name: /submit/i }).click() + await dock.locator('[data-slot="question-option"]').first().click() + await dock.getByRole("button", { name: /submit/i }).click() - await expectQuestionOpen(page) - }) - }) + await expectQuestionOpen(page) + }) + }, + { trackSession: project.trackSession }, + ) }) }) test("blocked question flow supports keyboard shortcuts", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock question keyboard", async (session) => { - await withDockSeed(project.sdk, session.id, async () => { - await project.gotoSession(session.id) + await withDockSession( + project.sdk, + "e2e composer dock question keyboard", + async (session) => { + await withDockSeed(project.sdk, session.id, async () => { + await project.gotoSession(session.id) - await seedSessionQuestion(project.sdk, { - sessionID: session.id, - questions: [ - { - header: "Need input", - question: "Pick one option", - options: [ - { label: "Continue", description: "Continue now" }, - { label: "Stop", description: "Stop here" }, - ], - }, - ], - }) + await seedSessionQuestion(project.sdk, { + sessionID: session.id, + questions: [ + { + header: "Need input", + question: "Pick one option", + options: [ + { label: "Continue", description: "Continue now" }, + { label: "Stop", description: "Stop here" }, + ], + }, + ], + }) - const dock = page.locator(questionDockSelector) - const first = dock.locator('[data-slot="question-option"]').first() - const second = dock.locator('[data-slot="question-option"]').nth(1) + const dock = page.locator(questionDockSelector) + const first = dock.locator('[data-slot="question-option"]').first() + const second = dock.locator('[data-slot="question-option"]').nth(1) - await expectQuestionBlocked(page) - await expect(first).toBeFocused() + await expectQuestionBlocked(page) + await expect(first).toBeFocused() - await page.keyboard.press("ArrowDown") - await expect(second).toBeFocused() + await page.keyboard.press("ArrowDown") + await expect(second).toBeFocused() - await page.keyboard.press("Space") - await page.keyboard.press(`${modKey}+Enter`) - await expectQuestionOpen(page) - }) - }) + await page.keyboard.press("Space") + await page.keyboard.press(`${modKey}+Enter`) + await expectQuestionOpen(page) + }) + }, + { trackSession: project.trackSession }, + ) }) }) test("blocked question flow supports escape dismiss", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock question escape", async (session) => { - await withDockSeed(project.sdk, session.id, async () => { - await project.gotoSession(session.id) + await withDockSession( + project.sdk, + "e2e composer dock question escape", + async (session) => { + await withDockSeed(project.sdk, session.id, async () => { + await project.gotoSession(session.id) - await seedSessionQuestion(project.sdk, { - sessionID: session.id, - questions: [ - { - header: "Need input", - question: "Pick one option", - options: [ - { label: "Continue", description: "Continue now" }, - { label: "Stop", description: "Stop here" }, - ], - }, - ], - }) + await seedSessionQuestion(project.sdk, { + sessionID: session.id, + questions: [ + { + header: "Need input", + question: "Pick one option", + options: [ + { label: "Continue", description: "Continue now" }, + { label: "Stop", description: "Stop here" }, + ], + }, + ], + }) - const dock = page.locator(questionDockSelector) - const first = dock.locator('[data-slot="question-option"]').first() + const dock = page.locator(questionDockSelector) + const first = dock.locator('[data-slot="question-option"]').first() - await expectQuestionBlocked(page) - await expect(first).toBeFocused() + await expectQuestionBlocked(page) + await expect(first).toBeFocused() - await page.keyboard.press("Escape") - await expectQuestionOpen(page) - }) - }) + await page.keyboard.press("Escape") + await expectQuestionOpen(page) + }) + }, + { trackSession: project.trackSession }, + ) }) }) test("blocked permission flow supports allow once", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock permission once", async (session) => { - await project.gotoSession(session.id) - await setAutoAccept(page, false) - await withMockPermission( - page, - { - id: "per_e2e_once", - sessionID: session.id, - permission: "bash", - patterns: ["/tmp/opencode-e2e-perm-once"], - metadata: { description: "Need permission for command" }, - }, - undefined, - async (state) => { - await page.goto(page.url()) - await expectPermissionBlocked(page) - - await clearPermissionDock(page, /allow once/i) - await state.resolved() - await page.goto(page.url()) - await expectPermissionOpen(page) - }, - ) - }) + await withDockSession( + project.sdk, + "e2e composer dock permission once", + async (session) => { + await project.gotoSession(session.id) + await setAutoAccept(page, false) + await withMockPermission( + page, + { + id: "per_e2e_once", + sessionID: session.id, + permission: "bash", + patterns: ["/tmp/opencode-e2e-perm-once"], + metadata: { description: "Need permission for command" }, + }, + undefined, + async (state) => { + await page.goto(page.url()) + await expectPermissionBlocked(page) + + await clearPermissionDock(page, /allow once/i) + await state.resolved() + await page.goto(page.url()) + await expectPermissionOpen(page) + }, + ) + }, + { trackSession: project.trackSession }, + ) }) }) test("blocked permission flow supports reject", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock permission reject", async (session) => { - await project.gotoSession(session.id) - await setAutoAccept(page, false) - await withMockPermission( - page, - { - id: "per_e2e_reject", - sessionID: session.id, - permission: "bash", - patterns: ["/tmp/opencode-e2e-perm-reject"], - }, - undefined, - async (state) => { - await page.goto(page.url()) - await expectPermissionBlocked(page) - - await clearPermissionDock(page, /deny/i) - await state.resolved() - await page.goto(page.url()) - await expectPermissionOpen(page) - }, - ) - }) + await withDockSession( + project.sdk, + "e2e composer dock permission reject", + async (session) => { + await project.gotoSession(session.id) + await setAutoAccept(page, false) + await withMockPermission( + page, + { + id: "per_e2e_reject", + sessionID: session.id, + permission: "bash", + patterns: ["/tmp/opencode-e2e-perm-reject"], + }, + undefined, + async (state) => { + await page.goto(page.url()) + await expectPermissionBlocked(page) + + await clearPermissionDock(page, /deny/i) + await state.resolved() + await page.goto(page.url()) + await expectPermissionOpen(page) + }, + ) + }, + { trackSession: project.trackSession }, + ) }) }) test("blocked permission flow supports allow always", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock permission always", async (session) => { - await project.gotoSession(session.id) - await setAutoAccept(page, false) - await withMockPermission( - page, - { - id: "per_e2e_always", - sessionID: session.id, - permission: "bash", - patterns: ["/tmp/opencode-e2e-perm-always"], - metadata: { description: "Need permission for command" }, - }, - undefined, - async (state) => { - await page.goto(page.url()) - await expectPermissionBlocked(page) - - await clearPermissionDock(page, /allow always/i) - await state.resolved() - await page.goto(page.url()) - await expectPermissionOpen(page) - }, - ) - }) + await withDockSession( + project.sdk, + "e2e composer dock permission always", + async (session) => { + await project.gotoSession(session.id) + await setAutoAccept(page, false) + await withMockPermission( + page, + { + id: "per_e2e_always", + sessionID: session.id, + permission: "bash", + patterns: ["/tmp/opencode-e2e-perm-always"], + metadata: { description: "Need permission for command" }, + }, + undefined, + async (state) => { + await page.goto(page.url()) + await expectPermissionBlocked(page) + + await clearPermissionDock(page, /allow always/i) + await state.resolved() + await page.goto(page.url()) + await expectPermissionOpen(page) + }, + ) + }, + { trackSession: project.trackSession }, + ) }) }) @@ -479,45 +515,51 @@ test("child session question request blocks parent dock and unblocks after submi withBackendProject, }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock child question parent", async (session) => { - await project.gotoSession(session.id) - - const child = await project.sdk.session - .create({ - title: "e2e composer dock child question", - parentID: session.id, - }) - .then((r) => r.data) - if (!child?.id) throw new Error("Child session create did not return an id") + await withDockSession( + project.sdk, + "e2e composer dock child question parent", + async (session) => { + await project.gotoSession(session.id) - try { - await withDockSeed(project.sdk, child.id, async () => { - await seedSessionQuestion(project.sdk, { - sessionID: child.id, - questions: [ - { - header: "Child input", - question: "Pick one child option", - options: [ - { label: "Continue", description: "Continue child" }, - { label: "Stop", description: "Stop child" }, - ], - }, - ], + const child = await project.sdk.session + .create({ + title: "e2e composer dock child question", + parentID: session.id, }) + .then((r) => r.data) + if (!child?.id) throw new Error("Child session create did not return an id") + project.trackSession(child.id) + + try { + await withDockSeed(project.sdk, child.id, async () => { + await seedSessionQuestion(project.sdk, { + sessionID: child.id, + questions: [ + { + header: "Child input", + question: "Pick one child option", + options: [ + { label: "Continue", description: "Continue child" }, + { label: "Stop", description: "Stop child" }, + ], + }, + ], + }) - const dock = page.locator(questionDockSelector) - await expectQuestionBlocked(page) + const dock = page.locator(questionDockSelector) + await expectQuestionBlocked(page) - await dock.locator('[data-slot="question-option"]').first().click() - await dock.getByRole("button", { name: /submit/i }).click() + await dock.locator('[data-slot="question-option"]').first().click() + await dock.getByRole("button", { name: /submit/i }).click() - await expectQuestionOpen(page) - }) - } finally { - await cleanupSession({ sdk: project.sdk, sessionID: child.id }) - } - }) + await expectQuestionOpen(page) + }) + } finally { + await cleanupSession({ sdk: project.sdk, sessionID: child.id }) + } + }, + { trackSession: project.trackSession }, + ) }) }) @@ -526,102 +568,118 @@ test("child session permission request blocks parent dock and supports allow onc withBackendProject, }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock child permission parent", async (session) => { - await project.gotoSession(session.id) - await setAutoAccept(page, false) - - const child = await project.sdk.session - .create({ - title: "e2e composer dock child permission", - parentID: session.id, - }) - .then((r) => r.data) - if (!child?.id) throw new Error("Child session create did not return an id") + await withDockSession( + project.sdk, + "e2e composer dock child permission parent", + async (session) => { + await project.gotoSession(session.id) + await setAutoAccept(page, false) - try { - await withMockPermission( - page, - { - id: "per_e2e_child", - sessionID: child.id, - permission: "bash", - patterns: ["/tmp/opencode-e2e-perm-child"], - metadata: { description: "Need child permission" }, - }, - { child }, - async (state) => { - await page.goto(page.url()) - await expectPermissionBlocked(page) + const child = await project.sdk.session + .create({ + title: "e2e composer dock child permission", + parentID: session.id, + }) + .then((r) => r.data) + if (!child?.id) throw new Error("Child session create did not return an id") + project.trackSession(child.id) - await clearPermissionDock(page, /allow once/i) - await state.resolved() - await page.goto(page.url()) + try { + await withMockPermission( + page, + { + id: "per_e2e_child", + sessionID: child.id, + permission: "bash", + patterns: ["/tmp/opencode-e2e-perm-child"], + metadata: { description: "Need child permission" }, + }, + { child }, + async (state) => { + await page.goto(page.url()) + await expectPermissionBlocked(page) - await expectPermissionOpen(page) - }, - ) - } finally { - await cleanupSession({ sdk: project.sdk, sessionID: child.id }) - } - }) + await clearPermissionDock(page, /allow once/i) + await state.resolved() + await page.goto(page.url()) + + await expectPermissionOpen(page) + }, + ) + } finally { + await cleanupSession({ sdk: project.sdk, sessionID: child.id }) + } + }, + { trackSession: project.trackSession }, + ) }) }) test("todo dock transitions and collapse behavior", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock todo", async (session) => { - const dock = await todoDock(page, session.id) - await project.gotoSession(session.id) - await expect(page.locator(sessionComposerDockSelector)).toBeVisible() - - try { - await dock.open([ - { content: "first task", status: "pending", priority: "high" }, - { content: "second task", status: "in_progress", priority: "medium" }, - ]) - await dock.expectOpen(["pending", "in_progress"]) - - await dock.collapse() - await dock.expectCollapsed(["pending", "in_progress"]) - - await dock.expand() - await dock.expectOpen(["pending", "in_progress"]) - - await dock.finish([ - { content: "first task", status: "completed", priority: "high" }, - { content: "second task", status: "cancelled", priority: "medium" }, - ]) - await dock.expectClosed() - } finally { - await dock.clear() - } - }) + await withDockSession( + project.sdk, + "e2e composer dock todo", + async (session) => { + const dock = await todoDock(page, session.id) + await project.gotoSession(session.id) + await expect(page.locator(sessionComposerDockSelector)).toBeVisible() + + try { + await dock.open([ + { content: "first task", status: "pending", priority: "high" }, + { content: "second task", status: "in_progress", priority: "medium" }, + ]) + await dock.expectOpen(["pending", "in_progress"]) + + await dock.collapse() + await dock.expectCollapsed(["pending", "in_progress"]) + + await dock.expand() + await dock.expectOpen(["pending", "in_progress"]) + + await dock.finish([ + { content: "first task", status: "completed", priority: "high" }, + { content: "second task", status: "cancelled", priority: "medium" }, + ]) + await dock.expectClosed() + } finally { + await dock.clear() + } + }, + { trackSession: project.trackSession }, + ) }) }) test("keyboard focus stays off prompt while blocked", async ({ page, withBackendProject }) => { await withBackendProject(async (project) => { - await withDockSession(project.sdk, "e2e composer dock keyboard", async (session) => { - await withDockSeed(project.sdk, session.id, async () => { - await project.gotoSession(session.id) + await withDockSession( + project.sdk, + "e2e composer dock keyboard", + async (session) => { + await withDockSeed(project.sdk, session.id, async () => { + await project.gotoSession(session.id) - await seedSessionQuestion(project.sdk, { - sessionID: session.id, - questions: [ - { - header: "Need input", - question: "Pick one option", - options: [{ label: "Continue", description: "Continue now" }], - }, - ], - }) + await seedSessionQuestion(project.sdk, { + sessionID: session.id, + questions: [ + { + header: "Need input", + question: "Pick one option", + options: [{ label: "Continue", description: "Continue now" }], + }, + ], + }) - await expectQuestionBlocked(page) + await expectQuestionBlocked(page) - await page.locator("main").click({ position: { x: 5, y: 5 } }) - await page.keyboard.type("abc") - await expect(page.locator(promptSelector)).toHaveCount(0) - }) - }) + await page.locator("main").click({ position: { x: 5, y: 5 } }) + await page.keyboard.type("abc") + await expect(page.locator(promptSelector)).toHaveCount(0) + }) + }, + { trackSession: project.trackSession }, + ) }) }) diff --git a/packages/app/e2e/session/session-undo-redo.spec.ts b/packages/app/e2e/session/session-undo-redo.spec.ts index b3a75e0dd..a63bd9e3b 100644 --- a/packages/app/e2e/session/session-undo-redo.spec.ts +++ b/packages/app/e2e/session/session-undo-redo.spec.ts @@ -58,6 +58,7 @@ test("slash undo sets revert and restores prior prompt", async ({ page, withBack const sdk = project.sdk await withSession(sdk, `e2e undo ${Date.now()}`, async (session) => { + project.trackSession(session.id) await project.gotoSession(session.id) const seeded = await seedConversation({ page, sdk, sessionID: session.id, token }) @@ -90,6 +91,7 @@ test("slash redo clears revert and restores latest state", async ({ page, withBa const sdk = project.sdk await withSession(sdk, `e2e redo ${Date.now()}`, async (session) => { + project.trackSession(session.id) await project.gotoSession(session.id) const seeded = await seedConversation({ page, sdk, sessionID: session.id, token }) @@ -138,6 +140,7 @@ test("slash undo/redo traverses multi-step revert stack", async ({ page, withBac const sdk = project.sdk await withSession(sdk, `e2e undo redo stack ${Date.now()}`, async (session) => { + project.trackSession(session.id) await project.gotoSession(session.id) const first = await seedConversation({ diff --git a/packages/app/e2e/session/session.spec.ts b/packages/app/e2e/session/session.spec.ts index d56e83f2f..6c885460c 100644 --- a/packages/app/e2e/session/session.spec.ts +++ b/packages/app/e2e/session/session.spec.ts @@ -38,6 +38,7 @@ test("session can be renamed via header menu", async ({ page, withBackendProject await withBackendProject(async (project) => { await withSession(project.sdk, originalTitle, async (session) => { + project.trackSession(session.id) await seedMessage(project.sdk, session.id) await project.gotoSession(session.id) await expect(page.getByRole("heading", { level: 1 }).first()).toHaveText(originalTitle) @@ -73,6 +74,7 @@ test("session can be archived via header menu", async ({ page, withBackendProjec await withBackendProject(async (project) => { await withSession(project.sdk, title, async (session) => { + project.trackSession(session.id) await seedMessage(project.sdk, session.id) await project.gotoSession(session.id) const menu = await openSessionMoreMenu(page, session.id) @@ -100,6 +102,7 @@ test("session can be deleted via header menu", async ({ page, withBackendProject await withBackendProject(async (project) => { await withSession(project.sdk, title, async (session) => { + project.trackSession(session.id) await seedMessage(project.sdk, session.id) await project.gotoSession(session.id) const menu = await openSessionMoreMenu(page, session.id) @@ -133,6 +136,7 @@ test("session can be shared and unshared via header button", async ({ page, with await withBackendProject(async (project) => { await withSession(project.sdk, title, async (session) => { + project.trackSession(session.id) await seedMessage(project.sdk, session.id) await project.gotoSession(session.id) |
