Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

34 lines · 1.5 KBRaw History
1import { describe, expect, it } from "vitest";
2import { FLUSH, concat, pkt, utf8 } from "@diffinery/git-core";
3import { parseReceivePack, parseReceivePackHead } from "../../src/git/protocol.js";
4
5const old = "0".repeat(40);
6const oid = "a".repeat(40);
7const body = (options: string[] | null) =>
8 concat([
9 pkt(`${old} ${oid} refs/heads/main\0report-status${options ? " push-options" : ""} atomic\n`),
10 pkt(`${old} ${oid} refs/heads/next\n`),
11 FLUSH,
12 ...(options ? [...options.map((o) => pkt(`${o}\n`)), FLUSH] : []),
13 utf8("PACK...."),
14 ]);
15
16describe("the start of a staged push", () => {
17 it("gives the commands, push options and where the pack starts, as parseReceivePack does", () => {
18 for (const options of [null, ["diffinery-import", "allow-secrets=a reason"]]) {
19 const b = body(options);
20 const head = parseReceivePackHead(b)!;
21 const whole = parseReceivePack(b);
22 expect(head.req.commands).toEqual(whole.commands);
23 expect([...head.req.capabilities]).toEqual([...whole.capabilities]);
24 expect(head.req.pushOptions).toEqual(whole.pushOptions);
25 expect(b.subarray(head.packOffset)).toEqual(whole.pack);
26 }
27 });
28 it("asks for more when the head is cut short, wherever it is cut", () => {
29 const b = body(["diffinery-import"]);
30 const full = parseReceivePackHead(b)!.packOffset;
31 for (let n = 0; n < full; n++) expect(parseReceivePackHead(b.subarray(0, n))).toBeNull();
32 expect(parseReceivePackHead(b.subarray(0, full))?.packOffset).toBe(full);
33 });
34});