This commit is contained in:
@@ -696,10 +696,11 @@ def test_ppt_audit_run_vision_queues_background_audit(client, monkeypatch):
|
||||
assert captured['max_files'] == 1
|
||||
|
||||
|
||||
def test_ppt_vision_audit_status_sanitizes_last_run(monkeypatch):
|
||||
def test_ppt_vision_audit_status_sanitizes_last_run(monkeypatch, tmp_path):
|
||||
"""背景視覺 QA 狀態只回檔名與摘要,不把 reports_dir 絕對路徑曝露到頁面。"""
|
||||
from services import ppt_vision_service as svc
|
||||
|
||||
monkeypatch.setenv('PPT_VISION_STATE_PATH', str(tmp_path / 'vision_state.json'))
|
||||
monkeypatch.setattr(svc, '_LAST_AUDIT_RUN', {
|
||||
'ok': True,
|
||||
'status': 'completed',
|
||||
@@ -731,6 +732,71 @@ def test_ppt_vision_audit_status_sanitizes_last_run(monkeypatch):
|
||||
assert '/app/data/reports' not in str(status)
|
||||
|
||||
|
||||
def test_ppt_vision_audit_status_reads_persisted_state(monkeypatch, tmp_path):
|
||||
"""多 worker 下狀態需從 runtime state 檔讀取,不能只靠單一 worker 記憶體。"""
|
||||
import json
|
||||
from services import ppt_vision_service as svc
|
||||
|
||||
state_path = tmp_path / 'vision_state.json'
|
||||
monkeypatch.setenv('PPT_VISION_STATE_PATH', str(state_path))
|
||||
monkeypatch.setattr(svc, '_LAST_AUDIT_RUN', None)
|
||||
state_path.write_text(json.dumps({
|
||||
'ok': True,
|
||||
'status': 'completed',
|
||||
'queued_at': '2026-05-19 12:00:00',
|
||||
'started_at': '2026-05-19 12:00:01',
|
||||
'finished_at': '2026-05-19 12:00:05',
|
||||
'updated_at': '2026-05-19 12:00:05',
|
||||
'filenames': ['/app/data/reports/ocbot_daily_20260518.pptx'],
|
||||
'max_files': 1,
|
||||
'summary': {
|
||||
'audited_files': [{
|
||||
'path': '/app/data/reports/ocbot_daily_20260518.pptx',
|
||||
'slides_checked': 1,
|
||||
'issues': 0,
|
||||
'error': None,
|
||||
}],
|
||||
'total_issues': 0,
|
||||
'errors': [],
|
||||
},
|
||||
}), encoding='utf-8')
|
||||
|
||||
status = svc.get_ppt_vision_audit_status()
|
||||
|
||||
assert status['status'] == 'completed'
|
||||
assert status['last_run']['updated_at'] == '2026-05-19 12:00:05'
|
||||
assert status['last_run']['filenames'] == ['ocbot_daily_20260518.pptx']
|
||||
assert '/app/data/reports' not in str(status)
|
||||
|
||||
|
||||
def test_ppt_vision_audit_background_respects_persisted_running(monkeypatch, tmp_path):
|
||||
"""另一個 worker 已在跑時,新 request 應回 already_running,避免重複開模型任務。"""
|
||||
import json
|
||||
from services import ppt_vision_service as svc
|
||||
|
||||
state_path = tmp_path / 'vision_state.json'
|
||||
monkeypatch.setenv('PPT_VISION_STATE_PATH', str(state_path))
|
||||
monkeypatch.setattr(svc, '_LAST_AUDIT_RUN', None)
|
||||
state_path.write_text(json.dumps({
|
||||
'ok': True,
|
||||
'status': 'running',
|
||||
'queued_at': '2999-05-19 12:00:00',
|
||||
'started_at': '2999-05-19 12:00:01',
|
||||
'updated_at': '2999-05-19 12:00:01',
|
||||
'filenames': ['/app/data/reports/ocbot_daily_20260518.pptx'],
|
||||
'max_files': 1,
|
||||
}), encoding='utf-8')
|
||||
|
||||
result = svc.start_ppt_vision_audit_background(
|
||||
filenames=['ocbot_daily_20260518.pptx'],
|
||||
max_files=1,
|
||||
)
|
||||
|
||||
assert result['ok'] is True
|
||||
assert result['status'] == 'already_running'
|
||||
assert result['last_run']['filenames'] == ['ocbot_daily_20260518.pptx']
|
||||
|
||||
|
||||
def test_ppt_audit_vision_status_route_returns_json(client, monkeypatch):
|
||||
"""頁面輪詢用 status endpoint 要能回最近一次背景視覺 QA 狀態。"""
|
||||
from services import ppt_vision_service as svc
|
||||
|
||||
Reference in New Issue
Block a user