papertrail/backend/engines/Valsci/tests/test_processor_heartbeat.py
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

52 lines
1.7 KiB
Python

import os
from app.services.processor_heartbeat import (
STALE_AFTER_SECONDS,
heartbeat_path,
read_heartbeat,
write_heartbeat,
)
def test_missing_heartbeat_reads_as_down(tmp_path):
result = read_heartbeat(tmp_path)
assert result == {"alive": False, "age_seconds": None, "pid": None, "config_mtime": None}
def test_fresh_heartbeat_reads_as_alive(tmp_path):
write_heartbeat(tmp_path, now=1000.0)
result = read_heartbeat(tmp_path, now=1003.0)
assert result["alive"] is True
assert result["age_seconds"] == 3.0
assert result["pid"] == os.getpid()
def test_heartbeat_round_trips_config_mtime(tmp_path):
write_heartbeat(tmp_path, now=1000.0, config_mtime=1699999999.5)
result = read_heartbeat(tmp_path, now=1001.0)
assert result["config_mtime"] == 1699999999.5
def test_stale_heartbeat_reads_as_down(tmp_path):
write_heartbeat(tmp_path, now=1000.0)
result = read_heartbeat(tmp_path, now=1000.0 + STALE_AFTER_SECONDS + 1)
assert result["alive"] is False
assert result["age_seconds"] == STALE_AFTER_SECONDS + 1
def test_corrupt_heartbeat_reads_as_down(tmp_path):
heartbeat_path(tmp_path).write_text("not json", encoding="utf-8")
result = read_heartbeat(tmp_path)
assert result == {"alive": False, "age_seconds": None, "pid": None, "config_mtime": None}
def test_write_creates_state_dir_and_overwrites(tmp_path):
target = tmp_path / "nested" / "state"
write_heartbeat(target, now=50.0)
write_heartbeat(target, now=60.0)
result = read_heartbeat(target, now=61.0)
assert result["alive"] is True
assert result["age_seconds"] == 1.0
# No stray temp files left behind by the atomic write.
assert [p.name for p in target.iterdir()] == ["processor_heartbeat.json"]