mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-26 13:16:24 +00:00
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
This commit is contained in:
parent
5a563b4e99
commit
d2f22e7ad8
@ -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()
|
||||
|
||||
@ -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 = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user