| 1 | use super::*; |
| 2 | |
| 3 | use super::context::COMPACTION_SUMMARY_MARKER; |
| 4 | use super::streaming::{TOOL_CALL_END_MARKERS, TOOL_CALL_MARKER_PAIRS}; |
| 5 | use super::turn_loop::{ |
| 6 | auto_review_block_tool_error, call_forces_prompt, initial_stream_error_user_message, |
| 7 | preview_request_error_user_message, registered_tool_approval_required, |
| 8 | registered_tool_forces_prompt, replace_runtime_mcp_tools, repo_law_must_block_without_prompt, |
| 9 | requested_sandbox_escalation, sandbox_escalation_denial, workspace_write_carve_out_applies, |
| 10 | }; |
| 11 | use crate::prompts::{ |
| 12 | InstructionSource, PromptSessionContext, system_prompt_flat_text, |
| 13 | system_prompt_for_mode_with_context_skills_and_session, |
| 14 | }; |
| 15 | use crate::test_support::{EnvVarGuard, lock_test_env}; |
| 16 | use codewhale_config::ProviderKind; |
| 17 | use codewhale_models::{SystemBlock, Usage}; |
| 18 | use serde_json::{Value, json}; |
| 19 | use std::collections::{HashMap, HashSet}; |
| 20 | use std::ffi::OsString; |
| 21 | use std::fs; |
| 22 | use std::path::{Path, PathBuf}; |
| 23 | use std::time::{Duration, Instant}; |
| 24 | use tempfile::tempdir; |
| 25 | |
| 26 | #[path = "tests/creator_gate.rs"] |
| 27 | mod creator_gate; |
| 28 | #[path = "tests/creator_loop.rs"] |
| 29 | mod creator_loop; |
| 30 | #[path = "tests/creator_refresh.rs"] |
| 31 | mod creator_refresh; |
| 32 | #[path = "tests/extension_creator.rs"] |
| 33 | mod extension_creator; |
| 34 | #[path = "tests/extension_hooks.rs"] |
| 35 | mod extension_hooks; |
| 36 | #[path = "tests/extension_prompts.rs"] |
| 37 | mod extension_prompts; |
| 38 | #[path = "tests/profile_constitution.rs"] |
| 39 | mod profile_constitution; |
| 40 | |
| 41 | #[path = "tests/child_host.rs"] |
| 42 | mod child_host; |
| 43 | |
| 44 | include!("tests/test_cases_01.rs"); |
| 45 | |
| 46 | mod compaction; |
| 47 | include!("tests/test_cases_02.rs"); |
| 48 | |
| 49 | include!("tests/test_cases_03.rs"); |
| 50 | |
| 51 | include!("tests/test_cases_04.rs"); |
| 52 | |
| 53 | include!("tests/test_cases_05.rs"); |
| 54 | |
| 55 | include!("tests/test_cases_06.rs"); |
| 56 | |
| 57 | include!("tests/test_cases_07.rs"); |
| 58 | |
| 59 | include!("tests/test_cases_08.rs"); |
| 60 | |
| 61 | include!("tests/test_cases_09.rs"); |
| 62 | |
| 63 | include!("tests/test_cases_10.rs"); |
| 64 | |
| 65 | include!("tests/test_cases_11.rs"); |
| 66 | |
| 67 | include!("tests/test_cases_12.rs"); |
| 68 | |
| 69 | include!("tests/test_cases_13.rs"); |
| 70 | |
| 71 | include!("tests/test_cases_14.rs"); |
| 72 | |
| 73 | include!("tests/test_cases_15.rs"); |
| 74 | |
| 75 | include!("tests/test_cases_16.rs"); |
| 76 | |
| 77 | include!("tests/test_cases_17.rs"); |
| 78 | |
| 79 | include!("tests/test_cases_18.rs"); |
| 80 | |
| 81 | include!("tests/test_cases_19.rs"); |
| 82 | |
| 83 | mod admission_gates; |
| 84 | mod redacted_thinking; |
| 85 | mod runtime_state; |
| 86 | mod sse_turn_recovery; |
| 87 | mod third_party_search; |
| 88 | mod tool_cancellation; |
| 89 | include!("tests/test_cases_20.rs"); |
| 90 | |
| 91 | #[path = "tests/rlm_host.rs"] |
| 92 | pub mod rlm_host; |
| 93 | |
| 94 | #[test] |
| 95 | fn run_completion_real_factories_observe_shutdown_and_direct_handles_do_not() { |
| 96 | let _env = lock_test_env(); |
| 97 | let home = tempdir().unwrap(); |
| 98 | let _home = EnvVarGuard::set("CODEWHALE_HOME", home.path()); |
| 99 | let runtime = tokio::runtime::Builder::new_current_thread() |
| 100 | .enable_all() |
| 101 | .build() |
| 102 | .unwrap(); |
| 103 | runtime.block_on(async { |
| 104 | let config = Config::default(); |
| 105 | let engine_config = || { |
| 106 | let mut config = deterministic_engine_config(home.path()); |
| 107 | config.features.disable(Feature::Mcp); |
| 108 | config.memory_enabled = false; |
| 109 | config |
| 110 | }; |
| 111 | let (direct, handle) = Engine::new(engine_config(), &config); |
| 112 | assert_eq!( |
| 113 | handle.wait_run_completion().await, |
| 114 | EngineRunCompletion::NotObserved |
| 115 | ); |
| 116 | drop(direct); |
| 117 | let handle = spawn_engine(engine_config(), &config, None).await; |
| 118 | let mut completion = Box::pin(handle.wait_run_completion()); |
| 119 | std::future::poll_fn(|cx| { |
| 120 | assert!(std::future::Future::poll(completion.as_mut(), cx).is_pending()); |
| 121 | std::task::Poll::Ready(()) |
| 122 | }) |
| 123 | .await; |
| 124 | drop(completion); |
| 125 | handle.send(Op::Shutdown).await.unwrap(); |
| 126 | assert_eq!( |
| 127 | tokio::time::timeout(Duration::from_secs(5), handle.wait_run_completion()) |
| 128 | .await |
| 129 | .unwrap(), |
| 130 | EngineRunCompletion::NormalReturn |
| 131 | ); |
| 132 | let (handle, task) = spawn_engine_with_authoritative_route_config( |
| 133 | engine_config(), |
| 134 | &config, |
| 135 | EngineHostProfile::Normal, |
| 136 | Arc::new(parking_lot::RwLock::new(config.clone())), |
| 137 | None, |
| 138 | None, |
| 139 | CancellationToken::new(), |
| 140 | ); |
| 141 | handle.send(Op::Shutdown).await.unwrap(); |
| 142 | assert_eq!( |
| 143 | tokio::time::timeout(Duration::from_secs(5), handle.wait_run_completion()) |
| 144 | .await |
| 145 | .unwrap(), |
| 146 | EngineRunCompletion::NormalReturn |
| 147 | ); |
| 148 | task.await.unwrap(); |
| 149 | }); |
| 150 | } |
| 151 |