-
Notifications
You must be signed in to change notification settings - Fork 6
Re-implement casting of HFIDs to a list if the rel peer schema has hf… #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds HFID normalization utilities 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (3)**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
tests/**/*.py📄 CodeRabbit inference engine (tests/AGENTS.md)
Files:
tests/unit/**/*.py📄 CodeRabbit inference engine (tests/AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-11-25T13:23:15.190ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
🔇 Additional comments (4)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
infrahub_sdk/spec/object.pytests/fixtures/schema_01.jsontests/unit/sdk/spec/test_object.py
🧰 Additional context used
📓 Path-based instructions (4)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification
Files:
infrahub_sdk/spec/object.pytests/unit/sdk/spec/test_object.py
infrahub_sdk/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Follow async/sync dual pattern for new features in the Python SDK
Files:
infrahub_sdk/spec/object.py
tests/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
tests/**/*.py: Usehttpx_mockfixture for HTTP mocking in tests instead of making real HTTP requests
Do not add@pytest.mark.asynciodecorator to async test functions (async auto-mode is globally enabled)
Files:
tests/unit/sdk/spec/test_object.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
Unit tests must be fast, mocked, and have no external dependencies
Files:
tests/unit/sdk/spec/test_object.py
🪛 GitHub Actions: CI
infrahub_sdk/spec/object.py
[error] 427-427: Ruff: PLR0915 Too many statements (51 > 50) in async def create_node.
🔇 Additional comments (11)
infrahub_sdk/spec/object.py (5)
10-10: LGTM!Import of
is_valid_uuidis appropriate for the UUID detection logic in the new normalization functions.
37-54: LGTM!The normalization logic is clear and well-documented. The function correctly handles all three cases: lists (unchanged), UUIDs (unchanged), and non-UUID strings (wrapped in list for single-component HFID).
57-64: LGTM!Simple and correct mapping of the reference normalization over a list of values.
85-85: LGTM!The
peer_has_hfidfield with a conservativeFalsedefault ensures normalization is only applied when explicitly determined.
153-154: LGTM!The
peer_has_hfidis correctly set after fetching the peer schema. Usingbool()properly handlesNone, empty lists, and non-empty lists.tests/fixtures/schema_01.json (1)
245-248: LGTM!Adding
human_friendly_idto the Tag node enables the HFID normalization tests. TheBuiltinLocationschema has relationships toBuiltinTag(bothtagsandprimary_tag), so this change properly supports testing both cardinality-one and cardinality-many HFID normalization scenarios.Note: The AI summary mentions
human_friendly_idwas added toGraphQLQuery, but the actual code shows onlyTagreceived this field. This is not an issue—the test coverage targets theBuiltinLocation→BuiltinTagrelationships.tests/unit/sdk/spec/test_object.py (5)
3-20: LGTM!Imports are appropriate for the new test infrastructure. Good use of
TYPE_CHECKINGfor theInfrahubNodetype hint.
277-336: LGTM!Comprehensive test cases covering all HFID normalization scenarios: cardinality-one (string, list, UUID) and cardinality-many (strings, lists, mixed, UUIDs). The dataclass provides clear structure for parameterized testing.
339-376: Well-structured integration test for HFID normalization.The test correctly:
- Mocks
InfrahubNode.saveto prevent HTTP calls- Captures the data passed to
client.createfor assertion- Validates both cardinality-one and cardinality-many normalization
One minor suggestion: Consider using
patch.object(client_with_schema_01, 'create', ...)for consistency with thepatchusage forsave, though the direct assignment works fine for tests.
379-469: LGTM!Excellent unit test coverage for
normalize_hfid_reference. The test cases clearly demonstrate the expected behavior difference whenpeer_has_hfidis True vs False, and the assertions verify both the type and value of the output.
472-529: LGTM!Good test coverage for verifying the actual GraphQL payload structure produced by
RelatedNode. While_generate_input_data()is a private method, testing it directly here is appropriate to verify the critical{"id": ...}vs{"hfid": [...]}payload distinction that the HFID normalization feature relies upon.
Deploying infrahub-sdk-python with
|
| Latest commit: |
bb46a8f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0771f256.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://may-202601-hfid-object-loadi.infrahub-sdk-python.pages.dev |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## stable #746 +/- ##
==========================================
+ Coverage 80.30% 80.32% +0.02%
==========================================
Files 115 115
Lines 9874 9888 +14
Branches 1518 1520 +2
==========================================
+ Hits 7929 7943 +14
Misses 1417 1417
Partials 528 528
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/unit/sdk/spec/test_object.py (1)
357-377: Consider usingpatch.objectfor cleaner fixture handling.Directly assigning
client_with_schema_01.create = mock_createmutates the fixture without restoration. While function-scoped fixtures typically get recreated, usingpatch.objectensures consistent cleanup and is more idiomatic.🔧 Suggested refactor using patch.object
- client_with_schema_01.create = mock_create - - with patch("infrahub_sdk.node.InfrahubNode.save", new_callable=AsyncMock): + with ( + patch.object(client_with_schema_01, "create", side_effect=mock_create), + patch("infrahub_sdk.node.InfrahubNode.save", new_callable=AsyncMock), + ): await obj.process(client=client_with_schema_01)
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/sdk/spec/test_object.py
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification
Files:
tests/unit/sdk/spec/test_object.py
tests/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
tests/**/*.py: Usehttpx_mockfixture for HTTP mocking in tests instead of making real HTTP requests
Do not add@pytest.mark.asynciodecorator to async test functions (async auto-mode is globally enabled)
Files:
tests/unit/sdk/spec/test_object.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
Unit tests must be fast, mocked, and have no external dependencies
Files:
tests/unit/sdk/spec/test_object.py
🧬 Code graph analysis (1)
tests/unit/sdk/spec/test_object.py (1)
infrahub_sdk/spec/object.py (9)
spec(676-682)ObjectFile(672-700)RelationshipDataFormat(67-75)get_relationship_info(136-199)normalize_hfid_reference(37-54)validate_format(212-231)validate_format(693-697)process(233-246)process(699-700)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: unit-tests (3.10)
- GitHub Check: unit-tests (3.12)
- GitHub Check: unit-tests (3.11)
- GitHub Check: unit-tests (3.14)
- GitHub Check: unit-tests (3.13)
- GitHub Check: integration-tests-latest-infrahub
- GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
tests/unit/sdk/spec/test_object.py (6)
1-21: LGTM!Imports are well-organized with appropriate use of
TYPE_CHECKINGfor type-hint-only imports. The new imports align with the test requirements for mocking and HFID normalization testing.
277-336: LGTM!The
HfidLoadTestCasedataclass is well-structured with proper type hints. The test cases provide comprehensive coverage including string-to-list normalization, UUID passthrough, and cardinality-many scenarios with mixed formats.
379-436: LGTM!The
GraphQLPayloadTestCasedataclass is well-documented with a clear explanation of howRelatedNodeinterprets data formats. The test cases provide good coverage of the normalization matrix for both HFID-enabled and non-HFID peers.
439-469: LGTM!The synchronous test is appropriate for the sync
normalize_hfid_referencefunction. The conditional normalization logic (based onpeer_has_hfid) correctly mirrors the expected runtime behavior, and assertions include helpful error messages.
472-500: LGTM!The
RelatedNodePayloadTestCasestructure is clean with appropriate test cases covering the key payload scenarios: UUID-to-id and HFID-to-hfid transformations.
503-527: No changes needed. The test appropriately verifies the GraphQL payload structure.
_generate_input_data()is the standard internal protocol for payload generation across the entire codebase and is the only way to access the combined payload structure. This method is defined inprotocols_base.pyas part of the contract and is used consistently in integration tests, unit tests, and core implementations. Testing this internal contract is appropriate for unit tests, and there is no public alternative API available.
tests/unit/sdk/spec/test_object.py
Outdated
| if test_case.peer_has_hfid: | ||
| # When peer has HFID, use normalization | ||
| processed_value = normalize_hfid_reference(test_case.input_value) | ||
| else: | ||
| # When peer has no HFID, pass value as-is (no normalization) | ||
| processed_value = test_case.input_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't actually test the logic that checks if the peer schema has an HFID defined. for that, this test probably needs to call get_relationship_info. although that looks like it will require some mocking
… RelationshipInfo updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/unit/sdk/spec/test_object.py (1)
507-531: Consider testing through public API instead of private method.The test directly calls
_generate_input_data()which is a private method (prefixed with_). While the test correctly verifies the GraphQL payload structure, testing private methods can be fragile as implementation details may change.Consider whether there's a public method or integration point that could be used instead to verify this behavior, or document why testing this private method is necessary for coverage.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
infrahub_sdk/spec/object.pytests/unit/sdk/spec/test_object.py
🧰 Additional context used
📓 Path-based instructions (4)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification
Files:
infrahub_sdk/spec/object.pytests/unit/sdk/spec/test_object.py
infrahub_sdk/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Follow async/sync dual pattern for new features in the Python SDK
Files:
infrahub_sdk/spec/object.py
tests/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
tests/**/*.py: Usehttpx_mockfixture for HTTP mocking in tests instead of making real HTTP requests
Do not add@pytest.mark.asynciodecorator to async test functions (async auto-mode is globally enabled)
Files:
tests/unit/sdk/spec/test_object.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
Unit tests must be fast, mocked, and have no external dependencies
Files:
tests/unit/sdk/spec/test_object.py
🧠 Learnings (1)
📚 Learning: 2025-11-25T13:23:15.190Z
Learnt from: wvandeun
Repo: opsmill/infrahub-sdk-python PR: 637
File: infrahub_sdk/operation.py:74-76
Timestamp: 2025-11-25T13:23:15.190Z
Learning: In infrahub_sdk/operation.py, the recursive=True parameter in _process_relationships is a temporary workaround to access Proposed Changes data. This will be replaced with proper object-level metadata implementation in version 1.7.
Applied to files:
infrahub_sdk/spec/object.py
🧬 Code graph analysis (2)
infrahub_sdk/spec/object.py (1)
infrahub_sdk/utils.py (1)
is_valid_uuid(85-91)
tests/unit/sdk/spec/test_object.py (2)
infrahub_sdk/schema/main.py (4)
RelationshipSchema(124-142)kind(279-280)get_matching_relationship(209-220)get_relationship(187-191)infrahub_sdk/spec/object.py (4)
spec(681-687)RelationshipDataFormat(67-75)get_relationship_info(141-204)normalize_hfid_reference(37-54)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: unit-tests (3.12)
- GitHub Check: unit-tests (3.10)
- GitHub Check: unit-tests (3.11)
- GitHub Check: unit-tests (3.13)
- GitHub Check: unit-tests (3.14)
- GitHub Check: integration-tests-latest-infrahub
🔇 Additional comments (11)
infrahub_sdk/spec/object.py (6)
10-10: LGTM!The import of
is_valid_uuidfrom..utilsis correctly added to support the HFID normalization logic.
37-54: LGTM!The
normalize_hfid_referencefunction is well-documented and correctly implements the normalization logic. The type hints are appropriate, and the function handles all three cases (list, UUID string, non-UUID string) correctly.
57-64: LGTM!The
normalize_hfid_referencesfunction correctly appliesnormalize_hfid_referenceto each element in the list.
85-90: LGTM!The new
peer_human_friendly_idfield andpeer_has_hfidproperty are correctly implemented. The property correctly handlesNoneand empty lists by returningFalse, and non-empty lists by returningTrue.
159-159: LGTM!Correctly populates
peer_human_friendly_idfrom the peer schema'shuman_friendly_idfield.
485-490: LGTM!The HFID normalization is correctly integrated into the
create_nodemethod. The conditional normalization based onpeer_has_hfidensures that references are only transformed when the peer schema defines a human-friendly ID, preserving backward compatibility for schemas without HFID.tests/unit/sdk/spec/test_object.py (5)
3-17: LGTM!The imports are well-organized and correctly bring in the necessary dependencies for the new tests, including
dataclassfor test case structures, mock utilities fromunittest.mock, and the newnormalize_hfid_referencefunction being tested.
278-337: LGTM!The
HfidLoadTestCasedataclass andHFID_NORMALIZATION_TEST_CASESprovide comprehensive coverage of HFID normalization scenarios, including cardinality-one and cardinality-many cases with strings, lists, UUIDs, and mixed formats.
340-377: LGTM!The test correctly validates HFID normalization by intercepting the
createcall and verifying the normalized data. The mocking approach withpatchandAsyncMockfollows the coding guidelines for unit tests.
380-453: LGTM!The
test_peer_has_hfid_from_schematest thoroughly verifies thepeer_has_hfidproperty behavior with proper mocking. The test cases correctly cover all three scenarios: defined HFID,None, and empty list.
456-473: LGTM!Excellent direct unit test for
normalize_hfid_referencethat covers all three code paths in isolation.
…/integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/unit/sdk/spec/test_object.py`:
- Around line 10-17: The import 'RelationshipSchema' in
tests/unit/sdk/spec/test_object.py is unused and causing F401; remove
'RelationshipSchema' from the import list (the from infrahub_sdk.schema import
... line) so the file only imports symbols actually used (RelatedNode,
ObjectFile, RelationshipDataFormat, get_relationship_info,
normalize_hfid_reference), then run the linter/tests to confirm the F401 is
resolved.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/sdk/spec/test_object.py
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification
Files:
tests/unit/sdk/spec/test_object.py
tests/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
tests/**/*.py: Usehttpx_mockfixture for HTTP mocking in tests instead of making real HTTP requests
Do not add@pytest.mark.asynciodecorator to async test functions (async auto-mode is globally enabled)
Files:
tests/unit/sdk/spec/test_object.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (tests/AGENTS.md)
Unit tests must be fast, mocked, and have no external dependencies
Files:
tests/unit/sdk/spec/test_object.py
🧬 Code graph analysis (1)
tests/unit/sdk/spec/test_object.py (1)
infrahub_sdk/spec/object.py (9)
spec(681-687)ObjectFile(677-705)RelationshipDataFormat(67-75)get_relationship_info(141-204)normalize_hfid_reference(37-54)validate_format(217-236)validate_format(698-702)process(238-251)process(704-705)
🪛 GitHub Actions: CI
tests/unit/sdk/spec/test_object.py
[error] 11-11: F401: 'infrahub_sdk.schema.RelationshipSchema' imported but unused. Remove unused import: 'RelationshipSchema'. (ruff)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
tests/unit/sdk/spec/test_object.py (3)
340-377: Well-structured integration-style test for HFID normalization.This test exercises the actual normalization flow through
ObjectFile.process()andclient.create(), capturing the transformed data to verify HFID normalization behavior. The mocking is appropriately scoped to only prevent actual network calls while testing the real logic.
380-397: LGTM!Clean, focused unit test that covers all three code paths in
normalize_hfid_reference: non-UUID strings wrapped in lists, UUIDs returned unchanged, and lists returned unchanged.
431-455: Good unit test for RelatedNode payload generation.The test effectively verifies that
RelatedNodeproduces the correct GraphQL payload structure ({"id": ...}vs{"hfid": [...]}). Accessing_generate_input_data()is acceptable here for testing the internal payload generation behavior.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
Reimplements #732 but only casting if the peer schema has an HFID defined.
Relevant CI runs in Infrahub: opsmill/infrahub#8096
Summary by CodeRabbit
New Features
Tests
Schema
✏️ Tip: You can customize this high-level summary in your review settings.