fix(compilation): raise clear error when managed_section file is missing#1627
fix(compilation): raise clear error when managed_section file is missing#1627yashpal-2004 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves managed-section compilation behavior by failing fast with a clear error when the target output file doesn’t exist, and adds a unit test to validate the error formatting/message.
Changes:
- Raise
ManagedSectionErrorwhenagents_md_mode="managed_section"and the output file is missing. - Add a unit test asserting the missing-file managed-section behavior and message formatting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/unit/compilation/test_managed_section.py | Adds coverage for the new managed-section missing-file error behavior. |
| src/apm_cli/compilation/agents_compiler.py | Enforces that managed-section updates require an existing output file and raises a clearer error if not. |
Comments suppressed due to low confidence (1)
src/apm_cli/compilation/agents_compiler.py:1265
- This wraps the error with
[{target}], which will render the full path (e.g.,[/tmp/.../AGENTS.md]). The existing test context/comment suggests the bracket prefix should be just the filename (e.g.,[AGENTS.md] ...). Consider changing the wrapper to usetarget.name(or a repo-relative path, if that’s the established convention) so the bracket format stays consistent and stable across environments.
except ManagedSectionError as exc:
raise ManagedSectionError(f"[{target}] {exc}") from exc
| 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 |
|
@microsoft-github-policy-service agree |
|
Thanks for this fix, @yashpal-2004 -- the intent here is exactly right. Closing as superseded: the same "raise a clear error when a managed_section file is missing" guard already landed on main via #1606 (merged in 7032bc0), so the missing-file path is now covered. We really appreciate you flagging and fixing it; please keep the contributions coming. |
Problem
When
agents_md_mode: managed_sectionis enabled but the target output file (e.g.,AGENTS.md) does not exist yet, the compiler falls back to checking for markers in an empty string. This triggers a confusing'markers not found'error, even though the actual issue is that the file itself is missing.Proposed Changes
_write_output_file_with_configwhenmanaged_sectionmode is enabled.ManagedSectionError:AGENTS.md does not exist yet. Create it with markers first, or use mode: full for initial generation.test_write_output_file_managed_section_missing_filetotests/unit/compilation/test_managed_section.pyto ensure correct behavior and error message generation.Verification
pytest tests/unit/compilation/test_managed_section.py(all tests passed, including the new test).ruff checkon the modified files (no linting/formatting errors).