@@ -141,6 +141,60 @@ def test_load_cargo_package_name_supports_inline_comments(self):
141141 "astrbot-desktop-tauri" ,
142142 )
143143
144+ def test_load_cargo_package_name_missing_cargo_toml_raises_file_not_found (self ):
145+ with tempfile .TemporaryDirectory () as tmpdir :
146+ project_root = Path (tmpdir )
147+
148+ with self .assertRaises (FileNotFoundError ):
149+ MODULE .load_cargo_package_name (project_root )
150+
151+ def test_load_cargo_package_name_missing_package_table_raises_value_error (self ):
152+ with tempfile .TemporaryDirectory () as tmpdir :
153+ project_root = Path (tmpdir )
154+ cargo_toml_path = project_root / "src-tauri" / "Cargo.toml"
155+ cargo_toml_path .parent .mkdir (parents = True )
156+ cargo_toml_path .write_text ('[workspace]\n members = ["crates/*"]\n ' )
157+
158+ with self .assertRaises (ValueError ):
159+ MODULE .load_cargo_package_name (project_root )
160+
161+ def test_load_cargo_package_name_missing_package_name_raises_value_error (self ):
162+ with tempfile .TemporaryDirectory () as tmpdir :
163+ project_root = Path (tmpdir )
164+ cargo_toml_path = project_root / "src-tauri" / "Cargo.toml"
165+ cargo_toml_path .parent .mkdir (parents = True )
166+ cargo_toml_path .write_text ('[package]\n version = "0.1.0"\n ' )
167+
168+ with self .assertRaises (ValueError ):
169+ MODULE .load_cargo_package_name (project_root )
170+
171+ def test_load_cargo_package_name_empty_package_name_raises_value_error (self ):
172+ with tempfile .TemporaryDirectory () as tmpdir :
173+ project_root = Path (tmpdir )
174+ cargo_toml_path = project_root / "src-tauri" / "Cargo.toml"
175+ cargo_toml_path .parent .mkdir (parents = True )
176+ cargo_toml_path .write_text ('[package]\n name = ""\n ' )
177+
178+ with self .assertRaises (ValueError ):
179+ MODULE .load_cargo_package_name (project_root )
180+
181+ def test_load_cargo_package_name_falls_back_to_package_when_bin_missing_name (self ):
182+ with tempfile .TemporaryDirectory () as tmpdir :
183+ project_root = Path (tmpdir )
184+ cargo_toml_path = project_root / "src-tauri" / "Cargo.toml"
185+ cargo_toml_path .parent .mkdir (parents = True )
186+ cargo_toml_path .write_text (
187+ "[package]\n "
188+ 'name = "astrbot-desktop-tauri"\n \n '
189+ "[[bin]]\n "
190+ 'path = "src/main.rs"\n '
191+ )
192+
193+ self .assertEqual (
194+ MODULE .load_cargo_package_name (project_root ),
195+ "astrbot-desktop-tauri" ,
196+ )
197+
144198 def test_load_cargo_package_name_prefers_explicit_bin_name (self ):
145199 with tempfile .TemporaryDirectory () as tmpdir :
146200 project_root = Path (tmpdir )
0 commit comments