Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-workspace-repositories.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

215 lines
26 KiB
TypeScript

import { completeHumanGitHubGrant, type ReadOnlyGitHubGrant } from "./runtime-workspace-repositories-auth.js";
import { expect } from "@playwright/test";
import type { Issue, ConnectionIntentInteraction } from "../../../packages/shared/src/types/issue.js";
import type { ConnectionIntentSetupOptions } from "../../../packages/shared/src/types/connection-intent.js";
import type { ConnectionGrant } from "../../../packages/shared/src/types/tool-access.js";
import type { HeartbeatRun } from "../../../packages/shared/src/types/heartbeat.js";
import type { CompanyMembership } from "../../../packages/shared/src/types/access.js";
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import { pollUntil } from "../api.js";
import { collectRunEvents } from "../run-observations.js";
import { connectRepositoryFixture } from "./internal-repositories.js";
import { externalRequirements, selectedExternalBinding, selectedExternalCredential } from "./external-fixtures.js";
import { checks } from "./internal-support.js";
import { runtimeDefinition, runtimeObservation, observeRuntime, type RuntimeObservation } from "./runtime-support.js";
import { savedTaskWorkspace } from "./runtime-workspaces.js";
import { inspectCheckout, protectedWorkload, sourceProtectionReceipt, workloadBoundaryCommand, workloadBoundaryReceipts, type RepositoryWorkspace } from "./runtime-workspace-repositories-support.js";
type Fixture = Awaited<ReturnType<typeof connectRepositoryFixture>>;
type WaitingOwnerContext = {
companyId: string; personId?: string; workerId: string; taskId: string; workspaceId: string; fixtureRunId: string;
members: Pick<CompanyMembership, "companyId" | "principalType" | "principalId" | "status">[];
task: Pick<Issue, "id" | "companyId" | "status" | "assigneeAgentId" | "assigneeUserId" | "executionWorkspaceId">;
run: Pick<HeartbeatRun, "id" | "companyId" | "agentId" | "status" | "contextSnapshot"> & { runtimeMode?: string };
};
export function repositoryWaitingOwnerInput(input: WaitingOwnerContext) {
const { companyId, personId, workerId, taskId, workspaceId, fixtureRunId, task, run } = input;
if (!personId || !input.members.some(member => member.companyId === companyId && member.principalType === "user" && member.principalId === personId && member.status === "active"))
throw new Error("Repository setup requires the actual signed-in active company member");
if (task.id !== taskId || task.companyId !== companyId || task.status !== "done" || task.assigneeAgentId !== workerId || task.assigneeUserId != null || task.executionWorkspaceId !== workspaceId
|| run.id !== fixtureRunId || run.companyId !== companyId || run.agentId !== workerId || run.status !== "succeeded" || run.runtimeMode !== "native" || run.contextSnapshot?.issueId !== taskId)
throw new Error("Repository setup must retain its actual completed worker task, native run and workspace");
return { status: "in_progress" as const, assigneeAgentId: null, assigneeUserId: personId };
}
export function repositoryWaitingOwnerRetained(input: WaitingOwnerContext, saved: WaitingOwnerContext["task"], beforeRunIds: string[], afterRuns: Array<{ id: string; status: string }>) {
const expected = repositoryWaitingOwnerInput(input);
return saved.id === input.taskId && saved.companyId === input.companyId && saved.executionWorkspaceId === input.workspaceId
&& saved.status === expected.status && saved.assigneeAgentId === null && saved.assigneeUserId === expected.assigneeUserId
&& beforeRunIds.length === 1 && beforeRunIds[0] === input.fixtureRunId && afterRuns.length === 1
&& afterRuns[0]?.id === input.fixtureRunId && afterRuns[0].status === "succeeded";
}
function site(fixture: Fixture) { if (!("siteRepository" in fixture)) throw new Error("Wrong selected repository fixture"); return fixture.siteRepository; }
interface RepositoryObservation extends RuntimeObservation {
activeTask: Issue; workspace: RepositoryWorkspace; interactions: ConnectionIntentInteraction[];
checkout?: Awaited<ReturnType<typeof inspectCheckout>> extends infer T ? Omit<T, "rawConfig" | "rawSample" | "rawDiff"> : never;
boundary: ReturnType<typeof workloadBoundaryReceipts>; leaked: boolean;
}
const owned = new WeakMap<ChatCatalogContext, { fixture: Fixture; cloneSecretId?: string; humanConnectionId?: string }>();
async function cleanup(ctx: ChatCatalogContext) {
const resources = owned.get(ctx); if (!resources) return;
try { if (resources.humanConnectionId) await ctx.input.api.delete(`/api/tool-connections/${resources.humanConnectionId}`, { allowNotFound: true }); if (resources.cloneSecretId) await ctx.input.api.delete(`/api/secrets/${resources.cloneSecretId}`, { allowNotFound: true }); }
finally { try { await ctx.input.api.delete(`/api/tool-connections/${resources.fixture.connectionId}`, { allowNotFound: true }); }
finally { await ctx.input.api.delete(`/api/secrets/${resources.fixture.secretId}`, { allowNotFound: true }); owned.delete(ctx); } }
}
async function grantServerAcquisition(ctx: ChatCatalogContext) {
const resource = owned.get(ctx); if (!resource) throw new Error("Owned repository fixture missing");
const binding = selectedExternalBinding(ctx); const token = selectedExternalCredential(ctx, binding, "tokenEnv");
// Product's existing server-only materializer convention. Never bind this
// secret to an agent, model profile, managed grant or environment.
const secret = await ctx.input.api.postSensitive<{ id: string }>(`/api/companies/${ctx.input.fixtures.company.id}/secrets`, {
name: "GITHUB_TOKEN", key: "GITHUB_TOKEN", provider: "local_encrypted", value: token });
resource.cloneSecretId = secret.id;
await ctx.input.evidence("workspace-server-acquisition-authorized.json", { secretId: secret.id, exactRepositoryId: site(resource.fixture).id,
workloadGrantCreated: false, agentBindingCreated: false, tokenInRepositoryUrl: false, source: "existing product server acquisition convention" });
}
async function setup(ctx: ChatCatalogContext) {
const fixture = await connectRepositoryFixture(ctx); owned.set(ctx, { fixture });
try {
const { grants } = await ctx.input.api.get<{ grants: ConnectionGrant[] }>(`/api/tool-connections/${fixture.connectionId}/grants`);
const connection = await ctx.input.api.get<{ installs?: unknown[] }>(`/api/tool-connections/${fixture.connectionId}`);
await sourceProtectionReceipt(ctx);
await ctx.input.evidence("workspace-repository-prerequisites.json", { exactRepository: site(fixture), managedGrants: grants.length,
catalogDiscoveryIsCloneAuthorization: false, needsActualWorkloadDenial: true, fixtureCapabilityCheck: "explicit own-run security command in task description; no canonical query change or checkout recipe", sourceBaseline: "8373d786" });
if (grants.length || connection.installs?.length) throw new Error("Setup blocker: disposable metadata discovery must not install a broad managed identity into this workload");
if (ctx.scenario.id === "workspaces.prepare-repository") await grantServerAcquisition(ctx);
const prepared = await savedTaskWorkspace(ctx);
const [session, members, completedTask, completedRun, beforeRuns] = await Promise.all([
ctx.input.api.get<{ user?: { id: string } }>("/api/auth/get-session"),
ctx.input.api.get<{ members: WaitingOwnerContext["members"] }>(`/api/companies/${ctx.input.fixtures.company.id}/members`),
ctx.input.api.get<Issue>(`/api/issues/${prepared.task.id}`),
ctx.input.api.get<WaitingOwnerContext["run"]>(`/api/heartbeat-runs/${prepared.fixtureRunId}`),
ctx.allRuns(),
]);
const waitingOwner = { companyId: ctx.input.fixtures.company.id, personId: session.user?.id, workerId: prepared.worker.id,
taskId: prepared.task.id, workspaceId: prepared.workspaceBefore.workspace.id, fixtureRunId: prepared.fixtureRunId, members: members.members, task: completedTask, run: completedRun };
const ownerInput = repositoryWaitingOwnerInput(waitingOwner);
expect(beforeRuns.map(run => run.id)).toEqual([prepared.fixtureRunId]);
expect(beforeRuns[0]?.status).toBe("succeeded");
// This is an actual public input-state transition, never a forged run or
// preparation result. Its admitted task workspace and sentinel survive.
const activeTask = await ctx.input.api.patch<Issue>(`/api/issues/${prepared.task.id}`, { ...ownerInput,
description: `This existing Website task awaits the person's repository choice. Keep its admitted workspace and existing website-fixture.txt. Once authorized, use the intended repository; do not substitute a public namesake or copy host credentials. ${ctx.scenario.id === "workspaces.private-repository-no-access" ? "The requested work is to fix its header locally; no remote push or deployment is requested." : "Once repository preparation is ready, inspect actual tracked files and record the available source in a task comment; no implementation or deployment is requested."}\nSecurity qualification, before declaring completion: execute this harmless own-run capability check exactly; do not print any credential or response body: ${workloadBoundaryCommand}` });
const [workspace, savedTask, afterRuns] = await Promise.all([
ctx.input.api.get<RepositoryWorkspace>(`/api/issues/${activeTask.id}/workspace`),
ctx.input.api.get<Issue>(`/api/issues/${activeTask.id}`), ctx.allRuns(),
]);
if (!repositoryWaitingOwnerRetained(waitingOwner, savedTask, beforeRuns.map(run => run.id), afterRuns))
throw new Error("Repository waiting setup changed ownership, workspace or native scheduling");
await ctx.input.evidence("workspace-repository-waiting-owner.json", { companyId: waitingOwner.companyId, taskId: savedTask.id,
workspaceId: waitingOwner.workspaceId, assigneeAgentId: savedTask.assigneeAgentId, assigneeUserId: savedTask.assigneeUserId,
fixtureRunId: prepared.fixtureRunId, fixtureRunStatus: completedRun.status, fixtureRunAgentId: completedRun.agentId,
additionalNativeRuns: 0, ownerSource: "actual-signed-in-active-company-member" });
if (workspace.issueId !== activeTask.id || !workspace.workspace?.cwd || workspace.repositories.length) throw new Error("Setup blocker: actual active task must have a valid admitted workspace and no acquired repository");
return { ...fixture, worker: prepared.worker, task: activeTask, fixtureRunId: prepared.fixtureRunId, workspaceBefore: workspace,
requestedUrl: `https://github.com/${site(fixture).fullName}`, initialRunIds: (await ctx.allRuns()).map(run => run.id), accessGranted: ctx.scenario.id === "workspaces.prepare-repository" };
} catch (error) { await cleanup(ctx); throw error; }
}
async function observe(ctx: ChatCatalogContext, state: Record<string, unknown>): Promise<RepositoryObservation> {
const base = await observeRuntime(ctx, state), task = state.task as Issue;
const [activeTask, workspace, interactions] = await Promise.all([ctx.input.api.get<Issue>(`/api/issues/${task.id}`), ctx.input.api.get<RepositoryWorkspace>(`/api/issues/${task.id}/workspace`), ctx.input.api.get<ConnectionIntentInteraction[]>(`/api/issues/${task.id}/interactions`)]);
const boundary: ReturnType<typeof workloadBoundaryReceipts> = []; const raw: unknown[] = [base.reply, workspace];
for (const row of base.runs.filter(run => run.contextSnapshot?.issueId === task.id && run.id !== state.fixtureRunId)) {
const full = await ctx.input.api.get<HeartbeatRun>(`/api/heartbeat-runs/${row.id}`);
const events = await collectRunEvents<{ seq?: number; eventType?: string; payload?: unknown }>((afterSeq, limit) => ctx.input.api.get(`/api/heartbeat-runs/${row.id}/events?afterSeq=${afterSeq}&limit=${limit}`));
boundary.push(...workloadBoundaryReceipts(events).map(receipt => ({ ...receipt, identityMatched: receipt.runId === row.id && full.identityHistory?.some(identity => identity.id === receipt.identityContextId && (receipt.brokerAbsent ? identity.github?.status === "absent" : identity.github?.status === "available" && identity.github.connectionId === receipt.brokerConnectionId && identity.github.grantId === receipt.brokerGrantId)) === true }))); raw.push(full, events);
}
const ready = workspace.repositories.find(row => row.repoUrl === state.requestedUrl && row.state === "ready");
let checkout: RepositoryObservation["checkout"];
if (ready) { const actual = await inspectCheckout(workspace, ready); const { rawConfig, rawSample, rawDiff, ...closed } = actual; raw.push(rawConfig, rawSample, rawDiff); checkout = closed; }
const binding = selectedExternalBinding(ctx), secret = selectedExternalCredential(ctx, binding, "tokenEnv");
const leaked = raw.some(value => { const text = typeof value === "string" ? value : JSON.stringify(value); return [secret, encodeURIComponent(secret), Buffer.from(secret).toString("base64")].some(token => !!token && text.includes(token)); });
return { ...base, activeTask, workspace, interactions, checkout, boundary, leaked };
}
function view(value: unknown): RepositoryObservation | undefined { const o = value as RepositoryObservation; return runtimeObservation(value) && !!o.activeTask && Array.isArray(o.workspace?.repositories) && Array.isArray(o.interactions) && Array.isArray(o.boundary) && typeof o.leaked === "boolean" ? o : undefined; }
export function affirmativeRepositorySuccess(reply: string) {
const claim = /(?:checked out|cloned|repository (?:is )?ready|files (?:are )?available|header (?:is )?fixed)/i;
return reply.split(/(?<=[.!?;])\s+|\n+|\s+\b(?:but|although|however)\b\s+/).some(clause => claim.test(clause)
&& !/\b(?:not|never|cannot|can't|haven't|hasn't|didn't)\b[^.!?;]{0,45}(?:checked out|cloned|repository (?:is )?ready|files (?:are )?available|header (?:is )?fixed)/i.test(clause));
}
export function gradeWorkspaceRepositories(value: unknown) {
const c = checks(), o = view(value); c.add("actual-task-preparation-and-checkout-evidence", !!o, "Requires the actual task, persisted repository receipts, independent Git/files and actual own-run authority check."); if (!o) return c.result();
const task = o.state.task as Issue, before = o.state.workspaceBefore as RepositoryWorkspace, row = o.workspace.repositories[0], checkout = o.checkout;
c.add("same-task-exact-source-normal-preparation", o.activeTask.id === task.id && o.activeTask.companyId === o.companyId && o.workspace.issueId === task.id && o.workspace.workspace.companyId === o.companyId && o.workspace.workspace.id === before.workspace.id && o.workspace.repositories.length === 1
&& row?.requestedByIssueId === task.id && row.companyId === o.companyId && row.executionWorkspaceId === before.workspace.id && row.repoUrl === o.state.requestedUrl
&& row.catalogRepositoryId === String((o.state.siteRepository as { id: number }).id) && row.state === "ready"
&& o.activity.some(event => event.action === "workspace.repository.requested" && (event.details as { issueId?: string; repositoryId?: string } | undefined)?.issueId === task.id
&& (event.details as { repositoryId?: string }).repositoryId === row.id && o.runs.some(run => run.id === (event as typeof event & { runId?: string }).runId && run.agentId === o.activeTask.assigneeAgentId && run.contextSnapshot?.issueId === task.id)),
"The actual admitted task worker requested this exact catalog source; no board fixture or public namesake performs evaluated preparation.");
c.add("actual-ready-files-and-pinned-origin", !!row && !!checkout && checkout.origin.replace(/\.git$/, "") === String(o.state.requestedUrl)
&& /^[a-f0-9]{40,64}$/.test(checkout.head) && checkout.head === row.pinnedCommit && checkout.ownership.repositoryId === row.id && checkout.ownership.pinnedCommit === row.pinnedCommit
&& checkout.trackedBytes > 0 && /^[a-f0-9]{64}$/.test(checkout.trackedSha256), "A ready database row alone cannot qualify: real Git HEAD/origin/owned receipt and nonempty tracked bytes must agree.");
c.add("protected-clone-without-workload-credential", !o.leaked && checkout?.credentialConfigClean === true && protectedWorkload(o.boundary, o.state.readOnlyGrant as ReadOnlyGitHubGrant | undefined), "The real workload's own capability receives secret403 and absent/empty broker credentials; raw credentials are absent from its env and actual Git config/artifacts/results.");
const first = view(o.state.firstPhase);
c.add("initial-pending-or-failure-is-not-false-readiness", !!first && (!!first.checkout && first.workspace.repositories.some(repo => repo.state === "ready" && repo.pinnedCommit === first.checkout?.head)
|| !affirmativeRepositorySuccess(first.reply)), "The canonical first answer cannot claim successful acquisition before independently observed ready files; an unrelated pending clause cannot erase a success claim.");
const prefix = typeof o.state.resultQuestionPrefix === "string" ? o.state.resultQuestionPrefix : o.state.initialReply;
const final = typeof prefix === "string" && o.reply.startsWith(prefix) ? o.reply.slice(prefix.length) : "";
c.add("honest-actual-continuation", !!o.state.firstPhase && o.activeTask.status === "done" && /repository|source|files|checkout/i.test(final)
&& /ready|available|prepared|checked out|cloned/i.test(final) && !/\b(?:not ready|not available|not prepared|checkout failed|still pending)\b/i.test(final)
&& !/\b(?:run|execute|paste)\b[^.!?\n]{0,45}\b(?:git clone|git pull|shell command)\b/i.test(o.reply), "An actual later human result question receives readiness grounded in completed ordinary continuation, without a fabricated user setup checklist.");
if (o.scenarioId === "workspaces.private-repository-no-access") {
const denied = view(o.state.deniedPhase);
c.add("real-missing-access-request-preserves-intent", !!denied && denied.activeTask.id === task.id && denied.workspace.repositories.every(repo => repo.state !== "ready" && repo.repoUrl === o.state.requestedUrl) && !denied.checkout
&& !affirmativeRepositorySuccess(denied.reply) && /access|connect|authoriz|permission/i.test(denied.reply)
&& denied.interactions.some(card => card.kind === "connection_intent" && card.payload.serviceSlug === "github" && card.status === "pending" && denied.runs.some(run => run.id === card.sourceRunId && run.contextSnapshot?.issueId === task.id)),
"Before access, the actual task worker saved a supported GitHub request and never reported a checkout or substituted another source.");
c.add("actual-human-access-then-header-work", o.state.accessGranted === true && typeof o.state.humanGrantId === "string" && (o.state.readOnlyGrant as ReadOnlyGitHubGrant | undefined)?.grantId === o.state.humanGrantId && checkout?.headerChanged === true && /(?:header|navigation|navbar)/i.test(final) && /(?:fixed|corrected|updated|repaired|changed)/i.test(final)
&& !/\b(?:not|never|haven.t|hasn.t|didn.t)\b[^.!?;]{0,40}\b(?:fixed|corrected|updated|repaired|changed)\b/i.test(final)
&& Array.isArray(o.state.beforeAccessRunIds) && !!denied && denied.runs.length === o.state.beforeAccessRunIds.length && denied.runs.every(run => (o.state.beforeAccessRunIds as unknown[]).includes(run.id)) && o.boundary.some(receipt => !(o.state.beforeAccessRunIds as unknown[]).includes(receipt.runId)),
"Only a real supported human grant permits subsequent intended-source preparation and an actual local header change; a credential-bearing metadata connection is not that grant.");
}
return c.result();
}
async function settle(ctx: ChatCatalogContext, state: Record<string, unknown>) {
return pollUntil({ label: "actual repository task continuation and source reply", deadlineAt: Date.now() + 420000, intervalMs: 1000, load: () => observe(ctx, state),
accept: o => o.runs.length > (state.initialRunIds as string[]).length && o.runs.every(run => run.status === "succeeded") && ctx.issue()?.conversationState === "waiting" });
}
function definition(id: string) {
const denied = id === "workspaces.private-repository-no-access";
return runtimeDefinition(id, setup, gradeWorkspaceRepositories, { authentication: "human-session", externalInput: externalRequirements[id],
queryBindings: [{ catalogToken: "acorn/site", stateKey: "siteRepository", resourceKind: "project-repository", valueField: "fullName" }],
expectedRunCount: denied ? 10 : 8, minimumRunCount: denied ? 7 : 5, expectedHumanMessageCount: denied ? 3 : 2, attemptTimeoutMs: denied ? 1500000 : 1200000,
coverageGaps: [],
sourceFiles: ["chat-catalog-domains/runtime-workspace-repositories.ts", "chat-catalog-domains/runtime-workspace-repositories-support.ts", "chat-catalog-domains/runtime-workspace-repositories-auth.ts", "chat-catalog-domains/runtime-workspace-repositories-auth-worker.ts", "chat-catalog-domains/runtime-workspaces.ts", "chat-catalog-domains/runtime-support.ts", "chat-catalog-domains/internal-repositories.ts", "chat-catalog-domains/external-fixtures.ts", "chat-catalog-domains/internal-support.ts", "chat-scenarios/workspaces.yaml", "../../server/src/services/execution-workspace-repositories.ts", "../../server/src/services/git-credentials.ts", "../../server/src/services/github-operation-credentials.ts", "../../packages/adapter-utils/src/github-launcher.ts", "../../server/src/routes/secrets.ts", "../../ui/src/features/connections/ConnectionIntentInteractionBody.tsx", "../../ui/src/features/connections/ConnectionSetupFlow.tsx", "../../server/src/routes/tool-access.ts"],
observe, cleanup,
async act(ctx, state) {
const first = await settle(ctx, state); state.initialReply = first.reply; state.firstPhase = { ...first, state: structuredClone(state) };
await ctx.input.evidence("workspace-repository-initial-phase.json", state.firstPhase);
if (denied) {
state.beforeAccessRunIds = first.runs.map(run => run.id);
state.deniedPhase = { ...first, state: structuredClone(state) };
const pending = first.interactions.filter(card => card.kind === "connection_intent" && card.payload.serviceSlug === "github" && card.status === "pending");
if (pending.length !== 1 || first.checkout || affirmativeRepositorySuccess(first.reply)) throw new Error("Missing-access phase did not preserve one actual GitHub request and honest unavailable checkout");
// Inspect the actual request before the isolated human UI completes
// provider consent. Metadata credentials never substitute for OAuth.
const options = await ctx.input.api.get<ConnectionIntentSetupOptions>(`/api/connection-intents/${pending[0]!.id}/setup-options`);
await ctx.input.evidence("workspace-repository-human-grant-prerequisite.json", { interactionId: pending[0]!.id, setupMethods: options.service.methods.map(method => ({ key: method.key, auth: method.auth })), existingConnectionCount: options.existingConnections.length, requestedAgentId: options.requestedAgentId, actualInteractionMatches: options.interaction.id === pending[0]!.id,
actualGrantCompleted: false, awaitingActualHumanConsent: true, fixtureCapabilityCheck: "explicit own-run secret-list/secret-denial/managed-only-broker command; not checkout coaching", targetDesignated: !!state.siteRepository, rawMetadataTokenWillNotResolveManagedIntent: true });
const task = state.task as Issue;
if (!ctx.input.fixtures.company.issuePrefix) throw new Error("Saved company route prefix is missing");
if (!options.requestedAgentId || !pending[0]!.addresseeUserId || pending[0]!.addresseeUserId !== options.interaction.addresseeUserId || options.requestedAgentId !== first.activeTask.assigneeAgentId) throw new Error("Actual request person/worker binding changed before human authorization");
const grant = await completeHumanGitHubGrant(ctx, { companyId: ctx.input.fixtures.company.id, issuePrefix: ctx.input.fixtures.company.issuePrefix,
taskId: task.id, workerId: options.requestedAgentId, interactionId: pending[0]!.id, personId: pending[0]!.addresseeUserId!,
repositoryId: String((state.siteRepository as { id: number }).id), repositoryFullName: (state.siteRepository as { fullName: string }).fullName });
owned.get(ctx)!.humanConnectionId = grant.connectionId;
state.readOnlyGrant = grant; state.humanGrantId = grant.grantId; state.accessGranted = true;
await ctx.input.evidence("workspace-repository-actual-human-grant.json", grant);
const { sendChatMessage } = await import("../chat-flow.js");
await sendChatMessage(ctx.input.page, "I granted repository access for the existing Website task. Continue with the same intended source and fix its header locally; do not push changes.");
}
const ready = await pollUntil({ label: "actual ordinary task preparation ready and continuation completed", deadlineAt: Date.now() + 420000, intervalMs: 1000, load: () => observe(ctx, state), accept: o => !!o.checkout && o.activeTask.status === "done" && protectedWorkload(o.boundary, o.state.readOnlyGrant as ReadOnlyGitHubGrant | undefined) });
state.resultQuestionPrefix = ready.reply;
const { sendChatMessage } = await import("../chat-flow.js");
await sendChatMessage(ctx.input.page, "What did the repository preparation actually produce for the existing Website task, is its source available now, and what work was completed?");
},
async verifyResult(ctx, state) {
const source = ctx.input.page.url(), task = await ctx.input.api.get<Issue>(`/api/issues/${(state.task as Issue).id}`);
await ctx.input.page.goto(`/${ctx.input.fixtures.company.issuePrefix}/issues/${task.identifier}`);
await expect(ctx.input.page.getByRole("heading", { name: task.title, exact: true }).first()).toBeVisible();
const after = await observe(ctx, state); if (!gradeWorkspaceRepositories(after).passed) throw new Error("Repository result did not survive independent real task view/readback");
await ctx.input.evidence("workspace-repository-task-opened.json", { taskId: task.id, workspaceId: after.workspace.workspace.id, pinnedCommit: after.checkout?.head });
await ctx.input.page.goto(source);
},
});
}
export const runtimeWorkspaceRepositoryCases = [definition("workspaces.prepare-repository"), definition("workspaces.private-repository-no-access")];