File
Blob: test/info-refs.worker.test.ts
| 1 | import { it, expect } from "vitest"; |
| 2 | import { env, exports as workerExports } from "cloudflare:workers"; |
| 3 | import { uniqueRepoId } from "./util/test-helpers"; |
| 4 | import { setupRepoForTests } from "./util/repoSeed"; |
| 5 | import { decodePktLinePayloads } from "./util/fetch-protocol"; |
| 6 | |
| 7 | it("advertises upload-pack v2 over info/refs", async () => { |
| 8 | const owner = "o"; |
| 9 | const repo = uniqueRepoId("r-info-refs"); |
| 10 | await setupRepoForTests(env, owner, repo); |
| 11 | |
| 12 | const url = new URL(`https://example.com/${owner}/${repo}/info/refs`); |
| 13 | url.searchParams.set("service", "git-upload-pack"); |
| 14 | const res = await workerExports.default.fetch(new Request(url, { method: "GET" })); |
| 15 | expect(res.status).toBe(200); |
| 16 | expect(res.headers.get("Content-Type")).toContain("git-upload-pack-advertisement"); |
| 17 | const bytes = new Uint8Array(await res.arrayBuffer()); |
| 18 | // The v2 prelude should start with an announcement and a flush, then version/agent lines |
| 19 | const textLines = decodePktLinePayloads(bytes); |
| 20 | // Look for "version 2" and "fetch" capability |
| 21 | expect(textLines.some((l) => l === "version 2\n")).toBe(true); |
| 22 | expect(textLines.some((l) => l === "fetch\n")).toBe(true); |
| 23 | // And the features we advertise |
| 24 | expect(textLines.some((l) => l === "ofs-delta\n")).toBe(true); |
| 25 | expect(textLines.some((l) => l === "side-band-64k\n")).toBe(true); |
| 26 | }); |
| 27 | |
| 28 | it("advertises upload-pack v2 over .git info/refs", async () => { |
| 29 | const owner = "o"; |
| 30 | const repo = uniqueRepoId("r-info-refs-dotgit"); |
| 31 | await setupRepoForTests(env, owner, repo); |
| 32 | |
| 33 | const url = new URL(`https://example.com/${owner}/${repo}.git/info/refs`); |
| 34 | url.searchParams.set("service", "git-upload-pack"); |
| 35 | const res = await workerExports.default.fetch(new Request(url, { method: "GET" })); |
| 36 | expect(res.status).toBe(200); |
| 37 | expect(res.headers.get("Content-Type")).toContain("git-upload-pack-advertisement"); |
| 38 | }); |