The toolkit repository is public and now publishes its own Pages site (benchmarks, badges, quality dashboard), so this site covers only the private SDK and OS. - validate_site: drop the toolkit page; the index may link to the toolkit's bench page. - check_live_pages: /alkane-toolkit/ and its bench page must be public; only the SDK and OS sites must stay closed. - metrics: grade coverage on the toolkit's bands instead of a fixed green A. - README: one CI badge plus the license; the script metrics no longer pose as SDK or OS metrics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
5.5 KiB
Python
123 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Privacy and shape checks for the generated Pages validator."""
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
from validate_site import validate
|
|
|
|
|
|
INDEX = """<!doctype html><html><head><title>Alkane benchmarks</title></head>
|
|
<body><h1>Alkane benchmarks</h1><a href="sdk/">SDK</a>
|
|
<a href="os/">OS</a></body></html>"""
|
|
PAGE = """<!doctype html><html><head><title>Alkane benchmarks</title></head>
|
|
<body><h1>Alkane benchmarks</h1><table><tr><td>10 ns/op</td></tr></table></body></html>"""
|
|
|
|
|
|
class SiteValidationTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.temp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.temp.cleanup)
|
|
self.root = Path(self.temp.name)
|
|
(self.root / "index.html").write_text(INDEX)
|
|
for repo in ("sdk", "os"):
|
|
(self.root / repo).mkdir()
|
|
(self.root / repo / "index.html").write_text(PAGE)
|
|
|
|
def test_valid_data_only_site(self):
|
|
self.assertEqual(validate(self.root), [])
|
|
|
|
def test_single_page_prepublication_cli(self):
|
|
command = [sys.executable, str(Path(__file__).with_name("validate_site.py")),
|
|
"--page", "os", str(self.root / "os/index.html")]
|
|
self.assertEqual(subprocess.run(command, capture_output=True).returncode, 0)
|
|
(self.root / "os/index.html").write_text(PAGE + '<meta http-equiv="refresh" content="0">')
|
|
self.assertEqual(subprocess.run(command, capture_output=True).returncode, 1)
|
|
|
|
def test_rejects_active_content(self):
|
|
(self.root / "os/index.html").write_text(PAGE + "<script>alert(1)</script>")
|
|
self.assertTrue(any("forbidden tag" in error for error in validate(self.root)))
|
|
|
|
def test_rejects_external_source_and_credential_marker(self):
|
|
(self.root / "sdk/index.html").write_text(
|
|
PAGE + '<img src="https://example.com/a.png">GITEA_TOKEN'
|
|
)
|
|
errors = validate(self.root)
|
|
self.assertTrue(any("forbidden tag: img" in error for error in errors))
|
|
self.assertTrue(any("credential marker" in error for error in errors))
|
|
|
|
def test_allows_only_pinned_source_commit_links(self):
|
|
commit = "a" * 40
|
|
(self.root / "os/index.html").write_text(
|
|
PAGE + f'<a href="https://gitea.bluefla.re/blueflare/alkane-os/commit/{commit}">commit</a>'
|
|
)
|
|
self.assertEqual(validate(self.root), [])
|
|
(self.root / "os/index.html").write_text(
|
|
PAGE + '<a href="https://example.com/commit/secret">commit</a>'
|
|
)
|
|
self.assertTrue(any("external or active reference" in error for error in validate(self.root)))
|
|
|
|
def test_allows_link_to_toolkit_site(self):
|
|
(self.root / "index.html").write_text(INDEX.replace(
|
|
"</body>", '<a href="https://blueflare.gitea.bluefla.re/alkane-toolkit/bench/">Toolkit</a></body>'))
|
|
self.assertEqual(validate(self.root), [])
|
|
|
|
def test_rejects_extra_files(self):
|
|
(self.root / "source.tar.gz").write_bytes(b"private source")
|
|
self.assertTrue(any("unexpected published files" in error for error in validate(self.root)))
|
|
|
|
def test_requires_both_reports(self):
|
|
(self.root / "os/index.html").unlink()
|
|
self.assertTrue(any("missing regular page" in error for error in validate(self.root)))
|
|
|
|
def test_rejects_css_import(self):
|
|
(self.root / "os/index.html").write_text(PAGE + "<style>@import 'https://example.com/x.css';</style>")
|
|
self.assertTrue(any("external CSS reference" in error for error in validate(self.root)))
|
|
|
|
def test_rejects_css_escaped_import(self):
|
|
(self.root / "os/index.html").write_text(
|
|
PAGE + r"<style>@im\70ort 'https://example.com/x.css';</style>"
|
|
)
|
|
self.assertTrue(any("external CSS reference" in error for error in validate(self.root)))
|
|
|
|
def test_rejects_meta_refresh(self):
|
|
(self.root / "os/index.html").write_text(
|
|
PAGE + '<meta http-equiv="refresh" content="0;url=https://example.com/">'
|
|
)
|
|
self.assertTrue(any("unexpected meta directive" in error for error in validate(self.root)))
|
|
|
|
def test_rejects_base_and_unexpected_attributes(self):
|
|
(self.root / "os/index.html").write_text(
|
|
PAGE + '<base href="https://example.com/"><a href="../" ping="https://example.com/">Back</a>'
|
|
)
|
|
errors = validate(self.root)
|
|
self.assertTrue(any("forbidden tag: base" in error for error in errors))
|
|
self.assertTrue(any("forbidden attribute on a: ping" in error for error in errors))
|
|
|
|
def test_rejects_unlisted_local_link(self):
|
|
(self.root / "os/index.html").write_text(
|
|
PAGE + '<a href="../../private/">Source</a>'
|
|
)
|
|
self.assertTrue(any("external or active reference" in error for error in validate(self.root)))
|
|
|
|
def test_rejects_symlink(self):
|
|
(self.root / "private").symlink_to(self.root / "os/index.html")
|
|
self.assertTrue(any("contains a symlink" in error for error in validate(self.root)))
|
|
|
|
def test_requires_index_navigation(self):
|
|
(self.root / "index.html").write_text(INDEX.replace('<a href="os/">OS</a>', ""))
|
|
self.assertTrue(any("missing project links" in error for error in validate(self.root)))
|
|
|
|
def test_requires_measurements_or_pending_notice(self):
|
|
(self.root / "sdk/index.html").write_text(
|
|
"<!doctype html><html><head><title>Alkane</title></head><body><h1>Alkane</h1></body></html>"
|
|
)
|
|
self.assertTrue(any("no measurements" in error for error in validate(self.root)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|