import { beforeEach, describe, expect, mock, test } from "bun:test";
import type { RepoRow, Viewer } from "~/lib/types";
import type { RequestCredential } from "../token-scope";
class StubEntrypoint {}
mock.module("cloudflare:workers", () => ({
env: { PUBLIC_URL: "https://forge.example.com" },
waitUntil: () => undefined,
WorkflowEntrypoint: StubEntrypoint,
DurableObject: StubEntrypoint,
WorkerEntrypoint: StubEntrypoint,
}));
mock.module("../db", () => ({
first: async () => ({ ok: 1 }),
all: async () => [],
run: async () => ({ meta: { changes: 0 } }),
batch: async () => [],
stmt: () => ({}),
chunks: <T>(items: T[]) => [items],
placeholders: (count: number) => Array(count).fill("?").join(", "),
MAX_IN_LIST: 90,
}));
const consulted: string[] = [];
let credential: RequestCredential | null = null;
let scratchResult: string | null = "write";
const actualJob = await import("../ci/job-token");
mock.module("../ci/job-token", () => ({
...actualJob,
jobTokenAccess: async () => {
consulted.push("job");
return { repoId: "repo", permissions: { contents: "write" } };
},
}));
const actualScratch = await import("../sites/scratch-git");
mock.module("../sites/scratch-git", () => ({
...actualScratch,
scratchGitPermission: async () => {
consulted.push("scratch");
return scratchResult;