package.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import assert from "node:assert/strict";
  2. import { spawnSync } from "node:child_process";
  3. import test from "node:test";
  4. import { readFile } from "node:fs/promises";
  5. interface PackageContract {
  6. private?: boolean;
  7. license?: string;
  8. bin?: Record<string, string>;
  9. files?: string[];
  10. scripts?: Record<string, string>;
  11. }
  12. test("npm package contract exposes only the compiled private CLI", async () => {
  13. const [packageText, sourceEntry, compiledEntry] = await Promise.all([
  14. readFile(new URL("../../package.json", import.meta.url), "utf8"),
  15. readFile(new URL("../../src/index.ts", import.meta.url), "utf8"),
  16. readFile(new URL("../src/index.js", import.meta.url), "utf8"),
  17. ]);
  18. const packageJson = JSON.parse(packageText) as PackageContract;
  19. assert.equal(packageJson.private, true);
  20. assert.equal(packageJson.license, "UNLICENSED");
  21. assert.deepEqual(packageJson.bin, { "codex-chief-of-staff": "dist/src/index.js" });
  22. assert.deepEqual(packageJson.files, ["dist/src", "README.md"]);
  23. assert.equal(packageJson.scripts?.prepack, "npm test");
  24. assert.match(sourceEntry, /^#!\/usr\/bin\/env node\n/);
  25. assert.match(compiledEntry, /^#!\/usr\/bin\/env node\n/);
  26. });
  27. test("packed-artifact verifier rejects a missing tarball argument", () => {
  28. const verifier = new URL("../../scripts/verify-packed-package.mjs", import.meta.url);
  29. const result = spawnSync(process.execPath, [verifier.pathname], { encoding: "utf8" });
  30. assert.notEqual(result.status, 0);
  31. assert.match(result.stderr, /Packed-package verification failed: usage:/);
  32. });