Skip to content

Commit b5d7899

Browse files
committed
🧪 Liberate the tests from their inline prison
At last, the tests have been FREED from their cramped quarters in history.rs and reducer.rs! They now reside in their own glorious src/studio/tests/ kingdom where they can BREATHE and MULTIPLY. No longer shall implementation code and test code share the same file like some kind of CHAOS ZONE. Order has been restored! But wait - there's MORE! I have exposed max_events as pub(crate) so we can VERIFY the history trimming actually works. Trust no one. Test EVERYTHING. Added comprehensive reducer tests because EVERY. SINGLE. PATH. must be covered: agent results, message navigation, edit modes, error handling - NONE SHALL ESCAPE MY VALIDATION!
1 parent 82ad0ac commit b5d7899

File tree

6 files changed

+338
-153
lines changed

6 files changed

+338
-153
lines changed

src/studio/history.rs

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct History {
9393
events: VecDeque<HistoryEntry>,
9494

9595
/// Maximum events to retain (prevents unbounded growth)
96-
max_events: usize,
96+
pub(crate) max_events: usize,
9797

9898
/// Chat messages (persists across modes)
9999
chat_messages: Vec<ChatMessage>,
@@ -577,85 +577,3 @@ pub struct ModeContext {
577577
/// Related content (e.g., commit message being discussed)
578578
pub related_content: Option<String>,
579579
}
580-
581-
// ═══════════════════════════════════════════════════════════════════════════════
582-
// Tests
583-
// ═══════════════════════════════════════════════════════════════════════════════
584-
585-
#[cfg(test)]
586-
mod tests {
587-
use super::*;
588-
589-
#[test]
590-
fn test_new_history() {
591-
let history = History::new();
592-
assert_eq!(history.event_count(), 0);
593-
assert_eq!(history.chat_messages().len(), 0);
594-
}
595-
596-
#[test]
597-
fn test_add_chat_message() {
598-
let mut history = History::new();
599-
600-
history.add_chat_message(ChatRole::User, "Hello, Iris!".to_string());
601-
history.add_chat_message(ChatRole::Iris, "Hello! How can I help?".to_string());
602-
603-
assert_eq!(history.chat_messages().len(), 2);
604-
assert_eq!(history.chat_messages()[0].role, ChatRole::User);
605-
assert_eq!(history.chat_messages()[1].role, ChatRole::Iris);
606-
}
607-
608-
#[test]
609-
fn test_record_content() {
610-
let mut history = History::new();
611-
612-
let msg = GeneratedMessage {
613-
emoji: Some("✨".to_string()),
614-
title: "Add new feature".to_string(),
615-
message: "Implement the thing".to_string(),
616-
};
617-
618-
history.record_content(
619-
Mode::Commit,
620-
ContentType::CommitMessage,
621-
&ContentData::Commit(msg),
622-
EventSource::Agent,
623-
"initial_generation",
624-
);
625-
626-
assert_eq!(
627-
history.content_version_count(Mode::Commit, ContentType::CommitMessage),
628-
1
629-
);
630-
assert!(
631-
history
632-
.latest_content(Mode::Commit, ContentType::CommitMessage)
633-
.is_some()
634-
);
635-
}
636-
637-
#[test]
638-
fn test_content_preview() {
639-
let msg = GeneratedMessage {
640-
emoji: Some("🔧".to_string()),
641-
title: "Fix the bug".to_string(),
642-
message: "Details here".to_string(),
643-
};
644-
645-
let data = ContentData::Commit(msg);
646-
assert!(data.preview(50).starts_with("🔧 Fix"));
647-
}
648-
649-
#[test]
650-
fn test_history_trimming() {
651-
let mut history = History::new();
652-
history.max_events = 10;
653-
654-
for i in 0..20 {
655-
history.add_chat_message(ChatRole::User, format!("Message {}", i));
656-
}
657-
658-
// Events should be trimmed, but chat messages aren't (different storage)
659-
assert!(history.event_count() <= 10);
660-
}
661-
}

src/studio/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ mod theme;
2828
// Submodules
2929
pub mod components;
3030

31+
#[cfg(test)]
32+
mod tests;
33+
3134
// Re-exports
3235
pub use app::{ExitResult, StudioApp, run_studio};
3336
pub use state::{Mode, StudioState};

src/studio/reducer.rs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,73 +1006,3 @@ fn reduce_mouse_event(
10061006

10071007
effects
10081008
}
1009-
1010-
// ═══════════════════════════════════════════════════════════════════════════════
1011-
// Tests
1012-
// ═══════════════════════════════════════════════════════════════════════════════
1013-
1014-
#[cfg(test)]
1015-
mod tests {
1016-
use super::*;
1017-
use crate::config::Config;
1018-
1019-
fn test_state() -> StudioState {
1020-
StudioState::new(Config::default(), None)
1021-
}
1022-
1023-
#[test]
1024-
fn test_mode_switch() {
1025-
let mut state = test_state();
1026-
let mut history = History::new();
1027-
1028-
let effects = reduce(
1029-
&mut state,
1030-
StudioEvent::SwitchMode(Mode::Commit),
1031-
&mut history,
1032-
);
1033-
1034-
assert_eq!(state.active_mode, Mode::Commit);
1035-
assert!(!effects.is_empty()); // Should have LoadData effect
1036-
}
1037-
1038-
#[test]
1039-
fn test_focus_panel() {
1040-
let mut state = test_state();
1041-
let mut history = History::new();
1042-
1043-
let _ = reduce(
1044-
&mut state,
1045-
StudioEvent::FocusPanel(PanelId::Right),
1046-
&mut history,
1047-
);
1048-
1049-
assert_eq!(state.focused_panel, PanelId::Right);
1050-
}
1051-
1052-
#[test]
1053-
fn test_notify() {
1054-
let mut state = test_state();
1055-
let mut history = History::new();
1056-
1057-
let _ = reduce(
1058-
&mut state,
1059-
StudioEvent::Notify {
1060-
level: NotificationLevel::Success,
1061-
message: "Test notification".to_string(),
1062-
},
1063-
&mut history,
1064-
);
1065-
1066-
assert!(!state.notifications.is_empty());
1067-
}
1068-
1069-
#[test]
1070-
fn test_quit_produces_effect() {
1071-
let mut state = test_state();
1072-
let mut history = History::new();
1073-
1074-
let effects = reduce(&mut state, StudioEvent::Quit, &mut history);
1075-
1076-
assert!(effects.iter().any(|e| matches!(e, SideEffect::Quit)));
1077-
}
1078-
}

src/studio/tests/history_tests.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//! Tests for the History system
2+
3+
use crate::studio::events::{ContentType, EventSource};
4+
use crate::studio::history::{ChatRole, ContentData, History};
5+
use crate::studio::state::Mode;
6+
use crate::types::GeneratedMessage;
7+
8+
#[test]
9+
fn test_new_history() {
10+
let history = History::new();
11+
assert_eq!(history.event_count(), 0);
12+
assert_eq!(history.chat_messages().len(), 0);
13+
}
14+
15+
#[test]
16+
fn test_add_chat_message() {
17+
let mut history = History::new();
18+
19+
history.add_chat_message(ChatRole::User, "Hello, Iris!".to_string());
20+
history.add_chat_message(ChatRole::Iris, "Hello! How can I help?".to_string());
21+
22+
assert_eq!(history.chat_messages().len(), 2);
23+
assert_eq!(history.chat_messages()[0].role, ChatRole::User);
24+
assert_eq!(history.chat_messages()[1].role, ChatRole::Iris);
25+
}
26+
27+
#[test]
28+
fn test_record_content() {
29+
let mut history = History::new();
30+
31+
let msg = GeneratedMessage {
32+
emoji: Some("✨".to_string()),
33+
title: "Add new feature".to_string(),
34+
message: "Implement the thing".to_string(),
35+
};
36+
37+
history.record_content(
38+
Mode::Commit,
39+
ContentType::CommitMessage,
40+
&ContentData::Commit(msg),
41+
EventSource::Agent,
42+
"initial_generation",
43+
);
44+
45+
assert_eq!(
46+
history.content_version_count(Mode::Commit, ContentType::CommitMessage),
47+
1
48+
);
49+
assert!(
50+
history
51+
.latest_content(Mode::Commit, ContentType::CommitMessage)
52+
.is_some()
53+
);
54+
}
55+
56+
#[test]
57+
fn test_content_preview() {
58+
let msg = GeneratedMessage {
59+
emoji: Some("🔧".to_string()),
60+
title: "Fix the bug".to_string(),
61+
message: "Details here".to_string(),
62+
};
63+
64+
let data = ContentData::Commit(msg);
65+
assert!(data.preview(50).starts_with("🔧 Fix"));
66+
}
67+
68+
#[test]
69+
fn test_history_trimming() {
70+
let mut history = History::new();
71+
history.max_events = 10;
72+
73+
for i in 0..20 {
74+
history.add_chat_message(ChatRole::User, format!("Message {}", i));
75+
}
76+
77+
// Events should be trimmed, but chat messages aren't (different storage)
78+
assert!(history.event_count() <= 10);
79+
}

src/studio/tests/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Tests for Iris Studio
2+
3+
mod history_tests;
4+
mod reducer_tests;

0 commit comments

Comments
 (0)