| 1 | //! Focused Gherkin acceptance evidence for FEAT-012 palette and slash |
| 2 | //! completion discovery filtering. Bound through separate scenario-level |
| 3 | //! cucumber worlds that prove the six FEAT-012 acceptance criteria plus the |
| 4 | //! alias-aware canonical unification decision (AT-010) through the live |
| 5 | //! palette builder, the live completion function, and the live dispatch |
| 6 | //! entry point. |
| 7 | |
| 8 | use cucumber::{World as _, given, then, when, writer::Stats as _}; |
| 9 | use tempfile::TempDir; |
| 10 | |
| 11 | use crate::commands::{self, CommandResult}; |
| 12 | use crate::tui::app::{App, TuiOptions}; |
| 13 | use crate::tui::command_palette::{self, CommandPaletteEntry}; |
| 14 | use crate::tui::widgets::{self, SlashMenuEntry}; |
| 15 | use codewhale_config::ProviderKind; |
| 16 | use codewhale_localization::Locale; |
| 17 | use codewhale_runtime::config::Config; |
| 18 | |
| 19 | // --- FEAT-012 discovery filtering constants --- |
| 20 | |
| 21 | const DISCOVERY_FEATURE_NAME: &str = "FEAT-012 Discovery Filtering (Palette And Slash Completion)"; |
| 22 | const DISCOVERY_FEATURE_PATH: &str = concat!( |
| 23 | env!("CARGO_MANIFEST_DIR"), |
| 24 | "/tests/features/feat-012-discovery-filtering.feature" |
| 25 | ); |
| 26 | |
| 27 | const AC1_SCENARIO: &str = "AC1 Visible user command appears once in the palette with metadata"; |
| 28 | const AC2_SCENARIO: &str = "AC2 Hidden user command is runnable but excluded from the palette"; |
| 29 | const AC3_SCENARIO: &str = "AC3 Visible user command appears in matching slash completion"; |
| 30 | const AC4_SCENARIO: &str = "AC4 Hidden user command is excluded from slash completion"; |
| 31 | const AC5_SCENARIO: &str = "AC5 User canonical shadow suppresses a built-in in both surfaces"; |
| 32 | const AC6_SCENARIO: &str = |
| 33 | "AC6 User command shadows a built-in alias without hiding canonical access"; |
| 34 | const AT010_SCENARIO: &str = |
| 35 | "AT-010 Alias-aware unification - accepted user alias claims a built-in canonical token"; |
| 36 | |
| 37 | // --- Shared helpers --- |
| 38 | |
| 39 | fn create_discovery_app(tmpdir: &TempDir) -> App { |
| 40 | let options = TuiOptions { |
| 41 | skills_dir: tmpdir.path().join("skills"), |
| 42 | memory_path: tmpdir.path().join("memory.md"), |
| 43 | mcp_config_path: tmpdir.path().join("mcp.json"), |
| 44 | ..crate::tui::test_support::test_tui_options(tmpdir.path()) |
| 45 | }; |
| 46 | App::new(options, &Config::default()) |
| 47 | } |
| 48 | |
| 49 | fn write_user_command(tmpdir: &TempDir, name: &str, content: &str) { |
| 50 | // Workspace commands load only in a trusted workspace. |
| 51 | crate::test_support::trust_workspace(tmpdir.path()); |
| 52 | let commands_dir = tmpdir.path().join(".codewhale").join("commands"); |
| 53 | std::fs::create_dir_all(commands_dir).expect("create commands dir"); |
| 54 | let path = tmpdir |
| 55 | .path() |
| 56 | .join(".codewhale") |
| 57 | .join("commands") |
| 58 | .join(format!("{name}.md")); |
| 59 | std::fs::write(path, content).expect("write user command"); |
| 60 | } |
| 61 | |
| 62 | fn palette_entries(tmpdir: &TempDir) -> Vec<CommandPaletteEntry> { |
| 63 | command_palette::build_entries( |
| 64 | Locale::En, |
| 65 | tmpdir.path().join("skills").as_path(), |
| 66 | &Default::default(), |
| 67 | tmpdir.path(), |
| 68 | tmpdir.path().join("mcp.json").as_path(), |
| 69 | None, |
| 70 | ) |
| 71 | } |
| 72 | |
| 73 | fn completion_hints(tmpdir: &TempDir, input: &str) -> Vec<SlashMenuEntry> { |
| 74 | widgets::slash_completion_hints( |
| 75 | input, |
| 76 | 128, |
| 77 | &[], |
| 78 | Locale::En, |
| 79 | Some(tmpdir.path()), |
| 80 | ProviderKind::Deepseek, |
| 81 | ) |
| 82 | } |
| 83 | |
| 84 | fn sent_message(result: &CommandResult) -> String { |
| 85 | match &result.action { |
| 86 | Some(crate::tui::app::AppAction::SendMessage(message)) => message.clone(), |
| 87 | other => panic!("expected SendMessage action, got {other:?}"), |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // --- AC1: Visible user command appears once in the palette with metadata --- |
| 92 | |
| 93 | #[derive(cucumber::World)] |
| 94 | #[world(init = Self::new)] |
| 95 | struct DiscoveryWorld01 { |
| 96 | tmpdir: Option<TempDir>, |
| 97 | entries: Option<Vec<CommandPaletteEntry>>, |
| 98 | } |
| 99 | |
| 100 | impl std::fmt::Debug for DiscoveryWorld01 { |
| 101 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 102 | f.debug_struct("DiscoveryWorld01") |
| 103 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 104 | .field("has_entries", &self.entries.is_some()) |
| 105 | .finish() |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | impl DiscoveryWorld01 { |
| 110 | fn new() -> Self { |
| 111 | Self { |
| 112 | tmpdir: None, |
| 113 | entries: None, |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | #[given("a workspace with a visible user command that has a description and usage")] |
| 119 | fn ac1_given_visible_with_metadata(world: &mut DiscoveryWorld01) { |
| 120 | let tmpdir = TempDir::new().expect("AC1 TempDir"); |
| 121 | write_user_command( |
| 122 | &tmpdir, |
| 123 | "review", |
| 124 | "---\ndescription: Review with context\nusage: /review <path>\n---\nreview $ARGUMENTS", |
| 125 | ); |
| 126 | commands::user_registry::reload(Some(tmpdir.path())); |
| 127 | world.tmpdir = Some(tmpdir); |
| 128 | } |
| 129 | |
| 130 | #[when("the command palette is queried")] |
| 131 | fn ac1_when_palette_queried(world: &mut DiscoveryWorld01) { |
| 132 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 133 | world.entries = Some(palette_entries(tmpdir)); |
| 134 | } |
| 135 | |
| 136 | #[then("the user command appears exactly once with its description and usage")] |
| 137 | fn ac1_then_user_entry_once(world: &mut DiscoveryWorld01) { |
| 138 | let entries = world.entries.as_ref().expect("entries should exist"); |
| 139 | let rows: Vec<_> = entries |
| 140 | .iter() |
| 141 | .filter(|entry| entry.label == "/review") |
| 142 | .collect(); |
| 143 | assert_eq!(rows.len(), 1, "exactly one /review row must exist"); |
| 144 | assert!( |
| 145 | rows[0].description.contains("Review with context"), |
| 146 | "row must carry the description: {}", |
| 147 | rows[0].description |
| 148 | ); |
| 149 | assert!( |
| 150 | rows[0].description.contains("/review <path>"), |
| 151 | "row must carry the usage: {}", |
| 152 | rows[0].description |
| 153 | ); |
| 154 | } |
| 155 | |
| 156 | #[then("no duplicate entry appears for the same effective token")] |
| 157 | fn ac1_then_no_duplicate(world: &mut DiscoveryWorld01) { |
| 158 | let entries = world.entries.as_ref().expect("entries should exist"); |
| 159 | let labels: Vec<_> = entries.iter().map(|entry| entry.label.clone()).collect(); |
| 160 | let duplicates: Vec<_> = labels |
| 161 | .iter() |
| 162 | .filter(|label| labels.iter().filter(|other| other == label).count() > 1) |
| 163 | .collect(); |
| 164 | assert!( |
| 165 | duplicates.is_empty(), |
| 166 | "no duplicate labels may appear: {duplicates:?}" |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | #[tokio::test(flavor = "current_thread")] |
| 171 | async fn feat012_ac1_visible_user_command_appears_once_in_palette() { |
| 172 | let writer = DiscoveryWorld01::cucumber() |
| 173 | .fail_on_skipped() |
| 174 | .with_default_cli() |
| 175 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 176 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AC1_SCENARIO |
| 177 | }) |
| 178 | .await; |
| 179 | assert_eq!(writer.failed_steps(), 0, "scenario failed: {AC1_SCENARIO}"); |
| 180 | assert_eq!( |
| 181 | writer.skipped_steps(), |
| 182 | 0, |
| 183 | "scenario skipped: {AC1_SCENARIO}" |
| 184 | ); |
| 185 | assert_eq!( |
| 186 | writer.passed_steps(), |
| 187 | 4, |
| 188 | "scenario did not run: {AC1_SCENARIO}" |
| 189 | ); |
| 190 | } |
| 191 | |
| 192 | // --- AC2: Hidden user command is runnable but excluded from the palette --- |
| 193 | |
| 194 | #[derive(cucumber::World)] |
| 195 | #[world(init = Self::new)] |
| 196 | struct DiscoveryWorld02 { |
| 197 | tmpdir: Option<TempDir>, |
| 198 | app: Option<Box<App>>, |
| 199 | result: Option<CommandResult>, |
| 200 | entries: Option<Vec<CommandPaletteEntry>>, |
| 201 | } |
| 202 | |
| 203 | impl std::fmt::Debug for DiscoveryWorld02 { |
| 204 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 205 | f.debug_struct("DiscoveryWorld02") |
| 206 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 207 | .field("has_app", &self.app.is_some()) |
| 208 | .field("has_result", &self.result.is_some()) |
| 209 | .field("has_entries", &self.entries.is_some()) |
| 210 | .finish() |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | impl DiscoveryWorld02 { |
| 215 | fn new() -> Self { |
| 216 | Self { |
| 217 | tmpdir: None, |
| 218 | app: None, |
| 219 | result: None, |
| 220 | entries: None, |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | #[given("a workspace with a hidden user command")] |
| 226 | fn ac2_given_hidden(world: &mut DiscoveryWorld02) { |
| 227 | let tmpdir = TempDir::new().expect("AC2 TempDir"); |
| 228 | write_user_command( |
| 229 | &tmpdir, |
| 230 | "secret", |
| 231 | "---\ndescription: Internal workflow\nhidden: true\n---\nsecret $ARGUMENTS", |
| 232 | ); |
| 233 | let mut app = create_discovery_app(&tmpdir); |
| 234 | app.workspace = tmpdir.path().to_path_buf(); |
| 235 | commands::user_registry::reload(Some(tmpdir.path())); |
| 236 | world.tmpdir = Some(tmpdir); |
| 237 | world.app = Some(Box::new(app)); |
| 238 | } |
| 239 | |
| 240 | #[when("the user runs the hidden command directly")] |
| 241 | fn ac2_when_run_hidden(world: &mut DiscoveryWorld02) { |
| 242 | let app = world.app.as_deref_mut().expect("app should exist"); |
| 243 | let result = commands::execute("/secret now", app); |
| 244 | world.result = Some(result); |
| 245 | } |
| 246 | |
| 247 | #[then("the user command executes")] |
| 248 | fn ac2_then_user_executes(world: &mut DiscoveryWorld02) { |
| 249 | let result = world.result.as_ref().expect("result should exist"); |
| 250 | assert!(!result.is_error, "hidden command should run: {result:?}"); |
| 251 | assert_eq!(sent_message(result), "secret now"); |
| 252 | } |
| 253 | |
| 254 | #[when("the command palette is queried")] |
| 255 | fn ac2_when_palette_queried(world: &mut DiscoveryWorld02) { |
| 256 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 257 | world.entries = Some(palette_entries(tmpdir)); |
| 258 | } |
| 259 | |
| 260 | #[then("the hidden command is absent from the palette")] |
| 261 | fn ac2_then_hidden_absent(world: &mut DiscoveryWorld02) { |
| 262 | let entries = world.entries.as_ref().expect("entries should exist"); |
| 263 | assert!( |
| 264 | !entries.iter().any(|entry| entry.label == "/secret"), |
| 265 | "hidden command must not be listed" |
| 266 | ); |
| 267 | } |
| 268 | |
| 269 | #[tokio::test(flavor = "current_thread")] |
| 270 | async fn feat012_ac2_hidden_user_command_runnable_but_excluded_from_palette() { |
| 271 | let writer = DiscoveryWorld02::cucumber() |
| 272 | .fail_on_skipped() |
| 273 | .with_default_cli() |
| 274 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 275 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AC2_SCENARIO |
| 276 | }) |
| 277 | .await; |
| 278 | assert_eq!(writer.failed_steps(), 0, "scenario failed: {AC2_SCENARIO}"); |
| 279 | assert_eq!( |
| 280 | writer.skipped_steps(), |
| 281 | 0, |
| 282 | "scenario skipped: {AC2_SCENARIO}" |
| 283 | ); |
| 284 | assert_eq!( |
| 285 | writer.passed_steps(), |
| 286 | 5, |
| 287 | "scenario did not run: {AC2_SCENARIO}" |
| 288 | ); |
| 289 | } |
| 290 | |
| 291 | // --- AC3: Visible user command appears in matching slash completion --- |
| 292 | |
| 293 | #[derive(cucumber::World)] |
| 294 | #[world(init = Self::new)] |
| 295 | struct DiscoveryWorld03 { |
| 296 | tmpdir: Option<TempDir>, |
| 297 | hints: Option<Vec<SlashMenuEntry>>, |
| 298 | } |
| 299 | |
| 300 | impl std::fmt::Debug for DiscoveryWorld03 { |
| 301 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 302 | f.debug_struct("DiscoveryWorld03") |
| 303 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 304 | .field("has_hints", &self.hints.is_some()) |
| 305 | .finish() |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | impl DiscoveryWorld03 { |
| 310 | fn new() -> Self { |
| 311 | Self { |
| 312 | tmpdir: None, |
| 313 | hints: None, |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | #[given("a workspace with a visible user command that has a description")] |
| 319 | fn ac3_given_visible(world: &mut DiscoveryWorld03) { |
| 320 | let tmpdir = TempDir::new().expect("AC3 TempDir"); |
| 321 | write_user_command( |
| 322 | &tmpdir, |
| 323 | "deploy", |
| 324 | "---\ndescription: Deploy target\n---\ndeploy $ARGUMENTS", |
| 325 | ); |
| 326 | commands::user_registry::reload(Some(tmpdir.path())); |
| 327 | world.tmpdir = Some(tmpdir); |
| 328 | } |
| 329 | |
| 330 | #[when("slash completion is queried with a matching prefix")] |
| 331 | fn ac3_when_completion_matching(world: &mut DiscoveryWorld03) { |
| 332 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 333 | world.hints = Some(completion_hints(tmpdir, "/dep")); |
| 334 | } |
| 335 | |
| 336 | #[then("the user command appears exactly once with its description")] |
| 337 | fn ac3_then_user_completion_once(world: &mut DiscoveryWorld03) { |
| 338 | let hints = world.hints.as_ref().expect("hints should exist"); |
| 339 | let rows: Vec<_> = hints.iter().filter(|hint| hint.name == "/deploy").collect(); |
| 340 | assert_eq!(rows.len(), 1, "exactly one /deploy hint must exist"); |
| 341 | assert_eq!(rows[0].description, "Deploy target"); |
| 342 | } |
| 343 | |
| 344 | #[tokio::test(flavor = "current_thread")] |
| 345 | async fn feat012_ac3_visible_user_command_appears_in_matching_completion() { |
| 346 | let writer = DiscoveryWorld03::cucumber() |
| 347 | .fail_on_skipped() |
| 348 | .with_default_cli() |
| 349 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 350 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AC3_SCENARIO |
| 351 | }) |
| 352 | .await; |
| 353 | assert_eq!(writer.failed_steps(), 0, "scenario failed: {AC3_SCENARIO}"); |
| 354 | assert_eq!( |
| 355 | writer.skipped_steps(), |
| 356 | 0, |
| 357 | "scenario skipped: {AC3_SCENARIO}" |
| 358 | ); |
| 359 | assert_eq!( |
| 360 | writer.passed_steps(), |
| 361 | 3, |
| 362 | "scenario did not run: {AC3_SCENARIO}" |
| 363 | ); |
| 364 | } |
| 365 | |
| 366 | // --- AC4: Hidden user command is excluded from slash completion --- |
| 367 | |
| 368 | #[derive(cucumber::World)] |
| 369 | #[world(init = Self::new)] |
| 370 | struct DiscoveryWorld04 { |
| 371 | tmpdir: Option<TempDir>, |
| 372 | hints: Option<Vec<SlashMenuEntry>>, |
| 373 | } |
| 374 | |
| 375 | impl std::fmt::Debug for DiscoveryWorld04 { |
| 376 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 377 | f.debug_struct("DiscoveryWorld04") |
| 378 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 379 | .field("has_hints", &self.hints.is_some()) |
| 380 | .finish() |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | impl DiscoveryWorld04 { |
| 385 | fn new() -> Self { |
| 386 | Self { |
| 387 | tmpdir: None, |
| 388 | hints: None, |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | #[given("a workspace with a hidden user command")] |
| 394 | fn ac4_given_hidden(world: &mut DiscoveryWorld04) { |
| 395 | let tmpdir = TempDir::new().expect("AC4 TempDir"); |
| 396 | write_user_command( |
| 397 | &tmpdir, |
| 398 | "secret", |
| 399 | "---\ndescription: Internal workflow\nhidden: true\n---\nsecret $ARGUMENTS", |
| 400 | ); |
| 401 | commands::user_registry::reload(Some(tmpdir.path())); |
| 402 | world.tmpdir = Some(tmpdir); |
| 403 | } |
| 404 | |
| 405 | #[when("slash completion is queried for its prefix")] |
| 406 | fn ac4_when_completion_prefix(world: &mut DiscoveryWorld04) { |
| 407 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 408 | world.hints = Some(completion_hints(tmpdir, "/sec")); |
| 409 | } |
| 410 | |
| 411 | #[then("the hidden command is absent from slash completion")] |
| 412 | fn ac4_then_hidden_absent(world: &mut DiscoveryWorld04) { |
| 413 | let hints = world.hints.as_ref().expect("hints should exist"); |
| 414 | assert!( |
| 415 | !hints.iter().any(|hint| hint.name == "/secret"), |
| 416 | "hidden command must not be suggested" |
| 417 | ); |
| 418 | } |
| 419 | |
| 420 | #[tokio::test(flavor = "current_thread")] |
| 421 | async fn feat012_ac4_hidden_user_command_excluded_from_completion() { |
| 422 | let writer = DiscoveryWorld04::cucumber() |
| 423 | .fail_on_skipped() |
| 424 | .with_default_cli() |
| 425 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 426 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AC4_SCENARIO |
| 427 | }) |
| 428 | .await; |
| 429 | assert_eq!(writer.failed_steps(), 0, "scenario failed: {AC4_SCENARIO}"); |
| 430 | assert_eq!( |
| 431 | writer.skipped_steps(), |
| 432 | 0, |
| 433 | "scenario skipped: {AC4_SCENARIO}" |
| 434 | ); |
| 435 | assert_eq!( |
| 436 | writer.passed_steps(), |
| 437 | 3, |
| 438 | "scenario did not run: {AC4_SCENARIO}" |
| 439 | ); |
| 440 | } |
| 441 | |
| 442 | // --- AC5: User canonical shadow suppresses a built-in in both surfaces --- |
| 443 | |
| 444 | #[derive(cucumber::World)] |
| 445 | #[world(init = Self::new)] |
| 446 | struct DiscoveryWorld05 { |
| 447 | tmpdir: Option<TempDir>, |
| 448 | entries: Option<Vec<CommandPaletteEntry>>, |
| 449 | hints: Option<Vec<SlashMenuEntry>>, |
| 450 | } |
| 451 | |
| 452 | impl std::fmt::Debug for DiscoveryWorld05 { |
| 453 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 454 | f.debug_struct("DiscoveryWorld05") |
| 455 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 456 | .field("has_entries", &self.entries.is_some()) |
| 457 | .field("has_hints", &self.hints.is_some()) |
| 458 | .finish() |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | impl DiscoveryWorld05 { |
| 463 | fn new() -> Self { |
| 464 | Self { |
| 465 | tmpdir: None, |
| 466 | entries: None, |
| 467 | hints: None, |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | #[given("a workspace with a visible user command owning a built-in canonical token")] |
| 473 | fn ac5_given_canonical_shadow(world: &mut DiscoveryWorld05) { |
| 474 | let tmpdir = TempDir::new().expect("AC5 TempDir"); |
| 475 | write_user_command( |
| 476 | &tmpdir, |
| 477 | "my-help", |
| 478 | "---\nname: help\ndescription: My private help\n---\ncustom help $ARGUMENTS", |
| 479 | ); |
| 480 | commands::user_registry::reload(Some(tmpdir.path())); |
| 481 | world.tmpdir = Some(tmpdir); |
| 482 | } |
| 483 | |
| 484 | #[when("the command palette and slash completion are queried")] |
| 485 | fn ac5_when_both_queried(world: &mut DiscoveryWorld05) { |
| 486 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 487 | world.entries = Some(palette_entries(tmpdir)); |
| 488 | world.hints = Some(completion_hints(tmpdir, "/help")); |
| 489 | } |
| 490 | |
| 491 | #[then("only the user-owned discovery entry appears for that token")] |
| 492 | fn ac5_then_only_user_entry(world: &mut DiscoveryWorld05) { |
| 493 | let entries = world.entries.as_ref().expect("entries should exist"); |
| 494 | let palette_rows: Vec<_> = entries |
| 495 | .iter() |
| 496 | .filter(|entry| entry.label == "/help") |
| 497 | .collect(); |
| 498 | assert_eq!(palette_rows.len(), 1, "exactly one palette /help row"); |
| 499 | assert!( |
| 500 | palette_rows[0].description.contains("My private help"), |
| 501 | "palette row must be user-owned: {}", |
| 502 | palette_rows[0].description |
| 503 | ); |
| 504 | |
| 505 | let hints = world.hints.as_ref().expect("hints should exist"); |
| 506 | let completion_rows: Vec<_> = hints.iter().filter(|hint| hint.name == "/help").collect(); |
| 507 | assert_eq!(completion_rows.len(), 1, "exactly one completion /help row"); |
| 508 | } |
| 509 | |
| 510 | #[then("its metadata identifies the user command")] |
| 511 | fn ac5_then_user_metadata(world: &mut DiscoveryWorld05) { |
| 512 | let hints = world.hints.as_ref().expect("hints should exist"); |
| 513 | let completion_rows: Vec<_> = hints.iter().filter(|hint| hint.name == "/help").collect(); |
| 514 | assert_eq!(completion_rows.len(), 1); |
| 515 | assert!( |
| 516 | completion_rows[0].description.contains("My private help"), |
| 517 | "completion row must carry user metadata: {}", |
| 518 | completion_rows[0].description |
| 519 | ); |
| 520 | } |
| 521 | |
| 522 | #[tokio::test(flavor = "current_thread")] |
| 523 | async fn feat012_ac5_canonical_shadow_suppresses_builtin_in_both_surfaces() { |
| 524 | let writer = DiscoveryWorld05::cucumber() |
| 525 | .fail_on_skipped() |
| 526 | .with_default_cli() |
| 527 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 528 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AC5_SCENARIO |
| 529 | }) |
| 530 | .await; |
| 531 | assert_eq!(writer.failed_steps(), 0, "scenario failed: {AC5_SCENARIO}"); |
| 532 | assert_eq!( |
| 533 | writer.skipped_steps(), |
| 534 | 0, |
| 535 | "scenario skipped: {AC5_SCENARIO}" |
| 536 | ); |
| 537 | assert_eq!( |
| 538 | writer.passed_steps(), |
| 539 | 4, |
| 540 | "scenario did not run: {AC5_SCENARIO}" |
| 541 | ); |
| 542 | } |
| 543 | |
| 544 | // --- AC6: User command shadows a built-in alias without hiding canonical access --- |
| 545 | |
| 546 | #[derive(cucumber::World)] |
| 547 | #[world(init = Self::new)] |
| 548 | struct DiscoveryWorld06 { |
| 549 | tmpdir: Option<TempDir>, |
| 550 | alias_hints: Option<Vec<SlashMenuEntry>>, |
| 551 | canonical_hints: Option<Vec<SlashMenuEntry>>, |
| 552 | } |
| 553 | |
| 554 | impl std::fmt::Debug for DiscoveryWorld06 { |
| 555 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 556 | f.debug_struct("DiscoveryWorld06") |
| 557 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 558 | .field("has_alias_hints", &self.alias_hints.is_some()) |
| 559 | .field("has_canonical_hints", &self.canonical_hints.is_some()) |
| 560 | .finish() |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | impl DiscoveryWorld06 { |
| 565 | fn new() -> Self { |
| 566 | Self { |
| 567 | tmpdir: None, |
| 568 | alias_hints: None, |
| 569 | canonical_hints: None, |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | #[given("a workspace with a visible user command owning a built-in alias token")] |
| 575 | fn ac6_given_alias_shadow(world: &mut DiscoveryWorld06) { |
| 576 | let tmpdir = TempDir::new().expect("AC6 TempDir"); |
| 577 | write_user_command( |
| 578 | &tmpdir, |
| 579 | "image-review", |
| 580 | "---\ndescription: Review an image\nalias: image\n---\nreview image", |
| 581 | ); |
| 582 | commands::user_registry::reload(Some(tmpdir.path())); |
| 583 | world.tmpdir = Some(tmpdir); |
| 584 | } |
| 585 | |
| 586 | #[when("slash completion is queried for the shadowed alias")] |
| 587 | fn ac6_when_alias_completion(world: &mut DiscoveryWorld06) { |
| 588 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 589 | world.alias_hints = Some(completion_hints(tmpdir, "/image")); |
| 590 | } |
| 591 | |
| 592 | #[then("the user command appears and the aliased built-in does not")] |
| 593 | fn ac6_then_alias_owned(world: &mut DiscoveryWorld06) { |
| 594 | let hints = world |
| 595 | .alias_hints |
| 596 | .as_ref() |
| 597 | .expect("alias hints should exist"); |
| 598 | assert!( |
| 599 | hints.iter().any(|hint| hint.name == "/image-review"), |
| 600 | "user command must complete through the /image alias" |
| 601 | ); |
| 602 | assert!( |
| 603 | !hints.iter().any(|hint| hint.name == "/attach"), |
| 604 | "built-in /attach must not complete through shadowed /image alias" |
| 605 | ); |
| 606 | } |
| 607 | |
| 608 | #[when("slash completion is queried for the built-in canonical prefix")] |
| 609 | fn ac6_when_canonical_completion(world: &mut DiscoveryWorld06) { |
| 610 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 611 | world.canonical_hints = Some(completion_hints(tmpdir, "/att")); |
| 612 | } |
| 613 | |
| 614 | #[then("the built-in canonical command remains available")] |
| 615 | fn ac6_then_canonical_available(world: &mut DiscoveryWorld06) { |
| 616 | let hints = world |
| 617 | .canonical_hints |
| 618 | .as_ref() |
| 619 | .expect("canonical hints should exist"); |
| 620 | assert!( |
| 621 | hints.iter().any(|hint| hint.name == "/attach"), |
| 622 | "canonical /attach must remain available" |
| 623 | ); |
| 624 | } |
| 625 | |
| 626 | #[tokio::test(flavor = "current_thread")] |
| 627 | async fn feat012_ac6_alias_shadow_preserves_canonical_access() { |
| 628 | let writer = DiscoveryWorld06::cucumber() |
| 629 | .fail_on_skipped() |
| 630 | .with_default_cli() |
| 631 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 632 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AC6_SCENARIO |
| 633 | }) |
| 634 | .await; |
| 635 | assert_eq!(writer.failed_steps(), 0, "scenario failed: {AC6_SCENARIO}"); |
| 636 | assert_eq!( |
| 637 | writer.skipped_steps(), |
| 638 | 0, |
| 639 | "scenario skipped: {AC6_SCENARIO}" |
| 640 | ); |
| 641 | assert_eq!( |
| 642 | writer.passed_steps(), |
| 643 | 5, |
| 644 | "scenario did not run: {AC6_SCENARIO}" |
| 645 | ); |
| 646 | } |
| 647 | |
| 648 | // --- AT-010: Accepted user alias claims a built-in canonical token --- |
| 649 | |
| 650 | #[derive(cucumber::World)] |
| 651 | #[world(init = Self::new)] |
| 652 | struct DiscoveryWorld10 { |
| 653 | tmpdir: Option<TempDir>, |
| 654 | entries: Option<Vec<CommandPaletteEntry>>, |
| 655 | hints: Option<Vec<SlashMenuEntry>>, |
| 656 | } |
| 657 | |
| 658 | impl std::fmt::Debug for DiscoveryWorld10 { |
| 659 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 660 | f.debug_struct("DiscoveryWorld10") |
| 661 | .field("has_tmpdir", &self.tmpdir.is_some()) |
| 662 | .field("has_entries", &self.entries.is_some()) |
| 663 | .field("has_hints", &self.hints.is_some()) |
| 664 | .finish() |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | impl DiscoveryWorld10 { |
| 669 | fn new() -> Self { |
| 670 | Self { |
| 671 | tmpdir: None, |
| 672 | entries: None, |
| 673 | hints: None, |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | #[given( |
| 679 | "a workspace with a visible user command whose accepted alias equals a built-in canonical token" |
| 680 | )] |
| 681 | fn at010_given_alias_claims_canonical(world: &mut DiscoveryWorld10) { |
| 682 | let tmpdir = TempDir::new().expect("AT-010 TempDir"); |
| 683 | write_user_command( |
| 684 | &tmpdir, |
| 685 | "assistant", |
| 686 | "---\ndescription: My assistant\nalias: help\n---\nassistant", |
| 687 | ); |
| 688 | commands::user_registry::reload(Some(tmpdir.path())); |
| 689 | world.tmpdir = Some(tmpdir); |
| 690 | } |
| 691 | |
| 692 | #[when("the command palette and slash completion are queried for that token")] |
| 693 | fn at010_when_both_queried(world: &mut DiscoveryWorld10) { |
| 694 | let tmpdir = world.tmpdir.as_ref().expect("tmpdir should exist"); |
| 695 | world.entries = Some(palette_entries(tmpdir)); |
| 696 | world.hints = Some(completion_hints(tmpdir, "/help")); |
| 697 | } |
| 698 | |
| 699 | #[then("both surfaces suppress the built-in canonical entry")] |
| 700 | fn at010_then_both_suppress(world: &mut DiscoveryWorld10) { |
| 701 | let entries = world.entries.as_ref().expect("entries should exist"); |
| 702 | assert!( |
| 703 | !entries.iter().any(|entry| entry.label == "/help"), |
| 704 | "palette must suppress built-in /help" |
| 705 | ); |
| 706 | let hints = world.hints.as_ref().expect("hints should exist"); |
| 707 | assert!( |
| 708 | !hints.iter().any(|hint| hint.name == "/help"), |
| 709 | "completion must suppress built-in /help" |
| 710 | ); |
| 711 | } |
| 712 | |
| 713 | #[then("the user command is the only discovery entry for that token")] |
| 714 | fn at010_then_only_user_entry(world: &mut DiscoveryWorld10) { |
| 715 | let entries = world.entries.as_ref().expect("entries should exist"); |
| 716 | assert!( |
| 717 | entries.iter().any(|entry| entry.label == "/assistant"), |
| 718 | "user command must appear in the palette" |
| 719 | ); |
| 720 | let hints = world.hints.as_ref().expect("hints should exist"); |
| 721 | assert!( |
| 722 | hints.iter().any(|hint| hint.name == "/assistant"), |
| 723 | "user command must appear in completion" |
| 724 | ); |
| 725 | } |
| 726 | |
| 727 | #[tokio::test(flavor = "current_thread")] |
| 728 | async fn feat012_at010_alias_claims_builtin_canonical_token_consistently() { |
| 729 | let writer = DiscoveryWorld10::cucumber() |
| 730 | .fail_on_skipped() |
| 731 | .with_default_cli() |
| 732 | .filter_run(DISCOVERY_FEATURE_PATH, move |feature, _, scenario| { |
| 733 | feature.name == DISCOVERY_FEATURE_NAME && scenario.name == AT010_SCENARIO |
| 734 | }) |
| 735 | .await; |
| 736 | assert_eq!( |
| 737 | writer.failed_steps(), |
| 738 | 0, |
| 739 | "scenario failed: {AT010_SCENARIO}" |
| 740 | ); |
| 741 | assert_eq!( |
| 742 | writer.skipped_steps(), |
| 743 | 0, |
| 744 | "scenario skipped: {AT010_SCENARIO}" |
| 745 | ); |
| 746 | assert_eq!( |
| 747 | writer.passed_steps(), |
| 748 | 4, |
| 749 | "scenario did not run: {AT010_SCENARIO}" |
| 750 | ); |
| 751 | } |
| 752 |