papertrail/tests/riskOfBias.test.ts
caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

83 lines
2.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import {
assessRiskOfBias,
type RiskOfBiasInput,
type RobJudgement,
} from "../lib/riskOfBias";
// A clean, well-conducted RCT: randomized, concealed, double-blind with a blinded
// assessor, negligible attrition under ITT, pre-registered with all outcomes
// reported, adequate N, ran to completion, publicly funded. Cases override only
// the fields they exercise.
const CLEAN: RiskOfBiasInput = {
randomSequenceGenerated: true,
allocationConcealed: true,
blinding: "double_blind",
outcomeAssessorBlinded: true,
outcomeType: "objective",
attritionRate: 0.02,
intentionToTreat: true,
preRegistered: true,
allPrespecifiedOutcomesReported: true,
sampleSize: 2000,
stoppedEarlyForBenefit: false,
funding: "public",
};
interface Case {
name: string;
input: RiskOfBiasInput;
overall: RobJudgement;
gradeSteps: number;
}
const CASES: Case[] = [
{
name: "clean well-conducted RCT -> low / 0 steps",
input: { ...CLEAN },
overall: "low",
gradeSteps: 0,
},
{
name: "one high critical domain (no concealment) -> high / 1 step",
input: { ...CLEAN, allocationConcealed: false },
overall: "high",
gradeSteps: 1,
},
{
name: "two high critical domains (no randomization + high attrition, no ITT) -> high / 2 steps",
input: {
...CLEAN,
randomSequenceGenerated: false,
attritionRate: 0.4,
intentionToTreat: false,
},
overall: "high",
gradeSteps: 2,
},
];
describe("assessRiskOfBias — deterministic RoB -> GRADE step reduction", () => {
for (const c of CASES) {
it(c.name, () => {
const result = assessRiskOfBias(c.input);
expect(result.overall).toBe(c.overall);
expect(result.gradeSteps).toBe(c.gradeSteps);
// gradeSteps stays within the GRADE per-domain cap.
expect(result.gradeSteps).toBeGreaterThanOrEqual(0);
expect(result.gradeSteps).toBeLessThanOrEqual(2);
// Every domain carries a non-empty reason.
for (const d of result.domains) {
expect(d.reason.length).toBeGreaterThan(0);
}
});
}
it("does not mutate its input", () => {
const input: RiskOfBiasInput = { ...CLEAN, allocationConcealed: false };
const snapshot = JSON.stringify(input);
assessRiskOfBias(input);
expect(JSON.stringify(input)).toBe(snapshot);
});
});