Files
llm-in-text/backend/tests/test_llm.py
T
ydy0615 59334e4057 Stabilize pro editing without heavy office runtime
The workspace now carries the pro editing flow, streaming completion path, and lighter Office preview state as one checkpoint so the remote has the current runnable project shape.

Constraint: Preserve the current workspace as a single reviewable project commit while excluding local agent state and verification artifacts. Removed stale Univer runtime dependencies from the lockfile so installs match package.json.

Rejected: Commit runtime screenshots, .omx state, and coverage files | they are local artifacts rather than source state.

Confidence: medium

Scope-risk: broad

Directive: Keep package.json and package-lock.json synchronized when changing frontend dependencies.

Tested: npm run build; C:\Users\ydy\.conda\envs\llmwebsite\python.exe -m pytest backend/tests/test_main_endpoints.py backend/tests/test_main_cancel.py backend/tests/test_llm.py backend/tests/test_llm_extended.py -v -o addopts= (44 passed).

Not-tested: Full pytest with repository coverage addopts currently reports 0% coverage because pytest-cov watches backend.* module names while tests import top-level backend modules.

Co-authored-by: OmX <omx@oh-my-codex.dev>
2026-05-24 23:30:32 +08:00

63 lines
1.6 KiB
Python

import asyncio
import importlib
import sys
from pathlib import Path
import pytest
BACKEND_DIR = Path(__file__).resolve().parents[1]
if str(BACKEND_DIR) not in sys.path:
sys.path.insert(0, str(BACKEND_DIR))
try:
llm = importlib.import_module("llm")
except ModuleNotFoundError:
pytest.skip("llm module dependencies are not available", allow_module_level=True)
def test_call_ollama_messages_roles_with_system(monkeypatch):
captured = {}
async def fake_generate(**kwargs):
captured["kwargs"] = kwargs
return {"response": "ok"}
monkeypatch.setattr(llm.client, "generate", fake_generate)
result = asyncio.run(
llm.call_ollama(
"user prompt body",
system_prompt="system prompt body",
tag="test",
temperature=0.1,
)
)
assert result["content"] == "ok"
assert captured["kwargs"]["prompt"] == "system prompt body\n\nuser prompt body"
assert captured["kwargs"]["raw"] is True
def test_call_ollama_messages_roles_without_system(monkeypatch):
captured = {}
async def fake_generate(**kwargs):
captured["kwargs"] = kwargs
return {"response": "ok"}
monkeypatch.setattr(llm.client, "generate", fake_generate)
result = asyncio.run(
llm.call_ollama(
"user prompt only",
system_prompt="",
tag="test-no-system",
temperature=0.1,
)
)
assert result["content"] == "ok"
assert captured["kwargs"]["prompt"] == "user prompt only"
assert captured["kwargs"]["raw"] is True