fix(compilation): raise clear error when managed_section file is missing#1627
Open
yashpal-2004 wants to merge 2 commits into
Open
fix(compilation): raise clear error when managed_section file is missing#1627yashpal-2004 wants to merge 2 commits into
yashpal-2004 wants to merge 2 commits into
Conversation
Contributor
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 |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).