Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `apm compile` validates the file path of a relative Markdown link independently of a `#fragment`, `?query` or combined suffix, so an existing file no longer produces a false `Referenced file not found` warning; a genuinely missing target is still reported using the path without the suffix. Heading and query values themselves are not validated, and emitted links, inlining, install-time rewriting and dry-run write semantics are unchanged. -- by @bodapatisaikrishna (#3255)
- `APM_HOME` is now the single root for APM-owned user state: global `apm.yml`, `apm.lock.yaml` and `apm_modules/`, `config.json`, marketplace registrations, lifecycle trust and logs, and deployment receipts all follow it, so two `APM_HOME` values no longer share or leak into `~/.apm`. Unset keeps `~/.apm`; a relative value resolves against the starting directory; target deployment destinations are unchanged, and state-changing commands still serialize across `APM_HOME` values. -- by @WilliamK112 (#3614)
- `apm install` for Codex now warns, naming the agent, when an agent's `model` is a Claude alias (`opus`, `sonnet`, `haiku`, `inherit`) or `claude-*` id; the value is still written to the Codex TOML exactly as declared. Rebuilt from #3481 by @xubenqiang. (#3650)
- `apm --help` shows the `apm view` summary in full again instead of wrapping it at 80 columns. (#3651)
Expand Down
5 changes: 5 additions & 0 deletions docs/src/content/docs/producer/package-relative-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ different -- see below.

`#fragment` and `?query` suffixes are preserved through the rewrite.

Compile-time validation checks the file path independently of those
suffixes: an existing file is not reported missing just because the link
adds a section address. The suffix itself is not validated -- APM does
not check that the heading or query exists in the target document.

## What APM does not rewrite

| Link form | Why it is left alone |
Expand Down
14 changes: 11 additions & 3 deletions src/apm_cli/compilation/link_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,21 @@ def validate_link_targets(content: str, base_path: Path) -> builtins.list[str]:
if path.startswith(("http://", "https://", "ftp://", "mailto:")) or path.startswith("#"):
continue

# A markdown target may carry a ``#fragment``, ``?query``, or both.
# Those address part of the target; they are not part of the filename.
# Reuse the resolver's existing split so validation agrees with the
# rewriting path instead of looking for ``file.md#fragment``.
path_part, _suffix = UnifiedLinkResolver._split_link_target(path)
if not path_part:
continue

# Resolve and check path
full_path = _resolve_path(path, base_path)
full_path = _resolve_path(path_part, base_path)
if not full_path or not full_path.exists():
errors.append(f"Referenced file not found: {path} (in link '{text}')")
errors.append(f"Referenced file not found: {path_part} (in link '{text}')")
elif not full_path.is_file() and not full_path.is_dir():
errors.append(
f"Referenced path is neither a file nor directory: {path} (in link '{text}')"
f"Referenced path is neither a file nor directory: {path_part} (in link '{text}')"
)

return errors
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/compilation/test_compile_link_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Compile-time link validation for suffixed markdown targets.

Issue #3255: a target such as ``references/standards.md#template`` names a
file plus a section, not a file called ``standards.md#template``. ``apm
compile`` must validate the filesystem path without the suffix and keep the
suffix out of missing-file diagnostics.
"""

from __future__ import annotations

from pathlib import Path

from click.testing import CliRunner

from apm_cli.cli import cli


def _write_instruction(project: Path) -> None:
instruction = project / ".apm" / "instructions" / "test.instructions.md"
instruction.parent.mkdir(parents=True)
instruction.write_text(
"""---
description: suffixed link fixture
applyTo: "**/*.py"
---
See [template](references/standards.md#template),
[query](references/standards.md?view=full),
[combined](references/standards.md?view=full#template), and
[missing](references/missing.md#template).
""",
encoding="utf-8",
)


def test_compile_dry_run_validates_suffixed_links_by_path(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "apm.yml").write_text("name: test-project\nversion: 0.1.0\n", encoding="utf-8")
_write_instruction(tmp_path)
references = tmp_path / ".apm" / "instructions" / "references"
references.mkdir()
(references / "standards.md").write_text("# Template\n", encoding="utf-8")

result = CliRunner().invoke(cli, ["compile", "--dry-run"])

assert result.exit_code == 0, result.output
output = " ".join(result.output.split())
assert "Referenced file not found: references/standards.md" not in output
assert "Referenced file not found: references/missing.md (in link 'missing')" in output
assert not (tmp_path / "AGENTS.md").exists()
13 changes: 13 additions & 0 deletions tests/unit/compilation/test_link_resolver_phase3.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,19 @@ def test_anchor_link_skipped(self, base_dir: Path) -> None:
errors = validate_link_targets("[Heading](#heading)", base_dir)
assert errors == []

@pytest.mark.parametrize("suffix", ["#template", "?view=full", "?view=full#template"])
def test_existing_file_with_suffix_no_errors(self, base_dir: Path, suffix: str) -> None:
(base_dir / "standards.md").write_text("content")
errors = validate_link_targets(f"[Standards](standards.md{suffix})", base_dir)
assert errors == []

@pytest.mark.parametrize("suffix", ["#template", "?view=full", "?view=full#template"])
def test_missing_file_with_suffix_reports_path_without_suffix(
self, base_dir: Path, suffix: str
) -> None:
errors = validate_link_targets(f"[Standards](missing.md{suffix})", base_dir)
assert errors == ["Referenced file not found: missing.md (in link 'Standards')"]


class TestResolvePath:
def test_empty_string_returns_none(self, base_dir: Path) -> None:
Expand Down