Skip to content

Pin the cross-document explicit-target reference from #1151 - #1198

Closed
dchaudhari7177 wants to merge 10 commits into
executablebooks:masterfrom
dchaudhari7177:fix/1151-false-positive-xref-missing
Closed

dchaudhari7177 wants to merge 10 commits into
executablebooks:masterfrom
dchaudhari7177:fix/1151-false-positive-xref-missing

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Closes #1151 — already fixed on master, so this is the regression test only.

The bisect

I ran the issue's reproduction verbatim against both:

v5.1.0   WARNING: local id not found in doc 'a': 'custom-anchor' [myst.xref_missing]
master   (no warning)

#1158 (stable heading anchors … explicit-id priority) landed after v5.1.0, which is the release the reporter was on. So the fix is in, and the issue can be closed once this or something like it guards it.

Why a new test rather than relying on doc_with_target_id

doc_with_target_id ("(ref)=\n# Title\n[](index.md#ref)") looks like it covers this, but it differs from the reported case in the two ways that mattered:

  • It is one file. The target and the link are both in index.md; the issue is about a link in b.md to a target in a.md.
  • It does not enable myst_heading_anchors. The false positive came from heading-anchor resolution taking precedence over the explicit target, so a case without heading anchors cannot see it.

The new test uses two documents with myst_heading_anchors: 3, and puts the explicit target directly above a heading — the placement that made heading-anchor resolution take over. It asserts on both spellings together ([](a.md#custom-anchor) and [](#custom-anchor)), since the bug was precisely that the two disagreed.

sphinx_doctree.srcdir is used to write the second file before the call, which is the only wrinkle — the fixture's __call__ writes one file, but the source directory is available for the rest.

Verified the test bites

Checked out v5.1.0, copied this test in, and ran it:

E  assert not "<src>\index.md:3: WARNING: local id not found in doc 'a': 'custom-anchor' [myst.xref_missing]"
FAILED test_cross_document_reference_to_an_explicit_target

Exactly the warning from the issue. On master it passes.

pytest tests/test_renderers/test_myst_refs.py    14 passed, 2 skipped
ruff 0.15.20 check / format                      clean

No source change, so no changelog entry.

dchaudhari7177 and others added 10 commits September 6, 2026 22:21
…#1151

`[](a.md#custom-anchor)` emitted

    local id not found in doc 'a': 'custom-anchor' [myst.xref_missing]

on 5.1.0, while rendering the correct working href -- and the pathless
`[](#custom-anchor)` form of the same reference resolved silently.

This is already fixed on master: executablebooks#1158 (explicit-id priority) landed after
v5.1.0. Bisected by running the issue's reproduction against both:

    v5.1.0   WARNING: local id not found in doc 'a': 'custom-anchor'
    master   (no warning)

So this adds only the regression test. The existing `doc_with_target_id`
case looks like it covers this, but it has the target and the link in one
file and does not enable `myst_heading_anchors` -- and it is the combination
of a second document plus heading-anchor resolution that produced the false
positive. The target is placed directly above a heading for the same reason.

Verified the test bites: on v5.1.0 it fails with exactly the warning from
the issue.

Closes executablebooks#1151
A path link with empty text to an explicit target in another document,
such as `[](other.md#my-label)` where `other.md` has `(my-label)=` above
a heading, resolved to the right anchor but rendered no link text. Since
executablebooks#1158 the link no longer warns, so the build passed with an invisible
link.

`resolve_myst_ref_doc` set the implicit text only on the heading-slug
path. The section-id and std-label paths now carry the section title
too. When no title exists, as for an anonymous label on a paragraph,
the link shows the target id instead of rendering empty, matching the
fallback for unresolved `[](#target)` links.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the cases the fix relies on but the test did not reach:
a label on a heading beyond the `myst_heading_anchors` depth,
a figure label (its caption), a label in an rST document,
a section's docutils id that differs from its slug,
and an unresolved id (one `myst.xref_missing` warning, the id shown as text).
Run the label cases with `myst_heading_anchors` unset as well,
and check for warnings after resolution, which is where they are emitted.
…efs.py

executablebooks#1207 also appends its tests at the end of the file, so after executablebooks#1207 is
squash-merged this branch would conflict with master there again.
Placing this test before `test_slug_id_stays_secondary_under_sortids`
keeps the two insertions apart.

Also drop the `assert not result.warnings` before resolution: reference
warnings are emitted on resolution, and the assert after it sees every
warning the first one could.
@chrisjsewell

Copy link
Copy Markdown
Member

Thank you @dchaudhari7177 for pinning this down. I'm going to close this one rather than merge it, because the case is already covered by tests on master: test_parse[doc_with_target_id] and [doc_with_target_name] from #1158, and #1207's [](other.md#my-label) cases (a label above a heading, linked from another document, with and without myst_heading_anchors), which are the same shape as your test. With the label lookup disabled, all of them fail. #1207 (2b9039e) also closed #1151. Thanks again, and for #1179, which has merged!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-reference to an explicit target emits a false-positive myst.xref_missing warning

3 participants