import unittest, tempfile, shutil, json, importlib.util from pathlib import Path ROOT=Path(__file__).resolve().parents[1] s=importlib.util.spec_from_file_location('validator',ROOT/'scripts/validate_run.py'); m=importlib.util.module_from_spec(s); s.loader.exec_module(m) class Tests(unittest.TestCase): def setUp(self): self.tmp=tempfile.TemporaryDirectory(); self.p=Path(self.tmp.name)/'run'; shutil.copytree(ROOT/'research-reports/2026-09-14',self.p) def tearDown(self):self.tmp.cleanup() def mutate(self,key,value): p=self.p/'evidence.json';d=json.loads(p.read_text(encoding='utf-8'));d['cases'][0][key]=value;p.write_text(json.dumps(d),encoding='utf-8') def test_valid(self): self.assertEqual(m.validate(self.p),[]) def test_missing_engine(self): (self.p/'exa.md').unlink();self.assertTrue(m.validate(self.p)) def test_old_evidence(self): self.mutate('evidence_date','2026-06-01');self.assertTrue(m.validate(self.p)) def test_exposure(self): self.mutate('exposure','Unknown');self.assertTrue(m.validate(self.p)) def test_citation(self): self.mutate('source_url','');self.assertTrue(m.validate(self.p)) def test_wrong_window(self): p=self.p/'evidence.json';d=json.loads(p.read_text(encoding='utf-8'));d['window_start']='2026-06-14T10:01:35-07:00';p.write_text(json.dumps(d));self.assertTrue(m.validate(self.p)) if __name__=='__main__':unittest.main()