Skip to content

Commit 7907c78

Browse files
saphidclaude
authored andcommitted
fix(server): browser setup advice names the server's T3 home
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 30084f0 commit 7907c78

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎apps/server/src/htmlRender/HtmlRender.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as ServerConfig from "../config.ts";
2222
import * as HtmlRender from "./HtmlRender.ts";
2323
import { HtmlRenderBrowserError } from "./headlessChrome.ts";
2424
import * as PreviewBrowser from "../preview/PreviewBrowser.ts";
25+
import * as PreviewBrowserHost from "../preview/PreviewBrowserHost.ts";
2526

2627
const TEST_BROWSER_ENV = "T3CODE_TEST_HEADLESS_SHELL";
2728

@@ -365,6 +366,34 @@ fs.createReadStream(null, { fd: 3 }).on("end", quit).on("data", (chunk) => {
365366
expect(Option.getOrElse(exitedBy, () => "killed by a signal")).toBe("asked to close");
366367
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
367368
);
369+
370+
it.live("names this server's home in the browser setup command", () =>
371+
Effect.gen(function* () {
372+
const fileSystem = yield* FileSystem.FileSystem;
373+
const path = yield* Path.Path;
374+
const directory = yield* fileSystem.makeTempDirectoryScoped({
375+
prefix: "t3-fake-browser-",
376+
});
377+
const executable = path.join(directory, "chrome-headless-shell");
378+
yield* fileSystem.writeFileString(
379+
executable,
380+
`#!${process.execPath}\nprocess.stderr.write(${JSON.stringify(PreviewBrowserHost.NO_SANDBOX_SIGNATURE)});\nprocess.exit(1);\n`,
381+
{ mode: 0o755 },
382+
);
383+
384+
const { error, baseDir } = yield* Effect.gen(function* () {
385+
const { baseDir } = yield* ServerConfig.ServerConfig;
386+
const htmlRender = yield* HtmlRender.HtmlRender;
387+
const error = yield* htmlRender.preview({ html: "<p>x</p>" }).pipe(Effect.flip);
388+
return { error, baseDir };
389+
}).pipe(
390+
Effect.provide(layerHtmlRender(executable)),
391+
Effect.provideService(HostProcess.UserId, 1000),
392+
);
393+
expect(error).toBeInstanceOf(PreviewBrowserHost.PreviewBrowserSandboxError);
394+
expect(error.message).toContain(`browser setup --base-dir ${baseDir}`);
395+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
396+
);
368397
},
369398
);
370399

‎apps/server/src/htmlRender/HtmlRender.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ const make = Effect.gen(function* () {
340340
const browsers = yield* Semaphore.make(MAX_CONCURRENT_BROWSERS);
341341
// Keep Chrome sandboxed unless explicitly disabled; root must opt out to run.
342342
const noSandbox = PreviewBrowserHost.sandboxDisabled(yield* HostProcess.Environment);
343-
const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND);
343+
// sudo resets the environment, so the command has to name this server's home.
344+
const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND, [
345+
"--base-dir",
346+
config.baseDir,
347+
]);
344348

345349
const launching = <A>(
346350
executable: string,

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,11 @@ const make = Effect.gen(function* () {
469469
const runFork = Effect.runForkWith(yield* Effect.context<never>());
470470
const runPromise = Effect.runPromiseWith(yield* Effect.context<never>());
471471
const launchServices = yield* Effect.context<ChildProcessSpawner.ChildProcessSpawner>();
472-
const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND);
472+
// sudo resets the environment, so the command has to name this server's home.
473+
const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND, [
474+
"--base-dir",
475+
config.baseDir,
476+
]);
473477
const agentScope = yield* AgentScope;
474478
const launchersDir = NodePath.join(config.stateDir, "server-browser", "launchers");
475479

0 commit comments

Comments
 (0)