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
14 changes: 6 additions & 8 deletions src/apm_cli/compilation/agents_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,22 +1276,20 @@ def _write_output_file_with_config(

if config.agents_md_mode == "managed_section":
target = Path(output_path)
if not target.is_file():
raise ManagedSectionError(
f"{target} does not exist yet. "
"Create it with the managed-section markers first, "
"or set agents_md.mode: full in apm.yml for initial generation."
)
existing = target.read_text(encoding="utf-8")
try:
if not target.exists():
raise ManagedSectionError(
f"[{target.name}] does not exist yet. Create it with markers first, or use mode: full for initial generation."
)
existing = target.read_text(encoding="utf-8")
content = apply_managed_section(
existing,
content,
config.agents_md_start_marker,
config.agents_md_end_marker,
)
except ManagedSectionError as exc:
raise ManagedSectionError(f"[{target}] {exc}") from exc
raise ManagedSectionError(f"[{target.name}] {exc}") from exc
elif config.agents_md_mode != "full":
raise ValueError(
f"Unknown agents_md.mode {config.agents_md_mode!r}. "
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/compilation/test_managed_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,11 @@ def test_write_output_file_managed_section_directory_at_path(self, tmp_path):
)

compiler = AgentsCompiler(str(tmp_path))
with pytest.raises(ManagedSectionError) as exc_info:
compiler._write_output_file_with_config(str(output_file), "New content.\n", config)

msg = str(exc_info.value)
assert "AGENTS.md does not exist yet. Create it with markers first, or use mode: full for initial generation." in msg
assert msg.startswith("[")
with pytest.raises(ManagedSectionError, match=r"(?i)does not exist|not exist|create it"):
compiler._write_output_file_with_config(str(output_file), "New content.\n", config)
Loading