okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-ctl: GitHub setup, Docker, docs and bench items for 0.2.7538acd098

main
4.3 KiB77 linesraw
1"""docs/TROUBLESHOOTING.md keeps every entry the 0.2.5 rewrite lost (restored for 0.2.7), and every pointer to it resolves.
2
3setup.py and the server print "see docs/TROUBLESHOOTING.md" with an entry's name, DETAILS.md sends readers there for environment variables, and other
4pages link to its headings. An entry that disappears turns those pointers into dead ends (the "Windows AMD: the driver resets" entry did, and setup's own
5test failed on it).
6"""
7from __future__ import annotations
8
9import re
10import unittest
11from pathlib import Path
12
13ROOT = Path(__file__).resolve().parents[2]
14PAGE = ROOT / "docs" / "TROUBLESHOOTING.md"
15
16# One distinctive phrase from the title of each entry the v0.2.4.2 page had (the page may reword the rest).
17ENTRIES = [
18    "couldn't find an engine for this computer", "needs a newer engine", "damaged and can't be opened", "strata doctor", "Sending logs for a bug report",
19    "froze, or got very slow", "app keeps more graphics memory free", "A download stopped", "driver is too old", "Port 8080 is already in use",
20    "Smart App Control", "new engine misbehaves", "git pull did not succeed", "build tools could not be installed", "does not compile",
21    "Startup takes a long time", "does not match GitHub's checksum", "It is slow and the disk light", "engine stopped unexpectedly", "exit code -9",
22    "exceeds the context", "slower than the tables", "came back empty", "Turing card", "--expert-cache N", "--resident-budget-gib N",
23    "page-locked expert copy", "0x141", "RTX 50 card", "Pictures are refused", "KFD topology is empty", "build's list", "0xC0000005",
24    "the driver resets", "Large pinned host allocations", "verify: timed out at layer N",
25]
26
27
28def slug(heading: str) -> str:
29    return re.sub(r"[^\w\- ]", "", heading.strip().lower()).replace(" ", "-")
30
31
32def anchors(path: Path) -> set[str]:
33    return {slug(h) for h in re.findall(r"^#+\s+(.*)$", path.read_text(encoding="utf-8"), re.M)}
34
35
36class TroubleshootingPage(unittest.TestCase):
37    def setUp(self):
38        self.text = PAGE.read_text(encoding="utf-8")
39        self.flat = re.sub(r"\s+", " ", self.text.replace("*", ""))
40
41    def test_every_entry_of_v0_2_4_2_is_on_the_page(self):
42        for phrase in ENTRIES:
43            self.assertIn(re.sub(r"\s+", " ", phrase), self.flat, f"the entry about {phrase!r} is missing")
44
45    def test_what_setup_and_the_server_point_to_is_there(self):
46        setup = (ROOT / "setup.py").read_text(encoding="utf-8")
47        for name in re.findall(r'docs/TROUBLESHOOTING\.md, \\"([^"\\]+)\\"', setup):
48            self.assertIn(name, self.text, f"setup.py points to the entry {name!r}")
49        server = (ROOT / "serve" / "server.py").read_text(encoding="utf-8")
50        self.assertIn("docs/TROUBLESHOOTING.md", server)
51        self.assertIn("Smart App Control", self.text)        # that pointer is the blocked-executable message
52        self.assertIn("--vision no", self.text)              # which names the way out for a source checkout
53
54    def test_the_variables_that_other_pages_send_here_are_explained(self):
55        details = (ROOT / "docs" / "DETAILS.md").read_text(encoding="utf-8")
56        for line in details.splitlines():
57            if "TROUBLESHOOTING.md" in line:
58                for name in re.findall(r"STRATA_[A-Z0-9_]+", line):
59                    self.assertIn(name, self.text, f"DETAILS.md sends readers here for {name}")
60
61    def test_links_into_the_page_and_out_of_it_resolve(self):
62        own = anchors(PAGE)
63        for md in sorted((ROOT / "docs").glob("*.md")) + [ROOT / "README.md", ROOT / "SECURITY.md"]:
64            for target in re.findall(r"\(((?:\.\./)?(?:docs/)?TROUBLESHOOTING\.md#[^)\s]+)\)", md.read_text(encoding="utf-8")):
65                self.assertIn(target.split("#", 1)[1], own, f"{md.name} links to {target}")
66        for match in re.finditer(r"\]\(([^)#\s]+)?(#[^)\s]*)?\)", self.text):
67            name, anchor = match.group(1), match.group(2)
68            if name and name.startswith("http"):
69                continue
70            target = (PAGE.parent / name).resolve() if name else PAGE
71            self.assertTrue(target.exists(), f"the page links to {name}, which is not there")
72            if anchor and target.suffix == ".md":
73                self.assertIn(anchor[1:], anchors(target), f"the page links to {name or ''}{anchor}")
74
75
76if __name__ == "__main__":
77    unittest.main()