The best way to control Claude Code, Codex and more from any computer or phone

main
ts 90 lines 3.32 KB
Raw
1 /// <reference lib="dom" />
2 import type { GitResolvePullRequestResult } from "@t3tools/contracts";
3 import { expect } from "e2e";
4
5 import { test, WEB } from "./t3.ts";
6
7 test(
8 "A failed local checkout does not show its error on another pull request",
9 WEB,
10 async ({ t3, app, browser, screen }) => {
11 await t3.project("demo");
12 await browser.setViewport({ width: 1280, height: 800 });
13 await browser.addInitScript(() => {
14 const send = WebSocket.prototype.send;
15 WebSocket.prototype.send = function (data) {
16 const request: {
17 _tag: string;
18 id: string;
19 tag: string;
20 payload: { cwd: string; reference: string };
21 } | null = typeof data === "string" ? JSON.parse(data) : null;
22 if (request?._tag !== "Request") return send.call(this, data);
23 const reply = (exit: unknown) =>
24 queueMicrotask(() =>
25 this.dispatchEvent(
26 new MessageEvent("message", {
27 data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }),
28 }),
29 ),
30 );
31 if (request.tag === "git.resolvePullRequest") {
32 const number = Number(request.payload.reference.replace(/^#/, ""));
33 const value: GitResolvePullRequestResult = {
34 pullRequest: {
35 number,
36 title: number === 42 ? "Update the release notes" : "Fix the status badge",
37 url: `https://github.com/example/demo/pull/${number}`,
38 baseBranch: "main",
39 headBranch: `change-${number}`,
40 state: "open",
41 },
42 };
43 reply({ _tag: "Success", value });
44 return;
45 }
46 if (request.tag === "git.preparePullRequestThread") {
47 reply({
48 _tag: "Failure",
49 cause: [
50 {
51 _tag: "Fail",
52 error: {
53 _tag: "GitManagerError",
54 operation: "preparePullRequestThread",
55 cwd: request.payload.cwd,
56 detail:
57 "This repository has uncommitted changes. Commit or stash them before checking out pull request #42 here, or check it out in its own folder.",
58 },
59 },
60 ],
61 });
62 return;
63 }
64 return send.call(this, data);
65 };
66 });
67
68 await t3.open("/");
69 await browser
70 .locator('[data-slot="combobox-trigger"][aria-label^="Branch:"]:visible')
71 .first()
72 .click();
73 await screen.getByPlaceholder("Search refs...").fill("#42");
74 const checkoutLabel = /Checkout (?:pull|change) request/i;
75 await screen.getByRole("option", checkoutLabel).tap();
76
77 const dialog = screen.getByRole("dialog", checkoutLabel);
78 await dialog.getByText("Update the release notes", { exact: true }).waitFor();
79 await dialog.getByRole("button", "Local", { exact: true }).tap();
80 const previousError = dialog.getByText(/before checking out pull request #42 here/);
81 await previousError.waitFor();
82 await dialog.getByRole("textbox").fill("#43");
83 await dialog.getByText("Fix the status badge", { exact: true }).waitFor();
84 await app.screenshot("second-pull-request");
85 expect(
86 await previousError.isVisible(),
87 "The second pull request does not display the first checkout error",
88 ).toBe(false);
89 },
90 );