Skip to content

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

Merged
danielmeppiel merged 7 commits intomainfrom
test-assist/base-integrator-coverage-24112158713-1ed81ee6d6c12d80
Apr 21, 2026
Merged

[Test Improver] test: add unit tests for BaseIntegrator shared infrastructure (69 tests)#618
danielmeppiel merged 7 commits 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 <[email protected]>
@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 Apr 8, 2026
@danielmeppiel danielmeppiel marked this pull request as ready for review April 18, 2026 03:01
Copilot AI review requested due to automatic review settings April 18, 2026 03:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a dedicated unit test suite for BaseIntegrator, the shared integration infrastructure used by all file-level integrators, to prevent regressions in path safety, collision detection, sync removal, routing, and file discovery.

Changes:

  • Introduces comprehensive unit tests for IntegrationResult and key BaseIntegrator helpers (collision detection, deploy-path validation, managed-file partitioning, empty-dir cleanup, sync removal, glob discovery, link resolution, and should_integrate).
  • Adds filesystem-backed tests for removal/discovery behavior to more closely match real integration behavior.
Show a summary per file
File Description
tests/unit/integration/test_base_integrator.py New unit test module covering BaseIntegrator shared infrastructure and IntegrationResult.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread tests/unit/integration/test_base_integrator.py Outdated
Comment thread tests/unit/integration/test_base_integrator.py Outdated
@danielmeppiel danielmeppiel added CI/CD Deprecated: use area/ci-cd. Kept for issue history; will be removed in milestone 0.10.0. and removed CI/CD Deprecated: use area/ci-cd. Kept for issue history; will be removed in milestone 0.10.0. labels Apr 19, 2026
@danielmeppiel danielmeppiel merged commit 037be8e into main Apr 21, 2026
9 checks passed
@danielmeppiel danielmeppiel deleted the test-assist/base-integrator-coverage-24112158713-1ed81ee6d6c12d80 branch April 21, 2026 07:33
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.

2 participants