mirror of
https://github.com/PR0M3TH3AN/bitgate.git
synced 2026-10-27 16:41:03 +00:00
Proves the engine did not stay video-specific during extraction. - application adapter contract in core (createApplicationAdapter, evaluateObject, collectTargets): an object names the targets that govern it and the strictest verdict reaching any of them wins, so denying a seller takes their whole catalogue down with no cascade logic in the application - examples/commerce: a marketplace on the public API covering all ten proof-of-fit behaviors the plan requires, including that no core change was needed. One product, one snapshot, four surfaces, four different verdicts. - README, integration guide, per-example README, CHANGELOG, four ADRs, and GPL-3.0-or-later LICENSE (the license was listed in Phase 1 but missing) - checkpoints rewritten to reflect actual state and to say plainly which migration-plan phases belong to the consumer repos rather than here Fixes a real gap found by the proof-of-fit: composeDecisions kept only the first decision's evidence, so an object governed by several targets lost the evidence that drove its verdict. Evidence now merges — counts summed, contributor lists unioned, flags or-ed. 556 tests; lint, typecheck, and per-package type build clean.
110 lines
3.5 KiB
JavaScript
110 lines
3.5 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
createEmptyEvidence,
|
|
freezeEvidence,
|
|
mergeEvidence,
|
|
redactEvidence,
|
|
} from "../src/evidence.js";
|
|
|
|
const populated = () => ({
|
|
...createEmptyEvidence(),
|
|
trustedReportTotal: 3,
|
|
trustedReportsByCategory: { spam: 2, nudity: 1 },
|
|
trustedReporterPubkeys: ["cc", "aa", "bb"],
|
|
trustedMuteTotal: 2,
|
|
trustedMutesByCategory: { other: 2 },
|
|
trustedMuterPubkeys: ["zz", "yy"],
|
|
});
|
|
|
|
describe("createEmptyEvidence", () => {
|
|
it("starts at zero with no flags set", () => {
|
|
const evidence = createEmptyEvidence();
|
|
expect(evidence.trustedReportTotal).toBe(0);
|
|
expect(evidence.personalBlock).toBe(false);
|
|
expect(evidence.protectedTarget).toBe(false);
|
|
expect(evidence.trustedReporterPubkeys).toEqual([]);
|
|
});
|
|
|
|
it("returns a fresh object each call", () => {
|
|
const first = createEmptyEvidence();
|
|
first.trustedReportTotal = 9;
|
|
expect(createEmptyEvidence().trustedReportTotal).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe("freezeEvidence", () => {
|
|
it("sorts pubkey lists for stable serialization", () => {
|
|
expect(freezeEvidence(populated()).trustedReporterPubkeys).toEqual(["aa", "bb", "cc"]);
|
|
});
|
|
|
|
it("sorts category keys", () => {
|
|
expect(Object.keys(freezeEvidence(populated()).trustedReportsByCategory)).toEqual([
|
|
"nudity",
|
|
"spam",
|
|
]);
|
|
});
|
|
|
|
it("preserves counts", () => {
|
|
const frozen = freezeEvidence(populated());
|
|
expect(frozen.trustedReportTotal).toBe(3);
|
|
expect(frozen.trustedReportsByCategory.spam).toBe(2);
|
|
});
|
|
|
|
it("does not mutate its input", () => {
|
|
const evidence = populated();
|
|
freezeEvidence(evidence);
|
|
expect(evidence.trustedReporterPubkeys).toEqual(["cc", "aa", "bb"]);
|
|
});
|
|
|
|
it("is stable across repeated calls", () => {
|
|
expect(freezeEvidence(populated())).toEqual(freezeEvidence(populated()));
|
|
});
|
|
});
|
|
|
|
describe("redactEvidence", () => {
|
|
it("drops contributor pubkeys", () => {
|
|
const redacted = redactEvidence(populated());
|
|
expect(redacted.trustedReporterPubkeys).toEqual([]);
|
|
expect(redacted.trustedMuterPubkeys).toEqual([]);
|
|
});
|
|
|
|
it("keeps the counts that explain the decision", () => {
|
|
const redacted = redactEvidence(populated());
|
|
expect(redacted.trustedReportTotal).toBe(3);
|
|
expect(redacted.trustedMuteTotal).toBe(2);
|
|
expect(redacted.trustedReportsByCategory).toEqual({ nudity: 1, spam: 2 });
|
|
});
|
|
});
|
|
|
|
describe("mergeEvidence", () => {
|
|
it("sums counts across targets", () => {
|
|
const merged = mergeEvidence([populated(), populated()]);
|
|
expect(merged.trustedReportTotal).toBe(6);
|
|
expect(merged.trustedReportsByCategory.spam).toBe(4);
|
|
});
|
|
|
|
it("unions contributor lists without duplicating", () => {
|
|
const merged = mergeEvidence([populated(), populated()]);
|
|
expect(merged.trustedReporterPubkeys).toEqual(["aa", "bb", "cc"]);
|
|
});
|
|
|
|
it("ors the boolean flags", () => {
|
|
const denied = { ...createEmptyEvidence(), userDenied: true };
|
|
const blocked = { ...createEmptyEvidence(), personalBlock: true };
|
|
const merged = mergeEvidence([denied, blocked]);
|
|
expect(merged.userDenied).toBe(true);
|
|
expect(merged.personalBlock).toBe(true);
|
|
expect(merged.eventDenied).toBe(false);
|
|
});
|
|
|
|
it("tolerates empty and malformed input", () => {
|
|
expect(mergeEvidence([]).trustedReportTotal).toBe(0);
|
|
expect(mergeEvidence(/** @type {any} */ ([null])).trustedReportTotal).toBe(0);
|
|
});
|
|
|
|
it("returns sorted, stable output", () => {
|
|
expect(mergeEvidence([populated()])).toEqual(mergeEvidence([populated()]));
|
|
});
|
|
});
|