@@ -140,7 +140,7 @@ async fn run_show(args: WorkspaceShowArgs) -> Result<()> {
140140 let agents_path = root. join ( "AGENTS.md" ) ;
141141 let git_dir = root. join ( ".git" ) ;
142142
143- let has_cortex_config = config_path. exists ( ) ;
143+ let has_cortex_config = config_path. is_file ( ) ;
144144 let has_agents_md = agents_path. exists ( ) ;
145145 let has_git = git_dir. exists ( ) ;
146146
@@ -150,14 +150,7 @@ async fn run_show(args: WorkspaceShowArgs) -> Result<()> {
150150 . and_then ( |n| n. to_str ( ) )
151151 . map ( |s| s. to_string ( ) ) ;
152152
153- // Load settings if config exists
154- let settings = if has_cortex_config {
155- std:: fs:: read_to_string ( & config_path)
156- . ok ( )
157- . and_then ( |content| toml:: from_str ( & content) . ok ( ) )
158- } else {
159- None
160- } ;
153+ let settings = load_workspace_settings ( & config_path) ;
161154
162155 let info = WorkspaceInfo {
163156 root : root. clone ( ) ,
@@ -237,6 +230,16 @@ async fn run_show(args: WorkspaceShowArgs) -> Result<()> {
237230 Ok ( ( ) )
238231}
239232
233+ fn load_workspace_settings ( config_path : & PathBuf ) -> Option < WorkspaceSettings > {
234+ if !config_path. is_file ( ) {
235+ return None ;
236+ }
237+
238+ std:: fs:: read_to_string ( config_path)
239+ . ok ( )
240+ . and_then ( |content| toml:: from_str ( & content) . ok ( ) )
241+ }
242+
240243async fn run_init ( args : WorkspaceInitArgs ) -> Result < ( ) > {
241244 let root = find_workspace_root ( ) ;
242245 let cortex_dir = root. join ( ".cortex" ) ;
@@ -417,6 +420,32 @@ async fn run_edit(args: WorkspaceEditArgs) -> Result<()> {
417420#[ cfg( test) ]
418421mod tests {
419422 use super :: * ;
423+ use tempfile:: TempDir ;
424+
425+ // ==========================================================================
426+ // Workspace config loading tests
427+ // ==========================================================================
428+
429+ #[ test]
430+ fn test_load_workspace_settings_reads_config_file ( ) {
431+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
432+ let config_path = temp_dir. path ( ) . join ( "config.toml" ) ;
433+ std:: fs:: write ( & config_path, r#"model = "gpt-4""# ) . unwrap ( ) ;
434+
435+ let settings = load_workspace_settings ( & config_path) . unwrap ( ) ;
436+
437+ assert_eq ! ( settings. model, Some ( "gpt-4" . to_string( ) ) ) ;
438+ }
439+
440+ #[ test]
441+ fn test_load_workspace_settings_ignores_config_directory ( ) {
442+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
443+ let config_path = temp_dir. path ( ) . join ( "config.toml" ) ;
444+ std:: fs:: create_dir_all ( & config_path) . unwrap ( ) ;
445+
446+ assert ! ( !config_path. is_file( ) ) ;
447+ assert ! ( load_workspace_settings( & config_path) . is_none( ) ) ;
448+ }
420449
421450 // ==========================================================================
422451 // WorkspaceSettings tests
0 commit comments