papertrail/tests/workbenchPayload.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

62 lines
2.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { buildPayload } from "../app/console/workbench/_components/payload";
import type { StudyForm } from "../app/console/workbench/_components/types";
// Minimal sanity test for the workbench payload builder — the only non-UI logic on
// the Evidence Workbench page. Confirms it maps form strings to the snake_case wire
// shape /api/evidence-report expects, fails fast on bad input, and passes an
// optional baseline risk only when valid.
const row = (over: Partial<StudyForm>): StudyForm => ({
id: "x",
label: "TrialA",
measure: "HR",
point: "0.75",
ciLower: "0.60",
ciUpper: "0.94",
...over,
});
const CLAIM = "Drug X cuts events by 25% across trials.";
describe("buildPayload", () => {
it("maps valid rows to the snake_case wire shape and includes baselineRisk when valid", () => {
const rows = [row({ id: "a" }), row({ id: "b", point: "0.82" })];
const res = buildPayload(CLAIM, rows, "0.12");
if ("error" in res) throw new Error(`unexpected error: ${res.error}`);
expect(res.payload.studies).toHaveLength(2);
expect(res.payload.studies[0]).toMatchObject({
label: "TrialA",
measure: "HR",
point: 0.75,
ci_lower: 0.6,
ci_upper: 0.94,
});
expect(res.payload.baselineRisk).toBe(0.12);
});
it("omits baselineRisk when the field is left blank", () => {
const rows = [row({ id: "a" }), row({ id: "b" })];
const res = buildPayload(CLAIM, rows, "");
if ("error" in res) throw new Error(`unexpected error: ${res.error}`);
expect(res.payload.baselineRisk).toBeUndefined();
});
it("rejects a CI upper that does not exceed the lower bound", () => {
const rows = [row({ id: "a", ciLower: "0.9", ciUpper: "0.8" }), row({ id: "b" })];
const res = buildPayload(CLAIM, rows, "");
expect("error" in res).toBe(true);
});
it("rejects a baseline risk outside (0, 1)", () => {
const rows = [row({ id: "a" }), row({ id: "b" })];
const res = buildPayload(CLAIM, rows, "1.5");
expect("error" in res).toBe(true);
});
it("requires at least two studies and a claim of >= 10 chars", () => {
expect("error" in buildPayload("short", [row({ id: "a" }), row({ id: "b" })], "")).toBe(true);
expect("error" in buildPayload(CLAIM, [row({ id: "a" })], "")).toBe(true);
});
});