mirror of
https://github.com/github/spec-kit.git
synced 2026-08-03 06:26:30 +08:00
* fix(integrations): exit cleanly on unbalanced quote in --integration-options (#3457) `_parse_integration_options` called `shlex.split(raw_options)` unguarded, so an unbalanced quote in the flag value (e.g. `--integration-options='--commands-dir "foo'`) made shlex raise `ValueError: No closing quotation` and a raw traceback escaped — unlike every other bad-input path in this function (unknown option, missing value, unexpected value), which print a message and exit 1. Reachable from `specify init --integration-options=...` and every `specify integration install/switch/upgrade/migrate --integration-options=...`. Wrap the split in a try/except ValueError that prints a one-line error and raises `typer.Exit(1)`, matching the existing loud-fail UX. Add a test asserting the unbalanced-quote input raises `typer.Exit` with exit code 1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -190,7 +190,15 @@ def _parse_integration_options(integration: Any, raw_options: str) -> dict[str,
|
||||
"""
|
||||
import shlex
|
||||
parsed: dict[str, Any] = {}
|
||||
tokens = shlex.split(raw_options)
|
||||
try:
|
||||
tokens = shlex.split(raw_options)
|
||||
except ValueError as exc:
|
||||
# An unbalanced quote (e.g. --integration-options='--commands-dir "foo')
|
||||
# makes shlex raise "No closing quotation". Translate it into the same
|
||||
# clean exit-1 UX as every other bad-input path below rather than
|
||||
# letting a raw traceback escape.
|
||||
console.print(f"[red]Error:[/red] Could not parse integration options: {exc}.")
|
||||
raise typer.Exit(1)
|
||||
declared_options = list(integration.options())
|
||||
declared = {opt.name.lstrip("-"): opt for opt in declared_options}
|
||||
allowed = ", ".join(sorted(opt.name for opt in declared_options))
|
||||
|
||||
@@ -2675,6 +2675,27 @@ class TestParseIntegrationOptionsEqualsForm:
|
||||
assert result_space["commands_dir"] == "./mydir"
|
||||
assert result_equals["commands_dir"] == "./mydir"
|
||||
|
||||
def test_unbalanced_quote_exits_cleanly(self, capsys):
|
||||
"""An unbalanced quote must exit(1) with a message, not a raw ValueError.
|
||||
|
||||
shlex.split() raises ValueError("No closing quotation") on an unbalanced
|
||||
quote; the parser must translate that into the same clean typer.Exit(1)
|
||||
UX as unknown-option / missing-value, rather than letting the traceback
|
||||
escape (issue #3457).
|
||||
"""
|
||||
import typer
|
||||
|
||||
from specify_cli.integrations._commands import _parse_integration_options
|
||||
from specify_cli.integrations import get_integration
|
||||
|
||||
integration = get_integration("generic")
|
||||
assert integration is not None
|
||||
|
||||
with pytest.raises(typer.Exit) as excinfo:
|
||||
_parse_integration_options(integration, '--commands-dir "foo')
|
||||
assert excinfo.value.exit_code == 1
|
||||
assert "Error: Could not parse integration options: No closing quotation." in capsys.readouterr().out
|
||||
|
||||
|
||||
class TestUninstallNoManifestClearsInitOptions:
|
||||
def test_init_options_cleared_on_no_manifest_uninstall(self, tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user