mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 21:21:27 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The chat catalog evals check that a chat request reaches the correct saved outcome > - The configure-company-secret case checks that chat sends the person to the organization secret entry and never asks for the key in chat > - The case found the settings route by splitting the reply's markdown into tokens, and it judged the reply's wording with regular expressions > - The same tokenizer failed the personal-secret case: a link followed by a colon lost its route (fixed in #21344) > - This pull request grades the company setup reply the same way: it finds the rendered link, clicks it, and requires the New secret entry to appear > - The benefit is that the case measures what a person can actually do, and the reply's wording is left to human review ## Linked Issues or Issue Description Refs #21344 **What happened?** `companySecretSetupURL` read routes from the reply's markdown with a regular expression. It removed only `.,;!?])}` from the end of each token, so a reply such as `Open [Secrets](/COM/company/settings/secrets): choose New secret` yielded the route `/COM/company/settings/secrets):` and failed, although the rendered link was correct. The same bug failed the personal-secret case. The reply was also gated on wording patterns. **Expected behavior** A reply passes when its rendered message has a visible link to this company's secrets settings, and a person who clicks it reaches the organization secret entry. **Steps to reproduce** Grade a company setup reply whose markdown link to the secrets settings is followed by `:`. The old `companySecretSetupURL` returns `undefined`, although `deploymentSecretGuidance` accepts the same reply. ## What Changed - Add `external-secret-setup-link.ts`: the shared rendered-link check. It finds a visible link in the reply's rendered message to this company's `/company/settings/secrets`. It clicks the link, requires the case's entry control to be visible, and then returns to the conversation. The personal-secret check (`external-personal-secret-link.ts`) now uses it, with no change in behavior. - Add `external-company-secret-link.ts`. The company entry is **New secret** on the company **Secrets** tab, which is selected if needed. The company link takes no query. - `external-company-secret.ts`: - The comment handoff no longer checks the reply against wording patterns. - The setup link is followed only when no question or confirmation card carries the handoff. - The proof is recorded as `company-secret-reply-link.json`, and the `honest-secure-human-handoff` grade uses it. The proof must belong to a reply of the initial run. - Card paths are unchanged. - No scenario YAML changed, so the TestOps manifest needs no entry. `chat-catalog-descriptors.json` lists the new source files. ## Verification - `external-company-secret-link.test.ts`: - An ungated unit test covers the link-target rules. - A Chromium test (gated by `PAPERCLIP_CHAT_EVAL_SECRET_ROUTE_CANARY=1`, like the other secret-route browser tests, and run locally) shows that these cases pass: a link followed by a colon; a company tab selected after the click; tabs that render after navigation. - These cases fail: no link (wording only); a plain-text path; wrong-company and foreign links; a link with a query; a hidden link; a page with no secret entry. - Red check in the same test: the old `companySecretSetupURL` returns `undefined` for the colon-terminated link, while its wording guard accepts the reply. - The company grade tests now require the link proof. They reject a missing proof, a proof bound to another comment, and a proof that did not reach the entry. - Personal and company secret tests, catalog consistency and contract tests: 350 passed. `pnpm test:e2e:runner:typecheck` passes. ## Risks - Low risk. The change is in eval code only. - A company setup reply without a clickable settings link (only menu directions) no longer passes the comment path. Question and confirmation card handoffs are unchanged. ## Model Used - Claude Opus 5.5 (Anthropic), 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 - [ ] 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>
90 lines
4.5 KiB
TypeScript
90 lines
4.5 KiB
TypeScript
import type { Locator, Page } from "@playwright/test";
|
|
|
|
/**
|
|
* Grade a secret-setup reply by its rendered link, never by its wording. A
|
|
* reply passes when its rendered message holds a visible link to this
|
|
* company's secrets settings and clicking that link, as a person would,
|
|
* reaches the case's entry control. The reply's wording is left to human
|
|
* review.
|
|
*/
|
|
export interface SecretSetupLinkProof {
|
|
commentId: string;
|
|
/** The rendered link's resolved target, as the person's click followed it. */
|
|
route: string;
|
|
linkText: string;
|
|
}
|
|
|
|
/**
|
|
* A rendered link target is supported only for this origin and company's
|
|
* secrets settings. `definitionId` admits one `definition` query naming it;
|
|
* without it no query is admitted.
|
|
*/
|
|
export function supportedSecretSettingsLink(href: string | null, origin: string, prefix: string, definitionId?: string): string | undefined {
|
|
try {
|
|
const url = new URL(href ?? "", origin);
|
|
const query = [...url.searchParams.keys()];
|
|
if (url.origin !== origin || url.username || url.password || url.hash) return;
|
|
if (url.pathname !== `/${prefix}/company/settings/secrets`) return;
|
|
if (query.some(key => key !== "definition" || !definitionId) || url.searchParams.getAll("definition").length > 1) return;
|
|
if (url.searchParams.has("definition") && url.searchParams.get("definition") !== definitionId) return;
|
|
return url.href;
|
|
} catch {
|
|
return;
|
|
}
|
|
}
|
|
|
|
export async function visibleInViewport(node: Locator, timeout: number): Promise<boolean> {
|
|
if (await node.count() !== 1 || !await node.isVisible()) return false;
|
|
await node.scrollIntoViewIfNeeded({ timeout });
|
|
return node.evaluate(element => {
|
|
const rect = element.getBoundingClientRect();
|
|
if (!element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) || rect.width <= 0 || rect.height <= 0
|
|
|| rect.bottom <= 0 || rect.top >= innerHeight || rect.right <= 0 || rect.left >= innerWidth) return false;
|
|
for (let parent = element.parentElement; parent; parent = parent.parentElement) {
|
|
const style = getComputedStyle(parent), box = parent.getBoundingClientRect();
|
|
if (/hidden|clip/.test(style.overflowX) && (rect.right <= box.left || rect.left >= box.right)) return false;
|
|
if (/hidden|clip/.test(style.overflowY) && (rect.bottom <= box.top || rect.top >= box.bottom)) return false;
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Find the visible supported link in the rendered reply, click it, and require
|
|
* the entry control that `entry` locates on the page the click reached.
|
|
* Returns to the conversation afterwards. Undefined when the reply has no such
|
|
* link or the click does not reach the entry.
|
|
*/
|
|
export async function followSecretSetupLink(page: Page, input: {
|
|
commentId: string; origin: string; prefix: string; timeout: number; definitionId?: string;
|
|
entry: (route: URL, remaining: () => number) => Promise<Locator>;
|
|
}): Promise<SecretSetupLinkProof | undefined> {
|
|
const deadline = Date.now() + input.timeout;
|
|
const remaining = () => {
|
|
const ms = deadline - Date.now();
|
|
if (ms <= 0) throw new Error("Secret setup reply link deadline exceeded");
|
|
return ms;
|
|
};
|
|
const comment = page.locator(`[id=${JSON.stringify(`comment-${input.commentId}`)}]`);
|
|
await comment.waitFor({ state: "visible", timeout: remaining() }).catch(() => undefined);
|
|
if (!await comment.isVisible()) return;
|
|
let chosen: { anchor: Locator; route: string; text: string } | undefined;
|
|
for (const anchor of await comment.locator("a[href]").all()) {
|
|
const route = supportedSecretSettingsLink(await anchor.getAttribute("href"), input.origin, input.prefix, input.definitionId);
|
|
if (route && await visibleInViewport(anchor, remaining())) { chosen = { anchor, route, text: (await anchor.innerText()).trim() }; break; }
|
|
}
|
|
if (!chosen) return;
|
|
const original = page.url();
|
|
try {
|
|
await chosen.anchor.click({ timeout: remaining() });
|
|
await page.waitForURL(url => url.origin === input.origin && url.pathname === new URL(chosen!.route).pathname, { timeout: remaining() });
|
|
const entry = await input.entry(new URL(chosen.route), remaining);
|
|
await entry.waitFor({ state: "visible", timeout: remaining() }).catch(() => undefined);
|
|
if (Date.now() >= deadline || !await visibleInViewport(entry, remaining())) return;
|
|
return { commentId: input.commentId, route: chosen.route, linkText: chosen.text };
|
|
} finally {
|
|
// Returning to the conversation has its own bound so a failed check still restores the page.
|
|
if (page.url() !== original) await page.goto(original, { waitUntil: "domcontentloaded", timeout: 15_000 });
|
|
}
|
|
}
|