diff --git a/site/scripts/fetch.test.ts b/site/scripts/fetch.test.ts index 810c22d6..91cf6c04 100644 --- a/site/scripts/fetch.test.ts +++ b/site/scripts/fetch.test.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, test } from "bun:test"; +import { afterEach, describe, expect, setDefaultTimeout, test } from "bun:test"; import { execFile } from "node:child_process"; import { mkdir, @@ -39,6 +39,16 @@ describe("source fetch command construction", () => { ]); }); + test("joins a base URL without a trailing slash", () => { + const args = buildCloneArgs( + "RigelBuild/meissa", + "/tmp/source", + undefined, + "https://github.com", + ); + expect(args).toContain("https://github.com/RigelBuild/meissa.git"); + }); + test("keeps blob filtering and drops clone depth for a pinned source", () => { const args = buildCloneArgs( "RigelBuild/meissa", @@ -152,7 +162,8 @@ async function makeRemote(): Promise { await mkdir(join(base, "RigelBuild"), { recursive: true }); await git(["init", "--quiet", "--bare", bare], base); await git(["symbolic-ref", "HEAD", "refs/heads/main"], bare); - // Without this the server drops --filter and the blob:none path is untested. + // Without this the server drops --filter. The blob:none path is exercised + // here, not verified: nothing checks that blobs were actually skipped. await git(["config", "uploadpack.allowFilter", "true"], bare); await git(["init", "--quiet", scratch], base); @@ -160,6 +171,10 @@ async function makeRemote(): Promise { await git(["remote", "add", "origin", bare], scratch); await writeFile(join(scratch, "README.md"), "# one\n"); await writeFile(join(scratch, "docs-bundle.toml"), 'name = "tool"\n'); + await mkdir(join(scratch, "docs"), { recursive: true }); + await writeFile(join(scratch, "docs", "x.md"), "# docs\n"); + await mkdir(join(scratch, "src"), { recursive: true }); + await writeFile(join(scratch, "src", "main.ts"), "export {};\n"); await commitAll(scratch, "first"); const first = await git(["rev-parse", "HEAD"], scratch); await writeFile(join(scratch, "README.md"), "# two\n"); @@ -170,7 +185,7 @@ async function makeRemote(): Promise { await commitAll(scratch, "side"); const side = await git(["rev-parse", "HEAD"], scratch); await git(["push", "--quiet", "origin", "main", "side"], scratch); - // Trailing slash: fetch.ts appends `${repo}.git` directly to baseUrl. + // Trailing slash, as in GITHUB_BASE_URL. buildCloneArgs also accepts none. return { baseUrl: `${pathToFileURL(base).href}/`, first, second, side }; } @@ -195,6 +210,9 @@ async function readFetched(workDir: string): Promise { return JSON.parse(await readFile(join(workDir, "fetched.json"), "utf8")); } +// The bare-repo tests clone for real; a loaded gate host can exceed Bun's 5 s default. +setDefaultTimeout(30_000); + describe("source fetch against a local bare repo", () => { test("checks out the pinned SHA instead of the branch head", async () => { const remote = await makeRemote(); @@ -222,10 +240,10 @@ describe("source fetch against a local bare repo", () => { expect.objectContaining({ sha: remote.first }), ]); - // runGit labels failures with args[0], which is "-C" for this call. + // runGit labels failures with the git subcommand: merge-base here. await expect( fetchTool(remote, new Map([[REPO, remote.side]]), true), - ).rejects.toThrow("git -C failed (1)"); + ).rejects.toThrow("git merge-base failed (1)"); // Control: the same side-branch SHA is accepted when production is off. const dev = await fetchTool(remote, new Map([[REPO, remote.side]]), false); @@ -239,6 +257,10 @@ describe("source fetch against a local bare repo", () => { const workDir = await fetchTool(remote, new Map(), false); const root = join(workDir, "sources", "tool"); expect(await readFile(join(root, "README.md"), "utf8")).toBe("# two\n"); + expect(await readFile(join(root, "docs", "x.md"), "utf8")).toBe("# docs\n"); + await expect(stat(join(root, "src", "main.ts"))).rejects.toMatchObject({ + code: "ENOENT", + }); await expect(stat(join(root, ".git"))).rejects.toMatchObject({ code: "ENOENT", }); diff --git a/site/scripts/fetch.ts b/site/scripts/fetch.ts index 4930c540..471a7859 100644 --- a/site/scripts/fetch.ts +++ b/site/scripts/fetch.ts @@ -18,7 +18,7 @@ interface FetchOptions { workDir: string; pins: ReadonlyMap; production: boolean; - /** Clone URL prefix ending in "/". Defaults to GitHub. */ + /** Clone URL prefix. Defaults to GitHub. */ baseUrl?: string; } @@ -85,7 +85,8 @@ export function buildCloneArgs( "--sparse", ]; if (pin === undefined) args.push("--depth", "1"); - args.push(`${baseUrl}${repo}.git`, destination); + const prefix = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`; + args.push(`${prefix}${repo}.git`, destination); return args; } @@ -112,6 +113,13 @@ export function buildGitEnvironment( return safe; } +// First argument after any leading `-C ` or `-c ` pairs. +function gitSubcommand(args: readonly string[]): string | undefined { + let index = 0; + while (args[index] === "-C" || args[index] === "-c") index += 2; + return args[index]; +} + function runGit( args: readonly string[], cwd: string, @@ -137,7 +145,11 @@ function runGit( child.on("close", (code) => { if (code === 0) resolve(stdout.trim()); else - reject(new Error(`git ${args[0]} failed (${code}): ${stderr.trim()}`)); + reject( + new Error( + `git ${gitSubcommand(args)} failed (${code}): ${stderr.trim()}`, + ), + ); }); }); } diff --git a/site/sources.json b/site/sources.json index f67ee30d..b572eab4 100644 --- a/site/sources.json +++ b/site/sources.json @@ -1,4 +1,9 @@ [ + { + "repo": "RigelBuild/meissa", + "mount": "/meissa/", + "config": "default" + }, { "repo": "RigelBuild/terraform-provider-googleworkspace", "mount": "/terraform-provider-googleworkspace/",