Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/privileged-provision.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

92 lines
9.7 KiB
TypeScript

import { createHash } from "node:crypto";
import { readFile, realpath, stat } from "node:fs/promises";
import path from "node:path";
import { expect } from "@playwright/test";
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import { pollUntil } from "../api.js";
import { extendedHarnessProfiles } from "../catalog.js";
import { sendChatMessage } from "../chat-flow.js";
import { checks, type Entity } from "./internal-support.js";
import type { RuntimeAgent } from "./runtime-support.js";
import { ownedInstalledTarget } from "./privileged-installed.js";
import { privilegedDefinition, privilegedObservation, settlePrivilegedChat, companionPhase } from "./privileged-support.js";
const targets = new WeakMap<ChatCatalogContext, Awaited<ReturnType<typeof ownedInstalledTarget>>>();
const sha = (b: Buffer) => createHash("sha256").update(b).digest("hex");
export function gradeProvisionRuntime(value: unknown) {
const c = checks(), o = privilegedObservation(value); c.add("actual-release-provision-evidence", !!o, "Actual installed release asset identity and genuine native Pi execution are required."); if (!o) return c.result();
c.add("owned-release-matched-assets", o.state.assetsInitiallyAbsent === true && o.state.provisionerSucceeded === true
&& typeof o.state.provisionerSha256 === "string" && typeof o.state.nativeClosureSha256 === "string"
&& o.state.releaseVersion === o.state.healthVersion && o.state.assetPathOwned === true,
"The public operator provisioner installs into the actual source release's owned server package, preserving exact provisioner and closure identities.");
c.add("qualified-running-pi-agent", o.state.piAgentConfigurationVerified === true && o.state.piRunId != null
&& o.state.piArtifactMatches === true && o.runs.some(run => run.id === o.state.piRunId && run.agentId === o.state.piAgentId
&& run.status === "succeeded" && run.runtimeMode === "native") && o.runs.length === 3,
"A separately declared Pi worker performs genuine native work with independently read file bytes; download alone never qualifies it.");
const guidance = String(o.state.guidance ?? "");
c.add("supported-operator-guidance", /runtime\s+setup\s+pi|runtime.*(?:setup|install)/i.test(guidance) && /operator|terminal|admin/i.test(guidance)
&& !/curl.*latest|I (?:have |successfully )?installed/i.test(guidance), "The actual initial response uses the supported operator path without arbitrary latest binaries or premature success.");
const phase = o.state.provisionReport as { attributed?: boolean; reply?: string } | undefined;
c.add("truthful-running-result", phase?.attributed === true && /Pi/i.test(phase.reply ?? "") && /run|execut|qualif/i.test(phase.reply ?? ""),
"A separate actual native reply interprets the factual provisioning and real worker receipt.");
return c.result();
}
const provision = privilegedDefinition("instance-operations.provision-runtime", "privileged-provision", {
async setup(ctx) {
const target = await ownedInstalledTarget(ctx), envName = target.receipt.piCredentialEnv;
if (!envName || !ctx.input.privateInputs?.read(envName)) throw new Error("Real Pi qualification requires the explicitly declared private OpenRouter credential environment reference");
const vendor = path.resolve(target.server, "../vendor/paperclip-runner"), assets = path.join(vendor, "provider-assets/pi", `${process.platform}-${process.arch}`);
let exists = false; try { exists = (await stat(assets)).isDirectory(); } catch (e) { if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e; }
if (exists) throw new Error("Canonical provision context requires this owned release to lack Pi assets; existing assets are never removed by the fixture");
const entry = await realpath(path.join(vendor, "cli/provision-pi.cjs"));
if (!entry.startsWith(target.root + path.sep)) throw new Error("Pi provisioner is not inside the intended owned installed server");
targets.set(ctx, target);
return { releaseVersion: target.receipt.version, assetsInitiallyAbsent: true, provisionerSha256: sha(await readFile(entry)),
piProfile: "runner-acpx-pi", piModel: extendedHarnessProfiles.find(p => p.id === "runner-acpx-pi")!.model };
},
async act(ctx, state) {
const initial = await settlePrivilegedChat(ctx); state.guidance = initial.reply; const target = targets.get(ctx)!;
await target.command(["runtime", "setup", "pi"], 900_000); state.provisionerSucceeded = true;
const closure = await realpath(path.resolve(target.server, "../vendor/paperclip-runner/provider-assets/pi", `${process.platform}-${process.arch}`, "native-closure.json"));
state.assetPathOwned = closure.startsWith(target.root + path.sep); if (!state.assetPathOwned) throw new Error("Provisioned Pi closure escapes the intended installation");
state.nativeClosureSha256 = sha(await readFile(closure));
// Credentials remain exclusively in the public encrypted secret boundary.
const token = ctx.input.privateInputs?.read(target.receipt.piCredentialEnv!); if (!token) throw new Error("Missing selected private Pi credential"); ctx.input.privateSecrets?.push(token);
const company = ctx.input.fixtures.company.id;
const secret = await ctx.input.api.postSensitive<{ id: string }>(`/api/companies/${company}/secrets`, { name: "Owned Pi qualification", key: "OPENROUTER_API_KEY", value: token });
const profile = extendedHarnessProfiles.find(p => p.id === "runner-acpx-pi")!;
const config = profile.buildAgent({ environmentId: ctx.input.fixtures.environment.id, environmentFixtureId: "local", workspacePath: ctx.input.workspacePath,
secretRefs: { OPENROUTER_API_KEY: { type: "secret_ref", secretId: secret.id, version: "latest" } }, executionId: ctx.input.nonce });
const agent = await ctx.input.api.post<RuntimeAgent>(`/api/companies/${company}/agents`, { ...config, name: "Pi qualification worker", reportsTo: ctx.input.fixtures.agent.id,
runtimeConfig: { heartbeat: { enabled: false, maxConcurrentRuns: 1 } } }); state.piAgentId = agent.id;
const ready = await pollUntil({ label: "Actual release Pi worker readiness", deadlineAt: Date.now() + 90000,
load: () => ctx.input.api.get<RuntimeAgent>(`/api/agents/${agent.id}`), accept: a => a.lifecycleState === "ready" });
const saved = ready.adapterConfig as { provider?: string; acpxAgent?: string; model?: string };
state.piAgentConfigurationVerified = ready.adapterType === "paperclip_runner" && saved.provider === "acpx" && saved.acpxAgent === "pi" && saved.model === profile.model;
for (const scope of [{ scopeType: "company", scopeId: company }, { scopeType: "agent", scopeId: agent.id }])
await ctx.input.api.post(`/api/companies/${company}/budgets/policies`, { ...scope, amount: 500, hardStopEnabled: true, isActive: true, unpricedUsagePolicy: "allow" });
const marker = `Pi native qualification ${ctx.input.nonce}`;
const task = await ctx.input.api.post<Entity>(`/api/companies/${company}/issues`, { title: "Owned release Pi readiness", status: "todo", assigneeAgentId: agent.id,
description: `Write pi-qualified.txt in your admitted workspace containing exactly ${JSON.stringify(marker)}, then complete this task. Do not create another task or external side effect.` });
const result = await pollUntil({ label: "Real release-matched native Pi task", deadlineAt: Date.now() + 180000,
load: async () => ({ task: await ctx.input.api.get<Entity>(`/api/issues/${task.id}`), runs: await ctx.allRuns() }),
accept: o => o.task.status === "done" && o.runs.length === 2 && o.runs.every(r => r.status === "succeeded"),
reject: o => o.runs.some(r => ["failed", "timed_out", "cancelled"].includes(r.status)) ? "Actual Pi qualification native run failed" : undefined });
const run = result.runs.find(r => r.agentId === agent.id)!; state.piRunId = run.id;
const file = await ctx.input.api.get<{ content?: { data?: string }; resource?: { workspaceKind?: string } }>(`/api/issues/${task.id}/file-resources/content?workspace=execution&path=pi-qualified.txt`);
state.piArtifactMatches = file.content?.data?.trim() === marker && file.resource?.workspaceKind === "execution_workspace";
const health = await ctx.input.api.get<{ version?: string }>("/api/health"); state.healthVersion = health.version;
const receipt = { releaseVersion: state.releaseVersion, provisionerSha256: state.provisionerSha256, nativeClosureSha256: state.nativeClosureSha256,
profile: profile.id, model: profile.model, piAgentId: agent.id, piRunId: run.id, piRunStatus: run.status, runtimeMode: run.runtimeMode,
exactFileVerified: state.piArtifactMatches, qualificationScope: "one real native task on the actual owned installed source target" };
await ctx.input.evidence("chat-catalog-pi-provision-and-native-readiness.json", receipt);
const message = `The operator provisioned the intended installation and ran its separate Pi qualification worker. These are the observed facts; please describe what they establish and their limits:\n\n${JSON.stringify(receipt)}`;
await sendChatMessage(ctx.input.page, message); state.provisionReport = await companionPhase(ctx, result.runs.map(r => r.id), message);
}, grade: gradeProvisionRuntime, async verifyResult(ctx) { await expect(ctx.input.page.getByTestId("task-chat-composer-input")).toBeVisible(); },
});
provision.expectedRunCount = 3; provision.expectedHumanMessageCount = 2; provision.attemptTimeoutMs = 1_440_000;
provision.coverageGaps = [];
provision.installedSource = "published-global-npm";
provision.requiredCredentials = ["OPENROUTER_API_KEY"];
provision.sourceFiles = [...provision.sourceFiles, "chat-catalog-domains/privileged-installed.ts", "../../cli/src/commands/runtime.ts", "../../packages/paperclip-runner/scripts/provision-pi.mjs"];
export const privilegedProvisionCases = [provision];