|
| 1 | +import { createRequire } from "node:module" |
| 2 | +import { mkdtemp, rm } from "node:fs/promises" |
| 3 | +import { tmpdir } from "node:os" |
| 4 | +import path from "node:path" |
| 5 | +import { startPanelPreview } from "./composer-panel-preview.mjs" |
| 6 | +import { directory } from "./composer-fixture.mjs" |
| 7 | + |
| 8 | +const { chromium, _electron, expect } = createRequire(new URL("../../app/package.json", import.meta.url))("@playwright/test") |
| 9 | +const preview = await startPanelPreview() |
| 10 | +const fixture = preview.fixture |
| 11 | +fixture.messages[1].parts[0].text = [ |
| 12 | + ...Array.from({ length: 31 }, (_, index) => `https://github.com/example/repo/pull/${index + 1}`), |
| 13 | + "[duplicate](https://github.com/EXAMPLE/REPO/pull/1/files?diff=split#top)", |
| 14 | + "https://duo.fyi/ink/https://github.com/example/repo/pull/2?tab=files#review", |
| 15 | + "https://github.com/example/repo/issues/900 https://github.com.evil.test/example/repo/pull/901", |
| 16 | + "https://github.com/example/repo/pull/902bad", |
| 17 | +].join("\n\n") |
| 18 | +fixture.messages[1].parts.push({ id: "tool_prs", messageID: "msg_2", sessionID: "ses_a", type: "tool", tool: "read", callID: "read_prs", |
| 19 | + state: { status: "completed", input: {}, output: "Result: https://github.com/tools/output/pull/42#discussion", title: "Read", time: { start: 1, end: 2 } } }) |
| 20 | +fixture.messagesB = [{ info: { ...fixture.messages[0].info, id: "other", sessionID: "ses_b" }, parts: [ |
| 21 | + { ...fixture.messages[0].parts[0], id: "other_part", messageID: "other", sessionID: "ses_b", text: "https://github.com/other/repo/pull/999" }, |
| 22 | +] }] |
| 23 | +const state = await (await fetch(`${fixture.url}/api/state`)).json() |
| 24 | +state.threads[0].prs = [{ repo: "example/repo", number: 1, url: "https://github.com/example/repo/pull/1", title: "Merged PR", state: "merged" }, |
| 25 | + { repo: "example/repo", number: 2, url: "https://github.com/example/repo/pull/2", title: "Closed PR", state: "closed" }] |
| 26 | +const profile = process.env.ES_DESKTOP_EXECUTABLE ? await mkdtemp(path.join(tmpdir(), "sidebar-prs-")) : undefined |
| 27 | +const app = profile ? await _electron.launch({ executablePath: process.env.ES_DESKTOP_EXECUTABLE, |
| 28 | + env: { ...process.env, ELECTRON_RUN_AS_NODE: "", ES_DESKTOP_USER_DATA: profile, ES_DESKTOP_RENDERER: "", |
| 29 | + OPENCODE_URL: fixture.url, ES_DASHBOARD_URL: fixture.url, OPENCODE_SERVER_PASSWORD: "" }, |
| 30 | +}) : undefined |
| 31 | +const browser = app ? undefined : await chromium.launch({ channel: "chrome", headless: true }) |
| 32 | +const page = app ? await app.firstWindow() : await browser.newPage() |
| 33 | +if (app) { |
| 34 | + await page.waitForURL("http://127.0.0.1:*/") |
| 35 | + preview.origin = new URL(page.url()).origin |
| 36 | + preview.url = `${preview.origin}/session/ses_a?directory=${encodeURIComponent(directory)}` |
| 37 | +} |
| 38 | +await page.context().route("**/*", route => new URL(route.request().url()).origin === preview.origin ? route.continue() : route.abort()) |
| 39 | +await page.route("**/api/state*", route => route.fulfill({ json: state })) |
| 40 | +const chips = page.locator(".session-info .pr-title-row") |
| 41 | +try { |
| 42 | + await page.goto(preview.url) |
| 43 | + await expect(chips).toHaveCount(32) |
| 44 | + await expect(page.locator(".info-heading", { hasText: "PRs referenced" })).toHaveCount(1) |
| 45 | + await expect(chips.nth(0)).toHaveAttribute("href", "https://duo.fyi/ink/https://github.com/example/repo/pull/1") |
| 46 | + await expect(chips.nth(0).locator(".icon-merged")).toHaveCount(1) |
| 47 | + await expect(chips.nth(1).locator(".icon-closed")).toHaveCount(1) |
| 48 | + await expect(chips.nth(2).locator(".pr-icon")).toHaveCount(0) |
| 49 | + await expect(chips.nth(31)).toHaveAttribute("href", "https://duo.fyi/ink/https://github.com/tools/output/pull/42") |
| 50 | + await expect(page.locator(".session-info .pr-title-row[href*='/999'], .session-info .pr-title-row[href*='/900'], .session-info .pr-title-row[href*='/901'], .session-info .pr-title-row[href*='/902']")).toHaveCount(0) |
| 51 | + await page.reload() |
| 52 | + await expect(chips).toHaveCount(32) |
| 53 | + const info = { ...fixture.messages[0].info, id: "live_pr", sessionID: "ses_a" } |
| 54 | + const part = { ...fixture.messages[0].parts[0], id: "live_part", messageID: info.id, text: "https://github.com/live/repo/pull/43" } |
| 55 | + fixture.messages.push({ info, parts: [part] }) |
| 56 | + fixture.emit("message.updated", { info }) |
| 57 | + fixture.emit("message.part.updated", { part }) |
| 58 | + await expect(chips).toHaveCount(33) |
| 59 | + await expect(chips.filter({ hasText: "live/repo#43" })).toHaveAttribute("href", "https://duo.fyi/ink/https://github.com/live/repo/pull/43") |
| 60 | + expect(fixture.calls.filter(call => !["GET", "HEAD", "OPTIONS"].includes(call.method))).toEqual([]) |
| 61 | + console.log(`PASS sidebar PRs ${app ? "native" : "browser"}: >25, metadata/unknown, tool output, strict links, other session, reload, live addition; zero mutations`) |
| 62 | +} finally { |
| 63 | + await app?.close() |
| 64 | + await browser?.close() |
| 65 | + await preview.close() |
| 66 | + if (profile) await rm(profile, { recursive: true, force: true }) |
| 67 | +} |
0 commit comments