Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-claude-validation.ts
T
f4337bb5fb test(evals): land the chat catalog eval harness on master (#19614)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The chat-feature evals measure whether agents complete real chat
requests through the product
> - The chat catalog eval harness and its repairs live on the
`chat-eval/master-candidate` branch, not on master
> - Today's work made 139 of 242 chat evals pass in verified single-case
live runs. Each product fix landed on master as its own pull request
> - The eval-side changes (setups, graders, fault seams, evidence
capture) still exist only on the candidate
> - This pull request lands the harness on master. Master stays the
source of truth for product behavior
> - The benefit is one tree: evals run against master commits, and
product fixes reach the evals as soon as they merge

## Linked Issues or Issue Description

Refs #19441, Refs #19599, Refs #20270, Refs #20334, Refs #20342, Refs
#20344, Refs #20354, Refs #20360, Refs #20373, Refs #20382, Refs #20409

**What existing behavior does this improve?**
The chat catalog eval harness and the product it evaluates live on a
long-running branch outside master. Eval fixes do not reach master, so
master-based eval runs use old setups and graders.

**Subsystem affected**
`tests/runner-e2e` chat catalog harness, plus a small set of product
changes that exist only on the candidate.

**Proposed change**
Land the harness on master. Every product fix from this eval work
already merged to master as its own pull request. Conflicts keep
master's product behavior.

## What Changed

- Most of the diff (808 of 851 files) is under `tests/runner-e2e/`:
chat-catalog domains, scenarios, descriptors, the TestOps manifest,
private evidence tooling, and their tests.
- Graders now check saved state, setup literals and rendered or clicked
links. Many keyword and regex checks on free-form replies are removed.
Each changed grader has a bumped `oracleVersion` and calibration tests
(a valid reply, a reworded valid reply, and broken variants that must
fail).
- The shared link helper `hasLink` no longer treats a list link (for
example `/COM/issues?view=mine`) as a link to every task without a URL
key.
- Setup fixes build real state through supported product routes: routine
history, agent grants through the board grant route, budget holds with a
real cap, and a storage-layer archive fault for
`inbox-search.archive-partial-failure`.
- Browser boundary journeys (sign-in, chat-disabled, onboarding) now
write the standard pass evidence files.
- Retargeted cases, approved by the maintainer:
`agent-chat.chat-disabled` (Conference Room gate),
`agents.restore-instructions` (no saved instruction history),
`access.manage-membership` (member permission edits stay board-only).
- The private evidence trusted files (`manual-private-handoff.ts`,
`manual-private-retention.ts`, `manual-private-report-assets.ts`) are
byte-identical to master.
- Product files outside `tests/` (43 files, +1,328 −49) carry
candidate-only changes that master does not yet have. Most are tests.
The main code changes are in `request-human-input.ts`,
`heartbeat-run-summary.ts`, `native-completion-feedback.ts`,
`native-run-finalizer.ts`, `openapi.ts`, `secrets.ts` and
`IssueChatLongThreadPerf.tsx`.

## Verification

- `pnpm vitest run chat-catalog-domains chat-catalog-contract.test.ts
chat-catalog-consistency.test.ts unit-launcher.test.mjs
--testTimeout=180000` in `tests/runner-e2e`: 269 files pass, 3,550 tests
pass.
- `node --test chat-full-catalog-testops-manifest.test.mjs`: 10 pass.
- `node tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check`:
no change.
- `tsc` for `server` and `tests/runner-e2e`: clean.
- Live single-case verification: 139 of 242 cases passed on paid runs,
and a person read the saved evidence for each. These are single-case
runs, not one full-cohort run.

## Risks

- Large diff. Most of it is test-only, but the 43 non-test files change
product code paths. Review those files first.
- Some graders are now less strict on reply wording. A person must read
replies for meaning on those cases.
- 42 cases need disposable outside accounts (Notion, Slack, GitHub,
Daytona and others) and stay blocked. `access.invite-teammate` stays
failing until local agent isolation lands, because the runner's durable
state keeps a live invite token.
- The paid workflow compares the trusted private-evidence files with
master. They are unchanged, so this risk is low.

## Model Used

Anthropic Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code
execution, in Claude Code. Subagents used the same model.

## 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
- [x] 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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-10 08:02:11 -06:00

94 lines
14 KiB
TypeScript

import { createHash } from "node:crypto";
import { isDeepStrictEqual } from "node:util";
import type { Agent } from "../../../packages/shared/src/types/agent.js";
import type { Environment } from "../../../packages/shared/src/types/environment.js";
import type { AiConnectionList } from "../../../packages/shared/src/ai-connections.js";
import { waitForReply } from "./identity-support.js";
import { checks } from "./internal-support.js";
import { collectRunEvents } from "../run-observations.js";
import { runtimeDefinition, runtimeObservation, observeRuntime } from "./runtime-support.js";
import { selectedRuntimeInputs, runtimePrivateSpec } from "./runtime-private.js";
import { privateClaudeOperation, matchesClaudeFixtureTarget } from "./runtime-claude-private.js";
const record = (value: unknown): Record<string, unknown> => value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
const operation = "POST /api/companies/{companyId}/adapters/{type}/test-environment";
export function actualAuthenticationFailure(codes: readonly string[]) { return codes.some(code => /(?:auth_required|auth_missing|authentication_failed|login_required|credentials_invalid|invalid_credentials)/i.test(code)); }
/** Correlated trusted native API execution, not an assistant-authored JSON claim. */
export function savedValidationReceipts(events: Array<{ seq?: number; eventType?: string; payload?: unknown }>, expected: { companyId: string; worker: Pick<Agent, "id" | "adapterType" | "adapterConfig" | "defaultEnvironmentId" | "runtimeConfig"> }) {
const inputs = new Map<string, Record<string, unknown>>(), results = new Map<string, Record<string, unknown>>(), completed = new Set<string>();
for (const event of events) {
const payload = record(record(record(event.payload).prpEvent).payload), item = record(payload.item);
if (event.eventType === "item.started" && item.type === "tool_use" && item.name === "call_api" && typeof item.id === "string") inputs.set(item.id, record(item.input));
if (event.eventType === "item.completed" && item.type === "tool_result" && typeof item.id === "string" && (!item.tool_use_id || item.tool_use_id === item.id)) results.set(item.id, record(item.result));
if (event.eventType === "tool.execution.completed" && payload.name === "call_api" && payload.status === "completed" && typeof payload.executionId === "string") completed.add(payload.executionId);
}
return [...inputs].flatMap(([id, input]) => {
if (input.operationId !== operation) return [];
const result = results.get(id), body = record(input.body), path = record(input.pathParams), data = record(result?.data), codes = Array.isArray(data.checks) ? data.checks.map(row => record(row).code).filter((value): value is string => typeof value === "string") : [];
return [{ executionId: id, sameConfiguration: path.companyId === expected.companyId && path.type === expected.worker.adapterType && body.agentId === expected.worker.id
&& (body.environmentId === undefined || body.environmentId === expected.worker.defaultEnvironmentId)
&& isDeepStrictEqual(body.adapterConfig, expected.worker.adapterConfig) && isDeepStrictEqual(body.aiConnection, expected.worker.runtimeConfig.aiConnection),
authenticatedFailure: completed.has(id) && result?.ok === true && result.status === 200 && result.apiOperationId === operation && actualAuthenticationFailure(codes), checkCodes: codes }];
});
}
export function validationFailureReplyMatches(reply: string) {
return /authenticat|login|sign.?in|credential|account access/i.test(reply) && /fail|could not|couldn't|unable|not (?:yet )?(?:ready|working)|blocked|needs|requires/i.test(reply)
&& /reconnect|sign.?in|reauthori[sz]|repair|refresh.*(?:account|credential)|check.*(?:account|credential)|human|operator|settings/i.test(reply)
&& !/(?:Morgan|profile|agent)\s+(?:is\s+)?(?:now\s+|fully\s+)?ready\b(?!\s+(?:once|when|after|pending|only|subject)\b)|validation (?:passed|succeeded)|(?:switched|replaced).*(?:account|harness)/i.test(reply);
}
export function gradeClaudeValidation(value: unknown) {
const c = checks(), o = runtimeObservation(value); c.add("actual-authentication-failure-context", !!o, "A genuinely eligible account and independently observed saved-target authentication failure are required."); if (!o) return c.result();
const s = o.state, worker = s.worker as Agent, saved = o.agents.find(row => row.id === worker?.id), receipts = s.canonicalValidationReceipts as ReturnType<typeof savedValidationReceipts> | undefined;
c.add("genuine-target-auth-failure-not-simulated", s.actualAccountEligible === true && s.actualSavedAuthenticationFailure === true && Array.isArray(receipts) && receipts.length === 1 && receipts[0]!.sameConfiguration && receipts[0]!.authenticatedFailure,
"The actual canonical run completes exactly one allowed saved-configuration API validation and receives real authentication failure; an initially passing target is an unavailable context, never a manufactured provider response.");
c.add("specific-failure-and-repair-no-false-ready", validationFailureReplyMatches(o.reply), "Chat identifies authentication failure with an actionable human repair path and distinguishes the saved profile from working execution.");
c.add("no-account-harness-target-substitution-or-paid-work", !!saved && saved.adapterType === worker.adapterType && JSON.stringify(saved.adapterConfig) === JSON.stringify(worker.adapterConfig)
&& JSON.stringify(saved.runtimeConfig?.aiConnection) === JSON.stringify(worker.runtimeConfig.aiConnection) && saved.defaultEnvironmentId === worker.defaultEnvironmentId && s.sameAccountSet === true
&& o.tasks.length === 0 && o.runs.length === 1 && o.runs[0]?.agentId === o.leadId && o.runs[0].status === "succeeded" && o.humanQueries.length === 1,
"Validation neither switches identity/account/computer nor repeatedly admits employee work or extra human directions.");
return c.result();
}
export const runtimeClaudeValidationCases = [runtimeDefinition("runs-adapters.validate-hire", async ctx => {
const selected = selectedRuntimeInputs(ctx, "runs-adapters.validate-hire"), companyId = ctx.input.fixtures.company.id, environmentId = ctx.input.fixtures.environment.id;
if (selected.values.targetRef !== "fixture.environment" || selected.values.accountBindingRef !== "selected.ANTHROPIC_API_KEY" || !ctx.input.privateSecrets) throw new Error("Setup blocker: require the actual owned selected Claude target/account and private sink");
const [company, detail, listed] = await Promise.all([ctx.input.api.get<{ id: string }>(`/api/companies/${companyId}`), ctx.input.api.get<Environment>(`/api/environments/${environmentId}`), ctx.input.api.get<Environment[]>(`/api/companies/${companyId}/environments`)]);
if (!matchesClaudeFixtureTarget({ company, expectedCompanyId: companyId, fixtureEnvironmentId: environmentId, detail, listed })) throw new Error("Selected validation target is not the owned active fixture");
const credential = selected.credentials.ANTHROPIC_API_KEY!; ctx.input.privateSecrets.push(credential);
const account = await privateClaudeOperation({ operation: "prepare-account", companyId, environmentId, credential, harnessExecutable: selected.values.harnessExecutable, model: selected.values.model, baseURL: ctx.input.api.baseURL, cookies: await ctx.input.page.context().cookies(ctx.input.api.baseURL) });
const accounts = await ctx.input.api.get<AiConnectionList>(`/api/companies/${companyId}/ai-connections`), connection = accounts.connections.find(row => row.id === account.connectionId && row.grantId === account.grantId);
if (!connection || connection.status !== "connected" || connection.provider !== "anthropic") throw new Error("Actual saved Anthropic account must be eligible before target failure qualification");
const worker = await ctx.input.api.post<Agent>(`/api/companies/${companyId}/agents`, { name: "Morgan", role: "engineer", title: "Frontend engineer", reportsTo: ctx.input.fixtures.agent.id, adapterType: "claude_local", runner: "legacy", adapterConfig: { command: selected.values.harnessExecutable, model: selected.values.model }, defaultEnvironmentId: environmentId,
runtimeConfig: { heartbeat: { enabled: false, maxConcurrentRuns: 1 }, aiConnection: { provider: "anthropic", method: "api_key", mode: "delegated", connectionId: account.connectionId, grantId: account.grantId } } });
const saved = await ctx.input.api.get<Agent>(`/api/agents/${worker.id}`), failure = await privateClaudeOperation({ operation: "validate-saved", companyId, environmentId, agentId: worker.id, connectionId: account.connectionId!, grantId: account.grantId!, baseURL: ctx.input.api.baseURL, cookies: await ctx.input.page.context().cookies(ctx.input.api.baseURL) }, credential);
if (!actualAuthenticationFailure(failure.probeCheckCodes)) throw new Error("Context prerequisite unavailable: this actual eligible-account saved target did not return a genuine authentication failure. A qualified stale/expired target session is required; no provider response or credential failure was manufactured.");
return { worker: saved, actualAccountEligible: true, actualSavedAuthenticationFailure: true, qualificationReceipt: failure, accountIdentities: accounts.connections.map(row => ({ id: row.id, grantId: row.grantId, provider: row.provider, status: row.status })),
providerProbes: [{ phase: "setup-account", operation: account.operation, publicProbeCount: 2, status: account.probeStatus, usage: "unavailable", cost: "unavailable" }, { phase: "saved-auth-failure-prerequisite", operation: failure.operation, publicProbeCount: 1, status: failure.probeStatus, checkCodes: failure.probeCheckCodes, usage: "unavailable", cost: "unavailable" }] };
}, gradeClaudeValidation, {
...runtimePrivateSpec("runs-adapters.validate-hire"), authentication: "human-session", expectedRunCount: 1, attemptTimeoutMs: 600000,
setupPolicy: { readiness: "preserve-scenario", invariantCheckIds: ["saved-eligible-account-with-genuine-auth-failure"] },
async verifySetup(ctx, s) {
const worker = s.worker as Agent, actual = await ctx.input.api.get<Agent>(`/api/agents/${worker.id}`), accounts = await ctx.input.api.get<AiConnectionList>(`/api/companies/${ctx.input.fixtures.company.id}/ai-connections`);
const lead = await ctx.input.api.get<Agent>(`/api/agents/${ctx.input.fixtures.agent.id}`);
const receipt = s.qualificationReceipt as { agentId?: string; environmentId?: string; probeCheckCodes?: string[] }, binding = actual.runtimeConfig.aiConnection;
const c = checks(); c.add("saved-eligible-account-with-genuine-auth-failure", lead.lifecycleState === "ready" && actual.companyId === ctx.input.fixtures.company.id && isDeepStrictEqual(actual.adapterConfig, worker.adapterConfig) && isDeepStrictEqual(actual.runtimeConfig.aiConnection, worker.runtimeConfig.aiConnection)
&& receipt.agentId === actual.id && receipt.environmentId === actual.defaultEnvironmentId && actualAuthenticationFailure(receipt.probeCheckCodes ?? []) && binding?.mode === "delegated" && accounts.connections.some(row => row.id === binding.connectionId && row.grantId === binding.grantId && row.status === "connected" && row.provider === "anthropic"),
"The independently fetched exact saved configuration/account matches the actual isolated target authentication-failure receipt; no artificial ready employee status is needed."); return c.result();
},
sourceFiles: ["chat-catalog-domains/runtime-claude-validation.ts", "chat-catalog-domains/runtime-claude-private.ts", "chat-catalog-domains/runtime-claude-private-worker.ts", "chat-catalog-domains/runtime-private.ts", "chat-catalog-domains/runtime-support.ts", "run-observations.ts", "../../server/src/routes/agents.ts", "../../server/src/services/ai-connection-runtime.ts", "chat-scenarios/runs-adapters.yaml"],
async act(ctx, state) {
await waitForReply(ctx); const runs = await ctx.allRuns(), worker = state.worker as Agent;
const events = await collectRunEvents<{ seq?: number; eventType?: string; payload?: unknown }>((afterSeq, limit) => ctx.input.api.get(`/api/heartbeat-runs/${runs[0]!.id}/events?afterSeq=${afterSeq}&limit=${limit}`));
for (const event of events) {
const item = record(record(record(record(event.payload).prpEvent).payload).item), result = record(item.result), artifact = record(result.artifact);
if (event.eventType !== "item.completed" || item.type !== "tool_result" || result.apiOperationId !== operation || result.data !== undefined || typeof artifact.artifactId !== "string" || !/^[a-f0-9-]{36}$/i.test(artifact.artifactId)) continue;
const response = await ctx.input.api.request.get(`/api/assets/${artifact.artifactId}/content`);
if (!response.ok()) throw new Error("Actual validation response artifact could not be independently read");
const bytes = await response.body(); await response.dispose();
if (bytes.length > 1048576 || bytes.length !== artifact.byteSize || createHash("sha256").update(bytes).digest("hex") !== artifact.sha256) throw new Error("Validation response artifact bytes/hash disagree with the actual native tool receipt");
try { result.data = JSON.parse(bytes.toString("utf8")); } catch { throw new Error("Actual validation response artifact was not complete JSON"); }
}
const receipts = savedValidationReceipts(events, { companyId: ctx.input.fixtures.company.id, worker }); state.canonicalValidationReceipts = receipts;
(state.providerProbes as unknown[]).push({ phase: "canonical-native-validation", operation: "test-environment", publicProbeCount: receipts.length, status: receipts.length === 1 && receipts[0]?.authenticatedFailure ? "authentication-failure" : "unproven", usage: "unavailable", cost: "unavailable" });
},
async observe(ctx, state) { const o = await observeRuntime(ctx, state), accounts = await ctx.input.api.get<AiConnectionList>(`/api/companies/${o.companyId}/ai-connections`); state.sameAccountSet = JSON.stringify(accounts.connections.map(row => ({ id: row.id, grantId: row.grantId, provider: row.provider, status: row.status }))) === JSON.stringify(state.accountIdentities); return o; },
})];