Skip to content

fix(compilation): raise clear error when managed_section file is missing#1627

Open
yashpal-2004 wants to merge 2 commits into
microsoft:mainfrom
yashpal-2004:fix-managed-section-missing-file
Open

fix(compilation): raise clear error when managed_section file is missing#1627
yashpal-2004 wants to merge 2 commits into
microsoft:mainfrom
yashpal-2004:fix-managed-section-missing-file

Conversation

@yashpal-2004
Copy link
Copy Markdown

Problem

When agents_md_mode: managed_section is 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

  • Added an explicit check for target file existence in _write_output_file_with_config when managed_section mode is enabled.
  • If the file does not exist, raise a specific, descriptive ManagedSectionError:
    AGENTS.md does not exist yet. Create it with markers first, or use mode: full for initial generation.
  • Added unit test test_write_output_file_managed_section_missing_file to tests/unit/compilation/test_managed_section.py to ensure correct behavior and error message generation.

Verification

  • Ran the unit tests locally under a Python 3.12 virtual environment:
    pytest tests/unit/compilation/test_managed_section.py (all tests passed, including the new test).
  • Ran ruff check on the modified files (no linting/formatting errors).

Copilot AI review requested due to automatic review settings June 2, 2026 21:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ManagedSectionError when agents_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 use target.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
@yashpal-2004
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants