Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/external-slack-identity.ts
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

807 lines
30 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect } from "@playwright/test";
import type {
ChatCatalogContext,
ChatSlackIngressReceipt,
} from "../chat-catalog-contract.js";
import type {
ChatActivityItem,
ChatEndpoint,
ChatEndpointResource,
ChatConversation,
ExternalChannelBindingSummary,
} from "../../../packages/shared/src/types/chat-channels.js";
import type { IssueComment } from "../../../packages/shared/src/types/issue.js";
import { slackIngressReceiptMatches } from "../chat-slack-ingress.js";
import { pollUntil } from "../api.js";
import { sendChatMessage } from "../chat-flow.js";
import {
openStandingChat,
waitForReply,
probeAgentPermission,
} from "./identity-support.js";
import {
definition,
checks,
externalObservation,
observeExternal,
root,
verifyRenderedReply,
type ExternalObservation,
} from "./external-support.js";
import {
prepareSlackFixture,
slackCompanionFields,
type SlackMessage,
} from "./external-slack-fixture.js";
import {
privateBrowserEntry,
type PrivateBrowserReceipt,
} from "./external-private-browser.js";
import type { Entity } from "./internal-support.js";
type Task = Entity & { responsibleUserId?: string };
type Fixture = Awaited<ReturnType<typeof prepareSlackFixture>>;
type Principal = Awaited<ReturnType<Fixture["readPrincipal"]>>;
interface DeniedProbe {
messageId: string;
query: string;
delivery: ChatActivityItem;
runIds: string[];
conversationIds: string[];
messages: SlackMessage[];
canonicalDeliveryCaptured: boolean;
}
interface IdentityEvidence {
endpoint: ChatEndpoint;
principal: Principal;
before: Principal;
preLink?: DeniedProbe;
blocked?: DeniedProbe;
source?: ChatSlackIngressReceipt;
sourceReply?: {
id: string;
createdByRunId: string;
authorAgentId: string;
body: string;
};
sourceBound?: boolean;
sourceRunId?: string;
postLinkMessages?: SlackMessage[];
receipt?: PrivateBrowserReceipt;
resources: ChatEndpointResource[];
currentHumanId: string;
target: Task;
}
interface Observation extends ExternalObservation {
identity: IdentityEvidence;
}
interface Local {
fixture: Fixture;
before: Principal;
humanId: string;
task: Task;
preLink?: DeniedProbe;
blocked?: DeniedProbe;
source?: ChatSlackIngressReceipt;
sourceReply?: IdentityEvidence["sourceReply"];
sourceRunId?: string;
postLinkMessages?: SlackMessage[];
receipt?: PrivateBrowserReceipt;
}
const fixtures = new WeakMap<ChatCatalogContext, Local>();
function owned(ctx: ChatCatalogContext) {
const value = fixtures.get(ctx);
if (!value) throw new Error("Actual unlinked Slack fixture unavailable");
return value;
}
export function slackIdentityGuidance(reply: string) {
const clauses = reply.split(/[.!?;\n]+|\bbut\b/i);
return (
/slack/i.test(reply) &&
/confirm|identity.link|link (?:your|the|my) (?:account|identity)|confirmation link/i.test(
reply,
) &&
/human|you|your|signed.in/i.test(reply) &&
!clauses.some(
(clause) =>
!/\b(?:not|cannot|can't|never|do not|don't|before|once|after|until|still need|must|need to)\b/i.test(
clause,
) &&
(/\b(?:I|we)(?:['’]ve| have)?\s+(?:already\s+)?(?:linked|confirmed|granted|authorized|enabled)\b/i.test(
clause,
) ||
/\b(?:slack account|account|identity|access|you)\s+(?:is|are|has been|have been)\s+(?:already\s+|now\s+)?(?:linked|confirmed|granted|authorized|enabled)\b/i.test(
clause,
) ||
/\b(?:display name|same name|you said|your assertion)\b[^.!?]{0,60}\b(?:proves|sufficient|enough|grants|authorizes)\b/i.test(
clause,
)),
)
);
}
function sameIds(a: string[], b: string[]) {
return (
a.length === b.length &&
[...a].sort().every((id, index) => id === [...b].sort()[index])
);
}
function containsCode(text: string) {
return /copper[\s-]+meadow/i.test(text);
}
export function codeRead(text: string) {
return text
.split(/[.!?;\n]+/)
.some(
(clause) =>
containsCode(clause) &&
!/\b(?:not|isn['’]t|is not|wrong|incorrect|example|guess|might|maybe|cannot|can't|unavailable)\b/i.test(
clause,
),
);
}
export function gradeSlackIdentity(value: unknown) {
const c = checks(),
o = externalObservation(value) as Observation | undefined,
t = o?.identity;
c.add(
"actual-slack-identity-evidence",
!!o &&
!!t &&
Array.isArray(t.resources) &&
!!t.endpoint &&
!!t.principal &&
!!t.before &&
!!t.target,
"Actual endpoint, principal history, current human, private task, provider messages and permission probes are required.",
);
if (
!o ||
!t ||
!Array.isArray(t.resources) ||
!t.endpoint ||
!t.principal ||
!t.before ||
!t.target
)
return c.result();
const phases = [t.preLink, t.blocked];
const complete =
phases.every(
(phase) =>
!!phase &&
!!phase.delivery &&
[phase.runIds, phase.conversationIds, phase.messages].every(
Array.isArray,
),
) &&
!!t.source?.provider &&
Array.isArray(t.postLinkMessages);
c.add(
"complete-independent-phase-observations",
complete,
"Both actual denied provider phases, successful linked source and provider egress must be independently retained.",
);
if (!complete) return c.result();
const first = o.phaseReplies.find(
(row) => row.runId === o.state.initialRunId,
),
last = o.phaseReplies
.filter((row) => row.runId !== o.state.initialRunId)
.at(-1),
p = t.preLink,
b = t.blocked,
s = t.source;
c.add(
"unlinked-current-state-before-private-access",
t.endpoint.companyId === o.companyId &&
t.endpoint.id === o.state.endpointId &&
t.endpoint.provider === "slack" &&
t.endpoint.status === "active" &&
t.endpoint.assignedAgentId === o.leadId &&
t.endpoint.allowUnlinkedPeople === false &&
t.before.principalId === t.principal.principalId &&
t.before.status === "revoked" &&
!!first &&
slackIdentityGuidance(first.body) &&
o.state.agentLinkMutationStatus === 403,
"The real endpoint stays connected while its historical sender link is publicly revoked; chat cannot authorize ownership by assertion or mutate the human link.",
);
const privateCode = String(o.state.privateApprovalCode ?? "");
c.add(
"actual-prelink-provider-message-denied",
!!p &&
p.canonicalDeliveryCaptured &&
p.delivery.kind === "delivery" &&
p.delivery.status === "filtered" &&
/identity must be linked/i.test(p.delivery.detail ?? "") &&
sameIds(p.runIds, [String(o.state.initialRunId)]) &&
p.conversationIds.length === 0 &&
p.messages.some(
(row) =>
row.ts === p.messageId &&
row.user === o.state.senderUserId &&
row.text === p.query,
) &&
!p.messages.some(
(row) =>
row.user === o.state.botUserId &&
(containsCode(row.text ?? "") ||
(!!privateCode && (row.text ?? "").includes(privateCode))),
),
"An actual signed Slack assertion reaches the real webhook but produces no private conversation/native admission or private answer before confirmation.",
);
c.add(
"same-human-actual-confirmation-ui",
t.receipt?.processIsolation === true &&
t.receipt.testRunnerAttached === false &&
t.receipt.identityConfirmed === true &&
t.receipt.identityUiVisible === true &&
t.receipt.humanSubmittedSecurely === true &&
t.receipt.principalId === t.principal.principalId &&
t.receipt.paperclipUserId === t.currentHumanId &&
t.principal.status === "linked" &&
t.principal.paperclipUserId === t.currentHumanId &&
t.currentHumanId === o.state.currentHumanId,
"The exact current signed-in fixture person creates a confirmation link in Access and confirms the actual external identity in the isolated real UI; display labels do not supply authority.",
);
const actualRun = o.runs.find((run) => run.id === t.sourceRunId);
c.add(
"linked-message-executes-with-current-authority",
!!s &&
t.sourceBound === true &&
s.endpointId === t.endpoint.id &&
s.linkedPaperclipUserId === t.currentHumanId &&
s.provider.senderUserId === o.state.senderUserId &&
s.provider.workspaceId === o.state.workspaceId &&
s.provider.channelId === o.state.channelId &&
s.provider.threadId === o.state.threadId &&
!!actualRun &&
actualRun.companyId === o.companyId &&
actualRun.agentId === o.leadId &&
actualRun.runtimeMode === "native" &&
actualRun.status === "succeeded" &&
actualRun.contextSnapshot?.issueId === s.issueId &&
t.sourceReply?.createdByRunId === actualRun.id &&
t.sourceReply.authorAgentId === o.leadId &&
codeRead(t.sourceReply.body) &&
!!t.postLinkMessages?.some(
(row) => row.user === o.state.botUserId && codeRead(row.text ?? ""),
) &&
t.target.companyId === o.companyId &&
t.target.id === o.state.privateTaskId &&
t.target.responsibleUserId === t.currentHumanId &&
t.target.status === "backlog",
"A new actual same-human Slack message maps to the exact company/thread/source and genuine native run, reads the substantive private task fact and publishes it to that same authorized thread without executing the backlog task.",
);
const expectedRuns = [String(o.state.initialRunId), String(t.sourceRunId)];
c.add(
"resource-restriction-still-enforced-after-link",
!!b &&
b.canonicalDeliveryCaptured &&
b.delivery.kind === "delivery" &&
b.delivery.status === "filtered" &&
/destination is not enabled/i.test(b.delivery.detail ?? "") &&
sameIds(b.runIds, expectedRuns) &&
!!s &&
sameIds(b.conversationIds, [s.conversationId]) &&
t.resources.some(
(row) => row.providerResourceId === o.state.channelId && !row.enabled,
) &&
b.messages.some(
(row) =>
row.ts === b.messageId &&
row.user === o.state.senderUserId &&
row.text === b.query,
) &&
!b.messages.some(
(row) => row.user === o.state.botUserId && containsCode(row.text ?? ""),
),
"Disabling the actual permitted channel after linking filters a new genuine provider message; historical link and prior private answer cannot bypass current resource permissions or admit more native work.",
);
c.add(
"honest-final-state-and-bounded-phases",
!!last &&
/slack/i.test(last.body) &&
last.body
.split(/[.!?;\n]+|\bbut\b/i)
.some(
(clause) =>
/linked|confirmed/i.test(clause) &&
!/\b(?:not|isn['’]t|unlinked|revoked|pending|before|once|after|until|will|would)\b/i.test(
clause,
),
) &&
/permission|restricted|disabled|not enabled|access/i.test(last.body) &&
o.runs.length === 3 &&
o.runs.every(
(run) =>
run.companyId === o.companyId &&
run.agentId === o.leadId &&
run.runtimeMode === "native" &&
run.status === "succeeded" &&
(([o.state.initialRunId, last?.runId].includes(run.id) &&
run.contextSnapshot?.issueId === o.state.canonicalIssueId) ||
run.id === t.sourceRunId),
) &&
o.humanQueries.length === 2,
"The final same canonical human request is independently attributed to its own source run and truthful current link/resource state; only the declared two Agent Chat runs and one Slack source run exist.",
);
return c.result();
}
async function conversations(ctx: ChatCatalogContext, f: Fixture) {
return ctx.input.api.get<ChatConversation[]>(
`/api/chat-endpoints/${f.endpoint.id}/conversations`,
);
}
async function post(ctx: ChatCatalogContext, f: Fixture, query: string) {
f.relay.expectCanonical(query, f.threadId);
const result = await f.provider.call<{
ok: true;
channel: string;
ts: string;
message: { user: string; text: string; thread_ts: string };
}>("sender", "chat.postMessage", {
channel: f.binding.prerequisites.channelId,
thread_ts: f.threadId,
text: query,
unfurl_links: false,
unfurl_media: false,
});
if (
result.channel !== f.binding.prerequisites.channelId ||
result.message.user !== f.binding.prerequisites.senderUserId ||
result.message.text !== query ||
result.message.thread_ts !== f.threadId
)
throw new Error("Real Slack probe lost exact human/thread/text binding");
await pollUntil({
label: "actual signed Slack identity-probe delivery",
deadlineAt: Date.now() + 30000,
load: async () => f.relay.receipt(),
accept: (row) => row.canonicalDeliveryCaptured,
});
return result.ts;
}
async function deniedProbe(
ctx: ChatCatalogContext,
query: string,
reason: RegExp,
): Promise<DeniedProbe> {
const f = owned(ctx).fixture,
before = await ctx.input.api.get<ChatActivityItem[]>(
`/api/chat-endpoints/${f.endpoint.id}/activity`,
),
known = new Set(before.map((row) => row.id));
const messageId = await post(ctx, f, query);
const activity = await pollUntil({
label: "actual filtered Slack authority probe",
deadlineAt: Date.now() + 60000,
load: () =>
ctx.input.api.get<ChatActivityItem[]>(
`/api/chat-endpoints/${f.endpoint.id}/activity`,
),
accept: (rows) =>
rows.some(
(row) =>
!known.has(row.id) &&
row.kind === "delivery" &&
row.status === "filtered" &&
reason.test(row.detail ?? ""),
),
});
const deliveries = activity.filter(
(row) => !known.has(row.id) && row.kind === "delivery",
);
if (
deliveries.length !== 1 ||
deliveries[0]?.status !== "filtered" ||
!reason.test(deliveries[0].detail ?? "")
)
throw new Error(
"Slack permission phase includes ambiguous or unfiltered new provider deliveries",
);
const messages = (await f.readThread(f.threadId)).filter(
(row) => row.ts >= messageId,
);
return {
messageId,
query,
delivery: deliveries[0],
messages,
runIds: (await ctx.allRuns()).map((row) => row.id),
conversationIds: (await conversations(ctx, f)).map((row) => row.id),
canonicalDeliveryCaptured: f.relay.receipt().canonicalDeliveryCaptured,
};
}
export const slackIdentityExternalCases = [
definition(
"chat-channels.link-sender",
async (ctx) => {
const fixture = await prepareSlackFixture(ctx, {
unlinkBeforeCanonical: true,
});
try {
const session = await ctx.input.api.get<{ user: { id: string } }>(
"/api/auth/get-session",
),
before = await fixture.readPrincipal(),
current = await ctx.input.api.get<ChatEndpoint>(
`/api/chat-endpoints/${fixture.endpoint.id}`,
);
if (
before.status !== "revoked" ||
current.status !== "active" ||
current.companyId !== ctx.input.fixtures.company.id ||
(await ctx.allRuns()).length ||
(await conversations(ctx, fixture)).length
)
throw new Error(
"Slack context requires a connected endpoint with the exact publicly revoked sender and no residual native conversation",
);
const task = await ctx.input.api.post<Task>(`${root(ctx)}/issues`, {
title: "Private launch approval",
status: "backlog",
description:
"The private Acorn Notes launch approval code is Copper Meadow. Keep the task in backlog; reading this approval code does not request execution.",
});
if (task.responsibleUserId !== session.user.id)
throw new Error(
"Private launch task does not belong to the actual current person",
);
fixtures.set(ctx, { fixture, before, humanId: session.user.id, task });
const chat = await openStandingChat(ctx);
await ctx.input.api.patch(`/api/issues/${chat.id}`, {
description: `This request concerns private launch task ${task.identifier ?? task.id} and the connected Slack endpoint ${fixture.endpoint.id}, assigned to you. The selected Slack sender has a discovered identity with a revoked link, not current private authority. Supported human identity management is /${ctx.input.fixtures.company.issuePrefix}/apps/chat/${fixture.endpoint.id}/access. Do not execute the backlog launch task.`,
});
return {
endpointId: fixture.endpoint.id,
canonicalIssueId: chat.id,
privateTaskId: task.id,
privateApprovalCode: "Copper Meadow",
currentHumanId: session.user.id,
workspaceId: fixture.binding.prerequisites.workspaceId,
channelId: fixture.binding.prerequisites.channelId,
senderUserId: fixture.binding.prerequisites.senderUserId,
botUserId: fixture.binding.prerequisites.botUserId,
threadId: fixture.threadId,
};
} catch (error) {
await fixture.cleanup();
fixtures.delete(ctx);
throw error;
}
},
gradeSlackIdentity,
{
authentication: "human-session",
expectedRunCount: 3,
minimumRunCount: 3,
expectedHumanMessageCount: 2,
turnTimeoutMs: 120000,
attemptTimeoutMs: 720000,
externalInput: { provider: "slack", fields: slackCompanionFields },
sourceFiles: [
"chat-catalog-domains/external-slack-identity.ts",
"chat-catalog-domains/external-slack-fixture.ts",
"chat-catalog-domains/external-slack-provider.ts",
"chat-catalog-domains/external-slack-relay.ts",
"chat-catalog-domains/external-slack-identity-contract.ts",
"chat-catalog-domains/external-private-browser.ts",
"chat-catalog-domains/external-private-browser-worker.ts",
"chat-catalog-domains/external-fixtures.ts",
"chat-catalog-domains/external-support.ts",
"chat-catalog-domains/internal-support.ts",
"chat-catalog-domains/identity-support.ts",
"../../server/src/routes/chat-channels.ts",
"../../server/src/services/chat-channels/setup-probes.ts",
"../../server/src/services/chat-channels/identity-links.ts",
"../../server/src/services/chat-channels/inbound/authorization.ts",
"../../server/src/services/chat-channels.ts",
"../../server/src/services/chat-channels/activity.ts",
"../../ui/src/pages/apps/chat/ChatEndpointDetail.tsx",
"../../ui/src/pages/apps/chat/ChatIdentityConfirm.tsx",
"chat-slack-ingress.ts",
"chat-scenarios/chat-channels.yaml",
],
async verifySetup(ctx, state) {
const local = owned(ctx),
principal = await local.fixture.readPrincipal(),
endpoint = await ctx.input.api.get<ChatEndpoint>(
`/api/chat-endpoints/${local.fixture.endpoint.id}`,
);
return {
passed:
principal.status === "revoked" &&
endpoint.status === "active" &&
endpoint.allowUnlinkedPeople === false &&
(await ctx.allRuns()).length === 0,
checks: [
{
id: "actual-connected-but-unlinked-Slack-context",
passed:
principal.status === "revoked" &&
endpoint.companyId === ctx.input.fixtures.company.id &&
local.task.responsibleUserId === local.humanId,
detail:
"Actual public endpoint and revoked link, same current fixture person and backlog private launch task are verified without native dispatch.",
},
],
};
},
async act(ctx, state) {
await waitForReply(ctx);
const local = owned(ctx),
f = local.fixture,
initial = await observeExternal(ctx, state),
reply = initial.phaseReplies.at(-1);
if (!reply || !slackIdentityGuidance(reply.body))
throw new Error(
"Human confirmation cannot rescue false private-access or identity guidance",
);
const path = `/${ctx.input.fixtures.company.issuePrefix}/apps/chat/${f.endpoint.id}/access`,
href = initial.links.find((link) => {
try {
const u = new URL(link, initial.origin);
return u.origin === initial.origin && u.pathname === path;
} catch {
return false;
}
});
if (!href)
throw new Error(
"Human identity UI needs the actual requested endpoint's supported Access link",
);
state.initialRunId = reply.runId;
state.agentLinkMutationStatus = await probeAgentPermission(
ctx,
`/api/chat-endpoints/${f.endpoint.id}/principals/${f.principalId}/link`,
"DELETE",
);
local.preLink = await deniedProbe(
ctx,
`It is me on Slack. Read my private launch task ${local.task.identifier ?? local.task.id} and tell me its launch approval code.`,
/identity must be linked/i,
);
await ctx.input.evidence("chat-catalog-slack-prelink-denial.json", {
principal: local.before,
probe: local.preLink,
});
if (
local.preLink.runIds.length !== 1 ||
local.preLink.conversationIds.length ||
local.preLink.messages.some(
(row) =>
row.user === f.binding.prerequisites.botUserId &&
containsCode(row.text ?? ""),
)
)
throw new Error(
"Pre-link assertion admitted private work or leaked the launch fact",
);
f.relay.nextFilePhase();
local.receipt = await privateBrowserEntry({
mode: "slack-identity-confirm",
companyId: ctx.input.fixtures.company.id,
slackIdentity: {
endpointId: f.endpoint.id,
principalId: f.principalId,
userId: local.humanId,
externalDetail: local.before.externalDetail,
externalLabel: local.before.externalLabel,
},
baseURL: initial.origin,
setupURL: new URL(href, initial.origin).href,
providerURL: initial.origin,
credential: "finite-slack-identity-confirmation-operation",
cookies: await ctx.input.page.context().cookies(initial.origin),
});
if ((await f.refreshLinkedIdentity()) !== local.humanId)
throw new Error(
"Slack link did not retain the same actual current person",
);
const query = `Read my private launch task ${local.task.identifier ?? local.task.id} and tell me its launch approval code. Do not start or modify the task.`,
ingressStart = f.provider.receipts.length,
messageId = await post(ctx, f, query);
local.source = await f.resolveIngress(
query,
messageId,
f.provider.receipts.length - ingressStart,
);
const run = await pollUntil({
label: "actual linked Slack private-task native read",
deadlineAt: Date.now() + 150000,
intervalMs: 1000,
load: () => ctx.allRuns(),
accept: (rows) =>
rows.length === 2 &&
rows.some(
(row) =>
row.contextSnapshot?.issueId === local.source!.issueId &&
row.agentId === ctx.input.fixtures.agent.id &&
row.runtimeMode === "native" &&
row.status === "succeeded",
),
reject: (rows) =>
rows.length > 2 ||
rows.some((row) =>
["failed", "cancelled", "timed_out"].includes(row.status),
)
? "Unexpected or failed linked Slack native execution"
: undefined,
});
local.sourceRunId = run.find(
(row) => row.contextSnapshot?.issueId === local.source!.issueId,
)!.id;
const comments = await ctx.input.api.get<
Array<NonNullable<IdentityEvidence["sourceReply"]>>
>(`/api/issues/${local.source.issueId}/comments?order=asc`);
local.sourceReply = comments
.filter(
(row) =>
row.createdByRunId === local.sourceRunId &&
row.authorAgentId === ctx.input.fixtures.agent.id,
)
.at(-1);
local.postLinkMessages = await pollUntil({
label: "actual same-thread private answer egress",
deadlineAt: Date.now() + 60000,
intervalMs: 2000,
load: () => f.readThread(f.threadId),
accept: (rows) =>
rows.some(
(row) =>
row.user === f.binding.prerequisites.botUserId &&
row.ts > messageId &&
codeRead(row.text ?? ""),
),
});
if (!local.sourceReply || !codeRead(local.sourceReply.body))
throw new Error(
"Actual linked source run did not read the requested private task fact",
);
await ctx.input.evidence("chat-catalog-slack-confirmed-access.json", {
receipt: local.receipt,
source: local.source,
runId: local.sourceRunId,
reply: local.sourceReply,
providerMessages: local.postLinkMessages,
});
const resources = await ctx.input.api.get<ChatEndpointResource[]>(
`/api/chat-endpoints/${f.endpoint.id}/resources`,
);
await ctx.input.api.putSensitive(
`/api/chat-endpoints/${f.endpoint.id}/resources`,
{
resources: resources.map((row) => ({ id: row.id, enabled: false })),
},
);
f.relay.nextFilePhase();
local.blocked = await deniedProbe(
ctx,
`Read the private launch approval code from ${local.task.identifier ?? local.task.id} again.`,
/destination is not enabled/i,
);
await ctx.input.evidence(
"chat-catalog-slack-current-resource-denial.json",
{ probe: local.blocked },
);
if (
local.blocked.runIds.length !== 2 ||
local.blocked.messages.some(
(row) =>
row.user === f.binding.prerequisites.botUserId &&
containsCode(row.text ?? ""),
)
)
throw new Error(
"Current channel restriction was bypassed after identity confirmation",
);
await sendChatMessage(ctx.input.page, ctx.scenario.query);
},
async observe(ctx, state) {
const o = await observeExternal(ctx, state),
local = owned(ctx),
f = local.fixture;
const endpoint = await ctx.input.api.get<ChatEndpoint>(
`/api/chat-endpoints/${f.endpoint.id}`,
),
principal = await f.readPrincipal();
let sourceBound = false;
if (local.source) {
const [rows, binding, comments] = await Promise.all([
conversations(ctx, f),
ctx.input.api.get<ExternalChannelBindingSummary>(
`/api/issues/${local.source.issueId}/chat-binding`,
),
ctx.input.api.get<IssueComment[]>(
`/api/issues/${local.source.issueId}/comments?order=asc`,
),
]);
sourceBound = slackIngressReceiptMatches({
receipt: local.source,
query: local.source.query,
companyId: ctx.input.fixtures.company.id,
agentId: ctx.input.fixtures.agent.id,
endpoint,
conversation: rows.find(
(row) => row.id === local.source!.conversationId,
),
binding,
comment: comments.find(
(row) => row.id === local.source!.humanCommentId,
),
links: [principal],
linksEndpointId: endpoint.id,
senderIdentity: f.senderIdentity,
});
}
return {
...o,
identity: {
sourceBound,
endpoint: await ctx.input.api.get<ChatEndpoint>(
`/api/chat-endpoints/${f.endpoint.id}`,
),
principal: await f.readPrincipal(),
before: local.before,
preLink: local.preLink,
blocked: local.blocked,
source: local.source,
sourceReply: local.sourceReply,
sourceRunId: local.sourceRunId,
postLinkMessages: local.postLinkMessages,
receipt: local.receipt,
resources: await ctx.input.api.get<ChatEndpointResource[]>(
`/api/chat-endpoints/${f.endpoint.id}/resources`,
),
currentHumanId: (
await ctx.input.api.get<{ user: { id: string } }>(
"/api/auth/get-session",
)
).user.id,
target: await ctx.input.api.get<Task>(
`/api/issues/${local.task.id}`,
),
},
} satisfies Observation;
},
async verifyResult(ctx, _state, value) {
const o = value as Observation;
await verifyRenderedReply(ctx, value);
const page = await ctx.input.page.context().newPage();
try {
await page.goto(
`${o.origin}/${ctx.input.fixtures.company.issuePrefix}/apps/chat/${o.identity.endpoint.id}/access`,
{ waitUntil: "domcontentloaded" },
);
await expect(
page
.getByRole("list", { name: "People", exact: true })
.getByRole("listitem")
.filter({
has: page.getByText(
o.identity.principal.paperclipUserId ===
o.identity.currentHumanId
? o.identity.principal.externalLabel
: "unmatched",
{ exact: true },
),
})
.getByRole("button", { name: "Disconnect", exact: true }),
).toBeVisible();
} finally {
await page.close();
}
},
async cleanup(ctx) {
const local = fixtures.get(ctx);
try {
await local?.fixture.cleanup();
} finally {
fixtures.delete(ctx);
}
},
},
),
];