@devries-cameron20 / t3code Mirror · read-only / commits / b883156e26
Fork 0

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 22, 00:45 UTC

fix(scripts): scenarios run where localhost resolves to IPv6 first (#34121)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 17:17 UTC b883156e269de2002873aebdef6019f336b687a7
3 files changed +61 -13
docs/operations/scenarios.md
+13 -1
@@ -70,7 +70,19 @@ cd scripts && pnpm exec e2e run scenarios/replay-turn-streams.e2e.ts --headed
70
71 e2e starts the dev stack through [`start-app.ts`](../../scripts/scenarios/start-app.ts) on a free
72 port, runs the tests, and stops it. Results land in `scripts/.e2e`: `report.json`, `summary.md`,
73 -and per test a `trace.md`, its screenshots, and a video. The first run downloads e2e's browser.
73 +and per test a `trace.md`, its screenshots, and a video. `vp run scenarios --target web` runs one
74 +target; flags go straight after the script name, without `--`.
75 +
76 +The first run downloads e2e's browser (about 120 MB). To fetch it ahead of time, such as in a
77 +machine image, run this from the repository root after `vp i`:
78 +
79 +```sh
80 +node scripts/node_modules/playwright-core/cli.js install --only-shell chromium ffmpeg
81 +```
82 +
83 +e2e opens the web app at `127.0.0.1`, and the start script tells the web dev server to bind that
84 +address. It does not use `localhost`, which some machines resolve to `::1` first.
85 +
86 `e2e run --help` lists the rest: `--grep`, `--watch`, `--last-failed`, `--changed-since`.
87
88 Run one at a time per checkout: a run recreates the checkout's scenario T3 home and its `.e2e`
scripts/e2e.config.ts
+8 -3
@@ -46,6 +46,11 @@ export const T3_HOME = resolved.home;
46 export const MOBILE_T3_HOME = `${T3_HOME}-mobile`;
47 export const MOBILE = resolved.mobile;
48 const startApp = resolved.startApp;
49 +/**
50 + * The one address e2e opens the web app at and the app is told to bind. Never `localhost`: the
51 + * runner and the app can resolve that name to different addresses.
52 + */
53 +const LOOPBACK = "127.0.0.1";
54
55 /**
56 * Leases a device from the Simlock pool, whose gateway speaks agent-device's lease protocol.
@@ -131,12 +136,12 @@ export default {
136 name: "web",
137 engine: web({ viewport: { width: 1280, height: 800 } }),
138 app: {
134 - url: "http://127.0.0.1:0",
139 + url: `http://${LOOPBACK}:0`,
140 // Vite answers before the server does; this path is proxied to the server.
136 - readyUrl: "http://127.0.0.1:{port}/.well-known/t3/environment",
141 + readyUrl: `http://${LOOPBACK}:{port}/.well-known/t3/environment`,
142 command: {
143 executable: resolved.node,
139 - args: [startApp, "web", T3_HOME, "{port}"],
144 + args: [startApp, "web", T3_HOME, LOOPBACK, "{port}"],
145 cwd: APP_DIR,
146 startupTimeout: 300_000,
147 log: ".e2e/app.log",
scripts/scenarios/start-app.ts
+40 -9
@@ -141,17 +141,21 @@ const startApp = Effect.fn("startApp")(function* (input: {
141 ];
142
143 if (input.surface === "web") {
144 - const [webPort = ""] = input.ports;
145 - const serverPort = yield* net.reserveLoopbackPort();
144 + // e2e opens the app at this host, so the web server is told to bind exactly it. Left to its
145 + // default, `localhost`, it binds ::1 alone on machines that resolve the name to IPv6 first.
146 + const [host = "", webPort = ""] = input.ports;
147 + const origin = `http://${host}:${webPort}`;
148 + const serverPort = String(yield* net.reserveLoopbackPort());
149 const token = yield* (yield* SecureRandom.SecureRandom).uuidV4();
147 - const runner = yield* start({
150 + const ports = ["--port", serverPort, "--dev-url", origin];
151 + const webEnv = { ...env, T3CODE_PORT_OFFSET: String(Number(webPort) - BASE_WEB_PORT) };
152 + const server = yield* start({
153 cwd: checkout,
154 command: node,
150 - args: devRunner("dev", ["--port", String(serverPort)]),
155 + args: devRunner("dev:server", ports),
156 env: {
152 - ...env,
153 - T3CODE_PORT_OFFSET: String(Number(webPort) - BASE_WEB_PORT),
154 - T3CODE_DEV_ALLOWED_ORIGINS: `http://127.0.0.1:${webPort}`,
157 + ...webEnv,
158 + T3CODE_DEV_ALLOWED_ORIGINS: origin,
159 // Makes the startup pairing link reusable, so every test can sign in with it.
160 T3CODE_DEV_AUTH_TOKEN: `${token}${token}`.replaceAll("-", ""),
161 },
@@ -165,7 +169,32 @@ const startApp = Effect.fn("startApp")(function* (input: {
169 .pipe(Effect.ignore);
170 },
171 });
168 - return yield* runner.exitCode;
172 + const web = yield* start({
173 + cwd: checkout,
174 + command: node,
175 + args: devRunner("dev:web", [...ports, "--", "--host", host]),
176 + env: webEnv,
177 + onLine: Console.log,
178 + });
179 + // A web server that came up on another loopback address would leave e2e waiting out its
180 + // whole startup timeout; say so at once instead.
181 + const boundElsewhere = Effect.gen(function* () {
182 + const elsewhere = host === "::1" ? "127.0.0.1" : "::1";
183 + if (yield* net.hasListenerOnHost(Number(webPort), host)) return yield* Effect.never;
184 + if (!(yield* net.hasListenerOnHost(Number(webPort), elsewhere))) {
185 + return yield* new ScenarioError({ message: "The web server is not listening yet." });
186 + }
187 + yield* Console.error(
188 + `The web server listens on ${elsewhere}:${webPort}, not on ${host}: it ignored --host.`,
189 + );
190 + return 1;
191 + }).pipe(
192 + Effect.retry({
193 + schedule: Schedule.spaced("1 second"),
194 + while: (error) => error._tag === "ScenarioError",
195 + }),
196 + );
197 + return yield* Effect.raceAll([server.exitCode, web.exitCode, boundElsewhere]);
198 }
199
200 // The device is another machine: the server listens on every interface, and Metro serves the
@@ -212,7 +241,9 @@ const command = Command.make(
241 ),
242 home: Argument.String("t3-home").pipe(Argument.withDescription("T3 home to recreate.")),
243 ports: Argument.String("port").pipe(
215 - Argument.withDescription("web: <web-port>. mobile: <server-port> <metro-port> <host>."),
244 + Argument.withDescription(
245 + "web: <host> <web-port>. mobile: <server-port> <metro-port> <host>.",
246 + ),
247 Argument.variadic(),
248 ),
249 },