GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — t3code/scripts/install.test.ts at main · AndryHTC/t3code

Expand file tree

/

install.test.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
468 lines (446 loc) · 20.3 KB
/

install.test.ts

Copy path

File metadata and controls

468 lines (446 loc) · 20.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
// @effect-diagnostics nodeBuiltinImport:off - Drives the real shell installer against a local GitHub fixture.
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as NodeChildProcess from "node:child_process";
import * as NodeCrypto from "node:crypto";
import * as NodeFSP from "node:fs/promises";
import * as NodeHttp from "node:http";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
import { describe, expect, it } from "vite-plus/test";
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: #22490
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer channel lookup", () => {
it.each([
// regression: #32897
["stable", "1.2.3", 1],
["preview", "1.2.4-preview.20261019.50", 0],
])("finds %s %s behind nightlies and %i HTTP 504s", async (channel, version, failures) => {
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-index-"));
const target = NodePath.join(root, "home/runtime/versions", version);
const server = NodeHttp.createServer((request, response) => {
if (failures-- > 0) return response.writeHead(504).end();
const url = new URL(request.url ?? "/", "http://fixture");
const body =
url.pathname === "/pingdotgg/t3code/releases/latest" &&
request.headers.accept === "application/json"
? { tag_name: "v1.2.3" }
: url.pathname === "/repos/pingdotgg/t3code/releases"
? { "1": nightlies, "2": [{ tag_name: `v${version}` }, { tag_name: "v1.2.3" }] }[
url.searchParams.get("page") ?? ""
]
: undefined;
if (body === undefined) response.statusCode = 404;
// The API pretty-prints and the installer reads it line by line.
response.end(JSON.stringify(body ?? [], null, 2));
});
try {
// An existing completed install isolates release resolution from archive downloads.
await NodeFSP.mkdir(target, { recursive: true });
await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), `${version}\n`);
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
const origin = `http://127.0.0.1:${address.port}`;
const source = await NodeFSP.readFile(
NodePath.resolve(import.meta.dirname, "install.sh"),
"utf8",
);
const installer = NodePath.join(root, "install.sh");
await NodeFSP.writeFile(installer, source.replace(/https:\/\/(api\.)?github\.com/g, origin));
const { code, output } = await new Promise<{ code: number | null; output: string }>(
(resolve, reject) => {
const child = NodeChildProcess.spawn("sh", [installer], {
env: {
...process.env,
T3CODE_VERSION: "",
T3CODE_CHANNEL: channel,
T3CODE_HOME: NodePath.join(root, "home"),
T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin"),
// A wrong version must fail here instead of downloading a real release.
T3CODE_RELEASE_BASE_URL: origin,
},
stdio: ["ignore", "pipe", "pipe"],
});
let output = "";
child.stdout.on("data", (chunk: Buffer) => (output += chunk.toString()));
child.stderr.on("data", (chunk: Buffer) => (output += chunk.toString()));
child.on("error", reject);
child.on("close", (code) => resolve({ code, output }));
},
);
expect(code, output).toBe(0);
expect(output).toContain(`Installed T3 Code ${version}`);
} finally {
server.closeAllConnections();
await new Promise<void>((resolve) => server.close(() => resolve()));
await NodeFSP.rm(root, { recursive: true, force: true });
}
});
});
/** Runs an installer for a version that is already unpacked, so only the t3 command step runs. */
async function installOver(input: {
readonly script: "install.sh" | "install.ps1";
readonly home: string;
readonly binDir: string;
readonly env?: NodeJS.ProcessEnv;
readonly cwd?: string;
}) {
const target = NodePath.join(input.home, "runtime", "versions", "1.2.3");
await NodeFSP.mkdir(target, { recursive: true });
await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), "1.2.3\n");
const installer = NodePath.resolve(import.meta.dirname, input.script);
const [command, args] =
input.script === "install.sh"
? ["sh", [installer]]
: ["powershell.exe", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", installer]];
const result = NodeChildProcess.spawnSync(command, args, {
encoding: "utf8",
...(input.cwd === undefined ? {} : { cwd: input.cwd }),
env: {
...process.env,
T3CODE_CHANNEL: "",
T3CODE_VERSION: "1.2.3",
T3CODE_HOME: input.home,
T3CODE_INSTALL_BIN_DIR: input.binDir,
T3CODE_RELEASE_BASE_URL: "http://127.0.0.1:9",
...input.env,
},
});
return { code: result.status, output: `${result.stdout}${result.stderr}`, target };
}
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("install.sh t3 command", () => {
it("replaces only this home's own links and prints a PATH command", async () => {
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-link-"));
try {
const home = NodePath.join(root, "home");
const binDir = NodePath.join(root, "bin");
const link = NodePath.join(binDir, "t3");
await NodeFSP.mkdir(binDir, { recursive: true });
await NodeFSP.writeFile(link, "#!/bin/sh\necho mine\n");
const foreign = await installOver({ script: "install.sh", home, binDir });
expect(foreign.code).not.toBe(0);
expect(foreign.output).toContain(`another t3 is already at ${link}`);
expect(await NodeFSP.readFile(link, "utf8")).toBe("#!/bin/sh\necho mine\n");
// Not even from inside the versions folder, where `.` would resolve into it.
const fromVersions = await installOver({
script: "install.sh",
home,
binDir,
cwd: foreign.target,
});
expect(fromVersions.code).not.toBe(0);
expect(await NodeFSP.readFile(link, "utf8")).toBe("#!/bin/sh\necho mine\n");
// A link that only looks like it points into versions (join() would normalize the ..).
await NodeFSP.rm(link);
await NodeFSP.mkdir(NodePath.join(home, "other"), { recursive: true });
await NodeFSP.writeFile(NodePath.join(home, "other/t3"), "#!/bin/sh\n");
await NodeFSP.symlink(`${home}/runtime/versions/../../other/t3`, link);
const climbing = await installOver({ script: "install.sh", home, binDir });
expect(climbing.code).not.toBe(0);
expect(await NodeFSP.readlink(link)).toBe(`${home}/runtime/versions/../../other/t3`);
// Only `<version>/t3` counts, not another program inside a version.
await NodeFSP.rm(link);
await NodeFSP.symlink(NodePath.join(home, "runtime/versions/1.0.0/helper"), link);
const sibling = await installOver({ script: "install.sh", home, binDir });
expect(sibling.code).not.toBe(0);
expect(await NodeFSP.readlink(link)).toBe(
NodePath.join(home, "runtime/versions/1.0.0/helper"),
);
// An upgrade over an older version's link, written through a symlinked T3 home.
await NodeFSP.rm(link);
await NodeFSP.symlink(NodePath.join(home, "runtime/versions/1.0.0/t3"), link);
await NodeFSP.symlink(home, NodePath.join(root, "alias"));
const upgrade = await installOver({
script: "install.sh",
home: NodePath.join(root, "alias"),
binDir,
env: { HOME: root, SHELL: "/bin/zsh", PATH: "/usr/bin:/bin" },
});
expect(upgrade.code, upgrade.output).toBe(0);
expect(await NodeFSP.readlink(link)).toBe(
NodePath.join(root, "alias/runtime/versions/1.2.3/t3"),
);
expect(upgrade.output).toContain(
`printf '\\n%s\\n' 'export PATH="$PATH:$HOME/bin"' >> ~/.zshrc`,
);
// Containers and CI often have no SHELL; `set -u` must not stop the installer there.
const noShell = await installOver({
script: "install.sh",
home,
binDir,
env: { HOME: root, SHELL: undefined, PATH: "/usr/bin:/bin" },
});
expect(noShell.code, noShell.output).toBe(0);
expect(noShell.output).toContain(`Add ${binDir} to your PATH`);
// Its folder on PATH with a trailing slash is still this t3, not another one.
const slashed = await installOver({
script: "install.sh",
home,
binDir,
env: { HOME: root, PATH: `${binDir}/:/usr/bin:/bin` },
});
expect(slashed.code, slashed.output).toBe(0);
expect(slashed.output).toContain("Run t3 to use T3 Code here");
// A relative folder is made absolute, so the PATH command never follows the working directory.
const relative = await installOver({
script: "install.sh",
home,
binDir: "bin",
cwd: root,
env: { HOME: root, SHELL: "/bin/zsh", PATH: "/usr/bin:/bin" },
});
expect(relative.code, relative.output).toBe(0);
expect(relative.output).toContain(`'export PATH="$PATH:$HOME/bin"'`);
await NodeFSP.rm(link);
await NodeFSP.symlink(NodePath.join(home, "bin/t3"), link);
const overDesktop = await installOver({
script: "install.sh",
home: `${home}//`,
binDir: `${binDir}/`,
});
expect(overDesktop.code, overDesktop.output).toBe(0);
expect(await NodeFSP.readlink(link)).toBe(NodePath.join(home, "runtime/versions/1.2.3/t3"));
} finally {
await NodeFSP.rm(root, { recursive: true, force: true });
}
});
});
describe.skipIf(HostProcess.Platform.defaultValue() !== "win32")("install.ps1 t3 command", () => {
it("replaces only its own t3.cmd, also in non-ASCII and bracketed paths", async () => {
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-ps1-"));
try {
// Windows PowerShell 5.1 reads files as ANSI by default and expands wildcards in paths.
const home = NodePath.join(root, "José", ".t3");
const binDir = NodePath.join(root, "bin[t3]");
const shim = NodePath.join(binDir, "t3.cmd");
await NodeFSP.mkdir(binDir, { recursive: true });
const desktopShim = '@echo off\r\n"C:\\Program Files\\T3 Code\\T3 Code.exe" "x" %*\r\n';
await NodeFSP.writeFile(shim, desktopShim);
const foreign = await installOver({ script: "install.ps1", home, binDir });
expect(foreign.code).not.toBe(0);
expect(foreign.output).toContain("another t3 is already at");
expect(await NodeFSP.readFile(shim, "utf8")).toBe(desktopShim);
// A hand-edited wrapper may set its own environment; replacing it would drop that.
const edited = `@echo off\r\nset "T3CODE_HOME=D:\\other"\r\n"${NodePath.join(home, "runtime", "versions", "1.0.0", "t3.exe")}" %*`;
await NodeFSP.writeFile(shim, edited, "utf8");
const wrapper = await installOver({ script: "install.ps1", home, binDir });
expect(wrapper.code).not.toBe(0);
expect(await NodeFSP.readFile(shim, "utf8")).toBe(edited);
const climbing = `@echo off\r\n"${NodePath.join(home, "runtime", "versions")}\\..\\other\\t3.exe" %*`;
await NodeFSP.writeFile(shim, climbing, "utf8");
const outside = await installOver({ script: "install.ps1", home, binDir });
expect(outside.code).not.toBe(0);
expect(await NodeFSP.readFile(shim, "utf8")).toBe(climbing);
const older = NodePath.join(home, "runtime", "versions", "1.0.0", "t3.exe");
await NodeFSP.writeFile(shim, `@echo off\r\n"${older}" %*`, "utf8");
const upgrade = await installOver({ script: "install.ps1", home, binDir });
expect(upgrade.code, upgrade.output).toBe(0);
expect(await NodeFSP.readFile(shim, "utf8")).toContain(
NodePath.join(upgrade.target, "t3.exe"),
);
const again = await installOver({ script: "install.ps1", home, binDir });
expect(again.code, again.output).toBe(0);
// Another t3 first on PATH still runs, so the installer names this one in full.
const otherBin = NodePath.join(root, "other");
await NodeFSP.mkdir(otherBin);
await NodeFSP.writeFile(NodePath.join(otherBin, "t3.cmd"), "@echo off\r\n");
// Windows spells it Path; a second PATH key would be ambiguous.
const pathKey =
Object.keys(process.env).find((key) => key.toUpperCase() === "PATH") ?? "PATH";
const shadowed = await installOver({
script: "install.ps1",
home,
binDir,
env: { [pathKey]: `${otherBin};${process.env[pathKey] ?? ""}` },
});
expect(shadowed.code, shadowed.output).toBe(0);
expect(shadowed.output).toContain(
`Another t3 at ${NodePath.join(otherBin, "t3.cmd")} runs first`,
);
// Its own folder on PATH with a trailing separator is already on PATH.
const slashed = await installOver({
script: "install.ps1",
home,
binDir,
env: { [pathKey]: `${binDir}\\;${process.env[pathKey] ?? ""}` },
});
expect(slashed.code, slashed.output).toBe(0);
expect(slashed.output).toContain("to use T3 Code here");
// The same when the install folder itself is given with a trailing separator.
const bothSlashed = await installOver({
script: "install.ps1",
home,
binDir: `${binDir}\\`,
env: { [pathKey]: `${binDir}\\;${process.env[pathKey] ?? ""}` },
});
expect(bothSlashed.code, bothSlashed.output).toBe(0);
expect(bothSlashed.output).toContain("to use T3 Code here");
} finally {
await NodeFSP.rm(root, { recursive: true, force: true });
}
});
});
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer checksum", () => {
it.each(
["home\\data", "home\ndata"].flatMap((homeName) =>
[true, false].map((validChecksum) => ({ homeName, validChecksum })),
),
)(
"verifies home $homeName with valid checksum $validChecksum",
async ({ homeName, validChecksum }) => {
const availableTools = ["sha256sum", "shasum"].filter(
(tool) =>
NodeChildProcess.spawnSync("sh", ["-c", 'command -v "$1"', "sh", tool]).status === 0,
);
expect(availableTools.length).toBeGreaterThan(0);
for (const checksumTool of availableTools) {
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-checksum-"));
const home = NodePath.join(root, homeName);
const version = "1.2.3";
const stem = `t3-${version}-linux-${HostProcess.Architecture.defaultValue()}`;
const archiveName = `${stem}.tar.gz`;
const server = NodeHttp.createServer();
try {
const tools = NodePath.join(root, "tools");
await NodeFSP.mkdir(tools);
for (const command of [
"sh",
"uname",
"tar",
"gzip",
"cut",
"curl",
"grep",
"mkdir",
"mktemp",
"rm",
"mv",
"ln",
checksumTool,
]) {
const executable = NodeChildProcess.execFileSync(
"sh",
["-c", 'command -v "$1"', "sh", command],
{ encoding: "utf8" },
).trim();
await NodeFSP.symlink(executable, NodePath.join(tools, command));
}
await NodeFSP.mkdir(NodePath.join(root, stem));
await NodeFSP.writeFile(
NodePath.join(root, stem, "t3"),
"#!/bin/sh\necho 't3 v1.2.3'\n",
{ mode: 0o755 },
);
const archivePath = NodePath.join(root, archiveName);
NodeChildProcess.execFileSync("tar", ["-czf", archivePath, "-C", root, stem]);
const archive = await NodeFSP.readFile(archivePath);
const digest = NodeCrypto.createHash("sha256").update(archive).digest("hex");
server.on("request", (request, response) => {
response.end(
request.url?.endsWith("/SHA256SUMS")
? `${validChecksum ? digest : "0".repeat(64)} ${archiveName}\n`
: archive,
);
});
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
const { code, output } = await new Promise<{ code: number | null; output: string }>(
(resolve, reject) => {
const child = NodeChildProcess.spawn(
"sh",
[NodePath.resolve(import.meta.dirname, "install.sh")],
{
env: {
...process.env,
PATH: tools,
T3CODE_VERSION: version,
T3CODE_HOME: home,
T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin"),
T3CODE_RELEASE_BASE_URL: `http://127.0.0.1:${address.port}`,
},
stdio: ["ignore", "pipe", "pipe"],
},
);
let output = "";
child.stdout.on("data", (chunk: Buffer) => (output += chunk.toString()));
child.stderr.on("data", (chunk: Buffer) => (output += chunk.toString()));
child.on("error", reject);
child.on("close", (code) => resolve({ code, output }));
},
);
const versions = NodePath.join(home, "runtime/versions");
if (validChecksum) {
expect(code, `${checksumTool}: ${output}`).toBe(0);
expect(
await NodeFSP.readFile(NodePath.join(versions, version, ".install-complete"), "utf8"),
).toBe("1.2.3\n");
expect(
NodeChildProcess.execFileSync(NodePath.join(root, "bin/t3"), ["--version"], {
encoding: "utf8",
}).trim(),
).toBe("t3 v1.2.3");
} else {
expect(code).not.toBe(0);
expect(output).toContain("checksum mismatch");
expect(output).not.toContain("Installed T3 Code");
expect(await NodeFSP.readdir(versions)).toEqual([]);
}
} finally {
server.closeAllConnections();
await new Promise<void>((resolve) => server.close(() => resolve()));
await NodeFSP.rm(root, { recursive: true, force: true });
}
}
},
);
});
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.