The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | /// <reference lib="dom" /> |
| 2 | import type { IssueDetail, IssueRef } from "@t3tools/contracts"; |
| 3 | import { expect } from "e2e"; |
| 4 | |
| 5 | import { test, WEB } from "./t3.ts"; |
| 6 | |
| 7 | test( |
| 8 | "A failed issue refresh tells the reader what went wrong", |
| 9 | WEB, |
| 10 | async ({ t3, app, browser, screen }) => { |
| 11 | await t3.project("demo"); |
| 12 | await browser.addInitScript(() => { |
| 13 | let rateLimited = false; |
| 14 | Object.assign(window, { |
| 15 | armIssueRefreshFailure: () => { |
| 16 | rateLimited = true; |
| 17 | }, |
| 18 | }); |
| 19 | const refresh = new Promise<void>((resolve) => { |
| 20 | Object.assign(window, { releaseIssueRefresh: () => resolve() }); |
| 21 | }); |
| 22 | // The first issue read succeeds; the refresh then hits GitHub's rate limit. |
| 23 | const send = WebSocket.prototype.send; |
| 24 | WebSocket.prototype.send = function (data) { |
| 25 | const request: { _tag: string; id: string; tag: string; payload: IssueRef } | null = |
| 26 | typeof data === "string" ? JSON.parse(data) : null; |
| 27 | if (request?._tag !== "Request" || request.tag !== "issues.detail") |
| 28 | return send.call(this, data); |
| 29 | const reply = (exit: unknown) => |
| 30 | this.dispatchEvent( |
| 31 | new MessageEvent("message", { |
| 32 | data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }), |
| 33 | }), |
| 34 | ); |
| 35 | if (rateLimited) { |
| 36 | void refresh.then(() => |
| 37 | reply({ |
| 38 | _tag: "Failure", |
| 39 | cause: [ |
| 40 | { |
| 41 | _tag: "Fail", |
| 42 | error: { |
| 43 | _tag: "IssueOperationError", |
| 44 | operation: "detail", |
| 45 | detail: "GitHub API rate limit exceeded.", |
| 46 | reason: "rate-limited", |
| 47 | }, |
| 48 | }, |
| 49 | ], |
| 50 | }), |
| 51 | ); |
| 52 | return; |
| 53 | } |
| 54 | const { projectId, tracker, scope, key } = request.payload; |
| 55 | const detail: IssueDetail = { |
| 56 | projectId, |
| 57 | tracker, |
| 58 | scope, |
| 59 | key, |
| 60 | host: "github.com", |
| 61 | displayKey: "#42", |
| 62 | projectTitle: "demo", |
| 63 | title: "Issue before the rate limit", |
| 64 | body: "The details from the last successful read.", |
| 65 | url: "https://github.com/example/demo/issues/42", |
| 66 | author: null, |
| 67 | state: { category: "open", name: "Open" }, |
| 68 | createdAt: "2026-10-01T00:00:00.000Z", |
| 69 | updatedAt: "2026-10-01T00:00:00.000Z", |
| 70 | closedAt: null, |
| 71 | assignees: [], |
| 72 | labels: [], |
| 73 | commentCount: 0, |
| 74 | writable: false, |
| 75 | capabilities: { |
| 76 | create: false, |
| 77 | edit: false, |
| 78 | comment: false, |
| 79 | labels: false, |
| 80 | assignees: false, |
| 81 | reactions: false, |
| 82 | templates: false, |
| 83 | linkedPullRequests: false, |
| 84 | events: false, |
| 85 | search: true, |
| 86 | }, |
| 87 | viewerPermissions: { |
| 88 | setState: false, |
| 89 | comment: false, |
| 90 | edit: false, |
| 91 | labels: false, |
| 92 | assignees: false, |
| 93 | }, |
| 94 | states: [], |
| 95 | viewer: null, |
| 96 | comments: [], |
| 97 | commentsCursor: null, |
| 98 | events: [], |
| 99 | linkedPullRequests: [], |
| 100 | }; |
| 101 | queueMicrotask(() => reply({ _tag: "Success", value: detail })); |
| 102 | }; |
| 103 | }); |
| 104 | |
| 105 | await t3.open("/issues?selectedProjectId=demo&tracker=github&scope=example/demo&key=42"); |
| 106 | await screen.getByText("Issue before the rate limit", { exact: true }).waitFor(); |
| 107 | await browser.evaluate(() => { |
| 108 | (window as unknown as { armIssueRefreshFailure: () => void }).armIssueRefreshFailure(); |
| 109 | return null; |
| 110 | }); |
| 111 | await screen.getByRole("button", "Refresh issue", { exact: true }).tap(); |
| 112 | const refreshing = browser.locator('button[aria-label="Refresh issue"]:disabled'); |
| 113 | await refreshing.waitFor(); |
| 114 | await browser.evaluate(() => { |
| 115 | (window as unknown as { releaseIssueRefresh: () => void }).releaseIssueRefresh(); |
| 116 | return null; |
| 117 | }); |
| 118 | await refreshing.waitFor({ state: "hidden" }); |
| 119 | await app.screenshot("after-failed-refresh"); |
| 120 | await expect( |
| 121 | screen.getByText("GitHub API rate limit exceeded.", { exact: false }), |
| 122 | ).toBeVisible(); |
| 123 | await expect(screen.getByText("Issue before the rate limit", { exact: true })).toBeVisible(); |
| 124 | }, |
| 125 | ); |