mirror of
https://github.com/JuliusBrussee/caveman.git
synced 2026-09-14 18:02:35 +08:00
82864c8f4c
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
71 lines
2.6 KiB
JavaScript
71 lines
2.6 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { spawn } from "node:child_process";
|
|
import { chmodSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const packageRoot = resolve(fileURLToPath(new URL("..", import.meta.url)));
|
|
const delegate = join(packageRoot, "dist", "caveman-delegate-mcp.mjs");
|
|
|
|
test("delegate tolerates invalid timeout and removes session data", async () => {
|
|
const root = mkdtempSync(join(tmpdir(), "cave-delegate-runtime-"));
|
|
const worker = join(root, "fake-pi.mjs");
|
|
writeFileSync(worker, `#!/usr/bin/env node
|
|
import { writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
const at = process.argv.indexOf("--session-dir");
|
|
const sessionDir = process.argv[at + 1];
|
|
writeFileSync(join(sessionDir, "usage.jsonl"), JSON.stringify({ usage: { input: 2, output: 3, cacheRead: 0, cacheWrite: 0, cost: { total: 0 } } }) + "\\n");
|
|
setTimeout(() => { process.stdout.write("worker ok\\n"); }, 50);
|
|
`, { mode: 0o700 });
|
|
chmodSync(worker, 0o700);
|
|
|
|
const server = spawn(process.execPath, [delegate], {
|
|
env: {
|
|
...process.env,
|
|
TMPDIR: root,
|
|
CAVE_DELEGATE_PI_BIN: worker,
|
|
CAVE_DELEGATE_TIMEOUT_MS: "not-a-number",
|
|
},
|
|
stdio: ["pipe", "pipe", "pipe"],
|
|
});
|
|
let stderr = "";
|
|
server.stderr.on("data", (chunk) => { stderr += chunk; });
|
|
|
|
try {
|
|
const response = new Promise((resolveResponse, reject) => {
|
|
let buffer = "";
|
|
server.stdout.on("data", (chunk) => {
|
|
buffer += chunk;
|
|
const newline = buffer.indexOf("\n");
|
|
if (newline === -1) return;
|
|
try { resolveResponse(JSON.parse(buffer.slice(0, newline))); }
|
|
catch (error) { reject(error); }
|
|
});
|
|
server.once("error", reject);
|
|
server.once("exit", (code) => reject(new Error(`delegate exited ${code}: ${stderr}`)));
|
|
});
|
|
server.stdin.write(JSON.stringify({
|
|
jsonrpc: "2.0",
|
|
id: 1,
|
|
method: "tools/call",
|
|
params: { name: "caveman_delegate", arguments: { task: "probe" } },
|
|
}) + "\n");
|
|
|
|
const message = await response;
|
|
assert.equal(message.error, undefined, JSON.stringify(message.error));
|
|
assert.match(message.result.content[0].text, /worker ok/);
|
|
assert.match(message.result.content[0].text, /input 2/);
|
|
assert.deepEqual(
|
|
readdirSync(root).filter((name) => name.startsWith("cave-delegate-")),
|
|
[],
|
|
"delegate session directory survived worker completion",
|
|
);
|
|
} finally {
|
|
server.kill("SIGTERM");
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|