Skip to content

Commit 87e13d3

Browse files
authored
fix(cli): make relative install homes produce working commands (pingdotgg#29241)
1 parent a5e7e5b commit 87e13d3

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎scripts/install.sh‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ set -eu
2020
repo="pingdotgg/t3code"
2121
base_url="${T3CODE_RELEASE_BASE_URL:-https://github.com/${repo}/releases/download}"
2222
t3_home="${T3CODE_HOME:-$HOME/.t3}"
23+
case "$t3_home" in
24+
/*) ;;
25+
*)
26+
# Preserve cwd's trailing newlines; trim only pwd's newline and the sentinel.
27+
t3_cwd="$(pwd -P && printf .)"
28+
t3_home="${t3_cwd%??}/$t3_home"
29+
;;
30+
esac
2331
bin_dir="${T3CODE_INSTALL_BIN_DIR:-$HOME/.local/bin}"
2432

2533
fail() {

‎scripts/install.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,54 @@ const nightlies = Array.from({ length: 100 }, (_, index) => ({
1212
tag_name: `v1.2.4-nightly.20261020.${200 - index}`,
1313
}));
1414

15+
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer home", () => {
16+
it("installs a relative home from a directory ending in a newline", async () => {
17+
const temporaryRoot = await NodeFSP.realpath(
18+
await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-home-")),
19+
);
20+
const root = NodePath.join(temporaryRoot, "cwd\n");
21+
const homeName = "-custom home\\home\n";
22+
const home = NodePath.join(root, homeName);
23+
const version = "1.2.3";
24+
const target = NodePath.join(home, "runtime/versions", version);
25+
const launcher = NodePath.join(root, "bin/t3");
26+
try {
27+
await NodeFSP.mkdir(target, { recursive: true });
28+
await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), `${version}\n`);
29+
await NodeFSP.writeFile(NodePath.join(target, "t3"), "#!/bin/sh\necho 't3 v1.2.3'\n", {
30+
mode: 0o755,
31+
});
32+
const { status, stdout, stderr } = NodeChildProcess.spawnSync(
33+
"sh",
34+
[NodePath.resolve(import.meta.dirname, "install.sh")],
35+
{
36+
cwd: root,
37+
env: {
38+
...process.env,
39+
HOME: root,
40+
T3CODE_HOME: homeName,
41+
T3CODE_VERSION: version,
42+
T3CODE_INSTALL_BIN_DIR: NodePath.dirname(launcher),
43+
T3CODE_RELEASE_BASE_URL: "http://127.0.0.1:1",
44+
},
45+
encoding: "utf8",
46+
},
47+
);
48+
expect(status, stdout + stderr).toBe(0);
49+
expect(stderr).toContain(`Installed T3 Code ${version}`);
50+
expect(await NodeFSP.readlink(launcher)).toBe(NodePath.join(target, "t3"));
51+
expect(
52+
NodeChildProcess.execFileSync(launcher, ["--version"], {
53+
cwd: NodeOS.tmpdir(),
54+
encoding: "utf8",
55+
}).trim(),
56+
).toBe("t3 v1.2.3");
57+
} finally {
58+
await NodeFSP.rm(temporaryRoot, { recursive: true, force: true });
59+
}
60+
});
61+
});
62+
1563
// regression: #22490
1664
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer channel lookup", () => {
1765
it.each([

0 commit comments

Comments
 (0)