Skip to content

Commit b712e7e

Browse files
author
ikeboy003
committed
dev-backend: provide a Scope so the backend actually spawns, and fix repoRoot
dev-backend.ts:114 is a scoped ChildProcess.make, but the runMain pipe only provided NodeServices.layer. Every invocation died at the first yield with "Service not found: effect/Scope" - both backends, including the default node path, and through pnpm dev. dev-runner.ts:940 already does this correctly. Second bug, only reachable once the first is fixed: new URL(".", import.meta.url) already ends in scripts/, so dirname() lands on apps/server. The extra .. walked out to apps/ and cargo was handed <workspace>/backend/Cargo.toml. e2e/drive-real-ui.cjs could not start dev-runner (spawn vp ENOENT - the workspace bin dir was not on PATH) and pinned an absolute chromium-1228 path under one user's home, so it could never run on the build box. Resolve the browser instead. Refs t3-ike pingdotgg#436, pingdotgg#437.
1 parent b88310a commit b712e7e

2 files changed

Lines changed: 129 additions & 27 deletions

File tree

‎apps/server/scripts/dev-backend.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ const resolveRustPort = (
7777

7878
const run = Effect.gen(function* () {
7979
const path = yield* Path.Path;
80-
const here = path.dirname(new URL(".", import.meta.url).pathname);
81-
const serverDir = path.resolve(here, "..");
80+
// `new URL(".", import.meta.url)` already ends in `scripts/`, so dirname()
81+
// strips the trailing slash and lands on `apps/server` — not `scripts`. Going
82+
// one more `..` from there walked out to `apps/`, and the cargo manifest path
83+
// resolved to `<workspace>/backend/Cargo.toml`, which does not exist.
84+
const serverDir = path.dirname(new URL(".", import.meta.url).pathname);
8285
const repoRoot = path.resolve(serverDir, "..", "..");
8386

8487
const backend = yield* selectBackend(process.env.T3CODE_BACKEND);
@@ -139,9 +142,14 @@ NodeRuntime.runMain(
139142
Effect.catchTag("DevBackendRefused", (error) =>
140143
Effect.logError(`[dev-backend] ${error.message}`).pipe(Effect.as(2)),
141144
),
145+
Effect.scoped,
142146
Effect.provide(NodeServices.layer),
143147
Effect.tap((code) =>
144-
code === 0 ? Effect.void : Effect.sync(() => { process.exitCode = code; }),
148+
code === 0
149+
? Effect.void
150+
: Effect.sync(() => {
151+
process.exitCode = code;
152+
}),
145153
),
146154
),
147155
);

‎e2e/drive-real-ui.cjs‎

Lines changed: 118 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,87 @@ const path = require("path");
33
const fs = require("fs");
44
const ROOT = process.cwd();
55
const { chromium } = require(path.join(ROOT, "apps/desktop/node_modules/playwright-core"));
6-
const CHROME = "/Users/nathanaelaninweze/Library/Caches/ms-playwright/chromium-1228/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing";
6+
// Resolve the browser through playwright-core's own registry. A hardcoded
7+
// absolute path pins the rig to one user's home and one chromium build, which is
8+
// why it cannot run on the build box.
9+
function resolveChrome() {
10+
if (process.env.T3_E2E_CHROME) return process.env.T3_E2E_CHROME;
11+
const registry = (() => {
12+
try {
13+
return chromium.executablePath();
14+
} catch {
15+
return null;
16+
}
17+
})();
18+
if (registry && fs.existsSync(registry)) return registry;
19+
// playwright-core's pinned revision is not always the one actually downloaded.
20+
// Fall back to any installed chromium build in the local cache.
21+
const cache =
22+
process.env.PLAYWRIGHT_BROWSERS_PATH ||
23+
path.join(
24+
require("os").homedir(),
25+
process.platform === "darwin" ? "Library/Caches/ms-playwright" : ".cache/ms-playwright",
26+
);
27+
if (!fs.existsSync(cache)) throw new Error("no playwright browser cache at " + cache);
28+
const tails = [
29+
"chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
30+
"chrome-mac/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
31+
"chrome-linux/chrome",
32+
];
33+
for (const dir of fs
34+
.readdirSync(cache)
35+
.filter((d) => d.startsWith("chromium-"))
36+
.sort()
37+
.reverse()) {
38+
for (const tail of tails) {
39+
const p = path.join(cache, dir, tail);
40+
if (fs.existsSync(p)) return p;
41+
}
42+
}
43+
throw new Error("no chromium build found under " + cache);
44+
}
45+
const CHROME = resolveChrome();
746

847
const log = [];
9-
const say = (s) => { log.push(String(s)); console.log(String(s)); };
48+
const say = (s) => {
49+
log.push(String(s));
50+
console.log(String(s));
51+
};
1052

1153
function startServer() {
1254
return new Promise((resolve, reject) => {
13-
const p = spawn("node", ["scripts/dev-runner.ts", "dev"], { cwd: ROOT, env: process.env });
55+
// The workspace bin dir must be on PATH or dev-runner dies with `spawn vp ENOENT`.
56+
const binDir = path.join(ROOT, "node_modules", ".bin");
57+
const env = { ...process.env, PATH: binDir + path.delimiter + process.env.PATH };
58+
if (!env.T3CODE_BACKEND) env.T3CODE_BACKEND = "rust";
59+
const p = spawn("node", ["scripts/dev-runner.ts", "dev"], { cwd: ROOT, env });
1460
let out = "";
15-
let url = null, pair = null;
16-
const maybe = () => { if (url && pair) { clearTimeout(t); resolve({ proc: p, url, pair, out }); } };
17-
const t = setTimeout(() => reject(new Error("no url/pair in 240s:\n" + out.slice(-1500))), 240000);
61+
let url = null,
62+
pair = null;
63+
const maybe = () => {
64+
if (url && pair) {
65+
clearTimeout(t);
66+
resolve({ proc: p, url, pair, out });
67+
}
68+
};
69+
const t = setTimeout(
70+
() => reject(new Error("no url/pair in 240s:\n" + out.slice(-1500))),
71+
240000,
72+
);
1873
const scan = (d) => {
1974
out += d;
20-
const u = out.match(/Local:\s+(http:\/\/localhost:\d+)/); if (u) url = u[1];
21-
const pr = out.match(/pairingUrl:\s*(http:\/\/localhost:\d+\/pair#token=\S+)/); if (pr) pair = pr[1];
75+
const u = out.match(/Local:\s+(http:\/\/localhost:\d+)/);
76+
if (u) url = u[1];
77+
const pr = out.match(/pairingUrl:\s*(http:\/\/localhost:\d+\/pair#token=\S+)/);
78+
if (pr) pair = pr[1];
2279
maybe();
2380
};
24-
p.stdout.on("data", scan); p.stderr.on("data", scan);
25-
p.on("exit", c => { clearTimeout(t); reject(new Error("server exited " + c + "\n" + out.slice(-1500))); });
81+
p.stdout.on("data", scan);
82+
p.stderr.on("data", scan);
83+
p.on("exit", (c) => {
84+
clearTimeout(t);
85+
reject(new Error("server exited " + c + "\n" + out.slice(-1500)));
86+
});
2687
});
2788
}
2889

@@ -36,29 +97,43 @@ function startServer() {
3697
browser = await chromium.launch({ executablePath: CHROME, args: ["--no-sandbox"] });
3798
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } });
3899
const page = await ctx.newPage();
39-
const errs = [], ws = [];
40-
page.on("console", m => { if (m.type() === "error") errs.push(m.text().slice(0, 160)); });
41-
page.on("websocket", s => s.on("framereceived", f => { if (ws.length < 60) ws.push(String(f.payload).slice(0, 200)); }));
100+
const errs = [],
101+
ws = [];
102+
page.on("console", (m) => {
103+
if (m.type() === "error") errs.push(m.text().slice(0, 160));
104+
});
105+
page.on("websocket", (s) =>
106+
s.on("framereceived", (f) => {
107+
if (ws.length < 60) ws.push(String(f.payload).slice(0, 200));
108+
}),
109+
);
42110

43111
// PAIR, then land in the app.
44112
await page.goto(server.pair, { waitUntil: "domcontentloaded", timeout: 60000 });
45113
await page.waitForTimeout(12000);
46114
say("AFTER PAIR url: " + page.url());
47115
say("AFTER PAIR title: " + (await page.title()));
48116
await page.screenshot({ path: "/tmp/t3e2e/01-after-pair.png" });
49-
const txt = (await page.evaluate(() => document.body.innerText || "")).replace(/\n{2,}/g, "\n").slice(0, 900);
117+
const txt = (await page.evaluate(() => document.body.innerText || ""))
118+
.replace(/\n{2,}/g, "\n")
119+
.slice(0, 900);
50120
say("BODY:\n" + txt);
51121

52122
// THE COMPOSER — the thing reins could not drive.
53-
const cands = ['[contenteditable="true"]', 'textarea', '[role="textbox"]'];
123+
const cands = ['[contenteditable="true"]', "textarea", '[role="textbox"]'];
54124
let found = null;
55-
for (const c of cands) { const n = await page.locator(c).count(); say("locator " + c + " -> " + n); if (n && !found) found = c; }
125+
for (const c of cands) {
126+
const n = await page.locator(c).count();
127+
say("locator " + c + " -> " + n);
128+
if (n && !found) found = c;
129+
}
56130
if (found) {
57131
const box = page.locator(found).first();
58132
await box.click();
59133
await page.keyboard.type("say the word BANANA and nothing else", { delay: 20 });
60134
await page.waitForTimeout(1200);
61-
const got = (await box.innerText().catch(() => "")) || (await box.inputValue().catch(() => ""));
135+
const got =
136+
(await box.innerText().catch(() => "")) || (await box.inputValue().catch(() => ""));
62137
say("COMPOSER AFTER keyboard.type: " + JSON.stringify(String(got).slice(0, 120)));
63138
await page.screenshot({ path: "/tmp/t3e2e/02-typed.png" });
64139

@@ -67,25 +142,44 @@ function startServer() {
67142
say("PRESSED ENTER at " + new Date().toISOString());
68143
for (let i = 0; i < 12; i++) {
69144
await page.waitForTimeout(5000);
70-
const t = (await page.evaluate(() => document.body.innerText || "")).replace(/\n{2,}/g, "\n");
71-
if (/BANANA/i.test(t) && !/say the word BANANA/i.test(t.replace(/say the word BANANA and nothing else/i,""))) { say("REPLY SEEN at tick " + i); break; }
72-
if (i % 3 === 0) say("tick " + i + " url=" + page.url() + " tail=" + t.slice(-160).replace(/\n/g," "));
145+
const t = (await page.evaluate(() => document.body.innerText || "")).replace(
146+
/\n{2,}/g,
147+
"\n",
148+
);
149+
if (
150+
/BANANA/i.test(t) &&
151+
!/say the word BANANA/i.test(t.replace(/say the word BANANA and nothing else/i, ""))
152+
) {
153+
say("REPLY SEEN at tick " + i);
154+
break;
155+
}
156+
if (i % 3 === 0)
157+
say("tick " + i + " url=" + page.url() + " tail=" + t.slice(-160).replace(/\n/g, " "));
73158
}
74159
await page.screenshot({ path: "/tmp/t3e2e/03-after-send.png", fullPage: true });
75-
const after = (await page.evaluate(() => document.body.innerText || "")).replace(/\n{2,}/g, "\n");
160+
const after = (await page.evaluate(() => document.body.innerText || "")).replace(
161+
/\n{2,}/g,
162+
"\n",
163+
);
76164
say("URL AFTER SEND: " + page.url());
77165
say("BODY AFTER SEND (1200):\n" + after.slice(0, 1200));
78166
} else {
79167
say("NO COMPOSER FOUND");
80168
}
81169
say("CONSOLE ERRORS (" + errs.length + "): " + errs.slice(0, 4).join(" | "));
82170
say("WS FRAMES RECEIVED (" + ws.length + "):");
83-
ws.slice(0, 10).forEach(f => say(" " + f));
171+
ws.slice(0, 10).forEach((f) => say(" " + f));
84172
} catch (e) {
85173
say("FAILED: " + (e && e.message ? e.message : String(e)));
86174
} finally {
87-
try { if (browser) await browser.close(); } catch (e) {}
88-
if (server && server.proc) { try { server.proc.kill("SIGKILL"); } catch (e) {} }
175+
try {
176+
if (browser) await browser.close();
177+
} catch (e) {}
178+
if (server && server.proc) {
179+
try {
180+
server.proc.kill("SIGKILL");
181+
} catch (e) {}
182+
}
89183
fs.writeFileSync("/tmp/t3e2e/run.log", log.join("\n"));
90184
process.exit(0);
91185
}

0 commit comments

Comments
 (0)