@@ -31,6 +31,8 @@ def mock_github_client(self):
3131 # Make synchronous methods actually synchronous
3232 client ._extract_repo_from_module_id = Mock ()
3333 client .match_file_patterns = Mock ()
34+ # Ensure resolve_version returns a string, not a mock
35+ client .resolve_version = AsyncMock (return_value = "1.0.0" )
3436 return client
3537
3638 @pytest .fixture
@@ -1149,3 +1151,78 @@ def mock_match_patterns(
11491151 # Verify the matching logic worked correctly
11501152 # With the bug, this might fail if valid_include_matched logic is broken
11511153 assert "# main.tf content" in result
1154+
1155+ @pytest .mark .asyncio
1156+ async def test_get_content_source_replacement (
1157+ self , config , mock_github_client
1158+ ):
1159+ """Test that source = '../../' is replaced with module ID and version."""
1160+ # Setup
1161+ request = GetContentRequest (
1162+ module_id = "terraform-ibm-modules/vpc/ibm" ,
1163+ path = "examples/basic" ,
1164+ include_files = ["main.tf" ]
1165+ )
1166+
1167+ mock_github_client ._extract_repo_from_module_id .return_value = (
1168+ "terraform-ibm-modules" , "terraform-ibm-vpc"
1169+ )
1170+ mock_github_client .resolve_version .return_value = "v1.2.3"
1171+
1172+ # Mock directory contents
1173+ mock_github_client .get_directory_contents .return_value = [
1174+ {
1175+ "name" : "main.tf" ,
1176+ "path" : "examples/basic/main.tf" ,
1177+ "type" : "file" ,
1178+ "download_url" : "https://api.github.com/repos/terraform-ibm-modules/terraform-ibm-vpc/contents/examples/basic/main.tf"
1179+ }
1180+ ]
1181+
1182+ # Mock file content with source = "../../" pattern
1183+ async def mock_get_file_content (owner , repo , path , ref ):
1184+ return {
1185+ "name" : "main.tf" ,
1186+ "path" : "examples/basic/main.tf" ,
1187+ "content" : "encoded_content" ,
1188+ "encoding" : "base64" ,
1189+ "size" : 200 ,
1190+ "decoded_content" : '''module "vpc" {
1191+ source = "../../"
1192+ vpc_name = var.vpc_name
1193+ resource_group_id = var.resource_group_id
1194+ }
1195+
1196+ module "other" {
1197+ source = "../.."
1198+ other_param = "value"
1199+ }'''
1200+ }
1201+
1202+ mock_github_client .get_file_content .side_effect = mock_get_file_content
1203+
1204+ # Mock pattern matching
1205+ mock_github_client .match_file_patterns .return_value = [
1206+ {
1207+ "name" : "main.tf" ,
1208+ "path" : "examples/basic/main.tf" ,
1209+ "type" : "file" ,
1210+ "download_url" : "https://api.github.com/repos/terraform-ibm-modules/terraform-ibm-vpc/contents/examples/basic/main.tf"
1211+ }
1212+ ]
1213+
1214+ # Execute
1215+ result = await get_content_impl (request , config , mock_github_client )
1216+
1217+ # Verify source replacement occurred
1218+ assert 'source = "terraform-ibm-modules/vpc/ibm"' in result
1219+ assert 'version = "1.2.3"' in result
1220+
1221+ # Verify original ../../ patterns are gone
1222+ assert 'source = "../../"' not in result
1223+ assert 'source = "../.."' not in result
1224+
1225+ # Verify basic structure is maintained
1226+ assert "## main.tf" in result
1227+ assert 'module "vpc"' in result
1228+ assert 'module "other"' in result
0 commit comments