docs: document scaffold status and make local doc checks reproducible

This commit is contained in:
shira committed 2026-10-05 21:03:19 +03:00
1 parent 70f96adf26
commit 0f206bfc29
7 files changed
+214 -7

No files matched your search

+66 -1
View File
@@ -1,9 +1,13 @@
from __future__ import annotations
import importlib.util
import os
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
from unittest import mock
MODULE_PATH = Path(__file__).with_name("docs-check.py")
@@ -13,7 +17,9 @@ DOCS_CHECK = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(DOCS_CHECK)
class DocsCheckTests(unittest.TestCase):
class RepositoryTestCase(unittest.TestCase):
"""Create a minimal valid repository layout in a temporary directory."""
def setUp(self) -> None:
self.temporary = tempfile.TemporaryDirectory()
self.root = Path(self.temporary.name)
@@ -40,6 +46,8 @@ class DocsCheckTests(unittest.TestCase):
path.write_text(content, encoding="utf-8")
return path
class DocsCheckTests(RepositoryTestCase):
def test_accepts_angle_bracket_path_with_spaces(self) -> None:
self.write("README.md", "# Root\n\n[Guide](<guides/guide with spaces.md>)\n")
self.write("guides/guide with spaces.md", "# Guide\n")
@@ -119,5 +127,62 @@ class DocsCheckTests(unittest.TestCase):
self.assertTrue(any("instruction import cycle" in error for error in errors), errors)
@unittest.skipUnless(shutil.which("git"), "git is required for ignore-rule tests")
class DocsCheckGitIgnoreTests(RepositoryTestCase):
LOCAL_README = "docs/other/notes/README.md"
def setUp(self) -> None:
super().setUp()
# Isolate git from user and system configuration and from any parent repository.
environment = mock.patch.dict(
os.environ,
{
"GIT_CONFIG_GLOBAL": os.devnull,
"GIT_CONFIG_NOSYSTEM": "1",
"GIT_CEILING_DIRECTORIES": str(self.root.resolve().parent),
},
)
environment.start()
self.addCleanup(environment.stop)
self.write(self.LOCAL_README, "[Missing](missing.md)\n")
def git(self, *arguments: str) -> None:
subprocess.run(["git", *arguments], cwd=self.root, check=True, capture_output=True)
def local_errors(self) -> list[str]:
errors = DOCS_CHECK.validate_repository(self.root)
return [error for error in errors if self.LOCAL_README in error]
def test_skips_markdown_excluded_through_info_exclude(self) -> None:
self.git("init", "--quiet")
with (self.root / ".git" / "info" / "exclude").open("a", encoding="utf-8") as exclude:
exclude.write("/docs/other/\n")
self.assertEqual([], DOCS_CHECK.validate_repository(self.root))
def test_skips_markdown_ignored_through_gitignore(self) -> None:
self.git("init", "--quiet")
self.write(".gitignore", "/docs/other/\n")
self.assertEqual([], DOCS_CHECK.validate_repository(self.root))
def test_reports_untracked_markdown_that_is_not_ignored(self) -> None:
self.git("init", "--quiet")
errors = self.local_errors()
self.assertTrue(any("broken local link" in error for error in errors), errors)
self.assertTrue(any("README is below a top-level directory" in error for error in errors), errors)
def test_reports_tracked_markdown_that_matches_ignore_rules(self) -> None:
self.git("init", "--quiet")
self.write(".gitignore", "/docs/other/\n")
self.git("add", "--force", self.LOCAL_README)
errors = self.local_errors()
self.assertTrue(any("broken local link" in error for error in errors), errors)
def test_reports_markdown_outside_git_work_tree(self) -> None:
self.write(".gitignore", "/docs/other/\n")
errors = self.local_errors()
self.assertTrue(any("broken local link" in error for error in errors), errors)
self.assertTrue(any("README is below a top-level directory" in error for error in errors), errors)
if __name__ == "__main__":
unittest.main()