import { describe, expect, mock, test } from "bun:test";
import { Database } from "bun:sqlite";
import { applyCombinedSchema } from "./test-schema.test-helper";
import type { RepoRow, 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 }));
const db = new Database(":memory:");
applyCombinedSchema(db);
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 () => ({ meta: { changes: 0 } }),
batch: async () => [],
stmt: (sql: string, ...params: unknown[]) => ({ sql, params }),
placeholders: (count: number) => Array(count).fill("?").join(", "),
chunks: <T>(items: T[]) => [items],
MAX_IN_LIST: 90,
}));
mock.module("./auth", () => ({
credentialFromRequest: () => null,
loadActiveUserById: async () => null,
PAT_PREFIX: "gf",
toViewer: () => null,
viewerFromSessionCookie: async () => null,
}));
mock.module("./usercontent-grant", () => ({ viewerFromGrant: async () => null }));
const { inboxReadableSql, repoPermission, requireRepoAccess, visibleReposClause } = await import("./repos");
const { scopedRepoPermission } = await import("./token-scope");