wip: qa7920 sidecar + rag stream timeout

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
sj
2026-08-21 11:04:28 +08:00
co-authored by Claude Opus 5
parent b725a9c125
commit 90033214b4
66 changed files with 18990 additions and 68 deletions
@@ -0,0 +1,39 @@
from pathlib import Path
import pytest
FRONTEND_DIR = Path(__file__).resolve().parents[2] / "apps" / "web" / "vue3"
PAGE_NAMES = ("index.html", "index_ml.html")
PAGE_SOURCES = {
name: (FRONTEND_DIR / name).read_text(encoding="utf-8")
for name in PAGE_NAMES
}
def _source(name: str) -> str:
return PAGE_SOURCES[name]
@pytest.mark.parametrize("name", PAGE_NAMES)
def test_rag_mode_uses_streaming_request(name: str) -> None:
source = _source(name)
start = source.index("// V2: RAG模式")
end = source.index("} catch (err)", start)
rag_block = source[start:end]
assert "requestRagWithProgress(" in rag_block
assert "fetchJsonWithTimeout('/api/agent/rag'" not in rag_block
@pytest.mark.parametrize("name", PAGE_NAMES)
def test_rag_stream_timeout_is_reset_after_each_received_chunk(name: str) -> None:
source = _source(name)
start = source.index("const readRagEventStream")
end = source.index("const requestRagWithProgress", start)
stream_block = source[start:end]
read_position = stream_block.index("const { value, done } = await reader.read();")
assert "const resetIdleTimer = () =>" in stream_block
assert stream_block.index("resetIdleTimer();", read_position) > read_position
assert "知识库检索连接空闲超时" in stream_block
@@ -0,0 +1,28 @@
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
MAIN = ROOT / "apps" / "web" / "vue3" / "main.py"
MAIN_SOURCE = MAIN.read_text(encoding="utf-8")
def _rag_routes() -> str:
start = MAIN_SOURCE.index('@app.post("/api/agent/rag")')
end = MAIN_SOURCE.index("# ==================== DiagnosisAgent API", start)
return MAIN_SOURCE[start:end]
def test_rag_proxy_has_no_inline_150_second_timeout() -> None:
routes = _rag_routes()
assert "timeout=150.0" not in routes
assert "complete QA exceeded 150 seconds" not in routes
assert "完整知识图谱问答超过 150 秒" not in routes
def test_rag_stream_proxy_preserves_upstream_sse_frames() -> None:
routes = _rag_routes()
assert "for frame in stream_dual_kb_qa(" in routes
assert "yield frame" in routes
assert 'media_type="text/event-stream"' in routes