content-explorer/tests/test_ui_provenance.py
tegwick f43edc1edc
Some checks failed
synthetic / suite (push) Has been cancelled
Add a synthetic quality suite and upstream parity record.
Assistant: grok
Assistant-Session: 01a1531b-6698-7732-8587-f28ea604bcdf
2026-10-19 10:38:49 +02:00

67 lines
2.2 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(), [])
def test_third_party_notice_names_the_pin(self) -> None:
self.assertEqual(provenance.third_party_problems(ROOT, PIN), [])
if __name__ == "__main__":
unittest.main()