Files
codex/codex-rs/tui/src/workspace_messages_tests.rs
T
Joe Savona 641e2e362c Ignore stale workspace headline requests and archived messages (#61411)
## Why

Workspace headline request counters restart when the chat widget is replaced, allowing a response for the previous widget to match a new pending request. Archived headlines can also be selected for the status line.

## What changed

- Use UUIDs for workspace headline requests and reject refresh events and responses that do not match the current widget's pending request.
- Skip archived messages when selecting the first non-empty workspace headline.

## Testing

Add a regression test verifying that a replacement widget rejects the previous widget's response while retaining its own pending request. Extend headline selection coverage to include an archived headline before the active one.

GitOrigin-RevId: 44b98ab8c6cb70b7cf8e8b9341f27c99c1e1490a
2026-11-14 00:08:20 +00:00

59 lines
2.0 KiB
Rust

use super::*;
use codex_app_server_protocol::WorkspaceMessage;
use pretty_assertions::assert_eq;
#[test]
fn workspace_headline_from_response_uses_first_non_empty_headline() {
let response = GetWorkspaceMessagesResponse {
feature_enabled: true,
messages: vec![
WorkspaceMessage {
message_id: "archived-headline".to_string(),
message_type: WorkspaceMessageType::Headline,
message_body: "Previous announcement".to_string(),
created_at: None,
archived_at: Some(1_700_000_000),
},
WorkspaceMessage {
message_id: "announcement-id".to_string(),
message_type: WorkspaceMessageType::Announcement,
message_body: "Announcement body".to_string(),
created_at: None,
archived_at: None,
},
WorkspaceMessage {
message_id: "empty-headline-id".to_string(),
message_type: WorkspaceMessageType::Headline,
message_body: " ".to_string(),
created_at: None,
archived_at: None,
},
WorkspaceMessage {
message_id: "headline-id".to_string(),
message_type: WorkspaceMessageType::Headline,
message_body: " Workspace headline ".to_string(),
created_at: None,
archived_at: None,
},
],
};
assert_eq!(
workspace_headline_from_response(response),
WorkspaceHeadlineFetchResult::Available(Some("Workspace headline".to_string()))
);
}
#[test]
fn workspace_headline_from_response_reports_feature_disabled() {
let response = GetWorkspaceMessagesResponse {
feature_enabled: false,
messages: Vec::new(),
};
assert_eq!(
workspace_headline_from_response(response),
WorkspaceHeadlineFetchResult::FeatureDisabled
);
}