Skip to content

[Test Improver] test: add unit tests for DistributedAgentsCompiler (50%→97%)#197

Closed
danielmeppiel wants to merge 2 commits into
mainfrom
test-assist/distributed-compiler-coverage-6145e1a939ce94cb
Closed

[Test Improver] test: add unit tests for DistributedAgentsCompiler (50%→97%)#197
danielmeppiel wants to merge 2 commits into
mainfrom
test-assist/distributed-compiler-coverage-6145e1a939ce94cb

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver — automated AI assistant

What

55 new unit tests for DistributedAgentsCompiler in tests/unit/compilation/test_distributed_compiler.py.
Also fixes a pre-existing ANSI escape-code test failure in tests/unit/test_install_command.py.

Why

distributed_compiler.py is the core engine for generating distributed AGENTS.md files across a project. At 50% coverage, several critical paths had no unit-level regression protection:

  • Orphaned-file detection, warning generation, and cleanup
  • _generate_agents_content (the actual AGENTS.md content builder)
  • _find_best_directory and _extract_directories_from_pattern (placement logic)
  • Exception handling in compile_distributed
  • Debug mode and clean_orphaned paths
  • generate_distributed_agents_files — both the constitution-only and normal-case branches

Approach

  • Isolated tests using unittest.mock.patch to avoid touching real filesystem or
    external dependencies (ContextOptimizer, UnifiedLinkResolver, CompilationFormatter).
  • Real filesystem used only where strictly needed (orphaned-file I/O, constitution file).
  • Tests verify observable behaviour (return values, warnings, file existence) rather than
    internal implementation details.
  • ANSI fix: added _strip_ansi() helper in test_install_command.py (also added to
    TestAnsiStripping in the new file as a regression guard).

Coverage impact

File Before After
distributed_compiler.py 50% 97%
Overall (apm_cli/) 54% 55%

Remaining 3% (8 lines) are a debug branch triggered only with live context-file references, a line inside a min_instructions filtering loop, and two lines in _find_orphaned_agents_files guarding against external-path edge cases. These require complex fixture setup for marginal benefit.

Test status

1339 passed in 12.36s   (previously: 1284 passed, 1 failed)

Reproduce

uv sync --extra dev
uv run pytest tests/unit/compilation/test_distributed_compiler.py tests/unit/test_install_command.py -v
uv run pytest tests/unit/ --no-header -q --cov=apm_cli.compilation.distributed_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

- Add 55 new unit tests in tests/unit/compilation/test_distributed_compiler.py
  covering DirectoryMap, PlacementResult, _extract_directories_from_pattern,
  _find_best_directory, analyze_directory_structure, _validate_coverage,
  _find_orphaned_agents_files, _generate_orphan_warnings, _cleanup_orphaned_files,
  generate_distributed_agents_files, _generate_agents_content,
  determine_agents_placement, compile_distributed exception/debug/orphan paths.
- Fix ANSI escape code handling in test_install_command.py so the test that
  checks 'apm install <org/repo>' strips Rich markup before asserting.

Coverage: distributed_compiler.py 50%->97%, overall 54%->55%.
All 1339 unit tests pass (previously 1284 pass + 1 fail).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel danielmeppiel added automation Deprecated: use type/automation. Kept for issue history; will be removed in milestone 0.10.0. testing Deprecated: use area/testing. Kept for issue history; will be removed in milestone 0.10.0. labels Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Deprecated: use type/automation. Kept for issue history; will be removed in milestone 0.10.0. testing Deprecated: use area/testing. Kept for issue history; will be removed in milestone 0.10.0.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant