Files
photocraft/crates/engine/tests/command_lookup.rs
Elvis33LEandClaude Opus 5.5 f4d489eb96 Command lookup: index registered and shell command IDs (#1156)
Opening a menu or the command palette looked up command ids by scanning the whole command
list. The registry now keeps its ordered specs and an id-to-index map in one OnceLock (first
match wins for a duplicate id), and is_live caches the shell command ids in a set. A batch of
917 lookups drops from 0.157 ms to 0.013 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 01:26:44 -04:00

18 lines
756 B
Rust

//! Index lookups must return the same spec, in the same order, as the registry's public slice.
use photocraft_engine::commands;
#[test]
fn every_lookup_matches_the_first_linear_match() {
let specs = commands::command_specs();
for spec in specs {
let linear = specs.iter().find(|s| s.id == spec.id).unwrap();
assert!(std::ptr::eq(commands::find(spec.id).unwrap(), linear), "{}", spec.id);
// The id need not be a static string: control/MCP dispatch owns its input.
let owned = spec.id.to_string();
assert!(std::ptr::eq(commands::find(&owned).unwrap(), linear));
}
for id in ["", "missing.command", "FILE.NEW", "file.new\0", "💾"] {
assert!(commands::find(id).is_none(), "{id:?}");
}
}