config-schema: deny empty arrays for command-like config options

Anytime an external tool is referenced in the config, the command can be
provided as a string or as a token array. In the latter case, the array
must not be empty; at least the command name must be provided.

The schema didn't previously object to an empty array, though; this has
now been rectified. I've added more sample configs to cover this case.
Those same configs can also be used to illustrate that this is indeed
jj's current behavior:

$ jj --config-file cli/tests/sample-configs/invalid/ui.pager_empty_array.toml show
Config error: Invalid type or value for ui.pager
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.pager.command_empty_array.toml show
Config error: Invalid type or value for ui.pager
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.editor_empty_array.toml config edit --user
Config error: Invalid type or value for ui.editor
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.diff-editor_empty_array.toml split
Error: Failed to load tool configuration
Caused by:
1: Invalid type or value for ui.diff-editor
2: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.merge-editor_empty_array.toml resolve
Error: Failed to load tool configuration
Caused by:
1: Invalid type or value for ui.merge-editor
2: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.diff.tool_empty_array.toml diff
Config error: Invalid type or value for ui.diff.tool
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/fix.tools.command_empty_array.toml fix
Config error: Invalid type or value for fix.tools.black
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
in `command`

As a notable exception, `ui.default-command` *is* allowed to be an empty
array. In that case, `jj` will print a usage message. This is also
covered by a valid sample config.
This commit is contained in:
Jonas Greitemann 2025-04-17 14:22:42 +02:00 committed by Jonas Greitemann
parent 5444067c37
commit 4a1754bc46
9 changed files with 33 additions and 0 deletions

View File

@ -52,6 +52,7 @@
"properties": {
"command": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
@ -109,6 +110,7 @@
},
{
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
@ -164,6 +166,7 @@
},
"tool": {
"type": ["array", "string"],
"minItems": 1,
"items": {
"type": "string"
},
@ -204,6 +207,7 @@
},
"editor": {
"type": ["array", "string"],
"minItems": 1,
"items": {
"type": "string"
},
@ -218,6 +222,7 @@
},
{
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
@ -233,6 +238,7 @@
},
{
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
@ -743,6 +749,7 @@
"properties": {
"command": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
},

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[fix.tools.black]
command = []

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[ui]
diff-editor = []

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[ui.diff]
tool = []

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[ui]
editor = []

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[ui]
merge-editor = []

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[ui.pager]
command = []

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[ui]
pager = []

View File

@ -0,0 +1,5 @@
#:schema ../../../src/config-schema.json
# Unlike most other array-valued command options, `default-command` is actually
# allowed to be empty. In this case, it will simply print usage info.
[ui]
default-command = []