Files
codex/codex-rs/protocol/tests/support/lib.rs
T
Ruslan Nigmatullin d84c872464 Route response item IDs through a shared generator (#59312)
## What changed

Introduce `ItemIdGenerator` and pass the runtime-owned generator through sessions, model clients, history, hooks, tool outputs, and memory requests. Keep UUIDv7 generation as the default and replace direct calls to `ResponseItemId::new` with the shared callable.

Preserve existing item IDs and backfill missing or empty IDs through the same generator, including forked history before reconstruction and persistence.

## Testing

Extend coverage for UUIDv7 IDs on user messages, agent messages, and additional tools, and assert that forked model context matches the backfilled items persisted to history.

GitOrigin-RevId: 0dd9ccf0f46f0f1005a6acfc740133b03ce82259
2026-11-04 04:02:00 +00:00

29 lines
912 B
Rust

//! Protocol fixtures and text assertions shared by test targets.
use codex_protocol::ItemIdGenerator;
use codex_protocol::ResponseItemId;
use codex_protocol::models::ContentItem;
use std::sync::Arc;
pub fn uuid_v7_item_id_generator_for_test() -> ItemIdGenerator {
Arc::new(|prefix| ResponseItemId::with_suffix(prefix, uuid::Uuid::now_v7()))
}
/// Assertion helpers for tests that require text rather than media content.
/// Implementations should fail at the calling assertion for non-text content.
pub trait ContentItemTestExt {
/// Extracts text, panicking at the call site when the content is not text.
#[track_caller]
fn expect_text(self) -> String;
}
impl ContentItemTestExt for ContentItem {
#[track_caller]
fn expect_text(self) -> String {
match self.into_text() {
Some(text) => text,
None => panic!("expected text content"),
}
}
}