import { beforeEach, describe, expect, mock, test } from "bun:test";
import { Database } from "bun:sqlite";
const encoder = new TextEncoder();
let head = "c1";
const commits: Record<string, string> = { c1: "t1", c2: "t2" };
const blobs: Record<string, Uint8Array> = {
app: encoder.encode("export const a = 1;\n".repeat(50)),
util: encoder.encode("package main\n".repeat(400)),
vendored: encoder.encode("var x = 1;\n".repeat(500)),
image: new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0, 0, 0]),
big: encoder.encode("x".repeat(200 * 1024)),
attrs: encoder.encode("*.go linguist-language=Golang\n"),
};
const trees: Record<string, Array<{ path: string; sha: string; mode: string }>> = {
t1: [
{ path: "src/app.ts", sha: "app", mode: "100644" },
{ path: "cmd/util.go", sha: "util", mode: "100644" },
{ path: "vendor/lib.js", sha: "vendored", mode: "100644" },
{ path: "logo.png", sha: "image", mode: "100644" },
{ path: "gen/huge.py", sha: "big", mode: "100644" },
],
};
const writes: Array<{ sql: string; params: unknown[] }> = [];
mock.module("cloudflare:workers", () => ({
DurableObject: class {
constructor(
protected ctx: unknown,
protected env: unknown,
) {}
},
env: {},
}));
mock.module("../repos", () => ({
loadRepoById: async () => ({ id: "r1", status: "ready", default_branch: "main", artifacts_name: "art" }),
}));
mock.module("../git/refs", () => ({ branchSha: () => head, listRefs: async () => [] }));
mock.module("../db", () => ({
run: async (sql: string, ...params: unknown[]) => void writes.push({ sql, params }),