3434from tests_common import IS_WINDOWS
3535
3636
37+ def is_config_ng_enabled ():
38+ """Check if config_ng is enabled via environment variable"""
39+ return os .getenv ("SNOWFLAKE_CLI_CONFIG_V2_ENABLED" ) == "true"
40+
41+
3742def test_empty_config_file_is_created_if_not_present ():
3843 from snowflake .cli .api .utils .path_utils import path_resolver
3944
@@ -383,7 +388,12 @@ def assert_correct_connections_loaded():
383388 assert_correct_connections_loaded ()
384389
385390
386- def test_connections_toml_override_config_toml (
391+ # Legacy version - skip when config_ng is enabled
392+ @pytest .mark .skipif (
393+ is_config_ng_enabled (),
394+ reason = "Legacy behavior: connections.toml replaces all connections from config.toml" ,
395+ )
396+ def test_connections_toml_override_config_toml_legacy (
387397 test_snowcli_config , snowflake_home , config_manager
388398):
389399 connections_toml = snowflake_home / "connections.toml"
@@ -394,12 +404,49 @@ def test_connections_toml_override_config_toml(
394404 )
395405 config_init (test_snowcli_config )
396406
407+ # Legacy: Only connections from connections.toml are present
397408 assert get_default_connection_dict () == {"database" : "overridden_database" }
398409 assert config_manager ["connections" ] == {
399410 "default" : {"database" : "overridden_database" }
400411 }
401412
402413
414+ # Config_ng version - skip when config_ng is NOT enabled
415+ @pytest .mark .skipif (
416+ not is_config_ng_enabled (),
417+ reason = "Config_ng behavior: connections.toml merges with config.toml per-key" ,
418+ )
419+ def test_connections_toml_override_config_toml_config_ng (
420+ test_snowcli_config , snowflake_home , config_manager
421+ ):
422+ """Test config_ng behavior: connections.toml merges with config.toml per-key"""
423+ connections_toml = snowflake_home / "connections.toml"
424+ connections_toml .write_text (
425+ """[default]
426+ database = "overridden_database"
427+ """
428+ )
429+ config_init (test_snowcli_config )
430+
431+ # Config_ng: Merged - database from connections.toml, other keys from config.toml
432+ # The key difference from legacy: keys from config.toml are preserved
433+ default_conn = get_default_connection_dict ()
434+
435+ # Key from connections.toml (level 3) overrides
436+ assert default_conn ["database" ] == "overridden_database"
437+
438+ # Keys from config.toml (level 2) are preserved
439+ assert default_conn ["schema" ] == "test_public"
440+ assert default_conn ["role" ] == "test_role"
441+ assert default_conn ["warehouse" ] == "xs"
442+ assert default_conn ["password" ] == "dummy_password"
443+
444+ # Verify other connections from config.toml are also accessible
445+ full_conn = get_connection_dict ("full" )
446+ assert full_conn ["account" ] == "dev_account"
447+ assert full_conn ["user" ] == "dev_user"
448+
449+
403450parametrize_chmod = pytest .mark .parametrize (
404451 "chmod" ,
405452 [
0 commit comments