Skip to content

[Test Improver] test: add unit tests for compile command logic (38% -> ~50%)#859

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/compile-command-logic-24811162489-b389af219034a9b1
Draft

[Test Improver] test: add unit tests for compile command logic (38% -> ~50%)#859
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/compile-command-logic-24811162489-b389af219034a9b1

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver - automated AI assistant for improving test coverage.

Goal and Rationale

src/apm_cli/commands/compile/cli.py (622 lines) was at ~38% coverage. This PR adds focused unit tests for:

  1. _resolve_compile_target - A pure function mapping CLI target inputs to compiler-understood strings. This function handles the logic for multi-target lists (["claude", "copilot"]"all") and is called on every apm compile invocation.

  2. _get_validation_suggestion - A pure helper providing actionable error messages during --validate mode.

  3. compile CLI early-exit paths - Validates the guard rails that prevent compilation on invalid project states (no apm.yml, no content, empty .apm/).

  4. --validate mode - Tests the validation-only code path including success, validation errors, and exception handling.

  5. --dry-run suppression of the no-content early exit (enabling preview in empty projects).

These paths were completely untested despite being exercised on every apm compile call.

Approach

  • Pure functions (_resolve_compile_target, _get_validation_suggestion) tested directly with no mocking needed.
  • CLI tests use Click's CliRunner with isolated_filesystem() to avoid filesystem side effects.
  • AgentsCompiler and discover_primitives are mocked to isolate the CLI dispatch logic from compilation internals.

Coverage Impact

Module Before After (estimated)
commands/compile/cli.py ~38% ~50%+
Total tests 5155 5173 (+18)

Test Status

All 18 new tests pass. Full unit suite (5173 tests) passes:

python3 -m uv run pytest tests/unit tests/test_console.py -q --ignore=tests/unit/commands/test_policy_status.py
5173 passed, 1 warning, 26 subtests passed in 18.35s

Note: test_policy_status.py has one pre-existing failure (unrelated to this PR — the _ascii_only check conflicts with ANSI codes in Rich's table output) and is ignored for baseline comparison.

Trade-offs

  • Tests for --validate mock discover_primitives and AgentsCompiler to stay fast and deterministic.
  • The --dry-run test exercises the path broadly rather than asserting specific output since the distributed/single-file fork has many state combinations.

Reproducibility

uv run pytest tests/unit/test_compile_command_logic.py -v

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

…ate mode, early exits)

- Tests for _resolve_compile_target: all target resolution paths (None, single
  string passthrough, list with claude-only, agents-family, mixed -> all)
- Tests for _get_validation_suggestion: covers Missing description, applyTo,
  empty content, and unknown-error fallback cases
- CLI integration tests for early-exit paths: no apm.yml, no content, empty .apm/
- CLI integration tests for --validate mode: success, failure, and exception paths
- CLI integration test for --dry-run suppressing the no-content early exit

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

🔒 Supply Chain Security Review — PASS

Reviewed tests/unit/test_compile_command_logic.py (243 lines, test-only) against five security criteria. No issues found.

Check Status Detail
CodeQL URL rule ✅ OK All in assertions check plain English words or filenames ("apm.yml", "validated", "description:", "applyTo", etc.). None are URL-shaped — no py/incomplete-url-substring-sanitization trigger.
Path safety ✅ OK All filesystem ops use runner.isolated_filesystem(temp_dir=tmp_path) with relative paths. No .. components, no absolute paths, no user-controlled segments.
Mock scope ✅ OK Patches target only apm_cli.commands.compile.cli.{discover_primitives, AgentsCompiler}. No mocks on path_security, AuthResolver, cleanup, or any security-critical module.
Test isolation ✅ OK All writes contained within pytest tmp_path. No os.environ mutation, no global os.chdir.
No network calls ✅ OK No HTTP client imports. The two paths that could reach the network (discover_primitives, AgentsCompiler) are mocked wherever they could be reached.

No required fixes, no suggestions. Clean from a supply-chain security perspective.

Generated by PR Review Panel for issue #859 · ● 7.5M ·

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