Skip to content
Merged
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
89 changes: 86 additions & 3 deletions apps/desktop/e2e/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,20 @@ test("accessibility: information text meets AA contrast, keyboard focus is visib

// Truncated titles and shortcut-bearing rows explain themselves on hover.
const rowTitle = await tid(currentRow(page), "thread-row-title").innerText();
await expect(currentRow(page).getByRole("button").first()).toHaveAccessibleName(rowTitle);
await currentRow(page).getByRole("button").first().focus();
const rowButton = currentRow(page).getByRole("button").first();
await expect(rowButton).toHaveAccessibleName(rowTitle);
await rowButton.focus();
await page.keyboard.press("ArrowRight");
await expect(page.getByRole("dialog", { name: "Chat details" })).toContainText(rowTitle);
// The pointer can still inspect another row: follow this keyboard control's actual association.
await expect(rowButton).toHaveAttribute("aria-controls", /\S/);
const details = page.locator(`[id=${JSON.stringify(await rowButton.getAttribute("aria-controls"))}]`);
await expect(details).toHaveRole("dialog");
await expect(details).toHaveAccessibleName("Chat details");
await expect(details).toContainText(rowTitle);
await expect(details.locator("summary")).toBeFocused();
await page.keyboard.press("Escape");
await expect(details).toHaveCount(0);
await expect(rowButton).toBeFocused();
await expect(tid(page, "new-chat")).toHaveAttribute("title", /⌘N/);

// Spinners and the thinking shimmer stop when the OS asks for reduced motion.
Expand All @@ -799,3 +808,77 @@ test("accessibility: information text meets AA contrast, keyboard focus is visib
expect(await spin()).toBe("none");
await page.emulateMedia({ reducedMotion: "no-preference" });
});

test("a menu rename belongs to that chat and never opens editing on a later chat", async () => {
await createThread(page, "Rename intent seed");
await tid(page, "thread-menu-toggle").click();
await tid(page, "action-rename").click();
const title = tid(page, "thread-title");
await expect(title).not.toHaveAttribute("readonly", "");
await title.fill("Explicitly renamed seed");
await title.press("Enter");
await expect(title).toHaveAttribute("readonly", "");
await expect(tid(currentRow(page), "thread-row-title")).toHaveText("Explicitly renamed seed");
const later = await createThread(page, "Later chat fixture");
await expect(title).toHaveAttribute("readonly", "");
const readLater = () => page.evaluate(async (id) => (await window.modex!.invoke("state:get", undefined)).threads.find(x => x.id === id), later);
const beforeBlur = await readLater();
expect(beforeBlur).toBeDefined();
expect(beforeBlur!.titleSource, "a later chat was not manually renamed").not.toBe("manual");
await expect(title).toHaveValue(beforeBlur!.title);
await tid(page, "composer-input").focus();
expect(await readLater()).toMatchObject({ id: later, title: beforeBlur!.title, titleSource: beforeBlur!.titleSource });

// A later mount still accepts new edit commands through every entry point.
await tid(page, "thread-menu-toggle").click();
await tid(page, "action-rename").click();
await expect(title).not.toHaveAttribute("readonly", "");
await title.fill("Later explicitly renamed");
await title.press("Enter");
await expect(title).toHaveAttribute("readonly", "");
await expect(title).toHaveValue("Later explicitly renamed");
await title.dblclick();
await expect(title).not.toHaveAttribute("readonly", "");
await title.fill("Cancelled later title");
await title.press("Escape");
await expect(title).toHaveAttribute("readonly", "");
await expect(title).toHaveValue("Later explicitly renamed");
await title.focus();
await title.press("Enter");
await expect(title).not.toHaveAttribute("readonly", "");
await title.fill("Later keyboard renamed");
await title.press("Enter");
await expect(title).toHaveAttribute("readonly", "");
await expect(title).toHaveValue("Later keyboard renamed");
expect(await readLater()).toMatchObject({ id: later, title: "Later keyboard renamed", titleSource: "manual" });
});

