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, 06:00 UTC
fix(web): a corrected telemetry URL can be tested while an earlier check runs (#39067)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 19, 2026 at 11:42 UTC
475ae52ac279152dd2c13a86a59227d3e1441e3d
4 files changed
+103
-8
apps/web/src/components/settings/TelemetryExportSettings.browser.test.tsx
+36
-1
@@ -63,7 +63,7 @@ import { TelemetryExportSettings } from "./TelemetryExportSettings";
63
64
function setup() {
65
updateSettings.mockClear();
66
- checkOtlpEndpoint.mockClear();
66
+ checkOtlpEndpoint.mockReset();
67
state.serverConfig = { environment: { capabilities: {} } };
68
}
69
@@ -139,4 +139,39 @@ describe("TelemetryExportSettings", () => {
139
input: { signal: "traces", url: "http://collector/v1/traces" },
140
});
141
});
142
+
143
+ it("can test a corrected URL and reports only the latest attempt when a URL is reused", async () => {
144
+ setup();
145
+ state.observability = { ...DEFAULT_SERVER_SETTINGS.observability, otlpTracesUrl: "" };
146
+ state.serverConfig = { environment: { capabilities: { otlpEndpointCheck: true } } };
147
+ const first = Promise.withResolvers<Awaited<ReturnType<typeof checkOtlpEndpoint>>>();
148
+ const corrected = Promise.withResolvers<Awaited<ReturnType<typeof checkOtlpEndpoint>>>();
149
+ const latest = Promise.withResolvers<Awaited<ReturnType<typeof checkOtlpEndpoint>>>();
150
+ checkOtlpEndpoint
151
+ .mockReturnValueOnce(first.promise)
152
+ .mockReturnValueOnce(corrected.promise)
153
+ .mockReturnValueOnce(latest.promise);
154
+ await using screen = await render(<TelemetryExportSettings />);
155
+
156
+ const traces = screen.getByLabelText("Traces endpoint");
157
+ const testTraces = screen.getByRole("button", { name: "Test" }).first();
158
+ await userEvent.fill(traces, "http://first/v1/traces");
159
+ await userEvent.click(testTraces);
160
+ await expect.element(testTraces).toBeDisabled();
161
+
162
+ await userEvent.fill(traces, "http://corrected/v1/traces");
163
+ await expect.element(testTraces).toBeEnabled();
164
+ await userEvent.click(testTraces);
165
+ await expect.element(testTraces).toBeDisabled();
166
+
167
+ await userEvent.fill(traces, "http://first/v1/traces");
168
+ await userEvent.click(testTraces);
169
+ await expect.element(testTraces).toBeDisabled();
170
+
171
+ corrected.resolve({ _tag: "Success", value: { _tag: "Accepted", latencyMs: 22 } });
172
+ first.resolve({ _tag: "Success", value: { _tag: "Accepted", latencyMs: 11 } });
173
+ latest.resolve({ _tag: "Success", value: { _tag: "Accepted", latencyMs: 33 } });
174
+
175
+ await expect.element(screen.getByText("Connected · 33 ms")).toBeInTheDocument();
176
+ });
177
});
apps/web/src/components/settings/TelemetryExportSettings.tsx
+10
-6
@@ -141,11 +141,12 @@ function TelemetryExportForm() {
141
const changedSignals = SIGNALS.filter(({ key }) => values[key].trim() !== saved[key]);
142
const changed = changedSignals.length > 0;
143
144
- const sendCheck = async (key: SignalKey, signal: OtlpSignal, url: string) => {
144
+ const sendCheck = async (key: SignalKey, signal: OtlpSignal, attempt: EndpointCheck) => {
145
if (!environmentId) return;
146
+ const { url } = attempt;
147
const response = await checkOtlpEndpoint({ environmentId, input: { signal, url } });
148
setChecks((previous) => {
148
- if (previous[key]?.url !== url || previous[key].result !== null) return previous;
149
+ if (previous[key] !== attempt) return previous;
150
const next = { ...previous };
151
if (response._tag === "Success") next[key] = { url, result: response.value };
152
else delete next[key];
@@ -155,14 +156,15 @@ function TelemetryExportForm() {
156
157
const checkEndpoint = (key: SignalKey, signal: OtlpSignal, url: string) => {
158
if (!isHttpUrl(url)) return;
158
- setChecks((previous) => ({ ...previous, [key]: { url, result: null } }));
159
- void sendCheck(key, signal, url);
159
+ const attempt = { url, result: null };
160
+ setChecks((previous) => ({ ...previous, [key]: attempt }));
161
+ void sendCheck(key, signal, attempt);
162
};
163
164
const sendPendingChecks = useEffectEvent(() => {
165
for (const { key, signal } of SIGNALS) {
166
const check = checks[key];
165
- if (check?.result === null) void sendCheck(key, signal, check.url);
167
+ if (check?.result === null) void sendCheck(key, signal, check);
168
}
169
});
170
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- sends pending endpoint check requests once the environment can run them
@@ -260,7 +262,9 @@ function TelemetryExportForm() {
262
type="button"
263
size="sm"
264
variant="outline"
263
- disabled={!isHttpUrl(url) || checks[key]?.result === null}
265
+ disabled={
266
+ !isHttpUrl(url) || (checks[key]?.url === url && checks[key].result === null)
267
+ }
268
onClick={() => void checkEndpoint(key, signal, url)}
269
>
270
<T>Test</T>
scripts/scenarios/corrected-telemetry-url-can-be-tested.e2e.ts
new
+56
@@ -0,0 +1,56 @@
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
+);
scripts/scenarios/t3.ts
+1
-1
@@ -235,7 +235,7 @@ const readPairingPath = Effect.gen(function* () {
235
});
236
237
/** The id every thread link starts with, asked of the server the app talks to. */
238
-const environmentId = (baseUrl: string) =>
238
+export const environmentId = (baseUrl: string) =>
239
HttpClient.get(`${baseUrl}/.well-known/t3/environment`).pipe(
240
Effect.flatMap(HttpClientResponse.filterStatusOk),
241
Effect.flatMap(