Skip to content
65 changes: 65 additions & 0 deletions apps/desktop/e2e/code-review-diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,71 @@ test("grouped diffs, both gutters, hierarchy, filter and keyboard selection use
expect((await log()).filter((r: any) => r.op === "files")).toHaveLength(1);
});

test("Viewed marks a file on this Mac for one revision, folds it, survives a reload and asks GitHub nothing (C65)", async () => {
await open();
const first = tid(page, "cr-file-section").first();
const viewed = page.getByRole("checkbox", { name: "Viewed src/holds/move.ts", exact: true });
await expect(tid(page, "cr-viewed-count")).toHaveText("0 of 4 viewed");
await expect(first.getByTestId("diff").first()).toBeVisible();
const asked = (await log()).length;
await viewed.focus();
await page.keyboard.press("Space");
await expect(viewed).toBeChecked();
await expect(first.getByTestId("diff")).toHaveCount(0);
await expect(tid(page, "cr-viewed-count")).toHaveText("1 of 4 viewed");
await expect(page.getByRole("button", { name: "View remote diff for src/holds/move.ts, viewed", exact: true })).toBeVisible();
// The file can still be opened, and unmarking it does not reopen or lose anything.
await page.getByRole("button", { name: "Expand src/holds/move.ts", exact: true }).click();
await expect(first.getByTestId("diff").first()).toBeVisible();
expect((await log()).length, "a mark is local: no read, and there is no write channel call").toBe(asked);
await page.reload();
await tid(page, "rail-code-review").click();
await page.locator('[data-testid="code-review-row"][data-pr="example-org/field-guide#91"]').click();
await tid(page, "code-review-tab-changes").click();
await expect(page.getByRole("checkbox", { name: "Viewed src/holds/move.ts", exact: true })).toBeChecked();
await expect(tid(page, "cr-viewed-count")).toHaveText("1 of 4 viewed");
// A new head may have changed the file: its marks are not carried over.
await app.evaluate(() => { const s = (globalThis as any).__diff; s.revision = { ...s.revision, headSha: "f".repeat(40) }; });
await refreshOverview();
await expect(tid(page, "cr-file-section").first()).toHaveAttribute("data-head-sha", "f".repeat(40));
await expect(tid(page, "cr-viewed-count")).toHaveText("0 of 4 viewed");
await expect(page.getByRole("checkbox", { name: "Viewed src/holds/move.ts", exact: true })).not.toBeChecked();
expect(await app.evaluate(() => (globalThis as any).__diff.local)).toEqual([]);
});

test("keyboard: F6 moves between the areas and [ ] between files, and typing a bracket in the filter types it (F6)", async () => {
await open();
await expect(tid(page, "cr-file-section")).toHaveCount(4);
await expect(tid(page, "cr-key-hint")).toContainText("F6");
const paths = await tid(page, "cr-file-section").evaluateAll((sections) => sections.map((s) => (s as HTMLElement).dataset.path!));
await tid(page, "code-review-search").focus();
const focused = () => page.evaluate(() => { const a = document.activeElement as HTMLElement | null; return a?.dataset.testid ?? a?.getAttribute("role") ?? a?.tagName ?? null; });
// Forward: inbox search, the selected tab, the diff, the file list, and round again. Four presses, not dozens of Tabs.
const seen: (string | null)[] = [];
for (let i = 0; i < 4; i++) { await page.keyboard.press("F6"); seen.push(await focused()); }
expect(seen).toEqual(["code-review-tab-changes", "code-review-diff", "cr-tree-file", "code-review-search"]);
await page.keyboard.press("Shift+F6");
expect(await focused()).toBe("cr-tree-file");
// ] and [ step through the files from anywhere in the pane, and stop at the ends.
const current = () => page.locator('[data-testid="cr-tree-file"][aria-current="true"]').getAttribute("title");
expect(await current()).toBe(paths[0]);
await page.keyboard.press("]");
await expect.poll(current).toBe(paths[1]);
await expect(page.locator(`[data-testid="cr-file-section"][data-path="${paths[1]}"]`)).toBeFocused();
await page.keyboard.press("]"); await page.keyboard.press("]"); await page.keyboard.press("]");
await expect.poll(current).toBe(paths[3]);
await page.keyboard.press("[");
await expect.poll(current).toBe(paths[2]);
// In a text field the keys are text.
const filter = page.getByRole("textbox", { name: "Filter remote files" });
await filter.focus();
await page.keyboard.type("[x]");
await expect(filter).toHaveValue("[x]");
await filter.fill("");
await expect.poll(current, "typing brackets moved to no other file").toBe(paths[2]);
expect(await app.evaluate(() => (globalThis as any).__diff.local)).toEqual([]);
});

