補 PPT 視覺 QA stale recovery
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s
This commit is contained in:
@@ -797,6 +797,68 @@ def test_ppt_vision_audit_background_respects_persisted_running(monkeypatch, tmp
|
||||
assert result['last_run']['filenames'] == ['ocbot_daily_20260518.pptx']
|
||||
|
||||
|
||||
def test_ppt_vision_audit_status_marks_dead_worker_stale(monkeypatch, tmp_path):
|
||||
"""部署 reload 後若舊 worker 已不存在,running state 要自動轉為可診斷錯誤。"""
|
||||
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)
|
||||
monkeypatch.setattr(svc, '_pid_exists', lambda _pid: False)
|
||||
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',
|
||||
'pid': 999999,
|
||||
'filenames': ['/app/data/reports/ocbot_daily_20260518.pptx'],
|
||||
'max_files': 1,
|
||||
}), encoding='utf-8')
|
||||
|
||||
status = svc.get_ppt_vision_audit_status()
|
||||
|
||||
assert status['running'] is False
|
||||
assert status['status'] == 'error'
|
||||
assert 'worker no longer running' in status['last_run']['error']
|
||||
assert status['last_run']['filenames'] == ['ocbot_daily_20260518.pptx']
|
||||
|
||||
|
||||
def test_ppt_vision_audit_background_allows_retry_after_dead_worker(monkeypatch, tmp_path):
|
||||
"""dead PID 的 running state 不應阻擋下一次手動補跑。"""
|
||||
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)
|
||||
monkeypatch.setattr(svc, '_pid_exists', lambda _pid: False)
|
||||
monkeypatch.setattr(svc, 'audit_recent_ppts', lambda **_kwargs: {
|
||||
'audited_files': [],
|
||||
'total_issues': 0,
|
||||
'errors': [],
|
||||
})
|
||||
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',
|
||||
'pid': 999999,
|
||||
'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'] == 'queued'
|
||||
|
||||
|
||||
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