Skip to content

[Test Improver] test: add unit tests for AgentsCompiler (65%→82% coverage)#221

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/agents-compiler-coverage-1773105017-70450d4bafccea6d
Draft

[Test Improver] test: add unit tests for AgentsCompiler (65%→82% coverage)#221
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/agents-compiler-coverage-1773105017-70450d4bafccea6d

Conversation

@danielmeppiel
Copy link
Collaborator

🤖 Test Improver – automated AI assistant

Goal & Rationale

src/apm_cli/compilation/agents_compiler.py is the main orchestrator for all AGENTS.md/CLAUDE.md compilation. At 65% coverage, many important error-handling and edge-case branches were untested, including:

  • Config loading from apm.yml (legacy single_file flag, placement settings, source attribution)
  • Exception paths that produce silent fallbacks instead of crashes
  • File-write error handling for both single-file and distributed modes
  • The _write_distributed_file() method (0% covered)

Approach

Added 34 focused unit tests in tests/unit/compilation/test_agents_compiler_coverage.py, complementing the existing test_compilation.py:

Test class Tests What it covers
TestCompilationConfigFromApmYmlAdditional 10 target, strategy, legacy single_file, min_instructions_per_file, source_attribution, exception fallback, no-file defaults
TestCompilationConfigPostInit 2 single_agents → strategy, exclude=None init
TestAgentsCompilerCompileException 2 Exception → failure result; local_only uses basic discover
TestValidatePrimitivesErrors 4 Primitive errors → warnings; outside-base-dir path; link errors
TestWriteOutputFile 1 OSError adds compiler error
TestWriteDistributedFile 4 Dir creation, no-constitution, injection failure fallback, OSError re-raise
TestGenerateSummaries 4 Relative and absolute-path cases for both summary methods
TestMergeResults 5 Empty list, single pass-through, two-result merge, failure propagation
TestCompileAgentsMdFunction 2 Error path raises RuntimeError; success returns content

Coverage Impact

Module Before After
agents_compiler.py 65% 82%

Remaining 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

34 passed in 0.27s   (new tests alone)
964 passed, 1 failed (full suite, pre-existing ANSI failure in test_install_command.py)

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

uv sync --extra dev
uv run pytest tests/unit/compilation/test_agents_compiler_coverage.py -v
uv run pytest tests/unit/compilation/ --cov=apm_cli.compilation.agents_compiler --cov-report=term-missing

Generated by Daily Test Improver ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@b87234850bf9664d198f28a02df0f937d0447295

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant