Skip to content

[Test Improver] tests(compile): add unit tests for compile() command early-exit paths#1233

Closed
danielmeppiel wants to merge 1 commit into
mainfrom
test-assist/compile-command-early-exit-tests-1011cb6f8b7556cf
Closed

[Test Improver] tests(compile): add unit tests for compile() command early-exit paths#1233
danielmeppiel wants to merge 1 commit into
mainfrom
test-assist/compile-command-early-exit-tests-1011cb6f8b7556cf

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver - automated AI assistant for test improvements.

Goal and Rationale

The compile() Click command in src/apm_cli/commands/compile/cli.py had extensive helper-function coverage (PR #1206) but the main command body's early-exit branches were untested. These guards protect users from confusing states:

  • No apm.yml in cwd → clear error + apm init suggestion
  • --all + --target conflict → error exit code 2
  • --target all (deprecated form) → deprecation warning
  • No APM content found → helpful error with suggestions
  • Empty .apm/ directory → targeted error mentioning instruction files
  • --dry-run bypasses the no-content exit (by design, line 421-422)
  • --validate mode: guard on missing apm.yml, success path, primitive count output

These paths are user-facing contract surfaces -- if they break silently, users get confusing output or misleading exit codes.

Approach

New test file tests/unit/compilation/test_compile_command_early_exits.py with 13 tests across 5 test classes. Uses CliRunner + tmp_path fixtures to set up minimal project states and invoke apm compile in isolated directories.

No mocking of internals -- tests exercise real code paths against minimal real-directory layouts, which makes them robust against refactors that preserve behaviour.

Coverage Impact

Before After
compile() main body early exits: untested 13 new passing tests pin these branches

These are behaviour-contract tests: they would catch regressions in error messages, exit codes, and guard ordering.

Trade-offs

  • Uses os.chdir inside tests (isolated per-test with try/finally) -- same pattern as test_compile_target_flag.py
  • No complex mocking; tests run fast (~0.4s for all 13)
  • Does not attempt to test the full compilation path (too many external dependencies for minimal additional value)

Reproducibility

# Run just these tests
.venv/bin/pytest tests/unit/compilation/test_compile_command_early_exits.py -v

# Full compilation suite
.venv/bin/pytest tests/unit/compilation/ -q

# Full unit suite
.venv/bin/pytest tests/unit/ -q

Test Status

  • New tests: 13 passing, 0 failing
  • Full unit suite: 7978 passing, 11 failing (all pre-existing: 7 policy_status ANSI + 4 runtime_factory LLM -- unrelated to this PR)
  • Lint: clean

Generated by Daily Test Improver - automated AI assistant

Note

🔒 Integrity filter blocked 17 items

The following items were blocked because they don't meet the GitHub integrity level.

  • #1230 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1227 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1224 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1149 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1146 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1117 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1113 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1028 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1017 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #928 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #900 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #881 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #869 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #691 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #409 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #7 list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • ... and 1 more item

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Daily Test Improver · ● 3M ·

To install this agentic workflow, run

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

Cover 13 untested branches in cli.py::compile():
- missing apm.yml: error + 'apm init' suggestion
- --all with --target: conflict exits with code 2
- --target all: deprecation warning still runs
- no APM content: error + helpful suggestions
- empty .apm dir: targeted error message
- --dry-run skips exit on missing content
- --validate: success path, primitive count output, guard on missing apm.yml

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 May 10, 2026
This was referenced May 22, 2026
@danielmeppiel danielmeppiel mentioned this pull request May 31, 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