TypeScript
fix(cli): make relative install homes produce working commands (#29241)
Lakshmi Tanmay87e13d3fe177
diff --git a/scripts/install.sh b/scripts/install.shindex 6e7ef3c77ca..ea7ec1e6c47 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -20,6 +20,14 @@ set -eurepo="pingdotgg/t3code"base_url="${T3CODE_RELEASE_BASE_URL:-https://github.com/${repo}/releases/download}"t3_home="${T3CODE_HOME:-$HOME/.t3}"+case "$t3_home" in+ /*) ;;+ *)+ # Preserve cwd's trailing newlines; trim only pwd's newline and the sentinel.+ t3_cwd="$(pwd -P && printf .)"+ t3_home="${t3_cwd%??}/$t3_home"+ ;;+esacbin_dir="${T3CODE_INSTALL_BIN_DIR:-$HOME/.local/bin}"fail() {diff --git a/scripts/install.test.ts b/scripts/install.test.tsindex 51d074fffba..910f780fe16 100644--- a/scripts/install.test.ts+++ b/scripts/install.test.ts@@ -12,6 +12,54 @@ const nightlies = Array.from({ length: 100 }, (_, index) => ({tag_name: `v1.2.4-nightly.20261020.${200 - index}`,}));+describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer home", () => {+ it("installs a relative home from a directory ending in a newline", async () => {+ const temporaryRoot = await NodeFSP.realpath(+ await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-home-")),+ );+ const root = NodePath.join(temporaryRoot, "cwd\n");+ const homeName = "-custom home\\home\n";+ const home = NodePath.join(root, homeName);+ const version = "1.2.3";+ const target = NodePath.join(home, "runtime/versions", version);+ const launcher = NodePath.join(root, "bin/t3");+ try {+ await NodeFSP.mkdir(target, { recursive: true });+ await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), `${version}\n`);+ await NodeFSP.writeFile(NodePath.join(target, "t3"), "#!/bin/sh\necho 't3 v1.2.3'\n", {+ mode: 0o755,+ });+ const { status, stdout, stderr } = NodeChildProcess.spawnSync(+ "sh",+ [NodePath.resolve(import.meta.dirname, "install.sh")],+ {+ cwd: root,+ env: {+ ...process.env,+ HOME: root,+ T3CODE_HOME: homeName,+ T3CODE_VERSION: version,+ T3CODE_INSTALL_BIN_DIR: NodePath.dirname(launcher),+ T3CODE_RELEASE_BASE_URL: "http://127.0.0.1:1",+ },+ encoding: "utf8",+ },+ );+ expect(status, stdout + stderr).toBe(0);+ expect(stderr).toContain(`Installed T3 Code ${version}`);+ expect(await NodeFSP.readlink(launcher)).toBe(NodePath.join(target, "t3"));+ expect(+ NodeChildProcess.execFileSync(launcher, ["--version"], {+ cwd: NodeOS.tmpdir(),+ encoding: "utf8",+ }).trim(),+ ).toBe("t3 v1.2.3");+ } finally {+ await NodeFSP.rm(temporaryRoot, { recursive: true, force: true });+ }+ });+});+// regression: #22490describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer channel lookup", () => {it.each([