317 lines · 11.9 KB
/**
 * Shared fixtures for the MCP end-to-end tests. They run against a live dev server (default
 * http://localhost:3000, override with MCP_BASE_URL) and seed users, tokens and sessions straight into
 * that server's local D1 and KV with wrangler. Set MCP_E2E_ROOT to the checkout that server runs from
 * (default: this checkout).
 */
import { createHash, randomBytes } from "node:crypto";
import { scopedSqlRows as scopedRows } from "./scoped-sql";
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
import type {
  OAuthClientInformationMixed,
  OAuthClientMetadata,
  OAuthClientProvider,
  OAuthTokens,
} from "@modelcontextprotocol/client";

export const BASE = process.env.MCP_BASE_URL ?? "http://localhost:3000";
export const MODERN = "2026-07-28";
/** Checkout whose `vite dev` serves BASE: wrangler seeds that checkout's local D1 and KV. */
const ROOT = process.env.MCP_E2E_ROOT ?? new URL("..", import.meta.url).pathname;
const REDIRECT = "http://127.0.0.1:8976/callback";
const SESSION_COOKIE = "__Host-gitfor_session";
const SSE_DATA = "data: ";
const SSE_ID = "id: ";
const HTTP_CREATED = 201;

export type World = {
  suffix: string;
  userId: string;
  owner: string;
  repo: string;
  otherRepo: string;
  repoId: string;
  classicToken: string;
  sessionCookie: string;
};

/** The parts of JSON-RPC replies the raw-HTTP tests look at. */
export type RpcReply = {
  result?: {