feat: add fixture import harness and conformance test framework for BitVid parity cases

This commit is contained in:
thePR0M3TH3AN committed 2026-07-26 18:58:41 -04:00
1 parent 10326a2804
commit 1002185a03
8 files changed
+249 -20

No files matched your search

+2 -14
View File
@@ -1,20 +1,8 @@
{
"name": "@nostr-governance/testing",
"version": "0.1.0",
"type": "module",
"main": "src/index.js",
"types": "dist/types/src/index.d.ts",
"files": ["src", "dist"],
"exports": {
".": {
"types": "./dist/types/src/index.d.ts",
"import": "./src/index.js"
}
},
"private": true,
"scripts": {
"test": "vitest run"
},
"dependencies": {
"@nostr-governance/core": "*"
}
}
}
+24
View File
@@ -0,0 +1,24 @@
// Shared test utilities for conformance harness
export function createFixture(name, state, target, expectation) {
return {
name,
state: {
adminState: state.adminState || {},
trust: state.trust || {},
reports: state.reports || [],
trustedMutes: state.trustedMutes || [],
overrides: state.overrides || {},
},
target,
expectation,
};
}
export function runConformanceTest(fixture, evaluator) {
const decision = evaluator(fixture.state, fixture.target);
return {
passed: JSON.stringify(decision) === JSON.stringify(fixture.expectation),
actual: decision,
expected: fixture.expectation,
};
}
+1 -1
View File
@@ -1,2 +1,2 @@
// Placeholder for testing module exports
// Testing package exports
export {};
+42
View File
@@ -0,0 +1,42 @@
// Test the conformance utilities
import { describe, it, expect } from "vitest";
import { createFixture, runConformanceTest } from "../src/conformance.js";
describe("conformance utilities", () => {
it("creates valid fixture objects", () => {
const fixture = createFixture(
"test-fixture",
{
adminState: { editors: [] },
trust: {},
reports: [],
trustedMutes: [],
overrides: {},
},
{ type: "user", pubkey: "test" },
{ visibility: "allow" }
);
expect(fixture.name).toBe("test-fixture");
expect(fixture.state.adminState.editors).toEqual([]);
expect(fixture.target).toEqual({ type: "user", pubkey: "test" });
expect(fixture.expectation).toEqual({ visibility: "allow" });
});
it("runs conformance tests", () => {
const fixture = createFixture(
"test-fixture",
{},
{ type: "user", pubkey: "test" },
{ visibility: "allow" }
);
// Mock evaluator that always returns the expectation
const mockEvaluator = () => ({ visibility: "allow" });
const result = runConformanceTest(fixture, mockEvaluator);
expect(result.passed).toBe(true);
expect(result.actual).toEqual({ visibility: "allow" });
expect(result.expected).toEqual({ visibility: "allow" });
});
});