Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions tests/benchmark-acquisition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, it } from "node:test";
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import {
parseAgenticBenchmarkAcquisitionRequest,
parseAgenticBenchmarkAcquisitionReplayResult,
parseAgenticBenchmarkAcquisitionRequest,
parseAgenticBenchmarkAcquisitionResult,
} from "../src/contracts/index.js";
import {
Expand All @@ -18,9 +17,8 @@ import {
sha256Canonical,
} from "../src/core/index.js";
import { acquireAgenticBenchmark, benchmarkCacheDirectoryKey } from "../src/engine/index.js";
import { runCli } from "../src/cli.js";
import { createTestForgeServer } from "../src/mcp/index.js";
import { TestForge } from "../src/sdk/index.js";
import { connectPublicMcp, runPublicCli } from "./support/public-surface.js";

const temporaryDirectories: string[] = [];

Expand Down Expand Up @@ -436,27 +434,23 @@ describe("benchmark acquisition", () => {
stderr += text;
},
};
assert.equal(await runCli(["benchmark-acquire", "-", "--json"], io), 4);
assert.equal(await runPublicCli(["benchmark-acquire", "-", "--json"], io), 4);
assert.match(stderr, /--allow-unsafe-execution/);
stdout = "";
stderr = "";
assert.equal(
await runCli(["benchmark-acquire", "-", "--allow-unsafe-execution", "--json"], io),
await runPublicCli(["benchmark-acquire", "-", "--allow-unsafe-execution", "--json"], io),
0,
stderr,
);
const cliResult = JSON.parse(stdout);
assert.equal(cliResult.status, "COMPLETE");
stdout = "";
stdin = JSON.stringify(cliResult);
assert.equal(await runCli(["benchmark-acquire-replay", "-", "--json"], io), 0);
assert.equal(await runPublicCli(["benchmark-acquire-replay", "-", "--json"], io), 0);
assert.equal(JSON.parse(stdout).valid, true);

const disabledServer = createTestForgeServer({ allowedRepositoryRoots: [root] });
const disabledPair = InMemoryTransport.createLinkedPair();
await disabledServer.connect(disabledPair[1]);
const disabledClient = new Client({ name: "test", version: "1.0.0" });
await disabledClient.connect(disabledPair[0]);
const disabledClient = await connectPublicMcp({ root });
assert.ok(
!(await disabledClient.listTools()).tools.some(
(tool) => tool.name === "testforge_benchmark_acquire",
Expand All @@ -468,23 +462,14 @@ describe("benchmark acquisition", () => {
});
assert.equal((replayed.structuredContent as Record<string, unknown>).valid, true);
await disabledClient.close();
await disabledServer.close();

const server = createTestForgeServer({
allowUnsafeExecution: true,
allowedRepositoryRoots: [root],
});
const pair = InMemoryTransport.createLinkedPair();
await server.connect(pair[1]);
const client = new Client({ name: "test", version: "1.0.0" });
await client.connect(pair[0]);
const client = await connectPublicMcp({ root, allowUnsafeExecution: true });
const acquired = await client.callTool({
name: "testforge_benchmark_acquire",
arguments: { request: request(root) },
});
assert.equal(acquired.isError, undefined);
assert.equal((acquired.structuredContent as Record<string, unknown>).status, "COMPLETE");
await client.close();
await server.close();
});
});
4 changes: 2 additions & 2 deletions tests/bun-designated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
classifyBunDesignatedRun,
designatedBunConfig,
} from "../integrations/bun/driver.mjs";
import { runCli } from "../src/cli.js";
import { parseEvidenceManifestV4 } from "../src/contracts/index.js";
import { replayEvidenceManifest } from "../src/core/index.js";
import { verifyCampaign } from "../src/engine/index.js";
Expand All @@ -25,6 +24,7 @@ import {
TEST_SOURCE,
writeTree,
} from "./support/designated-campaign.js";
import { runPublicCli } from "./support/public-surface.js";

