From ec8d0682dc36311d20167a2f7a299bb5f74554c2 Mon Sep 17 00:00:00 2001 From: leynos Date: Mon, 1 Jun 2026 00:28:09 +0200 Subject: [PATCH] Snapshot localized CLI help output (#290) Add `insta` coverage for localized top-level help in `en-US` and `es-ES`. Assert the `--config` flag and resolved Fluent description before snapshotting the full rendered help output so future CLI or localisation drift is caught in review. --- src/cli/mod.rs | 39 ++++++++ .../cli/netsuke__cli__tests__help_en_us.snap | 96 +++++++++++++++++++ .../cli/netsuke__cli__tests__help_es_es.snap | 96 +++++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 src/snapshots/cli/netsuke__cli__tests__help_en_us.snap create mode 100644 src/snapshots/cli/netsuke__cli__tests__help_es_es.snap diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 7553f245..977fe6af 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -313,7 +313,12 @@ where #[cfg(test)] mod tests { use super::*; + use crate::cli_localization::build_localizer; + use crate::snapshot_test_support::snapshot_settings; use crate::theme::ThemePreference; + use insta::assert_snapshot; + use rstest::rstest; + use test_support::fluent::normalize_fluent_isolates; #[test] fn config_projection_preserves_shared_preferences() { @@ -348,4 +353,38 @@ mod tests { assert_eq!(cli.config(), expected); } + + #[rstest] + #[case::en_us( + "en-US", + "help_en_us", + "Path to a configuration file, bypassing automatic discovery." + )] + #[case::es_es( + "es-ES", + "help_es_es", + "Ruta a un archivo de configuración, omitiendo la detección automática." + )] + fn localized_help_snapshots_include_config_flag( + #[case] locale: &str, + #[case] snapshot_name: &str, + #[case] config_help: &str, + ) { + let localizer = build_localizer(Some(locale)); + let mut command = localize_command(Cli::command(), localizer.as_ref()); + let rendered_help = command.render_long_help().to_string(); + let normalized_help = normalize_fluent_isolates(&rendered_help); + + assert!( + normalized_help.contains("--config "), + "localized help for {locale} should include the config flag" + ); + assert!( + normalized_help.contains(config_help), + "localized help for {locale} should include the config flag description" + ); + snapshot_settings("cli").bind(|| { + assert_snapshot!(snapshot_name, normalized_help); + }); + } } diff --git a/src/snapshots/cli/netsuke__cli__tests__help_en_us.snap b/src/snapshots/cli/netsuke__cli__tests__help_en_us.snap new file mode 100644 index 00000000..20918035 --- /dev/null +++ b/src/snapshots/cli/netsuke__cli__tests__help_en_us.snap @@ -0,0 +1,96 @@ +--- +source: src/cli/mod.rs +expression: normalized_help +--- +Netsuke transforms YAML + Jinja manifests into reproducible Ninja graphs and runs Ninja with safe defaults. + +Usage: netsuke [OPTIONS] [COMMAND] + +Commands: + build Build targets defined in the manifest (default). + clean Remove build artefacts via Ninja. + graph Emit the dependency graph in DOT format. + manifest Write the generated Ninja manifest without running Ninja. + help Print this message or the help of the given subcommand(s) + +Options: + -f, --file + Path to the Netsuke manifest file to use. + + [default: Netsukefile] + + -C, --directory + Run as if started in this directory. + + This affects manifest lookup, output paths, and config discovery. + + --config + Path to a configuration file, bypassing automatic discovery. + + -j, --jobs + Set the number of parallel build jobs. + + Values must be between 1 and 64. + + --fetch-allow-scheme + Additional URL schemes allowed for the fetch helper. + + --fetch-allow-host + Hostnames that are permitted when default deny is enabled. + + Supports wildcards such as `*.example.com`. + + --fetch-block-host + Hostnames that are always blocked, even when allowed elsewhere. + + Supports wildcards such as `*.example.com`. + + --fetch-default-deny + Deny all hosts by default; only allow the declared allowlist. + + -v, --verbose + Enable verbose diagnostic logging and completion timing summaries. + + --locale + Locale tag for CLI copy (for example: en-US, es-ES). + + --accessible + Force accessible output mode on or off. + + [possible values: true, false] + + --no-emoji + Suppress emoji glyphs in output. + + [possible values: true, false] + + --theme + CLI theme preset (auto, unicode, ascii). + + --colour-policy + Colour output policy (auto, always, never). + + --progress + Force standard progress summaries on or off. + + When omitted, Netsuke enables progress summaries in standard mode. + + [possible values: true, false] + + --spinner-mode + Progress spinner display mode (enabled, disabled). + + --diag-json + Emit machine-readable diagnostics as JSON on stderr. + + --output-format + Diagnostic output format (human, json). + + --default-target + Default build targets when none are specified. + + -h, --help + Print help (see a summary with '-h') + + -V, --version + Print version diff --git a/src/snapshots/cli/netsuke__cli__tests__help_es_es.snap b/src/snapshots/cli/netsuke__cli__tests__help_es_es.snap new file mode 100644 index 00000000..c7434f56 --- /dev/null +++ b/src/snapshots/cli/netsuke__cli__tests__help_es_es.snap @@ -0,0 +1,96 @@ +--- +source: src/cli/mod.rs +expression: normalized_help +--- +Netsuke transforma manifiestos YAML + Jinja en grafos Ninja reproducibles y ejecuta Ninja con valores seguros. + +Usage: netsuke [OPTIONS] [COMMAND] + +Commands: + build Compila objetivos definidos en el manifiesto (predeterminado). + clean Elimina artefactos de compilación mediante Ninja. + graph Emite el grafo de dependencias en formato DOT. + manifest Escribe el manifiesto Ninja sin ejecutar Ninja. + help Print this message or the help of the given subcommand(s) + +Options: + -f, --file + Ruta al archivo de manifiesto Netsuke. + + [default: Netsukefile] + + -C, --directory + Run as if started in this directory. + + This affects manifest lookup, output paths, and config discovery. + + --config + Ruta a un archivo de configuración, omitiendo la detección automática. + + -j, --jobs + Set the number of parallel build jobs. + + Values must be between 1 and 64. + + --fetch-allow-scheme + Esquemas de URL adicionales permitidos para el ayudante fetch. + + --fetch-allow-host + Hostnames that are permitted when default deny is enabled. + + Supports wildcards such as `*.example.com`. + + --fetch-block-host + Hostnames that are always blocked, even when allowed elsewhere. + + Supports wildcards such as `*.example.com`. + + --fetch-default-deny + Denegar todos los hosts por defecto; solo permitir la lista de permitidos. + + -v, --verbose + Habilitar registro de diagnóstico detallado y resúmenes de tiempo al completar. + + --locale + Etiqueta de idioma para la CLI (por ejemplo: en-US, es-ES). + + --accessible + Forzar el modo de salida accesible (activado o desactivado). + + [possible values: true, false] + + --no-emoji + Suprimir glifos emoji en la salida. + + [possible values: true, false] + + --theme + Tema predefinido de CLI (auto, unicode, ascii). + + --colour-policy + Política de color de salida (auto, always, never). + + --progress + Force standard progress summaries on or off. + + When omitted, Netsuke enables progress summaries in standard mode. + + [possible values: true, false] + + --spinner-mode + Modo de visualización del spinner de progreso (enabled, disabled). + + --diag-json + Emitir diagnósticos legibles por máquinas como JSON en stderr. + + --output-format + Formato de salida de diagnósticos (human, json). + + --default-target + Objetivos de compilación predeterminados cuando no se especifica ninguno. + + -h, --help + Print help (see a summary with '-h') + + -V, --version + Print version