42 lines
2.2 KiB
Python
42 lines
2.2 KiB
Python
import json
|
|
from types import SimpleNamespace
|
|
|
|
from dx_productivity.trial_task_center.read_trace import ReadTrace
|
|
|
|
|
|
def test_trace_keeps_last_stage_and_bounded_unicode_evidence(tmp_path):
|
|
trace = ReadTrace(tmp_path, project='board.prj', backend='native')
|
|
trace.emit('effective_parse', state='failed', uid='$1l44', raw_line='中文' * 10000)
|
|
rows = [json.loads(line) for line in (tmp_path / 'read-trace.jsonl').read_text('utf-8').splitlines()]
|
|
assert rows[-1]['stage'] == 'effective_parse' and rows[-1]['uid'] == '$1l44'
|
|
assert rows[-1]['pid'] > 0 and rows[-1]['timestamp_utc']
|
|
assert len(rows[-1]['raw_line']) < 4096
|
|
assert json.loads((tmp_path / 'read-state.json').read_text('utf-8')) == rows[-1]
|
|
|
|
|
|
def test_trace_io_failure_cannot_change_business_flow(tmp_path):
|
|
blocked = tmp_path / 'not-a-directory'
|
|
blocked.write_text('occupied')
|
|
ReadTrace(blocked).emit('open_project', state='started')
|
|
assert blocked.read_text() == 'occupied'
|
|
|
|
|
|
def test_supervised_read_progress_and_failed_rows_are_visible_in_main_log(tmp_path, monkeypatch):
|
|
from dx_productivity.trial_task_center.service import TaskCenterService
|
|
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
|
from dx_productivity.trial_task_center import batch_supervisor
|
|
from dx_productivity.trial_task_center.bom_import_report import BomImportReport, BomRowResult
|
|
report = BomImportReport((BomRowResult(2, 'board.prj', 'board', 'failed', 'missing UID'),), ())
|
|
def supervise(service, operation, arguments, **controls):
|
|
controls['on_progress']('正在打开工程 board.prj')
|
|
return report
|
|
monkeypatch.setattr(batch_supervisor, 'run_supervised', supervise)
|
|
context = configure_logging(tmp_path)
|
|
service = SimpleNamespace(_logging=context, _operation=lambda name, task, action: action())
|
|
messages = []
|
|
assert TaskCenterService._supervise(service, 'inspect_bom_batch', {'task_id': 'task1'}, on_progress=messages.append) is report
|
|
text = context.application_log_path.read_text('utf-8')
|
|
assert '正在打开工程 board.prj' in text and 'missing UID' in text
|
|
assert 'excel_row=2' in text and 'failed_rows=1' in text
|
|
assert messages == ['正在打开工程 board.prj']
|