import { describe, expect, it } from "bun:test";
import app from "../app";
async function get(path: string, headers: Record<string, string> = {}) {
return app.fetch(new Request(`http://localhost${path}`, { headers }));
}
describe("unmatched machine-surface paths return JSON", () => {
const jsonPaths = [
"/api/definitely-not-real",
"/api/v2/definitely-not-real",
"/mcp/definitely-not-real",
"/graphql/definitely-not-real",
"/scim/definitely-not-real",
"/.well-known/definitely-not-real",
];
for (const path of jsonPaths) {
it(`${path} → 404 application/json`, async () => {
const res = await get(path);
expect(res.status).toBe(404);
expect(res.headers.get("content-type")).toContain("application/json");
const body = await res.json();
expect(body.error).toBe("Not found");
expect(body.path).toBe(path);
});
}
it("a deep unmatched API path is JSON too", async () => {
const res = await get("/api/v2/repos/nope/nope/nope/nope");
expect(res.status).toBe(404);
expect(res.headers.get("content-type")).toContain("application/json");
});
});
describe("HTML surfaces are unaffected", () => {
it("a path that merely starts with an API root's letters stays HTML", async () => {
const res = await get("/mcpanything", { accept: "text/html" });
expect(res.headers.get("content-type")).toContain("text/html");
});
it("a normal repo path still renders HTML", async () => {
const res = await get("/someowner/somerepo", { accept: "text/html" });
expect(res.headers.get("content-type")).toContain("text/html");
});
});
|