Skip to content

Fix scan-root Markdown link resolution - #5674

Open
sdivyanshu90 wants to merge 1 commit into
Graphify-Labs:v8from
sdivyanshu90:fix/markdown-scan-root-links
Open

sdivyanshu90 wants to merge 1 commit into
Graphify-Labs:v8from
sdivyanshu90:fix/markdown-scan-root-links

Conversation

@sdivyanshu90

Copy link
Copy Markdown
Contributor

Fixes #5672

Summary

  • Resolve leading-slash Markdown inline and reference destinations from the active scan root.
  • Preserve document-relative destinations, explicit absolute paths under the scan root, and wikilink lookup.
  • Bump the AST cache schema so cached Markdown is re-extracted.

Validation

  • The regression builds a graph from a nested Markdown page and checks its references edges. Both scan-root edges are missing on upstream and present with this change.
  • python -m pytest -q tests/test_markdown*.py → 75 passed.
  • ruff check . → passed.
  • python -m pyright --outputjson → same diagnostics as clean upstream (1,258 errors and 241 warnings in this environment).
  • python -m graphify update . → completed.
  • python -m pytest tests -q → 12,592 passed, 147 skipped, 2 xfailed, and 17 failures. The same 17 tests fail on clean upstream in this environment.

@github-actions github-actions Bot added the needs:title PR title should follow the conventional-commit format label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for the pull request, @sdivyanshu90. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks @sdivyanshu90! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example:

fix(python): resolve a bare stdlib import correctly

Prefixes we use: feat, fix, docs, chore, refactor, test, perf, build, ci. Editing the PR title clears this automatically. This is just a nudge and does not block review.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Dec 1, 2026
@sdivyanshu90

Copy link
Copy Markdown
Contributor Author

@safishamsi Could you please review this PR?

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Review before merging · Merge confidence 4/5

1 bug · High impact

Markdown links beginning with / are resolved against the active scan root, with a containment check for paths handled this way.

P2  Encoded leading slashes still resolve from the filesystem root · markdown.py:368

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • A changed file's diff was too long to show in full, so the review may not have seen every changed line in it; the in-depth pass still reviewed every changed file.
  • 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 4174 functions depend on this change
  • 666 of 666 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed cfc1485

Comment on lines 365 to +368
return None
link_root = None
if not wikilink:
# Decoding can reveal a scheme or a protocol-relative prefix
# (%2F%2Fhost), so the external-link guard runs again.
if target.startswith("/") and (scan_root := _active_scan_root()) is not None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2  Encoded leading slashes still resolve from the filesystem root

A Markdown link whose leading slash is percent-encoded can point outside the scan root instead of resolving from the project root.

Handle decoded leading slashes like literal leading slashes in _resolve_markdown_link.

Evidence · checked against the code

Expected: The decoded target resolves beneath the scan root, like a literal leading-slash link.
Actually: The decoded target is an absolute path and is returned without being anchored to the scan root.

  • Independent source review: The literal /docs/guide.md path is handled by the new scan-root branch, which switches the source directory to the scan root and strips the leading slash. That guard does not apply to %2Fdocs/guide.md. The inspected tests cover percent-decoded external prefixes and ordinary percent-decoded filenames, but do not exercise an encoded leading slash with an active scan root.
Prompt to fix with AI
In graphify/extractors/markdown.py, _resolve_markdown_link (lines 365-368):
Problem: Encoded leading slashes still resolve from the filesystem root
Expected: The decoded target resolves beneath the scan root, like a literal leading-slash link.
Actually: The decoded target is an absolute path and is returned without being anchored to the scan root.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor needs:title PR title should follow the conventional-commit format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown repository-root links are missing from the built graph

1 participant