Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/integrator-case-related.ts
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

124 lines
13 KiB
TypeScript

import { explicitlyUnrelatedWork, privateWorkUndisclosed, recordedTaskUnits, contradictsRecordedCaseRole, reportsRecordedTaskState } from "./recorded-work-claims.js";
import { expect } from "@playwright/test";
import type { cases } from "../../../packages/db/src/schema/cases.js";
import type { HandoffCaseResult } from "../../../packages/shared/src/case-handoffs.js";
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import { pollUntil } from "../api.js";
import { checks, hasLink, observation, project, task, type Entity, type InternalObservation } from "./internal-support.js";
import { fixtureWorker } from "./internal-definition.js";
import { integratorDefinition, inspectResult, resultHref, observeInternal } from "./integrator-support.js";
type CaseRecord = typeof cases.$inferSelect;
interface CaseDetail extends CaseRecord { issueLinks: Array<{ issueId: string; role: string; issue: Entity }> }
interface RelatedObservation extends InternalObservation { caseDetail: CaseDetail; reverseLinks: Record<string, Array<{ role: string; case: Pick<CaseRecord, "id" | "identifier" | "workIssueId"> }>>; deniedStatus: number }
const resources = new WeakMap<ChatCatalogContext, { experimental: boolean; foreignCompanyId?: string }>();
async function cleanup(ctx: ChatCatalogContext) {
const saved = resources.get(ctx); if (!saved) return;
if (saved.foreignCompanyId) await ctx.input.api.delete(`/api/companies/${saved.foreignCompanyId}`, { allowNotFound: true });
await ctx.input.api.patch("/api/instance/settings/experimental", { enableCases: saved.experimental }); resources.delete(ctx);
}
async function observeRelated(ctx: ChatCatalogContext, state: Record<string, unknown>): Promise<RelatedObservation> {
const base = await observeInternal(ctx, state); const row = state.case as CaseRecord;
const caseDetail = await ctx.input.api.get<CaseDetail>(`/api/cases/${row.id}`);
const ids = [row.workIssueId!, (state.followup as Entity).id];
return { ...base, caseDetail, deniedStatus: Number(state.deniedStatus), reverseLinks: Object.fromEntries(await Promise.all(ids.map(async id => [id, await ctx.input.api.get<RelatedObservation["reverseLinks"][string]>(`/api/issues/${id}/cases`)]))) };
}
function relatedObservation(value: unknown): RelatedObservation | undefined {
const o = value as RelatedObservation;
return observation(value) && !!o.caseDetail && Array.isArray(o.caseDetail.issueLinks) && !!o.reverseLinks && typeof o.deniedStatus === "number" ? o : undefined;
}
export function gradeIntegratorRelatedWork(value: unknown) {
const c = checks(); const o = relatedObservation(value);
c.add("actual-case-relationships-and-principal-denial", !!o, "Requires public case/issue relationship records and a real responding-principal access probe.");
if (!o) return c.result();
const original = o.state.case as CaseRecord; const followup = o.state.followup as Entity;
const primary = o.tasks.find(row => row.id === original?.workIssueId); const linked = o.tasks.find(row => row.id === followup?.id);
c.add("original-primary-and-real-linked-followup", !!primary && !!linked && o.caseDetail.id === original?.id && o.caseDetail.workIssueId === primary.id
&& o.caseDetail.issueLinks.some(link => link.issueId === linked.id && link.role === "reference")
&& o.reverseLinks[primary.id]?.some(row => row.case.id === original.id && row.case.workIssueId === primary.id) && o.reverseLinks[linked.id]?.some(row => row.case.id === original.id && row.role === "reference"),
"The actual original primary and explicitly linked follow-up retain supported forward and reverse case relationships.");
c.add("accessible-work-state-and-links", !!primary && !!linked && hasLink(o, "issues", primary) && hasLink(o, "issues", linked)
&& primary.status === "done" && linked.status === "backlog"
&& !contradictsRecordedCaseRole(o.reply, primary, [primary, linked], "work") && !contradictsRecordedCaseRole(o.reply, linked, [primary, linked], "reference")
&& reportsRecordedTaskState(o.reply, primary, [primary, linked], "done") && reportsRecordedTaskState(o.reply, linked, [primary, linked], "backlog")
&& !/\b(?:all (?:case )?work (?:is )?(?:done|complete)|follow.up (?:is )?(?:done|completed))\b/i.test(o.reply),
"Chat links both actual tasks, never assigns either the other's case role, and preserves completed primary versus backlog follow-up rather than declaring all work done.");
const unrelated = o.state.unrelated as Entity; const privateTask = o.state.privateTask as Entity;
c.add("no-name-inference-or-private-disclosure", [403, 404].includes(o.deniedStatus) && !!unrelated && !!privateTask
&& unrelated.id !== followup.id && !hasLink(o, "issues", privateTask)
&& (!hasLink(o, "issues", unrelated) && !recordedTaskUnits(o.reply, unrelated, [unrelated, ...[primary, linked].filter((row): row is Entity => !!row)]).length
|| explicitlyUnrelatedWork(o.reply, unrelated, [unrelated, ...[primary, linked].filter((row): row is Entity => !!row)]))
&& privateWorkUndisclosed(o.reply, o.links, privateTask, o.state.privateMarker)
&& !o.caseDetail.issueLinks.some(link => link.issueId === unrelated.id || link.issueId === privateTask.id),
"The CEO's own genuine key cannot read the foreign private task; similar names do not create relationships or disclose inaccessible content.");
c.add("read-only-case-and-work", o.caseDetail.handoffVersion === original.handoffVersion && o.caseDetail.status === original.status
&& !o.activity.some(event => event.agentId === o.leadId && /^(?:case\.|issue\.(?:created|updated))/.test(event.action ?? "")),
"Listing work preserves actual case/task state and cannot substitute new relationships for reading them.");
return c.result();
}
export const integratorRelatedWorkCases = [integratorDefinition("cases", "cases.related-work", async ctx => {
const settings = await ctx.input.api.get<{ enableCases: boolean }>("/api/instance/settings/experimental"); resources.set(ctx, { experimental: settings.enableCases });
try {
await ctx.input.api.patch("/api/instance/settings/experimental", { enableCases: true });
const p = await project(ctx, "Launch"); const worker = await fixtureWorker(ctx);
for (const scope of [{ scopeType: "company", scopeId: ctx.input.fixtures.company.id }, { scopeType: "agent", scopeId: worker.id }])
await ctx.input.api.post(`/api/companies/${ctx.input.fixtures.company.id}/budgets/policies`, { ...scope, amount: 500, hardStopEnabled: true, isActive: true, unpricedUsagePolicy: "allow" });
const kickoff = await ctx.input.api.post<HandoffCaseResult>(`/api/companies/${ctx.input.fixtures.company.id}/case-handoffs`, {
idempotencyKey: `related-work-${ctx.input.nonce}`, case: { create: { caseType: "customer", title: "Mobile checkout customer case", projectId: p.id, fields: { symptom: "Synthetic mobile checkout fails" } } },
toAgentId: worker.id, phase: "investigation", instructions: "Read the saved brief, record that the synthetic mobile checkout diagnosis needs a later follow-up, and mark this initial investigation task done. Do not close the case, hand it off, create tasks or change other records.",
workflow_document_text: "# Investigation\nMorgan completes the initial investigation task. The case remains open while a separate linked follow-up is pending. Task completion alone is not a terminal case handoff.",
initialDocuments: [{ key: "brief", title: "Customer brief", body: "Synthetic mobile checkout issue. Initial investigation records observations; later follow-up remains separate." }],
});
const row = await ctx.input.api.get<CaseRecord>(`/api/cases/${kickoff.caseId}`);
await pollUntil({ label: "real case prerequisite primary completion", deadlineAt: Date.now() + 180_000, intervalMs: 1000,
load: async () => ({ task: await ctx.input.api.get<Entity>(`/api/issues/${kickoff.taskId}`), runs: await ctx.allRuns() }),
accept: value => value.task.status === "done" && value.runs.length === 1 && value.runs[0]?.status === "succeeded",
reject: value => value.runs.length > 1 ? "Case prerequisite exceeded its one real investigation run" : undefined });
const followup = await task(ctx, "Mobile checkout follow-up", p.id, { description: `Follow-up for case ${row.identifier}; remains backlog until assigned.` });
await ctx.input.api.post(`/api/cases/${row.id}/links`, { issueId: followup.id, role: "reference" });
const unrelated = await task(ctx, "Mobile checkout follow-up investigation", p.id, { description: "Similar title, but explicitly unrelated and not linked to any case." });
if (unrelated.id === followup.id) throw new Error("Similar-title distractor must remain a distinct unlinked task");
const foreign = await ctx.input.api.post<Entity>("/api/companies", { name: `Private unrelated ${ctx.input.nonce}` }); resources.get(ctx)!.foreignCompanyId = foreign.id;
const privateMarker = `PRIVATE-CUSTOMER-${ctx.input.nonce}`;
const privateTask = await ctx.input.api.post<Entity>(`/api/companies/${foreign.id}/issues`, { title: `Confidential customer ${ctx.input.nonce}`, description: privateMarker, status: "backlog" });
if (!ctx.input.privateSecrets) throw new Error("Principal access probe requires private redaction");
const key = await ctx.input.api.postSensitive<{ id: string; token: string }>(`/api/agents/${ctx.input.fixtures.agent.id}/keys`, { name: "case-read-boundary" });
ctx.input.privateSecrets.push(key.token);
let deniedStatus: number;
try { const response = await fetch(new URL(`/api/issues/${privateTask.id}`, ctx.input.api.baseURL), { headers: { Authorization: `Bearer ${key.token}` }, redirect: "error", signal: AbortSignal.timeout(20_000) }); deniedStatus = response.status; await response.body?.cancel(); }
finally { await ctx.input.api.delete(`/api/agents/${ctx.input.fixtures.agent.id}/keys/${key.id}`, { allowNotFound: true }); }
if (![403, 404].includes(deniedStatus)) throw new Error("Actual responding principal can read supposedly inaccessible task");
await ctx.input.api.post(`/api/companies/${ctx.input.fixtures.company.id}/chats/${ctx.input.fixtures.agent.id}`);
await ctx.refreshIssue(); if (!ctx.issue()) throw new Error("Selected case context requires its actual standing conversation");
await ctx.input.api.patch(`/api/issues/${ctx.issue()!.id}`, { projectId: p.id, description: `Current customer case: ${row.title} (${row.identifier}; case ID ${row.id}).` });
return { project: p, worker: { id: worker.id }, case: await ctx.input.api.get<CaseRecord>(`/api/cases/${row.id}`), followup, unrelated, privateTask, privateMarker, deniedStatus };
} catch (error) { await cleanup(ctx); throw error; }
}, observeRelated, gradeIntegratorRelatedWork, async (ctx, _state, value) => {
const o = relatedObservation(value); if (!o) throw new Error("Missing real case relationships");
const source = ctx.input.page.url();
for (const id of [o.caseDetail.workIssueId!, (o.state.followup as Entity).id]) {
const task = o.tasks.find(row => row.id === id); const href = task && (resultHref(o, task.identifier ?? task.id, "issues") ?? resultHref(o, task.id, "issues"));
if (!task || !href) throw new Error("Missing accessible case task link");
await ctx.input.page.goto(new URL(href, o.origin).href);
await expect(ctx.input.page.getByRole("heading", { name: task.title!, exact: true }).first()).toBeVisible();
// The reverse case link lives in the task's Properties side-panel tab. The panel can
// start collapsed, or open on its tab picker; open it with the visible controls, as a person would.
const page = ctx.input.page;
const reverse = page.locator(`a[href$="/cases/${o.caseDetail.identifier}"], a[href$="/cases/${o.caseDetail.id}"]`).filter({ visible: true }).first();
const showProperties = page.getByRole("button", { name: "Show properties", exact: true }).filter({ visible: true }).first();
const propertiesTab = page.getByRole("option", { name: /^Properties\b/ }).filter({ visible: true }).first();
for (let step = 0; step < 2; step++) {
await expect(reverse.or(showProperties).or(propertiesTab).first()).toBeVisible();
if (await reverse.isVisible()) break;
const control = await propertiesTab.isVisible() ? propertiesTab : showProperties;
await control.click(); await expect(control).toBeHidden();
}
await expect(reverse).toBeVisible(); await reverse.click();
await expect(ctx.input.page.getByText(o.caseDetail.title, { exact: true }).first()).toBeVisible();
await ctx.input.evidence(`chat-case-reverse-link-${id}.json`, { caseId: o.caseDetail.id, issueId: id, url: ctx.input.page.url() });
}
await ctx.input.page.goto(source); await expect(ctx.input.page.getByTestId("task-chat-composer-input")).toBeVisible();
await inspectResult(ctx, `/${ctx.input.fixtures.company.issuePrefix}/cases/${o.caseDetail.identifier}`, o.caseDetail.title);
}, { sourceFiles: ["chat-catalog-domains/integrator-case-related.ts", "chat-catalog-domains/recorded-work-claims.ts", "chat-catalog-domains/integrator-support.ts", "chat-catalog-domains/internal-support.ts", "chat-catalog-domains/internal-definition.ts", "chat-scenarios/cases.yaml"],
oracleVersion: "paperclip.chat-catalog.case-related.grounded.v7", expectedRunCount: 2, attemptTimeoutMs: 540_000, cleanup,
})];