fix(awooop): 等待 source correlation review 回寫
This commit is contained in:
171
apps/api/tests/test_awooop_source_correlation_apply_smoke.py
Normal file
171
apps/api/tests/test_awooop_source_correlation_apply_smoke.py
Normal file
@@ -0,0 +1,171 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT_PATH = (
|
||||
Path(__file__).resolve().parents[3]
|
||||
/ "scripts"
|
||||
/ "awooop_source_correlation_apply_smoke.py"
|
||||
)
|
||||
SPEC = importlib.util.spec_from_file_location(
|
||||
"awooop_source_correlation_apply_smoke",
|
||||
SCRIPT_PATH,
|
||||
)
|
||||
awooop_source_correlation_apply_smoke = importlib.util.module_from_spec(SPEC)
|
||||
assert SPEC and SPEC.loader
|
||||
sys.dont_write_bytecode = True
|
||||
sys.modules[SPEC.name] = awooop_source_correlation_apply_smoke
|
||||
SPEC.loader.exec_module(awooop_source_correlation_apply_smoke)
|
||||
|
||||
|
||||
def test_failed_check_summary_lists_preflight_failures() -> None:
|
||||
payload = {
|
||||
"checks": [
|
||||
{
|
||||
"name": "source_review_work_item",
|
||||
"passed": True,
|
||||
"detail": "source_correlation_review",
|
||||
},
|
||||
{
|
||||
"name": "accepted_review_recorded",
|
||||
"passed": False,
|
||||
"detail": "missing",
|
||||
},
|
||||
{
|
||||
"name": "target_incident_present",
|
||||
"passed": False,
|
||||
"detail": "missing target_incident_id",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
assert awooop_source_correlation_apply_smoke._failed_check_summary(payload) == (
|
||||
"accepted_review_recorded=missing, "
|
||||
"target_incident_present=missing target_incident_id"
|
||||
)
|
||||
|
||||
|
||||
def test_source_review_readback_state_detects_accepted_review() -> None:
|
||||
recurrence = {
|
||||
"items": [
|
||||
{
|
||||
"work_item": {
|
||||
"kind": "source_correlation_review",
|
||||
"work_item_id": (
|
||||
"source-evidence:sentry:upstream_canary:"
|
||||
"awoooi-source-link-canary-gitea-cd-4294-1"
|
||||
),
|
||||
},
|
||||
"source_correlation_review": {
|
||||
"work_item_id": (
|
||||
"source-evidence:sentry:upstream_canary:"
|
||||
"awoooi-source-link-canary-gitea-cd-4294-1"
|
||||
),
|
||||
"decision": "accepted",
|
||||
"review_id": "review-1",
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
state = awooop_source_correlation_apply_smoke._source_review_readback_state(
|
||||
recurrence,
|
||||
work_item_id=(
|
||||
"source-evidence:sentry:upstream_canary:"
|
||||
"awoooi-source-link-canary-gitea-cd-4294-1"
|
||||
),
|
||||
)
|
||||
|
||||
assert state == {
|
||||
"found": True,
|
||||
"decision": "accepted",
|
||||
"review_id": "review-1",
|
||||
}
|
||||
|
||||
|
||||
def test_source_review_readback_state_reports_missing_review() -> None:
|
||||
recurrence = {
|
||||
"items": [
|
||||
{
|
||||
"work_item": {
|
||||
"kind": "source_correlation_review",
|
||||
"work_item_id": "source-evidence:sentry:upstream_canary:item-1",
|
||||
},
|
||||
"source_correlation_review": None,
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
state = awooop_source_correlation_apply_smoke._source_review_readback_state(
|
||||
recurrence,
|
||||
work_item_id="source-evidence:sentry:upstream_canary:item-1",
|
||||
)
|
||||
|
||||
assert state == {
|
||||
"found": True,
|
||||
"decision": "missing",
|
||||
"review_id": None,
|
||||
}
|
||||
|
||||
|
||||
def test_wait_for_review_readback_retries_until_accepted(monkeypatch) -> None:
|
||||
work_item_id = "source-evidence:sentry:upstream_canary:item-1"
|
||||
calls: list[str] = []
|
||||
recurrences = [
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"work_item": {
|
||||
"kind": "source_correlation_review",
|
||||
"work_item_id": work_item_id,
|
||||
},
|
||||
"source_correlation_review": None,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"work_item": {
|
||||
"kind": "source_correlation_review",
|
||||
"work_item_id": work_item_id,
|
||||
},
|
||||
"source_correlation_review": {
|
||||
"work_item_id": work_item_id,
|
||||
"decision": "accepted",
|
||||
"review_id": "review-2",
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
def fake_http_json(url: str, **_: object) -> dict[str, object]:
|
||||
calls.append(url)
|
||||
return recurrences[min(len(calls) - 1, len(recurrences) - 1)]
|
||||
|
||||
monkeypatch.setattr(awooop_source_correlation_apply_smoke, "_http_json", fake_http_json)
|
||||
monkeypatch.setattr(awooop_source_correlation_apply_smoke.time, "sleep", lambda _: None)
|
||||
|
||||
state = awooop_source_correlation_apply_smoke._wait_for_review_readback(
|
||||
args=SimpleNamespace(
|
||||
api_url="https://awoooi.wooo.work",
|
||||
project_id="awoooi",
|
||||
provider="sentry",
|
||||
limit=300,
|
||||
review_readback_attempts=2,
|
||||
review_readback_interval_seconds=0,
|
||||
),
|
||||
work_item_id=work_item_id,
|
||||
)
|
||||
|
||||
assert state == {
|
||||
"found": True,
|
||||
"decision": "accepted",
|
||||
"review_id": "review-2",
|
||||
}
|
||||
assert len(calls) == 2
|
||||
Reference in New Issue
Block a user