[Test Improver] test: primitives models 78% → 100% coverage (Skill, conflict detection)#240
Merged
danielmeppiel merged 3 commits intomainfrom Mar 12, 2026
Conversation
… source filtering - Add Skill.validate() tests (missing name, description, empty content) - Add Instruction.validate() missing-description and empty-content branches - Add PrimitiveConflict.__str__() test - Add PrimitiveCollection conflict-detection tests: - local wins over dependency (replace) - local not replaced by later dependency (keep) - first dependency wins over second dependency - Add PrimitiveCollection.has_conflicts(), get_conflicts_by_type(), get_primitives_by_source() tests - Import Skill and PrimitiveConflict in test module primitives/models.py: 78% -> 100% Total: 1428 -> 1445 passing tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…1453-21e144de9777f273
Contributor
There was a problem hiding this comment.
Pull request overview
Expands the primitives unit test suite to cover newly introduced primitive types and behaviors (notably Skill and primitive conflict handling), while also applying minor formatting/consistency tweaks.
Changes:
- Add unit tests for
Skillvalidation andPrimitiveConflictstring formatting. - Add unit tests for
PrimitiveCollectionconflict-resolution behavior and new helpers (has_conflicts, filtering by type/source). - Apply small formatting cleanups (imports, commas, line wrapping, quoting) across the test file.
| def test_primitive_collection_add_unknown_type_raises(self): | ||
| """Test that adding an unknown type raises ValueError.""" | ||
| collection = PrimitiveCollection() | ||
| with self.assertRaises((ValueError, AttributeError)): |
There was a problem hiding this comment.
The test currently accepts both ValueError and AttributeError when adding an unknown primitive. PrimitiveCollection.add_primitive() explicitly raises ValueError for unknown types, so allowing AttributeError could mask an unintended regression (e.g., an internal attribute access bug). Tighten the assertion to expect only ValueError (and optionally match the message).
Suggested change
| with self.assertRaises((ValueError, AttributeError)): | |
| with self.assertRaises(ValueError): |
…1453-21e144de9777f273
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.
Goal and Rationale
src/apm_cli/primitives/models.pyhad 78% coverage, with key logic paths completely untested:Skill.validate()— no tests at all for the fourth APM primitive typePrimitiveCollectionconflict detection — the priority rules ("local wins over dependency") had zero test coverage; this is critical correctness logicPrimitiveConflict.__str__()— untested string representationInstruction.validate()branches — missing-description and empty-content pathsThe conflict detection logic is particularly important: it determines which version of a primitive "wins" when the same name appears in both local files and installed dependencies. A bug here would silently corrupt users' primitive collections.
Approach
Added 17 focused unit tests to
tests/unit/primitives/test_primitives.py:Skill.validate()— valid skill, missing name, missing description, empty content, all errors togetherInstruction.validate()— missing description branch, empty content branch, multiple errorsPrimitiveConflict.__str__()— string representation with multiple losing sourcesPrimitiveCollectionconflict detection:_add_with_conflict_detection)PrimitiveCollectionquery methods —has_conflicts(),get_conflicts_by_type(),get_primitives_by_source()isinstance(primitive, Skill)path inadd_primitive()Coverage Impact
src/apm_cli/primitives/models.pyTest Status
Reproducibility