80 lines
3.4 KiB
Python
80 lines
3.4 KiB
Python
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()
|