A3: derive the pinned command and catalog key lists in tests
Each command module keeps its own COMMAND_IDS next to its commands; the engine listing test checks their union against the registry, so a missing or extra command still fails without one shared list. The menu and palette tests derive their expectation from the listing and check grouping and ordering rules; the catalog's runtime keys are scanned from the sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
da58c83158
commit
95fd9b926f
28 changed files with 329 additions and 262 deletions
|
|
@ -53,3 +53,8 @@ impl Command for Quit {
|
|||
Ok(Outcome::effect(Effect::Quit))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["app.about", "app.quit"];
|
||||
|
|
|
|||
|
|
@ -258,3 +258,9 @@ impl Command for List {
|
|||
Ok(Outcome::value(Value::Array(list)))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] =
|
||||
&["buffer.close", "buffer.edit", "buffer.get", "buffer.list"];
|
||||
|
|
|
|||
|
|
@ -201,3 +201,8 @@ impl Command for SaveAll {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["file.open", "file.save", "file.saveAll"];
|
||||
|
|
|
|||
|
|
@ -955,6 +955,21 @@ impl Command for CreateBranch {
|
|||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"git.branches",
|
||||
"git.checkout",
|
||||
"git.commit",
|
||||
"git.createBranch",
|
||||
"git.lastMessage",
|
||||
"git.show",
|
||||
"git.stage",
|
||||
"git.status",
|
||||
"git.unstage",
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -114,3 +114,8 @@ impl Command for Blame {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["git.blame"];
|
||||
|
|
|
|||
|
|
@ -449,6 +449,11 @@ impl Command for LineChanges {
|
|||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["git.lineChanges"];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -221,3 +221,8 @@ impl Command for ShowAt {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["git.log", "git.showAt", "git.showCommit"];
|
||||
|
|
|
|||
|
|
@ -208,3 +208,13 @@ impl Command for MarkResolved {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"git.conflictVersions",
|
||||
"git.markResolved",
|
||||
"git.merge",
|
||||
"git.mergeAbort",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -699,3 +699,18 @@ impl Command for RemoteRemove {
|
|||
start(state, command, Op::Remove(p.name))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"git.cancel",
|
||||
"git.clone",
|
||||
"git.fetch",
|
||||
"git.pull",
|
||||
"git.push",
|
||||
"git.remoteAdd",
|
||||
"git.remoteRemove",
|
||||
"git.remoteSetUrl",
|
||||
"git.remotes",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -219,3 +219,13 @@ impl Command for StashDrop {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"git.stash",
|
||||
"git.stashApply",
|
||||
"git.stashDrop",
|
||||
"git.stashList",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -516,3 +516,8 @@ fn symbol_item(hit: &SymbolHit<'_>, container: bool) -> Value {
|
|||
}
|
||||
item
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["goto.class", "goto.file", "goto.symbol", "index.status"];
|
||||
|
|
|
|||
|
|
@ -841,6 +841,11 @@ fn cap(text: &str, max: usize) -> String {
|
|||
text.get(..end).unwrap_or("").to_string()
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["lsp.completion", "lsp.hover", "lsp.signatureHelp"];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
|
|
|||
|
|
@ -135,3 +135,9 @@ impl Command for Log {
|
|||
Ok(Outcome::value(json!({ "lines": state.lsp.log() })))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] =
|
||||
&["diagnostics.list", "lsp.log", "lsp.restart", "lsp.status"];
|
||||
|
|
|
|||
|
|
@ -780,6 +780,16 @@ fn notify_summary(state: &mut State, new_name: &str, applied: &edit::Applied) {
|
|||
);
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"lsp.definition",
|
||||
"lsp.prepareRename",
|
||||
"lsp.references",
|
||||
"lsp.rename",
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -80,3 +80,33 @@ pub fn register_builtins(registry: &mut Registry) -> Result<(), EngineError> {
|
|||
git_stash::register(registry)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The id lists of every module that registers built-in commands, one entry
|
||||
/// per module. Each module keeps its own list next to its commands, so new
|
||||
/// commands in different modules never touch the same lines.
|
||||
#[cfg(test)]
|
||||
pub(crate) const BUILTIN_COMMAND_IDS: &[&[&str]] = &[
|
||||
app::COMMAND_IDS,
|
||||
buffer::COMMAND_IDS,
|
||||
file::COMMAND_IDS,
|
||||
git::COMMAND_IDS,
|
||||
git_blame::COMMAND_IDS,
|
||||
git_lines::COMMAND_IDS,
|
||||
git_log::COMMAND_IDS,
|
||||
git_merge::COMMAND_IDS,
|
||||
git_remote::COMMAND_IDS,
|
||||
git_stash::COMMAND_IDS,
|
||||
goto::COMMAND_IDS,
|
||||
lsp_assist::COMMAND_IDS,
|
||||
lsp_diagnostics::COMMAND_IDS,
|
||||
lsp_nav::COMMAND_IDS,
|
||||
project::COMMAND_IDS,
|
||||
recovery::COMMAND_IDS,
|
||||
search::COMMAND_IDS,
|
||||
settings::COMMAND_IDS,
|
||||
syntax::COMMAND_IDS,
|
||||
terminal::COMMAND_IDS,
|
||||
theme::COMMAND_IDS,
|
||||
toolchain::COMMAND_IDS,
|
||||
ui::COMMAND_IDS,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -230,3 +230,13 @@ impl Command for Children {
|
|||
})))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"project.children",
|
||||
"project.close",
|
||||
"project.open",
|
||||
"project.openDialog",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -204,3 +204,8 @@ impl Command for Discard {
|
|||
Ok(Outcome::value(json!({ "discarded": discarded })))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["recovery.discard", "recovery.list", "recovery.restore"];
|
||||
|
|
|
|||
|
|
@ -302,3 +302,8 @@ impl From<lutra_search::Match> for SearchMatch {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["search.cancel", "search.find"];
|
||||
|
|
|
|||
|
|
@ -167,3 +167,13 @@ fn finish(
|
|||
.ok_or_else(|| EngineError::Internal(format!("setting vanished: {key}")))?;
|
||||
Ok(Outcome::value(json!({ "value": value })))
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"settings.get",
|
||||
"settings.list",
|
||||
"settings.reset",
|
||||
"settings.set",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -581,6 +581,11 @@ impl Command for OutlineCommand {
|
|||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["syntax.outline"];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -400,6 +400,16 @@ pub fn pump(state: &mut State) {
|
|||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &[
|
||||
"terminal.close",
|
||||
"terminal.create",
|
||||
"terminal.input",
|
||||
"terminal.resize",
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
|
|
|||
|
|
@ -100,3 +100,8 @@ impl Command for SystemPreference {
|
|||
Ok(Outcome::value(Value::Object(fields)))
|
||||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["theme.list", "theme.systemPreference"];
|
||||
|
|
|
|||
|
|
@ -639,6 +639,11 @@ impl Command for DownloadPhpactor {
|
|||
}
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["toolchain.downloadPhpactor", "toolchain.status"];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::{Read, Write};
|
||||
|
|
|
|||
|
|
@ -182,6 +182,11 @@ pub fn dispatch(state: &mut State, id: &str, params: Value) -> Option<Outcome> {
|
|||
Some(Outcome::value(Value::Null))
|
||||
}
|
||||
|
||||
/// The ids of the commands this module registers, checked against the
|
||||
/// registry by the engine's listing test. Add a new command's id here.
|
||||
#[cfg(test)]
|
||||
pub(crate) const COMMAND_IDS: &[&str] = &["ui.registerCommands"];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::valid_id;
|
||||
|
|
|
|||
|
|
@ -467,91 +467,23 @@ mod tests {
|
|||
let mut engine = Engine::new().unwrap();
|
||||
engine.register(Box::new(Disabled)).unwrap();
|
||||
let list = engine.list_commands();
|
||||
let ids: Vec<_> = list.iter().map(|c| c.id.as_str()).collect();
|
||||
assert_eq!(
|
||||
ids,
|
||||
vec![
|
||||
"app.about",
|
||||
"app.quit",
|
||||
"buffer.close",
|
||||
"buffer.edit",
|
||||
"buffer.get",
|
||||
"buffer.list",
|
||||
"diagnostics.list",
|
||||
"file.open",
|
||||
"file.save",
|
||||
"file.saveAll",
|
||||
"git.blame",
|
||||
"git.branches",
|
||||
"git.cancel",
|
||||
"git.checkout",
|
||||
"git.clone",
|
||||
"git.commit",
|
||||
"git.conflictVersions",
|
||||
"git.createBranch",
|
||||
"git.fetch",
|
||||
"git.lastMessage",
|
||||
"git.lineChanges",
|
||||
"git.log",
|
||||
"git.markResolved",
|
||||
"git.merge",
|
||||
"git.mergeAbort",
|
||||
"git.pull",
|
||||
"git.push",
|
||||
"git.remoteAdd",
|
||||
"git.remoteRemove",
|
||||
"git.remoteSetUrl",
|
||||
"git.remotes",
|
||||
"git.show",
|
||||
"git.showAt",
|
||||
"git.showCommit",
|
||||
"git.stage",
|
||||
"git.stash",
|
||||
"git.stashApply",
|
||||
"git.stashDrop",
|
||||
"git.stashList",
|
||||
"git.status",
|
||||
"git.unstage",
|
||||
"goto.class",
|
||||
"goto.file",
|
||||
"goto.symbol",
|
||||
"index.status",
|
||||
"lsp.completion",
|
||||
"lsp.definition",
|
||||
"lsp.hover",
|
||||
"lsp.log",
|
||||
"lsp.prepareRename",
|
||||
"lsp.references",
|
||||
"lsp.rename",
|
||||
"lsp.restart",
|
||||
"lsp.signatureHelp",
|
||||
"lsp.status",
|
||||
"project.children",
|
||||
"project.close",
|
||||
"project.open",
|
||||
"project.openDialog",
|
||||
"recovery.discard",
|
||||
"recovery.list",
|
||||
"recovery.restore",
|
||||
"search.cancel",
|
||||
"search.find",
|
||||
"settings.get",
|
||||
"settings.list",
|
||||
"settings.reset",
|
||||
"settings.set",
|
||||
"syntax.outline",
|
||||
"terminal.close",
|
||||
"terminal.create",
|
||||
"terminal.input",
|
||||
"terminal.resize",
|
||||
"test.disabled",
|
||||
"theme.list",
|
||||
"theme.systemPreference",
|
||||
"toolchain.downloadPhpactor",
|
||||
"toolchain.status",
|
||||
"ui.registerCommands",
|
||||
]
|
||||
let ids: Vec<&str> = list.iter().map(|c| c.id.as_str()).collect();
|
||||
let mut sorted = ids.clone();
|
||||
sorted.sort_unstable();
|
||||
assert_eq!(ids, sorted, "the listing is sorted by id");
|
||||
let mut expected: Vec<&str> = cmd::BUILTIN_COMMAND_IDS
|
||||
.iter()
|
||||
.flat_map(|ids| ids.iter().copied())
|
||||
.chain(["test.disabled"])
|
||||
.collect();
|
||||
expected.sort_unstable();
|
||||
let missing: Vec<_> = expected.iter().filter(|id| !ids.contains(id)).collect();
|
||||
let extra: Vec<_> = ids.iter().filter(|id| !expected.contains(id)).collect();
|
||||
assert!(
|
||||
missing.is_empty() && extra.is_empty(),
|
||||
"registered but not in a module's COMMAND_IDS: {extra:?}; listed in COMMAND_IDS but not registered: {missing:?}"
|
||||
);
|
||||
assert_eq!(ids, expected, "no id is listed twice");
|
||||
let by_id = |id: &str| list.iter().find(|c| c.id == id).unwrap();
|
||||
let quit = by_id("app.quit");
|
||||
assert_eq!(quit.default_shortcut.as_deref(), Some("Mod+Q"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue