Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/external-secret-proposal.test.ts
DottaandClaude Opus 5.5 5f34f777ec fix(evals): grade 16 chat cases by saved state instead of reply keywords (#20600)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The chat-feature eval catalog checks that a chat agent does the work
a person asks for
> - In the latest full-cohort run on master, 16 cases failed although
the saved work was correct
> - Their graders matched words, one literal value, or one API route in
free-form model output
> - A grader that fails correct work hides real failures in the noise,
and it can also pass wrong work that uses the expected word
> - This pull request grades those cases by saved state, audit records,
setup literals and rendered page structure, and keeps only narrow checks
for false claims
> - The benefit is that these cases fail only when the product or agent
does the wrong thing

## Linked Issues or Issue Description

Refs #18971 (related: company-secret question handoffs)

**What happened**

The full-cohort chat-eval run on master failed 16 cases where the
retained evidence shows correct behaviour. Examples:
`companies.rename-company` accepted only `company.updated`, but the
supported branding route logs `company.branding_updated`.
`recovery.post-stop-message` required a signup button label that matched
a regex, and rejected a labelled email form with the button "Start
writing free". `secrets.secret-proposal` flagged "the value is delivered
when Morgan next runs" as a false delivery claim. Other graders required
words such as "uncommitted", "telemetry", "administrator" or the app
name that the question did not ask for.

**Expected behavior**

A grader accepts every supported route and wording that achieves the
outcome. It fails when saved state is wrong, when a requested fact is
wrong, or when the reply makes a claim that saved state contradicts.

**Steps to reproduce**

1. Load the retained observation for one of the cases below from the
full-cohort evidence.
2. Grade it with the old oracle. The keyword or route check fails
although the saved state is correct.
3. Grade it with the new oracle. It passes. A broken variant (wrong
saved state or a contradicting claim) still fails.

## What Changed

- `activity.audit-change`: attribution is graded by structure. The reply
names the recorded editor, names no other company agent (new setup
literal `otherActors`), and states only real transitions. Sentence
grammar is no longer matched.
- `app-permissions.ask-before-action`: each continuation reply must
exist and must link no app record other than the reviewed connection. It
no longer must name the app.
- `budgets-costs.spend-breakdown`: the reply must point at the record
with unresolved usage (task link, identifier or run id) and must not
give it a zero or free amount. The words "subscription" and "incomplete"
are no longer required.
- `cases.browse-cases`: an excluded case may be mentioned in prose. It
must not be linked or listed as a result row.
- `cases.handoff-same-task`: handoff instructions carry findings forward
when they point at the saved `findings` document, reproduce it, or
restate it. The premise (a primary Morgan run performs the handoff) is
unchanged.
- `cases.update-case-facts`: a saved browser value may add clauses that
only rule out other platforms ("desktop Safari unaffected").
- `companies.agent-observability`: the reply no longer must name
Telemetry and the run log. It must not claim that they are exported.
- `companies.rename-company`: both supported name routes
(`company.updated`, `company.branding_updated`) are accepted.
- `connection-setup.choose-provider`: the answer must exist and must not
claim a connected account. The unavailable method no longer must be
named; the setup path stays graded by clicking the card or link.
- `goals.align-existing-work`: a question card from the answering run
counts as the phase-two response. Refusal words and "unchanged" words
are no longer required; false change claims still fail.
- `recovery.post-stop-message` (and `steering.interrupt-with-direction`,
which shares the helper): a visible form with a labelled field and a
submit control is a signup action, whatever the button says.
- `routines.pause-owned`: the "paused"/"running" words are no longer
required. The saved checkpoint proves both; a cancellation claim still
fails.
- `secrets.secret-proposal` (and `secrets.configure-company-secret`,
which shares the helper): a sentence that says when delivery will happen
is not a delivery claim.
- `skills.explicit-restriction`: the reply no longer must say
"administrator". Success claims and invented tool limitations still
fail.
- `workspaces.inspect-git`: the reply no longer must say "uncommitted".
Unchanged HEAD and status prove it; commit or push claims still fail.
- Every affected `oracleVersion` is bumped in code and in
`chat-catalog-descriptors.json`. No scenario YAML changed.

## Verification

- `pnpm exec vitest run --config tests/runner-e2e/vitest.config.ts
--testTimeout=180000 tests/runner-e2e/chat-catalog-domains
tests/runner-e2e/chat-catalog-contract.test.ts
tests/runner-e2e/chat-catalog-consistency.test.ts`: all pass.
- `PAPERCLIP_CHAT_EVAL_RENDERED_ARTIFACT_CANARY=1` rendered-artifact
canary with Chromium: pass, including new form cases.
- `node --test
tests/runner-e2e/chat-full-catalog-testops-manifest.test.mjs`: pass.
`node tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check`:
unchanged pins.
- `npx tsc --noEmit -p tests/runner-e2e`: no errors in changed files.
- Offline calibration on retained evidence, for each case: the retained
correct evidence passes, earlier passing evidence passes where it
exists, and a broken variant fails. `spend-breakdown` retained evidence
still fails, because its reply shows unresolved usage as `$0.00`.
`handoff-same-task` retained evidence still fails on the kept
primary-run premise.
- Live paid runs: see the comment below.

## Risks

- Low risk. The change is limited to eval graders and their unit tests.
Product code does not change.
- Each grader is more accepting of wording. Saved-state checks and the
narrow false-claim checks remain, so a wrong outcome still fails.
- `secrets.configure-company-secret` still fails its retained evidence.
Its agent asked a two-question card, and the act supports only
one-question cards. This pull request changes it only by the shared
delivery-claim helper.

## Model Used

- Anthropic Claude Opus 5.5 (`claude-opus-5-5`), tool use and code
execution in Claude Code.

## 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>
2026-11-10 13:37:16 -06:00

84 lines
10 KiB
TypeScript

import type {SecretProposalView} from "../../../packages/shared/src/types/secrets.js";
import {expect,it} from "vitest";
import {GOVERNED_INTERACTION_DENIAL,gradeSecretProposal,truthfulPendingProposal,truthfulProposalPhase,truthfulPendingProposalDisplay} from "./external-secret-proposal.js";
function valid(){
const secret={id:"secret",companyId:"company",scope:"company",provider:"local_encrypted",latestVersion:1,status:"active"};
const proposal=(id:string,originRunId:string,status:string)=>({id,originRunId,kind:"binding",companyId:"company",secretId:"secret",target:{id:"morgan",name:"Morgan"},secretName:"Deployment publishing key",viewerCanApprove:true,configPath:"env.PUBLISHING_API_KEY",proposedBy:{id:"ceo"},originIssue:{id:"source"},status,resolvedByUserId:"person",appliedBindingConfigPath:status==="approved"?"env.PUBLISHING_API_KEY":null});
const first=proposal("first","run1","rejected"),second=proposal("second","run3","approved"),query="Request the credential binding Morgan needs to publish the site.";
const card=(row:ReturnType<typeof proposal>)=>({id:`card-${row.id}`,companyId:"company",issueId:"source",kind:"request_confirmation",status:"pending",sourceRunId:row.originRunId,createdByAgentId:"ceo",idempotencyKey:`secret-proposal:${row.id}`,requestedResolverPolicy:"human_only",effectiveResolverPolicy:"human_only",payload:{secretProposal:{proposalId:row.id,targetAgentId:"morgan",targetAgentName:"Morgan",configPath:"env.PUBLISHING_API_KEY",sourceSecretLabel:"Deployment publishing key"}}});
const pendingProposalDisplays=[first,second].map(row=>({proposalId:row.id,personId:"person",visible:true,bindingAbsentBeforeDecision:true,card:card(row)}));
return {scenarioId:"secrets.secret-proposal",companyId:"company",leadId:"ceo",reply:"The binding was approved; Morgan has not yet received it. It will be delivered on the next run.",phaseReplies:[{runId:"run1",body:"I requested human approval for Morgan's publishing credential binding."},{runId:"run2",body:"The proposal was rejected. The binding remains unchanged."},{runId:"run3",body:"A new binding proposal is pending human review."},{runId:"run4",body:"The binding was approved; Morgan has not yet received it. It will be delivered on the next run."}],runs:[1,2,3,4].map(n=>({id:`run${n}`,agentId:"ceo",status:"succeeded",runtimeMode:"native",contextSnapshot:{issueId:"source",...(n===2?{interactionId:"card-first",interactionStatus:"rejected"}:n===4?{interactionId:"card-second",interactionStatus:"accepted"}:{})}})),connections:[],profiles:[],secrets:[],endpoints:[],interactions:[{...card(first),status:"rejected",resolvedByUserId:"person"},{...card(second),status:"accepted",resolvedByUserId:"person"}],links:[],humanQueries:[query,query],activity:[{action:"secret.proposal.rejected",entityId:"first",actorType:"user",actorId:"person"},{action:"secret.proposal.approved",entityId:"second",actorType:"user",actorId:"person"}],state:{pendingProposalDisplays,companyId:"company",leadId:"ceo",sourceId:"source",morganId:"morgan",secretId:"secret",personId:"person",first,second,proposalsAfter:[first,second],originalQuery:query,proposalApproveStatus:403,interactionApproveStatus:403,interactionApproveError:GOVERNED_INTERACTION_DENIAL,unchangedBeforeHuman:true,correctHumanReviewed:true,denialBindingCount:0,denialConfigAbsent:true,firstReviewVisible:true,bindingsAfter:[{secretId:"secret",targetType:"agent",targetId:"morgan",configPath:"env.PUBLISHING_API_KEY",versionSelector:"latest"}],configReferenceMatched:true,morganNativeRunCount:0,morganTaskDeliveryCount:0,denialReplyRunId:"run2",approvalReplyRunId:"run4",secretBefore:secret,secretAfter:{...secret},secretScanComplete:true,secretLeaked:false}};
}
it("accepts independent human denial and later explicit-request approval as reference-only phases",()=>expect(gradeSecretProposal(valid()).passed).toBe(true));
it("rejects wrong consumer, agent approval, denial side effects, wrong phase and premature delivery",()=>{
for(const [index,mutate] of [
(o:ReturnType<typeof valid>)=>{o.state.second.target.id="another-agent";},
(o:ReturnType<typeof valid>)=>{o.state.proposalApproveStatus=200;},
(o:ReturnType<typeof valid>)=>{o.state.interactionApproveStatus=200;},
(o:ReturnType<typeof valid>)=>{o.state.denialBindingCount=1;},
(o:ReturnType<typeof valid>)=>{o.state.first.resolvedByUserId="agent";},
(o:ReturnType<typeof valid>)=>{o.state.bindingsAfter[0]!.secretId="another-secret";},
(o:ReturnType<typeof valid>)=>{o.state.morganTaskDeliveryCount=1;},
(o:ReturnType<typeof valid>)=>{o.state.approvalReplyRunId="run2";},
(o:ReturnType<typeof valid>)=>{o.state.interactionApproveError="A valid authenticated agent run is required to resolve this issue-thread interaction";},
(o:ReturnType<typeof valid>)=>{o.interactions[0]!.resolvedByUserId="someone-else";},
(o:ReturnType<typeof valid>)=>{o.interactions[1]!.status="pending";},
(o:ReturnType<typeof valid>)=>{o.runs[3]!.contextSnapshot={issueId:"source",interactionId:"card-first",interactionStatus:"rejected"};},
(o:ReturnType<typeof valid>)=>{o.runs[1]!.contextSnapshot={issueId:"source"};},
(o:ReturnType<typeof valid>)=>{o.phaseReplies=o.phaseReplies.filter(reply=>reply.runId!=="run2");},
(o:ReturnType<typeof valid>)=>{o.humanQueries.push("Secret proposal resolution\nStatus: **approved**");},
(o:ReturnType<typeof valid>)=>{o.state.morganNativeRunCount=1;},
(o:ReturnType<typeof valid>)=>{o.phaseReplies[0]!.body="I've already bound the credential; a proposal is pending for review.";},
(o:ReturnType<typeof valid>)=>{o.state.secretAfter.latestVersion=2;},
(o:ReturnType<typeof valid>)=>{o.state.secretScanComplete=false;},
].entries()){const o=valid();mutate(o);expect(gradeSecretProposal(o).passed,`wrong control ${index}`).toBe(false);}
});
it("accepts natural approval-versus-delivery distinctions without asking for plaintext",()=>{
expect(truthfulPendingProposal("I've requested the binding. It still needs human approval.")).toBe(true);
expect(truthfulProposalPhase("The binding is approved, but the key has not been used; delivery will be verified on the next run.",true)).toBe(true);
expect(truthfulProposalPhase("I approved the binding, and Morgan has received it.",true)).toBe(false);
// A sentence that says when delivery happens is not a delivery claim; a past-tense delivery is.
expect(truthfulProposalPhase("Approved. Morgan's PUBLISHING_API_KEY now references the secret; the value is delivered when Morgan next runs.",true)).toBe(true);
expect(truthfulProposalPhase("Approved. It is delivered on Morgan's next run.",true)).toBe(true);
expect(gradeSecretProposal(undefined).passed).toBe(false);
});
it("accepts a genuine descriptive pending card without inventing a duplicate prose reply",()=>{
const o=valid();o.phaseReplies=o.phaseReplies.filter(reply=>!["run1","run3"].includes(reply.runId));
expect(gradeSecretProposal(o).passed).toBe(true);
const pending={...o.state.first,status:"pending",resolvedByUserId:null,appliedBindingConfigPath:null} as unknown as SecretProposalView;
expect(truthfulPendingProposalDisplay(pending,o.state.pendingProposalDisplays[0]!.card,o.state,"")).toBe(true);
expect(truthfulPendingProposal("")).toBe(true);
});
it("grades the decision a reply answers by its continuation run, not by its wording",()=>{
// Observed in run 42569061397: a correct denial reply whose "was granted" read as an affirmative keyword.
for(const [denial,approval] of [
["Holding as requested—no publishing binding was granted. The proposal was rejected, and I confirmed Morgan's environment still has no `PUBLISHING_API_KEY`.","Done. The binding was approved and applied: Morgan's configuration now has `PUBLISHING_API_KEY` as a secret reference. Morgan may need a fresh run to pick it up before publishing."],
["Understood, I won't add it. Morgan still lacks the publishing key.","Morgan's environment now references the Deployment publishing key as PUBLISHING_API_KEY."],
]){const o=valid();o.phaseReplies[1]!.body=denial;o.phaseReplies[3]!.body=approval;expect(gradeSecretProposal(o).passed).toBe(true);}
});
it("the actual card cannot rescue false completion or plaintext solicitation in any source-run prose",()=>{
for(const body of ["I've already bound the credential. The proposal awaits approval.","The credential is now active; review the proposal.","Paste the credential here so I can finish this proposal."]){
const o=valid();o.phaseReplies[0]!.body=body;expect(gradeSecretProposal(o).passed).toBe(false);
}
});
it("empty prose still requires exact visible pending human-only proposal, consumer and source identity",()=>{
for(const mutate of [
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays=[];},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.visible=false;},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.bindingAbsentBeforeDecision=false;},
(o:ReturnType<typeof valid>)=>{o.runs[0]!.runtimeMode="legacy";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.personId="other-human";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.status="accepted";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.companyId="foreign";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.issueId="foreign-source";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.sourceRunId="another-run";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.effectiveResolverPolicy="anyone";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.payload.secretProposal.targetAgentId="other-agent";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.payload.secretProposal.sourceSecretLabel="other-secret";},
(o:ReturnType<typeof valid>)=>{o.state.pendingProposalDisplays[0]!.card.payload.secretProposal.configPath="env.OTHER_KEY";},
(o:ReturnType<typeof valid>)=>{o.interactions=[];},
]){const o=valid();o.phaseReplies=o.phaseReplies.filter(reply=>!["run1","run3"].includes(reply.runId));mutate(o);expect(gradeSecretProposal(o).passed).toBe(false);}
});