The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /// <reference lib="dom" /> |
| 2 | import type { IssueComment, IssueCommentsPage, IssueDetail, IssueRef } from "@t3tools/contracts"; |
| 3 | import { expect } from "e2e"; |
| 4 | |
| 5 | import { test, WEB } from "./t3.ts"; |
| 6 | |
| 7 | test( |
| 8 | "A page requested before refreshing an issue does not restore old comments", |
| 9 | WEB, |
| 10 | async ({ t3, app, browser, screen }) => { |
| 11 | await t3.project("demo"); |
| 12 | await browser.addInitScript(() => { |
| 13 | const pendingPage = new Promise<void>((resolve) => { |
| 14 | Object.assign(window, { releaseOldIssuePage: () => resolve() }); |
| 15 | }); |
| 16 | const comment = (id: string, body: string, day: string): IssueComment => ({ |
| 17 | id, |
| 18 | body, |
| 19 | author: null, |
| 20 | createdAt: `2026-10-${day}T00:00:00.000Z`, |
| 21 | url: null, |
| 22 | }); |
| 23 | let refreshed = false; |
| 24 | let pendingRefresh: Promise<void> | undefined; |
| 25 | Object.assign(window, { |
| 26 | armIssueRefresh: () => { |
| 27 | refreshed = true; |
| 28 | }, |
| 29 | holdIssueRefresh: () => { |
| 30 | const { promise, resolve } = Promise.withResolvers<void>(); |
| 31 | pendingRefresh = promise; |
| 32 | Object.assign(window, { releaseIssueRefresh: resolve }); |
| 33 | }, |
| 34 | }); |
| 35 | // Keep the real socket for all other RPCs. Supply three pages of an unchanged GitHub |
| 36 | // comment history and hold the last page until the refreshed detail has rendered. |
| 37 | const send = WebSocket.prototype.send; |
| 38 | WebSocket.prototype.send = function (data) { |
| 39 | const request: { |
| 40 | _tag: string; |
| 41 | id: string; |
| 42 | tag: string; |
| 43 | payload: IssueRef & { cursor?: string }; |
| 44 | } | null = typeof data === "string" ? JSON.parse(data) : null; |
| 45 | if (request?._tag !== "Request") return send.call(this, data); |
| 46 | const reply = (value: IssueDetail | IssueCommentsPage) => |
| 47 | this.dispatchEvent( |
| 48 | new MessageEvent("message", { |
| 49 | data: JSON.stringify({ |
| 50 | _tag: "Exit", |
| 51 | requestId: request.id, |
| 52 | exit: { _tag: "Success", value }, |
| 53 | }), |
| 54 | }), |
| 55 | ); |
| 56 | if (request.tag === "issues.detail") { |
| 57 | const { projectId, tracker, scope, key } = request.payload; |
| 58 | const detail: IssueDetail = { |
| 59 | projectId, |
| 60 | tracker, |
| 61 | scope, |
| 62 | key, |
| 63 | host: "github.com", |
| 64 | displayKey: "#42", |
| 65 | projectTitle: "demo", |
| 66 | title: refreshed ? "Pagination issue after refresh" : "Pagination issue", |
| 67 | body: "Comment history", |
| 68 | url: "https://github.com/example/demo/issues/42", |
| 69 | author: null, |
| 70 | state: { category: "open", name: "Open" }, |
| 71 | createdAt: "2026-10-01T00:00:00.000Z", |
| 72 | updatedAt: "2026-10-04T00:00:00.000Z", |
| 73 | closedAt: null, |
| 74 | assignees: [], |
| 75 | labels: [], |
| 76 | commentCount: 201, |
| 77 | writable: false, |
| 78 | capabilities: { |
| 79 | create: false, |
| 80 | edit: false, |
| 81 | comment: false, |
| 82 | labels: false, |
| 83 | assignees: false, |
| 84 | reactions: false, |
| 85 | templates: false, |
| 86 | linkedPullRequests: false, |
| 87 | events: false, |
| 88 | search: true, |
| 89 | }, |
| 90 | viewerPermissions: { |
| 91 | setState: false, |
| 92 | comment: false, |
| 93 | edit: false, |
| 94 | labels: false, |
| 95 | assignees: false, |
| 96 | }, |
| 97 | states: [], |
| 98 | viewer: null, |
| 99 | comments: [comment("newest", "Newest comment", "04")], |
| 100 | commentsCursor: "first-older-page", |
| 101 | events: [], |
| 102 | linkedPullRequests: [], |
| 103 | }; |
| 104 | if (pendingRefresh) { |
| 105 | void pendingRefresh.then(() => reply(detail)); |
| 106 | pendingRefresh = undefined; |
| 107 | return; |
| 108 | } |
| 109 | queueMicrotask(() => reply(detail)); |
| 110 | } else if (request.tag === "issues.comments") { |
| 111 | if (request.payload.cursor === "first-older-page") { |
| 112 | queueMicrotask(() => |
| 113 | reply({ |
| 114 | comments: [comment("older", "First older comment", "03")], |
| 115 | nextCursor: "last-page", |
| 116 | }), |
| 117 | ); |
| 118 | } else if (request.payload.cursor === "last-page") { |
| 119 | void pendingPage.then(() => |
| 120 | reply({ |
| 121 | comments: [comment("oldest", "Oldest comment", "02")], |
| 122 | nextCursor: null, |
| 123 | }), |
| 124 | ); |
| 125 | } else return send.call(this, data); |
| 126 | } else return send.call(this, data); |
| 127 | }; |
| 128 | }); |
| 129 | |
| 130 | await t3.open("/issues?selectedProjectId=demo&tracker=github&scope=example/demo&key=42"); |
| 131 | const loadOlder = screen.getByRole("button", "Load older comments", { exact: true }); |
| 132 | // The issues route compiles on first open, which can outlast the 30 s action timeout. |
| 133 | await loadOlder.waitFor({ timeout: 60_000 }); |
| 134 | await loadOlder.tap(); |
| 135 | await screen.getByText("First older comment", { exact: true }).waitFor(); |
| 136 | await loadOlder.tap(); |
| 137 | const loading = screen.getByRole("button", "Loading…", { exact: true }); |
| 138 | await loading.waitFor(); |
| 139 | await browser.evaluate(() => { |
| 140 | (window as unknown as { armIssueRefresh: () => void }).armIssueRefresh(); |
| 141 | return null; |
| 142 | }); |
| 143 | await screen.getByRole("button", "Refresh issue", { exact: true }).tap(); |
| 144 | await screen.getByText("Pagination issue after refresh", { exact: true }).waitFor(); |
| 145 | |
| 146 | await browser.evaluate(() => { |
| 147 | (window as unknown as { releaseOldIssuePage: () => void }).releaseOldIssuePage(); |
| 148 | return null; |
| 149 | }); |
| 150 | const activity = 'section[aria-label^="Activity"]'; |
| 151 | await loading.waitFor({ state: "hidden" }); |
| 152 | await browser.evaluate((selector) => { |
| 153 | document.querySelector(selector)?.scrollIntoView({ block: "start" }); |
| 154 | return null; |
| 155 | }, activity); |
| 156 | await app.screenshot("activity-after-refresh-and-late-page"); |
| 157 | await expect(browser.locator(activity)).not.toContainText("First older comment"); |
| 158 | |
| 159 | await browser.evaluate(() => { |
| 160 | (window as unknown as { holdIssueRefresh: () => void }).holdIssueRefresh(); |
| 161 | return null; |
| 162 | }); |
| 163 | const refresh = screen.getByRole("button", "Refresh issue", { exact: true }); |
| 164 | await refresh.tap(); |
| 165 | await expect(refresh).toBeDisabled(); |
| 166 | await expect(loadOlder).toBeDisabled(); |
| 167 | await browser.evaluate(() => { |
| 168 | (window as unknown as { releaseIssueRefresh: () => void }).releaseIssueRefresh(); |
| 169 | return null; |
| 170 | }); |
| 171 | await expect(loadOlder).toBeEnabled(); |
| 172 | await loadOlder.tap(); |
| 173 | await screen.getByText("First older comment", { exact: true }).waitFor(); |
| 174 | }, |
| 175 | ); |