From 799511c20dd05aa76f2d66fb61a1760e4ecdac09 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Wed, 11 Sep 2024 10:22:38 -0500 Subject: [PATCH] cli: add test to ensure the default config has no symbol aliases In #4432 I submitted a patch to ship a symbol alias in the default configuration. However, Yuya quickly pointed out that this isn't acceptable because symbols override all branch and tag names, meaning that the name `at` would have at best been taken away from users, and at worst been very confusing for them down the road had they ever tried to use it. I should have thought of this myself (I encountered it long ago when first using Jujutsu, actually) but didn't. Such is life. But this didn't cause any tests to fail, as it was not immediately clear this would impede anything or cause downstream behavioral changes; the problems it adds are actually latent and it's very possible someone will want to make the same mistake in the future. And Yuya might not be able to stop them (me) in time; requiring him to go out of his way and then handle the fallout. I'm not a fan of this. Instead, let's patch this latent hole for good, or until we decide otherwise, by applying the Beyonce Rule: "if you liked that behavior, then you shoulda put a test on it." Signed-off-by: Austin Seipp --- cli/src/config.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cli/src/config.rs b/cli/src/config.rs index c22871dc2..ef6068539 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -1270,6 +1270,38 @@ mod tests { Ok(()) } + #[test] + fn ban_default_symbol_aliases() -> anyhow::Result<()> { + // NOTE(aseipp): symbol aliases override all branches and tags, so we + // must ban them from being introduced in the default `revset-aliases` + // + // relevant issue: https://github.com/martinvonz/jj/pull/4432 + for (alias, _) in default_config().get_table("revset-aliases")?.iter() { + // an alias could be something like: + // + // 'foo()' = ... + // 'foo(x,y)' = ... + // + // but can never be something like: + // + // 'foo)' = ... + // '(foo)' = ... + // + // and so testing for the presence of a closing parenthesis is + // sufficient to ensure we're not introducing a symbol. + if !alias.ends_with(")") { + anyhow::bail!( + "symbol alias `{}` is not allowed in the default configuration; alias must be \ + a nullary function i.e. '{}()'", + alias, + alias + ); + } + } + + Ok(()) + } + fn setup_config_fs(files: &Vec<&'static str>) -> anyhow::Result { let tmp = testutils::new_temp_dir(); for file in files {