fix(webui): resume incomplete model setup in the browser

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-07 14:20:06 +08:00
1 parent 7ed79fe309
commit 0b1fa0c3e4
3 files changed
+32 -62

No files matched your search

+31 -9
View File
@@ -2424,7 +2424,10 @@ def test_browser_readiness_rejects_connection_error(monkeypatch) -> None:
) is False
def test_webui_yes_starts_first_run_without_provider_setup(monkeypatch, tmp_path: Path) -> None:
@pytest.mark.parametrize("resume_args", [[], ["--yes"]])
def test_webui_resumes_first_run_without_provider_setup(
monkeypatch, tmp_path: Path, resume_args: list[str],
) -> None:
config_file = tmp_path / "config.json"
seen: dict[str, object] = {}
@@ -2440,13 +2443,26 @@ def test_webui_yes_starts_first_run_without_provider_setup(monkeypatch, tmp_path
monkeypatch.setattr("nanobot.cli.webui.sync_workspace_templates", lambda _path: None)
_patch_webui_managed_gateway(monkeypatch, seen)
result = runner.invoke(app, ["webui", "--config", str(config_file), "--yes", "--no-open"])
args = ["webui", "--config", str(config_file), "--workspace", str(tmp_path / "workspace")]
result = runner.invoke(app, [*args, "--yes", "--no-open"])
assert result.exit_code == 0
assert config_file.exists()
assert seen["start_options"].config_path == str(config_file.resolve(strict=False))
assert "Configure a provider and model in WebUI Settings → Models." in result.stdout
saved_config = json.loads(config_file.read_text(encoding="utf-8"))
seen.clear()
resumed = runner.invoke(app, [*args, *resume_args, "--no-open"])
assert resumed.exit_code == 0, resumed.stdout
assert seen["start_options"].config_path == str(config_file.resolve(strict=False))
assert "Configure a provider and model in WebUI Settings → Models." in resumed.stdout
assert "Quick Start" not in resumed.stdout
assert json.loads(config_file.read_text(encoding="utf-8")) == saved_config
assert saved_config["channels"]["websocket"]["host"] == "127.0.0.1"
assert saved_config["channels"]["websocket"]["tokenIssueSecret"]
def test_webui_missing_runtime_env_fails_before_starting_gateway(
monkeypatch,
@@ -2483,7 +2499,7 @@ def test_webui_missing_runtime_env_fails_before_starting_gateway(
assert f"${{{missing_env}}}" in config_file.read_text(encoding="utf-8")
def test_webui_yes_still_refuses_invalid_custom_model_setup(
def test_webui_yes_opens_settings_for_incomplete_custom_model_setup(
monkeypatch,
tmp_path: Path,
) -> None:
@@ -2505,14 +2521,20 @@ def test_webui_yes_still_refuses_invalid_custom_model_setup(
encoding="utf-8",
)
result = runner.invoke(app, ["webui", "--config", str(config_file), "--yes"])
_patch_gateway_ports_free(monkeypatch)
seen = _patch_webui_managed_gateway(monkeypatch)
result = runner.invoke(app, [
"webui", "--config", str(config_file), "--workspace", str(tmp_path / "workspace"),
"--yes", "--no-open",
])
assert result.exit_code == 1
assert "provider/model setup is incomplete" in result.stdout
assert result.exit_code == 0, result.stdout
assert seen["start_options"].config_path == str(config_file.resolve(strict=False))
assert "Model setup is incomplete" in result.stdout
assert "Settings → Models" in _without_rendered_line_breaks(result.stdout)
assert "nanobot onboard --wizard" in result.stdout
assert "nanobot status --config" in result.stdout
assert config_file.name in result.stdout
saved = json.loads(config_file.read_text(encoding="utf-8"))
assert saved["agents"]["defaults"]["model"] == "custom/test-model"
assert saved["providers"]["custom"]["displayName"] == "Custom"
def test_open_webui_browser_redacts_bootstrap_secret(monkeypatch, capsys) -> None: