Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/desktop/e2e/code-review-regressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,32 @@ test("local Changes stay local: a remote PR touching the same path never reaches
file: fs.readFileSync(path.join(repo, "src", "holds", "move.ts"), "utf8") }).toEqual(before);
expect(h.calls().filter((c) => !READ_ENDPOINT.test(c))).toEqual([]);
});

test("real use (F3): comments on lines of the diff are shown in Activity with their file and line, under the Comments filter, as inert text", async () => {
const world = baseWorld();
const who = { id: 3003, login: "bea-fixture", type: "User" };
// The base world lists no timeline: an empty one lets the activity read finish.
world.routes["repos/example-org/lending/issues/73/timeline"] = [];
world.routes["repos/example-org/lending/deployments"] = [];
world.routes["repos/example-org/lending/pulls/73/comments"] = [
{ id: 801, user: who, created_at: "2026-10-18T20:31:00Z", body: "Should this keep the position when the branch is closed?\n\n<script>window.__pwned=true</script>", path: "src/holds/move.ts", line: 41, side: "RIGHT" },
{ id: 802, user: who, created_at: "2026-10-18T20:32:00Z", body: "It does; see the closure test.", path: "src/holds/move.ts", line: 41, side: "RIGHT", in_reply_to_id: 801 },
{ id: 803, user: who, created_at: "2026-10-18T20:33:00Z", body: "This helper is gone now.", path: "src/holds/queue.ts", line: null, side: "LEFT" },
];
h = await launchWithGh(world);
const { page } = h;
await tid(page, "rail-code-review").click();
await prRow(page, "example-org/lending#73").click();
const activity = tid(page, "cr-activity");
const item = (id: number) => activity.locator(`[data-activity-id="line-comment:${id}"]`);
await expect(item(801)).toContainText("commented on src/holds/move.ts · line 41");
await expect(item(801)).toContainText("Should this keep the position when the branch is closed?");
await expect(item(802)).toContainText("replied on src/holds/move.ts · line 41");
await expect(item(803)).toContainText("commented on src/holds/queue.ts · line no longer in the diff");
await page.getByLabel("Activity filter").selectOption("comment");
await expect(activity.locator('[data-activity-id^="line-comment:"]')).toHaveCount(3);
await expect(activity.locator('[data-activity-id^="commit:"]')).toHaveCount(0);
expect(await page.evaluate(() => (window as unknown as { __pwned?: boolean }).__pwned)).toBeUndefined();
expect(h.calls().filter((c) => c.startsWith("repos/example-org/lending/pulls/73/comments"))).toEqual(["repos/example-org/lending/pulls/73/comments?per_page=100&page=1"]);
expect(h.calls().filter((c) => !READ_ENDPOINT.test(c) && !c.startsWith("repos/example-org/lending/deployments?"))).toEqual([]);
});
2 changes: 1 addition & 1 deletion apps/desktop/e2e/code-review-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const prRow = (p: Page, slug: string) => p.locator(`[data-testid="code-re
export const settle = (p: Page) => p.evaluate(() => window.modex!.invoke("code-review:read", { op: "connection", requestId: `settle-${Date.now()}` }));

/** Every endpoint the read service may ask for (docs/design/code-review.md, Read operations). */
export const READ_ENDPOINT = /^(user|search\/issues\?[^/]+|repos\/[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+(\/(pulls(\/\d+(\/files)?)?|compare\/[0-9a-f]{40}\.\.\.[0-9a-f]{40}|issues\/\d+\/timeline|commits\/[0-9a-f]{40}\/(check-runs|status)|contents\/[^?]+))?(\?[^/]*)?)$/;
export const READ_ENDPOINT = /^(user|search\/issues\?[^/]+|repos\/[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+(\/(pulls(\/\d+(\/(files|comments))?)?|compare\/[0-9a-f]{40}\.\.\.[0-9a-f]{40}|issues\/\d+\/timeline|commits\/[0-9a-f]{40}\/(check-runs|status)|contents\/[^?]+))?(\?[^/]*)?)$/;

/**
* resizeWindow, but within the display. These launches can't set MODEX_E2E (it disables the read service), so
Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src/main/engine/code-review/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ export function hasNext(header: string | undefined): boolean {
return typeof header === "string" && /<[^>]+>;\s*rel="next"/.test(header);
}

/** One comment on a line of the diff, from `pulls/{n}/comments`. Null when malformed. */
export function lineComment(value: unknown): Extract<PrActivity, { kind: "line-comment" }> | null {
const item = object(value);
const commentId = id(item?.id), at = time(item?.created_at), who = actor(item?.user);
if (!item || !commentId || !at || !who || typeof item.path !== "string" || !item.path || item.path.length > 4096) return null;
const line = count(item.line) || null;
return { kind: "line-comment", id: commentId, at, actor: who, body: text(item.body, 262_144), path: item.path, line,
side: item.side === "LEFT" ? "LEFT" : "RIGHT", replyTo: id(item.in_reply_to_id) };
}

/** Provider deployment + its latest status; a comment URL never enters this mapping. */
export function deployment(value: unknown, latest: unknown): Extract<PrActivity, { kind: "deployment" }> | null {
const record = object(value), status = object(latest);
Expand Down
33 changes: 29 additions & 4 deletions apps/desktop/src/main/engine/code-review/read-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type PrStack, type PrActivity, type PrCheck, type PrContext, type PrFiles, type PrKey, type PrOverview, type PrRevision, type PrSummary, type ReadResult, type ResolvedPr, type Unavailable,
} from "../../../shared/code-review.js";
import { ghHostsStamp, ghTransport, type GhAnswer, type GhCall, type GhTransport } from "./gh.js";
import { deployment, changedFile, checkRun, commitStatus, hasNext, json, pull, repository, searchRow, timeline, type Pull, type Repository } from "./github.js";
import { deployment, lineComment, changedFile, checkRun, commitStatus, hasNext, json, pull, repository, searchRow, timeline, type Pull, type Repository } from "./github.js";

/**
* Main's Code Review reads (#321): narrow GETs through the person's `gh` login, each bound to the
Expand Down Expand Up @@ -794,9 +794,10 @@ export class CodeReviewService {
if (pr) {
activity.unshift({ kind: "opened", id: `pr-${pr.id}`, at: pr.createdAt, actor: pr.author });
// Asked only once the timeline has arrived: a failed timeline costs GitHub no further request.
const read = await this.deployments(context, key, pr);
activity.push(...read.records);
deploymentFailure = read.failure;
// Line comments are not in the timeline; they are their own list. Both reads run together.
const [read, comments] = await Promise.all([this.deployments(context, key, pr), this.lineComments(context, key)]);
activity.push(...read.records, ...comments.records);
deploymentFailure = read.failure ?? comments.failure;
}
const more = hasNext(fetched.headers.link);
const next = more && number < TIMELINE_PAGES ? `p${number + 1}` : null;
Expand All @@ -809,6 +810,30 @@ export class CodeReviewService {
return { state: "ready", value: activity, fetchedAt, coverage };
}

/**
* The first page of comments on lines of the diff (100, oldest first). A failure is reported, not thrown,
* unless the read was cancelled or the account is gone; more than one page is reported as capped.
*/
private async lineComments(context: Context, key: PrKey): Promise<{ records: PrActivity[]; failure: Unavailable | "capped" | null }> {
const records: PrActivity[] = [];
let failure: Unavailable | "capped" | null = null;
try {
const fetched = await this.get(context, `${repoPath(this.repoFor(key))}/pulls/${key.number}/comments?per_page=${PAGE}&page=1`, { maxBytes: 8 * MB });
const listed: unknown = json(fetched.body);
if (!Array.isArray(listed)) throw new ReadFailure("failed", DETAIL.failed);
if (hasNext(fetched.headers.link)) failure = "capped";
for (const item of listed.slice(0, PAGE)) {
const mapped = lineComment(item);
if (mapped) records.push(mapped); else failure = "failed";
}
} catch (error) {
const caught = this.failure(error);
if (caught.cancelled || caught.reason === "signed-out") throw error;
failure = caught.reason;
}
return { records, failure };
}

/**
* A bounded current-head preview read, independent of arbitrary links in bot comments. Endpoint strings are
* built from main's repository and numeric provider IDs only. A failure is reported, not thrown, unless the
Expand Down
Loading
Loading