fix(awooop): 等待 source correlation review 回寫
Some checks failed
Code Review / ai-code-review (push) Successful in 14s
CD Pipeline / tests (push) Successful in 1m31s
CD Pipeline / build-and-deploy (push) Successful in 3m57s
CD Pipeline / post-deploy-checks (push) Failing after 15s

This commit is contained in:
Your Name
2026-06-15 12:42:37 +08:00
parent 2f559e8881
commit 802c4e5ab2
2 changed files with 259 additions and 1 deletions

View 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