mirror of
https://github.com/luongnv89/claude-howto.git
synced 2026-06-10 10:43:54 +02:00
test(scripts): cover repo-root boundary in check_cross_references (#95)
* test(scripts): cover repo-root boundary in check_cross_references Locks in the boundary behavior added in #91: links resolving outside the repo root are silently skipped, in-repo broken links still error, and valid in-repo links still pass. * test(scripts): cover missing-README detection in numbered lesson dirs
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Tests for check_cross_references.py — focus on repo-root boundary."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
import check_cross_references
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
return tmp_path
|
||||
|
||||
|
||||
def test_links_escaping_repo_root_are_skipped(
|
||||
repo: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
outside = repo.parent / "outside.md"
|
||||
outside.write_text("# Outside")
|
||||
|
||||
rel = os.path.relpath(outside, repo)
|
||||
(repo / "README.md").write_text(f"# Doc\n\n[escape]({rel})\n")
|
||||
|
||||
assert check_cross_references.main() == 0
|
||||
assert "broken cross-reference" not in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_broken_in_repo_link_is_reported(
|
||||
repo: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
(repo / "README.md").write_text("# Doc\n\n[missing](does-not-exist.md)\n")
|
||||
|
||||
assert check_cross_references.main() == 1
|
||||
assert "broken cross-reference" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_valid_in_repo_link_passes(
|
||||
repo: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
(repo / "other.md").write_text("# Other")
|
||||
(repo / "README.md").write_text("# Doc\n\n[ok](other.md)\n")
|
||||
|
||||
assert check_cross_references.main() == 0
|
||||
assert "All cross-references valid" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_numbered_lesson_dir_missing_readme_is_reported(
|
||||
repo: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
(repo / "README.md").write_text("# Doc")
|
||||
(repo / "01-intro").mkdir()
|
||||
|
||||
assert check_cross_references.main() == 1
|
||||
assert "01-intro: missing README.md" in capsys.readouterr().out
|
||||
Reference in New Issue
Block a user