Skip to content

fix(compile): validate link paths independently of #fragment and ?query - #3713

Merged
Daniel Meppiel (danielmeppiel) merged 4 commits into
microsoft:mainfrom
bodapatisaikrishna:fix/3255-link-validation-suffixes
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 4 commits into
microsoft:mainfrom
bodapatisaikrishna:fix/3255-link-validation-suffixes

Conversation

@bodapatisaikrishna

Copy link
Copy Markdown
Contributor

Description

apm compile reported Referenced file not found for a relative Markdown
link whose target exists but carries a #fragment, ?query, or both. For
example, [template](references/standards.md#template) was checked as a file
literally named standards.md#template.

validate_link_targets now splits the target with
UnifiedLinkResolver._split_link_target — the interpretation the rewrite path
already uses — and validates only the path component. Missing-file diagnostics
name that path without the suffix. Suffix values themselves are not validated:
the heading or query is not checked against the target document.

Emitted links, suffix preservation, inlining, install-time rewriting,
containment and invalid-path checks, and dry-run versus write semantics are
unchanged.

Issue and approved scope

Issue: Fixes #3255

Human scope-approval comment:
#3255 (comment)

This PR completes the issue as scoped. It does not add heading-ID validation,
section extraction, a new Markdown parser, or any new flag or target.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality

Local verification:

  • pytest tests/unit/compilation -q: 1514 passed, 1 skipped.
  • pytest tests/unit -q: 26,937 passed, 59 skipped. The 11 failures in this
    shell are unrelated environment checks in test_governance_evidence.py and
    test_helpers.py that require node and a python executable on PATH;
    they pass with node available, except the check for a literal python
    binary, which this environment does not provide.
  • ruff check and ruff format --check on the changed files: clean.
  • Manual apm compile --dry-run in a scratch project: existing targets with
    #fragment, ?query, and combined suffixes produced no missing-file
    warning; references/missing.md#template produced one warning naming
    references/missing.md. No preview files were written.

Spec conformance (OpenAPM v0.1)

  • N/A — this PR does not change OpenAPM-observable behaviour.

A markdown target such as references/standards.md#template names a file
plus a section address. validate_link_targets passed the whole target to
the filesystem check, so an existing file produced a false
'Referenced file not found' warning whenever the link carried a
#fragment, ?query, or both.

Split the target with UnifiedLinkResolver._split_link_target, the same
interpretation the rewrite path already uses, and validate only the path
component. Missing-file diagnostics now name that path without the
suffix. Suffix values are not validated, and link emission, inlining,
install-time rewriting and dry-run write semantics are unchanged.

Fixes microsoft#3255

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change separating filesystem-path validation from link fragments and queries.

No open issues 🎉

What changed in this PR

Fixes #3255 by making apm compile validate the filesystem path separately from Markdown link fragments and queries, avoiding false missing-file warnings.

Changes:

  • Reuses the existing link-target splitter for path validation and diagnostics, without changing link rewriting or inlining.
  • Adds regression tests for existing and missing targets with suffixes, plus CLI dry-run coverage.
  • Documents that heading and query values are not validated.
File Description
tests/​unit/​compilation/​test_link_resolver_phase3.py Adds parameterized tests for fragment, query, and combined suffixes.
tests/​unit/​compilation/​test_compile_link_validation.py Adds CLI coverage for warnings and dry-run output-file behavior.
src/​apm_cli/​compilation/​link_resolver.py Validates and reports only the path component of link targets.
docs/​src/​content/​docs/​producer/​package-relative-links.md Clarifies path-only validation and its limits.
CHANGELOG.md Records the fix and unchanged surrounding behavior.

Review effort: Balanced

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Thank you Sai krishna Bodapati (@bodapatisaikrishna) for this focused fix.

This PR links #3255, which has a current maintainer scope record (#3255 (comment)), and the description maps the change to that scope.

Before human review, it needs a rebase on main:

  • Main consolidated duplicate unit tests (011445b), which removed tests/unit/compilation/test_link_resolver_phase3.py. Please move your new cases into the surviving link resolver test module.
  • Main redesigned the docs site (94382be), which removed docs/src/content/docs/producer/package-relative-links.md. Please re-apply the doc note to the page that now covers package-relative links, or drop it if no page fits.

CI has not run on this fork head yet. A maintainer has to approve the workflow runs after you push. CODEOWNERS reviewers (Daniel Meppiel (@danielmeppiel), Sergio Sisternes (@sergio-sisternes-epam)) are already requested.

This is a triage recommendation only, not merge approval.


Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors.

@danielmeppiel Daniel Meppiel (danielmeppiel) added triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented. pillar/produce Pillar: author, package, publish and patch with confidence labels Nov 21, 2026
… files

Main removed tests/unit/compilation/test_link_resolver_phase3.py and
docs/src/content/docs/producer/package-relative-links.md. Move the suffix
cases and the compile CLI case into tests/unit/compilation/test_link_resolver.py,
the doc note into producer/write-primitives.md, and replace the direct
CHANGELOG.md entry with changelog.d/3713.fixed.md.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

Thanks Sai krishna Bodapati (@bodapatisaikrishna). To keep this moving for 0.38.0 I merged main into your branch (your commit is unchanged) and resolved the conflicts the triage note listed:

  • The suffix cases and the apm compile --dry-run case now live in tests/unit/compilation/test_link_resolver.py (the phase3 module was removed on main).
  • The doc note moved to producer/write-primitives.md, section "Links between files".
  • The CHANGELOG line is now the fragment changelog.d/3713.fixed.md (main uses per-PR fragments).

The new cases fail on main's link_resolver.py (7 failed) and pass with your fix (79 passed). CI runs are approved.


This comment is AI-generated (P3 lead agent) and may contain errors.

…nit module

The return-value cases sat in a component module and tripped the AQ003
unobserved-outcome ratchet (72 > 70). The compile CLI case stays there.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests lack the required installed-CLI regression coverage for normal and preview modes, all three suffix forms with existing and missing targets, and output-file behavior.

1 open issue

Review effort: Balanced

…icrosoft#3255)

Drive the installed apm compile in normal and --dry-run modes over
#fragment, ?query and combined suffixes: existing targets raise no
missing-file warning, missing targets are named without the suffix,
emitted links keep their suffix, and --dry-run writes nothing. Fails on
main's link_resolver (2 failed), passes with the fix. Answers the review
thread asking for the scope's installed-CLI done-when.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The regression tests perform real filesystem I/O in a unit-marked module, violating the marker definitions and misclassifying them during marker-based selection.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Mark filesystem-I/O regressions as component tests

tests/​unit/​compilation/​test_link_resolver_resolution.py:186

These regressions perform real filesystem I/O, but this module declares pytest.mark.unit at line 24. That conflicts with the behavioral definitions in pyproject.toml:201-202 (unit excludes filesystem access; component includes it) and misclassifies these cases during marker-based selection. Move this class into the existing component-marked test_link_resolver.py rather than adding a function-level behavioral marker to this pure-helper module.

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 880e055 into microsoft:main Nov 22, 2026
75 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pillar/produce Pillar: author, package, publish and patch with confidence triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] apm compile reports 'Referenced file not found' for links with a #fragment

3 participants