Add hosted synthetic control plane

This commit is contained in:
dirtydishes 2026-05-13 22:10:05 -04:00
parent af04875107
commit 8dcbcd2201
21 changed files with 3695 additions and 772 deletions

View file

@ -0,0 +1,61 @@
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
import {
getSyntheticAdminProxyConfig,
isSyntheticAdminFeatureEnabled
} from "./shared";
const originalFetch = globalThis.fetch;
describe("synthetic admin proxy helpers", () => {
beforeEach(() => {
process.env.NEXT_PUBLIC_SYNTHETIC_ADMIN = "1";
process.env.NEXT_PUBLIC_API_URL = "http://127.0.0.1:4000";
process.env.SYNTHETIC_ADMIN_TOKEN = "secret-token";
});
afterEach(() => {
globalThis.fetch = originalFetch;
});
it("gates visibility on the public env flag", () => {
expect(isSyntheticAdminFeatureEnabled("1")).toBe(true);
expect(isSyntheticAdminFeatureEnabled("0")).toBe(false);
});
it("reads the proxy config from server env only", () => {
expect(getSyntheticAdminProxyConfig()).toEqual({
apiBaseUrl: "http://127.0.0.1:4000",
token: "secret-token"
});
});
it("proxies status requests with the backend admin token", async () => {
const fetchMock = mock(async (input: string | URL, init?: RequestInit) => {
expect(String(input)).toBe("http://127.0.0.1:4000/admin/synthetic/status");
expect(new Headers(init?.headers).get("authorization")).toBe("Bearer secret-token");
return new Response(JSON.stringify({ enabled: true }), {
status: 200,
headers: {
"content-type": "application/json"
}
});
});
globalThis.fetch = fetchMock as typeof fetch;
const route = await import("./status/route");
const response = await route.GET();
expect(response.status).toBe(200);
expect(await response.json()).toEqual({ enabled: true });
expect(fetchMock).toHaveBeenCalledTimes(1);
});
it("returns 404 from proxy routes when the internal UI flag is off", async () => {
process.env.NEXT_PUBLIC_SYNTHETIC_ADMIN = "0";
const route = await import("./control/route");
const response = await route.GET();
expect(response.status).toBe(404);
});
});