Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/internal-task-attachment.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

125 lines
11 KiB
TypeScript

import { createHash } from "node:crypto";
import { expect } from "@playwright/test";
import type { ChatCatalogCase, ChatCatalogContext } from "../chat-catalog-contract.js";
import type { ChatQueryAttachmentReceipt } from "../chat-query-attachments.js";
import { pollUntil } from "../api.js";
import { openStandingChat } from "./identity-support.js";
import { fixtureWorker, makeDefinition } from "./internal-definition.js";
import { checks, entity, hasLink, observation, observeInternal, type Entity, type InternalObservation } from "./internal-support.js";
interface BriefObservation extends InternalObservation {
sourceId?: string; originalBytesHash: string; sourceAttachments: ChatQueryAttachmentReceipt[];
workAttachments: ChatQueryAttachmentReceipt[]; workDocuments: Entity[];
workerTaskStatus?: number; workerDownloadStatus?: number; workerDownloadedHash?: string; durablePath?: string;
workDescription?: string | null; workerReadInlineBrief?: boolean;
}
const hash = (bytes: Uint8Array) => createHash("sha256").update(bytes).digest("hex");
// Exact brief text, tolerant only of line endings, indentation, trailing spaces, blank lines and Markdown quote markers.
const briefLines = (text: string) => text.replace(/\r\n?/g, "\n").split("\n").map(line => line.trim().replace(/^(?:>\s?)+/, "").trim()).filter(Boolean);
export function containsExactBrief(context: string | null | undefined, brief: unknown): boolean {
if (typeof brief !== "string" || typeof context !== "string") return false;
const want = briefLines(brief); const have = briefLines(context);
return want.length > 0 && have.some((_, start) => want.every((line, offset) => have[start + offset] === line));
}
const workerProbeKeys = new WeakMap<ChatCatalogContext, { id: string; token: string; workerId: string }>();
export function gradeAttachmentBrief(value: unknown) {
const c = checks(); const o = observation(value) as BriefObservation | undefined;
c.add("independent-upload-and-worker-evidence", !!o && Array.isArray(o.sourceAttachments) && Array.isArray(o.workAttachments) && Array.isArray(o.workDocuments),
"The original UI upload, actual work context and independently authenticated worker download are required.");
if (!o || !Array.isArray(o.sourceAttachments) || !Array.isArray(o.workAttachments) || !Array.isArray(o.workDocuments)) return c.result();
const receipt = o.state.briefAttachment as ChatQueryAttachmentReceipt | undefined;
const worker = entity(o.state, "worker"); const work = o.tasks.filter(row => row.id !== o.sourceId); const saved = work[0];
c.add("actual-human-upload-retained", !!receipt && receipt.companyId === o.companyId && o.sourceAttachments.some(row => row.id === receipt.id && row.issueId === o.sourceId && row.companyId === o.companyId
&& row.createdByUserId === receipt.createdByUserId && row.createdByAgentId == null && row.issueCommentId && row.sha256 === o.state.briefHash)
&& o.originalBytesHash === o.state.briefHash, "The original signed-in person's uploaded brief and its exact bytes remain attached to the actual source human comment.");
c.add("one-contextual-ordinary-work-task", work.length === 1 && !!saved && saved.companyId === o.companyId && saved.assigneeAgentId === worker.id
&& o.activity.some(row => row.action === "issue.created" && row.entityId === saved.id && row.agentId === o.leadId)
&& hasLink(o, "issues", saved), "One actual CEO-created website task is delegated to the intended Morgan and linked in chat.");
const context = `${o.workDescription ?? saved?.description ?? ""}\n${o.workDocuments.map(row => row.body ?? "").join("\n")}`;
const copied = o.workAttachments.some(row => row.issueId === saved?.id && row.companyId === o.companyId && row.sha256 === o.state.briefHash
&& o.durablePath === row.contentPath);
const originalReference = !!receipt && context.includes(receipt.contentPath) && o.durablePath === receipt.contentPath;
const inline = containsExactBrief(context, o.state.briefBody);
c.add("durable-brief-in-work-context", copied || originalReference || inline,
"The delegated task owns an exact-byte copy, a durable actual attachment reference, or the complete exact brief text; an unavailable filename, a paraphrase or a source-chat-only attachment fails.");
const downloaded = o.workerDownloadStatus === 200 && o.workerDownloadedHash === o.state.briefHash;
c.add("morgan-can-read-the-real-brief", o.workerTaskStatus === 200 && (downloaded || (inline && o.workerReadInlineBrief === true)),
"An independent real Morgan bearer reads the work task and either downloads the actual referenced brief bytes or reads the complete exact brief in its own task context.");
const runs = saved ? o.runs.filter(row => row.contextSnapshot?.issueId === saved.id || row.contextSnapshot?.taskId === saved.id) : [];
c.add("separate-real-worker-admission", runs.length === 1 && runs[0]?.agentId === worker.id && ["queued", "running", "succeeded"].includes(runs[0]?.status ?? ""),
"Morgan's real admitted run belongs to the new work task, separate from the source conversation.");
return c.result();
}
async function workerReads(ctx: ChatCatalogContext, workerId: string, taskId: string, path: string | undefined, brief: string) {
const key = workerProbeKeys.get(ctx);
if (!key || key.workerId !== workerId) throw new Error("Attempt-private Morgan probe credential is unavailable");
const get = (value: string) => {
const url = new URL(value, ctx.input.api.baseURL);
if (url.origin !== ctx.input.api.baseURL || !/^\/api\/(?:issues|attachments)\//.test(url.pathname)) throw new Error("Worker brief read escaped isolated resources");
return fetch(url, { redirect: "error", signal: AbortSignal.timeout(15_000), headers: { Authorization: `Bearer ${key.token}` } });
};
const taskRead = await get(`/api/issues/${taskId}`); const workerTaskStatus = taskRead.status;
if (!path) {
if (!taskRead.ok) { await taskRead.body?.cancel(); return { workerTaskStatus }; }
const parts = [((await taskRead.json()) as Entity).description ?? ""];
const list = await get(`/api/issues/${taskId}/documents`);
if (list.ok) for (const summary of (await list.json()) as Entity[]) {
const doc = await get(`/api/issues/${taskId}/documents/${encodeURIComponent(summary.key!)}`);
if (doc.ok) parts.push(((await doc.json()) as Entity).body ?? ""); else await doc.body?.cancel();
} else await list.body?.cancel();
return { workerTaskStatus, workerReadInlineBrief: containsExactBrief(parts.join("\n"), brief) };
}
await taskRead.body?.cancel();
const response = await get(path); const workerDownloadStatus = response.status;
if (!response.ok) { await response.body?.cancel(); return { workerTaskStatus, workerDownloadStatus }; }
const bytes = new Uint8Array(await response.arrayBuffer());
if (bytes.byteLength > 65_536) throw new Error("Delegated brief unexpectedly exceeds its fixture size bound");
return { workerTaskStatus, workerDownloadStatus, workerDownloadedHash: hash(bytes) };
}
const base = makeDefinition("tasks.attachment-brief", async ctx => {
const worker = await fixtureWorker(ctx); const source = await openStandingChat(ctx);
const briefBody = `# Acorn Field Notes\nBuild a simple accessible website for small research teams.\nUse headline: Research without the busywork.\nOffer early signup with invitation code ORCHID-${ctx.input.nonce}.\n`;
const filename = "website-brief.md";
await ctx.input.page.locator('input[type="file"]').first().setInputFiles({ name: filename, mimeType: "text/markdown", buffer: Buffer.from(briefBody) });
const uploaded = await pollUntil({ label: "Actual human chat brief upload", deadlineAt: Date.now() + 30_000,
load: () => ctx.input.api.get<ChatQueryAttachmentReceipt[]>(`/api/issues/${source.id}/attachments`),
accept: rows => rows.filter(row => row.originalFilename === filename).length === 1 });
const receipt = uploaded.find(row => row.originalFilename === filename)!;
await expect(ctx.input.page.getByTestId("task-chat-composer-attachments")).toContainText(filename);
await expect(ctx.input.page.getByTestId("task-chat-composer-attachments")).not.toContainText("Uploading");
if (!ctx.input.privateSecrets) throw new Error("Worker brief probe requires private secret redaction");
const key = await ctx.input.api.postSensitive<{ id: string; token: string }>(`/api/agents/${worker.id}/keys`, { name: "delegated-brief-read-control" });
ctx.input.privateSecrets.push(key.token); workerProbeKeys.set(ctx, { ...key, workerId: worker.id });
return { worker, sourceId: source.id, briefAttachment: receipt, briefBody, briefHash: hash(Buffer.from(briefBody)), workerProbeKeyId: key.id };
}, gradeAttachmentBrief);
export const taskAttachmentCases: readonly ChatCatalogCase[] = [{ ...base, authentication: "human-session", oracleVersion: "paperclip.chat-catalog.attachment-brief.v2",
queryAttachments: [{ stateKey: "briefAttachment", filename: "website-brief.md" }], expectedRunCount: 3, minimumRunCount: 2,
runPolicy: { kind: "source-settled-with-active-work", maximumActiveWorkerRuns: 1 },
sourceFiles: [...base.sourceFiles, "chat-catalog-domains/internal-task-attachment.ts", "chat-catalog-domains/identity-support.ts", "chat-query-attachments.ts"],
async observe(ctx, state): Promise<BriefObservation> {
const o = await observeInternal(ctx, state); const source = ctx.issue();
const sourceAttachments = source ? await ctx.input.api.get<ChatQueryAttachmentReceipt[]>(`/api/issues/${source.id}/attachments`) : [];
const receipt = state.briefAttachment as ChatQueryAttachmentReceipt;
const originalBytesHash = hash(await ctx.input.api.getAttachmentContent(receipt.id));
const saved = o.tasks.filter(row => row.id !== source?.id)[0]; const workAttachments: ChatQueryAttachmentReceipt[] = []; const workDocuments: Entity[] = [];
let workDescription: string | null | undefined;
if (saved) {
// Company issue listings shorten descriptions; read the saved task in full.
workDescription = (await ctx.input.api.get<Entity>(`/api/issues/${saved.id}`)).description;
workAttachments.push(...await ctx.input.api.get<ChatQueryAttachmentReceipt[]>(`/api/issues/${saved.id}/attachments`));
for (const summary of await ctx.input.api.get<Entity[]>(`/api/issues/${saved.id}/documents`))
workDocuments.push(await ctx.input.api.get<Entity>(`/api/issues/${saved.id}/documents/${encodeURIComponent(summary.key!)}`));
}
const context = `${workDescription ?? ""}\n${workDocuments.map(row => row.body ?? "").join("\n")}`;
const durablePath = workAttachments.find(row => row.sha256 === state.briefHash)?.contentPath
?? (context.includes(receipt.contentPath) ? receipt.contentPath : undefined);
const reads = saved ? await workerReads(ctx, entity(state, "worker").id, saved.id, durablePath, String(state.briefBody ?? "")) : {};
return { ...o, sourceId: source?.id, sourceAttachments, originalBytesHash, workAttachments, workDocuments, workDescription, durablePath, ...reads };
},
async cleanup(ctx, state) {
const key = workerProbeKeys.get(ctx); workerProbeKeys.delete(ctx);
const id = key?.id ?? state.workerProbeKeyId;
if (id) await ctx.input.api.delete(`/api/agents/${entity(state, "worker").id}/keys/${id}`, { allowNotFound: true });
},
}];