@@ -211,6 +211,50 @@ def test_update_extracts_sam_json(self, mock_get_url, mock_url_newer):
211211 self .assertTrue ((resources_dir / "sam123.json" ).exists ())
212212
213213
214+ class TestAutoDownloadOnMissingSchemas (BaseTestCase ):
215+ """Test that schemas are auto-downloaded when provider files are missing"""
216+
217+ def setUp (self ) -> None :
218+ super ().setUp ()
219+ self .manager = _make_manager ()
220+
221+ @patch ("cfnlint.schema.manager.ProviderSchemaManager.update" )
222+ def test_auto_downloads_when_no_providers (self , mock_update ):
223+ """When no provider files exist, update is called automatically"""
224+ import tempfile
225+ from pathlib import Path
226+
227+ with tempfile .TemporaryDirectory () as tmpdir :
228+ providers_dir = Path (tmpdir ) / "providers"
229+ providers_dir .mkdir ()
230+
231+ self .manager ._providers_dir = providers_dir
232+ self .manager ._provider_schema_modules = {}
233+
234+ self .manager ._load_provider_module ("us-east-1" )
235+ mock_update .assert_called_once_with (force = False )
236+
237+ @patch ("cfnlint.schema.manager.ProviderSchemaManager.update" )
238+ def test_no_auto_download_when_providers_exist (self , mock_update ):
239+ """When provider files exist, update is not called"""
240+ import tempfile
241+ from pathlib import Path
242+
243+ with tempfile .TemporaryDirectory () as tmpdir :
244+ providers_dir = Path (tmpdir ) / "providers"
245+ providers_dir .mkdir ()
246+ (providers_dir / "us-east-1.json" ).write_text (
247+ json .dumps ({"AWS::S3::Bucket" : "abc123" })
248+ )
249+
250+ self .manager ._providers_dir = providers_dir
251+ self .manager ._provider_schema_modules = {}
252+ self .manager ._sam_schema_module = {}
253+
254+ self .manager ._load_provider_module ("us-east-1" )
255+ mock_update .assert_not_called ()
256+
257+
214258class TestManagerGetResourceSchema (BaseTestCase ):
215259 """Test get resource schema"""
216260
0 commit comments