Repository navigation
feat(markdown): reference files named by backticked paths (#5224) - #5352
vaibhav375 wants to merge 3 commits into
Conversation
|
Thanks for the pull request, @vaibhav375. 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. |
There was a problem hiding this comment.
Graphify review 
5 possible issues to check · High impact
Markdown code spans that name files can now create references to scanned documents and source files.
5 possible issues we couldn't confirm
- Document links from code spans in a section attach to the page, not the section, unlike authored links ·
graphify/extractors/markdown.py:739 - Backticked file paths such as
src/widget.pynever get a page-to-file references edge, because the callee check skips them ·graphify/markdown_resolution.py:476 - The page for a code-span file reference comes from the section chain without checking that the page is a known node ·
graphify/markdown_resolution.py:478 - +2 more in Graphify
They don't change the score.
Code graph · 4064 functions depend on this change
- 2 functions became more coupled.
extract()(1337 callers),extract_markdown()(23 callers). - 63 of 613 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed c5b2dda · 6 earlier findings not re-checked · Full report in the Graphify check
|
Thanks for the review. I went through all seven leads. Changes are in 6201c7a:
The other four are by design:
|
6201c7a to
caf0cc5
Compare
…abs#5224) A Markdown inline code span holding a file path (`src/app.ts`, `docs/other.md`) now becomes a doc->file `references` edge, the same edge the equivalent authored link produces. The path is read relative to the document, then (unless it starts with `./` or `../`) relative to the scan root; it is never matched by suffix, so an ambiguous, missing, outside-root, fenced or non-file span gets no edge. - Document targets are linked at extraction through the existing `add_link`, so they get the `target_file` stamp and the watch reconciliation authored links already have. - Source-file targets stay citations: the raw call carries the span's scan-root reading (`root_path`, a document-relative path computed from realpaths, so symlinked roots work) and the resolver matches both readings against the scanned corpus with `_match_file_link`. Nothing depends on files existing at extraction time, and Graphify-Labs#4804 evidence is unchanged. - Bump `_AST_CACHE_SCHEMA` to 50 so cached Markdown extractions re-run. Co-Authored-By: Claude <noreply@anthropic.com>
…raphify-Labs#5224) `os.path.relpath` raises ValueError on Windows when the scan root and the document are on different drives. The scan-root reading for a source-file span called it unguarded, so such a document would fail to extract. Compute the root's path from the document once, guarded like the sibling call in `add_doc_span`; without it the span keeps only its document-relative reading. Also say in the docstrings that document spans need an active scan root and that `root_path` is never recorded for explicit `./` / `../` cites, and read `source_file` with `.get` in the README page lookup test. Co-Authored-By: Claude <noreply@anthropic.com>
…fy-Labs#5224) `add_doc_span` resolved and stat-ed the path a code span named before checking that it stayed inside the scan root. A span is corpus-chosen, so `//host/share/notes.md` reached `realpath`/`isfile`, which on Windows authenticates to that host over SMB, and `../../outside.md` leaked whether a host file exists: the class GHSA-g6c9-j4vm-mwq4 closed for bash sources. Gate each candidate on `_resolve_safe` from the bash extractor, which refuses a UNC or out-of-tree path on the unresolved candidate before anything touches the filesystem, then resolves and re-checks. Co-Authored-By: Claude <noreply@anthropic.com>
caf0cc5 to
c5b2dda
Compare
What does this PR do?
Fixes #5224.
An AST/structural scan resolved explicit Markdown links to code and Markdown files. A backticked path to the same files (
`src/app.ts`,`docs/other.md`) produced noreferencesedge. This PR gives a code span holding a file path the same doc->filereferencesedge the equivalent link produces: EXTRACTED, from the page, with the span's source location.How a span is resolved:
./or../are read relative to the document only.Implementation, reusing the link paths that already exist:
.md,.mdx,.qmd,.markdown,.rst,.txt) are linked at extraction throughadd_link(graphify/extractors/markdown.py). They get thetarget_filestamp, so the watch rebuild carries them the way it carries authored doc->doc links. The target must be an existing file inside the scan root. The span's path is chosen by the indexed repo, so each candidate goes through_resolve_safe(from the GHSA-g6c9-j4vm-mwq4 fix) first: a UNC (//host/share) or out-of-tree path is refused before anything stats or resolves it. Realpaths are compared, so a symlinked root such as macOS's/var->/private/varworks.root_path).resolve_markdown_mentionstries both readings against the scanned corpus with the existing_match_file_link, and mintspage --references--> file(graphify/markdown_resolution.py)._AST_CACHE_SCHEMAis bumped to 52 with a chainedprior (51)note (rebased onto v83671f311, whose release took 51), so cached Markdown extractions re-run. Renumber as needed when landing.The existing test
test_file_span_is_evidence_but_not_a_doc_file_edgepinned the old "a span is evidence, not a link" behavior from #4806. It is renamed and updated to expect the doc->file edge this issue asks for.Type of change
Verification & Invariants
Invariant: fail closed. A span only becomes an edge when it names exactly one existing, scanned file through a document-relative or scan-root-relative path. In every other case the graph is unchanged from today: no suffix guesses, no edge to a file outside the root, and no edge to a heading named like the file. Persisted state: Markdown AST cache entries are invalidated by the schema bump. No graph.json schema change.
New tests in
tests/test_markdown_code_spans.py. All of them fail againstv8'smarkdown.py,markdown_resolution.pyandcache.py, except the no-edge boundary test:L3.../../path to a real file outside the root,./xwith only a root-levelx, self-citation, fenced spans, and non-file spans._rebuild_code(warm cache vs fresh build).//evil-host/share/notes.mdor an escaping../../outside.md(a real file outside the corpus) never reachesos.stat/os.lstat: the test records every call. It fails on the previous commit, which probed/evil-host/share/....os.path.relpathValueError) does not abort the document's extraction._rebuild_coderuns in subprocesses, as in the existing rebuild tests:./and../document spans resolve identically in partial and full rebuilds, in a corpus with code and in a docs-only corpus.I also mutated each new rule (the scan-root reading, the
.//../restriction on both paths, scan-root containment, and realpath), and each mutation fails at least one test.Limitations / unsupported cases
When both the document-relative and the scan-root-relative file exist, the document-relative one wins, the same precedence
_match_cited_filedocuments.A span inside link text, like
[`src/app.ts`](../src/other.ts), references both the span's file and the link's.Backslash paths and paths with spaces are not file spans, the same as today.
Without an active scan root, document spans do not link. A direct
extract()with noroot=gets document spans only that way. Source-file spans resolve against the corpus either way.Pre-existing, also on 0.9.113 with plain links, so not changed here: in a partial
_rebuild_code, doc->source-file citations inherit two behaviors of the link path. Spans now behave exactly like links in both:[a](./app.ts)fromdocs/gets an edge to the rootapp.tswhendocs/app.tsdoesn't exist._match_file_link's rootless fallback accepts it.[code](../src/app.ts)loses its edge when another scanned file is also namedapp.ts.Happy to open a separate issue for those.
How was this tested?
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments.No skill fragments or generated artifacts are touched, so the first box doesn't apply. Extraction reads the active scan root and the filesystem for document targets, and every corpus-chosen path is gated on
_resolve_safebefore any stat (GHSA-g6c9-j4vm-mwq4). Nothing is interpolated into a shell command or into Python source.