test("keyboard chat details follows its associated card while another chat is hovered", async () => {
await page.mouse.move(0, 0);
await page.keyboard.press("Escape");
await expect(page.getByRole("dialog", { name: "Chat details" })).toHaveCount(0);
const pointerId = await createThread(page, "Pointer details fixture");
const keyboardId = await createThread(page, "Keyboard details fixture");
// Other cases may change automatic naming; these two identities are fixture inputs, not title tests.
await page.evaluate(async ([pointerId, keyboardId]) => {
await window.modex!.invoke("thread:update", { threadId: pointerId!, patch: { title: "Pointer details fixture" } });
await window.modex!.invoke("thread:update", { threadId: keyboardId!, patch: { title: "Keyboard details fixture" } });
}, [pointerId, keyboardId]);
const pointer = page.locator(`[data-testid="thread-row"][data-thread-id="${pointerId}"]`);
const keyboard = page.locator(`[data-testid="thread-row"][data-thread-id="${keyboardId}"]`).getByRole("button").first();
await expect(keyboard).toHaveAccessibleName("Keyboard details fixture");
await pointer.hover();
await expect(page.getByRole("dialog", { name: "Chat details" })).toHaveCount(1);
await keyboard.focus();
await page.keyboard.press("ArrowRight");
await expect(keyboard).toHaveAttribute("aria-controls", /\S/);
const details = page.locator(`[id=${JSON.stringify(await keyboard.getAttribute("aria-controls"))}]`);
await expect(details).toHaveRole("dialog");
await expect(details).toHaveAccessibleName("Chat details");
await expect(details).toContainText("Keyboard details fixture");
await expect(details).not.toContainText("Pointer details fixture");
await expect(details.locator("summary")).toBeFocused();
await page.keyboard.press("Escape");
await expect(details).toHaveCount(0);
await expect(keyboard).toBeFocused();
});
117 changes: 116 additions & 1 deletion apps/desktop/e2e/code-review-regressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "node:path";
import { tid } from "./support.js";
import { baseWorld, FIELD_GUIDE, fitWindow, launchWithGh, LENDING, prRow, READ_ENDPOINT, settle, type Harness } from "./code-review-support.js";
import { ghFile, ghPull, ghRepo, ghRow, sha } from "../test/fixtures/code-review-gh-world.js";
import type { CodeReviewReply, CodeReviewRequest, Inbox, PrKey, PrOverview } from "../src/shared/code-review.js";
import type { CodeReviewReply, CodeReviewRequest, Inbox, PrKey, PrOverview, PrRevision } from "../src/shared/code-review.js";

