Files
mtusi2026lab7/student-tests/git-proof-cli.test.ts
T

81 lines
2.4 KiB
TypeScript

import { test, expect } from "bun:test";
import {
createAcceptCommand,
parseGitProofCLI,
} from "../scripts/git-proof-cli";
const path =
"evidence/openbao/canonical-git-proof-11111111-1111-4111-8111-111111111111.json",
sha = "a".repeat(64),
args = ["--checked-cache", "--git-proof", path, "--git-proof-sha", sha];
function fixture() {
const calls: string[] = [];
return {
calls,
ports: {
verifyProof: async (p: unknown) => {
calls.push("proof");
},
password: async () => {
calls.push("password");
return "fixture password";
},
accept: async (_password: string, proof: unknown) => {
calls.push("accept");
},
},
};
}
test("real Git checkout default remains native Git without proof flags", async () => {
const f = fixture();
expect(parseGitProofCLI(["--checked-cache"])).toEqual({ kind: "native-git" });
await createAcceptCommand(f.ports)([]);
expect(f.calls).toEqual(["password", "accept"]);
});
test("ZIP canonical proof is selected and verified before password or acceptance", async () => {
const f = fixture();
expect(parseGitProofCLI(args)).toEqual({
kind: "canonical-proof",
path,
sha256: sha,
});
await createAcceptCommand(f.ports)(args);
expect(f.calls).toEqual(["proof", "password", "accept"]);
});
test.each(
[
["--git-proof"],
["--git-proof", path],
["--git-proof-sha", sha],
["--git-proof", path, "--git-proof-sha", "invalid"],
["--git-proof", path, "--git-proof-sha", sha, "--git-proof", path],
].map((args) => ({ args })),
)(
"malformed proof flags reject before credentials: $args",
async ({ args: items }) => {
const f = fixture();
await expect(createAcceptCommand(f.ports)(items)).rejects.toThrow(
"GIT_PROOF_CLI_INVALID",
);
expect(f.calls).toEqual([]);
},
);
test("missing or changed proof preserves reader error and never reads password", async () => {
const f = fixture(),
error = Error("GIT_PROOF_SHA_MISMATCH");
f.ports.verifyProof = async () => {
throw error;
};
let actual;
try {
await createAcceptCommand(f.ports)(args);
} catch (e) {
actual = e;
}
expect(actual).toBe(error);
expect(f.calls).toEqual([]);
});
test("workflow ports have no filesystem, prompt or stand defaults", () =>
expect(() => createAcceptCommand({} as never)).toThrow(
"ACCEPT_COMMAND_PORTS_REQUIRED",
));