Skip to content

Commit c4d286e

Browse files
test(server): cover CLI runner detection through command suggestions
1 parent a98dad7 commit c4d286e

2 files changed

Lines changed: 49 additions & 36 deletions

File tree

‎apps/server/src/cli/invocation.test.ts‎

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,62 @@
11
import { assert, it } from "@effect/vitest";
22

3-
import { detectCliRunner, formatCliCommand, suggestedPackageSpec } from "./invocation.ts";
3+
import { formatCliCommand } from "./invocation.ts";
44

5-
it("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(
5+
it("formats package runner commands from their cache entry paths", () => {
6+
for (const [entryPath, expected] of [
7+
["/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs", "npx t3 serve"],
8+
[
99
"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(
10+
"npx t3 serve",
11+
],
12+
["/home/theo/.cache/pnpm/dlx/abc/node_modules/t3/dist/bin.mjs", "pnpm dlx t3 serve"],
13+
[
14+
"/home/theo/.local/share/pnpm/.pnpm/dlx/abc/node_modules/t3/dist/bin.mjs",
15+
"pnpm dlx t3 serve",
16+
],
17+
[
2318
"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/[email protected]/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(
19+
"pnpm dlx t3 serve",
20+
],
21+
["/home/theo/.bun/install/cache/[email protected]/dist/bin.mjs", "bunx t3 serve"],
22+
["/tmp/bunx-1000-t3@latest/node_modules/t3/dist/bin.mjs", "bunx t3 serve"],
23+
[
3124
"C:\\Users\\theo\\AppData\\Local\\Temp\\bunx-0-t3@latest\\node_modules\\t3\\dist\\bin.mjs",
32-
),
33-
"bunx",
34-
);
25+
"bunx t3 serve",
26+
],
27+
] as const) {
28+
assert.equal(formatCliCommand({ subcommand: "serve", entryPath, version: "0.0.31" }), expected);
29+
}
3530
});
3631

3732
it("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(""));
33+
for (const entryPath of [
34+
"/usr/local/lib/node_modules/t3/dist/bin.mjs",
35+
"/home/theo/Code/work/t3code/apps/server/dist/bin.mjs",
36+
"/home/theo/.t3/runtime/0.0.31/node_modules/t3/dist/bin.mjs",
37+
"",
38+
]) {
39+
assert.equal(
40+
formatCliCommand({ subcommand: "serve", entryPath, version: "0.0.31" }),
41+
"t3 serve",
42+
);
43+
}
4244
});
4345

4446
it("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+
for (const [version, expected] of [
48+
["0.0.31-nightly.20260729", "npx t3@nightly serve"],
49+
["0.0.31", "npx t3 serve"],
50+
] as const) {
51+
assert.equal(
52+
formatCliCommand({
53+
subcommand: "serve",
54+
entryPath: "/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs",
55+
version,
56+
}),
57+
expected,
58+
);
59+
}
4760
});
4861

4962
it("formats serve suggestions to match the launching command", () => {

‎apps/server/src/cli/invocation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type CliRunner = "npx" | "pnpm dlx" | "bunx";
1818
* Global installs and repo checkouts match none of these and return null.
1919
* Detection is best-effort; callers must fail closed to a plain `t3` command.
2020
*/
21-
export function detectCliRunner(entryPath: string): CliRunner | null {
21+
function detectCliRunner(entryPath: string): CliRunner | null {
2222
const path = entryPath.replaceAll("\\", "/");
2323
if (path.includes("/_npx/")) {
2424
return "npx";
@@ -42,7 +42,7 @@ export function detectCliRunner(entryPath: string): CliRunner | null {
4242
* from the running version: nightly builds re-suggest the nightly channel,
4343
* anything else suggests the bare package.
4444
*/
45-
export function suggestedPackageSpec(version: string): string {
45+
function suggestedPackageSpec(version: string): string {
4646
return version.includes("-nightly.") ? "t3@nightly" : "t3";
4747
}
4848

0 commit comments

Comments
 (0)