|
| 1 | +import { expect, test, type Page } from "@playwright/test" |
| 2 | +import { base64Encode } from "@opencode-ai/core/util/encode" |
| 3 | +import { mockOpenCodeServer } from "../utils/mock-server" |
| 4 | +import { expectAppVisible, expectSessionTitle } from "../utils/waits" |
| 5 | + |
| 6 | +const directory = "C:/OpenCode/ReviewLineCommentRegression" |
| 7 | +const sessionID = "ses_review_line_comment_regression" |
| 8 | +const title = "Review line comment regression" |
| 9 | + |
| 10 | +test.beforeEach(async ({ page }) => { |
| 11 | + await openReview(page) |
| 12 | +}) |
| 13 | + |
| 14 | +test("opens the comment editor when code is clicked", async ({ page }) => { |
| 15 | + const review = page.locator('[data-component="session-review"]') |
| 16 | + const line = review.getByText("export const value = 'after'", { exact: true }) |
| 17 | + await expectAppVisible(line) |
| 18 | + await line.click() |
| 19 | + |
| 20 | + await expect(review.getByRole("textbox")).toBeVisible() |
| 21 | +}) |
| 22 | + |
| 23 | +test("opens the comment editor when a line number is clicked", async ({ page }) => { |
| 24 | + const review = page.locator('[data-component="session-review"]') |
| 25 | + const lineNumber = review.locator('[data-column-number="1"]').last() |
| 26 | + await expectAppVisible(lineNumber) |
| 27 | + await lineNumber.click() |
| 28 | + |
| 29 | + await expect(review.getByRole("textbox")).toBeVisible() |
| 30 | +}) |
| 31 | + |
| 32 | +test("opens the comment editor for a line number range", async ({ page }) => { |
| 33 | + const review = page.locator('[data-component="session-review"]') |
| 34 | + const start = review.locator('[data-column-number="1"]').last() |
| 35 | + const end = review.locator('[data-column-number="3"]').last() |
| 36 | + await expectAppVisible(start) |
| 37 | + await expectAppVisible(end) |
| 38 | + |
| 39 | + const from = await start.boundingBox() |
| 40 | + const to = await end.boundingBox() |
| 41 | + if (!from || !to) throw new Error("Missing line number bounds") |
| 42 | + await page.mouse.move(from.x + from.width / 2, from.y + from.height / 2) |
| 43 | + await page.mouse.down() |
| 44 | + await page.mouse.move(to.x + to.width / 2, to.y + to.height / 2) |
| 45 | + await page.mouse.up() |
| 46 | + |
| 47 | + await expect(review.getByRole("textbox")).toBeVisible() |
| 48 | +}) |
| 49 | + |
| 50 | +test("shows a comment button when a line number is hovered", async ({ page }) => { |
| 51 | + const review = page.locator('[data-component="session-review"]') |
| 52 | + const lineNumber = review.locator('[data-column-number="1"]').last() |
| 53 | + await expectAppVisible(lineNumber) |
| 54 | + |
| 55 | + const comment = review.getByRole("button", { name: "Comment", exact: true }) |
| 56 | + await expect(async () => { |
| 57 | + await page.mouse.move(0, 0) |
| 58 | + await lineNumber.hover() |
| 59 | + await expect(comment).toBeVisible({ timeout: 500 }) |
| 60 | + }).toPass() |
| 61 | + await comment.click() |
| 62 | + await expect(review.getByRole("textbox")).toBeVisible() |
| 63 | +}) |
| 64 | + |
| 65 | +test("stages a submitted line comment in the prompt context", async ({ page }) => { |
| 66 | + const requests: string[] = [] |
| 67 | + page.on("request", (request) => { |
| 68 | + if (request.method() !== "GET") requests.push(`${request.method()} ${new URL(request.url()).pathname}`) |
| 69 | + }) |
| 70 | + |
| 71 | + const review = page.locator('[data-component="session-review"]') |
| 72 | + await review.getByText("export const value = 'after'", { exact: true }).click() |
| 73 | + await review.getByRole("textbox").fill("Use the existing value instead") |
| 74 | + await review.locator('[data-slot="line-comment-action"][data-variant="primary"]').click() |
| 75 | + |
| 76 | + await expect(review.getByText("Use the existing value instead", { exact: true })).toBeVisible() |
| 77 | + await page.getByRole("tab", { name: "Session" }).click() |
| 78 | + const context = page.getByText("Use the existing value instead", { exact: true }).last() |
| 79 | + await expect(context).toBeVisible() |
| 80 | + await expect(context.locator("..")).toContainText("review.ts:2") |
| 81 | + expect(requests).toEqual([]) |
| 82 | +}) |
| 83 | + |
| 84 | +async function openReview(page: Page) { |
| 85 | + await page.setViewportSize({ width: 700, height: 900 }) |
| 86 | + await mockOpenCodeServer(page, { |
| 87 | + directory, |
| 88 | + project: { |
| 89 | + id: "proj_review_line_comment_regression", |
| 90 | + worktree: directory, |
| 91 | + vcs: "git", |
| 92 | + name: "review-line-comment-regression", |
| 93 | + time: { created: 1700000000000, updated: 1700000000000 }, |
| 94 | + sandboxes: [], |
| 95 | + }, |
| 96 | + provider: { all: [], connected: [], default: {} }, |
| 97 | + sessions: [ |
| 98 | + { |
| 99 | + id: sessionID, |
| 100 | + slug: "review-line-comment-regression", |
| 101 | + projectID: "proj_review_line_comment_regression", |
| 102 | + directory, |
| 103 | + title, |
| 104 | + version: "dev", |
| 105 | + time: { created: 1700000000000, updated: 1700000000000 }, |
| 106 | + }, |
| 107 | + ], |
| 108 | + vcsDiff: [ |
| 109 | + { |
| 110 | + file: "src/review.ts", |
| 111 | + additions: 1, |
| 112 | + deletions: 1, |
| 113 | + status: "modified", |
| 114 | + patch: |
| 115 | + "diff --git a/src/review.ts b/src/review.ts\n--- a/src/review.ts\n+++ b/src/review.ts\n@@ -1,3 +1,3 @@\n export const first = 1\n-export const value = 'before'\n+export const value = 'after'\n export const last = 3\n", |
| 116 | + }, |
| 117 | + ], |
| 118 | + pageMessages: () => ({ |
| 119 | + items: [ |
| 120 | + { |
| 121 | + info: { |
| 122 | + id: "msg_review_line_comment_regression", |
| 123 | + sessionID, |
| 124 | + role: "user", |
| 125 | + time: { created: 1700000000000 }, |
| 126 | + summary: { diffs: [] }, |
| 127 | + agent: "build", |
| 128 | + model: { providerID: "opencode", modelID: "test" }, |
| 129 | + }, |
| 130 | + parts: [ |
| 131 | + { |
| 132 | + id: "prt_review_line_comment_regression", |
| 133 | + sessionID, |
| 134 | + messageID: "msg_review_line_comment_regression", |
| 135 | + type: "text", |
| 136 | + text: "Review this change.", |
| 137 | + }, |
| 138 | + ], |
| 139 | + }, |
| 140 | + ], |
| 141 | + }), |
| 142 | + }) |
| 143 | + |
| 144 | + await page.goto(`/${base64Encode(directory)}/session/${sessionID}`) |
| 145 | + await expectSessionTitle(page, title) |
| 146 | + const diffResponse = page.waitForResponse((response) => new URL(response.url()).pathname === "/vcs/diff") |
| 147 | + await page.getByRole("tab", { name: "Changes" }).click() |
| 148 | + expect(await (await diffResponse).json()).toHaveLength(1) |
| 149 | + |
| 150 | + const review = page.locator('[data-component="session-review"]') |
| 151 | + await expectAppVisible(review) |
| 152 | + await review |
| 153 | + .getByRole("heading", { name: /review\.ts/ }) |
| 154 | + .getByRole("button") |
| 155 | + .first() |
| 156 | + .click() |
| 157 | +} |
0 commit comments