import "./setup_env"; import { expect, test } from "bun:test"; import { validateCrash } from "../src/eddy_crashes"; import { crashBody } from "./fixtures/eddy_crash"; test("the report Eddy sends is accepted with every evidence file verified", () => { const body = crashBody(); const v = validateCrash(body); expect(v.report.id).toBe("crash-20261021T084146-1a2b3c4d"); expect([...v.files.values()].map(b => b.toString())).toContain("[devicesim] camera: dual"); }); test("a crash from the user's own task edits, or an unknown owner, is refused", () => { for (const cls of ["task-edit", "unknown", undefined]) expect(() => validateCrash(crashBody({ class: cls }))).toThrow("Crash class"); }); test("the gzipped logs of the crashed launch are accepted", () => { const v = validateCrash(crashBody({}, { "unified.log.gz": "gz-1", "app.log.gz": "gz-2", "supervisor.log.gz": "gz-3" })); expect([...v.files.values()].map(b => b.toString())).toEqual(expect.arrayContaining(["gz-1", "gz-2", "gz-3"])); }); test("only the evidence files Eddy shares are accepted, intact", () => { expect(() => validateCrash(crashBody({}, { "app.log": "user id 1" }))).toThrow("Invalid crash file"); expect(() => validateCrash(crashBody({}, { "registry.json": "{}" }))).toThrow("Invalid crash file"); const body = crashBody(); const [hash] = Object.keys(body.files); body.files[hash] = Buffer.from("changed").toString("base64"); expect(() => validateCrash(body)).toThrow("integrity"); const missing = crashBody(); missing.files = {}; expect(() => validateCrash(missing)).toThrow("Missing crash file"); expect(() => validateCrash(crashBody({}, { "report.ips": "x".repeat(4 * 1024 * 1024 + 1) }))).toThrow("Invalid crash file"); }); test("identity, baseline and signature are required in their wire formats", () => { expect(() => validateCrash(crashBody({ id: "../crash" }))).toThrow("schema/id"); expect(() => validateCrash(crashBody({ schema: "eddy-crash-v0" }))).toThrow("schema/id"); expect(() => validateCrash(crashBody({ baseline: "" }))).toThrow("baseline"); expect(() => validateCrash(crashBody({ signature: "free text" }))).toThrow("signature"); expect(() => validateCrash(crashBody({ confidence: "sure" }))).toThrow("confidence"); expect(() => validateCrash({})).toThrow("schema/id"); });