返回 CodeWhale
config_policy_status_tests.rs
根目录 / crates / tui / src / commands / config_policy_status_tests.rs
1 //! Existing public status regressions, moved out of the portable closure.
2 use crate::commands::CommandResult;
3 use crate::tui::app::App;
4 use codewhale_execpolicy::ApprovalMode;
5 use codewhale_localization::{Locale, MessageId, tr};
6 fn status(app: &mut App) -> CommandResult {
7 crate::commands::config_policy_host::status(app, None)
8 }
9 fn format_status(app: &mut App) -> String {
10 status(app).message.expect("status report")
11 }
12
13 mod tests {
14 use codewhale_models::Role;
15 use std::path::PathBuf;
16
17 use tempfile::TempDir;
18
19 use super::*;
20 use crate::tui::app::TuiOptions;
21 use crate::tui::history::HistoryCell;
22 use codewhale_config::AppMode;
23 use codewhale_config::ProviderKind;
24 use codewhale_models::{ContentBlock, Message};
25 use codewhale_runtime::config::Config;
26
27 #[test]
28 fn status_keeps_current_session_snapshot_remedy_after_notice_delivery() {
29 let _env = crate::test_support::lock_test_env();
30 let root = TempDir::new().unwrap();
31 let _home = crate::test_support::EnvVarGuard::set("CODEWHALE_HOME", root.path());
32 let _user_home = crate::test_support::EnvVarGuard::set("HOME", root.path());
33 let _user_profile = crate::test_support::EnvVarGuard::set("USERPROFILE", root.path());
34 let workspace = root.path().join("workspace");
35 std::fs::create_dir(&workspace).unwrap();
36 std::fs::write(workspace.join("large.txt"), vec![b'x'; 4096]).unwrap();
37 let mut app = create_test_app(workspace.clone());
38 app.current_session_id = Some("session-a".into());
39 assert!(
40 codewhale_engine::core::turn::pre_turn_snapshot(
41 &workspace,
42 1,
43 1024,
44 None,
45 Some("session-a")
46 )
47 .is_none()
48 );
49 assert_eq!(
50 codewhale_engine::core::turn::take_snapshots_disabled_notices(
51 &workspace,
52 Some("session-a")
53 )
54 .len(),
55 1
56 );
57 for _ in 0..2 {
58 let report = status(&mut app).message.unwrap();
59 assert!(report.contains("Snapshots and /undo are off"), "{report}");
60 assert!(report.contains("snapshot-eligible content"), "{report}");
61 // Stated once, not doubled by a raw reason plus a template.
62 assert_eq!(
63 report
64 .matches(codewhale_command_contract::config_policy::SNAPSHOTS_CAP_CONFIG_KEY)
65 .count(),
66 1,
67 "{report}"
68 );
69 }
70 app.current_session_id = Some("session-b".into());
71 assert!(
72 !status(&mut app)
73 .message
74 .unwrap()
75 .contains("Snapshots and /undo are off")
76 );
77 app.current_session_id = Some("session-a".into());
78 assert!(
79 codewhale_engine::core::turn::pre_turn_snapshot(
80 &workspace,
81 2,
82 0,
83 None,
84 Some("session-a")
85 )
86 .is_some()
87 );
88 assert!(
89 !status(&mut app)
90 .message
91 .unwrap()
92 .contains("Snapshots and /undo are off")
93 );
94 }
95
96 #[test]
97 fn status_warns_when_the_session_pin_left_a_fresh_roster_and_keeps_it() {
98 // #6035: warning only. The pin is never rewritten, and a route with
99 // no fresh roster proves nothing, so it stays silent.
100 let _env = crate::test_support::lock_test_env();
101 let _live = codewhale_engine::provider_lake::lock_live_snapshot();
102 let root = TempDir::new().unwrap();
103 let _home = crate::test_support::EnvVarGuard::set("CODEWHALE_HOME", root.path());
104 let _user_home = crate::test_support::EnvVarGuard::set("HOME", root.path());
105 let _user_profile = crate::test_support::EnvVarGuard::set("USERPROFILE", root.path());
106 codewhale_engine::provider_catalog_live::reset_cache_for_test();
107 let workspace = root.path().join("workspace");
108 std::fs::create_dir(&workspace).unwrap();
109 let mut app = create_test_app(workspace);
110 app.auto_model = false;
111 app.model = "deepseek-v4-flash".to_string();
112 let notice = "is not in deepseek's current model list";
113 assert!(
114 !status(&mut app).message.unwrap().contains(notice),
115 "no fresh roster, no claim"
116 );
117
118 let config = codewhale_plugins::providers::load_config(
119 app.config_path.clone(),
120 app.config_profile.as_deref(),
121 )
122 .unwrap_or_default();
123 let base_url = config.base_url_for_route(
124 &config
125 .resolve_provider_selection_identity("deepseek")
126 .unwrap(),
127 );
128 let fingerprint = codewhale_config::catalog::base_url_fingerprint(&base_url);
129 let fetched_at = codewhale_config::catalog::now_unix();
130 codewhale_engine::provider_catalog_live::record_success(
131 codewhale_config::catalog::ProviderCatalogDelta {
132 provider: "deepseek".to_string(),
133 base_url_fingerprint: fingerprint.clone(),
134 fetched_at,
135 offerings: vec![codewhale_config::catalog::CatalogOffering {
136 provider: "deepseek".to_string(),
137 wire_model_id: "deepseek-flash".to_string(),
138 endpoint_key: "chat".to_string(),
139 source: codewhale_config::catalog::CatalogSource::Live {
140 base_url_fingerprint: fingerprint,
141 fetched_at,
142 },
143 ..Default::default()
144 }],
145 },
146 );
147
148 let report = status(&mut app).message.unwrap();
149 assert!(report.contains(notice), "{report}");
150 assert!(report.contains("deepseek-v4-flash"), "{report}");
151 assert_eq!(app.model, "deepseek-v4-flash", "the pin is left unchanged");
152
153 app.model = "deepseek-flash".to_string();
154 assert!(!status(&mut app).message.unwrap().contains(notice));
155 app.model = "deepseek-v4-flash".to_string();
156 app.auto_model = true;
157 assert!(!status(&mut app).message.unwrap().contains(notice));
158 codewhale_engine::provider_catalog_live::reset_cache_for_test();
159 }
160
161 fn create_test_app(workspace: PathBuf) -> App {
162 let options = TuiOptions {
163 skills_dir: PathBuf::from("/tmp/test-skills"),
164 ..crate::tui::test_support::test_tui_options(workspace)
165 };
166 let mut app = App::new(options, &Config::default());
167 app.api_provider = ProviderKind::Deepseek;
168 app
169 }
170
171 #[test]
172 fn status_report_includes_runtime_fields() {
173 let tmpdir = TempDir::new().expect("temp dir");
174 std::fs::write(tmpdir.path().join("AGENTS.md"), "# Instructions").expect("write docs");
175 let mut app = create_test_app(tmpdir.path().to_path_buf());
176 app.current_session_id = Some("session-123".to_string());
177 app.session.total_tokens = 1234;
178 app.session.last_prompt_tokens = Some(100);
179 app.session.last_completion_tokens = Some(25);
180 app.session.last_prompt_cache_hit_tokens = Some(70);
181 app.session.last_prompt_cache_miss_tokens = Some(30);
182 app.api_messages_mut().push(Message {
183 role: Role::User,
184 content: vec![ContentBlock::Text {
185 text: "hello".to_string(),
186 cache_control: None,
187 }],
188 });
189 app.history.push(HistoryCell::User {
190 content: "hello".to_string(),
191 });
192
193 let result = status(&mut app);
194 let msg = result.message.expect("status message");
195 assert!(msg.starts_with(&format!("codewhale {}", env!("CARGO_PKG_VERSION"))));
196 assert!(msg.contains("Route:"));
197 assert!(msg.contains("Directory:"));
198 assert!(msg.contains("AGENTS.md"));
199 assert!(msg.contains("Mode:"));
200 assert!(msg.contains("approvals"));
201 assert!(msg.contains("Session:"));
202 assert!(msg.contains("session-123"));
203 assert!(msg.contains("Context window:"));
204 assert!(msg.contains("Tool outputs:"));
205 assert!(msg.contains("Session tokens:"));
206 assert!(msg.contains("/tokens"));
207 assert!(msg.contains("/statusline"));
208 }
209
210 /// Every row has to earn its place in a 24-row terminal. The report used
211 /// to run 31 lines, so at 80x24 — where the transcript viewport is 18
212 /// rows — a user who typed `/status` landed on the *tail*: the version,
213 /// route, directory, mode and sandbox rows had already scrolled off, and
214 /// what remained on screen was five "not reported" rows and a `$0.0000`.
215 ///
216 /// A fresh session is 18 rows, not 17: `Window override:` is present
217 /// unless the value is already configured. That matches the viewport
218 /// height, so the title still scrolls off once `/status` occupies a
219 /// history cell.
220 #[test]
221 fn status_report_fits_a_short_terminal() {
222 let tmpdir = TempDir::new().expect("temp dir");
223 let mut app = create_test_app(tmpdir.path().to_path_buf());
224 let msg = status(&mut app).message.expect("status message");
225 let rows = msg.lines().count();
226 assert!(
227 msg.contains("Window override:"),
228 "fresh session keeps the override row: {msg}"
229 );
230 assert_eq!(
231 rows, 18,
232 "fresh session is 18 rows with Window override present, got {rows} rows:\n{msg}"
233 );
234 let source = msg
235 .lines()
236 .find(|line| line.contains("Window source:"))
237 .unwrap();
238 assert!(
239 source.chars().count() <= 80,
240 "fresh source provenance must not wrap: {source}"
241 );
242 }
243
244 /// `Rate limits:` was a `push_row` of a string literal — it could never
245 /// report anything but "not available from provider telemetry". A row
246 /// that cannot say anything cannot inform, and it cost a row on every
247 /// terminal forever.
248 #[test]
249 fn status_report_drops_the_row_that_could_never_say_anything() {
250 let tmpdir = TempDir::new().expect("temp dir");
251 let mut app = create_test_app(tmpdir.path().to_path_buf());
252 let msg = status(&mut app).message.expect("status message");
253 assert!(!msg.contains("Rate limits"), "{msg}");
254 assert!(
255 !msg.contains("not available from provider telemetry"),
256 "{msg}"
257 );
258 }
259
260 /// The per-turn ledger is `/tokens`' whole subject and `/status` printed
261 /// six rows of it. Shedding the field beats printing it at the same
262 /// weight as the sandbox policy — but only if the report says where it
263 /// went, and only if the two facts that live nowhere else (the
264 /// cumulative in/out split and the cumulative cache totals) survive.
265 #[test]
266 fn status_report_sheds_the_per_turn_ledger_and_names_where_it_went() {
267 let tmpdir = TempDir::new().expect("temp dir");
268 let mut app = create_test_app(tmpdir.path().to_path_buf());
269 app.session.total_input_tokens = 900;
270 app.session.total_output_tokens = 120;
271 app.session.total_tokens = 1020;
272 app.session.total_cache_hit_tokens = 700;
273 app.session.total_cache_miss_tokens = 200;
274 app.session.last_prompt_tokens = Some(100);
275
276 let msg = status(&mut app).message.expect("status message");
277
278 for shed in [
279 "Last API input:",
280 "Last API output:",
281 "Cache hit/miss:",
282 "Session input:",
283 "Session output:",
284 "Total tokens:",
285 "Session cache:",
286 ] {
287 assert!(
288 !msg.contains(shed),
289 "{shed} should be shed, not printed: {msg}"
290 );
291 }
292 assert!(msg.contains("Per-turn tokens: /tokens"), "{msg}");
293 // The footer-item *keys* were a full-width row of internal config
294 // names; `/statusline` is the surface that owns them.
295 assert!(!msg.contains("reasoning_replay"), "{msg}");
296 assert!(!msg.contains("git_branch"), "{msg}");
297 assert!(msg.contains("Footer items: /statusline"), "{msg}");
298
299 let row = msg
300 .lines()
301 .find(|line| line.trim_start().starts_with("Session tokens:"))
302 .expect("session tokens row");
303 assert!(row.contains("900 in"), "{row}");
304 assert!(row.contains("120 out"), "{row}");
305 assert!(row.contains("1020 total"), "{row}");
306 assert!(row.contains("cache 700 hit / 200 miss"), "{row}");
307 }
308
309 /// Provider, model and effort are one fact — which route this turn goes
310 /// to — and the header rail already renders them as one dotted lockup.
311 #[test]
312 fn status_report_states_the_route_the_way_the_header_does() {
313 let tmpdir = TempDir::new().expect("temp dir");
314 let mut app = create_test_app(tmpdir.path().to_path_buf());
315 let msg = status(&mut app).message.expect("status message");
316 assert!(!msg.contains("Provider:"), "{msg}");
317 assert!(!msg.contains("Model:"), "{msg}");
318 let row = msg
319 .lines()
320 .find(|line| line.trim_start().starts_with("Route:"))
321 .expect("route row");
322 assert!(row.contains(" · "), "route must read as a lockup: {row}");
323 assert!(row.contains("reasoning"), "{row}");
324 }
325
326 /// #5134: the number alone sends users to the issue tracker. `/status` has
327 /// to name the provenance and the key that changes it, and it must name the
328 /// table the user is actually on — not a generic placeholder. The two are
329 /// separate facts, so the key gets its own aligned row instead of a
330 /// parenthesis that pushed the provenance off the end of an 80-column line.
331 #[test]
332 fn status_report_names_context_window_source_and_override_key() {
333 let tmpdir = TempDir::new().expect("temp dir");
334 let mut app = create_test_app(tmpdir.path().to_path_buf());
335 app.set_provider_identity_record(
336 codewhale_runtime::config::Config::default()
337 .resolve_provider_identity(ProviderKind::Moonshot.as_str())
338 .expect("captured fixture provider"),
339 );
340
341 let msg = status(&mut app).message.expect("status message");
342
343 let source_row = msg
344 .lines()
345 .find(|line| line.trim_start().starts_with("Window source:"))
346 .expect("window source row");
347 assert!(
348 !source_row.contains("context_window"),
349 "the provenance row states the provenance only: {source_row}"
350 );
351 // A labelled row, not an indented continuation: the transcript cell
352 // strips leading whitespace, so an aligned continuation line rendered
353 // flush against the label column and read as a field of its own with
354 // the label missing.
355 let override_row = msg
356 .lines()
357 .find(|line| line.trim_start().starts_with("Window override:"))
358 .expect("window override row");
359 assert!(
360 override_row.contains("[providers.moonshot] context_window in config.toml"),
361 "{override_row}"
362 );
363
364 // A user override reads as a statement of fact, not as advice to set
365 // something that is already set.
366 app.active_context_window =
367 Some(codewhale_engine::route_runtime::ContextWindowResolution {
368 tokens: 262_144,
369 source: codewhale_engine::route_runtime::ContextWindowSource::Configured,
370 });
371 app.active_context_window_source =
372 codewhale_engine::route_runtime::ContextWindowSource::Configured;
373 let msg = status(&mut app).message.expect("status message");
374 let row = msg
375 .lines()
376 .find(|line| line.trim_start().starts_with("Window source:"))
377 .expect("window source row");
378 assert!(row.contains("configured"), "{row}");
379 assert!(!msg.contains("Window override:"), "{msg}");
380 }
381
382 #[test]
383 fn status_report_keeps_exact_named_custom_provider() {
384 let tmpdir = TempDir::new().expect("temp dir");
385 let mut app = create_test_app(tmpdir.path().to_path_buf());
386 app.set_provider_identity(ProviderKind::Custom, "lm-studio");
387
388 let msg = status(&mut app).message.expect("status message");
389
390 let route_row = msg
391 .lines()
392 .find(|line| line.trim_start().starts_with("Route:"))
393 .expect("route row");
394 assert!(route_row.contains("lm-studio"), "{route_row}");
395 assert!(!route_row.contains("custom"), "{route_row}");
396 assert!(
397 msg.contains("[providers.lm-studio] context_window in config.toml"),
398 "the override must name the captured route table: {msg}"
399 );
400 }
401
402 #[test]
403 fn status_report_interpolation_preserves_braces_in_runtime_values() {
404 let tmpdir = TempDir::new().expect("temp dir");
405 let mut app = create_test_app(tmpdir.path().to_path_buf());
406 app.set_provider_identity(ProviderKind::Custom, "acme-{model}");
407 app.model = "vision-{reasoning}".to_string();
408 app.current_session_id = Some("session-{cells}-{messages}".to_string());
409
410 let msg = format_status(&mut app);
411 let route_row = msg
412 .lines()
413 .find(|line| line.trim_start().starts_with("Route:"))
414 .expect("route row");
415 assert!(
416 route_row.contains("acme-{model} · vision-{reasoning} ·"),
417 "{route_row}"
418 );
419 let session_row = msg
420 .lines()
421 .find(|line| line.trim_start().starts_with("Session:"))
422 .expect("session row");
423 assert!(
424 session_row.contains("session-{cells}-{messages}"),
425 "{session_row}"
426 );
427 }
428
429 #[test]
430 fn status_report_surfaces_effective_safety_policy() {
431 let tmpdir = TempDir::new().expect("temp dir");
432 let mut app = create_test_app(tmpdir.path().to_path_buf());
433 // `/status` is honest about enforcement: on a platform with no OS
434 // sandbox (e.g. Windows) it reports "<policy> requested, not enforced"
435 // instead of the enforced string. The test must hold on both, so it
436 // branches on the same signal `safety_summary` uses (`sandbox_backend`).
437 let unenforced = app.sandbox_backend.is_none();
438
439 app.mode = AppMode::Agent;
440 let agent = format_status(&mut app);
441 assert!(agent.contains("Safety:"));
442 if unenforced {
443 assert!(agent.contains("workspace-write requested, not enforced"));
444 } else {
445 // workspace-write no longer implies egress; /status must say so.
446 assert!(agent.contains("sandbox workspace-write, network off"));
447 }
448
449 app.approval_mode = ApprovalMode::Bypass;
450 let full_access = format_status(&mut app);
451 assert!(full_access.contains("sandbox disabled, network unrestricted"));
452
453 app.configured_sandbox_mode = Some("workspace-write".to_string());
454 let clamped = format_status(&mut app);
455 if unenforced {
456 assert!(clamped.contains("workspace-write requested, not enforced"));
457 } else {
458 // Clamping full access down to workspace-write lands on the same
459 // restricted posture an ordinary Agent turn gets.
460 assert!(clamped.contains("sandbox workspace-write, network off"));
461 }
462
463 // The explicit opt-in is the only thing that flips the reported label.
464 app.configured_sandbox_network = Some(true);
465 let networked = format_status(&mut app);
466 if unenforced {
467 assert!(networked.contains("workspace-write requested, not enforced"));
468 } else {
469 assert!(networked.contains("sandbox workspace-write, network on"));
470 }
471 app.configured_sandbox_network = None;
472
473 app.mode = AppMode::Plan;
474 let plan = format_status(&mut app);
475 if unenforced {
476 assert!(plan.contains("read-only requested, not enforced"));
477 } else {
478 assert!(plan.contains("sandbox read-only, network off"));
479 }
480
481 app.configured_sandbox_mode = None;
482 app.mode = AppMode::Agent;
483 let yolo = format_status(&mut app);
484 assert!(yolo.contains("sandbox disabled, network unrestricted"));
485 }
486
487 #[test]
488 fn status_report_surfaces_large_tool_output_pressure() {
489 let tmpdir = TempDir::new().expect("temp dir");
490 let mut app = create_test_app(tmpdir.path().to_path_buf());
491 let raw = "RAW_STATUS_PRESSURE\n".repeat(2_000);
492 app.api_messages_mut().push(Message {
493 role: Role::User,
494 content: vec![ContentBlock::ToolResult {
495 execution_id: None,
496 tool_use_id: "call-big".to_string(),
497 content: raw,
498 is_error: None,
499 content_blocks: None,
500 }],
501 });
502 app.session_artifacts
503 .push(codewhale_runtime::artifacts::ArtifactRecord {
504 id: "art_call-big".to_string(),
505 kind: codewhale_runtime::artifacts::ArtifactKind::ToolOutput,
506 session_id: "session-123".to_string(),
507 tool_call_id: "call-big".to_string(),
508 tool_name: "exec_shell".to_string(),
509 created_at: chrono::Utc::now(),
510 byte_size: 24_000,
511 preview: "large output".to_string(),
512 storage_path: PathBuf::from("artifacts/art_call-big.txt"),
513 });
514
515 let result = status(&mut app);
516 let msg = result.message.expect("status message");
517
518 assert!(msg.contains("Tool outputs:"));
519 assert!(msg.contains("raw over cap"));
520 assert!(msg.contains("context pressure"));
521 assert!(msg.contains("artifact"));
522 }
523
524 #[test]
525 fn status_values_start_in_one_column_for_cjk_labels() {
526 let tmpdir = TempDir::new().expect("temp dir");
527 let mut app = create_test_app(tmpdir.path().to_path_buf());
528 app.ui_locale = Locale::ZhHans;
529
530 let msg = format_status(&mut app);
531
532 let columns: Vec<usize> = [
533 MessageId::StatusLabelRoute,
534 MessageId::StatusLabelProjectDocs,
535 MessageId::StatusLabelContextWindow,
536 ]
537 .into_iter()
538 .map(|id| {
539 let label = format!("{}:", tr(Locale::ZhHans, id));
540 let line = msg
541 .lines()
542 .find(|line| line.trim_start().starts_with(&label))
543 .unwrap_or_else(|| panic!("missing {id:?}: {msg}"));
544 let value = line[line.find(&label).unwrap() + label.len()..].trim_start();
545 unicode_width::UnicodeWidthStr::width(&line[..line.len() - value.len()])
546 })
547 .collect();
548 assert!(
549 columns.windows(2).all(|w| w[0] == w[1]),
550 "{columns:?}\n{msg}"
551 );
552 }
553
554 #[test]
555 fn status_report_localizes_the_complete_japanese_surface() {
556 let tmpdir = TempDir::new().expect("temp dir");
557 let mut app = create_test_app(tmpdir.path().to_path_buf());
558 app.ui_locale = Locale::Ja;
559 app.approval_mode = ApprovalMode::Bypass;
560 // The installed window carries its own source and outranks the bare
561 // field, so a fixture that only sets the source keeps whatever window
562 // the test app resolved and the status reports that source instead.
563 app.active_context_window =
564 Some(codewhale_engine::route_runtime::ContextWindowResolution {
565 tokens: 200_000,
566 source: codewhale_engine::route_runtime::ContextWindowSource::ProviderReported,
567 });
568 app.active_context_window_source =
569 codewhale_engine::route_runtime::ContextWindowSource::ProviderReported;
570
571 let msg = format_status(&mut app);
572
573 for id in [
574 MessageId::StatusLabelRoute,
575 MessageId::StatusLabelDirectory,
576 MessageId::StatusLabelProjectDocs,
577 MessageId::StatusLabelMode,
578 MessageId::StatusLabelSafety,
579 MessageId::StatusLabelContextWindow,
580 MessageId::StatusLabelWindowSource,
581 MessageId::StatusLabelWindowOverride,
582 MessageId::StatusLabelSession,
583 MessageId::StatusLabelSessionTokens,
584 MessageId::StatusLabelSessionCost,
585 MessageId::StatusLabelToolOutputs,
586 MessageId::StatusProjectDocsNone,
587 MessageId::StatusContextSourceProviderReported,
588 MessageId::StatusSessionNotSaved,
589 MessageId::StatusToolNone,
590 MessageId::StatusSafetyDisabled,
591 ] {
592 let japanese = tr(Locale::Ja, id);
593 assert_ne!(japanese, tr(Locale::En, id), "{id:?} copied English");
594 assert!(msg.contains(japanese.as_ref()), "missing {id:?}: {msg}");
595 }
596
597 for english in [
598 "Route:",
599 "Directory:",
600 "Project docs:",
601 "Mode:",
602 "Safety:",
603 "Context window:",
604 "Window source:",
605 "Window override:",
606 "Session:",
607 "Session tokens:",
608 "Session cost:",
609 "Tool outputs:",
610 "reasoning ",
611 "no project docs",
612 "not saved yet",
613 "no large outputs tracked",
614 "Per-turn tokens:",
615 ] {
616 assert!(
617 !msg.contains(english),
618 "English leaked as {english:?}: {msg}"
619 );
620 }
621
622 // Protocol/config identities and commands remain literal inside the
623 // translated prose.
624 for literal in [
625 "deepseek",
626 "context_window",
627 "config.toml",
628 "/tokens",
629 "/statusline",
630 ] {
631 assert!(msg.contains(literal), "missing literal {literal:?}: {msg}");
632 }
633 }
634
635 #[test]
636 fn project_docs_reports_missing_docs() {
637 let tmpdir = TempDir::new().expect("temp dir");
638 let mut app = create_test_app(tmpdir.path().to_path_buf());
639 assert_eq!(
640 format_status(&mut app)
641 .lines()
642 .find(|line| line.trim_start().starts_with("Project docs:")),
643 Some(" Project docs: no project docs")
644 );
645 }
646
647 #[test]
648 fn status_cost_row_uses_unknown_for_subscription_and_local_routes() {
649 let tmpdir = TempDir::new().expect("temp dir");
650 let mut app = create_test_app(tmpdir.path().to_path_buf());
651 app.billing_presentation =
652 codewhale_engine::route_billing::BillingPresentation::Subscription("Codex OAuth quota");
653 let sub_report = format_status(&mut app);
654 let sub_cost_line = sub_report
655 .lines()
656 .find(|line| line.trim_start().starts_with("Session cost:"))
657 .expect("subscription Session cost line");
658 assert!(sub_cost_line.ends_with("unknown"), "{sub_cost_line}");
659 assert!(
660 !sub_cost_line.contains("Codex OAuth quota"),
661 "{sub_cost_line}"
662 );
663 assert!(!sub_cost_line.contains('$'), "{sub_cost_line}");
664
665 app.billing_presentation = codewhale_engine::route_billing::BillingPresentation::Local;
666 let local_report = format_status(&mut app);
667 let local_cost_line = local_report
668 .lines()
669 .find(|line| line.trim_start().starts_with("Session cost:"))
670 .expect("local Session cost line");
671 assert!(local_cost_line.ends_with("unknown"), "{local_cost_line}");
672 assert!(!local_cost_line.contains("local"), "{local_cost_line}");
673 assert!(!local_cost_line.contains('$'), "{local_cost_line}");
674 }
675 }
676
677 fn safety_id(flag: Option<bool>) -> MessageId {
678 use crate::commands::groups::config::policy::{
679 policy_messages::StatusText, status::safety_disabled_message,
680 };
681 match safety_disabled_message(flag) {
682 StatusText::StatusSafetyDisabledSetuidBlocked => {
683 MessageId::StatusSafetyDisabledSetuidBlocked
684 }
685 StatusText::StatusSafetyDisabledSetuidAllowed => {
686 MessageId::StatusSafetyDisabledSetuidAllowed
687 }
688 StatusText::StatusSafetyDisabled => MessageId::StatusSafetyDisabled,
689 other => panic!("unexpected safety text {other:?}"),
690 }
691 }
692 #[test]
693 fn status_safety_row_discloses_no_new_privs_flag_state_for_full_access() {
694 // #5723: both flag states get a distinct, truthful row; a platform
695 // without the flag keeps the plain full-access label. The live query
696 // is host-dependent, so the selector is pinned directly.
697 let blocked = tr(Locale::En, safety_id(Some(true)));
698 assert!(
699 blocked.contains("sandbox disabled, network unrestricted"),
700 "{blocked}"
701 );
702 assert!(blocked.contains("sudo/setuid blocked"), "{blocked}");
703
704 let relaxed = tr(Locale::En, safety_id(Some(false)));
705 assert!(
706 relaxed.contains("sandbox disabled, network unrestricted"),
707 "{relaxed}"
708 );
709 assert!(relaxed.contains("sudo/setuid allowed"), "{relaxed}");
710
711 let plain = safety_id(None);
712 assert_eq!(
713 tr(Locale::En, plain),
714 tr(Locale::En, MessageId::StatusSafetyDisabled)
715 );
716
717 // The disclosure is real prose, so every complete pack must carry a
718 // translation rather than a copy of the English string.
719 for id in [safety_id(Some(true)), safety_id(Some(false))] {
720 assert_ne!(tr(Locale::Ja, id), tr(Locale::En, id), "{id:?}");
721 }
722 }
723
723 lines RUST