Skip to content

[Test Improver] test: add unit tests for BaseIntegrator shared infrastructure (69 tests)#618

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/base-integrator-coverage-24112158713-1ed81ee6d6c12d80
Draft

[Test Improver] test: add unit tests for BaseIntegrator shared infrastructure (69 tests)#618
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/base-integrator-coverage-24112158713-1ed81ee6d6c12d80

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

Summary

🤖 Test Improver: automated AI assistant focused on improving test coverage for this repository.

BaseIntegrator is the core shared infrastructure that every file-level integrator inherits from. It handles collision detection, path validation, manifest-based sync, file discovery, empty-directory cleanup, and link resolution. Despite being relied on by all integrators, it had no dedicated unit tests.


Goal and Rationale

src/apm_cli/integration/base_integrator.py (441 lines) provides the foundational guarantees that protect against:

  • Path traversal attacks via validate_deploy_path
  • Collision overwrites of user-authored files via check_collision
  • Unsafe sync deletions via sync_remove_files + validate_deploy_path
  • Incorrect primitive routing via partition_managed_files (trie-based)
  • Symlink traversal via find_files_by_glob

Bugs here would silently affect all integrators (Copilot, Claude, Cursor, Codex, etc.).


Approach

One test class per method/feature group, 69 tests total:

Test Class Method Tests
TestIntegrationResult dataclass 3
TestCheckCollision check_collision 8
TestNormalizeManagedFiles normalize_managed_files 4
TestValidateDeployPath validate_deploy_path 8
TestPartitionBucketKey partition_bucket_key 8
TestPartitionManagedFiles partition_managed_files 13
TestCleanupEmptyParents cleanup_empty_parents 6
TestSyncRemoveFiles sync_remove_files 7
TestFindFilesByGlob find_files_by_glob 7
TestResolveLinks resolve_links 3
TestShouldIntegrate should_integrate 1

Key coverage points:

  • Traversal sequences rejected in validate_deploy_path
  • partition_managed_files trie routing covers all known targets (Copilot, Claude, Cursor, OpenCode, Codex) including deploy_root override for .agents/ skills
  • Backslash normalization in check_collision and normalize_managed_files
  • Legacy glob fallback in sync_remove_files when managed_files=None
  • Symlink exclusion and deduplication in find_files_by_glob
  • Bottom-up empty parent cleanup vs. non-empty dir preservation

Coverage Impact

Scope Before After
base_integrator.py ~0% (no dedicated tests) ~90%+
Test count 3,674 3,743 (+69)

Trade-offs

  • Tests use real tempfile.mkdtemp() for filesystem operations (needed to test actual file removal/discovery) - slightly slower than pure mocks but much more realistic
  • partition_managed_files tests exercise all known targets; adding a new target may require a new test case

Test Status

All 3,743 tests pass:

3743 passed in 13.85s

Run tests:

uv run pytest tests/unit/integration/test_base_integrator.py -v
uv run pytest tests/unit tests/test_console.py -x -q

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Tests cover all static and instance methods in base_integrator.py:
- IntegrationResult dataclass construction and optional fields
- check_collision: managed/unmanaged files, force flag, diagnostics
- normalize_managed_files: None passthrough, backslash normalization
- validate_deploy_path: allowed prefixes, traversal rejection
- partition_bucket_key: backward-compat alias mapping
- partition_managed_files: trie-based routing for all known targets
- cleanup_empty_parents: bottom-up empty dir removal
- sync_remove_files: manifest mode and legacy glob fallback
- find_files_by_glob: symlink exclusion, deduplication, sorting
- resolve_links: no-resolver passthrough, change counting
- should_integrate: always True baseline

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