Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

90 lines
3.3 KiB
Python

"""Tests for :mod:`integrations.hermes.parser`."""
from __future__ import annotations
from datetime import datetime
import pytest
from integrations.hermes.incident import LogLevel
from integrations.hermes.parser import parse_log_line
class TestParseLogLine:
def test_parses_run_id_header(self) -> None:
line = (
"2026-05-12 00:12:17,243 ERROR [20260512_001202_1bab8f] "
"tools.terminal_tool: terminal_tool exception:"
)
record = parse_log_line(line)
assert record is not None
assert record.timestamp == datetime(2026, 5, 12, 0, 12, 17, 243000)
assert record.level is LogLevel.ERROR
assert record.run_id == "20260512_001202_1bab8f"
assert record.logger == "tools.terminal_tool"
assert record.message == "terminal_tool exception:"
assert record.is_continuation is False
def test_parses_warning_without_run_id(self) -> None:
line = (
"2026-05-11 23:31:15,063 WARNING gateway.platforms.telegram_network: "
"[Telegram] Primary api.telegram.org connection failed"
)
record = parse_log_line(line)
assert record is not None
assert record.level is LogLevel.WARNING
assert record.logger == "gateway.platforms.telegram_network"
assert record.run_id is None
assert record.message.startswith("[Telegram] Primary api.telegram.org")
def test_blank_line_returns_none(self) -> None:
assert parse_log_line("") is None
assert parse_log_line("\n") is None
assert parse_log_line(" \n") is not None
def test_continuation_inherits_prev_level(self) -> None:
line = ' File "/Users/dev/.hermes/hermes-agent/tools/terminal_tool.py", line 1808'
record = parse_log_line(line, prev_level=LogLevel.ERROR)
assert record is not None
assert record.is_continuation is True
assert record.level is LogLevel.ERROR
assert record.logger == ""
assert record.message == line
def test_continuation_defaults_to_error_when_no_prev_level(self) -> None:
record = parse_log_line("Traceback (most recent call last):")
assert record is not None
assert record.is_continuation is True
# Defensive default so a multi-line payload that happens to be the
# very first line we ever see still surfaces as a high-severity
# signal rather than disappearing into DEBUG noise.
assert record.level is LogLevel.ERROR
def test_unknown_level_treated_as_continuation(self) -> None:
line = "2026-05-12 00:00:00,000 NOTICE foo.bar: msg"
record = parse_log_line(line, prev_level=LogLevel.WARNING)
assert record is not None
assert record.is_continuation is True
def test_strips_carriage_return(self) -> None:
line = "2026-05-12 00:00:00,000 INFO foo.bar: ok\r"
record = parse_log_line(line)
assert record is not None
assert record.raw == "2026-05-12 00:00:00,000 INFO foo.bar: ok"
@pytest.mark.parametrize(
"level_name",
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
)
def test_recognizes_all_standard_levels(self, level_name: str) -> None:
record = parse_log_line(f"2026-05-12 00:00:00,000 {level_name} foo.bar: hi")
assert record is not None
assert record.level is LogLevel(level_name)