Repository navigation
Fix root-token boundaries in doc citation scanning #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """Repo-root citation checks must not reinterpret nested upstream paths.""" | ||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| _SPEC = importlib.util.spec_from_file_location( | ||
| "check_doc_citations", Path(__file__).resolve().parents[1] / "tools/check_doc_citations.py") | ||
| citations = importlib.util.module_from_spec(_SPEC) | ||
| _SPEC.loader.exec_module(citations) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def source(tmp_path, monkeypatch): | ||
| monkeypatch.setattr(citations, "REPO", tmp_path) | ||
| root = tmp_path / "src" | ||
| root.mkdir() | ||
| return root / "sample.py" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("prefix", ["upstream-", "upstream/", "upstream_", ".", "../", "\\"]) | ||
| def test_embedded_paths_are_not_local_citations(source, capsys, prefix): | ||
| source.write_text(prefix + "doc/missing.py") # doc-citation-exempt | ||
| assert citations.main() == 0 | ||
| assert "0 citations resolve" in capsys.readouterr().out | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("path", [ | ||
| "jiuwenswarm/resources/skills/skill-gen-4-enterprise-doc/scripts/skill_gen/validator.py", # doc-citation-exempt | ||
| "https://example.test/doc/missing.md", # doc-citation-exempt | ||
| "https://example.test/component-doc/scripts/validator.py", # doc-citation-exempt | ||
| ]) | ||
| def test_upstream_and_url_paths_are_not_local_citations(source, capsys, path): | ||
| source.write_text(path) | ||
| assert citations.main() == 0 | ||
| assert "0 citations resolve" in capsys.readouterr().out | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("text", [ | ||
| "doc/missing.md", # doc-citation-exempt | ||
| "See `doc/missing.md`.", # doc-citation-exempt | ||
| "(doc/missing.md)", # doc-citation-exempt | ||
| "upstream-doc/remote.md and doc/missing.md", # doc-citation-exempt | ||
| ]) | ||
| def test_missing_root_citations_still_fail(source, capsys, text): | ||
| source.write_text(text) | ||
| assert citations.main() == 1 | ||
| assert "1 dangling citation(s) of 1 checked" in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_valid_local_citation_and_root_segments_resolve(source, capsys): | ||
| root = citations.REPO / "doc" | ||
| root.mkdir() | ||
| (root / "guide.md").write_text("guide") | ||
| source.write_text('See `doc/guide.md`.\nROOT / "doc" / "guide.md"') # doc-citation-exempt | ||
| assert citations.main() == 0 | ||
| assert "2 citations resolve" in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_missing_root_segments_still_fail(source, capsys): | ||
| source.write_text('REPO_ROOT / "doc" / "missing.md"') # doc-citation-exempt | ||
| assert citations.main() == 1 | ||
| output = capsys.readouterr().out | ||
| assert "built from path segments" in output | ||
| assert "1 dangling citation(s) of 1 checked" in output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./doccitations in the scanWhen a repository-root citation is written in the common shell-style form
./doc/missing.md, the new negative lookbehind rejects it becausedoc/is preceded by a dot. The scanner then reports zero citations and allows a dangling in-repository reference to pass, contrary to its stated repo-root citation contract. Exclude dots only when they belong to a preceding path component, while continuing to recognize an explicit./doc/...prefix.Useful? React with 👍 / 👎.