返回 CodeWhale
prompt_zones.rs
根目录 / crates / runtime / src / prompt_zones.rs
1 //! Three-zone prompt contract types for prefix-cache stability (#2264).
2 //!
3 //! Divides every request into three rigid zones:
4 //!
5 //! ```text
6 //! ┌─────────────────────────────────────────┐
7 //! │ PinnedPrefix (frozen after construction) │ ← system prompt + tool catalog
8 //! │ combined_sha256 computed at freeze() │ cache hit candidate
9 //! ├─────────────────────────────────────────┤
10 //! │ AppendLog (append-only) │ ← conversation history
11 //! │ push() only, no insert / remove / edit │ preserves prefix of prior turns
12 //! ├─────────────────────────────────────────┤
13 //! │ TurnScratch (ephemeral) │ ← per-turn metadata
14 //! │ cleared at every turn boundary │ the only new content per request
15 //! └─────────────────────────────────────────┘
16 //! ```
17 //!
18 //! ## Status (Phase 1 foundation)
19 //!
20 //! `PinnedPrefix` / `FrozenPrefix` / `PrefixDrift` are ready for use.
21 //! `AppendLog` / `TurnScratch` / `ThreeZoneRequest` are type scaffolding
22 //! for future phases — not yet wired into the request path.
23
24 #[cfg(test)]
25 use codewhale_models::Role;
26 use codewhale_models::{Message, SystemPrompt, Tool};
27 use std::sync::Arc;
28 // ── helpers ────────────────────────────────────────────────────────────
29
30 fn sha256_hex(bytes: &[u8]) -> String {
31 crate::hashing::sha256_hex(bytes)
32 }
33
34 fn system_text(system: Option<&SystemPrompt>) -> String {
35 match system {
36 Some(SystemPrompt::Text(text)) => text.clone(),
37 Some(SystemPrompt::Blocks(blocks)) => {
38 let mut text = String::new();
39 for block in blocks {
40 text.push_str(&block.text);
41 text.push('\n');
42 }
43 text
44 }
45 None => String::new(),
46 }
47 }
48
49 /// Serialize tools to a deterministic, sorted JSON string for hashing.
50 fn tool_catalog_digest(tools: &[Tool]) -> String {
51 let mut serialized: Vec<String> = tools
52 .iter()
53 .filter_map(|t| serde_json::to_string(t).ok())
54 .collect();
55 serialized.sort();
56 serialized.join("\n")
57 }
58
59 fn combined_hash(system_text: &str, tools: &[Tool]) -> String {
60 let system_sha = sha256_hex(system_text.as_bytes());
61 let tools_digest = tool_catalog_digest(tools);
62 let tools_sha = sha256_hex(tools_digest.as_bytes());
63 let combined = format!("{system_sha}:{tools_sha}");
64 sha256_hex(combined.as_bytes())
65 }
66
67 // ── FrozenPrefix ───────────────────────────────────────────────────────
68
69 /// An immutable frozen prefix — system prompt text + tool catalog,
70 /// hashed at freeze time. The hash is stable as long as the system prompt
71 /// text and full tool definitions (name, description, schema) are unchanged.
72 ///
73 /// Use [`PinnedPrefix::freeze`] to produce one.
74 #[derive(Debug, Clone, PartialEq, Eq)]
75 pub struct FrozenPrefix {
76 pub(crate) system_text: String,
77 pub(crate) tool_catalog: String,
78 pub(crate) combined_sha256: String,
79 }
80
81 impl FrozenPrefix {
82 /// Verify that `current_system_text` and `current_tools` match the frozen
83 /// prefix. Returns `Ok(())` when stable, `Err(PrefixDrift)` on mismatch.
84 ///
85 /// Fast path: compares raw text before falling back to SHA-256.
86 pub fn verify(
87 &self,
88 current_system_text: &str,
89 current_tools: &[Tool],
90 ) -> Result<(), PrefixDrift> {
91 let system_changed = current_system_text != self.system_text;
92 let current_tool_catalog = tool_catalog_digest(current_tools);
93 let tools_changed = current_tool_catalog != self.tool_catalog;
94
95 if !system_changed && !tools_changed {
96 return Ok(());
97 }
98
99 let current_hash = combined_hash(current_system_text, current_tools);
100 Err(PrefixDrift {
101 system_changed,
102 tools_changed,
103 frozen_hash: self.combined_sha256.clone(),
104 current_hash,
105 })
106 }
107
108 /// Returns a short (12-char) human-readable id for display.
109 #[must_use]
110 pub fn short_id(&self) -> &str {
111 if self.combined_sha256.len() >= 12 {
112 &self.combined_sha256[..12]
113 } else {
114 &self.combined_sha256
115 }
116 }
117
118 /// Returns the full combined SHA-256.
119 #[must_use]
120 pub fn hash(&self) -> &str {
121 &self.combined_sha256
122 }
123 }
124
125 // ── PinnedPrefix ───────────────────────────────────────────────────────
126
127 /// A mutable prefix builder. Construct from the system prompt and tool
128 /// catalog, then call [`freeze`](Self::freeze) to produce a [`FrozenPrefix`].
129 #[derive(Debug, Clone)]
130 pub struct PinnedPrefix {
131 system_text: String,
132 tools: Vec<Tool>,
133 }
134
135 impl PinnedPrefix {
136 #[must_use]
137 pub fn new(system: Option<&SystemPrompt>, tools: Vec<Tool>) -> Self {
138 Self {
139 system_text: system_text(system),
140 tools,
141 }
142 }
143
144 /// Freeze this prefix into an immutable [`FrozenPrefix`].
145 #[must_use]
146 pub fn freeze(&self) -> FrozenPrefix {
147 let tool_catalog = tool_catalog_digest(&self.tools);
148 let combined_sha256 = combined_hash(&self.system_text, &self.tools);
149
150 FrozenPrefix {
151 system_text: self.system_text.clone(),
152 tool_catalog,
153 combined_sha256,
154 }
155 }
156 }
157
158 // ── PrefixDrift ────────────────────────────────────────────────────────
159
160 /// Describes how the current prefix differs from the frozen baseline.
161 #[derive(Debug, Clone, PartialEq, Eq)]
162 pub struct PrefixDrift {
163 pub system_changed: bool,
164 pub tools_changed: bool,
165 pub frozen_hash: String,
166 pub current_hash: String,
167 }
168
169 impl std::fmt::Display for PrefixDrift {
170 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
171 let cause = match (self.system_changed, self.tools_changed) {
172 (true, true) => "system prompt and tool set",
173 (true, false) => "system prompt",
174 (false, true) => "tool set",
175 (false, false) => "unknown component",
176 };
177 write!(
178 f,
179 "prefix drift: {cause} changed (frozen={}, current={})",
180 &self.frozen_hash[..12.min(self.frozen_hash.len())],
181 &self.current_hash[..12.min(self.current_hash.len())]
182 )
183 }
184 }
185
186 // ── AppendLog ──────────────────────────────────────────────────────────
187
188 /// Append-only conversation history. Derefs to `&[Message]` via
189 /// [`Deref`](std::ops::Deref) for transparent read access; mutations go
190 /// through explicit methods (`push`, `truncate_to`, `trim_front`, `clear`)
191 /// whose names make cache impact obvious.
192 ///
193 /// Phase 4: backing store for `Session.messages` (#2264).
194 ///
195 /// The history is reference-counted (#6214 T2): snapshots hand out `Arc`
196 /// clones instead of deep-copying the transcript per event, and mutations
197 /// copy-on-write only while a snapshot is outstanding.
198 #[derive(Debug, Clone)]
199 pub struct AppendLog {
200 messages: Arc<Vec<Message>>,
201 }
202
203 impl AppendLog {
204 pub fn new() -> Self {
205 Self {
206 messages: Arc::new(Vec::new()),
207 }
208 }
209
210 pub fn from_messages(messages: Vec<Message>) -> Self {
211 Self {
212 messages: Arc::new(messages),
213 }
214 }
215
216 /// Share the current history without copying. The engine hands this to
217 /// `Event::SessionUpdated`; the `Arc` is immutable, so an outstanding
218 /// snapshot can never observe a later mutation.
219 #[must_use]
220 pub fn snapshot(&self) -> Arc<Vec<Message>> {
221 Arc::clone(&self.messages)
222 }
223
224 /// Append a message to the log. A single-message push is the cheapest
225 /// mutation for prefix-cache stability — it extends the byte sequence
226 /// without disturbing earlier turns.
227 pub fn push(&mut self, message: Message) {
228 Arc::make_mut(&mut self.messages).push(message);
229 }
230
231 /// Append multiple messages in one operation (fewer cache-line
232 /// invalidations than repeated `push`).
233 pub fn push_batch(&mut self, batch: Vec<Message>) {
234 Arc::make_mut(&mut self.messages).extend(batch);
235 }
236
237 /// Truncate to keep only the first `new_len` messages.
238 /// Discards newer messages (and their prefix-cache contribution)
239 /// from the tail.
240 pub fn truncate_to(&mut self, new_len: usize) {
241 Arc::make_mut(&mut self.messages).truncate(new_len);
242 }
243
244 /// Remove `count` messages from the front (oldest first).
245 /// Cache-destroying: drops the prefix that earlier turns share.
246 pub fn trim_front(&mut self, count: usize) {
247 let messages = Arc::make_mut(&mut self.messages);
248 if count >= messages.len() {
249 messages.clear();
250 } else {
251 messages.drain(0..count);
252 }
253 }
254
255 /// Remove all messages. Resets cache state completely.
256 pub fn clear(&mut self) {
257 Arc::make_mut(&mut self.messages).clear();
258 }
259
260 /// Return a mutable reference to the last message, if any.
261 /// Prefer this over `last_mut()` on the inner vec — the name signals
262 /// that only the most recent turn's content is being modified.
263 #[must_use]
264 pub fn last_mut(&mut self) -> Option<&mut Message> {
265 Arc::make_mut(&mut self.messages).last_mut()
266 }
267
268 /// Consume and return the inner `Vec<Message>`, copying only if a
269 /// snapshot still shares it.
270 #[must_use]
271 pub fn into_inner(self) -> Vec<Message> {
272 Arc::try_unwrap(self.messages).unwrap_or_else(|shared| (*shared).clone())
273 }
274 }
275
276 impl Default for AppendLog {
277 fn default() -> Self {
278 Self::new()
279 }
280 }
281
282 impl From<Vec<Message>> for AppendLog {
283 fn from(messages: Vec<Message>) -> Self {
284 Self {
285 messages: Arc::new(messages),
286 }
287 }
288 }
289
290 impl From<AppendLog> for Vec<Message> {
291 fn from(log: AppendLog) -> Self {
292 log.into_inner()
293 }
294 }
295
296 impl std::ops::Deref for AppendLog {
297 type Target = Vec<Message>;
298
299 fn deref(&self) -> &Self::Target {
300 &self.messages
301 }
302 }
303
304 // ── TurnScratch ────────────────────────────────────────────────────────
305
306 /// Per-turn ephemeral data. Cleared at every turn boundary.
307 ///
308 /// **Phase 1 scaffolding** — not yet wired into the engine request path.
309 #[cfg(test)]
310 #[derive(Debug, Clone, Default)]
311 pub struct TurnScratch {
312 pub working_set: Vec<String>,
313 pub user_message: Option<Message>,
314 }
315
316 #[cfg(test)]
317 impl TurnScratch {
318 pub fn new() -> Self {
319 Self::default()
320 }
321
322 pub fn clear(&mut self) {
323 self.working_set.clear();
324 self.user_message = None;
325 }
326
327 #[must_use]
328 pub fn is_empty(&self) -> bool {
329 self.working_set.is_empty() && self.user_message.is_none()
330 }
331 }
332
333 // ── ThreeZoneRequest ───────────────────────────────────────────────────
334
335 /// A composed three-zone request ready for DeepSeek API serialization.
336 ///
337 /// **Phase 1 scaffolding** — not yet wired into the engine request path.
338 /// Currently the engine continues to use `MessageRequest` directly.
339 #[cfg(test)]
340 #[derive(Debug, Clone)]
341 pub struct ThreeZoneRequest<'a> {
342 pub prefix: &'a FrozenPrefix,
343 pub log: &'a AppendLog,
344 pub scratch: TurnScratch,
345 pub model: String,
346 pub max_tokens: u32,
347 pub system: Option<SystemPrompt>,
348 pub tools: Option<Vec<Tool>>,
349 pub tool_choice: Option<serde_json::Value>,
350 pub reasoning_effort: Option<String>,
351 pub thinking: Option<serde_json::Value>,
352 pub stream: Option<bool>,
353 pub temperature: Option<f32>,
354 pub top_p: Option<f32>,
355 pub metadata: Option<serde_json::Value>,
356 }
357
358 #[cfg(test)]
359 impl<'a> ThreeZoneRequest<'a> {
360 /// Build the full message list from system prompt, append-log messages,
361 /// and scratch user message. The returned vector is serialized as the
362 /// `messages` field in the DeepSeek chat-completion request.
363 #[must_use]
364 pub fn build_messages(&self) -> Vec<Message> {
365 let mut messages = Vec::with_capacity(self.message_count());
366
367 match self.system.as_ref() {
368 Some(SystemPrompt::Text(text)) => {
369 messages.push(Message {
370 role: Role::System,
371 content: vec![codewhale_models::ContentBlock::Text {
372 text: text.clone(),
373 cache_control: None,
374 }],
375 });
376 }
377 Some(SystemPrompt::Blocks(blocks)) => {
378 let content: Vec<codewhale_models::ContentBlock> = blocks
379 .iter()
380 .map(|block| codewhale_models::ContentBlock::Text {
381 text: block.text.clone(),
382 cache_control: block.cache_control.clone(),
383 })
384 .collect();
385 messages.push(Message {
386 role: Role::System,
387 content,
388 });
389 }
390 None => {}
391 }
392
393 for msg in self.log.iter() {
394 messages.push(msg.clone());
395 }
396
397 if let Some(ref user_msg) = self.scratch.user_message {
398 messages.push(user_msg.clone());
399 }
400
401 messages
402 }
403
404 #[must_use]
405 pub fn message_count(&self) -> usize {
406 let system_count = if self.system.is_some() { 1 } else { 0 };
407 let scratch_count = if self.scratch.user_message.is_some() {
408 1
409 } else {
410 0
411 };
412 system_count + self.log.len() + scratch_count
413 }
414 }
415
416 // ── tests ──────────────────────────────────────────────────────────────
417
418 #[cfg(test)]
419 mod tests {
420 use super::*;
421 use codewhale_models::ContentBlock;
422
423 fn make_tool(name: &str) -> Tool {
424 Tool {
425 name: name.to_string(),
426 description: String::new(),
427 input_schema: serde_json::Value::Null,
428 tool_type: None,
429 allowed_callers: None,
430 defer_loading: None,
431 input_examples: None,
432 strict: None,
433 cache_control: None,
434 }
435 }
436
437 fn make_message(role: &str, text: &str) -> Message {
438 Message {
439 role: Role::from(role),
440 content: vec![ContentBlock::Text {
441 text: text.to_string(),
442 cache_control: None,
443 }],
444 }
445 }
446
447 // ── AppendLog ────────────────────────────────────────────────
448
449 #[test]
450 fn append_log_snapshot_shares_and_mutation_detaches() {
451 let mut log = AppendLog::new();
452 log.push(make_message("user", "hello"));
453 let shared = log.snapshot();
454 // No copy: the snapshot aliases the live log.
455 assert!(Arc::ptr_eq(&shared, &log.snapshot()));
456 log.push(make_message("assistant", "hi"));
457 // Copy-on-write: the outstanding snapshot still sees one message.
458 assert_eq!(shared.len(), 1);
459 assert_eq!(log.len(), 2);
460 }
461
462 // ── FrozenPrefix / PinnedPrefix ────────────────────────────────
463
464 #[test]
465 fn freeze_produces_stable_hash() {
466 let tools = vec![make_tool("read"), make_tool("write")];
467 let sys = SystemPrompt::Text("hello world".to_string());
468
469 let a = PinnedPrefix::new(Some(&sys), tools.clone()).freeze();
470 let b = PinnedPrefix::new(Some(&sys), tools).freeze();
471
472 assert_eq!(a.combined_sha256, b.combined_sha256);
473 assert_eq!(a.hash(), b.hash());
474 assert_eq!(a.short_id(), b.short_id());
475 }
476
477 #[test]
478 fn freeze_tool_order_is_stable() {
479 let sys = SystemPrompt::Text("system".to_string());
480 let tools_a = vec![make_tool("b"), make_tool("a")];
481 let tools_b = vec![make_tool("a"), make_tool("b")];
482
483 let a = PinnedPrefix::new(Some(&sys), tools_a).freeze();
484 let b = PinnedPrefix::new(Some(&sys), tools_b).freeze();
485
486 assert_eq!(a.combined_sha256, b.combined_sha256);
487 }
488
489 #[test]
490 fn freeze_empty_tools() {
491 let sys = SystemPrompt::Text("system".to_string());
492 let frozen = PinnedPrefix::new(Some(&sys), vec![]).freeze();
493 assert!(frozen.tool_catalog.is_empty());
494 assert!(!frozen.combined_sha256.is_empty());
495 assert_eq!(frozen.short_id().len(), 12);
496 }
497
498 #[test]
499 fn freeze_no_system() {
500 let tools = vec![make_tool("t1")];
501 let frozen = PinnedPrefix::new(None, tools).freeze();
502 assert!(frozen.system_text.is_empty());
503 assert!(frozen.tool_catalog.contains("t1"));
504 }
505
506 #[test]
507 fn verify_passes_when_stable() {
508 let sys = SystemPrompt::Text("system".to_string());
509 let tools = vec![make_tool("a")];
510 let frozen = PinnedPrefix::new(Some(&sys), tools.clone()).freeze();
511
512 assert!(frozen.verify("system", &tools).is_ok());
513 }
514
515 #[test]
516 fn verify_detects_system_change() {
517 let sys = SystemPrompt::Text("old".to_string());
518 let tools = vec![make_tool("a")];
519 let frozen = PinnedPrefix::new(Some(&sys), tools.clone()).freeze();
520
521 let drift = frozen.verify("new", &tools).unwrap_err();
522 assert!(drift.system_changed);
523 assert!(!drift.tools_changed);
524 }
525
526 #[test]
527 fn verify_detects_tool_change() {
528 let sys = SystemPrompt::Text("system".to_string());
529 let tools_a = vec![make_tool("a")];
530 let frozen = PinnedPrefix::new(Some(&sys), tools_a).freeze();
531
532 let tools_b = vec![make_tool("b")];
533 let drift = frozen.verify("system", &tools_b).unwrap_err();
534 assert!(!drift.system_changed);
535 assert!(drift.tools_changed);
536 }
537
538 #[test]
539 fn verify_detects_both_changes() {
540 let sys = SystemPrompt::Text("old".to_string());
541 let tools = vec![make_tool("a")];
542 let frozen = PinnedPrefix::new(Some(&sys), tools).freeze();
543
544 let drift = frozen.verify("new", &[make_tool("b")]).unwrap_err();
545 assert!(drift.system_changed);
546 assert!(drift.tools_changed);
547 }
548
549 #[test]
550 fn verify_detects_schema_change() {
551 let sys = SystemPrompt::Text("system".to_string());
552 let tool_a = make_tool("a");
553 let mut tool_a_v2 = make_tool("a");
554 tool_a_v2.description = "updated desc".to_string();
555
556 let frozen = PinnedPrefix::new(Some(&sys), vec![tool_a]).freeze();
557 let drift = frozen.verify("system", &[tool_a_v2]).unwrap_err();
558 // Same name, different schema — should detect the change.
559 assert!(drift.tools_changed);
560 }
561
562 #[test]
563 fn prefix_drift_display_is_readable() {
564 let drift = PrefixDrift {
565 system_changed: true,
566 tools_changed: false,
567 frozen_hash: "a".repeat(64),
568 current_hash: "b".repeat(64),
569 };
570 let display = drift.to_string();
571 assert!(display.contains("system prompt"));
572 assert!(display.contains("aaaaaaaaaaaa"));
573 assert!(display.contains("bbbbbbbbbbbb"));
574 }
575
576 // ── AppendLog ─────────────────────────────────────────────────
577
578 #[test]
579 fn append_log_push_and_iter() {
580 let mut log = AppendLog::new();
581 assert!(log.is_empty());
582
583 log.push(make_message("user", "hello"));
584 log.push(make_message("assistant", "hi"));
585
586 assert_eq!(log.len(), 2);
587 assert!(!log.is_empty());
588
589 let messages: Vec<_> = log.iter().collect();
590 assert_eq!(messages.len(), 2);
591 }
592
593 #[test]
594 fn append_log_from_messages() {
595 let msgs = vec![make_message("user", "a"), make_message("assistant", "b")];
596 let log = AppendLog::from_messages(msgs);
597 assert_eq!(log.len(), 2);
598 assert_eq!(log.as_slice().len(), 2);
599 }
600
601 // ── TurnScratch ───────────────────────────────────────────────
602
603 #[test]
604 fn scratch_clear_empties_all_fields() {
605 let mut scratch = TurnScratch::new();
606 scratch.working_set.push("file.rs".to_string());
607 scratch.user_message = Some(make_message("user", "task"));
608
609 assert!(!scratch.is_empty());
610 scratch.clear();
611 assert!(scratch.is_empty());
612 assert!(scratch.working_set.is_empty());
613 assert!(scratch.user_message.is_none());
614 }
615
616 // ── ThreeZoneRequest ──────────────────────────────────────────
617
618 #[test]
619 fn build_messages_concatenates_zones() {
620 let sys = SystemPrompt::Text("you are helpful".to_string());
621 let tools = vec![make_tool("read")];
622 let prefix = PinnedPrefix::new(Some(&sys), tools).freeze();
623
624 let mut log = AppendLog::new();
625 log.push(make_message("user", "prev question"));
626 log.push(make_message("assistant", "prev answer"));
627
628 let scratch = TurnScratch {
629 working_set: vec!["main.rs".to_string()],
630 user_message: Some(make_message("user", "current task")),
631 };
632
633 let request = ThreeZoneRequest {
634 prefix: &prefix,
635 log: &log,
636 scratch,
637 model: "deepseek-v4-pro".to_string(),
638 max_tokens: 4096,
639 system: Some(sys),
640 tools: None,
641 tool_choice: None,
642 reasoning_effort: None,
643 thinking: None,
644 stream: None,
645 temperature: None,
646 top_p: None,
647 metadata: None,
648 };
649
650 let messages = request.build_messages();
651 assert_eq!(messages.len(), 4);
652 assert_eq!(messages[0].role, "system");
653 assert_eq!(messages[1].role, "user");
654 assert_eq!(messages[2].role, "assistant");
655 assert_eq!(messages[3].role, "user");
656 assert_eq!(request.message_count(), 4);
657 }
658
659 #[test]
660 fn build_messages_no_system_no_scratch() {
661 let prefix = PinnedPrefix::new(None, vec![]).freeze();
662
663 let mut log = AppendLog::new();
664 log.push(make_message("user", "hi"));
665
666 let request = ThreeZoneRequest {
667 prefix: &prefix,
668 log: &log,
669 scratch: TurnScratch::new(),
670 model: "x".to_string(),
671 max_tokens: 1,
672 system: None,
673 tools: None,
674 tool_choice: None,
675 reasoning_effort: None,
676 thinking: None,
677 stream: None,
678 temperature: None,
679 top_p: None,
680 metadata: None,
681 };
682
683 let messages = request.build_messages();
684 assert_eq!(messages.len(), 1);
685 assert_eq!(request.message_count(), 1);
686 }
687
688 #[test]
689 fn blocks_system_prompt_preserves_cache_control() {
690 use codewhale_models::{CacheControl, SystemBlock};
691 let cc = Some(CacheControl {
692 cache_type: "ephemeral".to_string(),
693 });
694 let blocks = SystemPrompt::Blocks(vec![SystemBlock {
695 block_type: "text".to_string(),
696 text: "hello".to_string(),
697 cache_control: cc.clone(),
698 }]);
699
700 let prefix = PinnedPrefix::new(Some(&blocks), vec![]).freeze();
701 let log = AppendLog::new();
702 let scratch = TurnScratch::new();
703 let request = ThreeZoneRequest {
704 prefix: &prefix,
705 log: &log,
706 scratch,
707 model: "x".to_string(),
708 max_tokens: 1,
709 system: Some(blocks),
710 tools: None,
711 tool_choice: None,
712 reasoning_effort: None,
713 thinking: None,
714 stream: None,
715 temperature: None,
716 top_p: None,
717 metadata: None,
718 };
719
720 let messages = request.build_messages();
721 assert_eq!(messages.len(), 1);
722 assert_eq!(messages[0].role, "system");
723 // cache_control should be preserved on the block.
724 if let ContentBlock::Text {
725 cache_control: actual_cc,
726 ..
727 } = &messages[0].content[0]
728 {
729 assert_eq!(
730 actual_cc.as_ref().map(|c| c.cache_type.as_str()),
731 Some("ephemeral")
732 );
733 } else {
734 panic!("expected Text content block");
735 }
736 }
737 }
738
738 lines RUST