[Test Improver] test: add unit tests for AgentsCompiler (65%→82% coverage)#221
Draft
danielmeppiel wants to merge 1 commit intomainfrom
Draft
Conversation
Cover previously untested branches in agents_compiler.py: - CompilationConfig.from_apm_yml(): target, strategy, single_file legacy, min_instructions_per_file, source_attribution fields, exception fallback, no-file fallback, single_agents override, None override ignored - CompilationConfig.__post_init__: single_agents and exclude=None paths - AgentsCompiler.compile(): exception handling and local_only discovery path - AgentsCompiler.validate_primitives(): primitive errors → warnings, absolute-path fallback, link validation errors - AgentsCompiler._write_output_file(): OSError adds compiler error - AgentsCompiler._write_distributed_file(): full method coverage (dir creation, no-constitution, constitution injection failure fallback, OSError re-raise) - AgentsCompiler._generate_placement_summary(): relative and absolute path cases - AgentsCompiler._generate_distributed_summary(): format and path fallback - AgentsCompiler._merge_results(): empty list, single pass-through, two-result merge (content, warnings, stats), failure propagation, empty-path exclusion - compile_agents_md(): error path raises RuntimeError, success returns content 34 new tests, all pass. Overall agents_compiler coverage: 65% → 82%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 13, 2026
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.
🤖 Test Improver – automated AI assistant
Goal & Rationale
src/apm_cli/compilation/agents_compiler.pyis the main orchestrator for all AGENTS.md/CLAUDE.md compilation. At 65% coverage, many important error-handling and edge-case branches were untested, including:apm.yml(legacysingle_fileflag, placement settings, source attribution)_write_distributed_file()method (0% covered)Approach
Added 34 focused unit tests in
tests/unit/compilation/test_agents_compiler_coverage.py, complementing the existingtest_compilation.py:TestCompilationConfigFromApmYmlAdditionaltarget,strategy, legacysingle_file,min_instructions_per_file,source_attribution, exception fallback, no-file defaultsTestCompilationConfigPostInitsingle_agents→ strategy,exclude=NoneinitTestAgentsCompilerCompileExceptionlocal_onlyuses basic discoverTestValidatePrimitivesErrorsTestWriteOutputFileTestWriteDistributedFileTestGenerateSummariesTestMergeResultsTestCompileAgentsMdFunctionCoverage Impact
agents_compiler.pyRemaining uncovered lines (264-275, 278-280, 294-295, 312-333, 436-437, 467-468, 472-473, 501, 503, 517-518, 759-774, 783-801) are inside
_compile_distributed()and_compile_claude_md()display/formatting paths that require a full distributed compiler stack — not targeted in this PR.Test Status
The pre-existing failure (
test_install_no_apm_yml_no_packages_shows_helpful_error) is unrelated to this change — it's caused by Rich-formatted output containing ANSI escape codes that the test asserts against plain text.Reproducibility