The best way to control Claude Code, Codex and more from any computer or phone
test(desktop): two-account callback test uses two distinct ports (#37271)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Nov 15, 2026 at 08:16 UTC
ed7f069326dbd7375a5b1e6f8caa40be9f944a26
1 file changed
+21
-8
apps/desktop/src/app/CodexAuthCallback.test.ts
+21
-8
@@ -5,13 +5,25 @@ import { codexAuthDeliveryUrl, readCodexAuthDelivery } from "@t3tools/shared/cod
5
import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
6
import { receiveCodexAuthCallback, cancelCodexAuthCallback } from "./CodexAuthCallback.ts";
7
8
+// Holds every probe socket until all ports are read, so one call never returns the same port twice.
9
+async function freePorts(count: number) {
10
+ const servers = Array.from({ length: count }, () => NodeHttp.createServer());
11
+ await Promise.all(
12
+ servers.map((server) => new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve))),
13
+ );
14
+ const ports = servers.map((server) => {
15
+ const address = server.address();
16
+ if (!address || typeof address === "string") throw new Error("address");
17
+ return address.port;
18
+ });
19
+ await Promise.all(
20
+ servers.map((server) => new Promise<void>((resolve) => server.close(() => resolve()))),
21
+ );
22
+ return ports;
23
+}
24
async function freePort() {
9
- const server = NodeHttp.createServer();
10
- await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
11
- const address = server.address();
12
- if (!address || typeof address === "string") throw new Error("address");
13
- await new Promise<void>((resolve) => server.close(() => resolve()));
14
- return address.port;
25
+ const [port] = await freePorts(1);
26
+ return port!;
27
}
28
function request(port: number, state = "a".repeat(43)) {
29
const url = new URL("https://auth.openai.com/api/accounts/authorize");
@@ -118,8 +130,9 @@ describe("desktop Codex callback helper", () => {
130
}
131
});
132
it("allows two accounts to complete independently", async () => {
121
- const a = request(await freePort(), "a".repeat(43));
122
- const b = request(await freePort(), "c".repeat(43));
133
+ const [portA, portB] = await freePorts(2);
134
+ const a = request(portA!, "a".repeat(43));
135
+ const b = request(portB!, "c".repeat(43));
136
const openedA = Promise.withResolvers<void>();
137
const openedB = Promise.withResolvers<void>();
138
const receiveA = receiveCodexAuthCallback(a, async () => {