|
| 1 | +import { expect, test } from "@playwright/test" |
| 2 | +import type { ConfigEntry } from "@opencode/client/promise" |
| 3 | +import { mockOpenCodeServer } from "../utils/mock-server" |
| 4 | + |
| 5 | +const directory = "/repo/configured-lsp" |
| 6 | +const entries: ConfigEntry[] = [ |
| 7 | + { |
| 8 | + type: "document", |
| 9 | + path: "/config/opencode.json", |
| 10 | + info: { |
| 11 | + lsp: { |
| 12 | + typescript: { command: ["typescript-language-server", "--stdio"], extensions: [".ts", ".tsx"] }, |
| 13 | + }, |
| 14 | + }, |
| 15 | + }, |
| 16 | + { |
| 17 | + type: "document", |
| 18 | + path: `${directory}/opencode.jsonc`, |
| 19 | + info: { |
| 20 | + lsp: { |
| 21 | + typescript: { disabled: true }, |
| 22 | + rust: { command: ["rust-analyzer"], extensions: [".rs"] }, |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | +] |
| 27 | + |
| 28 | +test.use({ viewport: { width: 1280, height: 900 } }) |
| 29 | + |
| 30 | +test.beforeEach(async ({ page }) => { |
| 31 | + await mockOpenCodeServer(page, { |
| 32 | + directory, |
| 33 | + project: { |
| 34 | + id: "proj_configured_lsp", |
| 35 | + canonical: directory, |
| 36 | + name: "Configured LSP project", |
| 37 | + sandboxes: [], |
| 38 | + time: { created: 1, updated: 1 }, |
| 39 | + }, |
| 40 | + provider: { all: [], connected: [], default: {} }, |
| 41 | + sessions: [], |
| 42 | + pageMessages: () => ({ items: [] }), |
| 43 | + }) |
| 44 | + await page.addInitScript((directory) => { |
| 45 | + localStorage.setItem( |
| 46 | + "opencode.global.dat:server", |
| 47 | + JSON.stringify({ projects: { local: [{ worktree: directory, expanded: true }] } }), |
| 48 | + ) |
| 49 | + }, directory) |
| 50 | + await page.goto("/") |
| 51 | + await page.getByRole("button", { name: "Settings", exact: true }).click() |
| 52 | + const settings = page.getByTestId("settings-screen") |
| 53 | + await settings.getByRole("tab", { name: "Projects", exact: true }).click() |
| 54 | + await settings.getByRole("button", { name: "Configured LSP project", exact: true }).click() |
| 55 | + await settings.getByRole("tab", { name: "Extensions", exact: true }).click() |
| 56 | +}) |
| 57 | + |
| 58 | +test("shows inherited and project-configured LSP entries with config-only status", async ({ page }) => { |
| 59 | + const ready = Promise.withResolvers<void>() |
| 60 | + await page.route( |
| 61 | + (url) => url.pathname === "/api/config", |
| 62 | + async (route) => { |
| 63 | + await ready.promise |
| 64 | + await route.fulfill({ json: entries }) |
| 65 | + }, |
| 66 | + ) |
| 67 | + const requested = page.waitForRequest((request) => new URL(request.url()).pathname === "/api/config") |
| 68 | + const settings = page.getByTestId("settings-screen") |
| 69 | + await settings.getByRole("tab", { name: "LSPs", exact: true }).click() |
| 70 | + expect(new URL((await requested).url()).searchParams.get("location[directory]")).toBe(directory) |
| 71 | + const panel = settings.getByRole("tabpanel", { name: "LSPs", exact: true }) |
| 72 | + await expect(panel.getByText("Loading", { exact: true })).toBeVisible() |
| 73 | + ready.resolve() |
| 74 | + await expect(panel.getByText("typescript", { exact: true })).toBeVisible() |
| 75 | + await expect(panel.getByText("rust", { exact: true })).toBeVisible() |
| 76 | + const typescript = panel.locator(".project-settings-extension-row").filter({ hasText: "typescript" }) |
| 77 | + await expect(typescript).toContainText("Disabled in config") |
| 78 | + await expect(typescript).toContainText(".ts, .tsx") |
| 79 | + await expect(panel.locator(".project-settings-extension-row").filter({ hasText: "rust" })).toContainText( |
| 80 | + "Enabled in config", |
| 81 | + ) |
| 82 | + await expect(panel.getByRole("switch")).toHaveCount(0) |
| 83 | + await expect(panel.getByText("Setup required", { exact: true })).toHaveCount(0) |
| 84 | + await page.setViewportSize({ width: 390, height: 844 }) |
| 85 | + await expect(panel.getByText("rust", { exact: true })).toBeInViewport() |
| 86 | + await expect |
| 87 | + .poll(() => settings.evaluate((element) => element.scrollWidth - element.clientWidth)) |
| 88 | + .toBeLessThanOrEqual(1) |
| 89 | +}) |
| 90 | + |
| 91 | +for (const lsp of [true, false]) { |
| 92 | + test(`handles boolean lsp=${lsp} without inventing detected servers`, async ({ page }) => { |
| 93 | + await page.route( |
| 94 | + (url) => url.pathname === "/api/config", |
| 95 | + (route) => |
| 96 | + route.fulfill({ |
| 97 | + json: [{ type: "document", info: { lsp } }], |
| 98 | + }), |
| 99 | + ) |
| 100 | + const settings = page.getByTestId("settings-screen") |
| 101 | + await settings.getByRole("tab", { name: "LSPs", exact: true }).click() |
| 102 | + const panel = settings.getByRole("tabpanel", { name: "LSPs", exact: true }) |
| 103 | + await expect( |
| 104 | + panel.getByText(lsp ? "No language servers configured" : "Language servers disabled", { exact: true }), |
| 105 | + ).toBeVisible() |
| 106 | + await expect(panel.locator(".project-settings-extension-row")).toHaveCount(0) |
| 107 | + }) |
| 108 | +} |
| 109 | + |
| 110 | +test("keeps configuration load failures inside the tab and allows retry", async ({ page }) => { |
| 111 | + const state = { fail: true } |
| 112 | + await page.route( |
| 113 | + (url) => url.pathname === "/api/config", |
| 114 | + (route) => |
| 115 | + route.fulfill({ |
| 116 | + status: state.fail ? 404 : 200, |
| 117 | + json: state.fail ? {} : entries, |
| 118 | + }), |
| 119 | + ) |
| 120 | + const settings = page.getByTestId("settings-screen") |
| 121 | + await settings.getByRole("tab", { name: "LSPs", exact: true }).click() |
| 122 | + const panel = settings.getByRole("tabpanel", { name: "LSPs", exact: true }) |
| 123 | + await expect(panel.getByText("Could not load language server configuration", { exact: true })).toBeVisible() |
| 124 | + state.fail = false |
| 125 | + await panel.getByRole("button", { name: "Retry", exact: true }).click() |
| 126 | + await expect(panel.getByText("typescript", { exact: true })).toBeVisible() |
| 127 | + await settings.getByRole("tab", { name: "Skills", exact: true }).click() |
| 128 | + await expect(settings.getByRole("tabpanel", { name: "Skills", exact: true })).toBeVisible() |
| 129 | +}) |
0 commit comments