TypeScript
fix(cli): keep --base-dir in the sudo command browser setup prints (#23646)
Victor Vogelcf930195b4d6
diff --git a/apps/server/src/cli/browser.ts b/apps/server/src/cli/browser.tsindex 34a2efc55d5..ea3dbd347e5 100644--- a/apps/server/src/cli/browser.ts+++ b/apps/server/src/cli/browser.ts@@ -114,16 +114,21 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe}const fs = yield* FileSystem.FileSystem;const isRoot = (yield* HostProcess.UserId) === 0;- const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND);- // Root, unless sudo came from another user, is likely the server's own account.const env = yield* HostProcess.Environment;+ const baseDirPath = yield* setupBaseDir(baseDir);+ // sudo resets the environment, so a chosen home has to be on the command line.+ const setupCommand = yield* resolveRootCliCommand(+ PreviewBrowserHost.SETUP_SUBCOMMAND,+ Option.isSome(baseDir) || env.T3CODE_HOME !== undefined ? ["--base-dir", baseDirPath] : [],+ );+ // Root, unless sudo came from another user, is likely the server's own account.const rootWarning =isRoot && (env.SUDO_USER ?? "root") === "root" && !PreviewBrowserHost.sandboxDisabled(env)? new PreviewBrowserHost.PreviewBrowserRootError().message: undefined;const needsProfile = yield* PreviewBrowserHost.sandboxBlocked;- const browser = yield* installedBrowser(yield* setupBaseDir(baseDir));+ const browser = yield* installedBrowser(baseDirPath);const missing = Option.isSome(browser)? yield* PreviewBrowserHost.missingLibraries(browser.value): [];diff --git a/apps/server/src/cli/invocation.test.ts b/apps/server/src/cli/invocation.test.tsindex cd00f6ba1e4..ab68a689066 100644--- a/apps/server/src/cli/invocation.test.ts+++ b/apps/server/src/cli/invocation.test.ts@@ -19,8 +19,9 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {readonly path?: string;readonly env?: Record<string, string>;readonly executable?: boolean;+ readonly args?: ReadonlyArray<string>;}) =>- resolveRootCliCommand("browser setup").pipe(+ resolveRootCliCommand("browser setup", input.args).pipe(Effect.provideService(HostProcess.ExecutablePath, input.node),Effect.provideService(HostProcess.Arguments, [input.node, input.entry]),Effect.provideService(HostProcess.IsExecutable, input.executable ?? false),@@ -55,6 +56,23 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {}).pipe(Effect.scoped),);+ it.effect("keeps the arguments, so root runs setup on the same T3 home", () =>+ Effect.gen(function* () {+ const args = ["--base-dir", "/srv/t3 home"];+ expect(+ yield* rootCommand({+ node: "/home/theo/.local/node/bin/node",+ entry: "/home/theo/.local/lib/node_modules/t3/dist/bin.mjs",+ path: yield* pathWithT3,+ args,+ }),+ ).toBe(`sudo env "PATH=$PATH" t3 browser setup --base-dir '/srv/t3 home'`);+ expect(+ yield* rootCommand({ node: "/opt/t3/t3", entry: "/opt/t3/t3", executable: true, args }),+ ).toBe("sudo /opt/t3/t3 browser setup --base-dir '/srv/t3 home'");+ }).pipe(Effect.scoped),+ );+it.effect("names this install's launcher when t3 is not on PATH", () =>Effect.gen(function* () {const fs = yield* FileSystem.FileSystem;diff --git a/apps/server/src/cli/invocation.ts b/apps/server/src/cli/invocation.tsindex dbff3add054..283da3d041d 100644--- a/apps/server/src/cli/invocation.ts+++ b/apps/server/src/cli/invocation.ts@@ -181,8 +181,9 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand*/export const resolveRootCliCommand = Effect.fn("invocation.resolveRootCliCommand")(function* (subcommand: string,+ args: ReadonlyArray<string> = [],) {- const { command, launcher } = yield* resolveHostCliCommand(subcommand);+ const { command, launcher } = yield* resolveHostCliCommand(subcommand, args);if (launcher) return `sudo ${command}`;const executablePath = yield* HostProcess.ExecutablePath;const systemNode = ROOT_PATH_DIRECTORIES.some((directory) =>