35 lines
1.9 KiB
TypeScript
35 lines
1.9 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { belongsToProblem, reviewPayload } from "../src/lib/eddyReview";
|
|
|
|
describe("Eddy review ownership", () => {
|
|
const problem = { baseline: "notes-build-a", signature: "hang:window", aliases: ["hang:layout"] };
|
|
test("joins aliases only within the same exact baseline", () => {
|
|
expect(belongsToProblem(problem, { baseline: "notes-build-a", problem: "hang:layout" })).toBe(true);
|
|
expect(belongsToProblem(problem, { baseline: "notes-build-b", problem: "hang:window" })).toBe(false);
|
|
expect(belongsToProblem(problem, { baseline: "notes-build-a", problem: "hang:other" })).toBe(false);
|
|
});
|
|
test("a missing signature does not attach unrelated advice", () => {
|
|
expect(belongsToProblem(problem, { baseline: "notes-build-a", problem: null })).toBe(false);
|
|
});
|
|
});
|
|
async function pack(text: string, name = "guard.js") {
|
|
const bytes = new TextEncoder().encode(text);
|
|
const sha = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
return { manifest: {}, payload_b64: Buffer.from(bytes).toString("base64"), payload_name: name, sha256: sha };
|
|
}
|
|
describe("Eddy payload review", () => {
|
|
test("displays the verified source without executing it", async () => {
|
|
const source = 'throw new Error("must never execute"); // 布局';
|
|
const p = await pack(source);
|
|
expect((await reviewPayload(p, p.sha256)).text).toBe(source);
|
|
});
|
|
test("rejects bytes changed since the review record was loaded", async () => {
|
|
const p = await pack("return {}");
|
|
await expect(reviewPayload(p, "0".repeat(64))).rejects.toThrow("SHA-256");
|
|
});
|
|
test("keeps binary payloads downloadable without treating them as source", async () => {
|
|
const p = await pack("PK fixture", "pack.zip");
|
|
expect((await reviewPayload(p, p.sha256)).text).toBeNull();
|
|
});
|
|
});
|