Repository navigation
fix(compile): validate link paths independently of #fragment and ?query #3713
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
Daniel Meppiel (danielmeppiel)
merged 4 commits into
microsoft:main
from
bodapatisaikrishna:fix/3255-link-validation-suffixes
Nov 22, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b9e7e4
fix(compile): validate link paths independently of suffixes
bodapatisaikrishna 3f137c2
Merge main into #3713; move tests and docs note to surviving files
danielmeppiel 8a3adee
test: move #3255 validate_link_targets suffix cases to the unit module
danielmeppiel 3b798de
test(compile): installed-CLI coverage for suffixed link validation (#…
danielmeppiel 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 @@ | ||
| - `apm compile` validates the file path of a relative Markdown link independently of a `#fragment`, `?query` or combined suffix, so an existing file no longer produces a false `Referenced file not found` warning; a missing target is still reported, using the path without the suffix. -- by @bodapatisaikrishna (#3713) |
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
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
82 changes: 82 additions & 0 deletions
82
tests/integration/test_compile_suffixed_link_validation_e2e.py
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,82 @@ | ||
| """Installed-CLI coverage for compile-time validation of suffixed links (#3255). | ||
|
|
||
| A relative Markdown link may carry a ``#fragment``, ``?query`` or both. The | ||
| installed ``apm compile`` must validate the file path without the suffix: an | ||
| existing file is not reported missing, a missing file is reported by its path | ||
| alone, the emitted link keeps its suffix, and ``--dry-run`` writes nothing. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.integration, | ||
| pytest.mark.e2e, | ||
| pytest.mark.requires_apm_binary, | ||
| pytest.mark.requires_e2e_mode, | ||
| pytest.mark.promise("P-OWN-compiled-output-writes"), | ||
| ] | ||
|
|
||
| _SUFFIXES = ("#template", "?view=full", "?view=full#template") | ||
|
|
||
|
|
||
| def _create_project(project: Path) -> None: | ||
| (project / "apm.yml").write_text( | ||
| "name: suffixed-links\nversion: 0.1.0\ntargets:\n - codex\n", encoding="ascii" | ||
| ) | ||
| instructions = project / ".apm" / "instructions" | ||
| instructions.mkdir(parents=True) | ||
| links = [] | ||
| for index, suffix in enumerate(_SUFFIXES): | ||
| links.append(f"[present{index}](references/standards.md{suffix})") | ||
| links.append(f"[absent{index}](references/missing.md{suffix})") | ||
| (instructions / "links.instructions.md").write_text( | ||
| "---\ndescription: Suffixed links\napplyTo: '**'\n---\n# Links\n" + "\n".join(links) + "\n", | ||
| encoding="ascii", | ||
| ) | ||
| references = instructions / "references" | ||
| references.mkdir() | ||
| (references / "standards.md").write_text("# Template\n", encoding="ascii") | ||
|
|
||
|
|
||
| def _compile(apm_binary_path: Path, project: Path, *extra: str) -> str: | ||
| result = subprocess.run( | ||
| (str(apm_binary_path), "compile", *extra), | ||
| cwd=project, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| assert result.returncode == 0, result.stdout + result.stderr | ||
| return " ".join((result.stdout + result.stderr).split()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dry_run", [False, True], ids=["write", "dry-run"]) | ||
| def test_installed_compile_validates_suffixed_link_paths( | ||
| tmp_path: Path, apm_binary_path: Path, dry_run: bool | ||
| ) -> None: | ||
| project = tmp_path / "project" | ||
| project.mkdir() | ||
| _create_project(project) | ||
|
|
||
| output = _compile(apm_binary_path, project, *(("--dry-run",) if dry_run else ())) | ||
|
|
||
| assert "Referenced file not found: references/standards.md" not in output | ||
| for index in range(len(_SUFFIXES)): | ||
| assert ( | ||
| f"Referenced file not found: references/missing.md (in link 'absent{index}')" in output | ||
| ) | ||
| assert "missing.md#" not in output | ||
| assert "missing.md?" not in output | ||
|
|
||
| agents_md = project / "AGENTS.md" | ||
| if dry_run: | ||
| assert not agents_md.exists() | ||
| return | ||
| emitted = agents_md.read_text(encoding="utf-8") | ||
| for suffix in _SUFFIXES: | ||
| assert f"standards.md{suffix})" in emitted |
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
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.
Uh oh!
There was an error while loading. Please reload this page.