()
| 1031 | |
| 1032 | #[tokio::test] |
| 1033 | async fn test_run_task_container_success() { |
| 1034 | let mock_client = Arc::new(TrackedDockerClient::default()); |
| 1035 | let ctx = AppContext::builder().build(); |
| 1036 | let manager = DockerManager::new(&ctx, mock_client.clone(), None); |
| 1037 | |
| 1038 | let task = create_test_task(false); |
| 1039 | let agent = crate::agent::ClaudeAgent::with_tsk_env(ctx.tsk_env()); |
| 1040 | let result = manager.run_task_container("tsk/base", &task, &agent).await; |
| 1041 | |
| 1042 | assert!(result.is_ok()); |
| 1043 | let (output, task_result) = result.unwrap(); |
| 1044 | assert_eq!(output, "Container logs"); |
| 1045 | assert!(task_result.success); |
| 1046 | assert_eq!(task_result.message, "Task completed"); |
| 1047 | |
| 1048 | let create_calls = mock_client.create_container_calls.lock().unwrap(); |
| 1049 | assert_eq!(create_calls.len(), 2); // One for proxy, one for task container |
| 1050 | |
| 1051 | // Check that the command includes the agent command |
| 1052 | let task_container_config = &create_calls[1].1; |
| 1053 | let actual_cmd = task_container_config.cmd.as_ref().unwrap(); |
| 1054 | // Command should be sh -c with the agent command |
| 1055 | assert_eq!(actual_cmd.len(), 3); |
| 1056 | assert_eq!(actual_cmd[0], "sh"); |
| 1057 | assert_eq!(actual_cmd[1], "-c"); |
| 1058 | assert!(actual_cmd[2].contains("claude")); |
| 1059 | |
| 1060 | // Check that user is set |
| 1061 | assert_eq!(task_container_config.user, Some(CONTAINER_USER.to_string())); |
| 1062 | |
| 1063 | // Check proxy environment variables (uses fingerprinted proxy container name) |
| 1064 | let pcn = default_proxy_container_name(); |
| 1065 | let env = task_container_config.env.as_ref().unwrap(); |
| 1066 | assert!(env.contains(&format!("HTTP_PROXY=http://{pcn}:3128"))); |
| 1067 | assert!(env.contains(&format!("HTTPS_PROXY=http://{pcn}:3128"))); |
| 1068 | assert!( |
| 1069 | env.iter().any(|e| e.starts_with("JAVA_TOOL_OPTIONS=")), |
| 1070 | "JAVA_TOOL_OPTIONS should be set for proxy" |
| 1071 | ); |
| 1072 | |
| 1073 | // Check TSK environment variables |
| 1074 | assert!(env.contains(&"TSK_CONTAINER=1".to_string())); |
| 1075 | assert!(env.contains(&"TSK_TASK_ID=test-task-id".to_string())); |
| 1076 | drop(create_calls); // Release the lock |
| 1077 | |
| 1078 | let start_calls = mock_client.start_container_calls.lock().unwrap(); |
| 1079 | assert_eq!(start_calls.len(), 2); // One for proxy, one for task container |
| 1080 | assert_eq!(start_calls[0], pcn); |
| 1081 | assert_eq!(start_calls[1], "test-container-id-1"); |
| 1082 | |
| 1083 | let wait_calls = mock_client.wait_container_calls.lock().unwrap(); |
| 1084 | assert_eq!(wait_calls.len(), 1); |
| 1085 | assert_eq!(wait_calls[0], "test-container-id-1"); |
| 1086 | |
| 1087 | let remove_calls = mock_client.remove_container_calls.lock().unwrap(); |
| 1088 | assert_eq!(remove_calls.len(), 2); // One for task container, one for proxy |
| 1089 | assert_eq!(remove_calls[0].0, "test-container-id-1"); |
| 1090 | assert_eq!(remove_calls[1].0, pcn); |
nothing calls this directly
no test coverage detected