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

117 lines
12 KiB
TypeScript

import { execFile, spawn, type ChildProcess } from "node:child_process";
import { promisify } from "node:util";
import { createServer } from "node:http";
import { createHash } from "node:crypto";
import { cp, mkdir, mkdtemp, readFile, realpath, rm, stat, symlink, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import path from "node:path";
import { expect } from "@playwright/test";
import { createDb } from "../../../packages/db/src/index.js";
import { listenOnFetchAllowedPort } from "../../e2e/fetch-allowed-port.js";
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import { pollUntil } from "../api.js";
import { sendChatMessage } from "../chat-flow.js";
import { checks, project, task, type Entity } from "./internal-support.js";
import { privilegedDefinition, privilegedObservation, settlePrivilegedChat, companionPhase } from "./privileged-support.js";
const execute = promisify(execFile);
interface OwnedDev { root: string; checkout: string; home: string; instance: string; env: NodeJS.ProcessEnv; loader: string; entry: string; child?: ChildProcess; closed?: Promise<void>; config?: string }
const owned = new WeakMap<ChatCatalogContext, OwnedDev>();
const source = fileURLToPath(new URL("../../../", import.meta.url));
const digest = (b: Buffer) => createHash("sha256").update(b).digest("hex");
export function validOwnedDevResult(s: Record<string, unknown>) {
return s.sourceCanaryUnchanged === true && s.targetCanaryMatches === true && s.actualTargetHealthy === true
&& s.targetStopped === true && s.targetCleaned === true && s.unrelatedSentinelUnchanged === true
&& s.sourceRevisionPinned === true && typeof s.targetUrl === "string" && s.sourceCliMatches === true;
}
async function command(o: OwnedDev, args: string[]) {
try { return (await execute(process.execPath, ["--import", o.loader, o.entry, ...args], { cwd: o.checkout, env: o.env, timeout: 240000, maxBuffer: 1_048_576 })).stdout; }
catch { throw new Error("Owned development-instance CLI command failed; private output withheld"); }
}
async function stop(o: OwnedDev) {
if (!o.child || !o.closed) return;
if (o.child.exitCode === null && o.child.signalCode === null) o.child.kill("SIGTERM");
let timer: ReturnType<typeof setTimeout> | undefined;
try { await Promise.race([o.closed, new Promise<never>((_, reject) => { timer = setTimeout(() => reject(new Error("Owned CLI child did not stop; preserve its root instead of deleting live state")), 30000); })]); }
finally { if (timer) clearTimeout(timer); }
o.child = undefined;
}
export function gradeOwnedDev(value: unknown) {
const c = checks(), o = privilegedObservation(value); c.add("actual-dev-instance-evidence", !!o, "Actual supported owned checkout initialization, seeding, server readiness and cleanup are required."); if (!o) return c.result();
c.add("exact-owned-seeded-and-cleaned", validOwnedDevResult(o.state), "Only the owned checkout/instance is created and removed; copied canary rows, source state and unrelated sentinel independently verify isolation.");
c.add("operator-dev-guidance", /worktree|dev.*instance|isolated.*instance/i.test(String(o.state.guidance)) && /operator|terminal|human|checkout/i.test(String(o.state.guidance))
&& !/I (?:have |successfully )?(?:created|started|set up)/i.test(String(o.state.guidance)), "Initial chat assigns host changes to the explicit operator companion.");
const phase = o.state.devReport as { attributed?: boolean; reply?: string } | undefined;
c.add("native-reports-real-target", phase?.attributed === true && phase.reply?.includes(String(o.state.targetUrl)) === true
&& /health|ready|clean|stopp/i.test(phase.reply), "The actual follow-up reports the measured target URL and its final readiness/cleanup state.");
return c.result();
}
const dev = privilegedDefinition("cli-operations.owned-dev-instance", "privileged-owned-dev", {
async setup(ctx) {
const temp = process.env.PAPERCLIP_RUNNER_E2E_TEMP_ROOT, sourceConfig = process.env.PAPERCLIP_CONFIG, revision = process.env.PAPERCLIP_RUNNER_E2E_SOURCE_SHA;
if (!temp || !sourceConfig || !revision || !/^[a-f0-9]{40}$/.test(revision)) throw new Error("Owned dev companion requires a source-pinned immutable candidate and private source config");
const root = await mkdtemp(path.join(await realpath(temp), "operator-dev-"));
if (!(await realpath(sourceConfig)).startsWith(await realpath(temp) + path.sep)) throw new Error("Dev seed source config is outside this attempt");
const checkout = path.join(root, "checkout"), home = path.join(root, "instances-home");
const o: OwnedDev = { root, checkout, home, instance: `eval-${ctx.input.nonce.replace(/[^a-z0-9]/gi, "").slice(0, 32)}`,
loader: path.join(source, "cli/node_modules/tsx/dist/loader.mjs"), entry: path.join(checkout, "cli/src/index.ts"),
env: { PATH: process.env.PATH, HOME: path.join(root, "operator-home"), PAPERCLIP_HOME: home, PAPERCLIP_TELEMETRY_DISABLED: "1", PAPERCLIP_NO_BROWSER: "1", NO_COLOR: "1" } };
owned.set(ctx, o);
// Copy actual selected candidate sources. Dependency links resolve only to
// this immutable campaign candidate, never the shared mutable worktree.
const excluded = new Set(["node_modules", ".git", "dist", "target", "results", ".paperclip", "data", "__pycache__", ".env", ".codex", ".secrets"]);
await cp(source, checkout, { recursive: true, filter: file => !path.relative(source, file).split(path.sep).some(part => excluded.has(part)) });
for (const relative of ["", "cli", "server", "ui", "packages/db", "packages/shared"]) {
const modules = path.join(source, relative, "node_modules");
try { if ((await stat(modules)).isDirectory()) await symlink(await realpath(modules), path.join(checkout, relative, "node_modules")); }
catch (e) { if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e; }
}
await mkdir(o.env.HOME!, { recursive: true });
await execute("git", ["init", "--initial-branch=owned-eval"], { cwd: checkout, env: { ...o.env, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null" }, timeout: 10000 });
const sentinel = path.join(root, "unrelated-owned-sentinel.txt"); await writeFile(sentinel, ctx.input.nonce, { mode: 0o600 });
const launch = await project(ctx), canary = await task(ctx, "Owned dev seed canary", launch.id, { description: `Retain ${ctx.input.nonce}` });
return { task: canary, sourceConfigOwned: true, sourceRevision: revision, sourceRevisionPinned: true,
sourceCliMatches: digest(await readFile(o.entry)) === digest(await readFile(path.join(source, "cli/src/index.ts"))),
dependencySource: "explicit immutable candidate modules; source and compiled dependency provenance retained in campaign snapshot receipt" };
},
async act(ctx, state) {
const initial = await settlePrivilegedChat(ctx); state.guidance = initial.reply; const o = owned.get(ctx)!;
const reserve = async () => { const listener = createServer(); const port = await listenOnFetchAllowedPort(listener); await new Promise<void>((resolve, reject) => listener.close(e => e ? reject(e) : resolve())); return port; };
const serverPort = await reserve(), dbPort = await reserve();
if (serverPort === dbPort) throw new Error("Owned dev ports unexpectedly collide");
await command(o, ["worktree", "init", "--instance", o.instance, "--home", o.home, "--from-config", process.env.PAPERCLIP_CONFIG!, "--server-port", String(serverPort), "--db-port", String(dbPort), "--seed-mode", "minimal"]);
o.config = path.join(o.checkout, ".paperclip/config.json");
const actual = JSON.parse(await readFile(o.config, "utf8"));
const actualData = await realpath(actual.database.embeddedPostgresDataDir);
if (!actualData.startsWith(o.root + path.sep) || actual.database.embeddedPostgresPort !== dbPort || actual.server.port !== serverPort) throw new Error("Public worktree config escapes the exact owned target");
o.child = spawn(process.execPath, ["--import", o.loader, o.entry, "run", "--config", o.config, "--yes"], { cwd: o.checkout, env: o.env, stdio: "ignore" });
o.closed = new Promise<void>((resolve, reject) => { o.child!.once("error", reject); o.child!.once("close", () => resolve()); });
state.targetUrl = `http://127.0.0.1:${serverPort}`;
await pollUntil({ label: "Actual owned development target readiness", deadlineAt: Date.now() + 120000,
load: async () => { try { const r = await fetch(new URL("/api/health", String(state.targetUrl)), { signal: AbortSignal.timeout(3000) }); return { ok: r.ok, health: await r.json() as { status?: string } }; } catch { return { ok: false, health: {} }; } },
accept: r => r.ok && r.health.status === "ok", reject: () => o.child?.exitCode != null ? "Owned dev server exited before readiness" : undefined }); state.actualTargetHealthy = true;
const db = createDb(`postgres://paperclip:paperclip@127.0.0.1:${dbPort}/paperclip`, { maxConnections: 1, prepare: false }).$client;
const marker = state.task as Entity;
try { const rows = await db.unsafe("select id, company_id, title, description, status from issues where id = $1", [marker.id]);
state.targetCanaryMatches = rows.length === 1 && rows[0]!.company_id === marker.companyId && rows[0]!.title === marker.title && rows[0]!.description === marker.description && rows[0]!.status === marker.status;
} finally { await db.end({ timeout: 5 }); }
const sourceTask = await ctx.input.api.get<Entity>(`/api/issues/${marker.id}`);
state.sourceCanaryUnchanged = sourceTask.title === marker.title && sourceTask.description === marker.description && sourceTask.status === marker.status;
await stop(o); state.targetStopped = true;
await command(o, ["worktree:cleanup", o.instance, "--instance", o.instance, "--home", o.home]);
state.targetCleaned = !(await stat(path.join(o.home, "instances", o.instance)).then(() => true, e => { if (e.code === "ENOENT") return false; throw e; }));
state.unrelatedSentinelUnchanged = await readFile(path.join(o.root, "unrelated-owned-sentinel.txt"), "utf8") === ctx.input.nonce;
const receipt = { targetUrl: state.targetUrl, healthyWhenStarted: state.actualTargetHealthy, targetStopped: state.targetStopped, targetCleaned: state.targetCleaned,
seededCanaryMatches: state.targetCanaryMatches, sourceCanaryUnchanged: state.sourceCanaryUnchanged, unrelatedSentinelUnchanged: state.unrelatedSentinelUnchanged, sourceRevision: state.sourceRevision };
await ctx.input.evidence("chat-catalog-owned-dev-instance.json", receipt);
const message = `The operator used the supported owned development-instance commands and recorded these facts. Please report its URL and observed health/cleanup state:\n\n${JSON.stringify(receipt)}`;
await sendChatMessage(ctx.input.page, message); state.devReport = await companionPhase(ctx, initial.runs.map(r => r.id), message);
}, grade: gradeOwnedDev, async verifyResult(ctx) { await expect(ctx.input.page.getByTestId("task-chat-composer-input")).toBeVisible(); },
});
dev.expectedRunCount = 2; dev.expectedHumanMessageCount = 2; dev.attemptTimeoutMs = 900000;
dev.cleanup = async ctx => { const o = owned.get(ctx); if (!o) return; await stop(o); if (o.config) await command(o, ["worktree:cleanup", o.instance, "--instance", o.instance, "--home", o.home]);
const root = await realpath(process.env.PAPERCLIP_RUNNER_E2E_TEMP_ROOT!), directory = await realpath(o.root);
if (!directory.startsWith(root + path.sep) || !path.basename(directory).startsWith("operator-dev-")) throw new Error("Refusing non-owned development cleanup");
await rm(directory, { recursive: true }); owned.delete(ctx); };
dev.sourceFiles = [...dev.sourceFiles, "../../cli/src/index.ts", "../../cli/src/commands/worktree.ts", "../../cli/src/commands/run.ts", "../e2e/fetch-allowed-port.ts"];
export const privilegedOwnedDevCases = [dev];