Files
pi/packages/coding-agent/test/experimental-cli-entry.test.ts
T
Armin Ronacher ca7460d16b feat: build with TypeScript 7 and run sources with plain node
Replace the tsgo native preview with typescript@7.0.2 and port the check scripts to the TS 7 API. Target ES2024, drop useDefineForClassFields: false and unused decorator options, and enable verbatimModuleSyntax. Replace tsx with node plus the source resolver hook, passed to --import as a file URL.

closes #9965
2026-09-25 13:14:33 +02:00

68 lines
2.1 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { afterEach, describe, expect, it } from "vitest";
import { VERSION } from "../src/config.ts";
// --import takes a module specifier, not a filesystem path.
const sourceResolverUrl = pathToFileURL(resolve(__dirname, "../src/experimental/source-resolver.ts")).href;
const tempDirs: string[] = [];
afterEach(() => {
for (const directory of tempDirs.splice(0)) rmSync(directory, { recursive: true, force: true });
});
function runEntry(entry: string, experimental: boolean) {
const directory = mkdtempSync(join(tmpdir(), "pi-cli-boundary-"));
tempDirs.push(directory);
return spawnSync(
process.execPath,
[
"--import",
sourceResolverUrl,
resolve(__dirname, "../src", entry),
"server",
"--server-id",
"invalid",
"--version",
],
{
cwd: directory,
encoding: "utf8",
timeout: 15_000,
env: {
...process.env,
HOME: directory,
USERPROFILE: directory,
PI_CODING_AGENT_DIR: join(directory, "agent"),
PI_OFFLINE: "1",
PI_EXPERIMENTAL: experimental ? "1" : "0",
},
},
);
}
describe("stable and development CLI entrypoints", () => {
// #9132: enabling experiments must not pull remote-server dependencies into the published CLI.
it("does not dispatch experimental commands from the stable entrypoint", () => {
const result = runEntry("cli.ts", true);
expect(result.status, result.stderr).toBe(0);
expect(result.stdout.trim()).toBe(VERSION);
});
it("keeps experimental dispatch in the development entrypoint", () => {
const result = runEntry("experimental/cli.ts", true);
expect(result.status, result.stderr).toBe(1);
expect(result.stderr).toContain("Invalid --server-id");
expect(result.stdout).not.toContain(VERSION);
});
it("falls back to the stable CLI when experiments are disabled", () => {
const result = runEntry("experimental/cli.ts", false);
expect(result.status, result.stderr).toBe(0);
expect(result.stdout.trim()).toBe(VERSION);
});
});