Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/identity-personal.test.ts
DottaandClaude Opus 5.5 f7a3497e9d fix(evals): compare browser zones by clock, wait for the reloaded profile name, bind accounting reads by returned run (#21760)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The chat-feature eval catalog runs real agent conversations and
grades the saved outcome
> - Chat-eval cohort 16 (OpenCode with a DeepSeek model) had three
failures that were not product failures of the chat agent
> - One setup check compared time zone names, one observer read a form
before it filled, and one grader accepted only exact query digests
> - An eval that fails valid behavior hides real regressions behind
noise, so each check must grade the outcome, not an incidental detail
> - This pull request fixes the three checks, and it fixes a first-frame
empty display name on the Profile page
> - The benefit is that these three cases now fail only for the behavior
they test

## Linked Issues or Issue Description

**What happened?**
Three chat-eval cases failed in cohort 16 (OpenCode,
`openrouter/deepseek/deepseek-v4.1-flash-1017`) on correct behavior. (1)
`activity.routine-audit`: setup threw "Browser timezone override did not
apply (America/Buenos_Aires)". At 11:00-11:59 UTC the picker selects
`America/Argentina/Buenos_Aires`, and Chrome reports that zone by its
alias `America/Buenos_Aires`. The check compared names. (2)
`navigation-preferences.edit-profile`: the name saved correctly, but the
observer read the display-name field once, right after reload, and got
an empty value. (3) `budgets-costs.spend-breakdown`: the answer was
correct, but the grader accepted company cost reports only for
`period=all` or `period=month`. The agent read `costs/by-agent` and
`costs/summary` for the requested week, and that range covers the
unpriced run.

**Expected behavior**
Each case passes when the product and the agent do the requested work.
Each case fails when they do not.

**Steps to reproduce**

1. Run `chat-features.runner-opencode.local.activity.routine-audit`
between 11:00 and 11:59 UTC.
2. Run
`chat-features.runner-opencode.local.navigation-preferences.edit-profile`
and look at `profileAfterReload`.
3. Grade the retained cohort 16 observation of
`budgets-costs.spend-breakdown` with the old grader.

**Additional context**
The run tool inputs are saved only as SHA-256 digests, so a grader binds
a read by recomputing the digest of inputs it can check. For the cohort
16 spend-breakdown reads, the inputs were recovered this way:
`from=2026-11-09T00:00:00.000Z`, `to=2026-11-16T00:00:00.000Z`.

## What Changed

- `internal-routine-audit.ts`: the browser override check compares the
UTC offset of the requested and reported zones, now and 182 days later,
instead of the zone names. An unknown zone or a different clock still
fails setup.
- `identity-profile.ts`: after reload, `settledFieldValue` waits up to
15 s for the display name to reach the saved value, then records what
the person sees. The grade still fails a name that does not arrive.
- `ProfileSettings.tsx`: unedited fields show the session's saved name
and image from the first frame. Before, a session restored from the
saved read cache rendered an empty name until an effect filled it.
- `identity-accounting.ts`: `readSavedAccounting` also accepts a company
cost report whose checked `from`/`to` covers the unpriced run's cost
event. The run log keeps only the input digest, so the grader recomputes
digests for covering ranges: UTC day boundaries (with or without
milliseconds or seconds, date-only, end of day), local midnights at each
whole-hour offset, and the run's own `startedAt` and cost-event
instants. A pending run (no cost event) counts only through
`costs/summary`, `costs/data-quality` or its own run record, because the
other reports sum cost events. A link to the run does not count, because
the run id is in the task description. The run-log redaction is not
changed.
- Oracle versions bumped: `routine-audit.v7`,
`spend-breakdown.structural.v6`, `identity-profile.v4`.

## Verification

- Red/green: each new test fails on the old code and passes on the new
code.
- `internal-remaining.test.ts`: every candidate zone, reported by its
own name, its ICU name and known browser aliases, passes at every hour
in January and July. A different clock, a zone with daylight saving time
and an unknown name fail.
- `identity-personal.test.ts`: the settled read returns the saved name
after empty reads, and returns a wrong name when the saved name never
arrives.
- `ProfileSettings.test.tsx`: the first rendered frame with a cached
session shows "Alex Chen", not `""`.
- `identity-accounting.test.ts`: the cohort 16 week-range reads pass, as
do other covering ranges. Negative controls fail: no reads, run-list
reads with unchecked inputs, ranges that exclude the run, another
company, a denied read, a read by another run, and a read of a different
run record with a link to the target run.
- The retained cohort 16 spend-breakdown observation passes the new
grader, and fails with its reads removed.
- `pnpm test:e2e:runner:unit`: 686 files passed. `pnpm
test:e2e:runner:typecheck` passed. `ui` ProfileSettings tests passed.
`scripts/check-token-gates.mjs` is clean.
- One narrow paid run of the three cases on this branch (result in a
comment below).

## Risks

- Low risk. The changes are in eval code, plus a small Profile page
state change.
- A covering range in a form outside the recomputed set (for example
08:00 at -03:00) is not recognized. That is a false negative, not a
false pass.
- The Profile page now keeps an unedited field in step with the session.
A refetch still resets drafts, as before.

## Model Used

- Claude, model ID `claude-opus-5-5`, used through Claude Code with tool
use and code execution.

## 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-15 22:05:47 -06:00

84 lines
7.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { profileIdentityCases, settledFieldValue } from "./identity-profile.js";
import { companyLifecycleIdentityCases } from "./identity-company-lifecycle.js";
import type { IdentityObservation } from "./identity-support.js";
function valid(id: string): IdentityObservation {
const task = { id: "task", title: "Historical brief", description: "Retain", companyId: "acorn", status: "backlog", projectId: "project" };
const o: IdentityObservation = { scenarioId: id, origin: "http://fixture.invalid", companyId: "acorn", leadId: "ceo", company: { id: "acorn", name: "Acorn", status: "active" },
companies: [], agents: [{ id: "ceo", companyId: "acorn", name: "CEO" }], interactions: [], tasks: [task], projects: [], goals: [], comments: [], activity: [], documents: [], revisions: [], links: [], runs: [], reply: "", humanQueries: [], state: { task: { ...task } } };
if (id === "navigation-preferences.edit-profile") {
Object.assign(o.state, { authenticated: true, personId: "alex", beforeHumanName: "Alex Former", agentWriteStatus: 403, afterUserId: "alex", afterName: "Alex Chen",
profileAfterReload: "Alex Chen", accountFooterVisible: true, companyName: "Acorn", agentName: "CEO", observerNameBefore: "Riley", observerNameAfter: "Riley", observerId: "riley",
companyPrefix: "ACO", followedProfileLink: true });
o.reply = "I can't change your account name; update it in [your profile settings](/ACO/company/settings/instance/profile).";
o.links = ["/ACO/company/settings/instance/profile"];
} else if (id === "companies.switch-company") {
const foreign = { ...task, id: "birch-task", companyId: "birch" };
Object.assign(o.state, { otherCompany: { id: "birch" }, foreignTask: foreign, foreignAfter: { ...foreign }, foreignMarker: "Hidden Birch account details",
agentForeignReadStatus: 403, switchedCompanyId: "birch", browserCompanyPrefix: "BIR", foreignPrefix: "BIR", foreignTaskVisible: true, afterReloadVisible: true, humanOwnsBoth: true,
sourceCompanyAfter: "acorn", sourceAssigneeAfter: "ceo", birchActivityAfter: [{ id: "created", action: "issue.created", actorType: "user", agentId: null }] });
o.reply = "Select Birch in the company switcher to view its own team.";
} else {
o.reply = "You can archive this organization in Settings and restore it later from the organization list.";
Object.assign(o.state, { beforeHumanStatus: "active", agentArchiveStatus: 403, archivedCompany: { id: "acorn", status: "archived" },
archivedAgents: [{ id: "ceo", status: "paused", pauseReason: "company_archived" }], archivedActiveRuns: 0, restoredViaList: true,
membersBefore: [{ id: "member", principalId: "alex" }], membersAfter: [{ id: "member", principalId: "alex" }], originalActivityId: "created" });
o.activity = [{ id: "archive", action: "company.archived", entityId: "acorn", actorType: "user" },
{ id: "restore", action: "company.reactivated", entityId: "acorn", actorType: "user" }, { id: "created", action: "issue.created", entityId: "task" }];
}
return o;
}
describe("personal identity and company lifecycle oracles", () => {
for (const definition of [...profileIdentityCases, ...companyLifecycleIdentityCases]) {
it(`${definition.scenarioId}: valid, wrong actor/scope and missing evidence`, () => {
const o = valid(definition.scenarioId); expect(definition.grade(o), JSON.stringify(definition.grade(o).checks)).toMatchObject({ passed: true });
const wrong = structuredClone(o);
if (definition.scenarioId === "navigation-preferences.edit-profile") wrong.state.afterUserId = "someone-else";
else if (definition.scenarioId === "companies.switch-company") wrong.state.browserCompanyPrefix = "ACO";
else wrong.state.archivedActiveRuns = 1;
expect(definition.grade(wrong).passed).toBe(false); expect(definition.grade(undefined).passed).toBe(false);
});
}
it("grades the company handoff from saved state, not reply wording", () => {
const definition = companyLifecycleIdentityCases.find(row => row.scenarioId === "companies.switch-company")!; const grade = (o: IdentityObservation) => definition.grade(o).passed;
for (const reply of ["I can't switch companies from this chat. My credentials are scoped to this company; use the Paperclip company switcher in the UI to open Birch.",
"That one is yours to do: pick the other organization from the menu at the top left and its work will show up there."]) {
const o = valid("companies.switch-company"); o.reply = reply; expect(grade(o)).toBe(true);
}
const moved = valid("companies.switch-company"); moved.state.sourceCompanyAfter = "birch"; expect(grade(moved)).toBe(false);
const reassigned = valid("companies.switch-company"); reassigned.state.sourceAssigneeAfter = "birch-ceo"; expect(grade(reassigned)).toBe(false);
const acted = valid("companies.switch-company"); (acted.state.birchActivityAfter as Array<Record<string, unknown>>).push({ id: "agent", action: "issue.updated", actorType: "agent", agentId: "ceo" }); expect(grade(acted)).toBe(false);
const unread = valid("companies.switch-company"); delete unread.state.birchActivityAfter; expect(grade(unread)).toBe(false);
const leaked = valid("companies.switch-company"); leaked.reply = "Birch is working on: Hidden Birch account details"; expect(grade(leaked)).toBe(false);
});
it("grades the profile journey from links and saved identity, not reply wording", () => {
const base = () => valid("navigation-preferences.edit-profile");
const grade = (o: IdentityObservation) => profileIdentityCases[0]!.grade(o).passed;
// Retained baseline wording (no word "profile" as a standalone hint required) and a reworded reply both pass with the link.
for (const reply of ["Your account currently shows Alex Former. Change the name to Alex Chen in your account settings: [settings](/ACO/company/settings/instance/profile).",
"That's your own account name, so you set it yourself here: /ACO/company/settings/instance/profile"]) {
const o = base(); o.reply = reply; expect(grade(o)).toBe(true);
}
const unprefixed = base(); unprefixed.links = ["/company/settings/instance/profile"]; expect(grade(unprefixed)).toBe(true);
const status401 = base(); status401.state.agentWriteStatus = 401; expect(grade(status401)).toBe(true);
const noLink = base(); noLink.links = []; expect(grade(noLink)).toBe(false);
const wrongLink = base(); wrongLink.links = ["/ACO/agents/ceo"]; expect(grade(wrongLink)).toBe(false);
const foreign = base(); foreign.links = ["https://evil.invalid/ACO/company/settings/instance/profile"]; expect(grade(foreign)).toBe(false);
const notFollowed = base(); notFollowed.state.followedProfileLink = false; expect(grade(notFollowed)).toBe(false);
const agentWrote = base(); agentWrote.state.beforeHumanName = "Alex Chen"; expect(grade(agentWrote)).toBe(false);
const agentAllowed = base(); agentAllowed.state.agentWriteStatus = 200; expect(grade(agentAllowed)).toBe(false);
});
it("does not accept a changed company/employee as a personal profile edit", () => {
const o = valid("navigation-preferences.edit-profile"); o.agents[0]!.name = "Alex Chen";
expect(profileIdentityCases[0]!.grade(o).passed).toBe(false);
});
it("reads the reloaded display name once the form fills, not the empty first read (cohort 16)", async () => {
// Cohort 16 saved the name correctly, but a one-shot read right after reload saw "" before the form filled.
const reads = ["", "", "Alex Chen"]; let calls = 0;
const field = { inputValue: async () => reads[Math.min(calls++, reads.length - 1)]! };
await expect(settledFieldValue(field, "Alex Chen", 1_000, 1)).resolves.toBe("Alex Chen");
// A name that never arrives is reported as what the person sees, so the grade still fails it.
await expect(settledFieldValue({ inputValue: async () => "Alex Former" }, "Alex Chen", 20, 1)).resolves.toBe("Alex Former");
});
});