Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-agent-keys.test.ts
T

43 lines
3.5 KiB
TypeScript

import { it, expect } from "vitest";
import { gradeAgentKey, containsPrivateCredential } from "./runtime-agent-keys.js";
function valid() {
const worker = { id: "morgan", companyId: "company", name: "Morgan", permissions: {}, adapterConfig: {} };
const key = { id: "key", name: "local integration", revokedAt: null as string | null };
return { scenarioId: "agents.agent-api-key", origin: "http://fixture.invalid", companyId: "company", leadId: "ceo",
state: { worker, agentCreateStatus: 403, keysBeforeHuman: 0, humanCreated: true, createdKey: key, createdKeyAgentId: "morgan", createdKeyCompanyId: "company",
privateBrowserProcessIsolated: true, privateBrowserTestRunnerAttached: false, privateBrowserApiStepRecorder: false, tokenShownOnce: true, tokenAbsentAfterReload: true, privateScanComplete: true, artifactScanComplete: true, runEvidenceScanComplete: true, tokenLeaked: false,
revokedCredentialStatus: 401, finalKeys: [{ ...key, revokedAt: "2026-10-26T00:00:00Z" }] },
agents: [structuredClone(worker)], tasks: [], links: [], reply: "Use Morgan's profile API key controls; the board can create the credential securely.",
activity: ["agent.key_created", "agent.key_revoked"].map(action => ({ id: action, action, entityId: "morgan", actorType: "user", details: { keyId: "key" } })),
runs: [], humanQueries: [] };
}
it("accepts secure one-time human creation and actual credential revocation", () => expect(gradeAgentKey(valid()).passed).toBe(true));
it("rejects a mere fresh context still attached to Test API-step recording", () => { const o = valid(); o.state.privateBrowserApiStepRecorder = true; expect(gradeAgentKey(o).passed).toBe(false); });
it("accepts natural secure human-key guidance", () => { const o = valid(); o.reply = "Open Morgan's profile API key controls and create the local integration credential in your board session. Keep the one-time value private."; expect(gradeAgentKey(o).passed).toBe(true); });
it("rejects missing human credential evidence", () => expect(gradeAgentKey(undefined).passed).toBe(false));
it("rejects a key that authenticates a different agent", () => {
const o = valid(); o.state.createdKeyAgentId = "other"; expect(gradeAgentKey(o).passed).toBe(false);
});
it("rejects revocation metadata while the credential still works", () => {
const o = valid(); o.state.revokedCredentialStatus = 200; expect(gradeAgentKey(o).passed).toBe(false);
});
it("rejects credentials copied into conversation artifacts", () => {
const o = valid(); o.state.tokenLeaked = true; expect(gradeAgentKey(o).passed).toBe(false);
});
it("rejects incomplete generated artifact scans", () => {
const o = valid(); o.state.artifactScanComplete = false; expect(gradeAgentKey(o).passed).toBe(false);
});
it("rejects incomplete run log or event scans", () => {
const o = valid(); o.state.runEvidenceScanComplete = false; expect(gradeAgentKey(o).passed).toBe(false);
});
it("privately detects a synthetic credential in generated artifact bytes", () => {
const synthetic = "pcp_obviously_synthetic_calibration_credential";
expect(containsPrivateCredential(["safe reply", { artifact: `prefix ${synthetic} suffix` }], synthetic)).toBe(true);
expect(containsPrivateCredential(["safe reply", { artifact: "no credential" }], synthetic)).toBe(false);
});
it("privately detects a base64 encoded synthetic credential in run evidence", () => {
const synthetic = "pcp_obviously_synthetic_calibration_credential";
expect(containsPrivateCredential([{ event: Buffer.from(synthetic).toString("base64") }], synthetic)).toBe(true);
});