This commit is contained in:
@@ -373,6 +373,55 @@ def test_ppt_audit_history_audit_rows_include_inline_replay(client, monkeypatch,
|
||||
assert '回放' in html
|
||||
|
||||
|
||||
def test_ppt_audit_history_weekly_rows_include_visual_audit(client, monkeypatch, tmp_path):
|
||||
"""非 daily 簡報也應顯示自己的視覺 QA 歷史,不再要求切回 daily。"""
|
||||
import zipfile
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock
|
||||
from routes import admin_observability_routes as mod
|
||||
|
||||
reports_dir = tmp_path / 'reports'
|
||||
reports_dir.mkdir()
|
||||
pptx = reports_dir / 'ocbot_weekly_20260518.pptx'
|
||||
with zipfile.ZipFile(pptx, 'w') as zf:
|
||||
zf.writestr('[Content_Types].xml', '<Types></Types>')
|
||||
|
||||
monkeypatch.setenv('REPORTS_DIR', str(reports_dir))
|
||||
|
||||
class FakeSession:
|
||||
def execute(self, statement, _params=None):
|
||||
sql = str(statement)
|
||||
result = MagicMock()
|
||||
if 'FROM ppt_reports' in sql:
|
||||
result.fetchall.return_value = []
|
||||
elif 'SELECT audited_at, pptx_filename' in sql:
|
||||
result.fetchall.return_value = [
|
||||
(datetime(2026, 5, 18, 22, 7), 'ocbot_weekly_20260518.pptx', 'passed', 0, 0.91, 1800, '')
|
||||
]
|
||||
elif 'COALESCE(AVG(confidence)' in sql:
|
||||
result.fetchone.return_value = (1, 1, 0, 0, 0, 0.91, 0)
|
||||
elif 'GROUP BY pptx_filename' in sql:
|
||||
result.fetchall.return_value = []
|
||||
else:
|
||||
result.fetchall.return_value = []
|
||||
result.fetchone.return_value = (0,)
|
||||
return result
|
||||
|
||||
def close(self):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(mod, 'get_session', lambda: FakeSession())
|
||||
|
||||
r = client.get('/observability/ppt_audit_history?month=2026-05&report_type=weekly')
|
||||
html = r.data.decode('utf-8')
|
||||
|
||||
assert r.status_code == 200
|
||||
assert 'ocbot_weekly_20260518.pptx' in html
|
||||
assert '審核回放 · ocbot_weekly_20260518.pptx' in html
|
||||
assert '只有「每日日報」會進入視覺審核流程' not in html
|
||||
assert 'data-ppt-run-vision' in html
|
||||
|
||||
|
||||
def test_ppt_audit_history_shows_preview_prewarm_action(client, monkeypatch, tmp_path):
|
||||
"""未快取 PDF 的 PPTX 要能在產線清單直接預熱預覽。"""
|
||||
import zipfile
|
||||
@@ -432,6 +481,30 @@ def test_ppt_audit_file_prewarm_builds_preview_cache(client, monkeypatch, tmp_pa
|
||||
assert data['message'] == 'PDF 預覽快取已建立'
|
||||
|
||||
|
||||
def test_ppt_audit_run_vision_queues_background_audit(client, monkeypatch):
|
||||
"""立即視覺 QA 端點只排入背景任務,不讓瀏覽器等待模型跑完。"""
|
||||
from services import ppt_vision_service as svc
|
||||
|
||||
captured = {}
|
||||
|
||||
def fake_start(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return {'ok': True, 'status': 'queued', 'message': 'PPT vision audit queued.'}
|
||||
|
||||
monkeypatch.setattr(svc, 'start_ppt_vision_audit_background', fake_start)
|
||||
|
||||
r = client.post(
|
||||
'/observability/ppt_audit/run_vision',
|
||||
json={'filenames': ['ocbot_daily_20260518.pptx'], 'max_files': 1},
|
||||
)
|
||||
data = r.get_json()
|
||||
|
||||
assert r.status_code == 202
|
||||
assert data['ok'] is True
|
||||
assert captured['filenames'] == ['ocbot_daily_20260518.pptx']
|
||||
assert captured['max_files'] == 1
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# /observability/host_health
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user