import { describe, expect, it } from "bun:test";
import { readFileSync } from "fs";
const SRC = readFileSync("src/routes/fork.tsx", "utf8");
const handler = SRC.slice(SRC.indexOf('fork.post("/:owner/:repo/fork"'));
describe("fork access gate", () => {
it("checks read access via resolveRepoAccess before cloning", () => {
expect(handler).toContain("resolveRepoAccess");
expect(handler).toContain('access === "none"');
});
it("gates BEFORE the git clone, not after", () => {
const gate = handler.indexOf('access === "none"');
const clone = handler.indexOf('"git", "clone"');
expect(gate).toBeGreaterThan(-1);
expect(clone).toBeGreaterThan(-1);
expect(gate).toBeLessThan(clone);
});
it("denies indistinguishably from a missing repo", () => {
const denial = handler.slice(
handler.indexOf('access === "none"'),
handler.indexOf('"git", "clone"')
);
expect(denial).toContain("c.redirect(`/${ownerName}/${repoName}`)");
expect(denial).not.toMatch(/403|Forbidden|not allowed/i);
});
});
describe("fork visibility", () => {
it("inherits the source repo's visibility instead of hardcoding public", () => {
expect(handler).toContain("isPrivate: sourceRepo.isPrivate");
expect(handler).not.toMatch(/^\s*isPrivate: false,/m);
});
});
|