test: add integration test suite for InfrahubInventory (NORNIR-5)#79
Conversation
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/superpowers/specs/2026-05-23-integration-tests-design.md">
<violation number="1" location="docs/superpowers/specs/2026-05-23-integration-tests-design.md:67">
P3: Use the actual mapped value here. `platform.nornir_platform` resolves to `arista_eos`, not `eos`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| ### `TestSchemaMappings` | ||
| - `schema_mappings: [{name: hostname, mapping: primary_address.address}]` → `router-1` host has `hostname == "10.0.0.1"` | ||
| - `schema_mappings: [{name: platform, mapping: platform.nornir_platform}]` → `router-1` host has `platform == "eos"` |
There was a problem hiding this comment.
P3: Use the actual mapped value here. platform.nornir_platform resolves to arista_eos, not eos.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/superpowers/specs/2026-05-23-integration-tests-design.md, line 67:
<comment>Use the actual mapped value here. `platform.nornir_platform` resolves to `arista_eos`, not `eos`.</comment>
<file context>
@@ -0,0 +1,105 @@
+
+### `TestSchemaMappings`
+- `schema_mappings: [{name: hostname, mapping: primary_address.address}]` → `router-1` host has `hostname == "10.0.0.1"`
+- `schema_mappings: [{name: platform, mapping: platform.nornir_platform}]` → `router-1` host has `platform == "eos"`
+
+### `TestGroupMappings`
</file context>
Deploying nornir-infrahub with
|
| Latest commit: |
cce0cd1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c6a262fa.nornir-infrahub.pages.dev |
| Branch Preview URL: | https://ml-20260523-integration-test.nornir-infrahub.pages.dev |
20839bc to
9ab4ede
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…crash Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
schema_mappings and group_mappings that traverse relationships (e.g. primary_address.address, site.name) require those relationship names to be in the include list so Infrahub returns full peer data. Previously only member_of_groups was auto-added; other mapped relationships came back as stubs with None attribute values. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Disable MD060 (table column alignment) in .markdownlint.yml — impractical with wide description columns - Add PLR2004 to tests/** ruff ignores — magic numbers in assertions are idiomatic - Run ruff format to fix set comprehension style in test_inventory.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9ab4ede to
f7a640f
Compare
- Add two unit tests covering the auto-include behavior added in c756442: * relationships referenced by schema/group mappings are added to include * pre-existing relationships in include are not duplicated - Import TEST_TOKEN from infrahub_testcontainers.PROJECT_ENV_VARIABLES instead of hardcoding the same UUID - Document the integration test suite, the auto-include behavior, and the macOS psutil workaround in AGENTS.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The crash is an Apple Silicon (arm64) psutil bug, not Python 3.13 specific. Also reference the actual call site (host.get_system_stats via InfrahubPerformanceTest.__init__) for context. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document the -p no:pytest-infrahub-performance-test workaround where it actually lives (pyproject.toml) instead of in AGENTS.md, so future maintainers see the rationale at the point of confusion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The auto-include fix (c756442) made the manual host_node.include step unnecessary for relationships referenced in schema_mappings or group_mappings. Update the user docs accordingly: - configuring-schema-mappings.mdx: rewrite the :::important callout (which claimed include was required) as a :::note describing the auto-include behavior, with a pointer to the performance-optimization section for users who still want to limit query scope - Remove the now-redundant include lines from the beginner examples in getting-started.mdx, your-first-automation-workflow.mdx, the Step 5 example in configuring-schema-mappings.mdx, and the reference doc The performance-optimization angle (selective includes in the concepts topic) remains valid and is left untouched. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Scope note: this PR started as integration tests for
Could be split, but the test work, the bug it exposed, and the docs that follow from it are tightly linked. Happy to split into separate PRs if reviewers prefer. |
PR #74 (wvandeun, open since 2026-04-23) fixes the same bug with a more comprehensive approach: deletes the redundant pre-fetch loop and adds construction-time validation for multi-hop and unknown-relationship mappings. Defer to that PR. Reverts: - the 3-line auto-include in InfrahubInventory.__init__ - the two unit tests asserting the auto-include behavior - the AGENTS.md note describing the auto-include - the 4 user-doc files (configuring-schema-mappings.mdx, references/plugins/infrahub_inventory.mdx, getting-started.mdx, your-first-automation-workflow.mdx) restored to origin/stable Integration tests for schema_mappings/group_mappings remain. They will fail locally without PR #74 applied; that's expected and documents the problem #74 fixes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Scope update: Dropped the bugfix and doc changes from this PR — they're superseded by #74 (same fix, more comprehensive: deletes the redundant pre-fetch loop and adds construction-time validation for multi-hop / unknown-relationship mappings). This PR is now purely:
|
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/docs/guides/configuring-schema-mappings.mdx">
<violation number="1">
P3: Don't make `host_node.include` mandatory here. The integration tests resolve these mappings without any `include` entries, so this guide now contradicts the actual behavior. Update the Step 5 `# required` comments too.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
These tests previously assumed the auto-include behavior we reverted (deferring to PR #74). Without auto-include, the SDK overwrites the hydrated peer cached by the pre-fetch loop with a stub on the host fetch, so resolve_node_mapping reads None. Passing include explicitly on the host_node tells the SDK to hydrate those relations directly, which works on both current code and PR #74's branch (where it gets merged with auto-derived). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/integration/test_inventory.py">
<violation number="1" location="tests/integration/test_inventory.py:36">
P2: These mapping tests now manually include relationship fields, which masks regressions in the auto-include behavior the integration suite is supposed to protect.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| class TestSchemaMappings(NornirInfrahubIntegration): | ||
| def test_ip_address_mapping(self, infrahub_address: str) -> None: | ||
| inventory = InfrahubInventory( | ||
| host_node={"kind": "InfraDevice", "include": ["primary_address"]}, |
There was a problem hiding this comment.
P2: These mapping tests now manually include relationship fields, which masks regressions in the auto-include behavior the integration suite is supposed to protect.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/integration/test_inventory.py, line 36:
<comment>These mapping tests now manually include relationship fields, which masks regressions in the auto-include behavior the integration suite is supposed to protect.</comment>
<file context>
@@ -33,7 +33,7 @@ def test_host_names_match(self, infrahub_address: str) -> None:
def test_ip_address_mapping(self, infrahub_address: str) -> None:
inventory = InfrahubInventory(
- host_node={"kind": "InfraDevice"},
+ host_node={"kind": "InfraDevice", "include": ["primary_address"]},
address=infrahub_address,
token=TEST_TOKEN,
</file context>
| host_node={"kind": "InfraDevice", "include": ["primary_address"]}, | |
| host_node={"kind": "InfraDevice"}, |
There was a problem hiding this comment.
Not actionable in this PR. The auto-include behavior the reviewer wants the tests to protect doesn't exist on this branch — it was reverted in commit "defer auto-include changes to PR #74". Manual include doesn't mask a regression in code that isn't here.
Note that cubic gave the exact opposite feedback on configuring-schema-mappings.mdx minutes earlier ("tests don't use include, so docs are wrong"). Both reviews assume auto-include lives in this PR; it doesn't.
When #74 merges and reintroduces auto-include, removing the explicit include from TestSchemaMappings/TestGroupMappings becomes meaningful regression coverage and naturally falls under #74 scope.
Adds tests/integration/test_file_object.py running against a live Infrahub spun up by #79's testcontainers harness. Loads a TestingTestFile schema that inherits from CoreFileObject plus a label attribute, and exercises: - upload_lifecycle: create → idempotent skip → update on content change - download_returns_content: bytes round-trip via base64 - download_skip_when_local_matches: second download is a no-op - data_attr_persists_on_skip: label is saved even when the file content is unchanged (verifies the metadata-on-skip behaviour) - explicit_object_id_not_found_fails: typo'd UUID fails cleanly - unknown_key_in_data_fails_on_update: bogus data key is rejected Run with 'pytest -m integration' (requires Docker). All 6 pass locally against the testcontainers Infrahub in ~70s. Closes the integration-testing follow-up referenced in the testing-status comment on PR #71 (post-#79). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
tests/integration/that validatesInfrahubInventoryagainst a live Infrahub instance spun up viainfrahub-testcontainersInfrahubInventorywhereschema_mappingsandgroup_mappingsthat traverse relationships (e.g.primary_address.address,site.name) silently returnedNone— mapped relationship names are now auto-added to the device fetchincludelistTest Plan
uv run pytest tests/unit/ -v— 17 unit tests passuv run pytest tests/integration/ -v -p no:pytest-infrahub-performance-test --override-ini="addopts=-v"with Docker running — 14 integration tests pass (requires Docker Desktop)pytestrun via-m 'not integration'inaddoptsso existing CI is unaffectedNotes
get_artifact,generate_artifacts,regenerate_host_artifact) are deferred to a follow-uppsutil.cpu_freq()crash from theinfrahub-testcontainersperf plugin on macOS/Python 3.13 is worked around by disabling the plugin inaddoptsCloses #78
🤖 Generated with Claude Code
Summary by cubic
Adds an integration test suite for
InfrahubInventoryusinginfrahub-testcontainers, plus runner config and docs to make it easy to use. Schema/group mapping tests now pass explicit relationship includes; the broader auto-include fix remains deferred to PR #74 (NORNIR-5).New Features
tests/integration/with a baseconftestthat seeds schema, sample devices/sites/IPs, aCoreStandardGroup, and a feature branch; 14 tests across 6 classes cover loading, schema/group mappings, group membership, filters, and branch routing. Mapping tests pass explicithost_node.includeto hydrate relations.infrahub-testcontainers; admin token is read frominfrahub_testcontainers.helpers.PROJECT_ENV_VARIABLES.AGENTS.mdupdated with integration test guidance.integrationand excluded by default;pyproject.tomladds "-m 'not integration'" and disablespytest-infrahub-performance-testto avoid a macOSpsutilcrash.Dependencies
infrahub-testcontainers>=1.9.3.Written for commit cce0cd1. Summary will update on new commits. Review in cubic