test("expanding context asks the exact remote revision and never a local file", async () => {
await open();
const section = tid(page, "cr-file-section").first();
Expand Down
9 changes: 8 additions & 1 deletion apps/desktop/e2e/code-review-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ test("the rail opens the inbox, and a row opens its PR with the PR and Changes t
await expect(inbox.getByRole("group", { name: "Authored by me" })).toBeVisible();
await expect(inbox.getByRole("group", { name: "Needs my review" })).toBeVisible();
await expect(row(page, "example-org", "lending", 73)).toContainText(R1.overview.title);
// The repository and number are drawn on the row, not kept for screen readers only: pull requests from many
// repositories share one list (real-use benchmark, F5). The owner completes the accessible name.
const rowId = row(page, "example-org", "lending", 73).getByTestId("code-review-row-id");
await expect(rowId).toHaveText("lending #73");
expect((await rowId.boundingBox())!.width, "drawn at its own width, not clipped to a pixel").toBeGreaterThan(40);
await expect(row(page, "example-org", "lending", 73)).toHaveAccessibleName(/example-org\/ ?lending #73 · /);
await row(page, "example-org", "lending", 73).click();
await expect(row(page, "example-org", "lending", 73)).toHaveAttribute("aria-current", "true");
const prTab = tid(page, "code-review-tab-overview");
Expand Down Expand Up @@ -387,7 +393,8 @@ test("pin, copy and Open in GitHub use the canonical link, a pasted link opens i
await settle(page);
expect((await log(app)).filter((r) => r.requestId !== "settle").length).toBe(asked);
await expect(tid(page, "code-review-review").first()).toHaveAttribute("aria-disabled", "true");
await expect(tid(page, "code-review-new-tab").first()).toHaveAttribute("aria-disabled", "true");
// C07 (decision 6, 2026-11-04): this surface has no new-tab control.
await expect(tid(page, "code-review-new-tab")).toHaveCount(0);
// Pins outlive a reload, per account, and open their PR.
await page.reload();
await tid(page, "rail-code-review").click();
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop/e2e/code-review-overview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function open(hostile = false, mode = "normal") {
const failed = { state: "unavailable", reason: "offline", fetchedAt: NOW };
const overview = structuredClone(req.key?.number === 91 ? R4.overview : R1.overview);
if (g.__overviewMode === "renamed") overview.locator = { ...overview.locator, owner: "current-org", repo: "lending-renamed" };
if (hostile) overview.body = '# Hostile fixture\n\n<script>window.__pwned=true</script>\n\n[bad](javascript:alert(1))\n\n![remote](https://invalid.example/tracker.svg)\n\n[Safe](https://example.com/path)';
if (hostile) overview.body = '# Hostile fixture\n\n<script>window.__pwned=true</script>\n\n[bad](javascript:alert(1))\n\n![remote](https://invalid.example/tracker.svg)\n\n[Safe](https://example.com/path)\n\n<picture><source media="(prefers-color-scheme: dark)" srcset="https://invalid.example/dark.svg"><img src="https://invalid.example/light.png" alt="Medium severity" width="62"></picture> Contrast gate\n\n<a href="https://evil.example/login">visible words</a> and `<img alt="kept in code">`';
let result: unknown = failed;
if (req.op === "connection") result = R1.connection;
if (req.op === "inbox") result = R1.inbox;
Expand Down Expand Up @@ -136,6 +136,12 @@ test("hostile Markdown is inert and narrow content remains reachable", async ()
await expect(description).toContainText("<script>");
await expect(description.locator("script,img,iframe,svg")).toHaveCount(0);
await expect(description.locator('a[href^="javascript:"]')).toHaveCount(0);
// Bot-style HTML reads as its text: no source, no element, no hidden destination; code stays as written.
await expect(description).toContainText("Image: Medium severity Contrast gate");
await expect(description).toContainText("visible words and <img alt=\"kept in code\">");
await expect(description).not.toContainText("<picture");
await expect(description).not.toContainText("srcset");
await expect(description.locator('picture,source,a[href*="evil.example"]')).toHaveCount(0);
expect(await page.evaluate(() => (window as any).__pwned)).toBeUndefined();
await page.getByRole("button", { name: "Load more activity" }).click();
const comment = page.getByRole("button", { name: "Comment", exact: true });
Expand Down
11 changes: 2 additions & 9 deletions apps/desktop/e2e/code-review-regressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,8 @@ for (const delayed of [false, true]) test(`dispatch: unavailable actions start n
await page.keyboard.press("Escape");
await expect(page.getByRole("dialog", { name: "Review instructions" })).toHaveCount(0);
// Merge is CR-7's now (e2e/code-review-actions.spec.ts): opening it reads, and only an explicit preview and confirm writes.
for (const id of ["code-review-new-tab"]) {
const control = tid(page, id).first();
await expect(control, id).toHaveAttribute("aria-disabled", "true");
// aria-disabled, not disabled: it stays focusable, so force the pointer through to prove it does nothing.
await control.dblclick({ force: true });
await control.focus();
await page.keyboard.press("Enter");
await page.keyboard.press("Space");
}
// C07 (decision 6, 2026-11-04): the new-tab control is gone from this surface.
await expect(tid(page, "code-review-new-tab")).toHaveCount(0);
await expect(tid(page, "code-review-pr-id").first()).toHaveText("lending #73");
await settle(page);
// The settle reads are connection checks; nothing else reached gh, and no provider CLI started.
Expand Down
Loading
Loading