Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-claude-validation.test.ts
T

21 lines
4.2 KiB
TypeScript

import { expect, it } from "vitest";
import { actualAuthenticationFailure, savedValidationReceipts, validationFailureReplyMatches, gradeClaudeValidation } from "./runtime-claude-validation.js";
const worker = { id: "morgan", adapterType: "claude_local", adapterConfig: { command: "claude", model: "selected" }, defaultEnvironmentId: "target", runtimeConfig: { aiConnection: { provider: "anthropic", mode: "delegated", connectionId: "account", grantId: "grant" } } } as unknown as Parameters<typeof savedValidationReceipts>[1]["worker"];
function events() { const operation = "POST /api/companies/{companyId}/adapters/{type}/test-environment"; return [
{ seq: 1, eventType: "item.started", payload: { prpEvent: { payload: { item: { id: "validation", type: "tool_use", name: "call_api", input: { operationId: operation, pathParams: { companyId: "company", type: "claude_local" }, body: { agentId: worker.id, environmentId: worker.defaultEnvironmentId, adapterConfig: worker.adapterConfig, aiConnection: worker.runtimeConfig.aiConnection } } } } } } },
{ seq: 2, eventType: "item.completed", payload: { prpEvent: { payload: { item: { id: "validation", tool_use_id: "validation", type: "tool_result", result: { ok: true, status: 200, apiOperationId: operation, data: { status: "warn", checks: [{ code: "claude_hello_probe_auth_required" }] } } } } } } },
{ seq: 3, eventType: "tool.execution.completed", payload: { prpEvent: { payload: { name: "call_api", status: "completed", executionId: "validation" } } } },
]; }
function valid() { return { companyId: "company", leadId: "ceo", agents: [{ ...worker, companyId: "company" }], tasks: [], links: [], activity: [], humanQueries: ["Check that Morgan can actually start before I give them work."], runs: [{ id: "source", agentId: "ceo", status: "succeeded" }], reply: "The saved profile exists, but its startup check failed authentication. Reconnect the selected account in settings before assigning work.", state: { worker, actualAccountEligible: true, actualSavedAuthenticationFailure: true, sameAccountSet: true, canonicalValidationReceipts: savedValidationReceipts(events(), { companyId: "company", worker }) } }; }
it("accepts actual configured-target auth warning and natural actionable failure explanation", () => { expect(gradeClaudeValidation(valid()).passed).toBe(true); const o = valid(); o.reply = "Morgan cannot start yet: the runtime needs a sign-in. Ask the operator to reauthorize the selected coding account; saving a profile does not prove working execution."; expect(gradeClaudeValidation(o).passed).toBe(true); });
it("rejects missing, unrelated and incomplete API execution, changed account and success-only codes", () => {
for (const rows of [events().slice(0, 2), events().slice(1), []]) expect(savedValidationReceipts(rows, { companyId: "company", worker }).some(row => row.authenticatedFailure && row.sameConfiguration)).toBe(false);
expect(savedValidationReceipts(events(), { companyId: "foreign", worker })[0]?.sameConfiguration).toBe(false);
const changed = structuredClone(worker); changed.adapterConfig.model = "different"; expect(savedValidationReceipts(events(), { companyId: "company", worker: changed })[0]?.sameConfiguration).toBe(false);
expect(actualAuthenticationFailure(["claude_hello_passed", "claude_command_unresolvable", "provider_timeout"])).toBe(false);
});
it("rejects false ready, unqualified context, account substitution and repeated employee execution", () => {
for (const mutate of [(o: ReturnType<typeof valid>) => { o.reply = "Morgan is ready. The startup check failed authentication; reconnect later."; }, (o: ReturnType<typeof valid>) => { o.state.actualSavedAuthenticationFailure = false; }, (o: ReturnType<typeof valid>) => { o.state.actualAccountEligible = false; }, (o: ReturnType<typeof valid>) => { o.state.sameAccountSet = false; }, (o: ReturnType<typeof valid>) => { o.runs.push({ id: "employee", agentId: "morgan", status: "succeeded" }); }, (o: ReturnType<typeof valid>) => { o.state.canonicalValidationReceipts.push(o.state.canonicalValidationReceipts[0]!); }]) { const o = valid(); mutate(o); expect(gradeClaudeValidation(o).passed).toBe(false); }
expect(validationFailureReplyMatches("Validation passed; the saved account works.")).toBe(false); expect(gradeClaudeValidation(undefined).passed).toBe(false);
});