mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paperclip Runner needs repeatable evaluation contracts. > - Evaluation code must stay separate from provider launch and production orchestration. > - Offline fixtures need stable compatibility, scoring, traceability, and report rules. > - Published Runner consumers need only the supported evaluation contract surface. > - This pull request adds offline evaluation tooling and a workspace-private matrix kernel. > - The benefit is deterministic evaluation without credentials or paid provider calls. ## Linked Issues or Issue Description Refs #11297 This pull request extracts the offline evaluation unit from the earlier aggregate Runner work. ## What Changed - Add a workspace-private, provider-neutral evaluation matrix kernel. - Add the public `@paperclipai/paperclip-runner/evals` compatibility and native execution contracts. - Add fail-closed runnerd artifact and protocol compatibility checks. - Add deterministic workflow catalogs, scoring, traceability, and report generation. - Add sanitized Codex, OpenCode, and ACPX fixtures. - Add package-boundary and clean-consumer checks. - Add the eval package manifest to the Docker dependency stage. - Add the generated protocol fixture digest without changing the lockfile. ## Verification GitHub Actions must run: - Runner TypeScript and Rust type checks. - Runner unit and protocol tests. - Evaluation kernel tests. - Workflow traceability checks. - Clean-consumer and package-boundary checks. - Repository test, type-check, build, policy, and security gates. No local test command was run. The repository owner requested GitHub-only verification. ## Risks This is a large greenfield review surface with 51 files. The code does not launch a live provider or load credentials. Package and protocol drift fail closed. The workspace lockfile remains under the existing CI-owned process. ## Model Used OpenAI Codex with the GPT-5 agent model. The work used high reasoning, repository inspection, tool use, and parallel code review. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
160 lines
6.4 KiB
TypeScript
160 lines
6.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
assertBundleSecretFree,
|
|
bundleEvidenceDeclaration,
|
|
bundleId,
|
|
describeBundle,
|
|
EvalBundleSecretError,
|
|
type EvalBundle,
|
|
} from "./eval-bundle.js";
|
|
|
|
function bundle(overrides: Partial<EvalBundle> = {}): EvalBundle {
|
|
return {
|
|
schema: "paperclip.runner.eval-bundle.v1",
|
|
provider: { runtime: "runnerd", transport: "codex-app-server", protocolVersion: "prp.v1" },
|
|
model: { id: "gpt-5-codex", reasoningEffort: "medium" },
|
|
launchContext: { workingDirectoryClass: "ephemeral-fixture", scenarioId: "capability-eval-st-1", turnTimeoutMs: 60_000 },
|
|
promptPolicy: { id: "exact-single-call", callTemplate: "Call {op} exactly once.", restraintTemplate: "Do not call any tools." },
|
|
grants: ["discovery:tasks:read"],
|
|
runner: { package: "@paperclipai/paperclip-runner", binary: "paperclip-runnerd", version: "0.0.0" },
|
|
controlPlaneAdapter: { kind: "mock", contract: "paperclip.capability.control-plane.v1" },
|
|
faultInjection: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("bundleId", () => {
|
|
it("is stable and independent of field ordering", () => {
|
|
const a = bundle();
|
|
const b: EvalBundle = {
|
|
// Same content, different key insertion order.
|
|
faultInjection: [],
|
|
controlPlaneAdapter: { contract: "paperclip.capability.control-plane.v1", kind: "mock" },
|
|
runner: { version: "0.0.0", binary: "paperclip-runnerd", package: "@paperclipai/paperclip-runner" },
|
|
grants: ["discovery:tasks:read"],
|
|
promptPolicy: { restraintTemplate: "Do not call any tools.", callTemplate: "Call {op} exactly once.", id: "exact-single-call" },
|
|
model: { reasoningEffort: "medium", id: "gpt-5-codex" },
|
|
launchContext: { turnTimeoutMs: 60_000, scenarioId: "capability-eval-st-1", workingDirectoryClass: "ephemeral-fixture" },
|
|
provider: { protocolVersion: "prp.v1", transport: "codex-app-server", runtime: "runnerd" },
|
|
schema: "paperclip.runner.eval-bundle.v1",
|
|
};
|
|
expect(bundleId(a)).toBe(bundleId(b));
|
|
expect(bundleId(a)).toMatch(/^evb-[0-9a-f]{16}$/);
|
|
});
|
|
|
|
it("changes when any declared input changes", () => {
|
|
expect(bundleId(bundle())).not.toBe(bundleId(bundle({ model: { id: "gpt-5" } })));
|
|
expect(bundleId(bundle())).not.toBe(bundleId(bundle({ grants: ["discovery:agents:read"] })));
|
|
expect(bundleId(bundle())).not.toBe(
|
|
bundleId(bundle({ faultInjection: [{ id: "f1", class: "authorization", description: "deny grant" }] })),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("assertBundleSecretFree", () => {
|
|
it("accepts a clean, typed bundle", () => {
|
|
expect(() => assertBundleSecretFree(bundle())).not.toThrow();
|
|
expect(() =>
|
|
assertBundleSecretFree(
|
|
bundle({ faultInjection: [{ id: "f1", class: "provider_capability", description: "drop steering support" }] }),
|
|
),
|
|
).not.toThrow();
|
|
});
|
|
|
|
it("rejects an untyped grant", () => {
|
|
const rejected = "not-a-grant-with-private-material";
|
|
let error: unknown;
|
|
try {
|
|
assertBundleSecretFree(bundle({ grants: [rejected] }));
|
|
} catch (caught) {
|
|
error = caught;
|
|
}
|
|
expect(error).toBeInstanceOf(EvalBundleSecretError);
|
|
expect((error as Error).message).not.toContain(rejected);
|
|
});
|
|
|
|
it("scans a secret-shaped invalid grant before structural validation without echoing it", () => {
|
|
const rejected = ["xox", "b-1234567890-abcdefghijklmnop"].join("");
|
|
let error: unknown;
|
|
try {
|
|
assertBundleSecretFree(bundle({ grants: [rejected] }));
|
|
} catch (caught) {
|
|
error = caught;
|
|
}
|
|
expect(error).toMatchObject({ path: "bundle.grants[0]" });
|
|
expect((error as Error).message).toContain("slack-token");
|
|
expect((error as Error).message).not.toContain(rejected);
|
|
});
|
|
|
|
it("rejects a secret-shaped value smuggled into a template", () => {
|
|
const leaked = bundle({
|
|
promptPolicy: {
|
|
id: "leaky",
|
|
callTemplate: "Use key sk-ABCDEF0123456789ABCDEF to call {op}.",
|
|
restraintTemplate: "none",
|
|
},
|
|
});
|
|
expect(() => assertBundleSecretFree(leaked)).toThrow(/provider-key/);
|
|
});
|
|
|
|
it("rejects a bearer token and a forbidden key", () => {
|
|
const withToken = bundle({
|
|
launchContext: {
|
|
workingDirectoryClass: "clean-room",
|
|
scenarioId: "Authorization: Bearer abcdef0123456789abcdef",
|
|
turnTimeoutMs: 1000,
|
|
},
|
|
});
|
|
expect(() => assertBundleSecretFree(withToken)).toThrow(EvalBundleSecretError);
|
|
|
|
const withForbiddenKey = { ...bundle(), apiKey: "value" } as unknown as EvalBundle;
|
|
expect(() => assertBundleSecretFree(withForbiddenKey)).toThrow(
|
|
/forbidden credential field/,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("describeBundle", () => {
|
|
it("produces a redacted one-line summary carrying the bundle id", () => {
|
|
const described = describeBundle(bundle());
|
|
expect(described.bundleId).toBe(bundleId(bundle()));
|
|
expect(described.summary).toContain(described.bundleId);
|
|
expect(described.summary).toContain("1 grants");
|
|
expect(described.summary).toContain("0 faults");
|
|
expect(described.summary).not.toContain("codex-app-server");
|
|
expect(described.summary).not.toContain("gpt-5-codex");
|
|
expect(described.summary).not.toContain("sk-");
|
|
});
|
|
|
|
it("counts faults without persisting their free-form declaration", () => {
|
|
const described = describeBundle(
|
|
bundle({ faultInjection: [{ id: "f1", class: "conflict", description: "stale write" }] }),
|
|
);
|
|
expect(described.summary).toContain("1 faults");
|
|
expect(described.summary).not.toContain("stale write");
|
|
});
|
|
});
|
|
|
|
describe("bundleEvidenceDeclaration", () => {
|
|
it("persists explicit digests instead of free-form bundle content", () => {
|
|
const candidate = bundle({
|
|
promptPolicy: {
|
|
id: "custom-policy",
|
|
callTemplate: "Unique free-form call instructions.",
|
|
restraintTemplate: "Unique free-form restraint instructions.",
|
|
},
|
|
faultInjection: [{ id: "fault-a", class: "retry", description: "Unique fault detail." }],
|
|
});
|
|
const declaration = bundleEvidenceDeclaration(candidate);
|
|
const serialized = JSON.stringify(declaration);
|
|
|
|
expect(declaration.contentSha256).toMatch(/^sha256:[0-9a-f]{64}$/);
|
|
expect(declaration.promptPolicy.callTemplateSha256).toMatch(/^sha256:[0-9a-f]{64}$/);
|
|
expect(declaration.faultInjection).toMatchObject({ count: 1 });
|
|
expect(serialized).not.toContain("Unique free-form call instructions.");
|
|
expect(serialized).not.toContain("Unique free-form restraint instructions.");
|
|
expect(serialized).not.toContain("Unique fault detail.");
|
|
});
|
|
});
|