content-explorer/tests/test_ui_provenance.py
tegwick 940a6a90d0 Keep OnCo provenance headers on adapted UI files.
CONTENT-WP-0002-T08 requires each adapted file to name the pinned commit, the OnCo copyright, and ui/NOTICE.

Assistant: grok
Assistant-Session: 01a1346c-fdff-7741-b1af-b7283661554b
2026-10-13 23:32:25 +02:00

64 lines
2.1 KiB
Python

"""Adapted UI files keep the OnCo pin, copyright, and NOTICE."""
from __future__ import annotations
import importlib.util
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location("check_ui_provenance", ROOT / "scripts" / "check_ui_provenance.py")
provenance = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(provenance)
PIN = "b594d7433bf4e408b44215e25e5304696d6f840e"
class UiProvenance(unittest.TestCase):
def test_pin_matches_the_baseline_file(self) -> None:
self.assertEqual(provenance.load_pin(), PIN)
def test_rejects_an_adapted_file_without_the_pin(self) -> None:
sample = """
/**
* Adapted from OnCo SkipLink.
* Copyright (c) 2026 OnCo. MIT License. See ui/NOTICE.
*/
"""
problems = provenance.header_problems(sample, "sample", PIN)
self.assertEqual(len(problems), 1)
self.assertIn(PIN, problems[0])
def test_accepts_a_complete_header(self) -> None:
sample = f"""
/*
* Reduced from OnCo src/components/filters/ResultsTable.tsx
* https://github.com/judegomila/OnCo @ {PIN}
* Copyright (c) 2026 OnCo. MIT License. See ui/NOTICE.
*/
"""
self.assertEqual(provenance.header_problems(sample, "sample", PIN), [])
def test_ignores_a_file_that_was_not_copied(self) -> None:
sample = """
/**
* Generic record page.
* OnCo EntityDetail was not copied.
*/
"""
self.assertEqual(provenance.header_problems(sample, "sample", PIN), [])
def test_notice_requires_the_permission_text(self) -> None:
short = f"Copyright (c) 2026 OnCo\nMIT License\n{PIN}\n"
problems = provenance.notice_problems(short, PIN)
self.assertTrue(problems)
self.assertIn("Permission is hereby granted", problems[0])
def test_shipped_ui_keeps_headers_and_notices(self) -> None:
self.assertEqual(provenance.tree_problems(), [])
if __name__ == "__main__":
unittest.main()