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 | // @effect-diagnostics-next-line nodeBuiltinImport:off -- The test runs a loopback OTLP receiver. |
| 2 | import * as NodeHttp from "node:http"; |
| 3 | import { expect } from "e2e"; |
| 4 | |
| 5 | import { environmentId, runPromise, test, WEB } from "./t3.ts"; |
| 6 | |
| 7 | test( |
| 8 | "The corrected traces endpoint can be tested while the previous URL is still checking", |
| 9 | WEB, |
| 10 | async ({ t3, app, browser }) => { |
| 11 | const firstProbe = Promise.withResolvers<void>(); |
| 12 | let slowProbeClosed = false; |
| 13 | const collector = NodeHttp.createServer((request, response) => { |
| 14 | request.resume(); |
| 15 | if (request.url === "/slow/v1/traces") { |
| 16 | response.once("close", () => { |
| 17 | slowProbeClosed = true; |
| 18 | }); |
| 19 | firstProbe.resolve(); |
| 20 | return; |
| 21 | } |
| 22 | response.writeHead(200).end(); |
| 23 | }); |
| 24 | try { |
| 25 | await new Promise<void>((resolve) => collector.listen(0, "127.0.0.1", resolve)); |
| 26 | const address = collector.address(); |
| 27 | if (address === null || typeof address === "string") throw new Error("No collector port"); |
| 28 | const origin = `http://127.0.0.1:${address.port}`; |
| 29 | |
| 30 | await t3.project("demo"); |
| 31 | const environment = await runPromise(environmentId(app.baseUrl ?? "")); |
| 32 | await t3.open( |
| 33 | `/settings/diagnostics?machine=${encodeURIComponent(environment)}#telemetry-export`, |
| 34 | ); |
| 35 | |
| 36 | const traces = browser.locator("#otlpTracesUrl"); |
| 37 | const exportSection = browser.locator("#telemetry-export"); |
| 38 | const testTraces = exportSection.getByRole("button", "Test").first(); |
| 39 | await traces.fill(`${origin}/slow/v1/traces`); |
| 40 | await testTraces.tap(); |
| 41 | await firstProbe.promise; |
| 42 | await traces.fill(`${origin}/v1/traces`); |
| 43 | await exportSection.getByText("Not checked", { exact: true }).waitFor(); |
| 44 | |
| 45 | // Sample the screen before the old request reaches its server timeout. |
| 46 | const canTestCorrectedUrl = await testTraces.isEnabled(); |
| 47 | if (slowProbeClosed) |
| 48 | throw new Error("The slow telemetry probe closed before the button check"); |
| 49 | await app.screenshot("corrected-traces-url"); |
| 50 | expect(canTestCorrectedUrl, "The corrected traces URL can be tested immediately").toBe(true); |
| 51 | } finally { |
| 52 | collector.close(); |
| 53 | collector.closeAllConnections(); |
| 54 | } |
| 55 | }, |
| 56 | ); |