diff --git a/tests/runner-e2e/chat-catalog-descriptors.json b/tests/runner-e2e/chat-catalog-descriptors.json
index 6c7ce6a361a..b9e2d68393b 100644
--- a/tests/runner-e2e/chat-catalog-descriptors.json
+++ b/tests/runner-e2e/chat-catalog-descriptors.json
@@ -4977,6 +4977,8 @@
"chat-catalog-domains/external-secret-question.ts",
"chat-catalog-domains/external-secret-route.ts",
"chat-catalog-domains/external-company-secret-menu.ts",
+ "chat-catalog-domains/external-company-secret-link.ts",
+ "chat-catalog-domains/external-secret-setup-link.ts",
"chat-catalog-contract.ts",
"chat-catalog-flow.ts",
"chat-catalog-domains/external-private-browser.ts",
@@ -5052,6 +5054,7 @@
"chat-catalog-domains/external-personal-secret.ts",
"chat-catalog-domains/external-personal-secret-menu.ts",
"chat-catalog-domains/external-personal-secret-link.ts",
+ "chat-catalog-domains/external-secret-setup-link.ts",
"../../ui/src/pages/secrets/MyUserSecretsTab.tsx",
"chat-catalog-domains/external-personal-secret-confirmation.ts",
"chat-catalog-contract.ts",
diff --git a/tests/runner-e2e/chat-catalog-domains/external-company-secret-link.test.ts b/tests/runner-e2e/chat-catalog-domains/external-company-secret-link.test.ts
new file mode 100644
index 00000000000..f49591f7aea
--- /dev/null
+++ b/tests/runner-e2e/chat-catalog-domains/external-company-secret-link.test.ts
@@ -0,0 +1,61 @@
+import { chromium } from "@playwright/test";
+import { expect, it } from "vitest";
+import { followCompanySecretReplyLink } from "./external-company-secret-link.js";
+import { companySecretSetupURL } from "./external-company-secret.js";
+import { supportedSecretSettingsLink } from "./external-secret-setup-link.js";
+
+const origin = "https://paperclip.example", chat = `${origin}/COM/chat`, secrets = "/COM/company/settings/secrets";
+
+it("accepts only this company's secrets settings, without a query, as a company link target", () => {
+ expect(supportedSecretSettingsLink(secrets, origin, "COM")).toBe(origin + secrets);
+ for (const href of [`${secrets}?definition=any`, "/OTHER/company/settings/secrets", `https://foreign.example${secrets}`, `${secrets}#new`, null]) {
+ expect(supportedSecretSettingsLink(href, origin, "COM"), String(href)).toBeUndefined();
+ }
+});
+
+// A setup reply whose settings link is followed by a colon, the shape the
+// markdown tokenizer could not read.
+const body = `Open [Secrets](${secrets}): choose **New secret**, save the deployment key there, then I will bind it to Morgan's environment. Do not paste the key in chat.`;
+const rendered = `
Open Secrets : choose New secret , save the deployment key there, then I will bind it to Morgan's environment. Do not paste the key in chat.
`;
+
+it.skipIf(process.env.PAPERCLIP_CHAT_EVAL_SECRET_ROUTE_CANARY !== "1")("grades the company setup link by clicking it to the New secret entry, not by the reply's wording", async () => {
+ const browser = await chromium.launch({ headless: true, ...process.env.PAPERCLIP_RUNNER_E2E_CHROMIUM_EXECUTABLE ? { executablePath: process.env.PAPERCLIP_RUNNER_E2E_CHROMIUM_EXECUTABLE } : {} });
+ const page = await browser.newPage();
+ const tabs = (selected: "secrets" | "mine") => `Secrets My secrets New secret
`;
+ const scenarios: Array<{ name: string; reply: string; accepted?: true; secretsPage?: string }> = [
+ { name: "link followed by a colon", reply: rendered, accepted: true },
+ { name: "company tab selected after the click", reply: rendered, accepted: true, secretsPage: tabs("mine") },
+ { name: "tabs rendered after navigation", reply: rendered, accepted: true,
+ secretsPage: `
${tabs("secrets")} ` },
+ { name: "no link, only wording", reply: "Open Settings → Secrets and choose New secret.
" },
+ { name: "plain-text path, not a link", reply: `Go to ${secrets}.
` },
+ { name: "wrong company link", reply: 'Open Secrets .
' },
+ { name: "foreign link", reply: `Open Secrets .
` },
+ { name: "link with a query", reply: `Open Secrets .
` },
+ { name: "hidden link", reply: `Setup:
Open Secrets .
` },
+ { name: "link reaches no secret entry", reply: rendered, secretsPage: 'Secrets Read only.
' },
+ ];
+ try {
+ for (const scenario of scenarios) {
+ await page.unroute("**/*");
+ await page.route("**/*", async route => {
+ const path = new URL(route.request().url()).pathname;
+ await route.fulfill({ contentType: "text/html; charset=utf-8", body: path === secrets
+ ? scenario.secretsPage ?? tabs("secrets")
+ : ` ` });
+ });
+ await page.goto(chat);
+ const proof = await followCompanySecretReplyLink(page, { commentId: "reply", origin, prefix: "COM", timeout: 3_000 });
+ if (scenario.accepted) expect(proof, scenario.name).toMatchObject({ commentId: "reply", route: origin + secrets, reachedSecretEntry: true });
+ else expect(proof, scenario.name).toBeUndefined();
+ expect(page.url(), scenario.name).toBe(chat);
+ }
+ // The replaced check could not read the same link: its tokenizer kept the trailing colon.
+ await page.unroute("**/*");
+ await page.route("**/*", route => route.fulfill({ contentType: "text/html; charset=utf-8", body: ` ` }));
+ await page.goto(chat);
+ expect(await companySecretSetupURL(page, { body, commentId: "reply" }, origin, "COM", 3_000)).toBeUndefined();
+ } finally {
+ await browser.close();
+ }
+}, 60_000);
diff --git a/tests/runner-e2e/chat-catalog-domains/external-company-secret-link.ts b/tests/runner-e2e/chat-catalog-domains/external-company-secret-link.ts
new file mode 100644
index 00000000000..05eb78e4f60
--- /dev/null
+++ b/tests/runner-e2e/chat-catalog-domains/external-company-secret-link.ts
@@ -0,0 +1,26 @@
+import type { Page } from "@playwright/test";
+import { followSecretSetupLink, type SecretSetupLinkProof } from "./external-secret-setup-link.js";
+
+/**
+ * Grade a company-secret setup reply by its rendered link, never by its
+ * wording: clicking it, as a person would, must reach the organization
+ * secret entry ("New secret" on the company Secrets tab).
+ */
+export interface CompanySecretReplyLinkProof extends SecretSetupLinkProof {
+ reachedSecretEntry: true;
+}
+
+export async function followCompanySecretReplyLink(page: Page, input: {
+ commentId: string; origin: string; prefix: string; timeout: number;
+}): Promise {
+ const proof = await followSecretSetupLink(page, {
+ ...input,
+ entry: async (_route, remaining) => {
+ const tab = page.getByRole("tab", { name: "Secrets", exact: true });
+ await tab.waitFor({ state: "visible", timeout: remaining() }).catch(() => undefined);
+ if (await tab.count() === 1 && await tab.getAttribute("aria-selected") !== "true") await tab.click({ timeout: remaining() });
+ return page.getByRole("button", { name: "New secret", exact: true }).first();
+ },
+ });
+ return proof && { ...proof, reachedSecretEntry: true };
+}
diff --git a/tests/runner-e2e/chat-catalog-domains/external-company-secret.test.ts b/tests/runner-e2e/chat-catalog-domains/external-company-secret.test.ts
index 824a945d0e6..4bf5b080d35 100644
--- a/tests/runner-e2e/chat-catalog-domains/external-company-secret.test.ts
+++ b/tests/runner-e2e/chat-catalog-domains/external-company-secret.test.ts
@@ -11,7 +11,7 @@ import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import { companySecretApprovalCandidate,companySecretApprovalProof,companyOperatorBindingRequested,companySecretQuestionHandoff,companySecretExternalCases,deploymentSecretGuidance,companySecretControllerBaseline,companySecretControllersUnchanged,companySecretFollowup } from "./external-company-secret.js";
const controller={id:"controller",companyId:"company",scope:"company",ownerUserId:null,userSecretDefinitionId:null,key:"openrouter_api_key",name:"Runner E2E controller",provider:"local_encrypted",status:"active",managedMode:"paperclip_managed",latestVersion:1};
const controllerRefs={OPENROUTER_API_KEY:{type:"secret_ref",secretId:"controller",version:"latest"}} as const;
-function valid(){return {scenarioId:"secrets.configure-company-secret",companyId:"company",leadId:"ceo",reply:"The deployment key reference is now bound for Morgan. This confirms configuration, not a runtime delivery test.",phaseReplies:[{runId:"first",body:"Use secure secret settings for the deployment key, then bind its reference in Morgan's environment variables. Do not paste the key here."},{runId:"second",body:"The deployment key reference is now bound for Morgan. This confirms configuration, not a runtime delivery test."}],runs:[{id:"first",status:"succeeded"},{id:"second",status:"succeeded"}],connections:[],profiles:[],secrets:[{id:"secret",name:"Deployment API key",status:"active"}],endpoints:[],interactions:[],activity:[{entityId:"secret",action:"secret.created",actorType:"user",actorId:"person"}],links:[],humanQueries:[],state:{morganConfigBefore:{env:{}},morganConfigAfter:{env:{DEPLOYMENT_API_KEY:{type:"secret_ref",secretId:"secret",version:"latest"}}},morganOtherConfigBefore:{adapterType:"paperclip_runner"},morganOtherConfigAfter:{adapterType:"paperclip_runner"},bindingEnvironmentName:"DEPLOYMENT_API_KEY",currentPersonId:"person",initialRunId:"first",agentCreateStatus:403,secretCountBeforeHuman:1,controllerSecretBaseline:[controller],controllerSecretsPreserved:true,operatorChannel:"private-browser-company-secret-and-public-browser-binding",secretUiVisible:true,humanSubmittedSecurely:true,storageClean:true,secureBrowserUntraced:true,secretId:"secret",morganId:"morgan",bindings:[{targetType:"agent",targetId:"morgan",configPath:"env.DEPLOYMENT_API_KEY",versionSelector:"latest"}],savedReferenceMatches:true,morganBindingVisible:true,bindingHumanAttributed:true,secretScanComplete:true,secretLeaked:false}};}
+function valid(){return {scenarioId:"secrets.configure-company-secret",companyId:"company",leadId:"ceo",reply:"The deployment key reference is now bound for Morgan. This confirms configuration, not a runtime delivery test.",phaseReplies:[{runId:"first",commentId:"first-reply",body:"Use secure secret settings for the deployment key, then bind its reference in Morgan's environment variables. Do not paste the key here."},{runId:"second",body:"The deployment key reference is now bound for Morgan. This confirms configuration, not a runtime delivery test."}],runs:[{id:"first",status:"succeeded"},{id:"second",status:"succeeded"}],connections:[],profiles:[],secrets:[{id:"secret",name:"Deployment API key",status:"active"}],endpoints:[],interactions:[],activity:[{entityId:"secret",action:"secret.created",actorType:"user",actorId:"person"}],links:[],humanQueries:[],state:{replyLinkProof:{commentId:"first-reply",route:"http://paperclip.test/COM/company/settings/secrets",linkText:"Secrets",reachedSecretEntry:true} as Record|undefined,morganConfigBefore:{env:{}},morganConfigAfter:{env:{DEPLOYMENT_API_KEY:{type:"secret_ref",secretId:"secret",version:"latest"}}},morganOtherConfigBefore:{adapterType:"paperclip_runner"},morganOtherConfigAfter:{adapterType:"paperclip_runner"},bindingEnvironmentName:"DEPLOYMENT_API_KEY",currentPersonId:"person",initialRunId:"first",agentCreateStatus:403,secretCountBeforeHuman:1,controllerSecretBaseline:[controller],controllerSecretsPreserved:true,operatorChannel:"private-browser-company-secret-and-public-browser-binding",secretUiVisible:true,humanSubmittedSecurely:true,storageClean:true,secureBrowserUntraced:true,secretId:"secret",morganId:"morgan",bindings:[{targetType:"agent",targetId:"morgan",configPath:"env.DEPLOYMENT_API_KEY",versionSelector:"latest"}],savedReferenceMatches:true,morganBindingVisible:true,bindingHumanAttributed:true,secretScanComplete:true,secretLeaked:false}};}
describe("secure company credential and Morgan-only binding",()=>{
const definition=companySecretExternalCases[0]!;
it("accepts actual human UI entry/reference binding and a separate metadata confirmation",()=>expect(definition.grade(valid()).passed).toBe(true));
@@ -32,6 +32,10 @@ describe("secure company credential and Morgan-only binding",()=>{
(o:ReturnType)=>{o.state.secretLeaked=true;},
(o:ReturnType)=>{o.phaseReplies[1]!.runId="first";},
(o:ReturnType)=>{o.phaseReplies[1]!.body="Morgan's deployment key is not yet bound or available.";},
+ // The setup reply is graded by its followed link, not its wording.
+ (o:ReturnType)=>{o.state.replyLinkProof=undefined;},
+ (o:ReturnType)=>{o.state.replyLinkProof={...o.state.replyLinkProof,commentId:"unrelated-reply"};},
+ (o:ReturnType)=>{o.state.replyLinkProof={...o.state.replyLinkProof,reachedSecretEntry:false};},
]){const o=valid();mutate(o);expect(definition.grade(o).passed).toBe(false);}
expect(definition.grade(undefined).passed).toBe(false);
});
@@ -236,7 +240,7 @@ it("requires native saved-name binding and exact metadata-only question accounti
function commentNativeOutcome(){
const o=valid(),body="Use secure Settings Secrets for the deployment key. Once saved I'll add its secret reference to Morgan's environment. Tell me the name/key you used (not the value).";
const followup="Saved as deployment_api_key. Please finish the requested Morgan setup.";
- return {...o,phaseReplies:[{runId:"first",body},{runId:"second",body:o.phaseReplies[1]!.body}],runs:[{id:"first",companyId:"company",agentId:"ceo",runtimeMode:"native",status:"succeeded",startedAt:"2026-11-04T13:00:00Z",finishedAt:"2026-11-04T13:30:00Z",contextSnapshot:{issueId:"source",commentId:"initial-human"}},{id:"second",companyId:"company",agentId:"ceo",runtimeMode:"native",status:"succeeded",startedAt:"2026-11-04T13:40:01Z",contextSnapshot:{issueId:"source",commentId:"followup-human"}}],secrets:[{...o.secrets[0],companyId:"company",scope:"company",key:"deployment_api_key",createdAt:"2026-11-04T13:35:00Z",createdByUserId:"person"}],activity:[...o.activity,{companyId:"company",entityId:"morgan",action:"agent.updated",actorType:"agent",actorId:"ceo",runId:"second",createdAt:"2026-11-04T13:41:00Z"}],state:{...o.state,sourceIssueId:"source",operatorChannel:"private-browser-company-secret-and-native-binding",morganConfigBefore:{env:{}},morganConfigAfter:{env:{DEPLOYMENT_API_KEY:{type:"secret_ref",secretId:"secret",version:"latest"}}},morganOtherConfigBefore:{adapterType:"paperclip_runner"},morganOtherConfigAfter:{adapterType:"paperclip_runner"},followupCommentId:"followup-human",followupCreatedAt:"2026-11-04T13:40:00Z",followupBody:followup,companySourceComments:[{id:"followup-human",companyId:"company",issueId:"source",authorUserId:"person",createdAt:"2026-11-04T13:40:00Z",body:followup}]}};
+ return {...o,phaseReplies:[{runId:"first",commentId:"first-reply",body},{runId:"second",body:o.phaseReplies[1]!.body}],runs:[{id:"first",companyId:"company",agentId:"ceo",runtimeMode:"native",status:"succeeded",startedAt:"2026-11-04T13:00:00Z",finishedAt:"2026-11-04T13:30:00Z",contextSnapshot:{issueId:"source",commentId:"initial-human"}},{id:"second",companyId:"company",agentId:"ceo",runtimeMode:"native",status:"succeeded",startedAt:"2026-11-04T13:40:01Z",contextSnapshot:{issueId:"source",commentId:"followup-human"}}],secrets:[{...o.secrets[0],companyId:"company",scope:"company",key:"deployment_api_key",createdAt:"2026-11-04T13:35:00Z",createdByUserId:"person"}],activity:[...o.activity,{companyId:"company",entityId:"morgan",action:"agent.updated",actorType:"agent",actorId:"ceo",runId:"second",createdAt:"2026-11-04T13:41:00Z"}],state:{...o.state,sourceIssueId:"source",operatorChannel:"private-browser-company-secret-and-native-binding",morganConfigBefore:{env:{}},morganConfigAfter:{env:{DEPLOYMENT_API_KEY:{type:"secret_ref",secretId:"secret",version:"latest"}}},morganOtherConfigBefore:{adapterType:"paperclip_runner"},morganOtherConfigAfter:{adapterType:"paperclip_runner"},followupCommentId:"followup-human",followupCreatedAt:"2026-11-04T13:40:00Z",followupBody:followup,companySourceComments:[{id:"followup-human",companyId:"company",issueId:"source",authorUserId:"person",createdAt:"2026-11-04T13:40:00Z",body:followup}]}};
}
it("binds native comment continuation to the actual metadata-only human followup and permits idempotent binding retries",()=>{
const o=commentNativeOutcome();expect(o.state.followupBody).toBe("Saved as deployment_api_key. Please finish the requested Morgan setup.");
diff --git a/tests/runner-e2e/chat-catalog-domains/external-company-secret.ts b/tests/runner-e2e/chat-catalog-domains/external-company-secret.ts
index d7a9291079a..a57ad9d817f 100644
--- a/tests/runner-e2e/chat-catalog-domains/external-company-secret.ts
+++ b/tests/runner-e2e/chat-catalog-domains/external-company-secret.ts
@@ -3,6 +3,7 @@ import { truthfulPendingProposal,truthfulProposalPhase } from "./external-secret
import { pollUntil } from "../api.js";
import {isDeepStrictEqual} from "node:util";
import {visibleSecretSettingsURL} from "./external-secret-route.js";
+import {followCompanySecretReplyLink,type CompanySecretReplyLinkProof} from "./external-company-secret-link.js";
import {companySecretMenuDirections,companySecretMenuURL} from "./external-company-secret-menu.js";
import { verifyChatCatalogHumanQuestionAnswer,chatCatalogCompanyEnvironmentNameQuestion, chatCatalogSavedSecretNameIntent, verifyChatCatalogCompanySecretBindingApproval, type ChatCatalogExpectedCompanySecretBindingApproval, chatCatalogNativePhaseRemainingBudget, chatCatalogOriginalPhaseDeadline } from "../chat-catalog-contract.js";
import { createHash, randomBytes } from "node:crypto";
@@ -169,7 +170,10 @@ export function gradeCompanySecret(value:unknown){
const savedMetadata=o.secrets.find(row=>row.id===o.state.secretId) as unknown as CompanySecret|undefined;
const questionAnswered=!!question&&Number.isFinite(answeredAt)&&Number.isFinite(createdAt)&&createdAt<=answeredAt
&&(!nativeBindingRequired&&o.activity.some(row=>row.entityId===o.state.morganId&&row.actorType==="user"&&/agent\.(?:updated|config_updated)/.test(row.action??"")&&Number.isFinite(Date.parse(String(row.createdAt)))&&Date.parse(String(row.createdAt))<=answeredAt)||nativeBindingRequired&&savedMetadata?.companyId===o.companyId&&savedMetadata.scope==="company"&&savedMetadata.createdByUserId===o.state.currentPersonId)&&(!question.savedSecretName||Number.isFinite(questionCreatedAt)&&createdAt>questionCreatedAt)&&question.payloadHash===o.state.initialQuestionPayloadHash&&question.optionId===o.state.initialQuestionOptionId&&question.savedSecretName===o.state.initialQuestionSavedSecretName&&question.environmentName===o.state.initialQuestionEnvironmentName&&(!(question.environmentName||question.savedSecretName)||(question.questionId===o.state.initialQuestionFieldId&&o.state.questionResponseVerified===true))&&o.state.questionAnsweredThroughUi===true;
- c.add("honest-secure-human-handoff",((!!initial&&deploymentSecretGuidance(initial.body))||questionAnswered||!!confirmation)&&o.state.agentCreateStatus===403&&Array.isArray(o.state.controllerSecretBaseline)&&o.state.controllerSecretBaseline.length>0&&o.state.secretCountBeforeHuman===o.state.controllerSecretBaseline.length&&o.state.controllerSecretsPreserved===true,"The exact controller-bootstrap secrets remain unchanged; the initial actual reply directs secure deployment-key entry and Morgan-only reference binding while an ordinary agent cannot create the value.");
+ // The reply is graded by its rendered link: clicking it reached the organization secret entry.
+ const replyLink=o.state.replyLinkProof as CompanySecretReplyLinkProof|undefined;
+ const replyLinkReached=replyLink?.reachedSecretEntry===true&&o.phaseReplies.some(row=>row.runId===o.state.initialRunId&&row.commentId===replyLink.commentId);
+ c.add("honest-secure-human-handoff",(replyLinkReached||questionAnswered||!!confirmation)&&o.state.agentCreateStatus===403&&Array.isArray(o.state.controllerSecretBaseline)&&o.state.controllerSecretBaseline.length>0&&o.state.secretCountBeforeHuman===o.state.controllerSecretBaseline.length&&o.state.controllerSecretsPreserved===true,"The exact controller-bootstrap secrets remain unchanged; the initial actual reply directs secure deployment-key entry and Morgan-only reference binding while an ordinary agent cannot create the value.");
c.add("actual-private-ui-creation",o.state.operatorChannel===(nativeBindingRequired?"private-browser-company-secret-and-native-binding":"private-browser-company-secret-and-public-browser-binding")&&o.state.secretUiVisible===true&&o.state.humanSubmittedSecurely===true&&o.state.storageClean===true&&o.state.secureBrowserUntraced===true,"The signed-in person uses the real secret form in the finite noninstrumented browser and no value survives in browser drafts or visible UI.");
const bindings=o.state.bindings as CompanySecretUsageBinding[]|undefined;
const approval=companySecretApprovalProof(value);
@@ -216,7 +220,7 @@ export const companySecretExternalCases=[definition("secrets.configure-company-s
optionalCompanySecretBindingApproval:true,
expectedCompanySecretBindingApproval(value){if(!gradeCompanySecret(value).passed)return;return companySecretApprovalProof(value);},
oracleVersion:"paperclip.chat-catalog.company-secret-controller-baseline.v22",expectedRunCount:3,minimumRunCount:2,expectedHumanMessageCount:2,attemptTimeoutMs:480000,
- sourceFiles:["../../server/src/routes/secrets.ts","../../packages/paperclip-runner/src/cli/opencode-app-server-proxy.ts","../../packages/paperclip-runner/src/cli/opencode-proxy-finish-diagnostics.ts","../../packages/paperclip-runner/src/protocol-actions/request-human-input.ts","chat-catalog-domains/external-company-secret.ts","chat-catalog-domains/external-company-secret-confirmation.ts","chat-catalog-domains/external-secret-proposal.ts","chat-catalog-domains/external-secret-question.ts","chat-catalog-domains/external-secret-route.ts","chat-catalog-domains/external-company-secret-menu.ts","chat-catalog-contract.ts","chat-catalog-flow.ts","chat-catalog-domains/external-private-browser.ts","chat-catalog-domains/external-private-browser-worker.ts","chat-catalog-domains/external-credential-language.ts","chat-catalog-domains/external-secret-scan.ts","chat-catalog-domains/external-support.ts","chat-catalog-domains/internal-support.ts","chat-catalog-domains/identity-support.ts","live-fixtures.ts","../../server/src/services/secrets.ts","../../server/src/services/native-runtime/runner-api-catalog.ts","../../server/src/routes/issues.ts","run-observations.ts","chat-flow.ts","chat-scenarios/secrets.yaml"],
+ sourceFiles:["../../server/src/routes/secrets.ts","../../packages/paperclip-runner/src/cli/opencode-app-server-proxy.ts","../../packages/paperclip-runner/src/cli/opencode-proxy-finish-diagnostics.ts","../../packages/paperclip-runner/src/protocol-actions/request-human-input.ts","chat-catalog-domains/external-company-secret.ts","chat-catalog-domains/external-company-secret-confirmation.ts","chat-catalog-domains/external-secret-proposal.ts","chat-catalog-domains/external-secret-question.ts","chat-catalog-domains/external-secret-route.ts","chat-catalog-domains/external-company-secret-menu.ts","chat-catalog-domains/external-company-secret-link.ts","chat-catalog-domains/external-secret-setup-link.ts","chat-catalog-contract.ts","chat-catalog-flow.ts","chat-catalog-domains/external-private-browser.ts","chat-catalog-domains/external-private-browser-worker.ts","chat-catalog-domains/external-credential-language.ts","chat-catalog-domains/external-secret-scan.ts","chat-catalog-domains/external-support.ts","chat-catalog-domains/internal-support.ts","chat-catalog-domains/identity-support.ts","live-fixtures.ts","../../server/src/services/secrets.ts","../../server/src/services/native-runtime/runner-api-catalog.ts","../../server/src/routes/issues.ts","run-observations.ts","chat-flow.ts","chat-scenarios/secrets.yaml"],
async act(ctx,state){
const deadline=chatCatalogOriginalPhaseDeadline(ctx),remaining=()=>remainingIdentityObservationBudget(ctx);
await waitForReply(ctx,deadline);remaining();
@@ -230,7 +234,7 @@ export const companySecretExternalCases=[definition("secrets.configure-company-s
const pending=initial.interactions.filter(row=>row.status==="pending"&&(row as Partial).sourceRunId===run.id);
const question=pending.length===1?companySecretQuestionHandoff(pending[0],binding):undefined;
const confirmationBinding={...binding,canonicalCommentId:canonical[0]!.id},confirmation=pending.length===1?companySecretConfirmationHandoff(pending[0],confirmationBinding,text=>deploymentSecretGuidance(text)&&!companyOperatorBindingRequested(text)):undefined;
- const commentHandoff=!!reply&&reply.runId===run.id&&deploymentSecretGuidance(reply.body)&&comments.some(c=>c.id===reply.commentId&&c.companyId===source.companyId&&c.issueId===source.id&&c.authorAgentId===run.agentId&&c.createdByRunId===run.id&&c.body?.trim()===reply.body.trim());
+ const commentHandoff=!!reply&&reply.runId===run.id&&comments.some(c=>c.id===reply.commentId&&c.companyId===source.companyId&&c.issueId===source.id&&c.authorAgentId===run.agentId&&c.createdByRunId===run.id&&c.body?.trim()===reply.body.trim());
if(initial.companyId!==source.companyId||(pending.length?(!question&&!confirmation):!commentHandoff))throw new Error("Actual reply must direct secure deployment-key entry and Morgan-only reference binding before human action");
state.initialRunId=run.id;state.sourceIssueId=source.id;
state.nativeBindingRequired=confirmation?true:question?question.savedSecretName===true||!question.operatorBinding:!companyOperatorBindingRequested(reply!.body);
@@ -240,9 +244,13 @@ export const companySecretExternalCases=[definition("secrets.configure-company-s
const beforeHuman=await ctx.input.api.get(`${root(ctx)}/secrets`);
state.secretCountBeforeHuman=beforeHuman.length;if(!Array.isArray(state.controllerSecretBaseline)||beforeHuman.length!==state.controllerSecretBaseline.length||!companySecretControllersUnchanged(beforeHuman,state.controllerSecretBaseline))throw new Error("Secret catalog changed before authorized human entry");
const prefix=ctx.input.fixtures.company.issuePrefix;if(!prefix)throw new Error("Company secret setup requires the current company route prefix");
- const path=`/${prefix}/company/settings/secrets`,href=commentHandoff?await companySecretSetupURL(ctx.input.page,reply!,initial.origin,prefix,remaining()):confirmation?await visibleCompanySecretConfirmationURL(ctx.input.page,confirmation,initial.origin,prefix,remaining):undefined;
+ // The reply is graded by its rendered link, followed as a person would; wording is left to human review.
+ // A question or confirmation card already carries the handoff, so a reply link is then optional.
+ const replyLink=!question&&!confirmation&&commentHandoff&&reply?.commentId?await followCompanySecretReplyLink(ctx.input.page,{commentId:reply.commentId,origin:initial.origin,prefix,timeout:remaining()}):undefined;
+ if(replyLink){state.replyLinkProof=replyLink;await ctx.input.evidence("company-secret-reply-link.json",replyLink);}
+ const path=`/${prefix}/company/settings/secrets`,href=replyLink?replyLink.route:confirmation?await visibleCompanySecretConfirmationURL(ctx.input.page,confirmation,initial.origin,prefix,remaining):undefined;
if(confirmation)state.confirmationVisibleBeforeEntry=true;
- if(!href&&!question)throw new Error("Actual visible reply must direct the supported company secret management surface");
+ if(!href&&!question)throw new Error("Actual reply must link to the organization secret entry");
const receipt=await privateBrowserEntry({mode:"company-secret-create",companyId:ctx.input.fixtures.company.id,baseURL:initial.origin,setupURL:new URL(href??path,initial.origin).href,providerURL:"",credential:values.get(ctx)!,companyMetadata:confirmation?.metadata,cookies:await ctx.input.page.context().cookies(initial.origin)});
Object.assign(state,receipt,{secureBrowserUntraced:receipt.processIsolation&&receipt.testRunnerAttached===false&&receipt.apiStepRecorder===false&&receipt.tracingEnabled===false&&receipt.videoEnabled===false,operatorChannel:state.nativeBindingRequired?"private-browser-company-secret-and-native-binding":"private-browser-company-secret-and-public-browser-binding"});
if(!state.nativeBindingRequired){
diff --git a/tests/runner-e2e/chat-catalog-domains/external-personal-secret-link.ts b/tests/runner-e2e/chat-catalog-domains/external-personal-secret-link.ts
index aee336db2ac..bf10964a0d8 100644
--- a/tests/runner-e2e/chat-catalog-domains/external-personal-secret-link.ts
+++ b/tests/runner-e2e/chat-catalog-domains/external-personal-secret-link.ts
@@ -1,11 +1,10 @@
import type { Locator, Page } from "@playwright/test";
+import { followSecretSetupLink, supportedSecretSettingsLink as supportedLink } from "./external-secret-setup-link.js";
/**
* Grade a personal-secret setup reply by its rendered link, never by its
- * wording. The 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 current person's own-value entry for the required definition.
- * The reply's wording is left to human review.
+ * wording: clicking it, as a person would, must reach the current person's
+ * own-value entry for the required definition.
*/
export interface PersonalSecretReplyLinkProof {
commentId: string;
@@ -18,82 +17,32 @@ export interface PersonalSecretReplyLinkProof {
/** A rendered link target is supported only for this origin and company's secrets settings. */
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") || url.searchParams.getAll("definition").length > 1) return;
- if (url.searchParams.has("definition") && url.searchParams.get("definition") !== definitionId) return;
- return url.href;
- } catch {
- return;
- }
-}
-
-async function visible(node: Locator, timeout: number): Promise {
- 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;
- });
+ return supportedLink(href, origin, prefix, definitionId);
}
/**
- * Find the visible supported link in the rendered reply, click it, and prove
- * the click reached the own-value entry ("Set value" on the definition's row in
- * My secrets). Returns to the conversation afterwards. Undefined when the reply
- * has no such link or the click does not reach the entry.
+ * The own-value entry is "Set my value" in the detail sheet a definition link
+ * opens, or "Set value" on the definition's row in My secrets.
*/
export async function followPersonalSecretReplyLink(page: Page, input: {
commentId: string; origin: string; prefix: string; definitionId: string; definitionKey: string; timeout: number;
}): Promise {
- const deadline = Date.now() + input.timeout;
- const remaining = () => {
- const ms = deadline - Date.now();
- if (ms <= 0) throw new Error("Personal secret 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 visible(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() });
- let entry: Locator;
- if (new URL(chosen.route).searchParams.get("definition") === input.definitionId) {
- // A link naming the definition opens its detail sheet, whose own-value action is "Set my value".
- const sheet = page.locator('[data-testid="secret-details"]').filter({ has: page.getByText(input.definitionKey, { exact: true }) });
- entry = sheet.getByRole("button", { name: "Set my value", exact: true });
- } else {
+ const proof = await followSecretSetupLink(page, {
+ commentId: input.commentId, origin: input.origin, prefix: input.prefix, timeout: input.timeout, definitionId: input.definitionId,
+ entry: async (route, remaining): Promise => {
+ if (route.searchParams.get("definition") === input.definitionId) {
+ // A link naming the definition opens its detail sheet, whose own-value action is "Set my value".
+ const sheet = page.locator('[data-testid="secret-details"]').filter({ has: page.getByText(input.definitionKey, { exact: true }) });
+ return sheet.getByRole("button", { name: "Set my value", exact: true });
+ }
const tab = page.getByRole("tab", { name: "My secrets", exact: true });
await tab.waitFor({ state: "visible", timeout: remaining() }).catch(() => undefined);
if (await tab.count() === 1 && await tab.getAttribute("aria-selected") !== "true") await tab.click({ timeout: remaining() });
// The row is bound to the required definition by its identity, and shows its key.
const row = page.locator(`[data-testid=${JSON.stringify(`my-secret-${input.definitionId}`)}]`)
.filter({ has: page.getByText(input.definitionKey, { exact: true }) });
- entry = row.getByRole("button", { name: "Set value", exact: true });
- }
- await entry.waitFor({ state: "visible", timeout: remaining() }).catch(() => undefined);
- if (Date.now() >= deadline || !await visible(entry, remaining())) return;
- return { commentId: input.commentId, route: chosen.route, linkText: chosen.text, reachedOwnValueEntry: true, definitionKey: input.definitionKey };
- } 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 });
- }
+ return row.getByRole("button", { name: "Set value", exact: true });
+ },
+ });
+ return proof && { ...proof, reachedOwnValueEntry: true, definitionKey: input.definitionKey };
}
diff --git a/tests/runner-e2e/chat-catalog-domains/external-personal-secret.ts b/tests/runner-e2e/chat-catalog-domains/external-personal-secret.ts
index 99fd5bad0d0..8524af01f1a 100644
--- a/tests/runner-e2e/chat-catalog-domains/external-personal-secret.ts
+++ b/tests/runner-e2e/chat-catalog-domains/external-personal-secret.ts
@@ -503,6 +503,7 @@ export const personalSecretExternalCases = [
"chat-catalog-domains/external-personal-secret.ts",
"chat-catalog-domains/external-personal-secret-menu.ts",
"chat-catalog-domains/external-personal-secret-link.ts",
+ "chat-catalog-domains/external-secret-setup-link.ts",
"../../ui/src/pages/secrets/MyUserSecretsTab.tsx",
"chat-catalog-domains/external-personal-secret-confirmation.ts",
"chat-catalog-contract.ts",
diff --git a/tests/runner-e2e/chat-catalog-domains/external-secret-setup-link.ts b/tests/runner-e2e/chat-catalog-domains/external-secret-setup-link.ts
new file mode 100644
index 00000000000..38d50d0ae79
--- /dev/null
+++ b/tests/runner-e2e/chat-catalog-domains/external-secret-setup-link.ts
@@ -0,0 +1,89 @@
+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 {
+ 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;
+}): Promise {
+ 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 });
+ }
+}