@devries-cameron20 / t3code Mirror · read-only / commits / 03a2b1acc6
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 23, 03:00 UTC

fix(cli): browser setup installs missing fonts (#17570)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Adrian Las committed Oct 19, 2026 at 07:05 UTC 03a2b1acc67361e4ec14c56e6fc36758cd96ab48
3 files changed +182 -7
apps/server/src/cli/browser.test.ts
+118
@@ -4,11 +4,94 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Layer from "effect/Layer";
7 +import * as PlatformError from "effect/PlatformError";
8 +import * as Sink from "effect/Sink";
9 +import * as Stream from "effect/Stream";
10 import * as TestConsole from "effect/testing/TestConsole";
11 import { Command } from "effect/cli";
12 +import * as ChildProcess from "effect/process/ChildProcess";
13 +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
14
15 import { browserCommand } from "./browser.ts";
16
17 +const BROWSER = "/t3/tools/chrome-headless-shell/linux64/154/chrome-headless-shell";
18 +const FONT = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf";
19 +
20 +/**
21 + * Records every command. `fc-match` is missing until fonts are installed, unless
22 + * the host starts with a font; the browser fails to load libnss3 when asked to.
23 + */
24 +const fakeSpawner = (host: { readonly font?: string; readonly missingLibrary?: boolean }) => {
25 + const commands: Array<ReadonlyArray<string>> = [];
26 + let font = host.font;
27 + const spawner = ChildProcessSpawner.make((command) =>
28 + Effect.gen(function* () {
29 + if (!ChildProcess.isStandardCommand(command)) return yield* Effect.die("Unexpected pipeline");
30 + commands.push([command.command, ...command.args]);
31 + if (command.command === "apt-get" && command.args.includes("fonts-liberation")) font = FONT;
32 + if (command.command === "fc-match" && font === undefined) {
33 + return yield* PlatformError.systemError({
34 + _tag: "NotFound",
35 + module: "ChildProcess",
36 + method: "spawn",
37 + });
38 + }
39 + const output =
40 + command.command === "fc-match"
41 + ? font!
42 + : command.command === BROWSER && host.missingLibrary
43 + ? "error while loading shared libraries: libnss3.so: cannot open shared object file"
44 + : command.command === "ldd"
45 + ? "\tlibnss3.so => not found\n"
46 + : "";
47 + const bytes = Stream.make(new TextEncoder().encode(output));
48 + return ChildProcessSpawner.makeHandle({
49 + pid: ChildProcessSpawner.ProcessId(1),
50 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
51 + isRunning: Effect.succeed(false),
52 + kill: () => Effect.void,
53 + unref: Effect.succeed(Effect.void),
54 + stdin: Sink.drain,
55 + stdout: bytes,
56 + stderr: Stream.empty,
57 + all: bytes,
58 + getInputFd: () => Sink.drain,
59 + getOutputFd: () => Stream.empty,
60 + });
61 + }),
62 + );
63 + return { spawner, commands };
64 +};
65 +
66 +/** A Linux host with apt and T3's browser installed under `/t3`. */
67 +const runSetup = (host: {
68 + readonly root: boolean;
69 + readonly font?: string;
70 + readonly missingLibrary?: boolean;
71 +}) => {
72 + const { spawner, commands } = fakeSpawner(host);
73 + const fs = FileSystem.makeNoop({
74 + exists: (path) => Effect.succeed(path === "/usr/bin/apt-get" || path === BROWSER),
75 + readDirectory: (path) =>
76 + Effect.succeed(path.endsWith("chrome-headless-shell") ? ["linux64"] : ["154"]),
77 + });
78 + return Effect.gen(function* () {
79 + yield* Command.runWith(browserCommand, { version: "0.0.0" })(["setup", "--base-dir", "/t3"]);
80 + return { commands, output: (yield* TestConsole.logLines).join("\n") };
81 + }).pipe(
82 + Effect.provideService(FileSystem.FileSystem, fs),
83 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
84 + Effect.provideService(HostProcess.Platform, "linux"),
85 + Effect.provideService(HostProcess.UserId, host.root ? 0 : 1000),
86 + // Root through sudo from a regular user, so setup reports ready instead of the root warning.
87 + Effect.provideService(HostProcess.Environment, host.root ? { SUDO_USER: "alice" } : {}),
88 + Effect.provide(Layer.mergeAll(NodeServices.layer, TestConsole.layer)),
89 + );
90 +};
91 +
92 +const aptGet = (commands: ReadonlyArray<ReadonlyArray<string>>) =>
93 + commands.filter(([name]) => name === "apt-get");
94 +
95 it.effect("setup in a root shell warns that the server cannot run as root", () =>
96 Effect.gen(function* () {
97 // Every file read fails, so setup finds nothing to install and changes nothing.
@@ -18,6 +101,10 @@ it.effect("setup in a root shell warns that the server cannot run as root", () =
101 "/nonexistent",
102 ]).pipe(
103 Effect.provide(FileSystem.layerNoop({})),
104 + Effect.provideService(
105 + ChildProcessSpawner.ChildProcessSpawner,
106 + fakeSpawner({ font: FONT }).spawner,
107 + ),
108 Effect.provideService(HostProcess.Platform, "linux"),
109 Effect.provideService(HostProcess.UserId, 0),
110 // A root user who follows the old advice runs setup through sudo.
@@ -28,3 +115,34 @@ it.effect("setup in a root shell warns that the server cannot run as root", () =
115 expect(output).not.toContain("ready");
116 }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, TestConsole.layer))),
117 );
118 +
119 +it.effect("setup without root does not report a host without fonts as ready", () =>
120 + Effect.gen(function* () {
121 + const { commands, output } = yield* runSetup({ root: false });
122 + expect(output).toContain(
123 + "T3's browser needs fontconfig and system fonts; setup installs them.",
124 + );
125 + expect(output).toContain("This needs root. Run:");
126 + expect(output).not.toContain("ready");
127 + expect(aptGet(commands)).toEqual([]);
128 + }),
129 +);
130 +
131 +it.effect("setup as root installs missing libraries and fonts after one package refresh", () =>
132 + Effect.gen(function* () {
133 + const { commands, output } = yield* runSetup({ root: true, missingLibrary: true });
134 + const apt = aptGet(commands);
135 + expect(apt.filter(([, action]) => action === "update")).toHaveLength(1);
136 + expect(apt.find((args) => args.includes("libnss3"))).toBeDefined();
137 + expect(apt).toContainEqual([
138 + "apt-get",
139 + "install",
140 + "-y",
141 + "--no-install-recommends",
142 + "fontconfig",
143 + "fonts-liberation",
144 + ]);
145 + expect(output).toContain("Installed the browser's fonts.");
146 + expect(output).toContain("This host is ready for T3's browser.");
147 + }),
148 +);
apps/server/src/cli/browser.ts
+61 -5
@@ -84,9 +84,31 @@ const installedBrowser = Effect.fn("browserSetup.installedBrowser")(function* (b
84 return Option.none<string>();
85 });
86
87 +/**
88 + * Chrome starts without fonts, but pages then render no text. Without
89 + * fontconfig there is no `fc-match` at all, which counts as no font.
90 + */
91 +const fontAvailable = Effect.gen(function* () {
92 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
93 + const font = yield* spawner
94 + .string(
95 + ChildProcess.make("fc-match", ["--format=%{file}", "sans-serif"], {
96 + stdin: "ignore",
97 + stderr: "ignore",
98 + }),
99 + )
100 + .pipe(
101 + Effect.timeout("5 seconds"),
102 + Effect.orElseSucceed(() => ""),
103 + );
104 + return font.trim() !== "";
105 +}).pipe(Effect.withSpan("browserSetup.fontAvailable"));
106 +
107 +const FONT_PACKAGES = ["fontconfig", "fonts-liberation"];
108 +
109 const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe(
110 Command.withDescription(
89 - "Set up this Linux host for T3's browser: allow Chrome's sandbox and install its libraries.",
111 + "Set up this Linux host for T3's browser: allow Chrome's sandbox and install its libraries and fonts.",
112 ),
113 Command.withHandler(({ baseDir }) =>
114 Effect.gen(function* () {
@@ -108,9 +130,10 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
130 const missing = Option.isSome(browser)
131 ? yield* PreviewBrowserHost.missingLibraries(browser.value)
132 : [];
133 + const needsFonts = !(yield* fontAvailable);
134 const hasApt = yield* fs.exists("/usr/bin/apt-get").pipe(Effect.orElseSucceed(() => false));
135
113 - if (!needsProfile && missing.length === 0) {
136 + if (!needsProfile && missing.length === 0 && !needsFonts) {
137 return yield* Console.log(
138 rootWarning ??
139 (Option.isSome(browser)
@@ -128,6 +151,11 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
151 if (missing.length > 0) {
152 yield* Console.log(`T3's browser is missing ${missing.join(", ")}; setup installs them.`);
153 }
154 + if (needsFonts) {
155 + yield* Console.log(
156 + "T3's browser needs fontconfig and system fonts; setup installs them.",
157 + );
158 + }
159 return yield* Console.log(`\nThis needs root. Run:\n\n ${setupCommand}\n`);
160 }
161
@@ -153,13 +181,24 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
181 yield* Console.log("Allowed Chrome's sandbox for T3's browser.");
182 }
183
156 - if (missing.length > 0) {
157 - if (!hasApt) {
158 - return yield* Console.log(
184 + if ((missing.length > 0 || needsFonts) && !hasApt) {
185 + if (missing.length > 0) {
186 + yield* Console.log(
187 `T3's browser is missing ${missing.join(", ")}. Install them with your package manager, then run this again.`,
188 );
189 }
190 + if (needsFonts) {
191 + yield* Console.log(
192 + "T3's browser needs fontconfig and system fonts. Install them with your package manager, then run this again.",
193 + );
194 + }
195 + return;
196 + }
197 + if (missing.length > 0 || needsFonts) {
198 yield* runStep("refresh the package lists", "apt-get", ["update"]);
199 + }
200 +
201 + if (missing.length > 0) {
202 const packages = yield* Effect.forEach(PreviewBrowserHost.DEBIAN_PACKAGES, (names) =>
203 Effect.findFirst(names, aptOffers).pipe(Effect.map(Option.getOrElse(() => names[0]!))),
204 );
@@ -172,6 +211,23 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
211 yield* Console.log("Installed the browser's libraries.");
212 }
213
214 + if (needsFonts) {
215 + yield* runStep("install the browser's fonts", "apt-get", [
216 + "install",
217 + "-y",
218 + "--no-install-recommends",
219 + ...FONT_PACKAGES,
220 + ]);
221 + if (!(yield* fontAvailable)) {
222 + return yield* Console.log(
223 + "Font packages are installed, but Fontconfig still finds no system font. Check its configuration and run setup again.",
224 + );
225 + }
226 + yield* Console.log(
227 + "Installed the browser's fonts. Restart the T3 server if browser tabs were already open.",
228 + );
229 + }
230 +
231 yield* Console.log(rootWarning ?? "This host is ready for T3's browser.");
232 }),
233 ),
docs/user/remote-access.md
+3 -2
@@ -231,8 +231,9 @@ The server shows the exact line for how you started it, such as
231 `sudo npx t3 browser setup`, and keeps your `PATH` when Node is installed only
232 for your user. Where `t3` is not on your `PATH`, such as with only the
233 desktop app installed, it names the full path of the app's own `t3` instead. It allows Chrome's sandbox with an AppArmor profile and installs
234 -any missing libraries with apt. It is safe to run again. Without `sudo`, it
235 -only reports what it would change.
234 +any missing libraries and system fonts with apt; pages that load without text
235 +can mean the host has no fonts. It is safe to run again. Without `sudo`, it only
236 +reports what it would change.
237
238 The browser always runs in Chrome's sandbox. Where you cannot change the host,
239 set `T3CODE_SERVER_BROWSER_SANDBOX=0` for the environment to run without it.