wip: add codebase genome status regression tests
This commit is contained in:
113
tests/test_codebase_genome_status.py
Normal file
113
tests/test_codebase_genome_status.py
Normal file
@@ -0,0 +1,113 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
SCRIPT = ROOT / 'scripts' / 'codebase_genome_status.py'
|
||||
|
||||
spec = importlib.util.spec_from_file_location('codebase_genome_status', str(SCRIPT))
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
sys.modules['codebase_genome_status'] = mod
|
||||
spec.loader.exec_module(mod)
|
||||
|
||||
|
||||
class TestCodebaseGenomeStatus(unittest.TestCase):
|
||||
def test_fetch_org_repo_names_ignores_archived_and_dot_repos(self):
|
||||
payloads = [
|
||||
[
|
||||
{'name': 'timmy-home', 'archived': False},
|
||||
{'name': '.profile', 'archived': False},
|
||||
{'name': 'old-repo', 'archived': True},
|
||||
],
|
||||
[],
|
||||
]
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, payload):
|
||||
self.payload = json.dumps(payload).encode('utf-8')
|
||||
def read(self):
|
||||
return self.payload
|
||||
def __enter__(self):
|
||||
return self
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def fake_urlopen(req, timeout=30):
|
||||
return FakeResponse(payloads.pop(0))
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
token_file = pathlib.Path(tmp) / 'token'
|
||||
token_file.write_text('demo-token')
|
||||
from unittest.mock import patch
|
||||
with patch('codebase_genome_status.urllib.request.urlopen', side_effect=fake_urlopen):
|
||||
repos = mod.fetch_org_repo_names('Timmy_Foundation', 'https://forge.example.com', token_file)
|
||||
self.assertEqual(repos, ['timmy-home'])
|
||||
|
||||
def test_collects_artifacts_tests_and_duplicates(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
(root / 'GENOME.md').write_text('# host genome\n')
|
||||
(root / 'the-door-GENOME.md').write_text('# the-door\n')
|
||||
(root / 'genomes' / 'the-nexus').mkdir(parents=True)
|
||||
(root / 'genomes' / 'the-nexus' / 'GENOME.md').write_text('# the-nexus\n')
|
||||
(root / 'genomes' / 'burn-fleet').mkdir(parents=True)
|
||||
(root / 'genomes' / 'burn-fleet' / 'GENOME.md').write_text('# burn-fleet\n')
|
||||
(root / 'genomes' / 'burn-fleet-GENOME.md').write_text('# burn-fleet duplicate\n')
|
||||
(root / 'tests' / 'docs').mkdir(parents=True)
|
||||
(root / 'tests' / 'docs' / 'test_the_door_genome.py').write_text('')
|
||||
(root / 'tests' / 'test_the_nexus_genome.py').write_text('')
|
||||
(root / 'tests' / 'test_codebase_genome_pipeline.py').write_text('')
|
||||
|
||||
summary = mod.build_status_summary(
|
||||
repo_root=root,
|
||||
expected_repos=['timmy-home', 'the-door', 'the-nexus', 'burn-fleet', 'wolf'],
|
||||
state={'last_repo': 'the-nexus'},
|
||||
)
|
||||
|
||||
self.assertEqual(summary['total_expected_repos'], 5)
|
||||
self.assertEqual(summary['artifact_count'], 4)
|
||||
self.assertEqual(summary['tested_artifact_count'], 3)
|
||||
self.assertEqual(summary['next_uncovered_repo'], 'wolf')
|
||||
self.assertEqual(summary['last_repo'], 'the-nexus')
|
||||
self.assertEqual(summary['artifacts']['the-door']['has_test'], True)
|
||||
self.assertEqual(summary['artifacts']['the-nexus']['has_test'], True)
|
||||
self.assertEqual(summary['artifacts']['timmy-home']['has_test'], True)
|
||||
self.assertIn('burn-fleet', summary['duplicates'])
|
||||
self.assertEqual(summary['missing_repos'], ['wolf'])
|
||||
|
||||
def test_render_markdown_contains_required_sections(self):
|
||||
summary = {
|
||||
'generated_at': '2026-04-17T10:00:00Z',
|
||||
'total_expected_repos': 3,
|
||||
'artifact_count': 2,
|
||||
'tested_artifact_count': 1,
|
||||
'last_repo': 'the-door',
|
||||
'next_uncovered_repo': 'wolf',
|
||||
'missing_repos': ['wolf'],
|
||||
'duplicates': {'burn-fleet': ['genomes/burn-fleet/GENOME.md', 'genomes/burn-fleet-GENOME.md']},
|
||||
'artifacts': {
|
||||
'timmy-home': {'artifact_paths': ['GENOME.md'], 'has_test': True},
|
||||
'the-door': {'artifact_paths': ['the-door-GENOME.md'], 'has_test': False},
|
||||
},
|
||||
}
|
||||
rendered = mod.render_markdown(summary)
|
||||
for snippet in [
|
||||
'# Codebase Genome Status',
|
||||
'## Summary',
|
||||
'## Coverage Matrix',
|
||||
'## Missing Repo Artifacts',
|
||||
'## Duplicate Artifact Paths',
|
||||
'the-door-GENOME.md',
|
||||
'genomes/burn-fleet/GENOME.md',
|
||||
'wolf',
|
||||
]:
|
||||
self.assertIn(snippet, rendered)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user