Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2
3import { detectCliRunner, formatCliCommand, suggestedPackageSpec } from "./invocation.ts";
4
5it("detects package runners from their cache entry paths", () => {
6 assert.equal(detectCliRunner("/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs"), "npx");
7 assert.equal(
8 detectCliRunner(
9 "C:\\Users\\theo\\AppData\\Local\\npm-cache\\_npx\\abc\\node_modules\\t3\\dist\\bin.mjs",
10 ),
11 "npx",
12 );
13 assert.equal(
14 detectCliRunner("/home/theo/.cache/pnpm/dlx/abc/node_modules/t3/dist/bin.mjs"),
15 "pnpm dlx",
16 );
17 assert.equal(
18 detectCliRunner("/home/theo/.local/share/pnpm/.pnpm/dlx/abc/node_modules/t3/dist/bin.mjs"),
19 "pnpm dlx",
20 );
21 assert.equal(
22 detectCliRunner(
23 "C:\\Users\\theo\\AppData\\Local\\pnpm-cache\\dlx\\abc\\node_modules\\t3\\dist\\bin.mjs",
24 ),
25 "pnpm dlx",
26 );
27 assert.equal(detectCliRunner("/home/theo/.bun/install/cache/t3@0.0.31/dist/bin.mjs"), "bunx");
28 assert.equal(detectCliRunner("/tmp/bunx-1000-t3@latest/node_modules/t3/dist/bin.mjs"), "bunx");
29 assert.equal(
30 detectCliRunner(
31 "C:\\Users\\theo\\AppData\\Local\\Temp\\bunx-0-t3@latest\\node_modules\\t3\\dist\\bin.mjs",
32 ),
33 "bunx",
34 );
35});
36
37it("treats stable installs as direct invocations", () => {
38 assert.isNull(detectCliRunner("/usr/local/lib/node_modules/t3/dist/bin.mjs"));
39 assert.isNull(detectCliRunner("/home/theo/Code/work/t3code/apps/server/dist/bin.mjs"));
40 assert.isNull(detectCliRunner("/home/theo/.t3/runtime/0.0.31/node_modules/t3/dist/bin.mjs"));
41 assert.isNull(detectCliRunner(""));
42});
43
44it("re-suggests the nightly channel only for nightly builds", () => {
45 assert.equal(suggestedPackageSpec("0.0.31-nightly.20260729"), "t3@nightly");
46 assert.equal(suggestedPackageSpec("0.0.31"), "t3");
47});
48
49it("formats serve suggestions to match the launching command", () => {
50 assert.equal(
51 formatCliCommand({
52 subcommand: "serve",
53 entryPath: "/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs",
54 version: "0.0.31-nightly.20260729",
55 }),
56 "npx t3@nightly serve",
57 );
58 assert.equal(
59 formatCliCommand({
60 subcommand: "serve",
61 entryPath: "/tmp/bunx-1000-t3@latest/node_modules/t3/dist/bin.mjs",
62 version: "0.0.31",
63 }),
64 "bunx t3 serve",
65 );
66 assert.equal(
67 formatCliCommand({
68 subcommand: "serve",
69 entryPath: "/usr/local/lib/node_modules/t3/dist/bin.mjs",
70 version: "0.0.31-nightly.20260729",
71 }),
72 "t3 serve",
73 );
74});