4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
"""Test: generate_report unmasks slack_message before delivery."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _enable_masking(monkeypatch) -> None:
|
|
monkeypatch.setenv("OPENSRE_MASK_ENABLED", "true")
|
|
|
|
|
|
def _state_with_masking() -> dict[str, object]:
|
|
return {
|
|
"alert_name": "pipeline failure",
|
|
"pipeline_name": "pipeline",
|
|
"severity": "warning",
|
|
"problem_md": "# Incident in <NAMESPACE_0>",
|
|
"slack_message": "",
|
|
"report": "",
|
|
"masking_map": {
|
|
"<POD_0>": "etl-worker-7d9f8b-xkp2q",
|
|
"<NAMESPACE_0>": "tracer-test",
|
|
},
|
|
"root_cause": "etl-worker-7d9f8b-xkp2q OOMKilled in tracer-test",
|
|
"evidence": {},
|
|
"context": {},
|
|
"resolved_integrations": {},
|
|
"slack_context": {},
|
|
"discord_context": {},
|
|
"validated_claims": [],
|
|
"non_validated_claims": [],
|
|
}
|
|
|
|
|
|
def test_slack_message_is_unmasked_before_delivery() -> None:
|
|
from tools.investigation.reporting import node as pub_node
|
|
from tools.investigation.reporting.formatters.messages import ReportMessages
|
|
|
|
masked_message = "Root cause: <POD_0> crashed in <NAMESPACE_0>. Impact: customer-facing."
|
|
|
|
with (
|
|
patch.object(pub_node, "build_report_context", return_value=MagicMock()),
|
|
patch.object(
|
|
pub_node,
|
|
"build_report_messages",
|
|
return_value=ReportMessages(masked_message, "tg", "wa", []),
|
|
),
|
|
patch.object(pub_node, "render_report"),
|
|
patch.object(pub_node, "open_in_editor"),
|
|
patch.object(
|
|
pub_node,
|
|
"create_investigation_and_attach_url",
|
|
return_value=("inv-123", "https://test/inv-123"),
|
|
),
|
|
patch("integrations.slack.delivery.send_slack_report", return_value=(False, None)),
|
|
patch("integrations.slack.delivery.build_action_blocks", return_value=[]),
|
|
):
|
|
result = pub_node.generate_report(_state_with_masking()) # type: ignore[arg-type]
|
|
|
|
assert "<POD_0>" not in result["slack_message"]
|
|
assert "<NAMESPACE_0>" not in result["slack_message"]
|
|
assert "etl-worker-7d9f8b-xkp2q" in result["slack_message"]
|
|
assert "tracer-test" in result["slack_message"]
|
|
|
|
|
|
def test_empty_masking_map_is_passthrough() -> None:
|
|
from tools.investigation.reporting import node as pub_node
|
|
from tools.investigation.reporting.formatters.messages import ReportMessages
|
|
|
|
state = _state_with_masking()
|
|
state["masking_map"] = {}
|
|
message_without_placeholders = "Plain report with no placeholders."
|
|
|
|
with (
|
|
patch.object(pub_node, "build_report_context", return_value=MagicMock()),
|
|
patch.object(
|
|
pub_node,
|
|
"build_report_messages",
|
|
return_value=ReportMessages(message_without_placeholders, "tg", "wa", []),
|
|
),
|
|
patch.object(pub_node, "render_report"),
|
|
patch.object(pub_node, "open_in_editor"),
|
|
patch.object(
|
|
pub_node,
|
|
"create_investigation_and_attach_url",
|
|
return_value=("inv-123", "https://test/inv-123"),
|
|
),
|
|
patch("integrations.slack.delivery.send_slack_report", return_value=(False, None)),
|
|
patch("integrations.slack.delivery.build_action_blocks", return_value=[]),
|
|
):
|
|
result = pub_node.generate_report(state) # type: ignore[arg-type]
|
|
|
|
assert result["slack_message"] == message_without_placeholders
|