import { describe, expect, mock, test } from "bun:test";
import { Database } from "bun:sqlite";
import { applyCombinedSchema } from "./test-schema.test-helper";
import type { Viewer } from "~/lib/types";
mock.module("cloudflare:workers", () => ({
env: { PUBLIC_URL: "https://forge.example.com" },
waitUntil: () => undefined,
WorkflowEntrypoint: class {},
DurableObject: class {},
WorkerEntrypoint: class {},
}));
mock.module("@tanstack/react-start/server", () => ({
getRequestHeader: () => undefined,
getRequest: () => undefined,
deleteCookie: () => undefined,
getCookie: () => undefined,
setCookie: () => undefined,
setResponseHeader: () => undefined,
setResponseStatus: () => undefined,
}));
const db = new Database(":memory:");
applyCombinedSchema(db);
type Statement = { sql: string; params: unknown[] };
const exec = (sql: string, params: unknown[]) => db.query(sql).run(...(params as never[]));
mock.module("./db", () => ({
first: async (sql: string, ...params: unknown[]) => db.query(sql).get(...(params as never[])) ?? null,
all: async (sql: string, ...params: unknown[]) => db.query(sql).all(...(params as never[])),
run: async (sql: string, ...params: unknown[]) => ({ meta: { changes: exec(sql, params).changes } }),
batch: async (statements: Statement[]) => statements.map((statement) => exec(statement.sql, statement.params)),
stmt: (sql: string, ...params: unknown[]): Statement => ({ sql, params }),
placeholders: (count: number) => Array(count).fill("?").join(", "),
chunks: <T>(items: T[]) => [items],
MAX_IN_LIST: 90,
}));
const { sharedScopes } = await import("./test-shared-scopes");
mock.module("./scoped-db", () => sharedScopes(db));
const actualBridge = await import("./git/pull-bridge");