mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-15 18:56:05 +01:00
## 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>
598 lines
22 KiB
TypeScript
598 lines
22 KiB
TypeScript
import { expect } from "@playwright/test";
|
||
import type { ConnectionIntentInteraction } from "../../../packages/shared/src/types/issue.js";
|
||
import type {
|
||
ToolConnection,
|
||
ConnectionGrantsResponse,
|
||
ToolRunDecisionLookup,
|
||
ToolProfileEffectiveSummary,
|
||
ToolConnectionTestCallResult,
|
||
} from "../../../packages/shared/src/types/tool-access.js";
|
||
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
|
||
import { pollUntil } from "../api.js";
|
||
import {
|
||
externalRequirements,
|
||
selectedExternalBinding,
|
||
} from "./external-fixtures.js";
|
||
import { privateNotionOAuth } from "./external-notion-oauth.js";
|
||
import {
|
||
notionSelfWorkspaceMatches,
|
||
type NotionOAuthReceipt,
|
||
} from "./external-notion-oauth-contract.js";
|
||
import {
|
||
readNotionFixturePages,
|
||
connectNamedNotion,
|
||
verifyNotionWorkspace,
|
||
verifyNotionPersonalPageDenied,
|
||
type NotionPageOracle,
|
||
} from "./external-notion-provider.js";
|
||
import {
|
||
notionDateMentioned,
|
||
notionFactSpan,
|
||
notionPageIdentityMatches,
|
||
} from "./external-notion-semantics.js";
|
||
import {
|
||
checks,
|
||
definition,
|
||
externalObservation,
|
||
observeExternal,
|
||
root,
|
||
verifyRenderedReply,
|
||
} from "./external-support.js";
|
||
|
||
export function personalNotionGuidance(text: string) {
|
||
return text
|
||
.split(/[.!?;\n]+/)
|
||
.some(
|
||
(clause) =>
|
||
/\bpersonal\b/i.test(clause) &&
|
||
/\b(?:connect|authorize|authorization|sign.?in)\b/i.test(clause) &&
|
||
!/\bI(?:['’]ve| have)?\s+(?:already\s+)?(?:connected|authorized)\b/i.test(
|
||
clause,
|
||
),
|
||
);
|
||
}
|
||
export async function sharedNotionAuthority(
|
||
ctx: ChatCatalogContext,
|
||
id: string,
|
||
) {
|
||
const connection = await ctx.input.api.get<ToolConnection>(
|
||
`/api/tool-connections/${id}`,
|
||
);
|
||
const { grants } = await ctx.input.api.get<ConnectionGrantsResponse>(
|
||
`/api/tool-connections/${id}/grants`,
|
||
);
|
||
const { installs } = await ctx.input.api.get<{
|
||
installs: Array<{ targetType: string; targetId: string }>;
|
||
}>(`/api/tool-connections/${id}/installs`);
|
||
const sorted = (rows: unknown[]) =>
|
||
rows.map((row) => JSON.stringify(row)).sort();
|
||
return {
|
||
id: connection.id,
|
||
companyId: connection.companyId,
|
||
enabled: connection.enabled,
|
||
credentialPolicy: connection.credentialPolicy,
|
||
ownership: connection.ownership,
|
||
grants: sorted(
|
||
grants.map((g) => ({
|
||
id: g.id,
|
||
kind: g.kind,
|
||
subjectUserId: g.subjectUserId,
|
||
subjectAgentId: g.subjectAgentId,
|
||
status: g.status,
|
||
members: sorted(
|
||
(g.members ?? []).map((m) => ({
|
||
subjectType: m.subjectType,
|
||
subjectId: m.subjectId,
|
||
})),
|
||
),
|
||
delegations: sorted(
|
||
(g.delegations ?? []).map((d) => ({ agentId: d.agentId })),
|
||
),
|
||
})),
|
||
),
|
||
installs: sorted(
|
||
installs.map((i) => ({ targetType: i.targetType, targetId: i.targetId })),
|
||
),
|
||
};
|
||
}
|
||
export function gradeNotionSetup(value: unknown) {
|
||
const c = checks(),
|
||
o = externalObservation(value);
|
||
c.add(
|
||
"actual-personal-notion-setup-evidence",
|
||
!!o,
|
||
"Actual named-provider setup, pending request and provider-native read evidence are required.",
|
||
);
|
||
if (!o) return c.result();
|
||
const card = o.interactions.find(
|
||
(row) => row.id === o.state.intentId,
|
||
) as unknown as ConnectionIntentInteraction | undefined;
|
||
const receipt = o.state.oauthReceipt as NotionOAuthReceipt | undefined;
|
||
const initial = o.phaseReplies
|
||
.filter((row) => row.runId === o.state.initialRunId)
|
||
.map((row) => row.body)
|
||
.join("\n");
|
||
const continuation = o.phaseReplies
|
||
.filter((row) => row.runId !== o.state.initialRunId)
|
||
.map((row) => row.body)
|
||
.join("\n");
|
||
const pages = o.state.pages as NotionPageOracle[] | undefined,
|
||
recent = pages?.[0],
|
||
older = pages?.[1];
|
||
c.add(
|
||
"single-addressed-pending-request",
|
||
!!card &&
|
||
o.interactions.filter((row) => row.kind === "connection_intent")
|
||
.length === 1 &&
|
||
card.sourceRunId === o.state.initialRunId &&
|
||
card.addresseeUserId === o.state.humanId &&
|
||
o.state.pendingBeforeHuman === true &&
|
||
o.state.cardVisible === true &&
|
||
o.state.pendingWithoutCredential === true,
|
||
"The original model's addressed request remains pending without credentials; no hidden replacement or premature resolution.",
|
||
);
|
||
c.add(
|
||
"no-premature-unseen-summary",
|
||
!!recent &&
|
||
!notionFactSpan(initial, recent.fact) &&
|
||
(!older || !notionFactSpan(initial, older.fact)) &&
|
||
!/\b(?:I(?: have|'ve|’ve)? (?:already )?(?:read|reviewed|summarized)|here(?: is|'s|’s) (?:the |your )?(?:latest|launch summary))/i.test(
|
||
initial,
|
||
),
|
||
"The setup reply cannot claim research or substitute unseen page facts before human authorization.",
|
||
);
|
||
c.add(
|
||
"actual-human-provider-consent",
|
||
!!receipt &&
|
||
receipt.humanId === o.state.humanId &&
|
||
receipt.intentId === card?.id &&
|
||
receipt.personalDraft === true &&
|
||
receipt.credentialAbsentAtHandoff === true &&
|
||
receipt.providerHandoff === true &&
|
||
receipt.consentCompleted === true &&
|
||
receipt.callbackReturned === true &&
|
||
receipt.workspaceMatched === true &&
|
||
receipt.providerHumanMatched === true &&
|
||
receipt.processIsolation === true &&
|
||
receipt.testRunnerAttached === false &&
|
||
receipt.tracingEnabled === false &&
|
||
receipt.videoEnabled === false,
|
||
"The addressed fixture person actually completes full-page named Notion consent and returns; private get-self independently proves the selected workspace.",
|
||
);
|
||
c.add(
|
||
"same-usable-personal-connection",
|
||
!!card &&
|
||
card.result?.outcome === "connected" &&
|
||
card.result.connectionId === receipt?.connectionId &&
|
||
card.resolvedByUserId === o.state.humanId &&
|
||
!card.resolvedByAgentId &&
|
||
o.state.connectionId === receipt?.connectionId &&
|
||
o.connections.length ===
|
||
(o.scenarioId === "connection-setup.notion-wrong-account" ? 2 : 1) &&
|
||
o.state.samePersonalActive === true &&
|
||
o.state.currentHumanPreserved === true &&
|
||
o.state.originalSourcePreserved === true,
|
||
"Only the original personal draft becomes usable; the actual callback resolves the same request/user/conversation with one account.",
|
||
);
|
||
const decisions = o.state.decisions as ToolRunDecisionLookup[] | undefined;
|
||
c.add(
|
||
"new-canonical-continuation-read",
|
||
!!decisions?.some(
|
||
(row) =>
|
||
row.runId !== o.state.initialRunId &&
|
||
o.runs.some(
|
||
(run) => run.id === row.runId && run.status === "succeeded",
|
||
) &&
|
||
row.decisions.some(
|
||
(d) =>
|
||
d.invocation.runId === row.runId &&
|
||
d.invocation.agentId === o.leadId &&
|
||
d.invocation.issueId === o.state.sourceIssueId &&
|
||
d.invocation.connectionId === o.state.connectionId &&
|
||
d.invocation.status === "succeeded" &&
|
||
(o.state.readEntryIds as string[] | undefined)?.includes(
|
||
d.invocation.catalogEntryId ?? "",
|
||
),
|
||
),
|
||
),
|
||
"A new native continuation actually reads through the newly authorized Notion connection; the independent get-self/oracle read is insufficient.",
|
||
);
|
||
c.add(
|
||
"current-body-date-and-source",
|
||
!!recent &&
|
||
!!notionFactSpan(continuation, recent.fact) &&
|
||
notionDateMentioned(continuation, recent.editedAt) &&
|
||
o.links.some((link) => notionPageIdentityMatches(link, recent.id)) &&
|
||
(!older ||
|
||
!notionFactSpan(continuation, older.fact) ||
|
||
/older|background|previous|earlier/i.test(continuation)) &&
|
||
o.state.pagesUnchanged === true,
|
||
"The continuation summarizes the actual recent body fact with its real date/source, distinguishing older background.",
|
||
);
|
||
if (o.scenarioId === "connection-setup.notion-wrong-account") {
|
||
c.add(
|
||
"actual-shared-personal-mismatch",
|
||
o.state.sharedWorkspaceMatched === true &&
|
||
o.state.sharedMcpWorkspaceMatched === true &&
|
||
o.state.sharedCannotReadPersonal === true &&
|
||
o.state.sharedConnectionId !== o.state.connectionId &&
|
||
personalNotionGuidance(initial),
|
||
"The existing healthy shared workspace really lacks the known personal page; actual guidance requests the personal workspace rather than substituting shared notes.",
|
||
);
|
||
c.add(
|
||
"shared-authority-preserved",
|
||
o.state.sharedAuthorityPreserved === true,
|
||
"Actual shared account ownership, human audience, agent delegation and installs remain unchanged after creating the explicitly personal account.",
|
||
);
|
||
}
|
||
if (o.scenarioId === "connection-setup.save-and-resume") {
|
||
const saved = o.state.savedDraft as NotionOAuthReceipt | undefined;
|
||
c.add(
|
||
"real-human-saved-uncredentialed-draft",
|
||
!!saved &&
|
||
saved.personalDraft === true &&
|
||
saved.credentialAbsentAtHandoff === true &&
|
||
saved.providerHandoff === true &&
|
||
saved.draftSurvivedReload === true &&
|
||
!saved.consentCompleted &&
|
||
!saved.callbackReturned &&
|
||
saved.intentId === null &&
|
||
saved.connectionId === receipt?.connectionId &&
|
||
receipt?.resumedSameDraft === true &&
|
||
o.state.savedBeforeCanonical === true,
|
||
"Before the canonical query, actual Continue to Notion saves personal choices; the human leaves before credentials, reloads, and later authorizes that same durable draft.",
|
||
);
|
||
}
|
||
return c.result();
|
||
}
|
||
export const notionSetupSourceFiles = [
|
||
"chat-catalog-domains/external-notion-setup.ts",
|
||
"chat-catalog-domains/external-notion-oauth.ts",
|
||
"chat-catalog-domains/external-notion-oauth-worker.ts",
|
||
"chat-catalog-domains/external-notion-oauth-contract.ts",
|
||
"chat-catalog-domains/external-notion-provider.ts",
|
||
"chat-catalog-domains/external-notion-semantics.ts",
|
||
"chat-catalog-domains/external-public-signin.ts",
|
||
"chat-catalog-domains/external-public-signin-worker.ts",
|
||
"chat-catalog-domains/external-public-signin-contract.ts",
|
||
"public-mcp-flow.ts",
|
||
"chat-public-origin.ts",
|
||
"chat-catalog-domains/external-fixtures.ts",
|
||
"chat-catalog-domains/external-support.ts",
|
||
"chat-catalog-domains/internal-support.ts",
|
||
"chat-scenarios/connection-setup.yaml",
|
||
"../../ui/src/features/connections/ConnectionSetupFlow.tsx",
|
||
"../../ui/src/features/connections/ConnectionIntentInteractionBody.tsx",
|
||
"../../server/src/routes/tool-access.ts",
|
||
"../../server/src/services/tool-access/oauth/direct-callback.ts",
|
||
"../../scripts/smoke/notion-generic-live.mjs",
|
||
];
|
||
export const notionSetupExternalCases = [
|
||
"connection-setup.notion-missing",
|
||
"connection-setup.return-from-login",
|
||
"connection-setup.save-and-resume",
|
||
"connection-setup.notion-wrong-account",
|
||
].map((id) =>
|
||
definition(
|
||
id,
|
||
async (ctx) => {
|
||
const connections = (
|
||
await ctx.input.api.get<{ connections: ToolConnection[] }>(
|
||
`${root(ctx)}/tools/connections`,
|
||
)
|
||
).connections;
|
||
if (connections.length)
|
||
throw new Error(
|
||
"No-connection Notion setup requires a fresh disposable company",
|
||
);
|
||
const pages = await readNotionFixturePages(ctx);
|
||
const humanId = (
|
||
await ctx.input.api.get<{ user: { id: string } }>(
|
||
"/api/auth/get-session",
|
||
)
|
||
).user.id;
|
||
const state: Record<string, unknown> = {
|
||
pages,
|
||
humanId,
|
||
baselineConnectionIds: [],
|
||
savedBeforeCanonical: false,
|
||
};
|
||
if (id === "connection-setup.notion-wrong-account") {
|
||
const binding = selectedExternalBinding(ctx),
|
||
p = binding.prerequisites;
|
||
if (
|
||
p.sharedWorkspaceId!.replaceAll("-", "").toLowerCase() ===
|
||
p.workspaceId!.replaceAll("-", "").toLowerCase()
|
||
)
|
||
throw new Error(
|
||
"Setup blocker: shared and personal Notion workspaces must be genuinely distinct",
|
||
);
|
||
const shared = {
|
||
...binding,
|
||
prerequisites: {
|
||
...p,
|
||
workspaceId: p.sharedWorkspaceId!,
|
||
apiTokenEnv: p.sharedApiTokenEnv!,
|
||
mcpTokenEnv: p.sharedMcpTokenEnv!,
|
||
},
|
||
};
|
||
await verifyNotionWorkspace(ctx, shared);
|
||
await verifyNotionPersonalPageDenied(ctx, shared, p.recentPageId!);
|
||
const connected = await connectNamedNotion(ctx, shared, [
|
||
ctx.input.fixtures.agent.id,
|
||
]);
|
||
const proof =
|
||
await ctx.input.api.postSensitive<ToolConnectionTestCallResult>(
|
||
`/api/tool-connections/${connected.connectionId}/test-calls`,
|
||
{
|
||
agentId: ctx.input.fixtures.agent.id,
|
||
toolName: "notion-get-self",
|
||
parameters: {},
|
||
},
|
||
);
|
||
if (
|
||
proof.decision !== "allowed" ||
|
||
proof.error ||
|
||
!notionSelfWorkspaceMatches(proof.result, p.sharedWorkspaceId!)
|
||
) {
|
||
await ctx.input.api.delete(
|
||
`/api/tool-connections/${connected.connectionId}`,
|
||
{ allowNotFound: true },
|
||
);
|
||
throw new Error(
|
||
"Setup blocker: actual existing shared MCP authorization does not match its designated workspace",
|
||
);
|
||
}
|
||
state.sharedMcpWorkspaceMatched = true;
|
||
state.sharedConnectionId = connected.connectionId;
|
||
state.sharedAuthorityBefore = await sharedNotionAuthority(
|
||
ctx,
|
||
connected.connectionId,
|
||
);
|
||
state.sharedWorkspaceMatched = true;
|
||
state.sharedCannotReadPersonal = true;
|
||
}
|
||
if (id === "connection-setup.save-and-resume") {
|
||
try {
|
||
state.savedDraft = await privateNotionOAuth(ctx, {
|
||
operation: "save-draft",
|
||
});
|
||
state.savedBeforeCanonical = true;
|
||
} catch (error) {
|
||
// Every connection in this newly owned disposable company was created by
|
||
// this one finite UI operation. Do not leave an unreturned private draft.
|
||
for (const row of (
|
||
await ctx.input.api.get<{ connections: ToolConnection[] }>(
|
||
`${root(ctx)}/tools/connections`,
|
||
)
|
||
).connections)
|
||
await ctx.input.api.delete(`/api/tool-connections/${row.id}`, {
|
||
allowNotFound: true,
|
||
});
|
||
throw error;
|
||
}
|
||
}
|
||
return state;
|
||
},
|
||
gradeNotionSetup,
|
||
{
|
||
authentication: "human-session",
|
||
externalInput: externalRequirements[id],
|
||
expectedRunCount: 2,
|
||
minimumRunCount: 2,
|
||
expectedHumanMessageCount: 1,
|
||
turnTimeoutMs: 120000,
|
||
attemptTimeoutMs: 900000,
|
||
sourceFiles: notionSetupSourceFiles,
|
||
async act(ctx, state) {
|
||
const rows = await pollUntil({
|
||
label: "actual addressed pending Notion request",
|
||
deadlineAt: Date.now() + 150000,
|
||
load: async () => {
|
||
await ctx.refreshIssue();
|
||
return ctx.issue()
|
||
? ctx.input.api.get<ConnectionIntentInteraction[]>(
|
||
`/api/issues/${ctx.issue()!.id}/interactions`,
|
||
)
|
||
: [];
|
||
},
|
||
accept: (rows) =>
|
||
rows.some(
|
||
(row) =>
|
||
row.kind === "connection_intent" &&
|
||
row.status === "pending" &&
|
||
row.payload.serviceSlug === "notion",
|
||
),
|
||
});
|
||
const pending = rows.filter(
|
||
(row) =>
|
||
row.kind === "connection_intent" &&
|
||
row.status === "pending" &&
|
||
row.payload.serviceSlug === "notion",
|
||
);
|
||
if (
|
||
pending.length !== 1 ||
|
||
pending[0]!.addresseeUserId !== state.humanId ||
|
||
pending[0]!.payload.requestingAgentId !== ctx.input.fixtures.agent.id
|
||
)
|
||
throw new Error(
|
||
"Notion request is not uniquely addressed to the actual fixture person/requesting CEO",
|
||
);
|
||
const card = pending[0]!;
|
||
state.intentId = card.id;
|
||
state.initialRunId = card.sourceRunId;
|
||
state.sourceIssueId = ctx.issue()!.id;
|
||
state.pendingBeforeHuman = true;
|
||
await expect(
|
||
ctx.input.page
|
||
.getByRole("button", {
|
||
name: /^(Connect|Connect \/ Use existing)$/,
|
||
exact: true,
|
||
})
|
||
.first(),
|
||
).toBeVisible();
|
||
state.cardVisible = true;
|
||
const before = (
|
||
await ctx.input.api.get<{ connections: ToolConnection[] }>(
|
||
`${root(ctx)}/tools/connections`,
|
||
)
|
||
).connections;
|
||
const saved = state.savedDraft as NotionOAuthReceipt | undefined;
|
||
state.pendingWithoutCredential =
|
||
before.filter((row) => row.id !== state.sharedConnectionId).length ===
|
||
(saved ? 1 : 0) &&
|
||
before
|
||
.filter((row) => row.id !== state.sharedConnectionId)
|
||
.every(
|
||
(row) =>
|
||
row.id === saved?.connectionId &&
|
||
row.status === "draft" &&
|
||
row.credentialPolicy === "per_user" &&
|
||
!row.credentialSecretRefs.length &&
|
||
!row.credentialRefs?.length,
|
||
);
|
||
const current = await observeExternal(ctx, state);
|
||
const initial = current.phaseReplies
|
||
.filter((row) => row.runId === card.sourceRunId)
|
||
.map((row) => row.body)
|
||
.join("\n");
|
||
const pages = state.pages as NotionPageOracle[];
|
||
if (
|
||
!state.pendingWithoutCredential ||
|
||
!initial.trim() ||
|
||
pages.some((page) => notionFactSpan(initial, page.fact))
|
||
)
|
||
throw new Error(
|
||
"Notion request was prematurely satisfied or already exposed unseen fixture facts",
|
||
);
|
||
if (
|
||
id === "connection-setup.notion-wrong-account" &&
|
||
!personalNotionGuidance(initial)
|
||
)
|
||
throw new Error(
|
||
"Actual Notion guidance does not identify the requested personal workspace before the human acts",
|
||
);
|
||
// The visible addressed card's supported full-page setup host preserves the
|
||
// exact same intent. No API connection or completion substitutes for UI.
|
||
state.oauthReceipt = await privateNotionOAuth(ctx, {
|
||
operation: "authorize",
|
||
intentId: card.id,
|
||
...(saved ? { draftId: saved.connectionId } : {}),
|
||
});
|
||
state.connectionId = (
|
||
state.oauthReceipt as NotionOAuthReceipt
|
||
).connectionId;
|
||
await ctx.input.page.reload({ waitUntil: "domcontentloaded" });
|
||
},
|
||
async observe(ctx, state) {
|
||
const o = await observeExternal(ctx, state),
|
||
receipt = state.oauthReceipt as NotionOAuthReceipt | undefined;
|
||
if (receipt) {
|
||
const connection = await ctx.input.api.get<ToolConnection>(
|
||
`/api/tool-connections/${receipt.connectionId}`,
|
||
);
|
||
const grants = await ctx.input.api.get<ConnectionGrantsResponse>(
|
||
`/api/tool-connections/${receipt.connectionId}/grants`,
|
||
);
|
||
state.samePersonalActive =
|
||
connection.companyId === ctx.input.fixtures.company.id &&
|
||
connection.status === "active" &&
|
||
connection.healthStatus === "ok" &&
|
||
connection.credentialPolicy === "per_user" &&
|
||
grants.grants.filter(
|
||
(g) =>
|
||
g.kind === "user" &&
|
||
g.subjectUserId === state.humanId &&
|
||
g.status === "active",
|
||
).length === 1 &&
|
||
!grants.grants.some(
|
||
(g) => g.kind === "organization" && g.status === "active",
|
||
);
|
||
const effective =
|
||
await ctx.input.api.get<ToolProfileEffectiveSummary>(
|
||
`${root(ctx)}/tools/profiles/effective/agents/${ctx.input.fixtures.agent.id}`,
|
||
);
|
||
const catalog = await ctx.input.api.get<{
|
||
catalog: Array<{ id: string; isReadOnly: boolean }>;
|
||
}>(`/api/tool-connections/${receipt.connectionId}/catalog`);
|
||
state.readEntryIds = catalog.catalog
|
||
.filter(
|
||
(e) =>
|
||
e.isReadOnly &&
|
||
effective.allowedTools.some((t) => t.id === e.id),
|
||
)
|
||
.map((e) => e.id);
|
||
}
|
||
if (typeof state.sharedConnectionId === "string")
|
||
state.sharedAuthorityPreserved =
|
||
JSON.stringify(
|
||
await sharedNotionAuthority(ctx, state.sharedConnectionId),
|
||
) === JSON.stringify(state.sharedAuthorityBefore);
|
||
state.decisions = await Promise.all(
|
||
(await ctx.allRuns()).map((run) =>
|
||
ctx.input.api.get<ToolRunDecisionLookup>(
|
||
`${root(ctx)}/tools/runs/${run.id}/decisions`,
|
||
),
|
||
),
|
||
);
|
||
state.currentHumanPreserved =
|
||
(
|
||
await ctx.input.api.get<{ user: { id: string } }>(
|
||
"/api/auth/get-session",
|
||
)
|
||
).user.id === state.humanId;
|
||
state.originalSourcePreserved = ctx.issue()?.id === state.sourceIssueId;
|
||
const current = await readNotionFixturePages(ctx),
|
||
before = state.pages as NotionPageOracle[];
|
||
state.pagesUnchanged =
|
||
current.length === before.length &&
|
||
current.every(
|
||
(p, n) =>
|
||
p.id === before[n]?.id &&
|
||
p.editedAt === before[n]?.editedAt &&
|
||
p.marker === before[n]?.marker,
|
||
);
|
||
return { ...o, state };
|
||
},
|
||
async verifyResult(ctx, state, value) {
|
||
await verifyRenderedReply(ctx, value, String(state.initialRunId));
|
||
const o = externalObservation(value)!,
|
||
page = (state.pages as NotionPageOracle[])[0]!;
|
||
const href = o.links.find((link) =>
|
||
notionPageIdentityMatches(link, page.id),
|
||
);
|
||
if (!href)
|
||
throw new Error(
|
||
"Actual current Notion source link absent from resumed summary",
|
||
);
|
||
await expect(
|
||
ctx.input.page
|
||
.locator(`[id^="comment-"] a[href=${JSON.stringify(href)}]`)
|
||
.first(),
|
||
).toBeVisible();
|
||
await ctx.input.evidence("chat-catalog-notion-human-setup.json", {
|
||
scenarioId: ctx.scenario.id,
|
||
intentId: state.intentId,
|
||
sourceIssueId: state.sourceIssueId,
|
||
initialRunId: state.initialRunId,
|
||
connectionId: state.connectionId,
|
||
oauth: state.oauthReceipt,
|
||
draft: state.savedDraft,
|
||
currentHumanPreserved: state.currentHumanPreserved,
|
||
originalSourcePreserved: state.originalSourcePreserved,
|
||
});
|
||
},
|
||
async cleanup(ctx) {
|
||
for (const row of (
|
||
await ctx.input.api.get<{ connections: ToolConnection[] }>(
|
||
`${root(ctx)}/tools/connections`,
|
||
)
|
||
).connections)
|
||
await ctx.input.api.delete(`/api/tool-connections/${row.id}`, {
|
||
allowNotFound: true,
|
||
});
|
||
},
|
||
},
|
||
),
|
||
);
|