| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import assert from "node:assert/strict";
- import { spawnSync } from "node:child_process";
- import { readFile } from "node:fs/promises";
- import test from "node:test";
- interface PackageContract {
- version?: string;
- private?: boolean;
- bin?: Record<string, string>;
- files?: string[];
- scripts?: Record<string, string>;
- }
- test("npm package contract exposes the prebuilt private CLI", async () => {
- const [packageText, launcher, compiledCli, compiledConfig] = await Promise.all([
- readFile(new URL("../package.json", import.meta.url), "utf8"),
- readFile(new URL("../bin/codex-app-server-bridge.js", import.meta.url), "utf8"),
- readFile(new URL("../dist/cli.js", import.meta.url), "utf8"),
- readFile(new URL("../dist/config.js", import.meta.url), "utf8"),
- ]);
- const packageJson = JSON.parse(packageText) as PackageContract;
- assert.equal(packageJson.private, true);
- assert.equal(packageJson.version, "0.1.1");
- assert.deepEqual(packageJson.bin, {
- "codex-app-server-bridge": "bin/codex-app-server-bridge.js",
- });
- assert.deepEqual(packageJson.files, [
- "bin/",
- "dist/cli.js",
- "dist/config.js",
- "README.md",
- "LICENSE",
- ]);
- assert.equal(packageJson.scripts?.compile, "tsc --project tsconfig.build.json");
- assert.equal(packageJson.scripts?.build, undefined);
- for (const lifecycle of ["prepack", "prepare", "preinstall", "install", "postinstall"]) {
- assert.equal(packageJson.scripts?.[lifecycle], undefined);
- }
- assert.match(packageJson.scripts?.test ?? "", /npm run compile/);
- assert.equal(
- packageJson.scripts?.["verify:runtime"],
- "node scripts/verify-generated-runtime.mjs",
- );
- assert.equal(
- packageJson.scripts?.["verify:git-package"],
- "node scripts/verify-git-package.mjs",
- );
- assert.match(packageJson.scripts?.["pack:verified"] ?? "", /npm run verify:runtime/);
- assert.match(packageJson.scripts?.["pack:verified"] ?? "", /npm pack --ignore-scripts/);
- assert.match(launcher, /^#!\/usr\/bin\/env node\n/);
- assert.match(compiledCli, /export async function runBridge/);
- assert.match(compiledConfig, /export function parseEndpoint/);
- });
- test("Git ignore rules admit only the compiled bridge runtime", () => {
- const repository = new URL("..", import.meta.url);
- const checkIgnored = (path: string) => spawnSync(
- "git",
- ["check-ignore", "--no-index", "--quiet", path],
- { cwd: repository, encoding: "utf8" },
- ).status;
- assert.equal(checkIgnored("dist/cli.js"), 1);
- assert.equal(checkIgnored("dist/config.js"), 1);
- assert.equal(checkIgnored("dist/test/bridge.test.js"), 0);
- assert.equal(checkIgnored("dist/other-output.js"), 0);
- });
- test("packed-artifact verifier rejects a missing tarball argument", () => {
- const verifier = new URL("../scripts/verify-packed-package.mjs", import.meta.url);
- const result = spawnSync(process.execPath, [verifier.pathname], { encoding: "utf8" });
- assert.notEqual(result.status, 0);
- assert.match(result.stderr, /Packed-package verification failed: usage:/);
- });
|