mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-06 23:20:53 +01:00
Author private Grok operator OAuth and pairing handoff
This commit is contained in:
1 parent
406eb610dd
commit
f457fa84b0
8 files changed
+220
-23
No files matched your search
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"syntheticOnly": true,
|
||||
"tests": 2,
|
||||
"actualStandaloneChildRejectedBeforeBrowser": true,
|
||||
"expectedParentFailureIncluded": true,
|
||||
"realProviderCalls": 0,
|
||||
"canonicalAttempts": 0,
|
||||
"browserLaunches": 0,
|
||||
"qualificationClaim": "private child/reporting rejection boundary only; positive human UI, clipboard, OAuth and actual Bot pairing/round-trip remain unqualified",
|
||||
"checkedSinks": [
|
||||
"stdout",
|
||||
"JUnit",
|
||||
"blob ZIP entries",
|
||||
"HTML embedded report ZIP",
|
||||
"error-context"
|
||||
],
|
||||
"scannedItems": 12,
|
||||
"privateValueCount": 4,
|
||||
"findings": [],
|
||||
"sourceSha256": {
|
||||
"runtime-grok-operator.ts": "2185f117320149c428328922b383de61e9fd49333ea400ba11858c92f5e00e22",
|
||||
"runtime-grok-operator-worker.ts": "0d135a8d98286fe0f93b700e1473d6d0d4f36ca2320170d48d8c9d8be6c61870",
|
||||
"runtime-grok-operator-contract.ts": "6ab17ae769398340d6310bef769b40588dc48ca6584a8899403632b960f3b6dc",
|
||||
"runtime-grok-operator-privacy.spec.ts": "34d60ce125d03f3eaa48d02231c37b839e6cc994129537c275e1f6f0a58acb5a"
|
||||
},
|
||||
"configSha256": "a3ecb8c311f3c2f550b95e511c9245e2187e6fd06338445da51002e381a5f889"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { grokOperatorInputMatches, grokOperatorReceiptMatches, grokConsentUrlAllowed, grokCallbackOriginAllowed, type GrokOperatorInput } from "./runtime-grok-operator-contract.js";
|
||||
import { runtimePrivateRequirements } from "../chat-runtime-private-requirements.js";
|
||||
function input(): GrokOperatorInput { return { operation: "availability", executionId: "chat-features.runner-codex-subscription.local.agents.existing-grok-bot", attemptId: "a".repeat(32), receiptPath: "/owned/private/origin.json", backendOrigin: "http://127.0.0.1:43120", publicOrigin: "https://owned.example.test", companyId: randomUUID(), companyName: "Actual fixture company", prefix: "ACORN", personId: "actual-fixture-user", personName: "Fixture Person", leadId: randomUUID(), botName: "Actual existing Bot", operatorRef: "authorized-operator", botAuthorizationRef: "selected-existing-bot", operatorMode: "interactive-private-ui", publicSession: { cookies: [{ name: "secure-session", value: "synthetic-value", domain: "owned.example.test", path: "/", expires: -1, httpOnly: true, secure: true, sameSite: "Lax" }], origins: [] } }; }
|
||||
function receipt(i: GrokOperatorInput) { return { operation: i.operation, executionId: i.executionId, attemptId: i.attemptId, companyId: i.companyId, personId: i.personId, operatorRef: i.operatorRef, botAuthorizationRef: i.botAuthorizationRef, processIsolation: true, testRunnerAttached: false, humanSelectedAuthorizedBot: true, publicPersonMatched: true, privateStorageClean: true, clipboardClean: true } as const; }
|
||||
const expected = (i: GrokOperatorInput) => ({ operation: i.operation, executionId: i.executionId, attemptId: i.attemptId, companyId: i.companyId, personId: i.personId, operatorRef: i.operatorRef, botAuthorizationRef: i.botAuthorizationRef });
|
||||
it("requires exact selected operator/authorized-Bot fields before admission, not an ambient provider session", () => { expect(runtimePrivateRequirements["agents.existing-grok-bot"].fields).toEqual(["botId", "endpoint", "challengeMethod", "credentialEnvName", "operatorRef", "botAuthorizationRef", "operatorMode"]); expect(grokOperatorInputMatches(input())).toBe(true); const i = input(); for (const change of [{ executionId: "goals.list" }, { attemptId: "wrong" }, { operatorRef: "" }, { botAuthorizationRef: "" }, { publicOrigin: "http://owned.example.test" }, { operatorMode: "simulated" }]) expect(grokOperatorInputMatches({ ...i, ...change } as GrokOperatorInput)).toBe(false); });
|
||||
it("rejects loopback/copied foreign or insecure cookies and undeclared provider credentials in availability", () => { const i = input(); expect(grokOperatorInputMatches({ ...i, publicSession: { cookies: [{ ...i.publicSession.cookies[0]!, domain: "127.0.0.1" }], origins: [] } })).toBe(false); expect(grokOperatorInputMatches({ ...i, publicSession: { cookies: [{ ...i.publicSession.cookies[0]!, secure: false }], origins: [] } })).toBe(false); expect(grokOperatorInputMatches({ ...i, webhookKey: "secret-not-needed" })).toBe(false); });
|
||||
it("allows only actual same-instance agent consent pages and explicitly reviewed supported callback origins", () => { const origin = "https://owned.example.test", id = randomUUID(); expect(grokConsentUrlAllowed(`${origin}/dot-connect/${id}`, origin)).toBe(true); expect(grokConsentUrlAllowed(`${origin}/mcp-connect/${id}`, origin)).toBe(true); for (const value of [`https://foreign.test/dot-connect/${id}`, `${origin}/auth?next=/`, `${origin}/dot-connect/${id}?code=private`, `${origin}/dot-connect/${id}#secret`, `https://user:pass@owned.example.test/dot-connect/${id}`]) expect(grokConsentUrlAllowed(value, origin)).toBe(false); expect(grokCallbackOriginAllowed("https://grok.example.test")).toBe(true); expect(grokCallbackOriginAllowed("http://127.0.0.1:43199")).toBe(true); for (const value of ["http://remote.example.test", "file:///tmp/fake", "https://user:pass@provider.test", "https://provider.test/path", "null"]) expect(grokCallbackOriginAllowed(value)).toBe(false); });
|
||||
it("availability receipt attests presence only, never fake connection or readiness", () => { const i = input(), r = receipt(i); expect(grokOperatorReceiptMatches(r, expected(i))).toBe(true); for (const change of [{ personId: "foreign-user" }, { attemptId: "b".repeat(32) }, { humanSelectedAuthorizedBot: false }, { ready: true }, { pairingCode: "private-never-retain" }, { token: "private" }, { publicPairingConsentSubmitted: true }]) expect(grokOperatorReceiptMatches({ ...r, ...change } as typeof r, expected(i))).toBe(false); });
|
||||
it("requires complete scoped human handoff controls but does not accept them as Bot verification", () => { const i = { ...input(), operation: "setup" as const, webhookUrl: "https://selected.example.test/routine", webhookKey: "synthetic-protected-key" }, r = { ...receipt(i), agentId: randomUUID(), bindingId: randomUUID(), productInvitationUi: true, accessInstructionsDelivered: true, routineInstructionsDelivered: true, publicPairingConsentSubmitted: true, publicCompanyAgentMatched: true, clientCallbackApproved: true, pairingCodeConfinedToPublicForm: true } as const; expect(grokOperatorInputMatches(i)).toBe(true); expect(grokOperatorReceiptMatches(r, expected(i))).toBe(true); for (const change of [{ privateStorageClean: false }, { clipboardClean: false }, { clientCallbackApproved: false }, { publicCompanyAgentMatched: false }, { pairingCodeConfinedToPublicForm: false }, { verified: true }]) expect(grokOperatorReceiptMatches({ ...r, ...change } as typeof r, expected(i))).toBe(false); });
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { Cookie } from "@playwright/test";
|
||||
export interface GrokOperatorInput {
|
||||
operation: "availability" | "setup"; executionId: string; attemptId: string; receiptPath: string; backendOrigin: string; publicOrigin: string;
|
||||
companyId: string; companyName: string; prefix: string; personId: string; personName: string; leadId: string; botName: string;
|
||||
operatorRef: string; botAuthorizationRef: string; operatorMode: "interactive-private-ui";
|
||||
publicSession: { cookies: Cookie[]; origins: Array<{ origin: string; localStorage: Array<{ name: string; value: string }> }> };
|
||||
existingAgentId?: string; webhookUrl?: string; webhookKey?: string;
|
||||
}
|
||||
export interface GrokOperatorReceipt {
|
||||
operation: GrokOperatorInput["operation"]; executionId: string; attemptId: string; companyId: string; personId: string; operatorRef: string; botAuthorizationRef: string;
|
||||
processIsolation: true; testRunnerAttached: false; humanSelectedAuthorizedBot: true; publicPersonMatched: true; privateStorageClean: true; clipboardClean: true;
|
||||
agentId?: string; bindingId?: string; productInvitationUi?: true; accessInstructionsDelivered?: true; routineInstructionsDelivered?: true; publicPairingConsentSubmitted?: true; publicCompanyAgentMatched?: true; clientCallbackApproved?: true; pairingCodeConfinedToPublicForm?: true;
|
||||
}
|
||||
const uuid = (v: unknown) => typeof v === "string" && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(v);
|
||||
export function grokOperatorInputMatches(i: GrokOperatorInput) {
|
||||
try { const origin = new URL(i.publicOrigin), backend = new URL(i.backendOrigin), ref = (v: string) => /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/.test(v), host = origin.hostname;
|
||||
return Object.keys(i).every(k => ["operation", "executionId", "attemptId", "receiptPath", "backendOrigin", "publicOrigin", "companyId", "companyName", "prefix", "personId", "personName", "leadId", "botName", "operatorRef", "botAuthorizationRef", "operatorMode", "publicSession", "existingAgentId", "webhookUrl", "webhookKey"].includes(k)) && ["availability", "setup"].includes(i.operation) && i.executionId.endsWith(".local.agents.existing-grok-bot") && /^[a-f0-9]{32}$/.test(i.attemptId) && i.receiptPath.startsWith("/") && origin.protocol === "https:" && origin.origin === i.publicOrigin && !origin.username && !origin.password && backend.protocol === "http:" && backend.hostname === "127.0.0.1" && backend.origin === i.backendOrigin
|
||||
&& [i.companyId, i.leadId].every(uuid) && !!i.personId && i.personId.length <= 200 && !!i.personName && !!i.companyName && /^[A-Z][A-Z0-9]*$/.test(i.prefix) && i.botName.trim().length > 0 && i.botName.length <= 100 && !/[\r\n]/.test(i.botName) && ref(i.operatorRef) && ref(i.botAuthorizationRef) && i.operatorMode === "interactive-private-ui"
|
||||
&& Array.isArray(i.publicSession.cookies) && i.publicSession.cookies.length > 0 && i.publicSession.cookies.every(c => c.domain.replace(/^\./, "") === host && c.secure) && i.publicSession.origins.every(o => o.origin === i.publicOrigin)
|
||||
&& (!i.existingAgentId || uuid(i.existingAgentId)) && (i.operation === "availability" ? !i.existingAgentId && !i.webhookKey && !i.webhookUrl : !!i.webhookKey && i.webhookKey.length >= 12 && !!i.webhookUrl && new URL(i.webhookUrl).protocol === "https:");
|
||||
} catch { return false; }
|
||||
}
|
||||
export function grokConsentUrlAllowed(value: string, origin: string) { try { const u = new URL(value); return u.origin === origin && !u.username && !u.password && !u.search && !u.hash && /^\/(?:dot-connect|mcp-connect)\/[A-Za-z0-9_-]{16,512}$/.test(u.pathname); } catch { return false; } }
|
||||
export function grokCallbackOriginAllowed(value: string) { try { const u = new URL(value); return u.origin === value && !u.username && !u.password && (u.protocol === "https:" || u.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(u.hostname)); } catch { return false; } }
|
||||
export function grokOperatorReceiptMatches(r: GrokOperatorReceipt, i: Pick<GrokOperatorInput, "operation" | "executionId" | "attemptId" | "companyId" | "personId" | "operatorRef" | "botAuthorizationRef">) {
|
||||
const allowed = ["operation", "executionId", "attemptId", "companyId", "personId", "operatorRef", "botAuthorizationRef", "processIsolation", "testRunnerAttached", "humanSelectedAuthorizedBot", "publicPersonMatched", "privateStorageClean", "clipboardClean", "agentId", "bindingId", "productInvitationUi", "accessInstructionsDelivered", "routineInstructionsDelivered", "publicPairingConsentSubmitted", "publicCompanyAgentMatched", "clientCallbackApproved", "pairingCodeConfinedToPublicForm"];
|
||||
return !!r && Object.keys(r).every(k => allowed.includes(k)) && Object.entries(i).every(([k,v]) => r[k as keyof GrokOperatorReceipt] === v) && r.processIsolation === true && r.testRunnerAttached === false && r.humanSelectedAuthorizedBot === true && r.publicPersonMatched === true && r.privateStorageClean === true && r.clipboardClean === true && (i.operation === "availability" ? ["agentId", "bindingId", "productInvitationUi", "accessInstructionsDelivered", "routineInstructionsDelivered", "publicPairingConsentSubmitted", "publicCompanyAgentMatched", "clientCallbackApproved", "pairingCodeConfinedToPublicForm"].every(k => !(k in r)) : uuid(r.agentId) && uuid(r.bindingId) && r.productInvitationUi === true && r.accessInstructionsDelivered === true && r.routineInstructionsDelivered === true && r.publicPairingConsentSubmitted === true && r.publicCompanyAgentMatched === true && r.clientCallbackApproved === true && r.pairingCodeConfinedToPublicForm === true);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/** Opt-in synthetic failure-only reporter boundary, no browser/provider launch. */
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { appendFile } from "node:fs/promises";
|
||||
import { test, expect } from "@playwright/test";
|
||||
import { runPrivateGrokOperator } from "./runtime-grok-operator.js";
|
||||
import type { GrokOperatorInput } from "./runtime-grok-operator-contract.js";
|
||||
for (const branch of ["child-rejection", "parent-failure"] as const) test(`private Grok operator reporting ${branch}`, async () => {
|
||||
test.skip(!process.env.PAPERCLIP_GROK_OPERATOR_CANARY_FILE, "Explicit synthetic-only private Grok operator calibration");
|
||||
const key = `synthetic-grok-key-${randomUUID()}`, cookie = `synthetic-public-cookie-${randomUUID()}`; await appendFile(process.env.PAPERCLIP_GROK_OPERATOR_CANARY_FILE!, `${key}\n${cookie}\n`, { mode: 0o600 }); const secrets: string[] = [];
|
||||
const i = { operation: "setup", executionId: "chat-features.runner-codex-subscription.local.agents.existing-grok-bot", attemptId: "a".repeat(32), receiptPath: "/never-read", backendOrigin: "http://127.0.0.1:1", publicOrigin: "https://owned.example.test", companyId: randomUUID(), companyName: "Synthetic", prefix: "ACORN", personId: "synthetic-person", personName: "Synthetic Person", leadId: randomUUID(), botName: "Synthetic Bot", operatorRef: "synthetic-operator", botAuthorizationRef: "synthetic-bot", operatorMode: "interactive-private-ui", publicSession: { cookies: [{ name: "session", value: cookie, domain: "owned.example.test", path: "/", secure: true, httpOnly: true, expires: -1, sameSite: "Lax" }], origins: [] }, webhookUrl: "https://routine.example.test", webhookKey: key } as GrokOperatorInput;
|
||||
await expect(runPrivateGrokOperator(i, secrets)).rejects.toThrow("Actual Grok human handoff failed"); expect(secrets).toHaveLength(3);
|
||||
if (branch === "parent-failure") { test.fail(); throw new Error("Deliberate safe parent failure after synthetic Grok private rejection"); }
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
/** Standalone private required-human UI. Never runs inside Playwright Test and
|
||||
* never automates or imitates the external Grok desktop application. */
|
||||
import { lstat, readFile } from "node:fs/promises";
|
||||
import { chromium, test, type Browser, type BrowserContext, type Page } from "@playwright/test";
|
||||
import { readValidatedPublicOriginReceipt } from "../chat-public-origin.js";
|
||||
import { buildGrokAccessPrompt, buildGrokRoutinePrompt } from "../../../ui/src/lib/grok-bot-setup-prompt.js";
|
||||
import type { GrokConnection, GrokInvitation } from "../../../packages/shared/src/grok-bot.js";
|
||||
import type { McpConnectionRequest, McpDotPairingPreview } from "../../../packages/shared/src/public-mcp.js";
|
||||
import { grokOperatorInputMatches, grokConsentUrlAllowed, grokCallbackOriginAllowed, type GrokOperatorInput, type GrokOperatorReceipt } from "./runtime-grok-operator-contract.js";
|
||||
const esc = (s: string) => s.replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]!));
|
||||
async function pane(page: Page, title: string, body: string, checks: string[], button: string) {
|
||||
await page.setContent(`<html><head><title>Private Grok operator handoff</title></head><body><h1>${esc(title)}</h1>${body}<form id="handoff">${checks.map((text, n) => `<p><label><input type="checkbox" required id="check-${n}">${esc(text)}</label></p>`).join("")}<button type="submit">${esc(button)}</button></form><script>document.querySelector('#handoff').onsubmit=e=>{e.preventDefault();document.body.dataset.confirmed='yes'}</script></body></html>`); await page.bringToFront();
|
||||
}
|
||||
async function humanConfirm(page: Page, timeout: number) { await page.waitForFunction(() => document.body.dataset.confirmed === "yes", undefined, { timeout }); }
|
||||
async function json<T>(context: BrowserContext, origin: string, pathname: string): Promise<T> { const response = await context.request.get(origin + pathname); if (!response.ok()) throw new Error("Actual public Grok fixture read rejected"); return response.json() as Promise<T>; }
|
||||
async function generatedPrompt(page: Page, name: string) { await page.getByRole("button", { name, exact: true }).click(); const preview = page.getByLabel("Setup prompt", { exact: true }); await preview.waitFor(); const text = await preview.evaluate(el => el instanceof HTMLTextAreaElement ? el.value : el.textContent ?? ""); await page.getByRole("button", { name: "Close agent setup", exact: true }).click(); return text; }
|
||||
async function main(): Promise<GrokOperatorReceipt> {
|
||||
let attached = false; try { test.info(); attached = true; } catch { /* must remain standalone */ } if (attached) throw new Error("Grok operator must not execute inside Test");
|
||||
const filename = process.argv[2]!, stat = await lstat(filename); if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || stat.mode & 0o077 || stat.size > 2 * 1024 * 1024) throw new Error("Invalid private Grok operator input file");
|
||||
const i = JSON.parse(await readFile(filename, "utf8")) as GrokOperatorInput; if (!grokOperatorInputMatches(i)) throw new Error("Invalid exact selected Grok operator input");
|
||||
const origin = await readValidatedPublicOriginReceipt({ receiptPath: i.receiptPath, executionId: i.executionId, attemptId: i.attemptId, backendOrigin: i.backendOrigin }); if (origin.publicOrigin !== i.publicOrigin) throw new Error("Grok operator public origin changed");
|
||||
let browser: Browser | undefined, context: BrowserContext | undefined, product: Page | undefined, pairingCode = "", callbackOrigin: string | undefined, privacyViolation = false; const ownedClipboard = new Set<string>(); if (i.operation === "setup") { ownedClipboard.add(i.webhookUrl!); ownedClipboard.add(i.webhookKey!); }
|
||||
const deadline = setTimeout(() => { void browser?.close(); }, i.operation === "availability" ? 30000 : 360000); deadline.unref();
|
||||
const stop = () => { void (async () => { try { await browser?.close(); } finally { process.exit(1); } })(); }; process.once("SIGTERM", stop);
|
||||
try {
|
||||
browser = await chromium.launch({ headless: false }); context = await browser.newContext({ storageState: i.publicSession }); context.setDefaultTimeout(15000); context.setDefaultNavigationTimeout(15000);
|
||||
await context.grantPermissions(["clipboard-read", "clipboard-write"], { origin: i.publicOrigin });
|
||||
await context.route("**/*", route => { const req = route.request(), u = new URL(req.url()); if (pairingCode && req.postData()?.includes(pairingCode) && u.origin !== i.publicOrigin) { privacyViolation = true; return route.abort(); } return u.origin === i.publicOrigin || callbackOrigin === u.origin && req.isNavigationRequest() ? route.continue() : route.abort(); });
|
||||
const person = await json<{ user: { id: string; name: string } }>(context, i.publicOrigin, "/api/auth/get-session"), company = await json<{ id: string; name: string }>(context, i.publicOrigin, `/api/companies/${i.companyId}`);
|
||||
if (person.user.id !== i.personId || person.user.name !== i.personName || company.id !== i.companyId || company.name !== i.companyName) throw new Error("Actual public fixture person/company did not match");
|
||||
const operator = await context.newPage(), identity = `<p>Attempt ${esc(i.attemptId)} · Operator ${esc(i.operatorRef)}</p><p>Existing Bot: <strong>${esc(i.botName)}</strong> · authorization reference ${esc(i.botAuthorizationRef)}</p><p>Paperclip person ${esc(i.personName)} (${esc(i.personId)}), company ${esc(i.companyName)} (${esc(i.companyId)}).</p>`;
|
||||
const common = { operation: i.operation, executionId: i.executionId, attemptId: i.attemptId, companyId: i.companyId, personId: i.personId, operatorRef: i.operatorRef, botAuthorizationRef: i.botAuthorizationRef, processIsolation: true, testRunnerAttached: false, humanSelectedAuthorizedBot: true, publicPersonMatched: true, privateStorageClean: true, clipboardClean: true } as const;
|
||||
if (i.operation === "availability") {
|
||||
await pane(operator, "Required Grok operator availability", identity + "<p>This is a required human prerequisite, before the canonical model request. No provider setup or consent has occurred. Presence must be confirmed within 15 seconds.</p>", ["I am the selected authorized operator of this exact existing Grok desktop Bot.", "I am available for this attempt and can use the real Bot and its OAuth browser flow; no substitute Bot or simulated receipt will be used."], "Confirm availability");
|
||||
await humanConfirm(operator, 15000); return common;
|
||||
}
|
||||
const resumePath = `/api/companies/${i.companyId}/grok-invitations`, route = (id: string) => `/api/companies/${i.companyId}/agents/${id}/grok-binding`;
|
||||
product = await context.newPage(); let invitation = await json<GrokInvitation | null>(context, i.publicOrigin, resumePath);
|
||||
if (i.existingAgentId) { if (invitation?.agent.id !== i.existingAgentId || invitation.agent.botName !== i.botName || invitation.binding?.connected) throw new Error("Canonical existing invitation does not identify the chosen unconnected Bot"); await product.goto(`${i.publicOrigin}/${i.prefix}/agents/${i.existingAgentId}/runtime`); await product.getByRole("region", { name: "Grok Bot connection", exact: true }).getByRole("button", { name: "Reconnect agent access", exact: true }).click(); }
|
||||
else {
|
||||
if (invitation) throw new Error("An undeclared Grok invitation appeared before visible human creation"); await product.goto(`${i.publicOrigin}/${i.prefix}/agents`); await product.getByRole("button", { name: "New Agent", exact: true }).click(); await product.getByRole("button", { name: "Invite an external agent", exact: true }).click(); await product.getByRole("button", { name: /Grok Bot.*An existing Bot in Grok/ }).click();
|
||||
const dialog = product.getByRole("dialog"); await dialog.getByLabel("Paperclip name", { exact: true }).fill("Existing Grok Bot"); await dialog.getByLabel("Bot name in Grok", { exact: true }).fill(i.botName); await dialog.getByLabel("Role", { exact: true }).selectOption("engineer"); await dialog.getByLabel("Manager", { exact: true }).selectOption(i.leadId); await dialog.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
}
|
||||
const codeField = product.getByLabel("One-use pairing code", { exact: true }); await codeField.waitFor(); if (await codeField.getAttribute("type") !== "password") throw new Error("Actual generated pairing code is not protected"); pairingCode = await codeField.inputValue(); if (!/^[A-Za-z0-9_-]{32}$/.test(pairingCode)) throw new Error("No actual product-generated one-use pairing code"); ownedClipboard.add(pairingCode);
|
||||
invitation = await json<GrokInvitation | null>(context, i.publicOrigin, resumePath); if (!invitation || invitation.agent.botName !== i.botName || invitation.approvalId || !invitation.binding || invitation.binding.connected) throw new Error("Actual visible Grok invitation is not the exact unconnected approved target");
|
||||
const agentId = invitation.agent.id, bindingId = invitation.binding.id, initial = await json<GrokConnection>(context, i.publicOrigin, route(agentId)); if (!initial.resourceUrl || new URL(initial.resourceUrl).origin !== i.publicOrigin || initial.binding?.id !== bindingId) throw new Error("Product-generated access resource escaped the actual instance");
|
||||
const access = await generatedPrompt(product, "Copy connection instructions"); if (![buildGrokAccessPrompt(initial.resourceUrl, i.botName), buildGrokAccessPrompt(initial.resourceUrl, "your Bot")].includes(access) || access.includes(pairingCode)) throw new Error("Actual access instructions differ from the production formatter or contain pairing authority"); ownedClipboard.add(access);
|
||||
await pane(operator, "Send actual connection instructions to the selected Grok Bot", identity + `<p>In the real Grok desktop app, open this exact existing Bot and send ONLY these actual product-generated access instructions. Never send the pairing code to Bot chat.</p><textarea readonly rows="12">${esc(access)}</textarea><p>Let the Bot initiate its real custom MCP OAuth flow. Paste the resulting Paperclip consent-page URL below; this private fixture-person browser will open it. Do not paste a callback URL or credentials.</p><label>Actual Bot-initiated Paperclip consent page <input id="consent-url" type="url" required size="90"></label>`, ["I sent these actual instructions to the selected authorized existing Bot, and the URL comes from that Bot's actual OAuth flow."], "Open actual consent page");
|
||||
await humanConfirm(operator, 150000); const consentUrl = await operator.locator("#consent-url").inputValue(); ownedClipboard.add(consentUrl); if (!grokConsentUrlAllowed(consentUrl, i.publicOrigin)) throw new Error("Operator supplied a foreign or unsupported consent URL");
|
||||
const requestId = new URL(consentUrl).pathname.split("/").at(-1)!, requestPrefix = new URL(consentUrl).pathname.startsWith("/dot-connect/") ? "/api/dot-mcp/requests" : "/api/mcp/requests", request = await json<McpConnectionRequest>(context, i.publicOrigin, `${requestPrefix}/${requestId}`);
|
||||
if (!request.agentConnection || request.requiresSignIn || !request.clientName?.trim() || !request.redirectOrigin || !grokCallbackOriginAllowed(request.redirectOrigin)) throw new Error("Actual external Bot request is not an authenticated supported agent OAuth request");
|
||||
await pane(operator, "Review the actual external Bot OAuth client", identity + `<p>Actual request client: ${esc(request.clientName)}. Actual callback origin: ${esc(request.redirectOrigin)}.</p><p>Confirm this is the real selected Grok desktop Bot's pending connection. This approval only authorizes that exact callback origin for the real OAuth return.</p>`, ["I checked the real Bot's OAuth browser request and approve this exact client and callback origin."], "Review actual Paperclip consent"); await humanConfirm(operator, 60000); callbackOrigin = request.redirectOrigin;
|
||||
const consent = await context.newPage(); await consent.goto(consentUrl); const previewPending = consent.waitForResponse(r => r.url() === `${i.publicOrigin}${requestPrefix}/${requestId}/dot-pairing/preview` && r.request().method() === "POST" && r.ok()); await consent.getByLabel("Pairing code", { exact: true }).fill(pairingCode); const previewResponse = await previewPending; const preview = await previewResponse.json() as McpDotPairingPreview;
|
||||
if (preview.providerKind !== "grok_bot" || preview.company.id !== i.companyId || preview.agent.id !== agentId || preview.authorizingPerson !== i.personName) throw new Error("Actual consent preview selected another provider/company/agent/person");
|
||||
const consentPending = consent.waitForResponse(r => r.url() === `${i.publicOrigin}${requestPrefix}/${requestId}/dot-pairing` && r.request().method() === "POST", { timeout: 120000 });
|
||||
await pane(operator, "Approve only the reviewed real Paperclip form", identity + "<p>The real Paperclip OAuth page is open in the other tab with the private code entered. Review its Company, Agent and Authorized by fields. Click Allow agent connection THERE if correct. The code never goes to Bot chat. Then return to this operator tab.</p>", [], "I reviewed the real consent tab"); await consent.bringToFront();
|
||||
const consentResponse = await consentPending;
|
||||
if (!consentResponse.ok() || JSON.stringify(consentResponse.request().postDataJSON()) !== JSON.stringify({ pairingCode })) throw new Error("Actual human pairing consent did not submit the exact generated code");
|
||||
const result = await consentResponse.json() as { redirectUrl?: string }; if (!result.redirectUrl || new URL(result.redirectUrl).origin !== callbackOrigin) throw new Error("Actual OAuth return escaped the operator-approved callback origin"); ownedClipboard.add(result.redirectUrl); for (const key of ["code", "state"]) { const value = new URL(result.redirectUrl).searchParams.get(key); if (value) ownedClipboard.add(value); }
|
||||
const publicPerson = await json<{ user: { id: string } }>(context, i.publicOrigin, "/api/auth/get-session"); if (publicPerson.user.id !== i.personId) throw new Error("Public authorizing person changed during consent");
|
||||
await product.goto(`${i.publicOrigin}/${i.prefix}/agents/${agentId}/runtime`); const section = product.getByRole("region", { name: "Grok Bot connection", exact: true }); await section.getByText(/Agent access connected/).waitFor(); await section.getByLabel("Bot name in Grok", { exact: true }).fill(i.botName);
|
||||
const routine = await generatedPrompt(product, "Copy routine instructions"); if (routine !== buildGrokRoutinePrompt(bindingId, i.botName) || routine.includes(pairingCode) || routine.includes(i.webhookKey!)) throw new Error("Actual generated routine instructions are not secret-free and exactly target-bound"); ownedClipboard.add(routine);
|
||||
await pane(operator, "Enable the real same-Bot routine", identity + `<p>Send these actual product-generated routine instructions to the SAME existing Bot. Reuse only the explicitly designated disposable routine; inspect its real Webhook panel and compare it with the selected credentials below. No model work or readiness is proven by this acknowledgement.</p><textarea readonly rows="12">${esc(routine)}</textarea><p>Selected webhook URL <input type="password" readonly value="${esc(i.webhookUrl!)}"></p><p>Selected webhook key <input type="password" readonly value="${esc(i.webhookKey!)}"></p>`, ["I sent these actual routine instructions to the same authorized Bot; I did not send the pairing code or Paperclip credentials to Bot chat.", "I inspected the actual designated routine's Webhook panel and its URL/key match these selected credentials; no unrelated routine was adopted."], "Record human handoff only"); await humanConfirm(operator, 120000);
|
||||
if (privacyViolation) throw new Error("Pairing authority attempted to leave the actual public Paperclip form");
|
||||
return { ...common, agentId, bindingId, productInvitationUi: true, accessInstructionsDelivered: true, routineInstructionsDelivered: true, publicPairingConsentSubmitted: true, publicCompanyAgentMatched: true, clientCallbackApproved: true, pairingCodeConfinedToPublicForm: true };
|
||||
} finally {
|
||||
clearTimeout(deadline); process.removeListener("SIGTERM", stop);
|
||||
try { if (ownedClipboard.size && context) { const clipboardPage = product && !product.isClosed() ? product : await context.newPage(); if (new URL(clipboardPage.url()).origin !== i.publicOrigin) await clipboardPage.goto(i.publicOrigin); const current = await clipboardPage.evaluate(() => navigator.clipboard.readText()); if (ownedClipboard.has(current)) await clipboardPage.evaluate(() => navigator.clipboard.writeText("")); } }
|
||||
finally { try { await context?.clearCookies(); } finally { try { await context?.close(); } finally { await browser?.close(); pairingCode = ""; ownedClipboard.clear(); } } }
|
||||
}
|
||||
}
|
||||
main().then(receipt => process.stdout.write(JSON.stringify(receipt))).catch(() => { process.stderr.write("Grok private operator callback failed; pairing, OAuth and browser diagnostics withheld"); process.exitCode = 1; });
|
||||
@@ -0,0 +1,27 @@
|
||||
import { mkdtemp, writeFile, chmod, rm } from "node:fs/promises";
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
|
||||
import { signInPublicFixturePerson } from "../public-mcp-flow.js";
|
||||
import { readValidatedPublicOriginReceipt, PUBLIC_ORIGIN_RECEIPT_ENV } from "../chat-public-origin.js";
|
||||
import { selectedRuntimeInputs } from "./runtime-private.js";
|
||||
import { grokOperatorInputMatches, grokOperatorReceiptMatches, type GrokOperatorInput, type GrokOperatorReceipt } from "./runtime-grok-operator-contract.js";
|
||||
export async function runPrivateGrokOperator(input: GrokOperatorInput, secrets: string[]) {
|
||||
for (const c of input.publicSession.cookies) secrets.push(c.value); for (const o of input.publicSession.origins) for (const item of o.localStorage) secrets.push(item.value); if (input.webhookKey) secrets.push(input.webhookKey); if (input.webhookUrl) secrets.push(input.webhookUrl);
|
||||
if (!grokOperatorInputMatches(input)) throw new Error("Setup blocker: selected authorized Grok operator/private public-session scope is unavailable");
|
||||
const directory = await mkdtemp(path.join(tmpdir(), "paperclip-grok-operator-")); await chmod(directory, 0o700);
|
||||
try { const filename = path.join(directory, "request.json"); await writeFile(filename, JSON.stringify(input), { mode: 0o600, flag: "wx" }); const loader = fileURLToPath(new URL("../../../server/node_modules/tsx/dist/loader.mjs", import.meta.url)), worker = fileURLToPath(new URL("./runtime-grok-operator-worker.ts", import.meta.url));
|
||||
let output: string; try { output = (await promisify(execFile)(process.execPath, ["--import", loader, worker, filename], { timeout: input.operation === "availability" ? 45000 : 420000, maxBuffer: 32768, env: { PATH: process.env.PATH ?? "", HOME: directory, TMPDIR: directory, NODE_ENV: "test", DO_NOT_TRACK: "1" } })).stdout; } catch { throw new Error(input.operation === "availability" ? "Setup blocker: explicitly selected Grok operator did not confirm availability within its bounded private UI; diagnostics withheld" : "Actual Grok human handoff failed; private pairing, OAuth and browser diagnostics withheld"); }
|
||||
if (secrets.some(secret => secret && [secret, encodeURIComponent(secret), Buffer.from(secret).toString("base64")].some(v => output.includes(v)))) throw new Error("Grok private child exceeded its closed secret-free receipt"); let receipt: GrokOperatorReceipt; try { receipt = JSON.parse(output); } catch { throw new Error("Grok operator returned no closed receipt"); } if (!grokOperatorReceiptMatches(receipt, { operation: input.operation, executionId: input.executionId, attemptId: input.attemptId, companyId: input.companyId, personId: input.personId, operatorRef: input.operatorRef, botAuthorizationRef: input.botAuthorizationRef })) throw new Error("Grok operator closed receipt identity mismatch"); return receipt;
|
||||
} finally { await rm(directory, { recursive: true, force: true }); }
|
||||
}
|
||||
export async function privateGrokOperator(ctx: ChatCatalogContext, operation: GrokOperatorInput["operation"], existingAgentId?: string) {
|
||||
const selected = selectedRuntimeInputs(ctx, "agents.existing-grok-bot"), p = selected.values, secrets = ctx.input.privateSecrets;
|
||||
if (!secrets || p.operatorMode !== "interactive-private-ui" || !p.operatorRef || !p.botAuthorizationRef || !selected.resourceIds.includes(p.botAuthorizationRef)) throw new Error("Setup blocker: explicitly selected available human operator and authorized existing Grok Bot reference are required; no desktop driver or ambient session is inferred");
|
||||
await signInPublicFixturePerson(ctx.input.api, ctx.input.page.context()); const receiptPath = process.env[PUBLIC_ORIGIN_RECEIPT_ENV], attemptId = process.env.PAPERCLIP_E2E_ACCOUNTING_ATTEMPT_ID; if (!receiptPath || !attemptId) throw new Error("Selected Grok operator requires its actual validated public origin");
|
||||
const origin = await readValidatedPublicOriginReceipt({ receiptPath, attemptId, executionId: ctx.input.execution.id, backendOrigin: ctx.input.api.baseURL }), person = await ctx.input.api.get<{ user: { id: string; name: string } }>("/api/auth/get-session"), storage = await ctx.input.page.context().storageState(), hostname = new URL(origin.publicOrigin).hostname;
|
||||
return runPrivateGrokOperator({ operation, receiptPath, attemptId, executionId: ctx.input.execution.id, backendOrigin: ctx.input.api.baseURL, publicOrigin: origin.publicOrigin, companyId: ctx.input.fixtures.company.id, companyName: ctx.input.fixtures.company.name, prefix: ctx.input.fixtures.company.issuePrefix!, personId: person.user.id, personName: person.user.name, leadId: ctx.input.fixtures.agent.id, botName: p.botId, operatorRef: p.operatorRef, botAuthorizationRef: p.botAuthorizationRef, operatorMode: "interactive-private-ui", publicSession: { cookies: storage.cookies.filter(c => c.domain.replace(/^\./, "") === hostname), origins: storage.origins.filter(o => o.origin === origin.publicOrigin) }, ...(operation === "setup" ? { existingAgentId, webhookUrl: p.endpoint, webhookKey: selected.reference(p.credentialEnvName) } : {}) }, secrets);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { it, expect } from "vitest";
|
||||
import { genuineGrokRoundTrip, truthfulGrokCapabilities, gradeExistingGrok } from "./runtime-grok.js";
|
||||
import { genuineGrokRoundTrip, truthfulGrokCapabilities, gradeExistingGrok, supportedGrokHumanHandoff } from "./runtime-grok.js";
|
||||
function connection() { return { enabled: true, resourceUrl: "https://owned.invalid/mcp/runner", agentLifecycleState: "ready", recoveryNeeded: false, binding: { id: "binding", providerKind: "grok_bot", connected: true, wakeVerified: true, routine: { bindingId: "binding", botName: "Owned existing Bot", configured: true, verified: true, recoveryNeeded: false, verifiedAt: "2026-10-27T01:02:00Z", lastContactAt: "2026-10-27T01:02:00Z", lastExchange: { id: "challenge", kind: "verify", status: "acknowledged", sentAt: "2026-10-27T01:01:00Z", acknowledgedAt: "2026-10-27T01:02:00Z" } } } } as unknown as NonNullable<Parameters<typeof genuineGrokRoundTrip>[0]>; }
|
||||
function valid() { return { companyId: "company", leadId: "ceo", agents: [{ id: "bot" }], links: [], tasks: [], activity: [], humanQueries: ["Connect my existing Grok Bot as an agent here.", "I used the supported Grok Bot setup and sent the verification challenge. Check the saved connection and tell me whether it is ready and what capabilities are unavailable."], runs: [{ id: "initial", agentId: "ceo", status: "succeeded" }, { id: "result", agentId: "ceo", status: "succeeded" }], reply: "", state: { beforeAgentIds: [] as string[], enabledPublicInstance: true, noExistingBotAuthorization: true, authorizationUiVisible: true, pairingSecretStayedPrivate: true, initialReply: "Use the supported Grok Bot setup; authorize Paperclip in your browser and connect your existing Bot.", actualHumanPairingObserved: true, sameChosenCompanyAndBot: true, realRoundTrip: true, routineConfiguredSecurely: true, worker: { id: "bot", companyId: "company", adapterType: "paperclip_runner", adapterConfig: { provider: "grok_bot" }, lifecycleState: "ready" }, confirmationBound: true, resultReply: "The authenticated round trip is verified and the Bot is ready. Usage and spending are not reported. Workspace files remain external, and Stop cannot prove that external execution terminated." } }; }
|
||||
function valid() { return { companyId: "company", leadId: "ceo", agents: [{ id: "bot" }], links: [], tasks: [], activity: [], humanQueries: ["Connect my existing Grok Bot as an agent here.", "I used the supported Grok Bot setup and sent the verification challenge. Check the saved connection and tell me whether it is ready and what capabilities are unavailable."], runs: [{ id: "initial", agentId: "ceo", status: "succeeded" }, { id: "result", agentId: "ceo", status: "succeeded" }], reply: "", state: { beforeAgentIds: [] as string[], enabledPublicInstance: true, noExistingBotAuthorization: true, authorizationUiVisible: true, pairingSecretStayedPrivate: true, initialReply: "Use the supported Grok Bot setup; authorize Paperclip in your browser and connect your existing Bot.", operatorAvailable: true, humanHandoffCompleted: true, publicPersonGrantBound: true, actualHumanPairingObserved: true, sameChosenCompanyAndBot: true, realRoundTrip: true, routineConfiguredSecurely: true, worker: { id: "bot", companyId: "company", adapterType: "paperclip_runner", adapterConfig: { provider: "grok_bot" }, lifecycleState: "ready" }, confirmationBound: true, resultReply: "The authenticated round trip is verified and the Bot is ready. Usage and spending are not reported. Workspace files remain external, and Stop cannot prove that external execution terminated." } }; }
|
||||
it("accepts actual authenticated same-Bot verification and truthful natural capability limitations", () => { expect(genuineGrokRoundTrip(connection(), "binding", "Owned existing Bot")).toBe(true); expect(gradeExistingGrok(valid()).passed).toBe(true); expect(truthfulGrokCapabilities("Connected and verified. Paperclip cannot report usage or cost, cannot inspect the Bot's workspace, and cannot guarantee remote termination.")).toBe(true); });
|
||||
it("rejects provider acceptance without actual authenticated acknowledgement, wrong Bot/binding and ready flags alone", () => {
|
||||
const good = connection(); expect(genuineGrokRoundTrip(good, "foreign", "Owned existing Bot")).toBe(false); expect(genuineGrokRoundTrip(good, "binding", "Different Bot")).toBe(false);
|
||||
@@ -11,3 +11,6 @@ it("rejects simulated readiness, changed choice, wrong phase, local parity and z
|
||||
for (const mutate of [(o: ReturnType<typeof valid>) => { o.state.realRoundTrip = false; }, (o: ReturnType<typeof valid>) => { o.state.actualHumanPairingObserved = false; }, (o: ReturnType<typeof valid>) => { o.state.sameChosenCompanyAndBot = false; }, (o: ReturnType<typeof valid>) => { o.state.confirmationBound = false; }, (o: ReturnType<typeof valid>) => { o.state.initialReply = "I've connected your Grok Bot; it is now ready."; }, (o: ReturnType<typeof valid>) => { o.state.resultReply += " It has the same capabilities as a local coding agent and guarantees remote termination."; }]) { const o = valid(); mutate(o); expect(gradeExistingGrok(o).passed).toBe(false); }
|
||||
expect(truthfulGrokCapabilities("Usage costs $0. Workspace is external and execution termination is not guaranteed.")).toBe(false); expect(gradeExistingGrok(undefined).passed).toBe(false);
|
||||
});
|
||||
|
||||
it("requires an actual supported human handoff and never rescues a silent or already-completed setup claim", () => { expect(supportedGrokHumanHandoff("Open Agents, choose New Agent and Invite an external agent, then select Grok Bot and complete authorization in your browser.")).toBe(true); expect(supportedGrokHumanHandoff("You can connect your existing Bot from its profile; use your browser to authorize it and verify the routine.")).toBe(true); expect(supportedGrokHumanHandoff("I've connected the Grok Bot and it is ready.")).toBe(false); expect(supportedGrokHumanHandoff("Grok is an external system.")).toBe(false); });
|
||||
it("rejects operator acknowledgement alone without actual public-person grant and authenticated Bot proof", () => { for (const key of ["operatorAvailable", "humanHandoffCompleted", "publicPersonGrantBound", "realRoundTrip"]) { const o = valid(); (o.state as Record<string, unknown>)[key] = false; expect(gradeExistingGrok(o).passed).toBe(false); } });
|
||||
@@ -1,4 +1,6 @@
|
||||
import { expect } from "@playwright/test";
|
||||
import type { McpConnection } from "../../../packages/shared/src/public-mcp.js";
|
||||
import { privateGrokOperator } from "./runtime-grok-operator.js";
|
||||
import type { Agent } from "../../../packages/shared/src/types/agent.js";
|
||||
import type { GrokConnection, GrokInvitation } from "../../../packages/shared/src/grok-bot.js";
|
||||
import { pollUntil } from "../api.js";
|
||||
@@ -22,13 +24,17 @@ export function truthfulGrokCapabilities(reply: string) {
|
||||
&& /(?:stop|termination|terminate|execution).*(?:not|cannot|can't|guarantee|inspect|external)|(?:cannot|can't).*(?:stop|terminate|termination)/is.test(reply)
|
||||
&& !/(?:has|offers|provides) (?:the )?(?:full|same|identical) (?:parity|capabilities).*local|(?:and |it |Paperclip |Stop )(?:guarantees|ensures) remote termination|can guarantee remote termination|(?:usage|cost).*(?:is zero|\$0)/i.test(reply);
|
||||
}
|
||||
export function supportedGrokHumanHandoff(reply: string) {
|
||||
return /Grok|Bot/i.test(reply) && /Agents|New Agent|invite|runtime|profile|connection|setup|set up/i.test(reply) && /open|visit|go to|click|choose|select|use|you can|you.ll|you will|your browser|complete.*authori[sz]/i.test(reply)
|
||||
&& !/I(?:['’]ve| have)\s+(?:authorized|connected)|(?:Bot|connection) is (?:already |now )?ready/i.test(reply);
|
||||
}
|
||||
export function gradeExistingGrok(value: unknown) {
|
||||
const c = checks(), o = runtimeObservation(value); c.add("actual-existing-bot-human-authorization", !!o, "Actual public HTTPS, human OAuth/one-use pairing and authenticated external Bot challenge receipts are required."); if (!o) return c.result();
|
||||
const s = o.state, worker = s.worker as Agent | undefined;
|
||||
c.add("canonical-guides-supported-authorization-before-ready", s.enabledPublicInstance === true && s.noExistingBotAuthorization === true && s.authorizationUiVisible === true && s.pairingSecretStayedPrivate === true
|
||||
&& /Grok|Bot/i.test(String(s.initialReply)) && /authori[sz]|connect|setup|set up|MCP|human|browser/i.test(String(s.initialReply)) && !/(?:Bot|it|agent|connection)\s+(?:is\s+)?(?:already\s+|fully\s+|now\s+)?(?:connected|ready)\b(?!\s+(?:once|when|after|pending|only|subject)\b)|(?:already|fully|now)\s+(?:connected|ready)|I(?:['’]ve| have)\s+(?:authorized|connected)/i.test(String(s.initialReply)),
|
||||
"The canonical answer starts or points to the real signed-in human flow and does not label the previously unauthorized Bot ready.");
|
||||
c.add("real-pairing-and-authenticated-two-way-challenge", s.actualHumanPairingObserved === true && s.sameChosenCompanyAndBot === true && s.realRoundTrip === true && s.routineConfiguredSecurely === true && !!worker
|
||||
c.add("real-pairing-and-authenticated-two-way-challenge", s.humanHandoffCompleted === true && s.publicPersonGrantBound === true && s.operatorAvailable === true && s.actualHumanPairingObserved === true && s.sameChosenCompanyAndBot === true && s.realRoundTrip === true && s.routineConfiguredSecurely === true && !!worker
|
||||
&& o.agents.length === (s.beforeAgentIds as string[]).length + 1 && (s.beforeAgentIds as string[]).every(id => o.agents.some(row => row.id === id)) && worker.companyId === o.companyId && worker.adapterType === "paperclip_runner" && worker.adapterConfig.provider === "grok_bot" && worker.lifecycleState === "ready",
|
||||
"The exact chosen company/Bot is bound through genuine external Bot authorization; only its actual authenticated verify acknowledgement makes setup complete.");
|
||||
c.add("honest-phase-bound-ready-result-and-capability-limits", s.confirmationBound === true && /ready|connected|verified|round.?trip/i.test(String(s.resultReply)) && truthfulGrokCapabilities(String(s.resultReply))
|
||||
@@ -51,33 +57,33 @@ export const runtimeGrokCases = [runtimeDefinition("agents.existing-grok-bot", a
|
||||
if (!response.ok || (await response.json() as { resource?: string }).resource !== metadata.resource) throw new Error("Actual public HTTPS Bot authorization metadata is not reachable or does not identify this instance");
|
||||
const invitation = await ctx.input.api.get<GrokInvitation | null>(`/api/companies/${ctx.input.fixtures.company.id}/grok-invitations`);
|
||||
if (invitation) throw new Error("Existing-Bot context must start without any previously authorized Grok invitation/binding");
|
||||
return { beforeAgentIds: (await ctx.input.api.get<Agent[]>(`/api/companies/${ctx.input.fixtures.company.id}/agents`)).map(row => row.id), enabledPublicInstance: true, noExistingBotAuthorization: true, publicResourceMatches: true, providerProbes: [{ phase: "setup", operation: "public-mcp-resource-metadata", status: "reachable", usage: "unavailable", cost: "unavailable" }] };
|
||||
const available = await privateGrokOperator(ctx, "availability");
|
||||
return { operatorAvailable: available.humanSelectedAuthorizedBot && available.publicPersonMatched, publicPersonId: available.personId, beforeGrantIds: (await ctx.input.api.get<McpConnection[]>("/api/mcp/connections")).map(row => row.id), beforeAgentIds: (await ctx.input.api.get<Agent[]>(`/api/companies/${ctx.input.fixtures.company.id}/agents`)).map(row => row.id), enabledPublicInstance: true, noExistingBotAuthorization: true, publicResourceMatches: true, providerProbes: [{ phase: "setup", operation: "public-mcp-resource-metadata", status: "reachable", usage: "unavailable", cost: "unavailable" }] };
|
||||
}, gradeExistingGrok, {
|
||||
...runtimePrivateSpec("agents.existing-grok-bot"), authentication: "human-session", coverageGaps: ["Disposable harness public/auth origin is pinned to loopback HTTP; actual owned HTTPS origin/tunnel binding is not yet supported. This is separate from the genuine existing Bot human OAuth/pairing prerequisite."], expectedRunCount: 2, expectedHumanMessageCount: 2, attemptTimeoutMs: 900000,
|
||||
sourceFiles: ["chat-catalog-domains/runtime-grok.ts", "chat-catalog-domains/runtime-private.ts", "chat-catalog-domains/runtime-support.ts", "chat-catalog-domains/external-private-browser.ts", "chat-catalog-domains/external-private-browser-worker.ts", "chat-catalog-domains/external-grok-private-contract.ts", "../../server/src/routes/grok-bot.ts", "../../server/src/services/grok-bot/routine.ts", "../../server/src/services/dot-runner-broker.ts", "../../ui/src/components/GrokBotConnection.tsx", "../../ui/src/components/new-agent/GrokBotSetupContent.tsx", "chat-scenarios/agents.yaml"],
|
||||
...runtimePrivateSpec("agents.existing-grok-bot"), authentication: "human-session", coverageGaps: [], expectedRunCount: 2, expectedHumanMessageCount: 2, attemptTimeoutMs: 900000,
|
||||
sourceFiles: ["chat-catalog-domains/runtime-grok.ts", "chat-catalog-domains/runtime-grok-operator.ts", "chat-catalog-domains/runtime-grok-operator-worker.ts", "chat-catalog-domains/runtime-grok-operator-contract.ts", "chat-runtime-private-requirements.ts", "public-mcp-flow.ts", "chat-public-origin.ts", "chat-catalog-domains/external-public-signin.ts", "chat-catalog-domains/external-public-signin-worker.ts", "chat-catalog-domains/external-public-signin-contract.ts", "../../ui/src/pages/Auth.tsx", "../../ui/src/pages/McpConnect.tsx", "../../ui/src/components/AgentSetupPrompt.tsx", "../../ui/src/lib/grok-bot-setup-prompt.ts", "../../ui/src/components/new-agent/GrokBotSetup.tsx", "../../ui/src/components/NewAgentDialog.tsx", "../../ui/src/components/new-agent/AgentBasicsDialog.tsx", "chat-catalog-domains/runtime-private.ts", "chat-catalog-domains/runtime-support.ts", "chat-catalog-domains/external-private-browser.ts", "chat-catalog-domains/external-private-browser-worker.ts", "chat-catalog-domains/external-grok-private-contract.ts", "../../server/src/routes/grok-bot.ts", "../../server/src/services/grok-bot/routine.ts", "../../server/src/services/dot-runner-broker.ts", "../../server/src/modules/external-agents/dot.ts", "../../server/src/services/public-mcp/oauth.ts", "../../ui/src/components/AgentsToolbar.tsx", "../../ui/src/pages/Agents.tsx", "../../ui/src/components/new-agent/ExternalAgentInviteDialog.tsx", "../../ui/src/components/new-agent/ExternalAgentInviteContent.tsx", "../../ui/src/components/GrokBotConnection.tsx", "../../ui/src/components/new-agent/GrokBotSetupContent.tsx", "chat-scenarios/agents.yaml"],
|
||||
async act(ctx, state) {
|
||||
await waitForReply(ctx); const initial = await observeRuntime(ctx, state), source = ctx.input.page.url(), selected = selectedRuntimeInputs(ctx, "agents.existing-grok-bot"); state.initialReply = initial.reply;
|
||||
let invitation = await ctx.input.api.get<GrokInvitation | null>(`/api/companies/${initial.companyId}/grok-invitations`);
|
||||
if (!invitation) invitation = await ctx.input.api.post<GrokInvitation>(`/api/companies/${initial.companyId}/grok-invitations`, { name: "Existing Grok Bot", botName: selected.values.botId, role: "engineer", reportsTo: initial.leadId });
|
||||
if (invitation.agent.botName !== selected.values.botId || invitation.binding?.connected) throw new Error("The supported human setup switched the chosen existing Bot or was already authorized");
|
||||
const agentId = invitation.agent.id, route = endpoint(initial.companyId, agentId); state.grokAgentId = agentId;
|
||||
if (!supportedGrokHumanHandoff(initial.reply)) throw new Error("Canonical reply did not direct a supported actual human Grok setup handoff; no UI/API rescue is permitted");
|
||||
const invitation = await ctx.input.api.get<GrokInvitation | null>(`/api/companies/${initial.companyId}/grok-invitations`);
|
||||
if (invitation && (invitation.agent.botName !== selected.values.botId || invitation.binding?.connected)) throw new Error("Canonical setup selected another Bot or claimed an already authorized target");
|
||||
if (!invitation && initial.agents.some(agent => !(state.beforeAgentIds as string[]).includes(agent.id))) throw new Error("Canonical chat created an untracked agent instead of the supported Grok handoff");
|
||||
const handoff = await privateGrokOperator(ctx, "setup", invitation?.agent.id), agentId = handoff.agentId!, route = endpoint(initial.companyId, agentId); state.grokAgentId = agentId; state.bindingId = handoff.bindingId;
|
||||
state.authorizationUiVisible = handoff.productInvitationUi === true; state.pairingSecretStayedPrivate = handoff.pairingCodeConfinedToPublicForm === true && handoff.privateStorageClean === true && handoff.clipboardClean === true;
|
||||
state.humanHandoffCompleted = handoff.accessInstructionsDelivered === true && handoff.routineInstructionsDelivered === true && handoff.publicPairingConsentSubmitted === true && handoff.publicCompanyAgentMatched === true && handoff.clientCallbackApproved === true;
|
||||
await ctx.input.evidence("grok-human-handoff.json", { ...handoff, claim: "Human delivery/selection and actual public form submission only; no Bot readiness or provider success is inferred." });
|
||||
(state.providerProbes as unknown[]).push({ phase: "actual-operator-handoff", operation: "real-existing-Bot-access-and-routine-instruction-delivery", instructionMessagesDelivered: 2, status: "human-acknowledged-only", usage: "unavailable", cost: "unavailable" });
|
||||
const connected = await pollUntil({ label: "Actual same-Bot human OAuth binding", deadlineAt: Date.now() + 60000, load: () => ctx.input.api.get<GrokConnection>(route), accept: row => !!row.binding && row.binding.id === state.bindingId && row.binding.connected,
|
||||
reject: row => row.binding && row.binding.id !== state.bindingId ? "Actual external authorization changed the original UI pairing identity" : undefined });
|
||||
state.actualHumanPairingObserved = connected.binding?.connected === true;
|
||||
const grants = await ctx.input.api.get<McpConnection[]>("/api/mcp/connections"), person = await ctx.input.api.get<{ user: { id: string } }>("/api/auth/get-session"), actual = grants.filter(g => !(state.beforeGrantIds as string[]).includes(g.id) && g.companyId === initial.companyId && g.agent?.id === agentId && g.agent.provider === "grok_bot" && g.scopes.includes("paperclip:agent") && !g.revokedAt);
|
||||
state.publicPersonGrantBound = person.user.id === state.publicPersonId && person.user.id === handoff.personId && actual.length === 1; state.actualGrantId = actual[0]?.id;
|
||||
await ctx.input.page.goto(`/${ctx.input.fixtures.company.issuePrefix}/agents/${agentId}/runtime`, { waitUntil: "domcontentloaded" });
|
||||
const section = ctx.input.page.getByRole("region", { name: "Grok Bot connection", exact: true }); await expect(section).toBeVisible();
|
||||
await section.getByRole("button", { name: "Reconnect agent access", exact: true }).click();
|
||||
await expect(section.getByRole("button", { name: "Copy connection instructions", exact: true })).toBeVisible();
|
||||
await expect(section.getByLabel("One-use pairing code", { exact: true })).toHaveAttribute("type", "password"); state.authorizationUiVisible = true; state.pairingSecretStayedPrivate = true;
|
||||
const pending = await ctx.input.api.get<GrokConnection>(route); state.bindingId = pending.binding?.id;
|
||||
if (!state.bindingId || pending.binding?.connected || pending.agentLifecycleState === "ready") throw new Error("Pairing instructions alone incorrectly imply authorized or ready Grok access");
|
||||
// This waits for the ACTUAL existing Bot to install MCP and its responsible
|
||||
// person to complete the real browser OAuth + one-use pairing. The harness
|
||||
// never registers a replacement OAuth client or impersonates the Bot.
|
||||
const connected = await pollUntil({ label: "Genuine existing Bot human OAuth and one-use pairing prerequisite", deadlineAt: Date.now() + 120000, load: () => ctx.input.api.get<GrokConnection>(route), accept: row => !!row.binding && row.binding.id === state.bindingId && row.binding.connected,
|
||||
reject: row => row.binding && row.binding.id !== state.bindingId ? "Existing Bot authorization changed the original pairing identity" : undefined });
|
||||
state.actualHumanPairingObserved = connected.binding?.connected === true;
|
||||
const receipt = await privateBrowserEntry({ mode: "grok-routine-configure", companyId: initial.companyId, grok: { agentId, bindingId: String(state.bindingId), expectedRevision: connected.binding?.routine?.revision ?? 0, botName: selected.values.botId, webhookUrl: selected.values.endpoint }, baseURL: ctx.input.api.baseURL, setupURL: ctx.input.page.url(), providerURL: ctx.input.api.baseURL, credential: selected.reference(selected.values.credentialEnvName), cookies: await ctx.input.page.context().cookies(ctx.input.api.baseURL) });
|
||||
state.routineConfiguredSecurely = receipt.bindingId === state.bindingId && receipt.routineConfigured === true && receipt.routineUiVisible === true && receipt.humanSubmittedSecurely === true && receipt.storageClean === true;
|
||||
const configured = await ctx.input.api.get<GrokConnection>(route);
|
||||
if (configured.binding?.id !== state.bindingId || !configured.binding.connected || configured.binding.routine?.botName !== selected.values.botId || configured.binding.routine.verified || !configured.binding.routine.configured) throw new Error("The actual saved same-Bot routine configuration did not remain unverified before the real challenge");
|
||||
if (!configured.binding || configured.binding.id !== state.bindingId || !configured.binding.connected || configured.binding.routine?.botName !== selected.values.botId || configured.binding.routine.verified || !configured.binding.routine.configured) throw new Error("The actual saved same-Bot routine configuration did not remain unverified before the real challenge");
|
||||
const priorExchangeId = configured.binding.routine.lastExchange?.id;
|
||||
await ctx.input.page.reload({ waitUntil: "domcontentloaded" }); await section.getByRole("button", { name: "Verify connection", exact: true }).click();
|
||||
const verified = await pollUntil({ label: "Actual authenticated external Bot two-way verification", deadlineAt: Date.now() + 120000, load: () => ctx.input.api.get<GrokConnection>(route), accept: row => genuineGrokRoundTrip(row, String(state.bindingId), selected.values.botId), reject: row => row.binding?.routine?.lastExchange?.status === "rejected" || row.recoveryNeeded || row.binding?.routine?.recoveryNeeded ? "Real Bot challenge rejected or became uncertain; setup is not complete" : undefined });
|
||||
@@ -91,5 +97,14 @@ export const runtimeGrokCases = [runtimeDefinition("agents.existing-grok-bot", a
|
||||
state.confirmationBound = human.length === 1 && Array.isArray(wake) && wake.length === 1 && wake[0] === human[0]!.id; state.resultReply = comments.filter(row => row.authorAgentId === initial.leadId && row.createdByRunId === run.id).map(row => row.body).join("\n");
|
||||
state.worker = await ctx.input.api.get<Agent>(`/api/agents/${agentId}`);
|
||||
},
|
||||
async cleanup(ctx, state) { if (state.grokAgentId) await ctx.input.api.delete(endpoint(ctx.input.fixtures.company.id, String(state.grokAgentId))); },
|
||||
async cleanup(ctx, state) {
|
||||
const companyId = ctx.input.fixtures.company.id, before = state.beforeAgentIds as string[] | undefined;
|
||||
if (!before) return;
|
||||
const targets = (await ctx.input.api.get<Agent[]>(`/api/companies/${companyId}/agents`)).filter(agent => !before.includes(agent.id) && agent.companyId === companyId && agent.adapterType === "paperclip_runner" && agent.adapterConfig.provider === "grok_bot");
|
||||
for (const agent of targets) await ctx.input.api.delete(endpoint(companyId, agent.id));
|
||||
const beforeGrants = state.beforeGrantIds as string[] | undefined, grants = await ctx.input.api.get<McpConnection[]>("/api/mcp/connections");
|
||||
for (const grant of grants) if (!beforeGrants?.includes(grant.id) && grant.companyId === companyId && targets.some(agent => agent.id === grant.agent?.id) && !grant.revokedAt) await ctx.input.api.delete(`/api/mcp/connections/${grant.id}`);
|
||||
const retained = await ctx.input.api.get<McpConnection[]>("/api/mcp/connections"); if (retained.some(grant => grant.companyId === companyId && targets.some(agent => agent.id === grant.agent?.id) && !grant.revokedAt)) throw new Error("Actual owned Grok authority revocation is not confirmed");
|
||||
await ctx.input.evidence("grok-owned-authority-cleanup.json", { agentIds: targets.map(agent => agent.id), activeOwnedGrants: 0, externalBotRetained: true, claim: "Only this attempt's Paperclip authority is revoked. The user-owned Bot, account-wide plugin and designated reusable routine are retained; remote global termination is not claimed." });
|
||||
},
|
||||
})];
|
||||
Reference in new issue
Block a user