Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-grok.test.ts
T

17 lines
5.3 KiB
TypeScript

import { it, expect } from "vitest";
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.", 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);
for (const mutate of [(v: typeof good) => { v.binding!.routine!.lastExchange!.status = "accepted"; }, (v: typeof good) => { v.binding!.wakeVerified = false; }, (v: typeof good) => { v.binding!.connected = false; }, (v: typeof good) => { v.binding!.routine!.lastExchange!.acknowledgedAt = null; }, (v: typeof good) => { v.binding!.routine!.recoveryNeeded = true; }, (v: typeof good) => { v.resourceUrl = "http://localhost/mcp/runner"; }]) { const v = connection(); mutate(v); expect(genuineGrokRoundTrip(v, "binding", "Owned existing Bot")).toBe(false); }
});
it("rejects simulated readiness, changed choice, wrong phase, local parity and zero-cost guesses", () => {
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); } });