45 lines
3.2 KiB
Python
45 lines
3.2 KiB
Python
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))
|
|
def gaps(self, queries=True):
|
|
p=self.p/'search-log.json';d=json.loads(p.read_text(encoding='utf-8'))
|
|
d['coverage_status']='completed-with-gaps';d['coverage_gaps']=[{'engine':'exa','reason':'Exa source retrieval unavailable'}]
|
|
if not queries:d['exa']['queries']=[]
|
|
p.write_text(json.dumps(d),encoding='utf-8')
|
|
for name in ['standard-web.md','exa.md','comparison.md']:
|
|
q=self.p/name;q.write_text(q.read_text(encoding='utf-8')+'\ncompleted-with-gaps: Exa source retrieval unavailable\n',encoding='utf-8')
|
|
def test_gaps_deliverable(self):
|
|
self.gaps(False);self.assertEqual(m.validate(self.p),[]);self.assertFalse(m.checkpoint_eligible(self.p))
|
|
def test_full_checkpoint(self):self.assertTrue(m.checkpoint_eligible(self.p))
|
|
def test_gaps_cannot_excuse_unopened_source(self):
|
|
self.gaps();self.mutate('source_opened',False);self.assertTrue(m.validate(self.p))
|
|
def test_gaps_cannot_excuse_old_evidence(self):
|
|
self.gaps();self.mutate('evidence_date','2026-06-01');self.assertTrue(m.validate(self.p))
|
|
def test_gaps_require_disclosure(self):
|
|
self.gaps();p=self.p/'comparison.md';p.write_text('No gaps',encoding='utf-8');self.assertTrue(m.validate(self.p))
|
|
def test_gap_requires_reason(self):
|
|
self.gaps();p=self.p/'search-log.json';d=json.loads(p.read_text());d['coverage_gaps'][0]['reason']='';p.write_text(json.dumps(d));self.assertTrue(m.validate(self.p))
|
|
def test_missing_search_not_silent(self):
|
|
p=self.p/'search-log.json';d=json.loads(p.read_text());d['exa']['queries']=[];p.write_text(json.dumps(d));self.assertTrue(m.validate(self.p))
|
|
def test_gap_cannot_excuse_missing_artifact(self):
|
|
self.gaps();(self.p/'exa.md').unlink();self.assertTrue(m.validate(self.p))
|
|
if __name__=='__main__':unittest.main()
|