@@ -20,9 +20,7 @@ def test_save_includes_descriptions(config_manager, mock_config_dir):
2020 manager .save (include_defaults = True )
2121
2222 content = _config_path (mock_config_dir ).read_text (encoding = "utf-8" )
23- assert "# Logging configuration." in content
2423 assert "# Web/HTTP configuration." in content
25- assert "# Tidy3D API base URL." in content
2624
2725
2826def test_preserves_user_comments (config_manager , mock_config_dir ):
@@ -32,7 +30,7 @@ def test_preserves_user_comments(config_manager, mock_config_dir):
3230 config_path = _config_path (mock_config_dir )
3331 text = config_path .read_text (encoding = "utf-8" )
3432 text = text .replace (
35- "Tidy3D API base URL ." ,
33+ "Web/HTTP configuration ." ,
3634 "user-modified comment" ,
3735 )
3836 config_path .write_text (text , encoding = "utf-8" )
@@ -43,57 +41,90 @@ def test_preserves_user_comments(config_manager, mock_config_dir):
4341
4442 updated = config_path .read_text (encoding = "utf-8" )
4543 assert "user-modified comment" in updated
46- assert "Tidy3D API base URL ." not in updated
44+ assert "Web/HTTP configuration ." not in updated
4745
4846
4947def test_profile_preserves_comments (config_manager , mock_config_dir ):
50- manager = config_manager
51- manager .switch_profile ("custom" )
52- manager .update_section ("web" , timeout = 55 )
53- manager .save ()
54-
55- profile_path = mock_config_dir / "profiles" / "custom.toml"
56- text = profile_path .read_text (encoding = "utf-8" )
57- assert "HTTP request timeout in seconds." in text
58- text = text .replace ("HTTP request timeout in seconds." , "user comment" )
59- profile_path .write_text (text , encoding = "utf-8" )
48+ @config_registry .register_plugin ("profile_comment" )
49+ class ProfileComment (ConfigSection ):
50+ """Profile comment plugin."""
6051
61- manager .update_section ("web" , timeout = 56 )
62- manager .save ()
52+ knob : int = pd .Field (
53+ 1 ,
54+ description = "Profile knob description." ,
55+ json_schema_extra = {"persist" : True },
56+ )
6357
64- updated = profile_path .read_text (encoding = "utf-8" )
65- assert "user comment" in updated
66- assert "HTTP request timeout in seconds." not in updated
58+ try :
59+ manager = config_manager
60+ manager .switch_profile ("custom" )
61+ manager .update_section ("plugins.profile_comment" , knob = 5 )
62+ manager .save ()
63+
64+ profile_path = mock_config_dir / "profiles" / "custom.toml"
65+ text = profile_path .read_text (encoding = "utf-8" )
66+ assert "Profile knob description." in text
67+ text = text .replace ("Profile knob description." , "user comment" )
68+ profile_path .write_text (text , encoding = "utf-8" )
69+
70+ manager .update_section ("plugins.profile_comment" , knob = 7 )
71+ manager .save ()
72+
73+ updated = profile_path .read_text (encoding = "utf-8" )
74+ assert "user comment" in updated
75+ assert "Profile knob description." not in updated
76+ finally :
77+ config_registry ._SECTIONS .pop ("plugins.profile_comment" , None )
78+ reload_config (profile = "default" )
6779
6880
6981def test_cli_reset_config (mock_config_dir ):
70- reload_config (profile = "default" )
71- manager = get_manager ()
72- manager .update_section ("web" , api_endpoint = "https://example.com" )
73- manager .save (include_defaults = True )
74- manager .switch_profile ("custom" )
75- manager .update_section ("web" , timeout = 70 )
76- manager .save ()
82+ @config_registry .register_plugin ("cli_comment" )
83+ class CLIPlugin (ConfigSection ):
84+ """CLI plugin configuration."""
7785
78- profiles_dir = mock_config_dir / "profiles"
79- assert profiles_dir .exists ()
86+ knob : int = pd .Field (
87+ 3 ,
88+ description = "CLI knob description." ,
89+ json_schema_extra = {"persist" : True },
90+ )
8091
81- runner = CliRunner ()
82- result = runner .invoke (tidy3d_cli , ["config-reset" , "--yes" ])
83- assert result .exit_code == 0 , result .output
84-
85- config_text = _config_path (mock_config_dir ).read_text (encoding = "utf-8" )
86- assert "Web/HTTP configuration." in config_text
87- assert "Tidy3D API base URL" in config_text
88- assert not profiles_dir .exists ()
92+ try :
93+ reload_config (profile = "default" )
94+ manager = get_manager ()
95+ manager .update_section ("web" , apikey = "secret" )
96+ manager .save (include_defaults = True )
97+ manager .switch_profile ("custom" )
98+ manager .update_section ("plugins.cli_comment" , knob = 42 )
99+ manager .save ()
100+
101+ profiles_dir = mock_config_dir / "profiles"
102+ assert profiles_dir .exists ()
103+
104+ runner = CliRunner ()
105+ result = runner .invoke (tidy3d_cli , ["config-reset" , "--yes" ])
106+ assert result .exit_code == 0 , result .output
107+
108+ config_text = _config_path (mock_config_dir ).read_text (encoding = "utf-8" )
109+ assert "Web/HTTP configuration." in config_text
110+ assert "[web]" in config_text
111+ assert "secret" not in config_text
112+ assert not profiles_dir .exists ()
113+ finally :
114+ config_registry ._SECTIONS .pop ("plugins.cli_comment" , None )
115+ reload_config (profile = "default" )
89116
90117
91118def test_plugin_descriptions (mock_config_dir ):
92119 @config_registry .register_plugin ("comment_test" )
93120 class CommentPlugin (ConfigSection ):
94121 """Comment plugin configuration."""
95122
96- knob : int = pd .Field (3 , description = "Plugin knob description." )
123+ knob : int = pd .Field (
124+ 3 ,
125+ description = "Plugin knob description." ,
126+ json_schema_extra = {"persist" : True },
127+ )
97128
98129 try :
99130 reload_config (profile = "default" )
0 commit comments