Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,13 @@ voice_input = ["dep:voice_input"]
system_theme = []
tab_close_button_on_left = []
team_features_override = []
test-util = ["cloud_object_client/test-util", "warp_server_auth/test-util"]
test-util = [
"cloud_object_client/test-util",
"warp_server_auth/test-util",
"http_client/test-util",
"warp_core/test-util",
"ai/test-util",
]
team_workflows = ["team_features_override"]
terminal_lifecycle_recovery = []
toggle_bootstrap_block = []
Expand Down
2 changes: 1 addition & 1 deletion app/src/ai/document/ai_document_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl AIDocumentModel {
}
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn new_for_test() -> Self {
let (save_tx, _save_rx) = async_channel::unbounded();
Self {
Expand Down
2 changes: 1 addition & 1 deletion app/src/auth/auth_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl AuthManager {
}
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn new_for_test(ctx: &mut ModelContext<Self>) -> Self {
use crate::server::server_api::ServerApiProvider;

Expand Down
2 changes: 1 addition & 1 deletion app/src/cloud_object/model/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ impl CloudModel {
.collect::<HashMap<_, _>>()
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn mock(_ctx: &mut ModelContext<Self>) -> Self {
Self::new(None, Vec::new(), None)
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ mod tracing;
mod tui;
#[cfg(feature = "tui")]
pub mod tui_export;
#[cfg(all(feature = "tui", any(test, feature = "test-util")))]
mod tui_test_support;
mod ui_components;
mod undo_close;
mod uri;
Expand Down Expand Up @@ -648,7 +650,7 @@ impl LaunchMode {
}
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub(crate) fn new_for_unit_test() -> Self {
LaunchMode::Test {
driver: Box::new(None),
Expand Down
4 changes: 2 additions & 2 deletions app/src/server/server_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl ServerApi {
}
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
fn new_for_test() -> Self {
let (tx, _) = async_channel::unbounded();
let auth_state = Arc::new(AuthState::new_for_test());
Expand Down Expand Up @@ -1287,7 +1287,7 @@ impl ServerApiProvider {
}

/// Constructs a new SeverApiProvider for tests.
#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn new_for_test() -> Self {
let server_api = Arc::new(ServerApi::new_for_test());
let auth_client = Arc::new(AuthClientImpl::new(server_api.base_client.clone()));
Expand Down
2 changes: 1 addition & 1 deletion app/src/server/sync_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub struct SyncQueue {
}

impl SyncQueue {
#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn mock(ctx: &mut ModelContext<Self>) -> Self {
use super::server_api::ServerApiProvider;

Expand Down
9 changes: 6 additions & 3 deletions app/src/settings/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,14 @@ fn migrate_native_settings_to_settings_file(ctx: &mut AppContext) {
.map_err(|err| anyhow::anyhow!(err)));
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn init_and_register_user_preferences(ctx: &mut AppContext) {
let (public_prefs, _parse_error) = init_public_user_preferences();
let public_prefs = Box::<user_preferences::in_memory::InMemoryPreferences>::default();
let private_prefs = settings::PrivatePreferences::new(Box::<
user_preferences::in_memory::InMemoryPreferences,
>::default());
ctx.add_singleton_model(move |_| settings::PublicPreferences::new(public_prefs));
ctx.add_singleton_model(move |_| init_private_user_preferences());
ctx.add_singleton_model(move |_| private_prefs);
}

#[cfg(test)]
Expand Down
28 changes: 28 additions & 0 deletions app/src/terminal/local_tty/terminal_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,34 @@ pub struct TerminalSurfaceInit {
pub colors: ColorList,
pub inactive_pty_reads_rx: InactiveReceiver<Arc<Vec<u8>>>,
}

#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
impl TerminalSurfaceInit {
/// Creates mock terminal surface inputs without spawning a PTY.
pub fn new_for_test(ctx: &mut AppContext) -> Self {
let (_wakeups_tx, wakeups_rx) = async_channel::unbounded();
let (_events_tx, events_rx) = async_channel::unbounded();
let (pty_reads_tx, pty_reads_rx) =
async_broadcast::broadcast(PTY_READS_BROADCAST_CHANNEL_SIZE);
drop(pty_reads_tx);
let sessions = ctx.add_model(|_| Sessions::new_for_test());
let model_events =
ctx.add_model(|ctx| ModelEventDispatcher::new(events_rx, sessions.clone(), ctx));
let model = Arc::new(FairMutex::new(TerminalModel::mock(None, None)));
let colors = model.lock().colors();
let size_info = model.lock().block_list().size().to_owned();
Self {
wakeups_rx,
model_events,
model,
sessions,
size_info,
colors,
inactive_pty_reads_rx: pty_reads_rx.deactivate(),
}
}
}

/// A newly constructed terminal surface and its manager post-wiring callback.
pub struct TerminalSurfaceResult<S, PostWire> {
pub surface: ViewHandle<S>,
Expand Down
12 changes: 12 additions & 0 deletions app/src/tui/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ pub struct TuiMcpManager {
}

impl TuiMcpManager {
/// Creates an empty MCP aggregate for frontend tests.
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub(crate) fn new_for_test(_ctx: &mut ModelContext<Self>) -> Self {
Self {
snapshot: TuiMcpSnapshot {
config_path: PathBuf::new(),
config_state: TuiMcpConfigState::Missing,
servers: Vec::new(),
},
}
}

pub fn new(ctx: &mut ModelContext<Self>) -> Self {
ctx.subscribe_to_model(&FileBasedMCPManager::handle(ctx), |me, _, _, ctx| {
me.refresh(ctx);
Expand Down
2 changes: 2 additions & 0 deletions app/src/tui_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ pub use crate::tui::{
TuiMcpAction, TuiMcpConfigState, TuiMcpManager, TuiMcpManagerEvent, TuiMcpServerId,
TuiMcpServerSnapshot, TuiMcpServerStatus, TuiMcpSnapshot, TuiMcpTransport,
};
#[cfg(any(test, feature = "test-util"))]
pub use crate::tui_test_support::register_tui_session_view_test_singletons;
pub use crate::util::repo_detection::{detect_possible_git_repo, RepoDetectionSessionType};
pub use crate::util::time_format::format_elapsed_seconds;

Expand Down
114 changes: 114 additions & 0 deletions app/src/tui_test_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//! Test-only app initialization used by the external `warp_tui` crate.

use ai::api_keys::ApiKeyManager;
use ai::index::full_source_code_embedding::manager::CodebaseIndexManager;
use warp_core::execution_mode::{AppExecutionMode, ExecutionMode};
use warpui::SingletonEntity as _;

use crate::ai::active_agent_views_model::ActiveAgentViewsModel;
use crate::ai::agent_conversations_model::AgentConversationsModel;
use crate::ai::blocklist::local_agent_task_sync_model::LocalAgentTaskSyncModel;
use crate::ai::blocklist::orchestration_event_streamer::OrchestrationEventStreamer;
use crate::ai::blocklist::orchestration_events::OrchestrationEventService;
use crate::ai::blocklist::{BlocklistAIHistoryModel, BlocklistAIPermissions, QueuedQueryModel};
use crate::ai::cloud_agent_settings::CloudAgentSettings;
use crate::ai::connected_self_hosted_workers::ConnectedSelfHostedWorkersModel;
use crate::ai::execution_profiles::profiles::AIExecutionProfilesModel;
use crate::ai::harness_availability::HarnessAvailabilityModel;
use crate::ai::llms::LLMPreferences;
use crate::ai::mcp::templatable_manager::TemplatableMCPServerManager;
use crate::auth::auth_manager::AuthManager;
use crate::auth::AuthStateProvider;
use crate::cloud_object::model::persistence::CloudModel;
use crate::code_review::git_repo_model::GitRepoModels;
use crate::network::NetworkStatus;
use crate::server::server_api::ServerApiProvider;
use crate::server::sync_queue::SyncQueue;
use crate::settings::manager::SettingsManager;
use crate::settings::{init_and_register_user_preferences, AISettings};
use crate::terminal::cli_agent_sessions::CLIAgentSessionsModel;
use crate::user_config::WarpConfig;
use crate::workspaces::user_workspaces::UserWorkspaces;
use crate::LaunchMode;

/// Registers the app models required to construct full TUI session views in tests.
///
/// Registration order mirrors model subscription dependencies.
pub fn register_tui_session_view_test_singletons(app: &mut warpui::App) {
app.add_singleton_model(|ctx| AppExecutionMode::new(ExecutionMode::App, false, ctx));
app.update(init_and_register_user_preferences);
app.add_singleton_model(|_| SettingsManager::default());
app.add_singleton_model(WarpConfig::mock);
app.update(|ctx| {
warpui_extras::secure_storage::register_noop("test", ctx);
});
app.update(AISettings::register_and_subscribe_to_events);
CloudAgentSettings::register(app);
app.add_singleton_model(ApiKeyManager::new);

app.add_singleton_model(|_| NetworkStatus::new());
app.add_singleton_model(|_| ServerApiProvider::new_for_test());
app.add_singleton_model(|_| AuthStateProvider::new_for_test());
app.add_singleton_model(AuthManager::new_for_test);
app.add_singleton_model(|ctx| {
let (team_client, workspace_client) = {
let provider = ServerApiProvider::as_ref(ctx);
(provider.get_team_client(), provider.get_workspace_client())
};
UserWorkspaces::mock(team_client, workspace_client, vec![], ctx)
});
app.add_singleton_model(SyncQueue::mock);
app.add_singleton_model(CloudModel::mock);
app.add_singleton_model(|_| crate::appearance::Appearance::mock());

app.add_singleton_model(|_| TemplatableMCPServerManager::default());
app.add_singleton_model(LLMPreferences::new);
app.add_singleton_model(HarnessAvailabilityModel::new);
app.add_singleton_model(ConnectedSelfHostedWorkersModel::new);
app.add_singleton_model(BlocklistAIPermissions::new);
app.add_singleton_model(|ctx| {
AIExecutionProfilesModel::new(&LaunchMode::new_for_unit_test(), ctx)
});
app.add_singleton_model(|_| {
crate::ai::document::ai_document_model::AIDocumentModel::new_for_test()
});

app.add_singleton_model(|_| BlocklistAIHistoryModel::default());
app.add_singleton_model(QueuedQueryModel::new);
app.add_singleton_model(|_| CLIAgentSessionsModel::new());
app.add_singleton_model(OrchestrationEventService::new);
app.add_singleton_model(LocalAgentTaskSyncModel::new);
app.add_singleton_model(OrchestrationEventStreamer::new);
app.add_singleton_model(|_| ActiveAgentViewsModel::new());
app.add_singleton_model(|_| GitRepoModels::new());
app.add_singleton_model(|ctx| {
CodebaseIndexManager::new_for_test(ServerApiProvider::as_ref(ctx).get(), ctx)
});
app.add_singleton_model(AgentConversationsModel::new);

app.add_singleton_model(crate::tui::TuiMcpManager::new_for_test);
app.add_singleton_model(|ctx| {
crate::changelog_model::ChangelogModel::new(ServerApiProvider::as_ref(ctx).get())
});
app.add_singleton_model(|_| ai::project_context::model::ProjectContextModel::default());
app.update(crate::settings::TuiAutoupdateSettings::register);
app.update(crate::settings::CodeSettings::register);
app.update(crate::settings::FontSettings::register);
app.update(crate::settings::InputSettings::register);
app.update(crate::settings::InputModeSettings::register);
app.update(crate::settings::SelectionSettings::register);
app.update(crate::settings::ScrollSettings::register);
app.update(crate::settings::EmacsBindingsSettings::register);
app.update(crate::terminal::general_settings::GeneralSettings::register);

app.add_singleton_model(|_| repo_metadata::repositories::DetectedRepositories::default());
app.add_singleton_model(watcher::HomeDirectoryWatcher::new_for_test);
app.add_singleton_model(repo_metadata::watcher::DirectoryWatcher::new);
#[cfg(feature = "local_fs")]
app.add_singleton_model(repo_metadata::RepoMetadataModel::new);
app.add_singleton_model(
crate::warp_managed_paths_watcher::WarpManagedPathsWatcher::new_for_testing,
);
app.add_singleton_model(crate::workflows::local_workflows::LocalWorkflows::new);
app.add_singleton_model(crate::ai::skills::SkillManager::new);
}
2 changes: 1 addition & 1 deletion app/src/user_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub struct WarpConfig {
/// Additional platform-dependent functionality can be found in impl blocks
/// in native.rs and wasm.rs.
impl WarpConfig {
#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn mock(_ctx: &mut ModelContext<Self>) -> Self {
Self {
theme_config: WarpThemeConfig::new(),
Expand Down
2 changes: 1 addition & 1 deletion app/src/warp_managed_paths_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl WarpManagedPathsWatcher {
Self::new_internal(ctx, true)
}

#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub(crate) fn new_for_testing(ctx: &mut ModelContext<Self>) -> Self {
Self::new_internal(ctx, false)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/workspaces/user_workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub struct CreateTeamResponse {
}

impl UserWorkspaces {
#[cfg(test)]
#[cfg(any(test, all(feature = "tui", feature = "test-util")))]
pub fn mock(
team_client: Arc<dyn TeamClient>,
workspace_client: Arc<dyn WorkspaceClient>,
Expand Down
1 change: 1 addition & 0 deletions crates/warp_tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod option_selector;
mod orchestrated_agent_identity_styling;
mod orchestration_block;
mod resume;
mod session_registry;
mod skills_menu;
mod slash_commands;
mod terminal_background;
Expand Down
1 change: 1 addition & 0 deletions crates/warp_tui/src/orchestration_block_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn request(harness: &str, execution_mode: RunAgentsExecutionMode) -> RunAgentsRe
name: "researcher".to_string(),
prompt: "research".to_string(),
title: "Researcher".to_string(),
agent_identity_uid: String::new(),
}],
plan_id: "plan-1".to_string(),
harness_auth_secret_name: None,
Expand Down
Loading
Loading