import { beforeEach, describe, expect, mock, test } from "bun:test";
import { memoryScopes } from "./scoped-db/testing";
class StubEntrypoint {}
mock.module("cloudflare:workers", () => ({
env: {},
waitUntil: () => undefined,
WorkflowEntrypoint: StubEntrypoint,
DurableObject: StubEntrypoint,
WorkerEntrypoint: StubEntrypoint,
}));
const ZERO = "0".repeat(40);
let scopes = memoryScopes();
let forkOf: string | null = null;
mock.module("./db", () => ({
all: async () => [],
first: async () => ({ fork_of_id: forkOf }),
run: async () => ({ meta: { changes: 0 } }),
batch: async () => [],
stmt: () => ({}),
placeholders: () => "",
chunks: <T>(items: T[]) => [items],
MAX_IN_LIST: 90,
}));
mock.module("./scoped-db", () => ({
repoDb: (id: string) => scopes.repoDb(id),
accountDb: (id: string) => scopes.accountDb(id),
stmt: (sql: string, ...params: unknown[]) => ({ sql, params }),
}));
const { recentBranchPushesFor } = await import("./branch-pushes");
const repo = { id: "r1", default_branch: "main" };
function push(repoId: string, ref: string, after: string, at: number, pusher = "u1") {
scopes
.raw("repo", repoId)
.query(