Skip to content

Commit 6542d56

Browse files
committed
fix(cli): make relative install homes produce working commands
1 parent 47f2c8d commit 6542d56

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎scripts/install.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ 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+
*) t3_home="$(pwd -P)/$t3_home" ;;
26+
esac
2327
bin_dir="${T3CODE_INSTALL_BIN_DIR:-$HOME/.local/bin}"
2428

2529
fail() {

‎scripts/install.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,58 @@ 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.each([
17+
{ kind: "default", homeName: ".t3" },
18+
{ kind: "absolute", homeName: "absolute home" },
19+
{ kind: "relative", homeName: "custom-home" },
20+
{ kind: "relative", homeName: "custom home" },
21+
{ kind: "relative", homeName: "-custom\\home\n" },
22+
])("installs an executable link with $kind home $homeName", async ({ kind, homeName }) => {
23+
const root = await NodeFSP.realpath(
24+
await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-home-")),
25+
);
26+
const home = NodePath.join(root, homeName);
27+
const version = "1.2.3";
28+
const target = NodePath.join(home, "runtime/versions", version);
29+
const launcher = NodePath.join(root, "bin/t3");
30+
try {
31+
await NodeFSP.mkdir(target, { recursive: true });
32+
await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), `${version}\n`);
33+
await NodeFSP.writeFile(NodePath.join(target, "t3"), "#!/bin/sh\necho 't3 v1.2.3'\n", {
34+
mode: 0o755,
35+
});
36+
const { status, stdout, stderr } = NodeChildProcess.spawnSync(
37+
"sh",
38+
[NodePath.resolve(import.meta.dirname, "install.sh")],
39+
{
40+
cwd: root,
41+
env: {
42+
...process.env,
43+
HOME: root,
44+
T3CODE_HOME: kind === "default" ? undefined : kind === "absolute" ? home : homeName,
45+
T3CODE_VERSION: version,
46+
T3CODE_INSTALL_BIN_DIR: NodePath.dirname(launcher),
47+
T3CODE_RELEASE_BASE_URL: "http://127.0.0.1:1",
48+
},
49+
encoding: "utf8",
50+
},
51+
);
52+
expect(status, stdout + stderr).toBe(0);
53+
expect(stderr).toContain(`Installed T3 Code ${version}`);
54+
expect(await NodeFSP.readlink(launcher)).toBe(NodePath.join(target, "t3"));
55+
expect(
56+
NodeChildProcess.execFileSync(launcher, ["--version"], {
57+
cwd: NodeOS.tmpdir(),
58+
encoding: "utf8",
59+
}).trim(),
60+
).toBe("t3 v1.2.3");
61+
} finally {
62+
await NodeFSP.rm(root, { recursive: true, force: true });
63+
}
64+
});
65+
});
66+
1567
// regression: #22490
1668
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer channel lookup", () => {
1769
it.each([

0 commit comments

Comments
 (0)