| 1 | //! Actual Core fixtures for the migrated RLM contract. Replies are adapted to |
| 2 | //! the existing stream decoder; there is no fixture model/code loop. |
| 3 | use super::*; |
| 4 | use crate::core::engine::rlm_host::{CapturedRlmCaller, RlmInvocation, RlmMode, RlmPromptPolicy}; |
| 5 | use crate::llm_client::LlmClient; |
| 6 | use crate::rlm::bridge::{RlmBridge, RlmUsageAccumulator}; |
| 7 | use codewhale_models::{MessageRequest, MessageResponse, StreamEvent}; |
| 8 | use std::future::Future; |
| 9 | use std::pin::Pin; |
| 10 | |
| 11 | pub trait Replies: Send + Sync { |
| 12 | fn effective_route_envelope( |
| 13 | &self, |
| 14 | model: &str, |
| 15 | at: chrono::DateTime<chrono::Utc>, |
| 16 | ) -> crate::cost_status::EffectiveRouteEnvelope; |
| 17 | fn effective_max_output_tokens(&self, model: &str) -> u32; |
| 18 | fn create_message_boxed( |
| 19 | &self, |
| 20 | request: MessageRequest, |
| 21 | ) -> Pin<Box<dyn Future<Output = anyhow::Result<MessageResponse>> + Send + '_>>; |
| 22 | } |
| 23 | impl<T: LlmClient + Send + Sync> Replies for T { |
| 24 | fn effective_route_envelope( |
| 25 | &self, |
| 26 | model: &str, |
| 27 | at: chrono::DateTime<chrono::Utc>, |
| 28 | ) -> crate::cost_status::EffectiveRouteEnvelope { |
| 29 | LlmClient::effective_route_envelope(self, model, at) |
| 30 | } |
| 31 | fn effective_max_output_tokens(&self, model: &str) -> u32 { |
| 32 | LlmClient::effective_max_output_tokens(self, model) |
| 33 | } |
| 34 | fn create_message_boxed( |
| 35 | &self, |
| 36 | request: MessageRequest, |
| 37 | ) -> Pin<Box<dyn Future<Output = anyhow::Result<MessageResponse>> + Send + '_>> { |
| 38 | Box::pin(LlmClient::create_message(self, request)) |
| 39 | } |
| 40 | } |
| 41 | struct ReplyStream { |
| 42 | replies: Arc<dyn Replies>, |
| 43 | model: String, |
| 44 | } |
| 45 | #[async_trait::async_trait] |
| 46 | impl crate::core::model_client::ModelClient for ReplyStream { |
| 47 | fn provider_name(&self) -> &str { |
| 48 | "custom" |
| 49 | } |
| 50 | fn model(&self) -> &str { |
| 51 | &self.model |
| 52 | } |
| 53 | fn effective_route_envelope( |
| 54 | &self, |
| 55 | model: &str, |
| 56 | at: chrono::DateTime<chrono::Utc>, |
| 57 | ) -> crate::cost_status::EffectiveRouteEnvelope { |
| 58 | self.replies.effective_route_envelope(model, at) |
| 59 | } |
| 60 | fn effective_max_output_tokens(&self, model: &str) -> u32 { |
| 61 | self.replies.effective_max_output_tokens(model) |
| 62 | } |
| 63 | async fn create_message(&self, request: MessageRequest) -> anyhow::Result<MessageResponse> { |
| 64 | self.replies.create_message_boxed(request).await |
| 65 | } |
| 66 | async fn create_message_stream( |
| 67 | &self, |
| 68 | request: MessageRequest, |
| 69 | ) -> anyhow::Result<crate::llm_client::StreamEventBox> { |
| 70 | let response = self.replies.create_message_boxed(request).await?; |
| 71 | let mut start = response.clone(); |
| 72 | start.content.clear(); |
| 73 | let mut events = vec![StreamEvent::MessageStart { message: start }]; |
| 74 | for (index, block) in response.content.iter().enumerate() { |
| 75 | let index = u32::try_from(index).expect("fixture block index"); |
| 76 | match block { |
| 77 | ContentBlock::Text { text, .. } => { |
| 78 | events.push(StreamEvent::ContentBlockStart { |
| 79 | index, |
| 80 | content_block: codewhale_models::ContentBlockStart::Text { |
| 81 | text: String::new(), |
| 82 | }, |
| 83 | }); |
| 84 | events.push(StreamEvent::ContentBlockDelta { |
| 85 | index, |
| 86 | delta: codewhale_models::Delta::TextDelta { text: text.clone() }, |
| 87 | }); |
| 88 | } |
| 89 | _ => { |
| 90 | events.push(StreamEvent::ContentBlockStart { |
| 91 | index, |
| 92 | content_block: serde_json::from_value(serde_json::to_value(block)?)?, |
| 93 | }); |
| 94 | } |
| 95 | } |
| 96 | events.push(StreamEvent::ContentBlockStop { index }); |
| 97 | } |
| 98 | events.push(StreamEvent::MessageDelta { |
| 99 | delta: codewhale_models::MessageDelta { |
| 100 | stop_reason: response.stop_reason, |
| 101 | stop_sequence: response.stop_sequence, |
| 102 | title: None, |
| 103 | stop_details: None, |
| 104 | refusal: None, |
| 105 | }, |
| 106 | usage: Some(response.usage), |
| 107 | }); |
| 108 | events.push(StreamEvent::MessageStop); |
| 109 | Ok(Box::pin(futures_util::stream::iter( |
| 110 | events.into_iter().map(Ok), |
| 111 | ))) |
| 112 | } |
| 113 | async fn health_check(&self) -> anyhow::Result<bool> { |
| 114 | Ok(true) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | pub fn fixture_config(model: &str) -> Config { |
| 119 | let mut config: Config = toml::from_str(&format!("provider = 'rlm-fixture'\n[providers.rlm-fixture]\nkind = 'openai-compatible'\napi_key = 'owned-fixture-key'\nbase_url = 'http://127.0.0.1:9/v1'\nmodel = {}\ncontext_window = 1000000\n", serde_json::to_string(model).unwrap())).expect("fixture Config"); |
| 120 | config.default_text_model = Some(model.to_string()); |
| 121 | config |
| 122 | } |
| 123 | |
| 124 | pub fn install_fixture_route(engine: &mut Engine) { |
| 125 | let identity = engine |
| 126 | .api_config |
| 127 | .active_provider_identity() |
| 128 | .expect("fixture admitted exact id"); |
| 129 | let resolved = resolve_runtime_route_for_identity( |
| 130 | &engine.api_config, |
| 131 | &identity, |
| 132 | Some(&engine.session.model), |
| 133 | ) |
| 134 | .expect("fixture route"); |
| 135 | let client = CodewhaleClient::new(&resolved.config) |
| 136 | .expect("fixture captured client, never called unless loopback transport was supplied"); |
| 137 | engine.install_validated_runtime_route(ValidatedRuntimeRoute { |
| 138 | identity: resolved.identity, |
| 139 | candidate: resolved.candidate, |
| 140 | config: resolved.config, |
| 141 | model: resolved.model, |
| 142 | context_window: resolved.context_window, |
| 143 | client, |
| 144 | }); |
| 145 | } |
| 146 | |
| 147 | /// Use the actual configured Engine's posture, route, registry and services. |
| 148 | /// No client-only or ambient default configuration grants fixture authority. |
| 149 | pub fn admitted_context(engine: &Engine, turn_id: &str) -> ToolContext { |
| 150 | let posture = engine.applied_runtime_authority(); |
| 151 | let authority = TurnAuthority::from_effective_fields( |
| 152 | posture.mode, |
| 153 | posture.allow_shell, |
| 154 | posture.trust_mode, |
| 155 | posture.auto_approve, |
| 156 | posture.approval_mode, |
| 157 | ); |
| 158 | let route = TurnRouteContext { |
| 159 | provider: engine.api_provider, |
| 160 | model: engine.session.model.clone(), |
| 161 | capabilities: engine.active_route_capabilities, |
| 162 | limits: engine.active_route_limits, |
| 163 | client: engine.codewhale_client.clone(), |
| 164 | api_config: Box::new(engine.api_config.clone()), |
| 165 | locale_tag: "en".into(), |
| 166 | role_models: engine.subagent_role_models(), |
| 167 | auto_model: false, |
| 168 | reasoning_effort: None, |
| 169 | reasoning_effort_auto: false, |
| 170 | }; |
| 171 | let mut context = engine.build_tool_context_for_turn(&authority, &route); |
| 172 | let caller = CapturedRlmCaller::capture(engine, &authority, &route, &context, turn_id) |
| 173 | .expect("actual Core admission"); |
| 174 | context.rlm_caller = Some(Arc::new(caller)); |
| 175 | context |
| 176 | } |
| 177 | |
| 178 | pub fn caller_for(replies: Arc<dyn Replies>, model: &str) -> CapturedRlmCaller { |
| 179 | let workspace = Arc::new(tempfile::tempdir().expect("RLM fixture workspace")); |
| 180 | let config = fixture_config(model); |
| 181 | let (mut engine, _handle) = Engine::new_with_model_client( |
| 182 | EngineConfig { |
| 183 | workspace: workspace.path().to_path_buf(), |
| 184 | model: model.to_string(), |
| 185 | snapshots_enabled: false, |
| 186 | memory_enabled: false, |
| 187 | subagents_enabled: false, |
| 188 | terminal_chrome_enabled: false, |
| 189 | turn_wall_clock: Duration::from_secs(60), |
| 190 | ..EngineConfig::default() |
| 191 | }, |
| 192 | &config, |
| 193 | Arc::new(ReplyStream { |
| 194 | replies, |
| 195 | model: model.to_string(), |
| 196 | }), |
| 197 | ); |
| 198 | install_fixture_route(&mut engine); |
| 199 | engine.session.system_prompt = Some(SystemPrompt::Text( |
| 200 | "Captured operator Core policy. Task guidance is additive.".into(), |
| 201 | )); |
| 202 | let context = admitted_context(&engine, "fixture-origin-turn"); |
| 203 | let mut caller = context |
| 204 | .rlm_caller |
| 205 | .as_ref() |
| 206 | .expect("captured receipt") |
| 207 | .as_ref() |
| 208 | .clone(); |
| 209 | caller.hold_fixture_workspace(workspace); |
| 210 | caller |
| 211 | } |
| 212 | |
| 213 | /// Admit a loopback LlmClient through a real Engine with the supplied Config |
| 214 | /// and tool context services, rather than granting authority to its URL alone. |
| 215 | pub fn context_for_replies( |
| 216 | config: &Config, |
| 217 | model: &str, |
| 218 | context: &ToolContext, |
| 219 | replies: Arc<dyn Replies>, |
| 220 | ) -> ToolContext { |
| 221 | let (mut engine, _handle) = Engine::new_with_model_client( |
| 222 | EngineConfig { |
| 223 | workspace: context.workspace.clone(), |
| 224 | model: model.to_string(), |
| 225 | session_id: Some(context.state_namespace.clone()), |
| 226 | runtime_services: context.runtime.clone(), |
| 227 | plugin_registry: context.plugin_registry.clone(), |
| 228 | snapshots_enabled: false, |
| 229 | memory_enabled: false, |
| 230 | subagents_enabled: false, |
| 231 | terminal_chrome_enabled: false, |
| 232 | turn_wall_clock: Duration::from_secs(60), |
| 233 | ..EngineConfig::default() |
| 234 | }, |
| 235 | config, |
| 236 | Arc::new(ReplyStream { |
| 237 | replies, |
| 238 | model: model.to_string(), |
| 239 | }), |
| 240 | ); |
| 241 | install_fixture_route(&mut engine); |
| 242 | let mut admitted = admitted_context(&engine, "fixture-tool-origin-turn"); |
| 243 | admitted.nested_call_gate = context.nested_call_gate.clone(); |
| 244 | admitted |
| 245 | } |
| 246 | |
| 247 | pub struct BridgeFixture { |
| 248 | caller: CapturedRlmCaller, |
| 249 | depth: u32, |
| 250 | pub usage: RlmUsageAccumulator, |
| 251 | deadline: Option<tokio::time::Instant>, |
| 252 | gate: Option<crate::tools::codemode::NestedCallGate>, |
| 253 | events: Option<mpsc::Sender<Event>>, |
| 254 | } |
| 255 | impl BridgeFixture { |
| 256 | pub fn new(replies: Arc<dyn Replies>, model: String, depth: u32) -> Self { |
| 257 | Self::with_usage_accumulator(replies, model, depth, RlmUsageAccumulator::new()) |
| 258 | } |
| 259 | pub fn with_usage_accumulator( |
| 260 | replies: Arc<dyn Replies>, |
| 261 | model: String, |
| 262 | depth: u32, |
| 263 | usage: RlmUsageAccumulator, |
| 264 | ) -> Self { |
| 265 | Self { |
| 266 | caller: caller_for(replies, &model), |
| 267 | depth, |
| 268 | usage, |
| 269 | deadline: None, |
| 270 | gate: None, |
| 271 | events: None, |
| 272 | } |
| 273 | } |
| 274 | fn bridge(&self) -> RlmBridge<'_> { |
| 275 | let mut bridge = |
| 276 | RlmBridge::with_usage_accumulator(&self.caller, self.depth, self.usage.clone()) |
| 277 | .with_deadline(self.deadline) |
| 278 | .with_gate(self.gate.clone()); |
| 279 | if let Some(events) = &self.events { |
| 280 | bridge = bridge.with_events(events.clone()); |
| 281 | } |
| 282 | bridge |
| 283 | } |
| 284 | pub fn with_deadline(mut self, deadline: Option<tokio::time::Instant>) -> Self { |
| 285 | self.deadline = deadline; |
| 286 | self |
| 287 | } |
| 288 | pub fn with_gate(mut self, gate: Option<crate::tools::codemode::NestedCallGate>) -> Self { |
| 289 | self.gate = gate; |
| 290 | self |
| 291 | } |
| 292 | pub fn with_events(mut self, events: mpsc::Sender<Event>) -> Self { |
| 293 | self.events = Some(events); |
| 294 | self |
| 295 | } |
| 296 | pub async fn usage_snapshot(&self) -> crate::rlm::bridge::RlmUsageSnapshot { |
| 297 | self.usage.snapshot().await |
| 298 | } |
| 299 | pub async fn dispatch_rlm( |
| 300 | &self, |
| 301 | prompt: String, |
| 302 | model: Option<String>, |
| 303 | ) -> codewhale_repl::runtime::SingleResp { |
| 304 | self.bridge().dispatch_rlm(prompt, model).await |
| 305 | } |
| 306 | } |
| 307 | impl codewhale_repl::runtime::RpcDispatcher for BridgeFixture { |
| 308 | fn dispatch<'a>( |
| 309 | &'a self, |
| 310 | request: codewhale_repl::runtime::RpcRequest, |
| 311 | ) -> Pin<Box<dyn Future<Output = codewhale_repl::runtime::RpcResponse> + Send + 'a>> { |
| 312 | Box::pin(async move { |
| 313 | codewhale_repl::runtime::RpcDispatcher::dispatch(&self.bridge(), request).await |
| 314 | }) |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | #[allow(clippy::too_many_arguments)] |
| 319 | pub async fn run_admitted_fixture( |
| 320 | replies: Arc<dyn Replies>, |
| 321 | model: String, |
| 322 | prompt: String, |
| 323 | task: Option<String>, |
| 324 | _old_child_model: String, |
| 325 | events: mpsc::Sender<Event>, |
| 326 | depth: u32, |
| 327 | usage: RlmUsageAccumulator, |
| 328 | deadline: tokio::time::Instant, |
| 329 | gate: Option<crate::tools::codemode::NestedCallGate>, |
| 330 | ) -> crate::rlm::turn::RlmTurnResult { |
| 331 | let caller = caller_for(replies, &model); |
| 332 | caller |
| 333 | .dispatch(RlmInvocation { |
| 334 | prompt, |
| 335 | mode: RlmMode::Recursive { |
| 336 | depth_remaining: depth, |
| 337 | }, |
| 338 | prompt_policy: RlmPromptPolicy::Session, |
| 339 | max_tokens: None, |
| 340 | task_instructions: task, |
| 341 | deadline: Some(deadline), |
| 342 | gate, |
| 343 | events: Some(events), |
| 344 | usage, |
| 345 | }) |
| 346 | .await |
| 347 | } |
| 348 | #[allow(clippy::too_many_arguments)] |
| 349 | pub async fn run_fixture( |
| 350 | replies: Arc<dyn Replies>, |
| 351 | model: String, |
| 352 | prompt: String, |
| 353 | task: Option<String>, |
| 354 | old_child_model: String, |
| 355 | events: mpsc::Sender<Event>, |
| 356 | depth: u32, |
| 357 | ) -> crate::rlm::turn::RlmTurnResult { |
| 358 | run_admitted_fixture( |
| 359 | replies, |
| 360 | model, |
| 361 | prompt, |
| 362 | task, |
| 363 | old_child_model, |
| 364 | events, |
| 365 | depth, |
| 366 | RlmUsageAccumulator::new(), |
| 367 | tokio::time::Instant::now() + Duration::from_secs(60), |
| 368 | Some(crate::tools::codemode::NestedCallGate::admitting_for_test()), |
| 369 | ) |
| 370 | .await |
| 371 | } |
| 372 | |
| 373 | #[tokio::test] |
| 374 | async fn captured_identity_cancel_and_task_bounds_refuse_before_any_provider() { |
| 375 | let workspace = tempfile::tempdir().unwrap(); |
| 376 | let config = fixture_config("captured-model"); |
| 377 | let mock = Arc::new(crate::llm_client::mock::MockLlmClient::new(Vec::new())); |
| 378 | let context = context_for_replies( |
| 379 | &config, |
| 380 | "captured-model", |
| 381 | &ToolContext::new(workspace.path()), |
| 382 | mock.clone(), |
| 383 | ); |
| 384 | let caller = context.rlm_caller.as_ref().unwrap(); |
| 385 | for altered in [ |
| 386 | { |
| 387 | let mut c = context.clone(); |
| 388 | c.workspace = workspace.path().join("other"); |
| 389 | c |
| 390 | }, |
| 391 | { |
| 392 | let mut c = context.clone(); |
| 393 | c.state_namespace.push_str("-other"); |
| 394 | c |
| 395 | }, |
| 396 | { |
| 397 | let mut c = context.clone(); |
| 398 | c.owner_agent_id = Some("foreign-child".into()); |
| 399 | c |
| 400 | }, |
| 401 | ] { |
| 402 | assert!( |
| 403 | caller.validate_context(&altered).is_err(), |
| 404 | "caller mutation cannot grant a nested route" |
| 405 | ); |
| 406 | } |
| 407 | let zero_tokens = caller |
| 408 | .dispatch(RlmInvocation { |
| 409 | prompt: "no effect".into(), |
| 410 | mode: RlmMode::Completion, |
| 411 | prompt_policy: RlmPromptPolicy::Session, |
| 412 | max_tokens: Some(0), |
| 413 | task_instructions: None, |
| 414 | deadline: caller.deadline(), |
| 415 | gate: None, |
| 416 | events: None, |
| 417 | usage: RlmUsageAccumulator::new(), |
| 418 | }) |
| 419 | .await; |
| 420 | assert!( |
| 421 | zero_tokens |
| 422 | .error |
| 423 | .unwrap() |
| 424 | .contains("max_tokens must be greater than zero") |
| 425 | ); |
| 426 | assert_eq!(mock.call_count(), 0); |
| 427 | let rejected = caller |
| 428 | .dispatch(RlmInvocation { |
| 429 | prompt: "no effect".into(), |
| 430 | mode: RlmMode::Completion, |
| 431 | prompt_policy: RlmPromptPolicy::Session, |
| 432 | max_tokens: None, |
| 433 | task_instructions: Some("x".repeat(4097)), |
| 434 | deadline: caller.deadline(), |
| 435 | gate: None, |
| 436 | events: None, |
| 437 | usage: RlmUsageAccumulator::new(), |
| 438 | }) |
| 439 | .await; |
| 440 | assert!(rejected.error.unwrap().contains("4096 bytes")); |
| 441 | context.cancel_token.as_ref().unwrap().cancel(); |
| 442 | let cancelled = caller |
| 443 | .dispatch(RlmInvocation { |
| 444 | prompt: "no effect".into(), |
| 445 | mode: RlmMode::Completion, |
| 446 | prompt_policy: RlmPromptPolicy::Session, |
| 447 | max_tokens: None, |
| 448 | task_instructions: None, |
| 449 | deadline: caller.deadline(), |
| 450 | gate: None, |
| 451 | events: None, |
| 452 | usage: RlmUsageAccumulator::new(), |
| 453 | }) |
| 454 | .await; |
| 455 | assert!( |
| 456 | cancelled |
| 457 | .error |
| 458 | .unwrap() |
| 459 | .contains("originating turn is cancelled") |
| 460 | ); |
| 461 | assert_eq!(mock.call_count(), 0); |
| 462 | } |
| 463 | |
| 464 | #[tokio::test] |
| 465 | async fn dropping_an_actual_dispatched_core_call_keeps_unknown_usage_without_retaining_authority() { |
| 466 | struct Pending(Arc<tokio::sync::Notify>); |
| 467 | impl Replies for Pending { |
| 468 | fn effective_route_envelope( |
| 469 | &self, |
| 470 | model: &str, |
| 471 | at: chrono::DateTime<chrono::Utc>, |
| 472 | ) -> crate::cost_status::EffectiveRouteEnvelope { |
| 473 | crate::cost_status::EffectiveRouteEnvelope::capture_observed( |
| 474 | codewhale_config::ProviderKind::Custom, |
| 475 | "rlm-fixture", |
| 476 | model, |
| 477 | Some("http://127.0.0.1:9/v1"), |
| 478 | at, |
| 479 | ) |
| 480 | } |
| 481 | fn effective_max_output_tokens(&self, _: &str) -> u32 { |
| 482 | 8192 |
| 483 | } |
| 484 | fn create_message_boxed( |
| 485 | &self, |
| 486 | _: MessageRequest, |
| 487 | ) -> Pin<Box<dyn Future<Output = anyhow::Result<MessageResponse>> + Send + '_>> { |
| 488 | self.0.notify_one(); |
| 489 | Box::pin(std::future::pending()) |
| 490 | } |
| 491 | } |
| 492 | let entered = Arc::new(tokio::sync::Notify::new()); |
| 493 | let caller = Arc::new(caller_for( |
| 494 | Arc::new(Pending(entered.clone())), |
| 495 | "captured-model", |
| 496 | )); |
| 497 | let weak_caller = Arc::downgrade(&caller); |
| 498 | let usage = RlmUsageAccumulator::new(); |
| 499 | let mut dispatch = caller.dispatch(RlmInvocation { |
| 500 | prompt: "pending".into(), |
| 501 | mode: RlmMode::Completion, |
| 502 | prompt_policy: RlmPromptPolicy::Session, |
| 503 | max_tokens: None, |
| 504 | task_instructions: None, |
| 505 | deadline: Some(tokio::time::Instant::now() + Duration::from_secs(600)), |
| 506 | gate: None, |
| 507 | events: None, |
| 508 | usage: usage.clone(), |
| 509 | }); |
| 510 | tokio::time::timeout(Duration::from_secs(10), async { |
| 511 | tokio::select! { |
| 512 | biased; |
| 513 | () = entered.notified() => {} |
| 514 | result = &mut dispatch => panic!( |
| 515 | "dropped dispatch never reached the client: {:?}", |
| 516 | result.error |
| 517 | ), |
| 518 | } |
| 519 | }) |
| 520 | .await |
| 521 | .expect("the dispatched call must reach the client"); |
| 522 | tokio::time::pause(); |
| 523 | tokio::time::advance(Duration::from_secs(601)).await; |
| 524 | let result = dispatch.await; |
| 525 | assert!( |
| 526 | result |
| 527 | .error |
| 528 | .as_deref() |
| 529 | .unwrap() |
| 530 | .contains("wall-clock deadline") |
| 531 | ); |
| 532 | let snapshot = usage.snapshot().await; |
| 533 | assert_eq!(snapshot.records.len(), 1); |
| 534 | let revision = snapshot.records[0] |
| 535 | .settlement |
| 536 | .as_ref() |
| 537 | .expect("dropped dispatch keeps a settled receipt"); |
| 538 | assert_eq!( |
| 539 | revision.coverage, |
| 540 | crate::llm_client::ProviderUsageCoverage::Missing |
| 541 | ); |
| 542 | assert_eq!( |
| 543 | revision.reason, |
| 544 | Some(crate::cost_status::RuntimeUsageMissingReason::RequestOutcomeUnknown) |
| 545 | ); |
| 546 | assert_eq!(snapshot.records[0].usage.route.model, "captured-model"); |
| 547 | assert!(snapshot.drop_records.is_empty()); |
| 548 | assert_eq!(snapshot.dropped_records, 0); |
| 549 | assert_eq!( |
| 550 | usage.snapshot().await.records, |
| 551 | snapshot.records, |
| 552 | "inspection never republishes or loses the settled receipt" |
| 553 | ); |
| 554 | drop(caller); |
| 555 | assert!( |
| 556 | weak_caller.upgrade().is_none(), |
| 557 | "dropped nested work retains no caller authority" |
| 558 | ); |
| 559 | } |
| 560 | |
| 561 | #[tokio::test] |
| 562 | async fn full_caller_channel_never_delays_original_cancel_or_loses_usage_and_kernel_cleanup() { |
| 563 | struct FirstThenPending { |
| 564 | mock: crate::llm_client::mock::MockLlmClient, |
| 565 | entered: tokio::sync::Notify, |
| 566 | } |
| 567 | impl Replies for FirstThenPending { |
| 568 | fn effective_route_envelope( |
| 569 | &self, |
| 570 | model: &str, |
| 571 | at: chrono::DateTime<chrono::Utc>, |
| 572 | ) -> crate::cost_status::EffectiveRouteEnvelope { |
| 573 | Replies::effective_route_envelope(&self.mock, model, at) |
| 574 | } |
| 575 | fn effective_max_output_tokens(&self, model: &str) -> u32 { |
| 576 | Replies::effective_max_output_tokens(&self.mock, model) |
| 577 | } |
| 578 | fn create_message_boxed( |
| 579 | &self, |
| 580 | request: MessageRequest, |
| 581 | ) -> Pin<Box<dyn Future<Output = anyhow::Result<MessageResponse>> + Send + '_>> { |
| 582 | Box::pin(async move { |
| 583 | if self.mock.call_count() > 0 { |
| 584 | self.entered.notify_one(); |
| 585 | std::future::pending().await |
| 586 | } else { |
| 587 | Replies::create_message_boxed(&self.mock, request).await |
| 588 | } |
| 589 | }) |
| 590 | } |
| 591 | } |
| 592 | let replies = Arc::new(FirstThenPending { |
| 593 | mock: crate::llm_client::mock::MockLlmClient::new(Vec::new()), |
| 594 | entered: tokio::sync::Notify::new(), |
| 595 | }); |
| 596 | replies.mock.push_message_response(MessageResponse { |
| 597 | tool_projection_warning: None, |
| 598 | id: "completed-python-round".into(), |
| 599 | r#type: "message".into(), |
| 600 | role: "assistant".into(), |
| 601 | content: vec![ContentBlock::Text { |
| 602 | text: "```repl\nprint(len(content))\n```".into(), |
| 603 | cache_control: None, |
| 604 | }], |
| 605 | model: "captured-model".into(), |
| 606 | stop_reason: Some("end_turn".into()), |
| 607 | stop_sequence: None, |
| 608 | container: None, |
| 609 | title: None, |
| 610 | stop_details: None, |
| 611 | refusal: None, |
| 612 | usage: Usage { |
| 613 | input_tokens: 7, |
| 614 | output_tokens: 11, |
| 615 | ..Usage::default() |
| 616 | }, |
| 617 | }); |
| 618 | let caller = caller_for(replies.clone(), "captured-model"); |
| 619 | let cancel = caller.fixture_origin_cancel(); |
| 620 | let usage = RlmUsageAccumulator::new(); |
| 621 | let (tx, mut rx) = mpsc::channel(1); |
| 622 | let deadline = caller.deadline().expect("admitted caller has a deadline"); |
| 623 | let call = caller.dispatch(RlmInvocation { |
| 624 | prompt: "context held only by Python".into(), |
| 625 | mode: RlmMode::Recursive { depth_remaining: 0 }, |
| 626 | prompt_policy: RlmPromptPolicy::Session, |
| 627 | max_tokens: None, |
| 628 | task_instructions: None, |
| 629 | deadline: Some(deadline), |
| 630 | gate: Some(crate::tools::codemode::NestedCallGate::admitting_for_test()), |
| 631 | events: Some(tx.clone()), |
| 632 | usage: usage.clone(), |
| 633 | }); |
| 634 | tokio::pin!(call); |
| 635 | tokio::time::timeout_at(deadline, async { |
| 636 | loop { |
| 637 | tokio::select! { |
| 638 | biased; |
| 639 | _ = replies.entered.notified() => break, |
| 640 | result = &mut call => panic!("second provider request was never reached: {:?}", result.error), |
| 641 | event = rx.recv() => assert!(event.is_some()), |
| 642 | } |
| 643 | } |
| 644 | }).await.expect("completed Python round must reach the second actual Core request"); |
| 645 | // Preserve the receiver but stop observing: it can no longer release a |
| 646 | // blocked forwarding send. Cancellation, not its 60-second deadline, |
| 647 | // must now retire the owned provider and Python work. |
| 648 | let _ = tx.try_send(Event::status("occupied caller channel")); |
| 649 | cancel.cancel(); |
| 650 | let result = tokio::time::timeout(Duration::from_secs(1), &mut call) |
| 651 | .await |
| 652 | .expect("original cancellation must interrupt a full observational channel"); |
| 653 | assert!( |
| 654 | tokio::time::Instant::now() < deadline, |
| 655 | "cancellation must finish before the invocation deadline" |
| 656 | ); |
| 657 | assert_eq!(result.iterations, 2); |
| 658 | assert_eq!(result.usage.input_tokens, 7); |
| 659 | assert_eq!(result.usage.output_tokens, 11); |
| 660 | assert_eq!(result.routed_usage.len(), 2); |
| 661 | let revision = result.routed_usage[1] |
| 662 | .settlement |
| 663 | .as_ref() |
| 664 | .expect("cancelled request keeps a settled receipt"); |
| 665 | assert_eq!( |
| 666 | revision.coverage, |
| 667 | crate::llm_client::ProviderUsageCoverage::Missing |
| 668 | ); |
| 669 | assert_eq!( |
| 670 | revision.reason, |
| 671 | Some(crate::cost_status::RuntimeUsageMissingReason::RequestOutcomeUnknown) |
| 672 | ); |
| 673 | assert!(result.routed_usage_drop_records.is_empty()); |
| 674 | assert_eq!( |
| 675 | result |
| 676 | .trace |
| 677 | .first() |
| 678 | .expect("completed round trace") |
| 679 | .stdout_preview |
| 680 | .trim(), |
| 681 | "27", |
| 682 | "the kernel received its context over stdin" |
| 683 | ); |
| 684 | assert_eq!(usage.snapshot().await.dropped_records, 0); |
| 685 | } |
| 686 | |
| 687 | #[tokio::test] |
| 688 | async fn nested_host_never_claims_or_overwrites_parent_posture_revision() { |
| 689 | let workspace = tempfile::tempdir().unwrap(); |
| 690 | let config = fixture_config("captured-model"); |
| 691 | let mock = Arc::new(crate::llm_client::mock::MockLlmClient::new(Vec::new())); |
| 692 | let (mut parent, _handle) = Engine::new_with_model_client( |
| 693 | EngineConfig { |
| 694 | workspace: workspace.path().to_path_buf(), |
| 695 | model: "captured-model".into(), |
| 696 | memory_enabled: false, |
| 697 | snapshots_enabled: false, |
| 698 | subagents_enabled: false, |
| 699 | ..EngineConfig::default() |
| 700 | }, |
| 701 | &config, |
| 702 | mock, |
| 703 | ); |
| 704 | install_fixture_route(&mut parent); |
| 705 | { |
| 706 | let mut state = parent.live_runtime_authority.lock().unwrap(); |
| 707 | state.revision = 17; |
| 708 | state.applied_revision = 8; |
| 709 | } |
| 710 | let context = admitted_context(&parent, "origin-posture-turn"); |
| 711 | let caller = context.rlm_caller.as_ref().unwrap().clone(); |
| 712 | let (nested, _handle) = Engine::new_rlm_admitted( |
| 713 | caller, |
| 714 | RlmInvocation { |
| 715 | prompt: "no provider invocation".into(), |
| 716 | mode: RlmMode::Completion, |
| 717 | prompt_policy: RlmPromptPolicy::Session, |
| 718 | max_tokens: None, |
| 719 | task_instructions: None, |
| 720 | deadline: Some(tokio::time::Instant::now() + Duration::from_secs(60)), |
| 721 | gate: None, |
| 722 | events: None, |
| 723 | usage: RlmUsageAccumulator::new(), |
| 724 | }, |
| 725 | ) |
| 726 | .await |
| 727 | .unwrap(); |
| 728 | assert!(Arc::ptr_eq( |
| 729 | &nested.subagent_manager, |
| 730 | &parent.subagent_manager |
| 731 | )); |
| 732 | assert!(!Arc::ptr_eq( |
| 733 | &nested.live_runtime_authority, |
| 734 | &parent.live_runtime_authority |
| 735 | )); |
| 736 | nested.record_applied_runtime_authority(&TurnAuthority::from_effective_fields( |
| 737 | AppMode::Plan, |
| 738 | false, |
| 739 | false, |
| 740 | false, |
| 741 | ApprovalMode::Never, |
| 742 | )); |
| 743 | let state = parent.live_runtime_authority.lock().unwrap(); |
| 744 | assert_eq!(state.revision, 17); |
| 745 | assert_eq!(state.applied_revision, 8); |
| 746 | assert_eq!(parent.current_mode, AppMode::Agent); |
| 747 | } |
| 748 | |
| 749 | #[tokio::test] |
| 750 | async fn repeated_real_core_preparation_failures_have_bounded_receipts_without_provider_work() { |
| 751 | let workspace = tempfile::tempdir().unwrap(); |
| 752 | let mut config = fixture_config("captured-model"); |
| 753 | let identity = config.active_provider_identity().unwrap(); |
| 754 | config |
| 755 | .provider_config_for_mut(&identity) |
| 756 | .unwrap() |
| 757 | .context_window = Some(1); |
| 758 | let mock = Arc::new(crate::llm_client::mock::MockLlmClient::new(Vec::new())); |
| 759 | let (mut engine, _handle) = Engine::new_with_model_client( |
| 760 | EngineConfig { |
| 761 | workspace: workspace.path().to_path_buf(), |
| 762 | model: "captured-model".into(), |
| 763 | memory_enabled: false, |
| 764 | snapshots_enabled: false, |
| 765 | subagents_enabled: false, |
| 766 | terminal_chrome_enabled: false, |
| 767 | ..EngineConfig::default() |
| 768 | }, |
| 769 | &config, |
| 770 | mock.clone(), |
| 771 | ); |
| 772 | install_fixture_route(&mut engine); |
| 773 | assert_eq!( |
| 774 | engine |
| 775 | .active_route_limits |
| 776 | .and_then(|limits| limits.context_tokens), |
| 777 | Some(1), |
| 778 | "the installed actual Core route carries the fixture's tiny context budget", |
| 779 | ); |
| 780 | let context = admitted_context(&engine, "bounded-failed-turn"); |
| 781 | let caller = context.rlm_caller.as_ref().unwrap(); |
| 782 | let usage = RlmUsageAccumulator::new(); |
| 783 | let invocation = || RlmInvocation { |
| 784 | prompt: "real request preparation must retain this whole input".into(), |
| 785 | mode: RlmMode::Completion, |
| 786 | prompt_policy: RlmPromptPolicy::Session, |
| 787 | max_tokens: None, |
| 788 | task_instructions: None, |
| 789 | deadline: Some(tokio::time::Instant::now() + Duration::from_secs(60)), |
| 790 | gate: None, |
| 791 | events: None, |
| 792 | usage: usage.clone(), |
| 793 | }; |
| 794 | for _ in 0..crate::cost_status::MAX_CHILD_USAGE_RECORDS { |
| 795 | let result = caller.dispatch(invocation()).await; |
| 796 | assert!( |
| 797 | result.error.as_deref().unwrap().contains("history exceeds"), |
| 798 | "{result:?}" |
| 799 | ); |
| 800 | assert_eq!(result.iterations, 0); |
| 801 | } |
| 802 | let before = usage.snapshot().await; |
| 803 | assert_eq!( |
| 804 | before.nested_events.len(), |
| 805 | crate::cost_status::MAX_CHILD_USAGE_RECORDS |
| 806 | ); |
| 807 | assert!(before.records.is_empty()); |
| 808 | assert!(before.drop_records.is_empty()); |
| 809 | assert_eq!(before.dropped_records, 0); |
| 810 | assert_eq!(mock.call_count(), 0); |
| 811 | let refused = caller.dispatch(invocation()).await; |
| 812 | assert!( |
| 813 | refused |
| 814 | .error |
| 815 | .as_deref() |
| 816 | .unwrap() |
| 817 | .contains("nested-turn receipt limit") |
| 818 | ); |
| 819 | let after = usage.snapshot().await; |
| 820 | assert_eq!(after.nested_events, before.nested_events); |
| 821 | assert_eq!(mock.call_count(), 0); |
| 822 | } |
| 823 | |
| 824 | #[tokio::test] |
| 825 | async fn actual_expired_python_startup_is_refused() { |
| 826 | let mock = Arc::new(crate::llm_client::mock::MockLlmClient::new(Vec::new())); |
| 827 | let caller = Arc::new(caller_for(mock.clone(), "captured-model")); |
| 828 | let result = Engine::new_rlm_admitted( |
| 829 | caller, |
| 830 | RlmInvocation { |
| 831 | prompt: "startup fixture".to_string(), |
| 832 | mode: RlmMode::Recursive { depth_remaining: 0 }, |
| 833 | prompt_policy: RlmPromptPolicy::Session, |
| 834 | max_tokens: None, |
| 835 | task_instructions: None, |
| 836 | deadline: Some(tokio::time::Instant::now()), |
| 837 | gate: Some(crate::tools::codemode::NestedCallGate::admitting_for_test()), |
| 838 | events: None, |
| 839 | usage: RlmUsageAccumulator::new(), |
| 840 | }, |
| 841 | ) |
| 842 | .await; |
| 843 | assert!( |
| 844 | result |
| 845 | .err() |
| 846 | .unwrap() |
| 847 | .to_string() |
| 848 | .contains("Python startup failed") |
| 849 | ); |
| 850 | assert_eq!(mock.call_count(), 0); |
| 851 | } |
| 852 | |
| 853 | #[tokio::test] |
| 854 | async fn a_plugin_completion_carries_no_constitution_and_no_plugin_prompt_section() { |
| 855 | let workspace = tempfile::tempdir().unwrap(); |
| 856 | std::fs::write( |
| 857 | workspace.path().join("AGENTS.md"), |
| 858 | "WORKSPACE_INSTRUCTION_SENTINEL\n", |
| 859 | ) |
| 860 | .unwrap(); |
| 861 | let config = fixture_config("captured-model"); |
| 862 | let mock = Arc::new(crate::llm_client::mock::MockLlmClient::new(Vec::new())); |
| 863 | let reply = |text: &str| MessageResponse { |
| 864 | tool_projection_warning: None, |
| 865 | id: "isolated-policy-msg".into(), |
| 866 | r#type: "message".into(), |
| 867 | role: "assistant".into(), |
| 868 | content: vec![ContentBlock::Text { |
| 869 | text: text.to_string(), |
| 870 | cache_control: None, |
| 871 | }], |
| 872 | model: "captured-model".into(), |
| 873 | stop_reason: Some("end_turn".into()), |
| 874 | stop_sequence: None, |
| 875 | container: None, |
| 876 | title: None, |
| 877 | stop_details: None, |
| 878 | refusal: None, |
| 879 | usage: Usage::default(), |
| 880 | }; |
| 881 | mock.push_message_response(reply("session reply")); |
| 882 | mock.push_message_response(reply("plugin reply")); |
| 883 | let (mut engine, _handle) = Engine::new_with_model_client( |
| 884 | EngineConfig { |
| 885 | workspace: workspace.path().to_path_buf(), |
| 886 | model: "captured-model".into(), |
| 887 | snapshots_enabled: false, |
| 888 | memory_enabled: false, |
| 889 | subagents_enabled: false, |
| 890 | terminal_chrome_enabled: false, |
| 891 | turn_wall_clock: Duration::from_secs(60), |
| 892 | ..EngineConfig::default() |
| 893 | }, |
| 894 | &config, |
| 895 | Arc::new(ReplyStream { |
| 896 | replies: mock.clone(), |
| 897 | model: "captured-model".into(), |
| 898 | }), |
| 899 | ); |
| 900 | install_fixture_route(&mut engine); |
| 901 | assert!( |
| 902 | engine |
| 903 | .session |
| 904 | .instruction_assembly |
| 905 | .as_deref() |
| 906 | .and_then(|assembly| assembly.block.as_deref()) |
| 907 | .is_some_and(|block| block.contains("WORKSPACE_INSTRUCTION_SENTINEL")) |
| 908 | ); |
| 909 | engine.extension_prompt_block = Some("OTHER_PLUGIN_PROMPT_SENTINEL".into()); |
| 910 | engine.constitution_block = Some("ACCOUNT_CONSTITUTION_SENTINEL".into()); |
| 911 | let context = admitted_context(&engine, "isolated-plugin-origin-turn"); |
| 912 | let caller = context.rlm_caller.as_ref().unwrap(); |
| 913 | |
| 914 | let session_result = caller |
| 915 | .dispatch(RlmInvocation { |
| 916 | prompt: "SESSION_PROMPT_SENTINEL".into(), |
| 917 | mode: RlmMode::Completion, |
| 918 | prompt_policy: RlmPromptPolicy::Session, |
| 919 | max_tokens: None, |
| 920 | task_instructions: Some("SESSION_TASK_SENTINEL".into()), |
| 921 | deadline: caller.deadline(), |
| 922 | gate: None, |
| 923 | events: None, |
| 924 | usage: RlmUsageAccumulator::new(), |
| 925 | }) |
| 926 | .await; |
| 927 | assert_eq!(session_result.answer, "session reply"); |
| 928 | |
| 929 | let isolated_result = caller |
| 930 | .dispatch(RlmInvocation { |
| 931 | prompt: "PLUGIN_PROMPT_SENTINEL".into(), |
| 932 | mode: RlmMode::Completion, |
| 933 | prompt_policy: RlmPromptPolicy::IsolatedPlugin, |
| 934 | max_tokens: None, |
| 935 | task_instructions: Some("PLUGIN_SYSTEM_SENTINEL".into()), |
| 936 | deadline: caller.deadline(), |
| 937 | gate: None, |
| 938 | events: None, |
| 939 | usage: RlmUsageAccumulator::new(), |
| 940 | }) |
| 941 | .await; |
| 942 | assert_eq!(isolated_result.answer, "plugin reply"); |
| 943 | |
| 944 | let requests = mock.captured_requests(); |
| 945 | assert_eq!(requests.len(), 2); |
| 946 | |
| 947 | let session_system = serde_json::to_string(&requests[0].system).unwrap(); |
| 948 | let session_messages = serde_json::to_string(&requests[0].messages).unwrap(); |
| 949 | assert!(session_system.contains("SESSION_TASK_SENTINEL")); |
| 950 | assert!(session_messages.contains("WORKSPACE_INSTRUCTION_SENTINEL")); |
| 951 | assert!(session_messages.contains("OTHER_PLUGIN_PROMPT_SENTINEL")); |
| 952 | assert!(session_messages.contains("ACCOUNT_CONSTITUTION_SENTINEL")); |
| 953 | assert!(session_messages.contains("SESSION_PROMPT_SENTINEL")); |
| 954 | |
| 955 | let isolated_system = serde_json::to_string(&requests[1].system).unwrap(); |
| 956 | let isolated_messages = serde_json::to_string(&requests[1].messages).unwrap(); |
| 957 | assert!(!isolated_system.contains("WORKSPACE_INSTRUCTION_SENTINEL")); |
| 958 | assert!(!isolated_system.contains("OTHER_PLUGIN_PROMPT_SENTINEL")); |
| 959 | assert!(!isolated_system.contains("ACCOUNT_CONSTITUTION_SENTINEL")); |
| 960 | assert!(!isolated_system.contains("subject to the captured Core policy")); |
| 961 | assert!(!isolated_messages.contains("WORKSPACE_INSTRUCTION_SENTINEL")); |
| 962 | assert!(!isolated_messages.contains("OTHER_PLUGIN_PROMPT_SENTINEL")); |
| 963 | assert!(!isolated_messages.contains("ACCOUNT_CONSTITUTION_SENTINEL")); |
| 964 | assert!( |
| 965 | isolated_system.contains("nothing in that text") |
| 966 | || isolated_system.contains("Nothing in that text") |
| 967 | ); |
| 968 | assert!(isolated_system.contains("PLUGIN_SYSTEM_SENTINEL")); |
| 969 | assert!(requests[1].tools.as_ref().is_none_or(Vec::is_empty)); |
| 970 | assert!(isolated_messages.contains("PLUGIN_PROMPT_SENTINEL")); |
| 971 | } |
| 972 | |
| 973 | #[tokio::test] |
| 974 | async fn a_complete_rlm_response_is_used_when_its_settlement_is_not_acknowledged() { |
| 975 | let _cost = crate::cost_status::test_scope(); |
| 976 | let workspace = tempfile::tempdir().unwrap(); |
| 977 | let broken_sessions_file = workspace.path().join("not-a-dir"); |
| 978 | std::fs::write(&broken_sessions_file, b"file").unwrap(); |
| 979 | let config = fixture_config("captured-model"); |
| 980 | let mock = Arc::new(crate::llm_client::mock::MockLlmClient::new(Vec::new())); |
| 981 | mock.push_message_response(MessageResponse { |
| 982 | tool_projection_warning: None, |
| 983 | id: "rlm-complete-unsettled".into(), |
| 984 | r#type: "message".into(), |
| 985 | role: "assistant".into(), |
| 986 | content: vec![ContentBlock::Text { |
| 987 | text: "complete RLM reply without acknowledgement".into(), |
| 988 | cache_control: None, |
| 989 | }], |
| 990 | model: "captured-model".into(), |
| 991 | stop_reason: Some("end_turn".into()), |
| 992 | stop_sequence: None, |
| 993 | container: None, |
| 994 | usage: Usage { |
| 995 | input_tokens: 19, |
| 996 | output_tokens: 7, |
| 997 | ..Usage::default() |
| 998 | }, |
| 999 | title: None, |
| 1000 | stop_details: None, |
| 1001 | refusal: None, |
| 1002 | }); |
| 1003 | let (mut engine, _handle) = Engine::new_with_model_client( |
| 1004 | EngineConfig { |
| 1005 | workspace: workspace.path().to_path_buf(), |
| 1006 | model: "captured-model".into(), |
| 1007 | snapshots_enabled: false, |
| 1008 | memory_enabled: false, |
| 1009 | subagents_enabled: false, |
| 1010 | terminal_chrome_enabled: false, |
| 1011 | turn_wall_clock: Duration::from_secs(60), |
| 1012 | ..EngineConfig::default() |
| 1013 | }, |
| 1014 | &config, |
| 1015 | Arc::new(ReplyStream { |
| 1016 | replies: mock.clone(), |
| 1017 | model: "captured-model".into(), |
| 1018 | }), |
| 1019 | ); |
| 1020 | install_fixture_route(&mut engine); |
| 1021 | let mut context = admitted_context(&engine, "rlm-unacknowledged-origin"); |
| 1022 | context.accounting_origin = Some(crate::cost_status::NativeUsageOrigin::session( |
| 1023 | crate::cost_status::scope_token(), |
| 1024 | broken_sessions_file, |
| 1025 | "broken-rlm-session".into(), |
| 1026 | )); |
| 1027 | let caller = CapturedRlmCaller::capture( |
| 1028 | &engine, |
| 1029 | &TurnAuthority::from_effective_fields( |
| 1030 | engine.applied_runtime_authority().mode, |
| 1031 | engine.applied_runtime_authority().allow_shell, |
| 1032 | engine.applied_runtime_authority().trust_mode, |
| 1033 | engine.applied_runtime_authority().auto_approve, |
| 1034 | engine.applied_runtime_authority().approval_mode, |
| 1035 | ), |
| 1036 | &TurnRouteContext { |
| 1037 | provider: engine.api_provider, |
| 1038 | model: engine.session.model.clone(), |
| 1039 | capabilities: engine.active_route_capabilities, |
| 1040 | limits: engine.active_route_limits, |
| 1041 | client: engine.codewhale_client.clone(), |
| 1042 | api_config: Box::new(engine.api_config.clone()), |
| 1043 | locale_tag: "en".into(), |
| 1044 | role_models: engine.subagent_role_models(), |
| 1045 | auto_model: false, |
| 1046 | reasoning_effort: None, |
| 1047 | reasoning_effort_auto: false, |
| 1048 | }, |
| 1049 | &context, |
| 1050 | "rlm-unacknowledged-turn", |
| 1051 | ) |
| 1052 | .expect("capture caller"); |
| 1053 | |
| 1054 | let result = caller |
| 1055 | .dispatch(RlmInvocation { |
| 1056 | prompt: "deliver complete reply".into(), |
| 1057 | mode: RlmMode::Completion, |
| 1058 | prompt_policy: RlmPromptPolicy::Session, |
| 1059 | max_tokens: None, |
| 1060 | task_instructions: None, |
| 1061 | deadline: Some(tokio::time::Instant::now() + Duration::from_secs(60)), |
| 1062 | gate: None, |
| 1063 | events: None, |
| 1064 | usage: RlmUsageAccumulator::new(), |
| 1065 | }) |
| 1066 | .await; |
| 1067 | assert!(result.error.is_none(), "{result:?}"); |
| 1068 | assert_eq!(result.answer, "complete RLM reply without acknowledgement"); |
| 1069 | assert_eq!(mock.call_count(), 1); |
| 1070 | } |
| 1071 |