Files
DeepTutor/tests/runtime/test_launcher.py
Bingxi Zhao (Frank) 90a2c14c81 chore: backend + frontend follow-ons for v1.4.0-beta
Wires the new memory / capability / settings / quiz subsystems into
existing surfaces and finishes the chat-pipeline follow-on work.

Backend:
- Session services pick up the cumulative source inventory + new tool
  tags (turn_runtime, sqlite_store, pocketbase_store, protocol,
  base_session_manager).
- LlamaIndex RAG pipeline config / document_loader / retrievers
  tightened; rag/service.py routed to match.
- Sessions / unified_ws / settings / notebook routers updated for
  delete-chat-turn, multi-user, and the new tool surface.
- TutorBot manager + Zulip channel + openai_compat_provider follow-on
  fixes layered on top of the v1.3.10 SSL/Zulip sweeps.
- runtime/{banner, launcher, orchestrator}, services/setup/init,
  prompt/manager, json_parser refined for the runtime-settings
  rewrite.

Frontend:
- Co-Learn pages and session-surfaces removed (folded into chat).
- Chat composer / messages / trace / session panels, sidebars,
  common modals, markdown renderers, and i18n updated for the new
  ask_user / write_note / source-inventory flow.
- Admin, agents, co-writer, playground, book pages picked up the
  shared updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 18:08:22 +08:00

97 lines
3.1 KiB
Python

from __future__ import annotations
from pathlib import Path
from deeptutor.runtime import launcher
def test_packaged_web_cache_replaces_next_public_placeholders(tmp_path: Path) -> None:
packaged = tmp_path / "pkg"
(packaged / ".next" / "static").mkdir(parents=True)
(packaged / "server.js").write_text(
"const api='__NEXT_PUBLIC_API_BASE_PLACEHOLDER__';",
encoding="utf-8",
)
(packaged / ".next" / "static" / "app.js").write_text(
"auth='__NEXT_PUBLIC_AUTH_ENABLED_PLACEHOLDER__'",
encoding="utf-8",
)
runtime = launcher._copy_packaged_web_if_needed(
packaged,
home=tmp_path / "home",
api_base="http://localhost:8001",
auth_enabled=True,
)
assert (runtime / "server.js").read_text(encoding="utf-8") == (
"const api='http://localhost:8001';"
)
assert "auth='true'" in (runtime / ".next" / "static" / "app.js").read_text(encoding="utf-8")
def test_packaged_web_cache_refreshes_when_public_settings_change(tmp_path: Path) -> None:
packaged = tmp_path / "pkg"
(packaged / ".next").mkdir(parents=True)
(packaged / "server.js").write_text(
"const api='__NEXT_PUBLIC_API_BASE_PLACEHOLDER__';",
encoding="utf-8",
)
home = tmp_path / "home"
first = launcher._copy_packaged_web_if_needed(
packaged,
home=home,
api_base="http://localhost:8001",
auth_enabled=False,
)
second = launcher._copy_packaged_web_if_needed(
packaged,
home=home,
api_base="https://api.example",
auth_enabled=False,
)
assert first == second
assert "https://api.example" in (second / "server.js").read_text(encoding="utf-8")
def test_detect_existing_source_frontend_from_next_dev_lock(tmp_path: Path, monkeypatch) -> None:
source = tmp_path / "web"
lock = source / ".next" / "dev" / "lock"
lock.parent.mkdir(parents=True)
lock.write_text(
'{"pid":12345,"port":3999,"appUrl":"http://localhost:3999"}',
encoding="utf-8",
)
monkeypatch.setattr(launcher, "_is_pid_alive", lambda pid: pid == 12345)
monkeypatch.setattr(launcher, "_port_accepts_connection", lambda port: False)
existing = launcher._detect_existing_source_frontend(
launcher.FrontendRuntime("source", [], source)
)
assert existing is not None
assert existing.url == "http://localhost:3999"
assert existing.port == 3999
assert existing.pid == 12345
assert existing.lock_path == lock
def test_detect_existing_source_frontend_ignores_stale_lock(tmp_path: Path, monkeypatch) -> None:
source = tmp_path / "web"
lock = source / ".next" / "dev" / "lock"
lock.parent.mkdir(parents=True)
lock.write_text(
'{"pid":12345,"port":3999,"appUrl":"http://localhost:3999"}',
encoding="utf-8",
)
monkeypatch.setattr(launcher, "_is_pid_alive", lambda pid: False)
monkeypatch.setattr(launcher, "_port_accepts_connection", lambda port: False)
existing = launcher._detect_existing_source_frontend(
launcher.FrontendRuntime("source", [], source)
)
assert existing is None