返回 CodeWhale
lane.rs
根目录 / crates / tui / src / commands / groups / core / lane.rs
1 #[cfg(test)]
2 mod tests {
3 use crate::tui::app::{App, TuiOptions};
4 use codewhale_lane::control::operations_for_domain;
5 use codewhale_lane::{ControlDomain, ControlOperation, ControlSurface};
6 use codewhale_runtime::config::Config;
7 use std::path::PathBuf;
8
9 fn test_app() -> App {
10 let options = TuiOptions {
11 ..crate::tui::test_support::test_tui_options(PathBuf::from("."))
12 };
13 App::new(options, &Config::default())
14 }
15
16 #[test]
17 fn bare_lane_and_list_resolve_to_the_same_read_verb() {
18 let mut app = test_app();
19 let bare = crate::commands::execute("/lane", &mut app);
20 let whitespace = crate::commands::execute("/lane ", &mut app);
21 let explicit = crate::commands::execute("/lane list", &mut app);
22 assert_eq!(bare, explicit);
23 assert_eq!(whitespace, explicit);
24 }
25
26 #[test]
27 fn every_slash_verb_maps_onto_a_shared_lane_operation() {
28 for descriptor in operations_for_domain(ControlDomain::Lane) {
29 assert_eq!(
30 ControlOperation::parse_verb(ControlDomain::Lane, descriptor.verb),
31 Some(descriptor.operation),
32 "/lane {} must resolve to {}",
33 descriptor.verb,
34 descriptor.id
35 );
36 }
37 for (spelling, expected) in [
38 ("stop", ControlOperation::LaneInterrupt),
39 ("cancel", ControlOperation::LaneInterrupt),
40 ("inspect", ControlOperation::LaneStatus),
41 ("ls", ControlOperation::LaneList),
42 ] {
43 assert_eq!(
44 ControlOperation::parse_verb(ControlDomain::Lane, spelling),
45 Some(expected)
46 );
47 }
48 }
49
50 #[test]
51 fn unknown_verbs_are_rejected_without_touching_the_registry() {
52 let mut app = test_app();
53 let result = crate::commands::execute("/lane obliterate lane-a1b2c3d4", &mut app);
54 assert!(result.is_error);
55 assert!(
56 result
57 .message
58 .as_deref()
59 .is_some_and(|message| message.contains("Unknown /lane verb 'obliterate'"))
60 );
61 }
62
63 #[test]
64 fn help_lists_every_verb_with_its_authority_and_cli_twin() {
65 let mut app = test_app();
66 let help = crate::commands::execute("/lane help", &mut app)
67 .message
68 .unwrap_or_default();
69 for descriptor in operations_for_domain(ControlDomain::Lane) {
70 assert!(
71 help.contains(descriptor.cli_invocation),
72 "help must name the CLI twin of {}",
73 descriptor.id
74 );
75 assert!(
76 help.contains(&descriptor.slash_invocation()),
77 "help must name the slash form of {}",
78 descriptor.id
79 );
80 }
81 assert!(help.contains("read"));
82 assert!(help.contains("write"));
83 assert!(
84 help.contains("$CODEWHALE_HOME/lanes/"),
85 "help must say which durable store it reads"
86 );
87 }
88
89 #[test]
90 fn restart_and_resume_report_that_they_have_no_backend() {
91 let mut app = test_app();
92 for verb in ["restart", "resume"] {
93 let result = crate::commands::execute(&format!("/lane {verb} lane-a1b2c3d4"), &mut app);
94 assert!(result.is_error, "/lane {verb}");
95 let message = result.message.as_deref().unwrap_or_default();
96 assert!(
97 message.contains("backend_not_implemented") || message.contains("no_lane_registry"),
98 "/lane {verb} must explain itself, got: {message}"
99 );
100 }
101 }
102
103 #[test]
104 fn slash_command_and_cli_agree_on_lane_verb_ids() {
105 let info = crate::commands::get_command_info("lane").expect("lane info");
106 for descriptor in operations_for_domain(ControlDomain::Lane) {
107 assert_eq!(descriptor.slash_command, info.name);
108 assert!(
109 info.usage.contains(descriptor.verb),
110 "/lane usage must document {}",
111 descriptor.verb
112 );
113 assert!(descriptor.offers(ControlSurface::Slash));
114 assert!(descriptor.offers(ControlSurface::Cli));
115 }
116 }
117
118 #[test]
119 fn bare_lane_is_read_only_so_the_hotbar_cannot_mutate_state() {
120 let info = crate::commands::get_command_info("lane").expect("lane info");
121 let descriptor = ControlOperation::LaneList.descriptor();
122 assert_eq!(
123 descriptor.authority,
124 codewhale_lane::ControlAuthority::Read,
125 "a bare hotbar press must not be a write"
126 );
127 assert!(
128 !info.requires_required_argument(),
129 "/lane must be directly runnable from the palette and hotbar"
130 );
131 assert_eq!(descriptor.hotbar_action_id(), "slash.lane");
132 }
133 }
134
134 lines RUST