Files
juliusbrussee__caveman/packages/cli/tests/caveman-bin-resolution.runtime.mjs
Julius Brussee 82864c8f4c feat: ship Caveman 2.0.0 — engine, proxy, SDKs, unified CLI
Single-commit port of the Caveman 2 tree onto the original repo history
(candidate caveman-2@88878a4 applied over main@3098342). No unrelated-history
merge; original history untouched.

Preserved v1 surfaces:
- skills/caveman/SKILL.md byte-for-byte, plus plugin mirror and caveman.skill zip
- legacy CI (Node 18/20/22 installer + Python 3.11 suites) alongside engine-ci
- cli/install.js compatibility shim forwarding to bin/install.js
- .codex/config.toml ships both hooks and codex_hooks for older Codex (#617)
- README Trendshift + Skills.sh badges and local star-history asset
- v1.10.0-pinned curl installs; benchmarks/tmp-starcharts ignore rules

Fixed for public same-repo release:
- SECURITY.md vulnerability reporting points at this repository
- release-binaries.yml publishes to this repo via job-scoped GITHUB_TOKEN
  (cross-repo PAT removed); binary-release environment still gates signing
- packages/cli/PUBLISHING.md rewritten for packages/ layout and same-repo flow
- profile-contract and provider-catalog lanes skip lane-scope gates on
  initial import so the launch PR can gate on their real validation steps
- ANNOUNCEMENT.md network claim corrected: compression is local; requests
  still go to the provider you configured

Caveman 2 stays opt-in: bin-v1.0.0 binaries and @caveman-ai/cli publish
separately after this lands and soaks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLvb5QniwYjmcawyssQNw9
2026-08-11 16:46:10 +02:00

55 lines
2.6 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert";
import { spawn } from "node:child_process";
import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const cli = join(dirname(fileURLToPath(import.meta.url)), "..", "dist", "index.js");
// The missing-binary panels tell users to build into ~/.caveman/bin — so the CLI
// must actually find binaries there without a PATH edit. `caveman stats` shells to
// caveman-proxy; a stub in $CAVEMAN_HOME/bin (NOT on PATH) must be what runs.
test("caveman binaries resolve from ~/.caveman/bin without a PATH entry", async () => {
const home = mkdtempSync(join(tmpdir(), "cave-binres-"));
const binDir = join(home, "bin");
mkdirSync(binDir, { recursive: true });
writeFileSync(join(binDir, "caveman-proxy"), `#!/bin/sh\nif [ "$1" = "stats" ]; then printf '{"resolved_from":"caveman-home-bin"}'; fi\n`, { mode: 0o755 });
const env = { ...process.env, NO_COLOR: "1", CAVEMAN_HOME: home };
delete env.CAVEMAN_PROXY_BIN;
const out = await new Promise((resolve, reject) => {
const child = spawn("node", [cli, "stats"], { env });
let stdout = "";
let stderr = "";
child.stdout.on("data", (d) => (stdout += d));
child.stderr.on("data", (d) => (stderr += d));
child.on("exit", (code) => resolve({ code, stdout, stderr }));
child.on("error", reject);
});
assert.equal(out.code, 0, `stats exited ${out.code}: ${out.stderr}`);
assert.match(out.stdout, /caveman-home-bin/, "stats must run the ~/.caveman/bin binary");
});
// The explicit env override must still win over ~/.caveman/bin.
test("CAVEMAN_PROXY_BIN overrides the ~/.caveman/bin fallback", async () => {
const home = mkdtempSync(join(tmpdir(), "cave-binres2-"));
const binDir = join(home, "bin");
mkdirSync(binDir, { recursive: true });
writeFileSync(join(binDir, "caveman-proxy"), `#!/bin/sh\nprintf 'WRONG'\n`, { mode: 0o755 });
const override = join(home, "override-proxy");
writeFileSync(override, `#!/bin/sh\nif [ "$1" = "stats" ]; then printf '{"resolved_from":"env-override"}'; fi\n`, { mode: 0o755 });
const env = { ...process.env, NO_COLOR: "1", CAVEMAN_HOME: home, CAVEMAN_PROXY_BIN: override };
const out = await new Promise((resolve, reject) => {
const child = spawn("node", [cli, "stats"], { env });
let stdout = "";
child.stdout.on("data", (d) => (stdout += d));
child.on("exit", (code) => resolve({ code, stdout }));
child.on("error", reject);
});
assert.equal(out.code, 0);
assert.match(out.stdout, /env-override/, "the env override must win");
});