Skip to content

Commit 7fa2ae9

Browse files
Nick  VaccarelloNick  Vaccarello
authored andcommitted
docs(tests): add tests README with coverage and commands\nchore(tools): add JSON report option to sanity CLI suite
1 parent 59788f5 commit 7fa2ae9

File tree

2 files changed

+85
-6
lines changed

2 files changed

+85
-6
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Tests Overview
2+
3+
This directory contains unit tests and harnesses for the medical diagnosis model.
4+
5+
## What we test
6+
7+
- API v2 core
8+
- `test_api_phase1.py`: validates responses against sample cases using FastAPI TestClient.
9+
- Selector math
10+
- `test_selector.py`: checks Expected Information Gain (EIG) ranking on toy distributions.
11+
- Security & Ops
12+
- `test_security_cors_rate.py`: CORS preflight (localhost:3000), API key auth (401 vs 200), rate limiting (429 on bursts).
13+
- Adaptive endpoints (alpha)
14+
- `test_adaptive_endpoints.py`: start → answer → finish flow.
15+
16+
## How to run
17+
18+
```bash
19+
# From repo root
20+
PYTHONPATH="$PWD:$PWD/medical_diagnosis_model" MDM_QUICK_TRAIN=1 \
21+
pytest -q medical_diagnosis_model/tests
22+
```
23+
24+
## Sanity CLI (recommended)
25+
26+
Run end-to-end checks and write a JSON report:
27+
28+
```bash
29+
cd medical_diagnosis_model
30+
python tools/sanity.py suite --auto-start --api-key devkey \
31+
--with-api --with-export --with-rate --with-adaptive \
32+
--report-json reports/sanity_latest.json
33+
```
34+
35+
## Outputs and artifacts
36+
37+
- tests/phase_1_backend/outputs/: cURL-based runs and summaries (gitignored)
38+
- exports/: generated PDFs from /export (gitignored)
39+
- reports/sanity_latest.json: suite status summary

medical_diagnosis_model/tools/sanity.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,57 @@ def cmd_adaptive(args: argparse.Namespace) -> None:
212212

213213

214214
def cmd_suite(args: argparse.Namespace) -> None:
215+
statuses = {
216+
"data": None,
217+
"tests": None,
218+
"api": None,
219+
"export": None,
220+
"rate": None,
221+
"adaptive": None,
222+
}
223+
224+
def _safe(run_fn, key):
225+
try:
226+
run_fn(args)
227+
statuses[key] = True
228+
except SystemExit:
229+
statuses[key] = False
230+
215231
# Always run data + tests
216-
cmd_data(args)
217-
cmd_tests(args)
232+
_safe(cmd_data, "data")
233+
_safe(cmd_tests, "tests")
218234
# Optionally run API-related checks
219235
if args.with_api:
220-
cmd_api(args)
236+
_safe(cmd_api, "api")
221237
if args.with_export:
222-
cmd_export(args)
238+
_safe(cmd_export, "export")
223239
if args.with_rate:
224-
cmd_rate(args)
240+
_safe(cmd_rate, "rate")
225241
if args.with_adaptive:
226-
cmd_adaptive(args)
242+
_safe(cmd_adaptive, "adaptive")
243+
244+
# Optional JSON report
245+
if getattr(args, "report_json", None):
246+
import json, datetime
247+
report = {
248+
"timestamp": datetime.datetime.utcnow().isoformat() + "Z",
249+
"config": {
250+
"with_api": bool(args.with_api),
251+
"with_export": bool(args.with_export),
252+
"with_rate": bool(args.with_rate),
253+
"with_adaptive": bool(args.with_adaptive),
254+
},
255+
"statuses": statuses,
256+
}
257+
out_path = Path(args.report_json)
258+
out_path.parent.mkdir(parents=True, exist_ok=True)
259+
out_path.write_text(json.dumps(report, indent=2), encoding="utf-8")
260+
print(f"Wrote sanity report to {out_path}")
261+
262+
# Exit non-zero if any selected check failed
263+
failures = [k for k, v in statuses.items() if v is False]
264+
if failures:
265+
raise SystemExit(1)
227266

228267

229268
def build_parser() -> argparse.ArgumentParser:
@@ -268,6 +307,7 @@ def add_api_opts(sp):
268307
sp_suite.add_argument("--with-export", action="store_true")
269308
sp_suite.add_argument("--with-rate", action="store_true")
270309
sp_suite.add_argument("--with-adaptive", action="store_true")
310+
sp_suite.add_argument("--report-json", default=None, help="Write JSON summary to this path")
271311
sp_suite.set_defaults(func=cmd_suite)
272312

273313
return p

0 commit comments

Comments
 (0)