From d2f22e7ad8fa23ea6dee58bf770de99542a11db8 Mon Sep 17 00:00:00 2001 From: sun04222 <3242054475@qq.com> Date: Sat, 24 Oct 2026 13:29:48 +0800 Subject: [PATCH] fix(scripts): make configure.py --help print usage without generating files (#7404) configure.py did not parse its arguments, so `--help` printed no usage and ran the bootstrap as a side effect (creating config.yaml, .env and frontend/.env in a fresh checkout), and any unrecognized flag was silently ignored the same way. Parse arguments with argparse before touching the filesystem: --help now prints usage and exits 0, unknown flags exit 2, and the no-argument invocation used by `make configure` is unchanged. Extend the regression tests from #7102 with two offline subprocess cases covering both new behaviors. Fixes #7382 --- backend/tests/test_configure_script.py | 35 ++++++++++++++++++++++++++ scripts/configure.py | 9 ++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/backend/tests/test_configure_script.py b/backend/tests/test_configure_script.py index 6972f6b52d..0551d136f2 100644 --- a/backend/tests/test_configure_script.py +++ b/backend/tests/test_configure_script.py @@ -64,3 +64,38 @@ def test_configure_preserves_existing_configuration(config_checkout: Path, confi assert config_path.read_text(encoding="utf-8") == "existing: true\n" assert not (config_checkout / ".env").exists() assert not (config_checkout / "frontend" / ".env").exists() + + +def test_configure_help_prints_usage_without_generating_files(config_checkout: Path): + result = subprocess.run( + [sys.executable, str(config_checkout / "scripts" / "configure.py"), "--help"], + capture_output=True, + text=True, + encoding="utf-8", + check=False, + timeout=30, + ) + + assert result.returncode == 0, result.stderr + assert "usage: configure.py" in result.stdout + assert "Cross-platform config bootstrap script for DeerFlow." in result.stdout + assert not (config_checkout / "config.yaml").exists() + assert not (config_checkout / ".env").exists() + assert not (config_checkout / "frontend" / ".env").exists() + + +def test_configure_rejects_unknown_flags_without_generating_files(config_checkout: Path): + result = subprocess.run( + [sys.executable, str(config_checkout / "scripts" / "configure.py"), "--not-a-real-flag"], + capture_output=True, + text=True, + encoding="utf-8", + check=False, + timeout=30, + ) + + assert result.returncode == 2 + assert "unrecognized arguments" in result.stderr + assert not (config_checkout / "config.yaml").exists() + assert not (config_checkout / ".env").exists() + assert not (config_checkout / "frontend" / ".env").exists() diff --git a/scripts/configure.py b/scripts/configure.py index ae7e25ecce..25e58fc817 100644 --- a/scripts/configure.py +++ b/scripts/configure.py @@ -3,6 +3,7 @@ from __future__ import annotations +import argparse import shutil import sys from pathlib import Path @@ -17,7 +18,13 @@ def copy_if_missing(src: Path, dst: Path) -> None: shutil.copyfile(src, dst) -def main() -> int: +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser( + prog="configure.py", + description="Cross-platform config bootstrap script for DeerFlow.", + ) + parser.parse_args(argv) + project_root = Path(__file__).resolve().parent.parent existing_config = [