Skip to content

Commit cf93019

Browse files
only21milclaude
andauthored
fix(cli): keep --base-dir in the sudo command browser setup prints (#23646)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 353cf7b commit cf93019

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎apps/server/src/cli/browser.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,21 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
114114
}
115115
const fs = yield* FileSystem.FileSystem;
116116
const isRoot = (yield* HostProcess.UserId) === 0;
117-
const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND);
118-
// Root, unless sudo came from another user, is likely the server's own account.
119117
const env = yield* HostProcess.Environment;
118+
const baseDirPath = yield* setupBaseDir(baseDir);
119+
// sudo resets the environment, so a chosen home has to be on the command line.
120+
const setupCommand = yield* resolveRootCliCommand(
121+
PreviewBrowserHost.SETUP_SUBCOMMAND,
122+
Option.isSome(baseDir) || env.T3CODE_HOME !== undefined ? ["--base-dir", baseDirPath] : [],
123+
);
124+
// Root, unless sudo came from another user, is likely the server's own account.
120125
const rootWarning =
121126
isRoot && (env.SUDO_USER ?? "root") === "root" && !PreviewBrowserHost.sandboxDisabled(env)
122127
? new PreviewBrowserHost.PreviewBrowserRootError().message
123128
: undefined;
124129

125130
const needsProfile = yield* PreviewBrowserHost.sandboxBlocked;
126-
const browser = yield* installedBrowser(yield* setupBaseDir(baseDir));
131+
const browser = yield* installedBrowser(baseDirPath);
127132
const missing = Option.isSome(browser)
128133
? yield* PreviewBrowserHost.missingLibraries(browser.value)
129134
: [];

‎apps/server/src/cli/invocation.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {
1919
readonly path?: string;
2020
readonly env?: Record<string, string>;
2121
readonly executable?: boolean;
22+
readonly args?: ReadonlyArray<string>;
2223
}) =>
23-
resolveRootCliCommand("browser setup").pipe(
24+
resolveRootCliCommand("browser setup", input.args).pipe(
2425
Effect.provideService(HostProcess.ExecutablePath, input.node),
2526
Effect.provideService(HostProcess.Arguments, [input.node, input.entry]),
2627
Effect.provideService(HostProcess.IsExecutable, input.executable ?? false),
@@ -55,6 +56,23 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {
5556
}).pipe(Effect.scoped),
5657
);
5758

59+
it.effect("keeps the arguments, so root runs setup on the same T3 home", () =>
60+
Effect.gen(function* () {
61+
const args = ["--base-dir", "/srv/t3 home"];
62+
expect(
63+
yield* rootCommand({
64+
node: "/home/theo/.local/node/bin/node",
65+
entry: "/home/theo/.local/lib/node_modules/t3/dist/bin.mjs",
66+
path: yield* pathWithT3,
67+
args,
68+
}),
69+
).toBe(`sudo env "PATH=$PATH" t3 browser setup --base-dir '/srv/t3 home'`);
70+
expect(
71+
yield* rootCommand({ node: "/opt/t3/t3", entry: "/opt/t3/t3", executable: true, args }),
72+
).toBe("sudo /opt/t3/t3 browser setup --base-dir '/srv/t3 home'");
73+
}).pipe(Effect.scoped),
74+
);
75+
5876
it.effect("names this install's launcher when t3 is not on PATH", () =>
5977
Effect.gen(function* () {
6078
const fs = yield* FileSystem.FileSystem;

‎apps/server/src/cli/invocation.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand
181181
*/
182182
export const resolveRootCliCommand = Effect.fn("invocation.resolveRootCliCommand")(function* (
183183
subcommand: string,
184+
args: ReadonlyArray<string> = [],
184185
) {
185-
const { command, launcher } = yield* resolveHostCliCommand(subcommand);
186+
const { command, launcher } = yield* resolveHostCliCommand(subcommand, args);
186187
if (launcher) return `sudo ${command}`;
187188
const executablePath = yield* HostProcess.ExecutablePath;
188189
const systemNode = ROOT_PATH_DIRECTORIES.some((directory) =>

0 commit comments

Comments
 (0)