mirror of
https://github.com/PR0M3TH3AN/bitgate.git
synced 2026-10-27 08:31:00 +00:00
The evaluator was a skeleton with invented thresholds (5/3/10/5) and two unimplemented branches. Rebuild it against the migration plan's spec and the behavior characterized from the pinned reference commit. Core: - four independent decision dimensions (ranking, visibility, interaction, transaction) with severity ladders and max-merge composition - stable reason identifiers replacing free-text strings - structured evidence, redacted unless a profile opts in - administrative-state reduction with capability filtering at merge time, so revoking a role drops that actor's entries immediately - protected actors stripped from every denial set - snapshot fingerprints for cache invalidation - generic policy engine: applications supply profiles and category thresholds; the core carries none of its own Characterization: - 34 generated fixtures covering every behavior the plan's Phase 0 requires - conformance suite that actually evaluates them, replacing a placeholder that asserted a list's length - reference thresholds (3/3/20/5, 60-day mute window) live in bitvid-compat as an application profile, not as engine defaults Fixes found while building: - reduceAdminState accepted malformed target identifiers, because getTargetKey formats anything it is given - community-user-deny fired for any contributor rather than only for community-curated sources 273 tests pass; typecheck and the reference-import guard are clean.
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { createEmptyEvidence, freezeEvidence, 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 });
|
|
});
|
|
});
|