From 636acd1087c7574a2397e36fc6aef340a61db261 Mon Sep 17 00:00:00 2001 From: Raykov-MS Date: Mon, 22 Jun 2026 11:48:39 +0300 Subject: [PATCH] fixes --- app/pipeline/config.py | 2 +- app/pipeline/parser.py | 2 +- app/pipeline/service.py | 3 ++- tests/unit/test_parser.py | 11 ++++++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/pipeline/config.py b/app/pipeline/config.py index 28cfc7c..77c7ae2 100644 --- a/app/pipeline/config.py +++ b/app/pipeline/config.py @@ -4,7 +4,7 @@ import re from datetime import datetime FILE_NAME_PATTERNS = ( - re.compile(r"^SKO115FZ_\d{2}_[A-Za-zА-Яа-я0-9]{9}_\d{8}_[ХX]\d{5}\.xml$"), + re.compile(r"^SKO115FZ_\d{2}_[A-Za-zА-Яа-я0-9]{9}_\d{8}_(?:[ХX]\d{5}|\d{6})\.xml$"), ) DEFAULT_OUTPUT_DIR_NAME = "Out" diff --git a/app/pipeline/parser.py b/app/pipeline/parser.py index f1c896c..e022e85 100644 --- a/app/pipeline/parser.py +++ b/app/pipeline/parser.py @@ -55,7 +55,7 @@ def parse_xml_content(file_name: str, xml_content: bytes | str) -> FileParseResu result = FileParseResult(file_name=file_name) if not validate_file_name(file_name): - result.fatal_error = "Некорректное имя файла" + result.fatal_error = "Некорректное имя XML-файла" return result try: diff --git a/app/pipeline/service.py b/app/pipeline/service.py index 83b5a46..f845516 100644 --- a/app/pipeline/service.py +++ b/app/pipeline/service.py @@ -277,7 +277,8 @@ def _upload_artifacts( write_report(report_rows, local_report) write_protocol(protocol_rows, local_protocol) - local_log.write_text("\n".join(log_lines) + "\n", encoding="utf-8") + # Use CRLF to keep one-record-per-line in Windows viewers. + local_log.write_text("\r\n".join(log_lines) + "\r\n", encoding="utf-8") upload_local_file(local_report, report_path, samba_conn=samba_conn) upload_local_file(local_protocol, protocol_path, samba_conn=samba_conn) diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index 4c13a82..186b555 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -20,7 +20,7 @@ def _base_xml(operations: str) -> str: def test_parse_xml_with_invalid_name_returns_fatal() -> None: result = parse_xml_content("broken.xml", "<СообщОперКО/>") assert result.is_fatal - assert "Некорректное имя файла" in (result.fatal_error or "") + assert "Некорректное имя XML-файла" in (result.fatal_error or "") def test_parse_xml_with_malformed_xml_returns_fatal() -> None: @@ -82,3 +82,12 @@ def test_parse_xml_operation_error_marks_partial(monkeypatch) -> None: assert not result.is_fatal assert result.operation_errors assert result.operation_errors[0].record_id == "OP3" + + +def test_parse_xml_with_numeric_suffix_file_name_is_valid() -> None: + xml = _base_xml( + "<Операция><ИдентификаторЗаписи>OP4<СуммаОпер>100" + ) + result = parse_xml_content("SKO115FZ_01_044525111_20251224_000051.xml", xml) + assert not result.is_fatal + assert len(result.rows) == 1