fix: keep onboard cli defaults unchanged

Remove the PR changes that made nanobot onboard default to the wizard, added --defaults, added non-TTY fallback behavior, and changed the Docker smoke command. Keep Quick Start available through nanobot onboard --wizard.
This commit is contained in:
chengyongru
2026-06-22 13:04:05 +08:00
committed by Xubin Ren
parent da225fc24e
commit 8e9f09f829
14 changed files with 53 additions and 162 deletions
+10 -89
View File
@@ -91,13 +91,12 @@ def mock_paths():
def test_onboard_fresh_install(mock_paths):
"""No existing config in non-TTY mode should fall back to defaults."""
"""No existing config — should create from scratch."""
config_file, workspace_dir, mock_ws = mock_paths
result = runner.invoke(app, ["onboard"])
assert result.exit_code == 0
assert "No interactive terminal detected" in result.stdout
assert "Created config" in result.stdout
assert "Created workspace" in result.stdout
assert "nanobot is ready" in result.stdout
@@ -108,13 +107,12 @@ def test_onboard_fresh_install(mock_paths):
assert mock_ws.call_args.args == (expected_workspace,)
def test_onboard_existing_config_refresh(mock_paths, monkeypatch):
def test_onboard_existing_config_refresh(mock_paths):
"""Config exists, user declines overwrite — should refresh (load-merge-save)."""
config_file, workspace_dir, _ = mock_paths
config_file.write_text('{"existing": true}')
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: True)
result = runner.invoke(app, ["onboard", "--defaults"], input="n\n")
result = runner.invoke(app, ["onboard"], input="n\n")
assert result.exit_code == 0
assert "Config already exists" in result.stdout
@@ -123,62 +121,12 @@ def test_onboard_existing_config_refresh(mock_paths, monkeypatch):
assert (workspace_dir / "AGENTS.md").exists()
def test_onboard_non_tty_existing_config_refreshes_without_prompt(mock_paths):
"""Default onboard should not ask overwrite when falling back outside a TTY."""
config_file, workspace_dir, _ = mock_paths
config_file.write_text("{}")
result = runner.invoke(app, ["onboard"])
assert result.exit_code == 0
assert "No interactive terminal detected" in result.stdout
assert "Config already exists" not in result.stdout
assert "existing values preserved" in result.stdout
assert workspace_dir.exists()
def test_onboard_defaults_non_tty_existing_config_preserves_values_without_prompt(
tmp_path, monkeypatch
):
"""Explicit --defaults should refresh existing configs without prompts outside a TTY."""
config_path = tmp_path / "config.json"
workspace_path = tmp_path / "workspace"
config_path.write_text(
json.dumps({"agents": {"defaults": {"model": "custom/keep"}}}),
encoding="utf-8",
)
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: False)
monkeypatch.setattr("nanobot.channels.registry.discover_all", lambda: {})
result = runner.invoke(
app,
[
"onboard",
"--defaults",
"--config",
str(config_path),
"--workspace",
str(workspace_path),
],
)
assert result.exit_code == 0
assert "Config already exists" not in result.stdout
assert "Overwrite?" not in result.stdout
assert "existing values preserved" in result.stdout
saved = Config.model_validate(json.loads(config_path.read_text(encoding="utf-8")))
assert saved.agents.defaults.model == "custom/keep"
assert saved.workspace_path == workspace_path
def test_onboard_existing_config_overwrite(mock_paths, monkeypatch):
def test_onboard_existing_config_overwrite(mock_paths):
"""Config exists, user confirms overwrite — should reset to defaults."""
config_file, workspace_dir, _ = mock_paths
config_file.write_text('{"existing": true}')
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: True)
result = runner.invoke(app, ["onboard", "--defaults"], input="y\n")
result = runner.invoke(app, ["onboard"], input="y\n")
assert result.exit_code == 0
assert "Config already exists" in result.stdout
@@ -186,14 +134,13 @@ def test_onboard_existing_config_overwrite(mock_paths, monkeypatch):
assert workspace_dir.exists()
def test_onboard_existing_workspace_safe_create(mock_paths, monkeypatch):
def test_onboard_existing_workspace_safe_create(mock_paths):
"""Workspace exists — should not recreate, but still add missing templates."""
config_file, workspace_dir, _ = mock_paths
workspace_dir.mkdir(parents=True)
config_file.write_text("{}")
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: True)
result = runner.invoke(app, ["onboard", "--defaults"], input="n\n")
result = runner.invoke(app, ["onboard"], input="n\n")
assert result.exit_code == 0
assert "Created workspace" not in result.stdout
@@ -217,7 +164,6 @@ def test_onboard_help_shows_workspace_and_config_options():
assert "--config" in stripped_output
assert "-c" in stripped_output
assert "--wizard" in stripped_output
assert "--defaults" in stripped_output
assert "--dir" not in stripped_output
@@ -226,13 +172,12 @@ def test_onboard_interactive_discard_does_not_save_or_create_workspace(mock_path
from nanobot.cli.onboard import OnboardResult
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: True)
monkeypatch.setattr(
"nanobot.cli.onboard.run_onboard",
lambda initial_config: OnboardResult(config=initial_config, should_save=False),
)
result = runner.invoke(app, ["onboard"])
result = runner.invoke(app, ["onboard", "--wizard"])
assert result.exit_code == 0
assert "No changes were saved" in result.stdout
@@ -248,14 +193,7 @@ def test_onboard_uses_explicit_config_and_workspace_paths(tmp_path, monkeypatch)
result = runner.invoke(
app,
[
"onboard",
"--defaults",
"--config",
str(config_path),
"--workspace",
str(workspace_path),
],
["onboard", "--config", str(config_path), "--workspace", str(workspace_path)],
)
assert result.exit_code == 0
@@ -279,12 +217,11 @@ def test_onboard_wizard_preserves_explicit_config_in_next_steps(tmp_path, monkey
"nanobot.cli.onboard.run_onboard",
lambda initial_config: OnboardResult(config=initial_config, should_save=True),
)
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: True)
monkeypatch.setattr("nanobot.channels.registry.discover_all", lambda: {})
result = runner.invoke(
app,
["onboard", "--config", str(config_path), "--workspace", str(workspace_path)],
["onboard", "--wizard", "--config", str(config_path), "--workspace", str(workspace_path)],
)
assert result.exit_code == 0
@@ -295,22 +232,6 @@ def test_onboard_wizard_preserves_explicit_config_in_next_steps(tmp_path, monkey
assert f"nanobot gateway --config {resolved_config}" in compact_output
def test_onboard_wizard_non_tty_falls_back_to_defaults(mock_paths, monkeypatch):
config_file, _workspace_dir, _ = mock_paths
monkeypatch.setattr("nanobot.cli.commands._onboard_can_prompt", lambda: False)
monkeypatch.setattr(
"nanobot.cli.onboard.run_onboard",
lambda initial_config: (_ for _ in ()).throw(AssertionError("should not prompt")),
)
result = runner.invoke(app, ["onboard", "--wizard"])
assert result.exit_code == 0
assert "No interactive terminal detected" in result.stdout
assert config_file.exists()
def test_config_matches_github_copilot_codex_with_hyphen_prefix():
config = Config()
config.agents.defaults.model = "github-copilot/gpt-5.3-codex"
+2 -2
View File
@@ -8,8 +8,8 @@ echo "=== Building Docker image ==="
docker build -t "$IMAGE_NAME" .
echo ""
echo "=== Running 'nanobot onboard --defaults' ==="
docker run --name nanobot-test-run "$IMAGE_NAME" onboard --defaults
echo "=== Running 'nanobot onboard' ==="
docker run --name nanobot-test-run "$IMAGE_NAME" onboard
echo ""
echo "=== Running 'nanobot status' ==="