Skip to content

Commit 947c882

Browse files
author
ikeboy003
committed
e2e: real Playwright harness, backend tool-loop script, and the WS/command fixes left uncommitted
Committing work that had accumulated UNCOMMITTED in the shared checkout. It was not lost through carelessness: .git/index.lock had been sitting stale since 01:33 - sixteen hours, no live git process - so every write in this repo failed with could not write index. That is a large part of t3-ike pingdotgg#393 (182 cells, 13 commits between them); agents were not declining to commit, they could not. Lands the first real frontend e2e harness (playwright.config.ts, e2e/fixtures.ts, e2e/actions/preview-refresh-focus-zoom.spec.ts), the rust-backend tool-loop script, and the contract_tests/server_main work that went with them. test-results/ and playwright-report/ are gitignored rather than committed: they are regenerated on every run, and this repo already learned that lesson once when a .t3code-agent .db blew past GitHub's 100MB limit and rejected the push.
1 parent b712e7e commit 947c882

12 files changed

Lines changed: 1278 additions & 12 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ node_modules/
4343
# 282MB of it, regenerated on every run, and one .db already blew past
4444
# GitHub's 100MB file limit and rejected the push.
4545
.t3code-agent/
46+
47+
# Playwright run artifacts — regenerated on every e2e run.
48+
apps/web/test-results/
49+
apps/web/playwright-report/
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/**
2+
* ACTIONS 010-014/153 — the five `previewFocus`-gated preview keybindings.
3+
*
4+
* preview.refresh mod+r
5+
* preview.focusUrl mod+l
6+
* preview.zoomIn mod+= / mod++
7+
* preview.zoomOut mod+-
8+
* preview.resetZoom mod+0
9+
*
10+
* ALL FIVE ARE **BLOCKED**, NOT FAILING, AND NOT NO-OPS. The distinction is the
11+
* whole point of this file, so it is asserted rather than asserted-around.
12+
*
13+
* All five are advertised by the backend with `when: previewFocus`
14+
* (backend/src/keybindings.rs:97-102). `previewFocus` can only become true once
15+
* a preview pane exists. A preview pane can only exist if the server implements
16+
* the preview surface. It does not:
17+
*
18+
* packages/contracts/src/rpc.ts:271-280 declares TEN preview methods
19+
* preview.open / navigate / resize / refresh / close / list / reportStatus
20+
* previewAutomation.connect / respond / focusHost
21+
*
22+
* backend/src/server_main.rs implements ZERO of them
23+
* $ grep -rn "preview" backend/src/
24+
* server_main.rs:2670 (a comment)
25+
* server_main.rs:3812 (a comment)
26+
* server_main.rs:3979 review::diff_preview <- the DIFF preview, unrelated
27+
* text.rs:11 (a comment)
28+
* keybindings.rs:96 push("mod+shift+j", "preview.toggle", None)
29+
*
30+
* So the server hands the client keybindings for a command surface it has not
31+
* implemented. `preview.toggle` is worse than the five here: it carries NO
32+
* `when` guard at all, so it is reachable, and pressing mod+shift+j does
33+
* nothing, forever, with no error.
34+
*
35+
* These specs are written to GO GREEN THE DAY PREVIEW LANDS. They are not
36+
* stubbed, not `.skip`-ed, and must not be deleted: `test.fixme` marks a known
37+
* missing capability and is reported by the runner as such, which is exactly the
38+
* BLOCKED row this task asks for — a `skip` would hide it and a deleted spec
39+
* would buy green with a smaller suite.
40+
*
41+
* WHOEVER IMPLEMENTS PREVIEW: change `test.fixme(` back to `test(` for each of
42+
* the five. The bodies are the real assertions and are already written.
43+
*
44+
* `test.fixme` is used in its DECLARATIVE form deliberately: the in-body form
45+
* runs after fixtures are constructed, which boots a backend and a browser to
46+
* reach a line that says "do not run this". Declared, the runner reports the row
47+
* without paying for the stack.
48+
*/
49+
import { test, expect } from "../fixtures";
50+
51+
/** The precondition every one of these five shares, and that nothing can satisfy today. */
52+
async function openPreviewAndFocusIt(page: import("@playwright/test").Page) {
53+
// `preview.toggle` is the only ungated entry point to `previewFocus`.
54+
await page.keyboard.press("ControlOrMeta+Shift+J");
55+
await expect(
56+
page.locator('[data-preview-pane], iframe[title*="preview" i]').first(),
57+
"preview.toggle must open a preview pane — it is the only way previewFocus " +
58+
"can ever become true, and all five keybindings in this file are gated on it",
59+
).toBeVisible();
60+
}
61+
62+
// DESCRIBE-LEVEL, NOT PER-TEST. `test.fixme(true, ...)` inside a test body is
63+
// evaluated AFTER beforeEach, so the shared `openPreviewAndFocusIt` precondition
64+
// ran first and the test reported a 180s TIMEOUT instead of BLOCKED. A blocked
65+
// capability must not burn a timeout to say so.
66+
test.describe
67+
.fixme("preview keybindings (previewFocus-gated) — BLOCKED: backend implements none of the 10 preview.* RPCs", () => {
68+
test.beforeEach(async ({ gotoApp, page }) => {
69+
await gotoApp(page);
70+
});
71+
72+
test.fixme("010 preview.refresh (mod+r) reloads the preview without navigating the app", async ({
73+
page,
74+
}) => {
75+
await openPreviewAndFocusIt(page);
76+
const appUrl = page.url();
77+
await page.keyboard.press("ControlOrMeta+R");
78+
// The app must not be the thing that reloaded — that is the browser default
79+
// this binding has to preventDefault.
80+
expect(page.url()).toBe(appUrl);
81+
});
82+
83+
test.fixme("011 preview.focusUrl (mod+l) moves focus to the preview URL bar", async ({
84+
page,
85+
}) => {
86+
await openPreviewAndFocusIt(page);
87+
await page.keyboard.press("ControlOrMeta+L");
88+
const focused = page.locator(":focus");
89+
await expect(focused).toHaveAttribute("data-preview-url", /.*/);
90+
});
91+
92+
test.fixme("012 preview.zoomIn (mod+= and mod++) increases preview zoom", async ({ page }) => {
93+
await openPreviewAndFocusIt(page);
94+
const pane = page.locator("[data-preview-pane]").first();
95+
const before = await pane.getAttribute("data-preview-zoom");
96+
await page.keyboard.press("ControlOrMeta+=");
97+
await expect(pane).not.toHaveAttribute("data-preview-zoom", before ?? "");
98+
// BOTH chords are advertised (mod+= and mod++); a spec that exercises only
99+
// one reports coverage it does not have.
100+
const afterFirst = await pane.getAttribute("data-preview-zoom");
101+
await page.keyboard.press("ControlOrMeta++");
102+
await expect(pane).not.toHaveAttribute("data-preview-zoom", afterFirst ?? "");
103+
});
104+
105+
test.fixme("013 preview.zoomOut (mod+-) decreases preview zoom", async ({ page }) => {
106+
await openPreviewAndFocusIt(page);
107+
const pane = page.locator("[data-preview-pane]").first();
108+
const before = await pane.getAttribute("data-preview-zoom");
109+
await page.keyboard.press("ControlOrMeta+-");
110+
await expect(pane).not.toHaveAttribute("data-preview-zoom", before ?? "");
111+
});
112+
113+
test.fixme("014 preview.resetZoom (mod+0) returns preview zoom to its default", async ({
114+
page,
115+
}) => {
116+
await openPreviewAndFocusIt(page);
117+
const pane = page.locator("[data-preview-pane]").first();
118+
const baseline = await pane.getAttribute("data-preview-zoom");
119+
await page.keyboard.press("ControlOrMeta+=");
120+
await expect(pane).not.toHaveAttribute("data-preview-zoom", baseline ?? "");
121+
await page.keyboard.press("ControlOrMeta+0");
122+
await expect(pane).toHaveAttribute("data-preview-zoom", baseline ?? "");
123+
});
124+
});
125+
126+
test.describe("preview.toggle (ungated, reachable today)", () => {
127+
test.beforeEach(async ({ gotoApp, page }) => {
128+
await gotoApp(page);
129+
});
130+
131+
/**
132+
* THIS ONE IS NOT BLOCKED AND IT IS THE REASON THIS FILE FOUND A DEFECT.
133+
*
134+
* `preview.toggle` is advertised with NO `when` guard, so unlike the five
135+
* above a user can actually reach it. It is the precondition for all of them,
136+
* so if it silently does nothing they are unreachable by construction. That is
137+
* a live product claim, testable today, and it runs.
138+
*/
139+
test("009b preview.toggle is advertised to the client and must not silently do nothing", async ({
140+
page,
141+
}) => {
142+
const advertised = await page.evaluate(async () => {
143+
// Read what the SERVER advertises, not what the client hardcodes.
144+
const res = await fetch("/api/keybindings").catch(() => null);
145+
return res && res.ok ? await res.json().catch(() => null) : null;
146+
});
147+
// The binding's existence is asserted from the backend source regardless of
148+
// whether this route exists; see the header. What must hold at the glass is
149+
// that pressing it either opens something or reports why it cannot.
150+
const before = await page.locator("body").innerText();
151+
await page.keyboard.press("ControlOrMeta+Shift+J");
152+
const after = await page.locator("body").innerText();
153+
expect(
154+
after !== before,
155+
"pressing the advertised, UNGATED preview.toggle (mod+shift+j) changed nothing " +
156+
"in the UI. The backend advertises this keybinding (keybindings.rs:96) while " +
157+
"implementing none of the ten preview.* RPCs the contract declares " +
158+
"(rpc.ts:271-280), so the command is dead on arrival: no pane, no error, no " +
159+
"feedback. Either implement the preview surface or stop advertising the " +
160+
`binding. (advertised payload: ${JSON.stringify(advertised)?.slice(0, 200)})`,
161+
).toBe(true);
162+
});
163+
});

