test(server): cover CLI runner detection through command suggestions (#10066)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-05 01:54:25 -07:00
1 parent 4db2c542a8
commit 0acf05f4f5
2 files changed
+49 -36

No files matched your search

+47 -34
View File
@@ -1,49 +1,62 @@
import { assert, it } from "@effect/vitest";
import { detectCliRunner, formatCliCommand, suggestedPackageSpec } from "./invocation.ts";
import { formatCliCommand } from "./invocation.ts";
it("detects package runners from their cache entry paths", () => {
assert.equal(detectCliRunner("/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs"), "npx");
assert.equal(
detectCliRunner(
it("formats package runner commands from their cache entry paths", () => {
for (const [entryPath, expected] of [
["/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs", "npx t3 serve"],
[
"C:\\Users\\theo\\AppData\\Local\\npm-cache\\_npx\\abc\\node_modules\\t3\\dist\\bin.mjs",
),
"npx",
);
assert.equal(
detectCliRunner("/home/theo/.cache/pnpm/dlx/abc/node_modules/t3/dist/bin.mjs"),
"pnpm dlx",
);
assert.equal(
detectCliRunner("/home/theo/.local/share/pnpm/.pnpm/dlx/abc/node_modules/t3/dist/bin.mjs"),
"pnpm dlx",
);
assert.equal(
detectCliRunner(
"npx t3 serve",
],
["/home/theo/.cache/pnpm/dlx/abc/node_modules/t3/dist/bin.mjs", "pnpm dlx t3 serve"],
[
"/home/theo/.local/share/pnpm/.pnpm/dlx/abc/node_modules/t3/dist/bin.mjs",
"pnpm dlx t3 serve",
],
[
"C:\\Users\\theo\\AppData\\Local\\pnpm-cache\\dlx\\abc\\node_modules\\t3\\dist\\bin.mjs",
),
"pnpm dlx",
);
assert.equal(detectCliRunner("/home/theo/.bun/install/cache/[email protected]/dist/bin.mjs"), "bunx");
assert.equal(detectCliRunner("/tmp/bunx-1000-t3@latest/node_modules/t3/dist/bin.mjs"), "bunx");
assert.equal(
detectCliRunner(
"pnpm dlx t3 serve",
],
["/home/theo/.bun/install/cache/[email protected]/dist/bin.mjs", "bunx t3 serve"],
["/tmp/bunx-1000-t3@latest/node_modules/t3/dist/bin.mjs", "bunx t3 serve"],
[
"C:\\Users\\theo\\AppData\\Local\\Temp\\bunx-0-t3@latest\\node_modules\\t3\\dist\\bin.mjs",
),
"bunx",
);
"bunx t3 serve",
],
] as const) {
assert.equal(formatCliCommand({ subcommand: "serve", entryPath, version: "0.0.31" }), expected);
}
});
it("treats stable installs as direct invocations", () => {
assert.isNull(detectCliRunner("/usr/local/lib/node_modules/t3/dist/bin.mjs"));
assert.isNull(detectCliRunner("/home/theo/Code/work/t3code/apps/server/dist/bin.mjs"));
assert.isNull(detectCliRunner("/home/theo/.t3/runtime/0.0.31/node_modules/t3/dist/bin.mjs"));
assert.isNull(detectCliRunner(""));
for (const entryPath of [
"/usr/local/lib/node_modules/t3/dist/bin.mjs",
"/home/theo/Code/work/t3code/apps/server/dist/bin.mjs",
"/home/theo/.t3/runtime/0.0.31/node_modules/t3/dist/bin.mjs",
"",
]) {
assert.equal(
formatCliCommand({ subcommand: "serve", entryPath, version: "0.0.31" }),
"t3 serve",
);
}
});
it("re-suggests the nightly channel only for nightly builds", () => {
assert.equal(suggestedPackageSpec("0.0.31-nightly.20260729"), "t3@nightly");
assert.equal(suggestedPackageSpec("0.0.31"), "t3");
for (const [version, expected] of [
["0.0.31-nightly.20260729", "npx t3@nightly serve"],
["0.0.31", "npx t3 serve"],
] as const) {
assert.equal(
formatCliCommand({
subcommand: "serve",
entryPath: "/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs",
version,
}),
expected,
);
}
});
it("formats serve suggestions to match the launching command", () => {
+2 -2
View File
@@ -18,7 +18,7 @@ export type CliRunner = "npx" | "pnpm dlx" | "bunx";
* Global installs and repo checkouts match none of these and return null.
* Detection is best-effort; callers must fail closed to a plain `t3` command.
*/
export function detectCliRunner(entryPath: string): CliRunner | null {
function detectCliRunner(entryPath: string): CliRunner | null {
const path = entryPath.replaceAll("\\", "/");
if (path.includes("/_npx/")) {
return "npx";
@@ -42,7 +42,7 @@ export function detectCliRunner(entryPath: string): CliRunner | null {
* from the running version: nightly builds re-suggest the nightly channel,
* anything else suggests the bare package.
*/
export function suggestedPackageSpec(version: string): string {
function suggestedPackageSpec(version: string): string {
return version.includes("-nightly.") ? "t3@nightly" : "t3";
}