#!/usr/bin/env python3 from __future__ import annotations import unittest from pathlib import Path REPO = Path(__file__).resolve().parents[2] BOOKS = REPO / 'books' INFRA = BOOKS / '_infra' BOOK_NAMES = ('workflow-tuts', 'agent-practice-tuts') PER_BOOK_ALLOWED = {'.gitignore', 'README.md', 'Makefile', 'STYLE.md', 'TERMINOLOGY.md', 'templates', 'book.yaml', 'SUMMARY.md', 'manuscript', 'media'} class SharedBookInfraLayoutTests(unittest.TestCase): def test_shared_infra_exists(self) -> None: self.assertTrue((INFRA / 'Brewfile').is_file()) self.assertTrue((INFRA / 'book.mk').is_file()) self.assertTrue((INFRA / 'scripts').is_dir()) self.assertTrue((INFRA / 'theme').is_dir()) def test_books_keep_content_and_book_specific_assets_only(self) -> None: for name in BOOK_NAMES: root = BOOKS / name entries = {path.name for path in root.iterdir()} self.assertTrue(entries.issuperset(PER_BOOK_ALLOWED), f'{name} missing expected content dirs/files') self.assertFalse({'Brewfile', 'scripts', 'theme'} & entries, f'{name} still carries duplicated build infra') def test_book_makefiles_delegate_to_shared_infra(self) -> None: for name in BOOK_NAMES: makefile = (BOOKS / name / 'Makefile').read_text(encoding='utf-8') self.assertIn('../_infra/book.mk', makefile, f'{name} Makefile should include shared book.mk') if __name__ == '__main__': unittest.main()