added
This commit is contained in:
commit
ffbf83ebc5
41 files changed
+2782
No files matched your search
@@ -0,0 +1,3 @@
|
||||
# Tests
|
||||
|
||||
Run `python -B -m unittest discover -s tests -v`. Tests cover complete-week boundaries, rejected incomplete evidence, provenance, idempotent finalization, standard catalog compatibility, metadata alignment and unchanged checkpoint behavior. Synthetic fixtures do not constitute weekly research.
|
||||
@@ -0,0 +1,79 @@
|
||||
import copy
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import test_workflow as fixtures
|
||||
|
||||
w = fixtures.w
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
spec = importlib.util.spec_from_file_location('structural_validator', ROOT / 'scripts/validate_repository.py')
|
||||
v = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(v)
|
||||
|
||||
|
||||
class RepositoryStructureTests(unittest.TestCase):
|
||||
def test_real_repository_alignment(self):
|
||||
result = v.validate(ROOT)
|
||||
self.assertTrue(result['passed'], result['findings'])
|
||||
|
||||
def test_mismatched_identity_rejected(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
variables = w.read(ROOT / 'repository-variables.json')
|
||||
manifest = w.read(ROOT / 'repository.json')
|
||||
variables['identity']['publisher']['name'] = 'Synthetic unrelated publisher'
|
||||
w.atomic_json(root / 'repository-variables.json', variables)
|
||||
findings = []
|
||||
v.validate_variables(root, manifest, findings)
|
||||
self.assertTrue(any('Publisher differs' in f['message'] for f in findings))
|
||||
|
||||
def test_catalog_schema_and_operational_checkpoint_are_separate(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
fixtures.WorkflowTests().fixture(root)
|
||||
w.finalize(root, 'evidence/run.json')
|
||||
w.finalize(root, 'evidence/run.json')
|
||||
index = w.read(root / 'content-index.json')
|
||||
item = index['items'][0]
|
||||
self.assertEqual(item['content_id'], 'outdoor-industry-run')
|
||||
self.assertEqual(item['path'], 'reports/run.md')
|
||||
self.assertEqual(item['status'], 'draft')
|
||||
self.assertIsNone(item['published_at'])
|
||||
schema = w.read(ROOT / 'schemas/content-index.schema.json')
|
||||
contract = schema['$defs']['contentItem']
|
||||
self.assertTrue(set(contract['required']) <= set(item))
|
||||
self.assertTrue(set(item) <= set(contract['properties']))
|
||||
checkpoint = w.read(root / 'state/last-successful-run.json')
|
||||
self.assertEqual(set(checkpoint), {'id', 'report_path', 'evidence_path', 'window'})
|
||||
self.assertEqual(checkpoint['evidence_path'], 'evidence/run.json')
|
||||
self.assertEqual(w.validate_repo(root)['indexed_reports'], 1)
|
||||
|
||||
def test_catalog_cannot_claim_incomplete_evidence(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
e = fixtures.WorkflowTests().fixture(root)
|
||||
w.finalize(root, 'evidence/run.json')
|
||||
e['coverage']['exa'] = 'unavailable'
|
||||
w.atomic_json(root / 'evidence/run.json', e)
|
||||
with self.assertRaises(ValueError):
|
||||
w.validate_repo(root)
|
||||
|
||||
def test_duplicate_catalog_path_rejected(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
fixtures.WorkflowTests().fixture(root)
|
||||
w.finalize(root, 'evidence/run.json')
|
||||
index = w.read(root / 'content-index.json')
|
||||
duplicate = copy.deepcopy(index['items'][0])
|
||||
duplicate['content_id'] = 'different-id'
|
||||
index['items'].append(duplicate)
|
||||
w.atomic_json(root / 'content-index.json', index)
|
||||
with self.assertRaises(ValueError):
|
||||
w.validate_repo(root)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,89 @@
|
||||
import copy
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
spec = importlib.util.spec_from_file_location("workflow", Path(__file__).parents[1] / "scripts/workflow.py")
|
||||
w = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(w)
|
||||
|
||||
|
||||
class WorkflowTests(unittest.TestCase):
|
||||
def test_completed_week_on_monday_and_midweek(self):
|
||||
expected = {"start": "2026-10-12", "end_exclusive": "2026-10-19", "timezone": "America/Denver"}
|
||||
self.assertEqual(w.window("2026-10-19"), expected)
|
||||
self.assertEqual(w.window("2026-10-21"), expected)
|
||||
|
||||
def test_dst_weeks_use_local_calendar(self):
|
||||
self.assertEqual(w.window("2026-11-02")["start"], "2026-10-26")
|
||||
self.assertEqual(w.window("2026-03-09")["start"], "2026-03-02")
|
||||
|
||||
def test_path_escape(self):
|
||||
with self.assertRaises(ValueError):
|
||||
w.inside(Path.cwd(), "../outside.json")
|
||||
|
||||
def fixture(self, root):
|
||||
for d in ("config", "reports", "evidence", "receipts", "state"):
|
||||
(root / d).mkdir()
|
||||
w.atomic_json(root / "config/research.json", {"baseline_searches_per_method": 6})
|
||||
w.atomic_json(root / "repository.json", {"version": "0.1.0", "entrypoints": {}})
|
||||
(root / "VERSION").write_text("0.1.0")
|
||||
w.atomic_json(root / "content-index.json", {"items": [], "updated_at": "2026-10-14"})
|
||||
(root / "playbook.md").write_text("# Strategy")
|
||||
body = "\n".join("## " + h for h in w.HEADINGS)
|
||||
body += "\n[S001](https://example.com/news)"
|
||||
(root / "reports/run.md").write_text(body)
|
||||
receipt = {"run_id": "run", "status": "complete", "validation_passed": True, "gaps": [], "capture_completeness": "complete", "started_at": "2026-10-19T07:00:00-06:00", "ended_at": "2026-10-19T07:30:00-06:00", "usage": None}
|
||||
w.atomic_json(root / "receipts/run.json", receipt)
|
||||
e = {"run_id": "run", "run_date": "2026-10-19", "window": w.window("2026-10-19"), "status": "complete", "report_path": "reports/run.md", "receipt_path": "receipts/run.json", "coverage": {p: "complete" for p in w.POOLS}, "playbook": {"path": str(root / "playbook.md"), "sha256": w.hashlib.sha256((root / "playbook.md").read_bytes()).hexdigest(), "sections": ["strategy"]}, "searches": [{"method": m, "query": "fixture", "status": "ok", "returned_count": 0} for m in ("standard_web", "exa") for _ in range(6)], "pool_checks": {p: [{"url": "https://example.com/index", "status": "ok"}] for p in ("sec_edgar", "rock_fight")}, "sources": [{"id": "S001", "url": "https://example.com/news", "title": "fixture", "published_date": "2026-10-12", "discovery_methods": ["standard_web", "exa"], "retrieval_method": "web_open", "format": "article", "claim": "fixture", "north_america_relevance": "U.S. retail", "evidence_level": "explicit", "confidence": "high", "kind": "news"}]}
|
||||
w.atomic_json(root / "evidence/run.json", e)
|
||||
return e
|
||||
|
||||
def test_success_is_idempotent(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
self.fixture(root)
|
||||
w.finalize(root, "evidence/run.json")
|
||||
w.finalize(root, "evidence/run.json")
|
||||
self.assertEqual(len(w.read(root / "content-index.json")["items"]), 1)
|
||||
self.assertTrue((root / "state/last-successful-run.json").exists())
|
||||
|
||||
def test_bad_evidence_never_advances_checkpoint(self):
|
||||
for mutation in ("missing_exa", "stale", "partial", "podcast", "sec", "hash", "unknown_date"):
|
||||
with self.subTest(mutation=mutation), tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
e = self.fixture(root)
|
||||
if mutation == "missing_exa":
|
||||
e["searches"] = [s for s in e["searches"] if s["method"] != "exa"]
|
||||
elif mutation == "stale":
|
||||
e["sources"][0]["published_date"] = "2025-10-12"
|
||||
elif mutation == "partial":
|
||||
e["coverage"]["sec_edgar"] = "unavailable"
|
||||
elif mutation == "podcast":
|
||||
e["sources"][0]["kind"] = "podcast"
|
||||
elif mutation == "sec":
|
||||
e["sources"][0]["kind"] = "sec"
|
||||
elif mutation == "hash":
|
||||
e["playbook"]["sha256"] = "bad"
|
||||
else:
|
||||
e["sources"][0]["published_date"] = "unknown"
|
||||
w.atomic_json(root / "evidence/run.json", e)
|
||||
with self.assertRaises((ValueError, KeyError)):
|
||||
w.finalize(root, "evidence/run.json")
|
||||
self.assertFalse((root / "state/last-successful-run.json").exists())
|
||||
self.assertEqual(w.read(root / "content-index.json")["items"], [])
|
||||
|
||||
def test_failure_count_is_unavailable(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
e = self.fixture(root)
|
||||
e["searches"][0].update(status="error", returned_count=0)
|
||||
w.atomic_json(root / "evidence/run.json", e)
|
||||
with self.assertRaises(ValueError):
|
||||
w.validate_run(root, root / "evidence/run.json")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user