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

Aperta Adatta ai principianti
#3,255 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Inizia con validate_link_targets in src/apm_cli/compilation/link_resolver.py e i test del risolutore dei link in tests/unit/compilation/test_link_resolver*.py. Controlla come vengono risolti i link relativi con frammenti e stringhe di query, quindi esegui i test di regressione per i file esistenti e mancanti. Il lavoro è completato quando i target esistenti superano i test e quelli mancanti vengono segnalati senza il suffisso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
apm compile warns Referenced file not found for a relative Markdown link that carries a fragment, such as [template](references/standards.md#template), even though references/standards.md exists. validate_link_targets in src/apm_cli/compilation/link_resolver.py skips links that start with #, but passes file.md#fragment to _resolve_path unchanged, so the existence check looks for a file literally named standards.md#template. ?query suffixes behave the same.

Skills commonly link to a heading in a reference file, so a skill package with valid links produces one warning per link.

To Reproduce

from pathlib import Path
from apm_cli.compilation.link_resolver import validate_link_targets

base = Path("pkg"); (base / "references").mkdir(parents=True, exist_ok=True)
(base / "references" / "standards.md").write_text("# Template\n")
print(validate_link_targets("[t](references/standards.md#template)", base))
# ["Referenced file not found: references/standards.md#template (in link 't')"]

Or apm install a skill whose SKILL.md links to references/<file>.md#<heading>, then run apm compile --dry-run.

Expected behavior
The fragment (and query) is ignored for the existence check: an existing file passes and a missing file is still reported, without the fragment.

Environment

  • OS: macOS 26 (also expected on Linux and Windows; the check is platform independent)
  • Python Version: 3.12
  • APM Version: 0.33.0 (code unchanged on main)

Additional context
Proposed fix (happy to open a PR once the scope is approved), in validate_link_targets before _resolve_path:

        # Strip a #fragment or ?query: it targets a heading, not a file
        path = re.split(r"[#?]", path, maxsplit=1)[0]

With two regression tests (an existing file with a fragment passes; a missing file with a fragment is reported without it), tests/unit/compilation/test_link_resolver*.py passes (164 tests). resolve_markdown_links has the same startswith("#")-only skip, so a context link with a fragment is not inlined; it may want the same treatment.

Lingua principale
Python
Stelle
4.2k
Fork
412
Merge medio
1g 12h
PR unite (30g)
68

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/apm

Tutte le issue di microsoft/apm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.