import { describe, expect, test } from "bun:test";
import {
  gateReceiptIdentityMatches,
  type GateReceiptIdentity,
} from "./gate-receipt";

const identity: GateReceiptIdentity = {
  candidateTree: "a".repeat(40),
  gateGraphDigest: "b".repeat(64),
  declaredInputsDigest: "c".repeat(64),
  lockfileDigest: "d".repeat(64),
  toolchainDigest: "e".repeat(64),
  fixtureSchemaDigest: "f".repeat(64),
  commandDigest: "1".repeat(64),
  warningDigest: "2".repeat(64),
  logDigest: "3".repeat(64),
  artifactDigest: "4".repeat(64),
};

describe("gate receipt identity", () => {
  test("matches only an exact identity", () => {
    expect(gateReceiptIdentityMatches(identity, { ...identity })).toBe(true);
  });

  test("rejects every identity field mismatch", () => {
    for (const field of Object.keys(identity) as Array<keyof GateReceiptIdentity>) {
      expect(gateReceiptIdentityMatches(identity, {
        ...identity,
        [field]: field === "candidateTree" ? "9".repeat(40) : "9".repeat(64),
      })).toBe(false);
    }
  });
});
