Files
Aislo/resources/tester/test_570_1_preview_up.py
T
eomsangdonandClaude Opus 5.5 61b799eefd feat(tools): 빌드판 포트 지정 · 개발판 자리에 빌드판 (PLAN 570-1 · 요구 398)
- preview_up.py --port N · --replace-dev(빌드가 된 뒤에만 개발 포트 vite dev 를 끄고 그 자리에 빌드판)
- 빌드 실패 = 아무것도 안 끔 · 옛 빌드판이 그 자리면 끄고 개발판으로
- 기본(개발 포트 − 1000) 그대로 · 지킴 시험 test_570_1_preview_up
- (git 밖 .claude) dev_up.py --build · git-sync-all.ps1 -Global 데스크탑 메인 = WMI 로 dev_up --build · 5173 빌드판 확인

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:08:47 +09:00

73 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""570-1 빌드판 자리 — 기본 = 개발 포트 − 1000 · --replace-dev = 개발 포트 · 빌드 실패면 안 끔."""
import importlib.util
import subprocess
from pathlib import Path
import pytest
SRC = Path(__file__).resolve().parents[2] / "tools" / "preview_up.py"
@pytest.fixture
def pu(monkeypatch, tmp_path):
spec = importlib.util.spec_from_file_location("preview_up_570", SRC)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
calls: list = []
monkeypatch.setattr(mod, "TMP", str(tmp_path))
monkeypatch.setattr(mod, "PID_FILE", str(tmp_path / "preview.pid"))
monkeypatch.setattr(mod, "LOG", str(tmp_path / "preview.log"))
monkeypatch.setattr(mod, "owners_ports", lambda: (8001, 5174))
monkeypatch.setattr(mod, "stop", lambda: calls.append("stop"))
monkeypatch.setattr(mod, "free_port", lambda port: calls.append(("free", port)))
monkeypatch.setattr(mod, "run", lambda cmd, env: None)
monkeypatch.setattr(mod.time, "sleep", lambda s: None)
monkeypatch.setattr(mod.urllib.request, "urlopen", lambda url, timeout: calls.append(url))
class Proc:
pid = 1
monkeypatch.setattr(mod, "spawn", lambda cmd, env: calls.append(("spawn", cmd)) or Proc())
monkeypatch.delenv("AISLO_VITE_PORT", raising=False)
monkeypatch.delenv("AISLO_API_PORT", raising=False)
mod.calls = calls
return mod
def spawned_port(calls) -> str:
cmd = next(c[1] for c in calls if isinstance(c, tuple) and c[0] == "spawn")
return cmd[cmd.index("--port") + 1]
def test_default_dev_minus_1000(pu, monkeypatch):
monkeypatch.setattr(pu.sys, "argv", ["preview_up.py"])
assert pu.main() == 0
assert spawned_port(pu.calls) == "4174"
assert not any(isinstance(c, tuple) and c[0] == "free" for c in pu.calls)
def test_port_arg(pu, monkeypatch):
monkeypatch.setattr(pu.sys, "argv", ["preview_up.py", "--port", "4999"])
assert pu.main() == 0
assert spawned_port(pu.calls) == "4999"
def test_replace_dev_takes_dev_port_after_build(pu, monkeypatch):
monkeypatch.setattr(pu.sys, "argv", ["preview_up.py", "--replace-dev"])
assert pu.main() == 0
assert spawned_port(pu.calls) == "5174"
assert pu.calls.index(("free", 5174)) < next(
i for i, c in enumerate(pu.calls) if isinstance(c, tuple) and c[0] == "spawn"
)
def test_replace_dev_build_fail_kills_nothing(pu, monkeypatch):
def boom(cmd, env):
raise subprocess.CalledProcessError(1, cmd)
monkeypatch.setattr(pu, "run", boom)
monkeypatch.setattr(pu.sys, "argv", ["preview_up.py", "--replace-dev"])
assert pu.main() == 1
assert pu.calls == []