test_landing_large_html.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 1 | """Stress tests — landing validator on large HTML payloads.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import time |
| 6 | from pathlib import Path |
| 7 | |
| 8 | from tools.landing.validate import validate_landing |
| 9 | |
| 10 | KIT_ROOT = Path(__file__).resolve().parents[2] |
| 11 | |
| 12 | |
| 13 | def test_validator_large_padded_html_bounded(tmp_path: Path) -> None: |
| 14 | """Duplicate landing tree with padded HTML; validator must finish without OOM.""" |
| 15 | landing_src = KIT_ROOT / "docs" / "landing" |
| 16 | landing_dst = tmp_path / "docs" / "landing" |
| 17 | landing_dst.mkdir(parents=True) |
| 18 | |
| 19 | # Stub linked doc targets referenced from landing pages. |
| 20 | linked = [ |
| 21 | "README.md", |
| 22 | "docs/GIT-ONLY-QUICKSTART.md", |
| 23 | "docs/CONSUMER-ADAPTER-PATTERN.md", |
| 24 | "docs/K7-DOGFOOD-OPERATOR-RUNBOOK.md", |
| 25 | "docs/TRACK-Q-DESKTOP-OPERATOR-RUNBOOK.md", |
| 26 | "docs/ROADMAP.md", |
| 27 | "docs/archive/phases/PHASE-K12-TRACK-N-LANDING-CONTRACT.md", |
| 28 | "docs/consumers/videofactory/OVERSEER-SETUP.md", |
| 29 | "docs/consumers/knowtation/OVERSEER-SETUP.md", |
| 30 | "docs/consumers/scooling/OVERSEER-SETUP.md", |
| 31 | "templates/ci/freeze-review-github-actions.yml", |
| 32 | ] |
| 33 | for rel in linked: |
| 34 | path = tmp_path / rel |
| 35 | path.parent.mkdir(parents=True, exist_ok=True) |
| 36 | path.write_text("# stub\n", encoding="utf-8") |
| 37 | |
| 38 | for rel in ( |
| 39 | "manifest.yaml", |
| 40 | "index.html", |
| 41 | "docs.html", |
| 42 | "assets/style.css", |
| 43 | "assets/favicon.ico", |
| 44 | "assets/favicon-32.png", |
| 45 | "assets/apple-touch-icon.png", |
| 46 | "assets/theme.js", |
| 47 | "assets/musehub-logo.svg", |
| 48 | "assets/ok-mark.svg", |
| 49 | "assets/ok-mark-1024.png", |
| 50 | ): |
| 51 | src = landing_src / rel |
| 52 | if not src.is_file(): |
| 53 | continue |
| 54 | dst = landing_dst / rel |
| 55 | dst.parent.mkdir(parents=True, exist_ok=True) |
| 56 | if rel.endswith(".html"): |
| 57 | content = src.read_text(encoding="utf-8") |
| 58 | content = content.replace("</body>", "<!-- " + ("x" * 500_000) + " --></body>") |
| 59 | dst.write_text(content, encoding="utf-8") |
| 60 | elif rel.endswith((".css", ".js", ".yaml")): |
| 61 | dst.write_text(src.read_text(encoding="utf-8"), encoding="utf-8") |
| 62 | else: |
| 63 | dst.write_bytes(src.read_bytes()) |
| 64 | |
| 65 | diagrams_src = landing_src / "assets" / "diagrams" |
| 66 | diagrams_dst = landing_dst / "assets" / "diagrams" |
| 67 | diagrams_dst.mkdir(parents=True, exist_ok=True) |
| 68 | for svg in diagrams_src.glob("*.svg"): |
| 69 | (diagrams_dst / svg.name).write_bytes(svg.read_bytes()) |
| 70 | |
| 71 | scenarios_dst = landing_dst / "scenarios" / "index.html" |
| 72 | scenarios_dst.parent.mkdir(parents=True, exist_ok=True) |
| 73 | scenarios_dst.write_text( |
| 74 | (landing_src / "scenarios" / "index.html").read_text(encoding="utf-8"), |
| 75 | encoding="utf-8", |
| 76 | ) |
| 77 | (tmp_path / "LICENSE").write_text((KIT_ROOT / "LICENSE").read_text(encoding="utf-8")) |
| 78 | (tmp_path / "SECURITY.md").write_text((KIT_ROOT / "SECURITY.md").read_text(encoding="utf-8")) |
| 79 | |
| 80 | start = time.monotonic() |
| 81 | result = validate_landing(tmp_path) |
| 82 | elapsed = time.monotonic() - start |
| 83 | |
| 84 | assert result.ok, result.errors |
| 85 | assert elapsed < 2.0 |