328 lines · 13.5 KB
/**
 * API e2e for the editor: token protocol, guards, live co-editing room (two Yjs clients + an HTTP agent),
 * commits from the room, PAT scope narrowing, socket revocation, and the opt-in container.
 *
 *   EDITOR_E2E_URL=http://localhost:3000 GITFOR_TOKEN=gitfor_pat_... GITFOR_WRITER_TOKEN=gitfor_pat_... \
 *   GITFOR_E2E_D1=.wrangler/state/v3/d1/miniflare-D1DatabaseObject/<id>.sqlite bun run e2e/editor-api.e2e.ts
 */
import { CLOSE_DOWNGRADED } from "../src/lib/editor-protocol";
import {
  BASE,
  call,
  check,
  log,
  finish,
  HTTP,
  join,
  LOCAL_D1,
  mint,
  PAT,
  quote,
  seedRepo,
  sleep,
  sql,
  until,
  WRITER_PAT,
} from "./editor-helpers";

const LFS_POINTER = `version https://git-lfs.github.com/spec/v1\noid sha256:${"a".repeat(64)}\nsize 12\n`;
const BIG_FILE_BYTES = 2 * 1024 * 1024;
const RECHECK_WAIT_MS = 100_000;
const CURSOR_ANCHOR = 3;
if (!PAT) throw new Error("Set GITFOR_TOKEN");

const repo = await seedRepo("editor-api", {
  "README.md": "# hello\n",
  "src/app.ts": "export const answer = 41;\n",
  "assets/big.bin": LFS_POINTER,
  ".gitattributes": "*.psd filter=lfs diff=lfs merge=lfs -text\n",
  "big.txt": "x".repeat(BIG_FILE_BYTES),
  "package.json": '{"scripts":{"hello":"echo hello-from-task"}}\n',