Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pull-requests-keep-failed-continuation.e2e.ts

158 lines6.2 KB

1/// <reference lib="dom" />
2import type { PullRequestListInput, PullRequestListResult, ProjectId } from "@t3tools/contracts";
3import { expect } from "e2e";
4​
5import { SECOND_HOME, startSecondServer } from "./second-server.ts";
6import { makeState, test, WEB } from "./t3.ts";
7​
8test(
9 "Loading more pull requests keeps a failed environment available for retry",
10 WEB,
11 async ({ t3, app, screen, browser }) => {
12 await t3.project("demo");
13 const server = startSecondServer(app.baseUrl ?? "");
14 try {
15 const { host, token } = await server.ready;
16 await makeState(SECOND_HOME).state.project("remote-demo");
17 await browser.addInitScript((remoteHost) => {
18 let remoteAvailable = false;
19 document.addEventListener("restore-pull-request-listing", () => {
20 remoteAvailable = true;
21 });
22 const date = "2026-10-01T00:00:00.000Z";
23 const provider = "github" as PullRequestListResult["providers"][number]["kind"];
24 const list = (remote: boolean, page: number, partition: boolean): PullRequestListResult => {
25 const repository = remote ? "example/remote-demo" : "example/demo";
26 const projectTitle = remote ? "remote-demo" : "demo";
27 const projectId = projectTitle as ProjectId;
28 const number = (remote ? 200 : 100) - page;
29 const title = remote
30 ? ["Linked pull request", "Older linked pull request"][page]!
31 : ["Local pull request", "Older local pull request", "Oldest local pull request"][
32 page
33 ]!;
34 const hasMore = !partition && page < (remote ? 1 : 2);
35 return {
36 entries: partition
37 ? []
38 : [
39 {
40 provider,
41 host: "github.com",
42 repository,
43 projectId,
44 projectTitle,
45 number,
46 title,
47 url: "https://github.com/" + repository + "/pull/" + number,
48 author: null,
49 headBranch: "review-" + number,
50 baseBranch: "main",
51 state: "open",
52 isDraft: false,
53 mergeability: "unknown",
54 additions: 0,
55 deletions: 0,
56 createdAt: date,
57 updatedAt: date,
58 viewerReviewRequested: false,
59 labels: [],
60 },
61 ],
62 errors: [],
63 nextCursors: hasMore ? { ["github.com " + repository]: String(page + 1) } : {},
64 viewers: {},
65 providers: [
66 {
67 host: "github.com",
68 kind: provider,
69 searchesOnHost: true,
70 projectCount: 1,
71 configured: true,
72 detail: null,
73 },
74 ],
75 truncated: hasMore,
76 };
77 };
78 const send = WebSocket.prototype.send;
79 WebSocket.prototype.send = function (data) {
80 const request: {
81 _tag: string;
82 id: string;
83 tag: string;
84 payload: PullRequestListInput;
85 } | null = typeof data === "string" ? JSON.parse(data) : null;
86 if (request?._tag !== "Request" || request.tag !== "pullRequests.list")
87 return send.call(this, data);
88 const remote = new URL(this.url).host === remoteHost;
89 const page = Number(Object.values(request.payload.cursors ?? {})[0] ?? 0);
90 const exit =
91 remote && page > 0 && !remoteAvailable
92 ? {
93 _tag: "Failure",
94 cause: [
95 {
96 _tag: "Fail",
97 error: {
98 _tag: "PullRequestOperationError",
99 operation: "list",
100 detail: "The linked environment could not load older pull requests.",
101 },
102 },
103 ],
104 }
105 : {
106 _tag: "Success",
107 value: list(
108 remote,
109 page,
110 request.payload.involvement !== undefined &&
111 request.payload.involvement !== "all",
112 ),
113 };
114 queueMicrotask(() =>
115 this.dispatchEvent(
116 new MessageEvent("message", {
117 data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }),
118 }),
119 ),
120 );
121 };
122 }, new URL(host).host);
123​
124 await t3.open("/settings/connections");
125 await screen.getByRole("button", "Add environment").tap();
126 const dialog = screen.getByRole("dialog");
127 await dialog.getByPlaceholder("backend.example.com").fill(host);
128 await dialog.getByPlaceholder("PAIRCODE").fill(token);
129 await dialog.getByRole("button", "Add environment").tap();
130 await screen.getByRole("heading", "Backend added", { exact: true }).waitFor();
131 await app.open("/pull-requests");
132​
133 await screen.getByText("Local pull request", { exact: true }).waitFor();
134 await screen.getByText("Linked pull request", { exact: true }).waitFor();
135 const loadMore = screen.getByRole("button", "Load more pull requests", { exact: true });
136 const retry = screen.getByRole("button", "Retry", { exact: true });
137 await loadMore.tap();
138 await screen.getByText("Older local pull request", { exact: true }).waitFor();
139 await retry.waitFor();
140 await expect(loadMore).toBeEnabled();
141 await loadMore.tap();
142 await screen.getByText("Oldest local pull request", { exact: true }).waitFor();
143 await browser.evaluate(() => {
144 document.dispatchEvent(new Event("restore-pull-request-listing"));
145 return null;
146 });
147 try {
148 await expect(retry).toBeVisible();
149 await retry.tap();
150 await expect(screen.getByText("Older linked pull request", { exact: true })).toBeVisible();
151 } finally {
152 await app.screenshot("pull-request-list-after-load-more");
153 }
154 } finally {
155 await server.stop();
156 }
157 },
158);