/** Shared setup for the editor e2e scripts: API calls, seeded repos and local-D1 hooks. */
import { execFileSync } from "node:child_process";
import { RoomClient } from "../src/editor-extension/room-client";
import type { RoomControl } from "../src/lib/editor-protocol";
export const BASE = (process.env.EDITOR_E2E_URL ?? "http://localhost:3000").replace(/\/$/, "");
export const PAT = process.env.GITFOR_TOKEN ?? "";
export const WRITER_PAT = process.env.GITFOR_WRITER_TOKEN ?? "";
/** Local D1 sqlite file; lets the script flip settings no public API exposes (revocation, PAT scope). */
export const LOCAL_D1 = process.env.GITFOR_E2E_D1 ?? "";
const SQLITE = process.env.SQLITE ?? "sqlite3";
export const HTTP = {
ok: 200,
created: 201,
noContent: 204,
badRequest: 400,
unauthorized: 401,
payment: 402,
forbidden: 403,
notFound: 404,
conflict: 409,
tooLarge: 413,
} as const;
let failures = 0;
/** Prints a progress line; e2e scripts report on stdout. */
export function log(line: string): void {
process.stdout.write(`${line}\n`);
}
export function check(condition: unknown, message: string): void {
if (!condition) failures++;
log(`${condition ? "ok" : "not ok"} - ${message}`);
}
export function finish(): never {
log(failures === 0 ? "all checks passed" : `${failures} check(s) failed`);
process.exit(failures === 0 ? 0 : 1);
}