import { beforeEach, describe, expect, mock, test } from "bun:test";
import { scopedTestState } from "./scoped.test-helper";
const limited: string[] = [];
const kv = new Map<string, string>();
mock.module("cloudflare:workers", () => ({
env: {
SECRETS_KEY: "k".repeat(40),
PUBLIC_URL: "https://forge.test",
SITES_DOMAIN: "sites.test",
KV: {
get: async (key: string) => kv.get(key) ?? null,
put: async (key: string, value: string) => void kv.set(key, value),
delete: async (key: string) => void kv.delete(key),
},
},
waitUntil: () => undefined,
}));
const scoped = scopedTestState();
scoped.install();
mock.module("../limits", () => ({
enforceRateLimit: async (_binding: string, key: string) => void limited.push(key),
numberVar: (_value: string | undefined, fallback: number) => fallback,
}));
mock.module("./deploy", () => ({
loadSiteById: async (id: string) => ({ id, label: `s-${id}` }),
activateSiteDeployment: async () => "active",
failSiteDeployment: async () => undefined,
insertDeployment: async () => ({ id: "d" }),
}));
const { claimUrl, ipHash, reserveScratch } = await import("./scratch-core");
beforeEach(() => {
kv.clear();
scoped.reset();
limited.length = 0;
});