import { beforeEach, describe, expect, mock, test } from "bun:test";
import { Database } from "bun:sqlite";
mock.module("cloudflare:workers", () => ({
DurableObject: class {
constructor(
protected ctx: unknown,
protected env: unknown,
) {}
},
env: {},
}));
mock.module("../repos", () => ({ loadRepoById: async () => null }));
mock.module("../git/refs", () => ({ branchSha: () => null, listRefs: async () => [] }));
mock.module("../git/store", () => ({ withStore: async () => undefined }));
mock.module("../git/diff", () => ({ diffTreesBounded: async () => ({ changes: [], truncated: false }) }));
const { RepoSearch } = await import("./repo-search-do");
let db = new Database(":memory:");
let alarm: number | null = null;
const stored = new Map<string, unknown>();
function object() {
const storage = {
sql: {
exec: (query: string, ...params: Array<string | number | null>) => {
const rows = db.query(query).all(...params) as Record<string, unknown>[];
return Object.assign(rows[Symbol.iterator](), { toArray: () => rows, one: () => rows[0] });
},
},
get: async (key: string) => stored.get(key),
put: async (key: string, value: unknown) => void stored.set(key, value),
getAlarm: async () => alarm,
setAlarm: async (at: number) => void (alarm = at),
transactionSync: (run: () => void) => run(),
};
return new RepoSearch({ storage } as never, {} as never);
}
function index(path: string, sha: string, content: string): void {