返回 CodeWhale
test_support.rs
根目录 / crates / tui / src / tui / test_support.rs
1 use std::path::{Path, PathBuf};
2
3 // ── Shared App/TuiOptions fixtures (#3923) ──────────────────────────────
4 //
5 // Before this module owned them, `create_test_app` was copy-pasted across 28
6 // test modules, each spelling out the full `TuiOptions` literal — 87 literals
7 // in all. The copies had drifted: different modules pinned different locales,
8 // currencies, and onboarding flags without anyone having chosen that, which is
9 // the non-hermeticity behind the intermittent `config_command_allow_shell_*`
10 // failures. Adding a `TuiOptions` field meant editing up to 87 sites.
11 //
12 // Express intentional differences by mutating the returned value at the call
13 // site, so the difference is visible as a deliberate line of test code rather
14 // than hidden inside another near-identical literal.
15
16 /// Default `TuiOptions` for tests, pinned to the deepseek-v4-pro fixture route.
17 pub(crate) fn test_tui_options(workspace: impl AsRef<Path>) -> crate::tui::app::TuiOptions {
18 let workspace = workspace.as_ref().to_path_buf();
19 crate::tui::app::TuiOptions {
20 model: "deepseek-v4-pro".to_string(),
21 workspace,
22 config_path: None,
23 config_profile: None,
24 allow_shell: false,
25 use_mouse_capture: false,
26 use_bracketed_paste: true,
27 max_subagents: 1,
28 skills_dir: PathBuf::from("."),
29 memory_path: PathBuf::from("memory.md"),
30 mcp_config_path: PathBuf::from("mcp.json"),
31 use_memory: false,
32 // Majority-of-fixtures defaults, measured across the 89 literals this
33 // helper replaced. Modules that need the other value say so explicitly.
34 start_in_agent_mode: false,
35 skip_onboarding: true,
36 yolo: false,
37 resume_session_id: None,
38 initial_input: None,
39 startup_notice: None,
40 }
41 }
42
43 /// Build an `App` whose observable state does not depend on the developer's
44 /// machine.
45 ///
46 /// `App::new` consults real persisted settings (provider/model maps,
47 /// auto-model, route limits, locale, currency), so an un-pinned fixture
48 /// computes against whatever the developer last configured. Every pin below
49 /// exists because some test was observed to depend on it. This fixture models
50 /// a session after the user has chosen a Startup action; direct `App::new`
51 /// tests remain the clean-launch authority.
52 pub(crate) fn test_app_with_options(options: crate::tui::app::TuiOptions) -> crate::tui::app::App {
53 let config = codewhale_runtime::config::Config::default();
54 let mut app = crate::tui::app::App::new(options, &config);
55
56 // Shared behavior tests operate on the live session surface. Do not make
57 // the production startup conditional for them: clean launches are covered
58 // by direct `App::new` tests that retain the Tideline Startup Hero.
59 app.launch.visible = false;
60
61 // Deterministic presentation regardless of host locale.
62 app.cost_currency = codewhale_config::pricing::CostCurrency::Usd;
63 app.ui_locale = codewhale_localization::Locale::En;
64 // Transcript tests must not depend on a concurrently swapped settings
65 // home. Tests for hidden reasoning opt out explicitly.
66 app.show_thinking = true;
67 // Pin the route identity: without this, a machine with customized
68 // settings computes context-window assertions against a different model
69 // than the requested deepseek-v4-pro.
70 app.set_provider_identity(codewhale_config::ProviderKind::Deepseek, "deepseek");
71 app.billing_presentation = codewhale_engine::route_billing::BillingPresentation::Metered;
72 app.model = "deepseek-v4-pro".to_string();
73 app.auto_model = false;
74 app.last_effective_model = None;
75 app.active_route_limits = None;
76 app.active_context_window = None;
77 app.active_context_window_override = None;
78 // Fixtures replace `app.workspace` freely. Do not retain `App::new`'s real
79 // process cwd as a second discovery root: parallel tests and a large
80 // developer checkout can otherwise consume the bounded mention index
81 // before the fixture workspace is scanned.
82 app.composer.mention_cwd = None;
83 // `App::new` derives onboarding state from the real `~/.codewhale`, and a
84 // pending step makes `ui::frame::render` take its onboarding early return
85 // before it assigns `last_prompt_area` or any other chrome geometry. CI
86 // has no such state, so a layout test written against that machine passes
87 // there and fails on any developer box mid-onboarding — for no product
88 // reason. Shared fixtures render the ordinary session surface; onboarding
89 // has its own tests that set this state deliberately.
90 app.onboarding = crate::tui::app::OnboardingState::None;
91 app
92 }
93
93 lines RUST