/**
* CR-8 (#327) cross-slice regressions: the CR-3 renderer over CR-2's production read service, in real Electron,
Expand Down Expand Up @@ -165,6 +165,121 @@ test("incomplete data: a timed-out search, a hidden repository, a short files li
expect(JSON.stringify(files)).not.toContain("SENTINEL");
});

function revocationWorld() {
const world = baseWorld();
world.routes["repos/example-org/lending/pulls/73"] = ghPull(LENDING, 73, "Private review", { body: "CR_REVOKED_PRIVATE_BODY", files: 1 });
world.routes["repos/example-org/lending/pulls/73/files"] = [ghFile("src/private.ts", "@@ -1 +1 @@\n-before\n+CR_REVOKED_PATCH", 1, 1)];
world.routes["repos/example-org/lending/contents/src/private.ts"] = { status: 200, raw: "CR_REVOKED_CONTEXT\n" };
world.routes["repos/example-org/lending/issues/73/timeline"] = [];
world.routes["repos/example-org/lending/deployments"] = [];
world.routes[`repos/example-org/lending/commits/${sha("c")}/check-runs`] = { total_count: 0, check_runs: [] };
world.routes[`repos/example-org/lending/commits/${sha("c")}/status`] = { total_count: 0, statuses: [] };
return world;
}

function revocationReads(key: PrKey, revision: PrRevision): CodeReviewRequest[] {
return [
{ op: "overview", requestId: "revoke-overview", key },
{ op: "resolve", requestId: "revoke-resolve", input: "https://github.com/example-org/lending/pull/73" },
{ op: "context", requestId: "revoke-context", key, revision, side: "head", path: "src/private.ts", start: 1, end: 1 },
{ op: "activity", requestId: "revoke-activity", key, cursor: null },
{ op: "checks", requestId: "revoke-checks", key, revision },
{ op: "files", requestId: "revoke-files", key, revision, cursor: null },
];
}

for (const status of [403, 404, 410]) test(`revoked access ${status}: an accessible PR never returns kept private reads after denial and a network failure`, async () => {
h = await launchWithGh(revocationWorld());
const { page } = h;
await tid(page, "rail-code-review").click();
await prRow(page, "example-org/lending#73").click();
await expect(tid(page, "code-review-overview-body")).toContainText("CR_REVOKED_PRIVATE_BODY");
const key = await keyOf("example-org/lending#73");
const overview = await invoke({ op: "overview", requestId: "revoke-initial", key });
if (overview.result.state !== "ready") throw new Error("accessible overview not ready");
const revision = (overview.result.value as PrOverview).revision;
const reads = revocationReads(key, revision);
for (const request of reads) expect((await invoke(request)).result.state, request.op).toBe("ready");
const other = await keyOf("example-org/field-guide#73");
const otherRead: CodeReviewRequest = { op: "overview", requestId: "revoke-unrelated", key: other };
expect((await invoke(otherRead)).result.state).toBe("ready");
// Positive control: a failed network read really reaches main's same-account kept-answer path.
h.world((w) => { w.offline = true; });
expect((await invoke(otherRead)).result).toMatchObject({ state: "stale", reason: "offline" });
h.world((w) => {
w.offline = false;
w.routes["repos/example-org/lending/pulls/73"] = { status, body: { message: "No longer accessible" }, stderr: "gh: ghp_REVOKED_DIAGNOSTIC_SENTINEL denied\n" };
});
await tid(page, "code-review-inbox-menu").click();
await tid(page, "code-review-refresh").click();
await expect(tid(page, "code-review-overview-error")).toBeVisible();
await expect(tid(page, "code-review-overview-body")).not.toContainText("CR_REVOKED_PRIVATE_BODY");
expect(await page.content()).not.toContain("REVOKED_DIAGNOSTIC_SENTINEL");
const denial = await invoke({ op: "overview", requestId: `revoke-denial-${status}`, key });
expect(denial.result).toMatchObject({ state: "unavailable", reason: status === 403 ? "denied" : "not-found" });
expect(JSON.stringify(denial)).not.toMatch(/CR_REVOKED_(PRIVATE_BODY|CONTEXT|PATCH)|REVOKED_DIAGNOSTIC_SENTINEL/);
h.world((w) => { w.offline = true; });
for (const request of reads) {
const denied = await invoke(request);
expect(denied.result.state, request.op).toBe("unavailable");
expect(JSON.stringify(denied), request.op).not.toMatch(/CR_REVOKED_(PRIVATE_BODY|CONTEXT|PATCH)|REVOKED_DIAGNOSTIC_SENTINEL/);
}
expect((await invoke(otherRead)).result).toMatchObject({ state: "stale", reason: "offline" });
await tid(page, "code-review-overview-error").getByRole("button", { name: "Retry" }).click();
await expect(tid(page, "code-review-overview-error")).toContainText("Check the network connection");
await expect(tid(page, "code-review-overview-body")).not.toContainText("CR_REVOKED_PRIVATE_BODY");
expect(await page.content()).not.toContain("REVOKED_DIAGNOSTIC_SENTINEL");
expect(h.providerStarts()).toEqual([]);
expect(h.posts()).toEqual([]);
expect(h.calls().filter((call) => /^(POST|PUT|PATCH|DELETE) /.test(call))).toEqual([]);
});

test("revoked access: a held private context response cannot return after the accessible PR is denied", async () => {
h = await launchWithGh(revocationWorld());
const key = await keyOf("example-org/lending#73");
const overview = await invoke({ op: "overview", requestId: "held-revoke-overview", key });
if (overview.result.state !== "ready") throw new Error("accessible overview not ready");
const revision = (overview.result.value as PrOverview).revision;
const request: CodeReviewRequest = { op: "context", requestId: "held-revoke-context", key, revision, side: "head", path: "src/private.ts", start: 1, end: 1 };
const content = "repos/example-org/lending/contents/src/private.ts";
h.world((w) => { w.holds = { [content]: "private-context" }; });
const during = invoke(request);
await expect.poll(() => h.calls().filter((call) => call.startsWith(content + "?")).length).toBe(1);
h.world((w) => { w.routes["repos/example-org/lending/pulls/73"] = { status: 403, body: { message: "No longer accessible" }, stderr: "gh: ghp_REVOKED_DIAGNOSTIC_SENTINEL denied\n" }; });
const denial = await invoke({ op: "overview", requestId: "held-revoke-denial", key });
expect(denial.result).toMatchObject({ state: "unavailable", reason: "denied" });
h.release("private-context");
const late = await during;
expect(late.result).toMatchObject({ state: "unavailable", reason: "denied" });
expect(JSON.stringify([denial, late])).not.toMatch(/CR_REVOKED_(PRIVATE_BODY|CONTEXT)|REVOKED_DIAGNOSTIC_SENTINEL/);
h.world((w) => { w.offline = true; });
const after = await invoke({ ...request, requestId: "held-revoke-offline" });
expect(after.result.state).toBe("unavailable");
expect(JSON.stringify(after)).not.toContain("CR_REVOKED_CONTEXT");
expect(await h.page.content()).not.toContain("REVOKED_DIAGNOSTIC_SENTINEL");
expect(h.providerStarts()).toEqual([]);
expect(h.posts()).toEqual([]);
expect(h.calls().filter((call) => /^(POST|PUT|PATCH|DELETE) /.test(call))).toEqual([]);
});

test("unsafe context paths: Electron IPC refuses traversal and disguised paths before starting a GitHub read", async () => {
h = await launchWithGh(revocationWorld());
const key = await keyOf("example-org/lending#73");
const overview = await invoke({ op: "overview", requestId: "unsafe-path-overview", key });
if (overview.result.state !== "ready") throw new Error("accessible overview not ready");
const revision = (overview.result.value as PrOverview).revision;
// A valid context proves the real handler is active before testing its input boundary.
const request: CodeReviewRequest = { op: "context", requestId: "unsafe-path-context", key, revision, side: "head", path: "src/private.ts", start: 1, end: 1 };
expect((await invoke(request)).result).toMatchObject({ state: "ready", value: { lines: ["CR_REVOKED_CONTEXT"] } });
const before = h.calls();
for (const path of ["/etc/passwd", "docs/../../secrets", "./src/private.ts", "src//private.ts", "src/a\u0000b", "src/\u202eprivate.ts", "src/pri\u200dvate.ts", "src/\ud800.ts"]) {
await expect(invoke({ ...request, path })).rejects.toThrow(/Invalid Code Review request/);
}
expect(h.calls()).toEqual(before);
expect(h.providerStarts()).toEqual([]);
expect(h.posts()).toEqual([]);
});

test("hostile content: PR text renders inert, and unsafe or look-alike links never resolve, open or navigate", async () => {
const world = baseWorld();
const hostile = `<img src=x onerror="document.title='pwned'"> Fix ‮gnp.exe‬ <script>document.title='pwned'</script> [x](javascript:alert(1))`;
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/e2e/human-requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ for (const moveFocus of [false, true]) test(`a native question preserves the exi
const transcript = JSON.parse(fs.readFileSync(path.join(home, "app/threads", `${threadId}.json`), "utf8"));
expect(transcript.filter((item: { kind: string }) => item.kind === "user").map((item: { text: string }) => item.text)).toEqual(["deploy it"]);
expect(replies(logs)).toHaveLength(1);
await app.close();
app = undefined;
expect(everything(path.join(home, "app"))).not.toContain("question-only-secret");
} finally { await app?.close(); fs.rmSync(logs, { recursive: true, force: true }); }
});
Expand Down Expand Up @@ -242,6 +244,8 @@ test("Codex questions: the card answers by its schema, the CLI hears once, the s
await expect.poll(() => replies(logs).length).toBe(2);
expect(replies(logs)[1]).toMatchObject({ request: 902, error: { code: -32000 } });

await app.close();
app = undefined;
// Nothing Modex saved (threads, journal, state) holds the secret.
expect(everything(path.join(home, "app")).includes("s3cr3t-token")).toBe(false);
} finally {
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop/src/renderer/components/TitleBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ function ThreadTitle({ title, onRename, renameSignal }: { title: string; onRenam
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState(title);
const input = useRef<HTMLInputElement>(null);
useEffect(() => { if (renameSignal > 0) setEditing(true); }, [renameSignal]);
// A menu command applies to the mounted title, never to a later thread.
const seenRenameSignal = useRef(renameSignal);
useEffect(() => {
if (renameSignal === seenRenameSignal.current) return;
seenRenameSignal.current = renameSignal;
setEditing(true);
}, [renameSignal]);
useEffect(() => { if (!editing) setDraft(title); }, [title, editing]);
useEffect(() => { if (editing) { input.current?.focus(); input.current?.select(); } }, [editing]);

Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/test/fixtures/code-review-gh-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// (PUT …/pulls/N/merge) is recorded the same way, and the PR then reads as merged by the account;
// so are a PATCH of the PR, a reviewer request and the two draft mutations, which the PR then shows.
export interface GhWorld {
/** Fail API reads as network failures while retaining the same synthetic signed-in identity. */
offline?: boolean;
/** `gh api user`; null answers as gh does when nobody is signed in (exit 4). */
user: { id: number; login: string } | null;
/** Search rows per group, before the person's text and paging narrow them. */
Expand Down Expand Up @@ -44,6 +46,10 @@ const read = () => JSON.parse(fs.readFileSync(process.env.FAKE_GH_WORLD, "utf8")
const wait = (hold) => { const released = hold && require("node:path").join(process.env.FAKE_GH_HOLDS, hold); if (released) { const flag = new Int32Array(new SharedArrayBuffer(4)); while (!fs.existsSync(released)) Atomics.wait(flag, 0, 0, 25); } };
wait((read().holds || {})[route]);
const world = read();
if (world.offline && method === "GET" && route !== "user") {
process.stderr.write("dial tcp: network is unreachable\n");
process.exit(1);
}
const postsFile = process.env.FAKE_GH_POSTS;
const posts = () => postsFile && fs.existsSync(postsFile) ? fs.readFileSync(postsFile, "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l)) : [];
const reason = { 200: "OK", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone" };
Expand Down
Loading
Loading