@@ -798,4 +798,84 @@ mod tests {
798798 assert ! ( !debug_output. contains( "***REDACTED***" ) ) ;
799799 assert ! ( debug_output. contains( "AgentConfig" ) ) ;
800800 }
801+
802+ fn minimal_config ( cli_command : & str ) -> AgentConfig {
803+ AgentConfig {
804+ agent_id : "test-agent" . to_string ( ) ,
805+ cli_command : cli_command. to_string ( ) ,
806+ args : vec ! [ ] ,
807+ working_dir : None ,
808+ env_vars : HashMap :: new ( ) ,
809+ required_api_keys : vec ! [ ] ,
810+ resource_limits : ResourceLimits :: default ( ) ,
811+ use_stdin : false ,
812+ supports_stdin : false ,
813+ }
814+ }
815+
816+ #[ tokio:: test]
817+ async fn test_validate_missing_cli_returns_cli_not_found ( ) {
818+ let config = minimal_config ( "__terraphim_no_such_cli_xyz_999__" ) ;
819+ let validator = AgentValidator :: new ( & config) ;
820+ let result = validator. validate ( ) . await ;
821+ assert ! (
822+ matches!( result, Err ( ValidationError :: CliNotFound ( _) ) ) ,
823+ "expected CliNotFound, got {:?}" ,
824+ result
825+ ) ;
826+ }
827+
828+ #[ tokio:: test]
829+ async fn test_validate_missing_api_key_returns_api_key_not_set ( ) {
830+ const KEY : & str = "TERRAPHIM_TEST_MISSING_KEY_SPAWNER_XYZ" ;
831+ unsafe { std:: env:: remove_var ( KEY ) } ;
832+
833+ let mut config = minimal_config ( "echo" ) ;
834+ config. required_api_keys = vec ! [ KEY . to_string( ) ] ;
835+
836+ let validator = AgentValidator :: new ( & config) ;
837+ let result = validator. validate ( ) . await ;
838+ assert ! (
839+ matches!( result, Err ( ValidationError :: ApiKeyNotSet ( _) ) ) ,
840+ "expected ApiKeyNotSet, got {:?}" ,
841+ result
842+ ) ;
843+ }
844+
845+ #[ tokio:: test]
846+ async fn test_validate_valid_config_succeeds ( ) {
847+ let config = minimal_config ( "echo" ) ;
848+ let validator = AgentValidator :: new ( & config) ;
849+ let result = validator. validate ( ) . await ;
850+ assert ! ( result. is_ok( ) , "expected Ok(()), got {:?}" , result) ;
851+ }
852+
853+ #[ tokio:: test]
854+ async fn test_validate_api_key_present_succeeds ( ) {
855+ const KEY : & str = "TERRAPHIM_TEST_PRESENT_KEY_SPAWNER_XYZ" ;
856+ unsafe { std:: env:: set_var ( KEY , "dummy-value" ) } ;
857+
858+ let mut config = minimal_config ( "echo" ) ;
859+ config. required_api_keys = vec ! [ KEY . to_string( ) ] ;
860+
861+ let validator = AgentValidator :: new ( & config) ;
862+ let result = validator. validate ( ) . await ;
863+
864+ unsafe { std:: env:: remove_var ( KEY ) } ;
865+
866+ assert ! ( result. is_ok( ) , "expected Ok(()), got {:?}" , result) ;
867+ }
868+
869+ #[ tokio:: test]
870+ async fn test_validate_missing_working_dir_returns_error ( ) {
871+ let mut config = minimal_config ( "echo" ) ;
872+ config. working_dir = Some ( std:: path:: PathBuf :: from ( "/nonexistent/path/xyz_999" ) ) ;
873+ let validator = AgentValidator :: new ( & config) ;
874+ let result = validator. validate ( ) . await ;
875+ assert ! (
876+ matches!( result, Err ( ValidationError :: WorkingDirNotFound ( _) ) ) ,
877+ "expected WorkingDirNotFound, got {:?}" ,
878+ result
879+ ) ;
880+ }
801881}
0 commit comments