‎apps/web/e2e/fixtures.ts‎

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/**
2+
* THE shared e2e fixtures. One harness, per the reviewers' standing order.
3+
*
4+
* What this boots is the REAL stack: the Rust `t3code-server` binary and the
5+
* real Vite-served web bundle, talking over the app's own WebSocket. Nothing is
6+
* mocked. A spec that mounts a component against a fake RPC layer is a unit test
7+
* with a `.spec.ts` extension, and this channel has already rejected that.
8+
*
9+
* THINGS THAT COST OTHER AGENTS A ROUND, ENCODED HERE SO THEY DO NOT AGAIN:
10+
*
11+
* - `T3CODE_BACKEND` defaults to `node`. A harness that omits it goes green
12+
* against the NODE server and proves nothing about the Rust one. This starts
13+
* the Rust binary directly, so there is no default to get wrong.
14+
* - The dev port is HASHED PER WORKTREE. Anything hardcoding 5733/13773
15+
* attaches to a different cell's running app and screenshots that. Ports here
16+
* are allocated from :0 and read back.
17+
* - `domcontentloaded` never fires promptly in dev: the entry is a deferred
18+
* module script, so the event waits for the whole module graph. Waiting on it
19+
* reports "the app does not boot" for a cold cache. `gotoApp` commits and
20+
* then waits for the composer.
21+
* - `playwright-core`'s bundled browser does not resolve (the registry pins a
22+
* chromium build that is not the one installed), and a hardcoded absolute
23+
* `ms-playwright` cache path cannot run on the build box. `channel: "chrome"`
24+
* is resolved by name.
25+
*/
26+
import { test as base, expect, type Page } from "@playwright/test";
27+
import { spawn, type ChildProcess } from "node:child_process";
28+
import { mkdtempSync, existsSync } from "node:fs";
29+
import { tmpdir } from "node:os";
30+
import { join, resolve } from "node:path";
31+
import { createServer } from "node:net";
32+
import { fileURLToPath } from "node:url";
33+
34+
const WEB_DIR = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
35+
const REPO = resolve(WEB_DIR, "..", "..");
36+
37+
/** An OS-allocated free port. Never a constant — see the header. */
38+
async function freePort(): Promise<number> {
39+
return await new Promise((res, rej) => {
40+
const s = createServer();
41+
s.on("error", rej);
42+
s.listen(0, "127.0.0.1", () => {
43+
const p = (s.address() as { port: number }).port;
44+
s.close(() => res(p));
45+
});
46+
});
47+
}
48+
49+
async function waitForHttp(url: string, timeoutMs: number): Promise<void> {
50+
const deadline = Date.now() + timeoutMs;
51+
let last = "never attempted";
52+
while (Date.now() < deadline) {
53+
try {
54+
// Any HTTP answer means the socket is serving. The Rust server 404s `/`
55+
// by design (it serves /ws and /api), so status is not the signal —
56+
// getting a response at all is.
57+
await fetch(url, { signal: AbortSignal.timeout(4000) });
58+
return;
59+
} catch (e) {
60+
last = String((e as Error).message);
61+
}
62+
}
63+
throw new Error(`nothing answered at ${url} within ${timeoutMs}ms (last: ${last})`);
64+
}
65+
66+
/**
67+
* The Rust backend under test. `restart()` exists from the first commit even
68+
* though few specs call it yet: every durability claim needs it, and retrofitting
69+
* a restart fixture into thirty specs later is how it quietly never happens.
70+
*/
71+
export class Backend {
72+
proc: ChildProcess | null = null;
73+
constructor(
74+
readonly port: number,
75+
readonly home: string,
76+
readonly workspace: string,
77+
readonly bin: string,
78+
readonly agentBin: string,
79+
) {}
80+
81+
async start(): Promise<void> {
82+
this.proc = spawn(this.bin, [], {
83+
stdio: "ignore",
84+
env: {
85+
...process.env,
86+
T3CODE_SERVER_PORT: String(this.port),
87+
T3CODE_WORKSPACE: this.workspace,
88+
T3CODE_AGENT_DATA: this.home,
89+
// Without this the driver resolves the bare name `t3code-agent` against
90+
// PATH, finds nothing, and every provider reports "No provider
91+
// available" — the symptom every UI-driving attempt here has hit.
92+
T3CODE_AGENT_BIN: this.agentBin,
93+
},
94+
});
95+
await waitForHttp(`http://127.0.0.1:${this.port}/`, 60_000);
96+
}
97+
98+
async stop(): Promise<void> {
99+
if (!this.proc) return;
100+
const p = this.proc;
101+
this.proc = null;
102+
await new Promise<void>((res) => {
103+
p.once("exit", () => res());
104+
p.kill("SIGTERM");
105+
setTimeout(() => p.kill("SIGKILL"), 5_000).unref();
106+
});
107+
}
108+
109+
/** Kill and restart the backend. State that does not survive this was never durable. */
110+
async restart(): Promise<void> {
111+
await this.stop();
112+
await this.start();
113+
}
114+
}
115+
116+
interface Fixtures {
117+
backend: Backend;
118+
appUrl: string;
119+
gotoApp: (page: Page) => Promise<void>;
120+
}
121+
122+
export const test = base.extend<Record<string, never>, Fixtures>({
123+
backend: [
124+
async ({}, use) => {
125+
const bin = join(REPO, "backend", "target", "debug", "t3code-server");
126+
const agentBin = join(REPO, "backend", "target", "debug", "t3code-agent");
127+
if (!existsSync(bin) || !existsSync(agentBin)) {
128+
throw new Error(
129+
`the Rust backend is not built. Run:\n` +
130+
` cd ${join(REPO, "backend")} && cargo build --bin t3code-server --bin t3code-agent\n` +
131+
`Missing: ${!existsSync(bin) ? bin : ""} ${!existsSync(agentBin) ? agentBin : ""}`,
132+
);
133+
}
134+
const home = mkdtempSync(join(tmpdir(), "t3e2e-home-"));
135+
const workspace = mkdtempSync(join(tmpdir(), "t3e2e-ws-"));
136+
const backend = new Backend(await freePort(), home, workspace, bin, agentBin);
137+
await backend.start();
138+
await use(backend);
139+
await backend.stop();
140+
},
141+
{ scope: "worker" },
142+
],
143+
144+
appUrl: [
145+
async ({ backend }, use) => {
146+
const webPort = await freePort();
147+
const vp = join(REPO, "node_modules", ".bin", "vp");
148+
const web = spawn(vp, ["dev", "--port", String(webPort)], {
149+
cwd: WEB_DIR,
150+
stdio: "ignore",
151+
env: {
152+
...process.env,
153+
// `vp` lives in the workspace bin dir; spawning dev-runner with an
154+
// unaugmented PATH is what made the previous rig die on ENOENT.
155+
PATH: `${join(REPO, "node_modules", ".bin")}:${process.env.PATH ?? ""}`,
156+
T3CODE_PORT: String(backend.port),
157+
T3CODE_SINGLE_ORIGIN_DEV: "1",
158+
// Bundled dev collapses a cold module graph from minutes to seconds.
159+
T3CODE_BUNDLED_DEV: "1",
160+
},
161+
});
162+
const url = `http://127.0.0.1:${webPort}/`;
163+
await waitForHttp(url, 180_000);
164+
// WARM THE BUNDLE BEFORE ANY SPEC NAVIGATES. Vite answers the socket long
165+
// before it can serve a built graph, so the FIRST navigation pays the
166+
// whole bundle and blows a per-test timeout — which reads as "the app does
167+
// not boot" instead of "the cache was cold". Paying it once, here, keeps
168+
// that cost out of every spec's budget.
169+
const warmDeadline = Date.now() + 240_000;
170+
for (;;) {
171+
try {
172+
const r = await fetch(url, { signal: AbortSignal.timeout(120_000) });
173+
await r.text();
174+
break;
175+
} catch {
176+
if (Date.now() > warmDeadline) throw new Error(`web bundle never warmed at ${url}`);
177+
}
178+
}
179+
await use(url);
180+
web.kill("SIGTERM");
181+
},
182+
{ scope: "worker" },
183+
],
184+
185+
gotoApp: [
186+
async ({ appUrl }, use) => {
187+
await use(async (page: Page) => {
188+
await page.goto(appUrl, { waitUntil: "commit", timeout: 180_000 });
189+
await page
190+
.locator('[contenteditable="true"]')
191+
.first()
192+
.waitFor({ state: "visible", timeout: 180_000 });
193+
});
194+
},
195+
{ scope: "worker" },
196+
],
197+
});
198+
199+
export { expect };

‎apps/web/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"devDependencies": {
5353
"@effect/platform-node": "catalog:",
5454
"@effect/vitest": "catalog:",
55+
"@playwright/test": "1.60.0",
5556
"@rolldown/plugin-babel": "^0.2.0",
5657
"@tailwindcss/vite": "^4.0.0",
5758
"@tanstack/router-plugin": "^1.161.0",

0 commit comments

Comments
 (0)