Provider Name Extraction Tests Summary
This document summarizes the tests added for provider name extraction logic in hybrid_execution.py.
Test Coverage
The following test methods were added to TestHybridExecution class in test_hybrid_execution.py:
1. test_provider_name_extraction_explicit_provider
Tests extraction of provider names when resources have explicit nf_provider attributes:
- Resources with Provider instances (no alias)
- Resources with Provider instances (with alias using _provider_alias)
2. test_provider_name_extraction_string_provider
Tests extraction when nf_provider is:
- A direct string reference (e.g., "hashicorp/aws")
- An object with a provider_name attribute
3. test_provider_name_extraction_from_type
Tests extraction from resource type when no explicit provider: - Standard resource types with underscore (e.g., "aws_s3_bucket" → "aws") - Multi-segment resource types (e.g., "azurerm_virtual_machine" → "azurerm") - Resource types without underscore (defaults to "default")
4. test_provider_name_extraction_edge_cases
Tests edge cases including:
- Provider with multi-level alias (e.g., "prod.west")
- Complex resource types (e.g., "google_compute_instance_group_manager")
- Resources with None/empty provider attribute
- Provider instances without nf_type attribute (fallback to provider_name)
5. test_provider_name_extraction_integration
Integration test with a realistic multi-provider stack scenario: - Multiple AWS providers (main and aliased) - Resources with different provider patterns - Mixed explicit and inferred providers
Key Implementation Details
The tests verify the provider name extraction logic in _build_stack_state method which handles:
- Explicit provider reference - Check
nf_providerattribute - If it's a Provider instance, use
nf_typeand optional_provider_alias - If it has
provider_nameattribute, use that -
If it's a string, use it directly
-
Inference from resource type - When no explicit provider
- Extract provider from resource type prefix (before first underscore)
- Default to "default" if no underscore found
Test Execution
All tests use mocked orchestrator to avoid recursion issues:
hybrid._orchestrator = Mock()
hybrid._orchestrator._resolve_runtime_tokens = Mock(return_value={})
hybrid._orchestrator._extract_dependencies = Mock(return_value=[])
This ensures tests focus on provider extraction logic without triggering complex orchestration workflows.