@@ -1671,3 +1671,72 @@ fn test_detect_version_variable_creates_profiles_for_each_version() {
1671
1671
assert ! ( v17_entry. addons_paths_sourced( ) . as_ref( ) . unwrap( ) . iter( ) . any( |s| s. value( ) == & v17_path) ) ;
1672
1672
assert ! ( v18_entry. addons_paths_sourced( ) . as_ref( ) . unwrap( ) . iter( ) . any( |s| s. value( ) == & v18_path) ) ;
1673
1673
}
1674
+
1675
+ #[ test]
1676
+ fn test_config_file_path_priority ( ) {
1677
+ let temp = TempDir :: new ( ) . unwrap ( ) ;
1678
+ let ws_folder = temp. child ( "workspace1" ) ;
1679
+ ws_folder. create_dir_all ( ) . unwrap ( ) ;
1680
+
1681
+ // Create two addon dirs for testing merge
1682
+ let ws_addon = ws_folder. child ( "ws_addons" ) ;
1683
+ ws_addon. create_dir_all ( ) . unwrap ( ) ;
1684
+ ws_addon. child ( "mod" ) . child ( "__manifest__.py" ) . touch ( ) . unwrap ( ) ;
1685
+
1686
+ let ext_addon = temp. child ( "ext_addons" ) ;
1687
+ ext_addon. create_dir_all ( ) . unwrap ( ) ;
1688
+ ext_addon. child ( "mod" ) . child ( "__manifest__.py" ) . touch ( ) . unwrap ( ) ;
1689
+
1690
+ // Workspace config with one addons_path
1691
+ let ws_toml = format ! ( r#"
1692
+ [[config]]
1693
+ name = "default"
1694
+ python_path = "python"
1695
+ addons_paths = ["{}"]
1696
+ "# , ws_addon. path( ) . sanitize( ) ) ;
1697
+ ws_folder. child ( "odools.toml" ) . write_str ( & ws_toml) . unwrap ( ) ;
1698
+
1699
+ // External config with a different addons_path
1700
+ let ext_toml = format ! ( r#"
1701
+ [[config]]
1702
+ name = "default"
1703
+ file_cache = true
1704
+ auto_refresh_delay = 4321
1705
+ addons_paths = ["{}"]
1706
+ "# , ext_addon. path( ) . sanitize( ) ) ;
1707
+ let ext_config = temp. child ( "external_config.toml" ) ;
1708
+ ext_config. write_str ( & ext_toml) . unwrap ( ) ;
1709
+
1710
+ let mut ws_folders = HashMap :: new ( ) ;
1711
+ ws_folders. insert ( S ! ( "ws1" ) , ws_folder. path ( ) . sanitize ( ) . to_string ( ) ) ;
1712
+
1713
+ let config_path = ext_config. path ( ) . sanitize ( ) ;
1714
+ let ( config_map, _config_file) = get_configuration ( & ws_folders, & Some ( config_path) ) . unwrap ( ) ;
1715
+ let config = config_map. get ( "default" ) . unwrap ( ) ;
1716
+
1717
+ // Should use values from external config
1718
+ assert_eq ! ( config. file_cache, true ) ;
1719
+ assert_eq ! ( config. auto_refresh_delay, 4321 ) ;
1720
+
1721
+ // Should merge addons_paths from both configs
1722
+ let ws_addon_path = ws_addon. path ( ) . sanitize ( ) ;
1723
+ let ext_addon_path = ext_addon. path ( ) . sanitize ( ) ;
1724
+ assert ! ( config. addons_paths. iter( ) . any( |p| p == & ws_addon_path) , "Should contain ws_addon path" ) ;
1725
+ assert ! ( config. addons_paths. iter( ) . any( |p| p == & ext_addon_path) , "Should contain ext_addon path" ) ;
1726
+ }
1727
+
1728
+ #[ test]
1729
+ fn test_config_file_path_nonexistent_errors ( ) {
1730
+ let temp = TempDir :: new ( ) . unwrap ( ) ;
1731
+ let ws_folder = temp. child ( "workspace1" ) ;
1732
+ ws_folder. create_dir_all ( ) . unwrap ( ) ;
1733
+
1734
+ let mut ws_folders = HashMap :: new ( ) ;
1735
+ ws_folders. insert ( S ! ( "ws1" ) , ws_folder. path ( ) . sanitize ( ) . to_string ( ) ) ;
1736
+
1737
+ // Provide a non-existent config file path
1738
+ let non_existent = temp. child ( "does_not_exist.toml" ) ;
1739
+ let config_path = non_existent. path ( ) . sanitize ( ) ;
1740
+ let result = get_configuration ( & ws_folders, & Some ( config_path) ) ;
1741
+ assert ! ( result. is_err( ) , "Expected error when config file path does not exist" ) ;
1742
+ }
0 commit comments