132 lines · 4.3 KB
import { describe, expect, mock, test } from "bun:test";
import { concatBytes, FLUSH_PKT, packetText, parseAllPackets, pktLine } from "./pktline";

const env: Record<string, unknown> = { ARTIFACTS_SHARDS: "1" };
mock.module("cloudflare:workers", () => ({
  env,
  waitUntil: () => undefined,
  WorkflowEntrypoint: class {},
  DurableObject: class {},
  WorkerEntrypoint: class {},
}));

const { lsRefsRequest, parseLsRefs } = await import("./refs");
const shards = await import("./artifacts-shards");
const { tokenLifetimeSeconds, tokenSecret } = await import("./artifacts");

const A = "a".repeat(40);
const B = "b".repeat(40);
const C = "c".repeat(40);

describe("ls-refs", () => {
  test("requests only HEAD, branches and tags", () => {
    const lines = parseAllPackets(lsRefsRequest()).map((packet) =>
      packet.kind === "data" ? packetText(packet) : packet.kind,
    );
    expect(lines).toEqual([
      "command=ls-refs",
      "agent=git/gitfor",
      "delim",
      "symrefs",
      "peel",
      "ref-prefix HEAD",
      "ref-prefix refs/heads/",
      "ref-prefix refs/tags/",
      "flush",
    ]);
  });

  test("parses HEAD, branches, peeled tags and ignores hidden refs", () => {
    const body = concatBytes([