import { beforeEach, 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";
type Handler = (input: { data: Record<string, unknown>; context: { viewer: Viewer } }) => Promise<unknown>;
type Builder = { middleware: () => Builder; validator: () => Builder; handler: (fn: Handler) => Handler };
function builder(): Builder {
const self: Builder = { middleware: () => self, validator: () => self, handler: (fn) => fn };
return self;
}
const dropped: string[] = [];
const testEnv: Record<string, unknown> = {
PUBLIC_URL: "http://localhost:8787",
SECRETS_KEY: "test-key",
RATE_LIMITS_DISABLED: "true",
EMAIL_FROM: "gitfor <noreply@gitfor.dev>",
EVENTS: { send: async () => undefined },
KV: { get: async () => null, put: async () => undefined, delete: async () => undefined },
MCP_HUB: {
idFromName: (name: string) => name,
get: () => ({
invalidateSubscribers: async (repoId: string) => {
dropped.push(repoId);
},
}),
},
};
class StubEntrypoint {}
mock.module("cloudflare:workers", () => ({
env: testEnv,
waitUntil: () => undefined,
WorkflowEntrypoint: StubEntrypoint,
DurableObject: StubEntrypoint,
WorkerEntrypoint: StubEntrypoint,
}));
mock.module("@tanstack/react-start/server", () => ({