const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const driver = path.join(repositoryRoot, "integrations", "bun", "driver.mjs");
Expand Down Expand Up @@ -667,7 +667,7 @@ describe("v4 designated campaigns", () => {
},
};
assert.equal(
await runCli(
await runPublicCli(
["verify", requestFile, "--allow-unsafe-execution", "--allow-windows-native-execution"],
io,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/bun-init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { it } from "node:test";
import { runCli, type CliIo } from "../src/cli.js";
import { initializeRepository } from "../src/engine/index.js";
import { type PublicCliIo as CliIo, runPublicCli } from "./support/public-surface.js";

it("initializes a Bun test repository with the official v2 adapter configuration", async () => {
const root = await mkdtemp(path.join(os.tmpdir(), "assertledger-bun-init-"));
Expand Down Expand Up @@ -101,7 +101,7 @@ it("accepts an explicit Bun framework in the static CLI doctor", async () => {
writeStderr: () => {},
};
assert.equal(
await runCli(["doctor", root, "--framework", "bun:test", "--json"], io),
await runPublicCli(["doctor", root, "--framework", "bun:test", "--json"], io),
0,
stdout,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/container-facades.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import os from "node:os";
import path from "node:path";
import { afterEach, describe, it } from "node:test";
import { fileURLToPath } from "node:url";
import { runCli } from "../src/cli.js";
import type {
EvidenceManifestContract,
EvidenceManifestV2Contract,
Expand All @@ -17,6 +16,7 @@ import {
type GitRegressionOptions,
type GitRegressionV2Options,
} from "../src/sdk/index.js";
import { runPublicCli } from "./support/public-surface.js";

const FAKE_RUNTIME = fileURLToPath(
new URL("./support/fake-container-runtime.mjs", import.meta.url),
Expand All @@ -43,7 +43,7 @@ async function temporaryDirectory(prefix: string): Promise<string> {
async function cli(argv: string[], cwd = process.cwd()) {
let stdout = "";
let stderr = "";
const code = await runCli(argv, {
const code = await runPublicCli(argv, {
cwd,
readStdin: async () => "",
writeStdout: (text) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/container-isolation-docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import os from "node:os";
import path from "node:path";
import { afterEach, describe, it } from "node:test";
import { fileURLToPath } from "node:url";
import { runCli } from "../src/cli.js";
import { parseEvidenceManifestV2, parseEvidenceManifestV4 } from "../src/contracts/index.js";
import { replayEvidenceManifest } from "../src/core/index.js";
import { runProcess, verifyCampaign } from "../src/engine/index.js";
Expand All @@ -15,6 +14,7 @@ import {
KEEPS_DOCS,
OVERRUNS_UNDER_FAULT,
} from "./support/designated-campaign.js";
import { runPublicCli } from "./support/public-surface.js";

// Hostile scenarios against a real Docker Engine. They need an operator-provided runtime argv and a
// locally present digest-pinned Node.js image, never pull, and fail instead of skipping when
Expand Down Expand Up @@ -355,7 +355,7 @@ describe("real container isolation", { skip, concurrency: false }, () => {
stderr += text;
},
};
const code = await runCli(
const code = await runPublicCli(
[
"check",
root,
Expand Down Expand Up @@ -386,7 +386,7 @@ describe("real container isolation", { skip, concurrency: false }, () => {
const manifest = parseEvidenceManifestV2(JSON.parse(await readFile(manifestPath, "utf8")));
assert.equal(manifest.decision.status, "VERIFIED");
assert.equal(manifest.evidenceContext.execution.backend.kind, "container");
assert.equal(await runCli(["replay", manifestPath], io), 0, stderr);
assert.equal(await runPublicCli(["replay", manifestPath], io), 0, stderr);
await assertCleanedUp(volumesBefore);
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/container-transport-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os from "node:os";
import path from "node:path";
import { it } from "node:test";
import { fileURLToPath } from "node:url";
import { runCli } from "../src/cli.js";
import { runPublicCli } from "./support/public-surface.js";

async function refusedWitness(transport: string, capable = false) {
const parent = await mkdtemp(path.join(os.tmpdir(), "assertledger-transport-"));
Expand Down Expand Up @@ -51,7 +51,7 @@ async function refusedWitness(transport: string, capable = false) {
import.meta.url,
),
);
const code = await runCli(
const code = await runPublicCli(
[
"import-witness",
"-",
Expand Down
13 changes: 3 additions & 10 deletions tests/corpus-allocation.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { describe, it } from "node:test";
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import {
agenticCorpusAllocationJsonSchema,
agenticCorpusAllocationReplayResultJsonSchema,
Expand All @@ -16,10 +15,9 @@ import {
createAgenticCorpusAllocation,
replayAgenticCorpusAllocation,
} from "../src/core/index.js";
import { runCli } from "../src/cli.js";
import { parseAgenticCorpusCase } from "../src/evaluation/agentic-corpus.js";
import { createTestForgeServer } from "../src/mcp/index.js";
import { TestForge } from "../src/sdk/index.js";
import { connectPublicMcp, runPublicCli } from "./support/public-surface.js";

const SEED_DIGEST = "sha256:0000000000000000000000000000000000000000000000000000000000000001";
const CASE_IDS = [
Expand Down Expand Up @@ -233,14 +231,10 @@ describe("Agentic Corpus Allocation v1", () => {
},
writeStderr() {},
};
assert.equal(await runCli(["corpus-allocate", "-", "--json"], cliIo), 0);
assert.equal(await runPublicCli(["corpus-allocate", "-", "--json"], cliIo), 0);
assert.deepEqual(JSON.parse(cliOutput.join("")), allocation);

const server = createTestForgeServer();
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
const client = new Client({ name: "corpus-allocation-test", version: "1.0.0" });
await server.connect(serverTransport);
await client.connect(clientTransport);
const client = await connectPublicMcp({ name: "corpus-allocation-test" });
const allocated = await client.callTool({
name: "testforge_corpus_allocate",
arguments: { request: request() },
Expand All @@ -252,6 +246,5 @@ describe("Agentic Corpus Allocation v1", () => {
});
assert.equal((replayed.structuredContent as { valid: boolean }).valid, true);
await client.close();
await server.close();
});
});
22 changes: 12 additions & 10 deletions tests/corpus-experiment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ import {
agenticCorpusProvenanceSigningBytes,
agenticCorpusTrustPolicyDigest,
} from "../src/evaluation/agentic-corpus.js";
import { createTestForgeServer } from "../src/mcp/index.js";
import { runCli } from "../src/cli.js";
import { TestForge } from "../src/sdk/index.js";
import { connectPublicMcp, listedInputSchemas, runPublicCli } from "./support/public-surface.js";

const SOURCE_IDENTITY_DIGEST = `sha256:${"c".repeat(64)}`;
const SOURCE_B_IDENTITY_DIGEST = `sha256:${"2".repeat(64)}`;
Expand Down Expand Up @@ -1041,7 +1040,7 @@ describe("externally anchored H3 experiment v1", () => {
await writeFile(path.join(root, `${name}.json`), JSON.stringify(document), "utf8");
}
const diagnostics: string[] = [];
const code = await runCli(
const code = await runPublicCli(
[
"corpus-experiment-replay",
"artifact.json",
Expand Down Expand Up @@ -1089,7 +1088,7 @@ describe("externally anchored H3 experiment v1", () => {
assert.equal(await run(fixture({ firstBaselineOutcome: "INFRA_ERROR" })), 3);
const value = fixture();
assert.equal(
await runCli(["corpus-experiment-replay", "-", "--json"], {
await runPublicCli(["corpus-experiment-replay", "-", "--json"], {
cwd: process.cwd(),
async readStdin() {
return JSON.stringify(value.artifact);
Expand All @@ -1102,11 +1101,14 @@ describe("externally anchored H3 experiment v1", () => {
});

it("does not expose H3 creation or replay as default MCP tools", async () => {
const server = createTestForgeServer();
const tools = (server as unknown as { _registeredTools: Record<string, unknown> })
._registeredTools;
assert.equal(Object.hasOwn(tools, "testforge_corpus_experiment"), false);
assert.equal(Object.hasOwn(tools, "testforge_corpus_experiment_replay"), false);
await server.close();
const client = await connectPublicMcp();
try {
const tools = await listedInputSchemas(client);
assert.ok(tools.has("testforge_corpus_allocate"));
assert.equal(tools.has("testforge_corpus_experiment"), false);
assert.equal(tools.has("testforge_corpus_experiment_replay"), false);
} finally {
await client.close();
}
});
});
26 changes: 14 additions & 12 deletions tests/developer-experience.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { runFixtureDemo } from "../src/engine/demo.js";
import { verifyCampaign as executeCampaign, initializeRepository } from "../src/engine/index.js";
import { type RepositorySetupResult, setupRepository } from "../src/engine/setup.js";
import { AssertLedger } from "../src/sdk/index.js";
import { runPublicCli } from "./support/public-surface.js";

const packageMetadata = JSON.parse(
await readFile(new URL("../package.json", import.meta.url), "utf8"),
Expand Down Expand Up @@ -904,9 +905,10 @@ describe("developer entry points", () => {
);
const capture = captureIo(root);

const exitCode = await runCli(["setup", root, "--client", "codex", "--dry-run"], capture.io, {
setupEntry: path.resolve("dist", "cli.js"),
});
const exitCode = await runPublicCli(
["setup", root, "--client", "codex", "--dry-run"],
capture.io,
);

assert.equal(exitCode, 4);
assert.equal(capture.stderr(), "");
Expand Down Expand Up @@ -971,7 +973,7 @@ describe("developer entry points", () => {

it("prints typed diagnostics for invalid plain setup arguments", async () => {
const capture = captureIo(process.cwd());
const exitCode = await runCli(
const exitCode = await runPublicCli(
["setup", ".", "--client", "codex", "--dry-run", "--write"],
capture.io,
);
Expand Down Expand Up @@ -1072,7 +1074,7 @@ describe("developer entry points", () => {

it("keeps invalid and unexpected demo JSON failures typed and opaque", async () => {
const invalidCapture = captureIo(process.cwd());
assert.equal(await runCli(["demo", "--json", "--unknown"], invalidCapture.io), 64);
assert.equal(await runPublicCli(["demo", "--json", "--unknown"], invalidCapture.io), 64);
assert.equal(invalidCapture.stderr(), "");
const invalid = JSON.parse(invalidCapture.stdout()) as {
status: string;
Expand Down Expand Up @@ -1273,7 +1275,7 @@ describe("developer entry points", () => {
const before = await readFile(path.join(root, "package.json"), "utf8");
const capture = captureIo(root);

assert.equal(await runCli(["doctor", ".", "--json"], capture.io), 0);
assert.equal(await runPublicCli(["doctor", ".", "--json"], capture.io), 0);
const result = parseRepositoryInitResult(JSON.parse(capture.stdout()));
assert.equal(result.status, "WOULD_CREATE");
assert.deepEqual(result.requiredOperatorInputs, ["worlds", "candidates"]);
Expand All @@ -1292,7 +1294,7 @@ describe("developer entry points", () => {
const root = await fixtureRepository();
const capture = captureIo(root);

assert.equal(await runCli(["doctor", "."], capture.io), 0);
assert.equal(await runPublicCli(["doctor", "."], capture.io), 0);
assert.match(capture.stdout(), /Status: WOULD_CREATE/u);
assert.match(capture.stdout(), /Required operator inputs: worlds, candidates/u);
assert.match(capture.stdout(), /UNSANDBOXED trusted-local/u);
Expand All @@ -1303,19 +1305,19 @@ describe("developer entry points", () => {
it("supports help and version aliases while preserving empty and unknown usage errors", async () => {
for (const argv of [["help"], ["--help"], ["-h"]]) {
const capture = captureIo(process.cwd());
assert.equal(await runCli(argv, capture.io), 0);
assert.equal(await runPublicCli(argv, capture.io), 0);
assert.match(capture.stdout(), /Usage: assertledger/u);
assert.equal(capture.stderr(), "");
}
for (const argv of [["version"], ["--version"], ["-v"]]) {
const capture = captureIo(process.cwd());
assert.equal(await runCli(argv, capture.io), 0);
assert.equal(await runPublicCli(argv, capture.io), 0);
assert.equal(capture.stdout(), `assertledger ${packageMetadata.version}\n`);
assert.equal(capture.stderr(), "");
}
for (const argv of [[], ["unknown"]]) {
const capture = captureIo(process.cwd());
assert.equal(await runCli(argv, capture.io), 64);
assert.equal(await runPublicCli(argv, capture.io), 64);
assert.equal(capture.stdout(), "");
assert.match(capture.stderr(), /Usage: assertledger/u);
}
Expand Down Expand Up @@ -1610,7 +1612,7 @@ describe("developer entry points", () => {
["disconnect", ".", "--client", "claude"],
]) {
const capture = captureIo(root);
assert.equal(await runCli(argv, capture.io), 64);
assert.equal(await runPublicCli(argv, capture.io), 64);
assert.match(capture.stderr(), /Usage: assertledger/u);
assert.equal(capture.stdout(), "");
}
Expand All @@ -1623,7 +1625,7 @@ describe("developer entry points", () => {
["mcp", "--root", "-x"],
]) {
const capture = captureIo(process.cwd());
assert.equal(await runCli(argv, capture.io), 64);
assert.equal(await runPublicCli(argv, capture.io), 64);
assert.equal(capture.stdout(), "");
assert.match(capture.stderr(), /Usage: assertledger/u);
}
Expand Down
Loading
Loading