diff --git a/crates/engine/src/cmd/app.rs b/crates/engine/src/cmd/app.rs index 2f18e4e..8a04e75 100644 --- a/crates/engine/src/cmd/app.rs +++ b/crates/engine/src/cmd/app.rs @@ -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"]; diff --git a/crates/engine/src/cmd/buffer.rs b/crates/engine/src/cmd/buffer.rs index 68fb7ec..6dae200 100644 --- a/crates/engine/src/cmd/buffer.rs +++ b/crates/engine/src/cmd/buffer.rs @@ -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"]; diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 74d71aa..fc35781 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -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"]; diff --git a/crates/engine/src/cmd/git.rs b/crates/engine/src/cmd/git.rs index 3ad6f81..a5b72be 100644 --- a/crates/engine/src/cmd/git.rs +++ b/crates/engine/src/cmd/git.rs @@ -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::*; diff --git a/crates/engine/src/cmd/git_blame.rs b/crates/engine/src/cmd/git_blame.rs index 72fc4c4..3a1966e 100644 --- a/crates/engine/src/cmd/git_blame.rs +++ b/crates/engine/src/cmd/git_blame.rs @@ -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"]; diff --git a/crates/engine/src/cmd/git_lines.rs b/crates/engine/src/cmd/git_lines.rs index 7fb751d..48871ef 100644 --- a/crates/engine/src/cmd/git_lines.rs +++ b/crates/engine/src/cmd/git_lines.rs @@ -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::*; diff --git a/crates/engine/src/cmd/git_log.rs b/crates/engine/src/cmd/git_log.rs index 64022d2..32ae371 100644 --- a/crates/engine/src/cmd/git_log.rs +++ b/crates/engine/src/cmd/git_log.rs @@ -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"]; diff --git a/crates/engine/src/cmd/git_merge.rs b/crates/engine/src/cmd/git_merge.rs index 838efd0..72cd646 100644 --- a/crates/engine/src/cmd/git_merge.rs +++ b/crates/engine/src/cmd/git_merge.rs @@ -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", +]; diff --git a/crates/engine/src/cmd/git_remote.rs b/crates/engine/src/cmd/git_remote.rs index 827db5a..fe9f5ab 100644 --- a/crates/engine/src/cmd/git_remote.rs +++ b/crates/engine/src/cmd/git_remote.rs @@ -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", +]; diff --git a/crates/engine/src/cmd/git_stash.rs b/crates/engine/src/cmd/git_stash.rs index cdefd97..3757251 100644 --- a/crates/engine/src/cmd/git_stash.rs +++ b/crates/engine/src/cmd/git_stash.rs @@ -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", +]; diff --git a/crates/engine/src/cmd/goto.rs b/crates/engine/src/cmd/goto.rs index 83bf2a9..22eb88d 100644 --- a/crates/engine/src/cmd/goto.rs +++ b/crates/engine/src/cmd/goto.rs @@ -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"]; diff --git a/crates/engine/src/cmd/lsp_assist.rs b/crates/engine/src/cmd/lsp_assist.rs index d45ae26..df1a313 100644 --- a/crates/engine/src/cmd/lsp_assist.rs +++ b/crates/engine/src/cmd/lsp_assist.rs @@ -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; diff --git a/crates/engine/src/cmd/lsp_diagnostics.rs b/crates/engine/src/cmd/lsp_diagnostics.rs index 7f41623..ce8f784 100644 --- a/crates/engine/src/cmd/lsp_diagnostics.rs +++ b/crates/engine/src/cmd/lsp_diagnostics.rs @@ -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"]; diff --git a/crates/engine/src/cmd/lsp_nav.rs b/crates/engine/src/cmd/lsp_nav.rs index 36fe76e..b5dcf52 100644 --- a/crates/engine/src/cmd/lsp_nav.rs +++ b/crates/engine/src/cmd/lsp_nav.rs @@ -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::*; diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs index 1b82e60..8fc5c18 100644 --- a/crates/engine/src/cmd/mod.rs +++ b/crates/engine/src/cmd/mod.rs @@ -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, +]; diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index a94b379..102129e 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -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", +]; diff --git a/crates/engine/src/cmd/recovery.rs b/crates/engine/src/cmd/recovery.rs index d81835a..ad8d43a 100644 --- a/crates/engine/src/cmd/recovery.rs +++ b/crates/engine/src/cmd/recovery.rs @@ -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"]; diff --git a/crates/engine/src/cmd/search.rs b/crates/engine/src/cmd/search.rs index 91c92c2..d5f7ff7 100644 --- a/crates/engine/src/cmd/search.rs +++ b/crates/engine/src/cmd/search.rs @@ -302,3 +302,8 @@ impl From 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"]; diff --git a/crates/engine/src/cmd/settings.rs b/crates/engine/src/cmd/settings.rs index 84c31a1..520e5c5 100644 --- a/crates/engine/src/cmd/settings.rs +++ b/crates/engine/src/cmd/settings.rs @@ -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", +]; diff --git a/crates/engine/src/cmd/syntax.rs b/crates/engine/src/cmd/syntax.rs index 38d3cf6..2ea7253 100644 --- a/crates/engine/src/cmd/syntax.rs +++ b/crates/engine/src/cmd/syntax.rs @@ -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::*; diff --git a/crates/engine/src/cmd/terminal.rs b/crates/engine/src/cmd/terminal.rs index 6561a1e..9776385 100644 --- a/crates/engine/src/cmd/terminal.rs +++ b/crates/engine/src/cmd/terminal.rs @@ -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; diff --git a/crates/engine/src/cmd/theme.rs b/crates/engine/src/cmd/theme.rs index c6acc34..fb09f38 100644 --- a/crates/engine/src/cmd/theme.rs +++ b/crates/engine/src/cmd/theme.rs @@ -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"]; diff --git a/crates/engine/src/cmd/toolchain.rs b/crates/engine/src/cmd/toolchain.rs index 0025290..b9ca990 100644 --- a/crates/engine/src/cmd/toolchain.rs +++ b/crates/engine/src/cmd/toolchain.rs @@ -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}; diff --git a/crates/engine/src/cmd/ui.rs b/crates/engine/src/cmd/ui.rs index 8999fd0..2af76c2 100644 --- a/crates/engine/src/cmd/ui.rs +++ b/crates/engine/src/cmd/ui.rs @@ -182,6 +182,11 @@ pub fn dispatch(state: &mut State, id: &str, params: Value) -> Option { 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; diff --git a/crates/engine/src/engine.rs b/crates/engine/src/engine.rs index 51f856b..6cf84cb 100644 --- a/crates/engine/src/engine.rs +++ b/crates/engine/src/engine.rs @@ -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")); diff --git a/ui/tests/i18n/catalog.test.ts b/ui/tests/i18n/catalog.test.ts index 72f6166..617e6a2 100644 --- a/ui/tests/i18n/catalog.test.ts +++ b/ui/tests/i18n/catalog.test.ts @@ -38,108 +38,85 @@ const usedKeys = sourceFiles(SRC).flatMap((file) => })), ); +/** Root of the repository. */ +const REPO = join(SRC, "..", ".."); + +/** + * Lists the Rust files below a directory, leaving out `tests` directories + * and build output. + * + * @param dir - the directory. + */ +function rustFiles(dir: string): string[] { + return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { + const path = join(dir, entry.name); + if (entry.isDirectory()) { + return ["tests", "target", "node_modules"].includes(entry.name) ? [] : rustFiles(path); + } + return entry.name.endsWith(".rs") ? [path] : []; + }); +} + +/** + * The shipped part of a Rust file: everything before its unit test module. + * + * @param file - the path. + */ +function shippedRust(file: string): string { + return readFileSync(file, "utf8").replace(/\r\n/g, "\n").split("\n#[cfg(test)]\nmod tests")[0] ?? ""; +} + +/** + * Turns a settings enum value into its key segment (`lutra-dark` → + * `lutraDark`). + * + * @param value - the value as the engine stores it. + */ +function camel(value: string): string { + return value.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase()); +} + /** * Keys the source never passes to `t` literally because they arrive at - * runtime: theme labels from `theme.list`, the settings' `labelKey`, - * `descriptionKey`, section names and enum value names from - * `settings.list`, the `messageKey` of - * `notification` events (engine and desktop host), the keys the - * notifications store passes through a constant, and the Changes - * window's commit toasts (M4.2), the branch toasts (M4.5), the merge - * toasts (M4.8) and the remote toasts (M4.10), passed as - * `messageKey`. + * runtime, derived from the source so new ones need no list here: + * + * - any `notification.*` literal: the `messageKey` of `notification` + * events (engine and desktop host) and of the toasts the frontend raises; + * - Rust `*_key: "…"` fields: theme labels and the settings' `labelKey` + * and `descriptionKey`; + * - per settings definition, its section name (`settings.section.`) and + * each enum value (`settings..value.`). */ -const RUNTIME_KEYS = new Set([ - "notification.command.failed", - "notification.lsp.failed", - "notification.lsp.message", - "notification.lsp.renamed", - "notification.project.notLocal", - "notification.project.openFailed", - "notification.project.unsavedChanges", - "notification.recovery.corrupt", - "notification.recovery.unavailable", - "notification.recovery.writeFailed", - "notification.save.failed", - "notification.vcs.branchCreated", - "notification.vcs.checkedOut", - "notification.vcs.checkoutFailed", - "notification.vcs.checkoutNotSaved", - "notification.vcs.historyNoFile", - "notification.vcs.commitNotSaved", - "notification.vcs.committed", - "notification.vcs.mergeAborted", - "notification.vcs.mergeConflicts", - "notification.vcs.mergeFailed", - "notification.vcs.mergeNotSaved", - "notification.vcs.mergeUpToDate", - "notification.vcs.merged", - "notification.vcs.newBranchFailed", - "notification.vcs.cloned", - "notification.vcs.fetchFailed", - "notification.vcs.fetched", - "notification.vcs.pullFailed", - "notification.vcs.pullNotSaved", - "notification.vcs.pulled", - "notification.vcs.pushFailed", - "notification.vcs.pushed", - "notification.vcs.pushedUpstream", - "notification.vcs.remoteCancelled", - "notification.vcs.resolved", - "notification.vcs.stashApplied", - "notification.vcs.stashDropped", - "notification.vcs.stashPopped", - "notification.vcs.stashed", - "notification.settings.corrupt", - "notification.settings.corruptNotMoved", - "notification.settings.unavailable", - "notification.toolchain.downloadDone", - "notification.toolchain.downloadFailed", - "notification.toolchain.downloadStarted", - "notification.toolchain.phpMissing", - "notification.vfs.pumpFailed", - "notification.watch.failed", - "settings.appearance.theme.description", - "settings.appearance.theme.label", - "settings.appearance.theme.value.lutraDark", - "settings.appearance.theme.value.lutraLight", - "settings.appearance.theme.value.system", - "settings.editor.autosave.idleSeconds.description", - "settings.editor.autosave.idleSeconds.label", - "settings.editor.autosave.onBlur.description", - "settings.editor.autosave.onBlur.label", - "settings.editor.autosave.onTabSwitch.description", - "settings.editor.autosave.onTabSwitch.label", - "settings.editor.completion.autoPopup.description", - "settings.editor.completion.autoPopup.label", - "settings.editor.completion.delayMs.description", - "settings.editor.completion.delayMs.label", - "settings.editor.fontSize.description", - "settings.editor.fontSize.label", - "settings.editor.hover.delayMs.description", - "settings.editor.hover.delayMs.label", - "settings.git.executable.description", - "settings.git.executable.label", - "settings.git.pull.mode.description", - "settings.git.pull.mode.label", - "settings.git.pull.mode.value.merge", - "settings.git.pull.mode.value.rebase", - "settings.php.executable.description", - "settings.php.executable.label", - "settings.phpactor.autoDownload.description", - "settings.phpactor.autoDownload.label", - "settings.phpactor.path.description", - "settings.phpactor.path.label", - "settings.section.appearance", - "settings.section.editor", - "settings.section.git", - "settings.section.php", - "settings.ui.language.description", - "settings.ui.language.label", - "settings.ui.language.value.en", - "theme.lutraDark", - "theme.lutraLight", -]); +const RUNTIME_KEYS = (() => { + const keys = new Set(); + const add = (text: string, pattern: RegExp): void => { + for (const m of text.matchAll(pattern)) { + keys.add(m[1] ?? ""); + } + }; + for (const file of sourceFiles(SRC)) { + add(readFileSync(file, "utf8"), /["'`](notification\.[A-Za-z0-9.]+)["'`]/g); + } + for (const file of [...rustFiles(join(REPO, "crates")), ...rustFiles(join(REPO, "apps"))]) { + const text = shippedRust(file); + add(text, /"(notification\.[A-Za-z0-9.]+)"/g); + add(text, /\b[a-z]+_key:\s*"([a-z][A-Za-z0-9.]*)"/g); + for (const def of text.matchAll(/\bDef\s*\{([\s\S]*?)\n\s*\},?\n/g)) { + const body = def[1] ?? ""; + const key = /\bkey:\s*"([^"]+)"/.exec(body)?.[1]; + const section = /\bsection:\s*"([^"]+)"/.exec(body)?.[1]; + if (section !== undefined) { + keys.add(`settings.section.${section}`); + } + const values = /Kind::Enum\(&\[([^\]]*)\]\)/.exec(body)?.[1] ?? ""; + for (const value of values.matchAll(/"([^"]+)"/g)) { + keys.add(`settings.${key ?? ""}.value.${camel(value[1] ?? "")}`); + } + } + } + keys.delete(""); + return keys; +})(); afterEach(() => { vi.restoreAllMocks(); @@ -206,6 +183,19 @@ describe("en.json", () => { expect(missing).toEqual([]); }); + it("finds the runtime keys of every source", () => { + for (const key of [ + "notification.vcs.committed", + "notification.project.unsavedChanges", + "settings.editor.fontSize.label", + "settings.section.git", + "settings.appearance.theme.value.lutraDark", + "theme.lutraLight", + ]) { + expect(RUNTIME_KEYS.has(key), key).toBe(true); + } + }); + it("has every runtime key", () => { expect([...RUNTIME_KEYS].filter((key) => !hasMessage(key))).toEqual([]); }); diff --git a/ui/tests/menu/AppMenu.test.ts b/ui/tests/menu/AppMenu.test.ts index 2943641..9fc76fa 100644 --- a/ui/tests/menu/AppMenu.test.ts +++ b/ui/tests/menu/AppMenu.test.ts @@ -255,49 +255,32 @@ describe("AppMenu", () => { expect(menu.find("[data-test=menu-button]").attributes("aria-expanded")).toBe("true"); const headings = [...document.querySelectorAll("[data-test=menu-group]")].map((g) => g.querySelector(".app-menu__heading")?.textContent.trim()); expect(headings).toEqual(["File", "Edit", "View", "Go", "Git", "Help"]); - expect(itemIds()).toEqual([ + const listed = listing() as { id: string; menuPath: string | null }[]; + const withPath = listed.filter((c) => c.menuPath !== null); + expect([...itemIds()].sort()).toEqual(withPath.map((c) => c.id).sort()); + const groups = [...document.querySelectorAll("[data-test=menu-group]")].map((g) => ({ + heading: g.querySelector(".app-menu__heading")?.textContent.trim() ?? "", + ids: [...g.querySelectorAll("[data-test=menu-item]")].map((el) => el.dataset.command ?? ""), + labels: [...g.querySelectorAll("[data-test=menu-item]")].map((el) => el.querySelector(".app-menu__label")?.textContent.trim() ?? ""), + })); + for (const group of groups) { + for (const id of group.ids) { + expect(withPath.find((c) => c.id === id)?.menuPath?.split("/")[0], id).toBe(group.heading); + } + } + expect(groups.find((g) => g.heading === "File")?.ids).toEqual([ "project.openDialog", "file.save", "file.saveAll", "buffer.close", "project.close", "app.quit", - "editor.complete", - "editor.parameterInfo", - "editor.quickDocumentation", - "palette.open", - "view.toggleProjectTree", - "view.toggleStructure", - "find.open", - "terminal.open", - "problems.open", - "settings.open", - "goto.fileOpen", - "goto.classOpen", - "goto.symbolOpen", - "vcs.abortMerge", - "vcs.toggleBlame", - "vcs.branches", - "vcs.openChanges", - "vcs.clone", - "vcs.commit", - "vcs.fetch", - "vcs.showLog", - "vcs.manageRemotes", - "vcs.merge", - "vcs.newBranch", - "vcs.nextChange", - "vcs.previousChange", - "vcs.pull", - "vcs.push", - "vcs.refresh", - "vcs.resolveConflicts", - "vcs.showDiff", - "vcs.showHistory", - "vcs.stash", - "vcs.showStashes", - "app.about", ]); + expect(groups.find((g) => g.heading === "Go")?.ids).toEqual(["goto.fileOpen", "goto.classOpen", "goto.symbolOpen"]); + const git = groups.find((g) => g.heading === "Git")?.labels ?? []; + expect(git.length).toBeGreaterThan(1); + expect(git).toEqual([...git].sort((x, y) => x.localeCompare(y))); + expect(itemIds().at(-1)).toBe("app.about"); const close = document.querySelector("[data-command='buffer.close']"); expect(close?.textContent).toContain("Close Tab"); expect(close?.querySelector("[data-test=menu-shortcut]")?.textContent).toBe("Ctrl+W"); diff --git a/ui/tests/palette/CommandPalette.test.ts b/ui/tests/palette/CommandPalette.test.ts index e771e54..c5486f8 100644 --- a/ui/tests/palette/CommandPalette.test.ts +++ b/ui/tests/palette/CommandPalette.test.ts @@ -257,49 +257,14 @@ describe("CommandPalette", () => { await press(PALETTE_KEY); expect(wrapper.find("[data-test=palette]").exists()).toBe(true); expect(document.activeElement).toBe(wrapper.find("[data-test=palette-input]").element); - expect(rows(wrapper)).toEqual([ - "vcs.abortMerge", - "vcs.toggleBlame", - "vcs.branches", - "vcs.openChanges", - "vcs.checkout", - "vcs.clone", - "project.close", - "palette.open", - "vcs.commit", - "editor.complete", - "vcs.fetch", - "find.open", - "goto.classOpen", - "goto.fileOpen", - "goto.symbolOpen", - "vcs.showLog", - "vcs.manageRemotes", - "vcs.merge", - "vcs.newBranch", - "vcs.nextChange", - "project.openDialog", - "menu.open", - "editor.parameterInfo", - "vcs.previousChange", - "problems.open", - "vcs.pull", - "vcs.push", - "editor.quickDocumentation", - "app.quit", - "vcs.refresh", - "vcs.resolveConflicts", - "editor.reveal", - "settings.open", - "vcs.showCommit", - "vcs.showDiff", - "vcs.showHistory", - "view.toggleProjectTree", - "view.toggleStructure", - "vcs.stash", - "vcs.showStashes", - "terminal.open", - ]); + const offered = (listing() as { id: string; menuPath: string | null; defaultShortcut: string | null; ui: boolean }[]) + .filter((c) => c.ui || c.menuPath !== null || c.defaultShortcut !== null) + .map((c) => c.id); + expect(offered).toContain("palette.open"); + expect(offered).not.toContain("buffer.edit"); + expect([...rows(wrapper)].sort()).toEqual([...offered].sort()); + const labels = wrapper.findAll("[data-test=palette-row] .palette__label").map((label) => label.text()); + expect(labels).toEqual([...labels].sort((x, y) => x.localeCompare(y))); const quit = wrapper.find("[data-command='app.quit']"); expect(quit.find("[data-test=palette-shortcut]").text()).toBe("Ctrl+Q"); expect(quit.text()).toContain("Quit");