From 37761c9fe64a9c120c667712d88eda4e6b242f7e Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Wed, 18 Nov 2026 18:06:24 +0900 Subject: [PATCH 1/3] test(scenarios): sign in with a session cookie instead of the pair page t3.open opened the pairing link and waited for the browser to leave /pair with a negated URL assertion. That wait held for e2e's 1 s negation grace on every open. A positive wait does not work instead: the pair page reloads the app after it signs in, and that reload interrupts the test's next app.open. t3.open now exchanges the pairing token at /api/auth/browser-session, the endpoint the pair page itself calls, puts the returned session cookies in the browser, and opens the target directly. Only the response cookies are read, so a proof can still run against a base server whose response body differs. Co-Authored-By: Claude Opus 5.5 --- docs/operations/scenarios.md | 5 +-- scripts/scenarios/t3.ts | 63 +++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/docs/operations/scenarios.md b/docs/operations/scenarios.md index 798d066371684..be5aefc10a3b7 100644 --- a/docs/operations/scenarios.md +++ b/docs/operations/scenarios.md @@ -68,16 +68,13 @@ configured. ### Getting to the screen Most scenarios that could not run stopped on the way to the screen the bug is on, not on the -bug. Three rules avoid that: +bug. Two rules avoid that: - **Open by link, not by sidebar.** `await t3.open(thread)` lands on the thread ([`thread-opens-by-link.e2e.ts`](../../scripts/scenarios/thread-opens-by-link.e2e.ts)), and `await t3.open("/settings/general")` on a settings page. A sidebar row is a button that covers its own title, so a tap on `getByText("Earlier work")` is intercepted. When the sidebar is what the scenario is about, target the row's button: `screen.getByRole("button", "Earlier work")`. -- **Let `t3.open` do the navigating.** It waits until the pairing page has signed in before it - goes anywhere. A second `app.open` straight after the pairing link cancels the sign-in and - shows the pairing page again. - **Seed before opening.** Create projects and threads first, then call `t3.open`. With no project the app opens its first-run page instead of the one the scenario expects. diff --git a/scripts/scenarios/t3.ts b/scripts/scenarios/t3.ts index fab377de1028b..aa71d13ef1637 100644 --- a/scripts/scenarios/t3.ts +++ b/scripts/scenarios/t3.ts @@ -3,8 +3,7 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import * as NodeServices from "@effect/platform-node/NodeServices"; import * as NodeWS from "@effect/platform-node/NodeWS"; -import { test as base } from "@e2e-dev/web"; -import { expect } from "e2e"; +import { test as base, type Cookie } from "@e2e-dev/web"; import { CommandId, EnvironmentHttpApi, @@ -14,6 +13,8 @@ import { WsRpcGroup, } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; +import { getPairingTokenFromUrl } from "@t3tools/shared/remote"; +import * as Clock from "effect/Clock"; import * as SecureRandom from "effect/crypto/SecureRandom"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; @@ -22,7 +23,13 @@ import * as Layer from "effect/Layer"; import * as Path from "effect/Path"; import * as Schedule from "effect/Schedule"; import * as Schema from "effect/Schema"; -import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http"; +import { + Cookies, + FetchHttpClient, + HttpClient, + HttpClientRequest, + HttpClientResponse, +} from "effect/http"; import { RpcClient, RpcSerialization } from "effect/rpc"; import { Socket } from "effect/socket"; @@ -234,6 +241,41 @@ const readPairingPath = Effect.gen(function* () { return yield* fs.readFileString(path.join(T3_HOME, "pairing-path")); }); +const sameSite = { lax: "Lax", strict: "Strict", none: "None" } as const; + +/** + * Signs in the way the pairing page does and returns the session cookies. Opening the page + * instead races its reload after sign-in against the test's next `app.open`. + */ +const signIn = Effect.fn("scenario.signIn")(function* (baseUrl: string) { + const credential = getPairingTokenFromUrl(new URL(yield* readPairingPath, baseUrl)); + if (credential === null) { + return yield* new ScenarioError({ message: "The pairing link holds no token." }); + } + const client = yield* HttpApiClient.make(EnvironmentHttpApi, { baseUrl }); + // Only the cookies are read: a proof runs this against a base server whose body may differ. + const response = yield* client.auth + .browserSession({ payload: { credential }, responseMode: "response-only" }) + .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk)); + // Drops the expired cookies that only clear an older session. + const cookies = Cookies.mergeIntoArray( + [], + baseUrl, + response.cookies, + yield* Clock.currentTimeMillis, + ); + return cookies.map(({ name, value, options = {} }): Cookie => ({ + name, + value, + // The server sets no Domain and `Path=/`, which is what a cookie for the origin gets. + url: baseUrl, + ...(options.expires && { expires: Math.floor(options.expires.getTime() / 1000) }), + ...(options.httpOnly !== undefined && { httpOnly: options.httpOnly }), + ...(options.secure !== undefined && { secure: options.secure }), + ...(options.sameSite && { sameSite: sameSite[options.sameSite] }), + })); +}, Effect.provide(FetchHttpClient.layer)); + /** The id every thread link starts with, asked of the server the app talks to. */ export const environmentId = (baseUrl: string) => HttpClient.get(`${baseUrl}/.well-known/t3/environment`).pipe( @@ -278,14 +320,13 @@ export const test = base.extend<{ t3: T3 }>({ await use({ ...state, open: async (target = "/") => { - await app.open(await runPromise(readPairingPath)); - // The pairing page signs in and then leaves itself. Going anywhere before it has done - // so cancels the sign-in, and the next page is the pairing page again. - await expect(browser).not.toHaveURL(/\/pair(?:[?#]|$)/, { timeout: 60_000 }); - if (typeof target !== "string") { - const environment = await runPromise(environmentId(app.baseUrl ?? "")); - await app.open(`/${environment}/${target.threadId}`); - } else if (target !== "/") await app.open(target); + const baseUrl = app.baseUrl ?? ""; + await browser.setCookies(await runPromise(signIn(baseUrl))); + await app.open( + typeof target === "string" + ? target + : `/${await runPromise(environmentId(baseUrl))}/${target.threadId}`, + ); }, }); await runPromise(cleanup); From 6c86c18425f74772b77a887444cf677be3724b53 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Mon, 23 Nov 2026 15:01:45 -0600 Subject: [PATCH 2/3] test(scenarios): retry transient browser sign-in failures Retry the browser-session exchange within a 15-second budget. Use the scenario's reusable dev credential so a lost response can be retried safely. GPT 6.2 Sol in Codex --- scripts/scenarios/start-app.ts | 18 +++++++----------- scripts/scenarios/t3.ts | 33 +++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/scripts/scenarios/start-app.ts b/scripts/scenarios/start-app.ts index d635f1ba0fd64..59d0715ffc4c6 100644 --- a/scripts/scenarios/start-app.ts +++ b/scripts/scenarios/start-app.ts @@ -148,6 +148,11 @@ const startApp = Effect.fn("startApp")(function* (input: { const origin = `http://${host}:${webPort}`; const serverPort = String(yield* net.reserveLoopbackPort()); const token = yield* (yield* SecureRandom.SecureRandom).uuidV4(); + const credential = `${token}${token}`.replaceAll("-", ""); + // The fixture can retry this credential even if a session response was lost. + yield* fs.writeFileString(path.join(input.home, "browser-dev-token"), credential, { + mode: 0o600, + }); const ports = ["--port", serverPort, "--dev-url", origin]; const webEnv = { ...env, T3CODE_PORT_OFFSET: String(Number(webPort) - BASE_WEB_PORT) }; const server = yield* start({ @@ -157,18 +162,9 @@ const startApp = Effect.fn("startApp")(function* (input: { env: { ...webEnv, T3CODE_DEV_ALLOWED_ORIGINS: origin, - // Makes the startup pairing link reusable, so every test can sign in with it. - T3CODE_DEV_AUTH_TOKEN: `${token}${token}`.replaceAll("-", ""), - }, - onLine: (line) => { - const url = /pairingUrl:\s*(\S+)/.exec(line)?.[1]; - if (url === undefined) return Console.log(line); - // The link is a credential: it goes to a file the tests read, never to the log. - const { pathname, search, hash } = new URL(url); - return fs - .writeFileString(path.join(input.home, "pairing-path"), `${pathname}${search}${hash}`) - .pipe(Effect.ignore); + T3CODE_DEV_AUTH_TOKEN: credential, }, + onLine: (line) => (line.includes("pairingUrl:") ? Effect.void : Console.log(line)), }); const web = yield* start({ cwd: checkout, diff --git a/scripts/scenarios/t3.ts b/scripts/scenarios/t3.ts index aa71d13ef1637..b511bbe680a2f 100644 --- a/scripts/scenarios/t3.ts +++ b/scripts/scenarios/t3.ts @@ -13,7 +13,6 @@ import { WsRpcGroup, } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; -import { getPairingTokenFromUrl } from "@t3tools/shared/remote"; import * as Clock from "effect/Clock"; import * as SecureRandom from "effect/crypto/SecureRandom"; import * as Effect from "effect/Effect"; @@ -27,6 +26,7 @@ import { Cookies, FetchHttpClient, HttpClient, + HttpClientError, HttpClientRequest, HttpClientResponse, } from "effect/http"; @@ -235,12 +235,6 @@ export function makeState(home: string, env: NodeJS.ProcessEnv = {}) { }; } -const readPairingPath = Effect.gen(function* () { - const fs = yield* FileSystem.FileSystem; - const path = yield* Path.Path; - return yield* fs.readFileString(path.join(T3_HOME, "pairing-path")); -}); - const sameSite = { lax: "Lax", strict: "Strict", none: "None" } as const; /** @@ -248,15 +242,30 @@ const sameSite = { lax: "Lax", strict: "Strict", none: "None" } as const; * instead races its reload after sign-in against the test's next `app.open`. */ const signIn = Effect.fn("scenario.signIn")(function* (baseUrl: string) { - const credential = getPairingTokenFromUrl(new URL(yield* readPairingPath, baseUrl)); - if (credential === null) { - return yield* new ScenarioError({ message: "The pairing link holds no token." }); - } + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const credential = yield* fs.readFileString(path.join(T3_HOME, "browser-dev-token")); const client = yield* HttpApiClient.make(EnvironmentHttpApi, { baseUrl }); // Only the cookies are read: a proof runs this against a base server whose body may differ. const response = yield* client.auth .browserSession({ payload: { credential }, responseMode: "response-only" }) - .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk)); + .pipe( + Effect.flatMap(HttpClientResponse.filterStatusOk), + Effect.retry({ + schedule: Schedule.spaced("500 millis"), + while: (error) => { + if (!HttpClientError.isHttpClientError(error)) return false; + const status = error.response?.status; + return ( + error.reason._tag === "TransportError" || + status === 502 || + status === 503 || + status === 504 + ); + }, + }), + Effect.timeout("15 seconds"), + ); // Drops the expired cookies that only clear an older session. const cookies = Cookies.mergeIntoArray( [], From 5e73cc43ac07f79b66d88f7c67ea5c9d0ff79ca7 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Mon, 23 Nov 2026 15:07:09 -0600 Subject: [PATCH 3/3] docs: clarify web scenario navigation The iOS fixture opens the app without a target. Scope the target examples to the web fixture. GPT 6.2 Sol in Codex --- docs/internals/15_testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internals/15_testing.md b/docs/internals/15_testing.md index 8e93e5e3dc12c..9408797a09834 100644 --- a/docs/internals/15_testing.md +++ b/docs/internals/15_testing.md @@ -53,7 +53,7 @@ vp run scenarios:prove scripts/scenarios/.e2e.ts --base main --upload-comm ``` - One test per file (`WEB` from `./t3.ts` or `IOS` from `./t3-mobile.ts`). Seed projects and threads via `t3.project` / `t3.thread` before calling `t3.open(...)` so the app does not land on first-run setup. -- Navigate directly with `t3.open(thread)` or `t3.open("/settings/...")` unless the scenario exercises sidebar navigation. +- In web scenarios, navigate directly with `t3.open(thread)` or `t3.open("/settings/...")` unless the scenario exercises sidebar navigation. - Put `expect` assertions only on the behavior the bug breaks, and take `app.screenshot("label")` where the bug shows so `scenarios:prove` pairs base and head captures. Never call `agent.act` or `agent.assert` (no model is configured). - The app starts with a minimal env (`PATH`, `HOME`, temp dir); pass extra env vars via `T3_SCENARIO_INHERIT_ENV='VAR,PREFIX_*'`. Run one scenario run at a time per checkout. - `scenarios:prove` exits `0` only when the test fails on base and passes on head (`1` = did not prove, `2` = app failed to start, `3` = scenario failed before its assertion). iOS scenarios lease a Simlock simulator and require `SIMLOCK_AGENT_DEVICE_URL` and `AGENT_DEVICE_DAEMON_AUTH_TOKEN`.