fix(cli): localize existing-server prompts for Chinese launcher

This commit is contained in:
chenmingxuan committed 2026-10-29 16:48:29 +08:00
1 parent c6d2050ff0
commit 506e3bf1c5
3 files changed
+126 -11

No files matched your search

+76
View File
@@ -109,6 +109,82 @@ def _recording_console():
return Console(file=io.StringIO(), force_terminal=False, width=120)
@pytest.mark.parametrize("language", ["zh-CN", "en"])
@pytest.mark.parametrize("choice", ["", "2", "3"])
def test_existing_server_prompt_respects_launch_language(monkeypatch, language, choice):
from artemis.runtime import server_lifecycle
console = _recording_console()
monkeypatch.setenv("ARTEMIS_LAUNCH_LANG", language)
monkeypatch.setattr(ui, "Console", lambda: console)
monkeypatch.setattr(ui.sys.stdin, "isatty", lambda: True)
monkeypatch.setattr(server_lifecycle, "is_port_in_use", lambda port: True)
monkeypatch.setattr(server_lifecycle, "find_server_pids", lambda port: [1234])
prompts, opened, stopped = [], [], []
monkeypatch.setattr("builtins.input", lambda prompt: prompts.append(prompt) or choice)
monkeypatch.setattr(ui.webbrowser, "open", opened.append)
monkeypatch.setattr(ui, "load_session_reconciler", lambda: None)
class RestartSelected(Exception):
pass
def stop_server(**kwargs):
stopped.append(kwargs)
raise RestartSelected # Never launch or stop a real service.
monkeypatch.setattr(server_lifecycle, "stop_server", stop_server)
if choice == "2":
with pytest.raises(RestartSelected):
ui.ui_command(port=8123)
else:
ui.ui_command(port=8123)
output = console.file.getvalue()
assert "8123" in output and "PID: 1234" in output
if language == "zh-CN":
assert all(
text in output
for text in ("服务正在运行", "请选择操作", "打开浏览器(默认)", "重启服务", "取消")
)
assert "请输入选项" in prompts[0]
assert "Choose an action" not in output and "Restart server" not in output
if choice == "2":
assert "正在停止端口 8123" in output
else:
assert "Choose an action" in output and "Open browser (default)" in output
assert "Select [1-3, default 1]" in prompts[0]
assert opened == (["http://localhost:8123"] if not choice else [])
assert stopped == ([{"port": 8123, "timeout": 12.0}] if choice == "2" else [])
@pytest.mark.parametrize("language", ["zh-CN", None])
@pytest.mark.parametrize("open_browser", [True, False])
def test_existing_server_noninteractive_does_not_restart(monkeypatch, language, open_browser):
from artemis.runtime import server_lifecycle
console = _recording_console()
if language:
monkeypatch.setenv("ARTEMIS_LAUNCH_LANG", language)
else:
monkeypatch.delenv("ARTEMIS_LAUNCH_LANG", raising=False)
monkeypatch.setattr(ui, "Console", lambda: console)
monkeypatch.setattr(ui.sys.stdin, "isatty", lambda: False)
monkeypatch.setattr(server_lifecycle, "is_port_in_use", lambda port: True)
monkeypatch.setattr(server_lifecycle, "find_server_pids", lambda port: [])
monkeypatch.setattr(
server_lifecycle, "stop_server", lambda **kwargs: pytest.fail("Unexpected restart")
)
opened = []
monkeypatch.setattr(ui.webbrowser, "open", opened.append)
ui.ui_command(port=8123, open_browser=open_browser)
output = console.file.getvalue()
assert "artemis restart" in output
assert ("服务正在运行" if language else "already in use") in output
assert opened == (["http://localhost:8123"] if open_browser else [])
def test_ensure_showcase_built_skips_install_when_deps_current(monkeypatch):
steps = []
monkeypatch.setattr(ui, "_showcase_build_required", lambda showcase_dir: True)