fix(awooop): set shadow run defaults for mirrors
This commit is contained in:
@@ -82,11 +82,15 @@ async def ensure_completed_shadow_run(
|
||||
INSERT INTO awooop_run_state (
|
||||
run_id, project_id, agent_id, state,
|
||||
trigger_type, trigger_ref, is_shadow,
|
||||
input_sha256, created_at, completed_at, timeout_at
|
||||
input_sha256,
|
||||
attempt_count, max_attempts, cost_usd, step_count,
|
||||
created_at, completed_at, timeout_at
|
||||
) VALUES (
|
||||
:run_id, :project_id, :agent_id, 'completed',
|
||||
:trigger_type, :trigger_ref, TRUE,
|
||||
:input_sha256, NOW(), NOW(), NOW()
|
||||
:input_sha256,
|
||||
0, 3, 0.0000, 0,
|
||||
NOW(), NOW(), NOW()
|
||||
)
|
||||
ON CONFLICT (run_id) DO NOTHING
|
||||
RETURNING run_id
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
from src.services.channel_hub import (
|
||||
build_grouped_alert_provider_event_id,
|
||||
build_grouped_alert_run_id,
|
||||
ensure_completed_shadow_run,
|
||||
format_grouped_alert_digest_text,
|
||||
format_grouped_alert_event_content,
|
||||
)
|
||||
@@ -67,3 +68,40 @@ def test_format_grouped_alert_digest_text_is_html_safe() -> None:
|
||||
assert "sentry&snuba" in content
|
||||
assert "<b>7</b> 筆同組告警" in content
|
||||
assert "AwoooP Run 監控" in content
|
||||
|
||||
|
||||
class _FakeResult:
|
||||
def fetchone(self) -> tuple[str] | None:
|
||||
return ("created",)
|
||||
|
||||
|
||||
class _FakeSession:
|
||||
def __init__(self) -> None:
|
||||
self.statement = ""
|
||||
self.params = {}
|
||||
|
||||
async def execute(self, statement, params): # noqa: ANN001
|
||||
self.statement = str(statement)
|
||||
self.params = params
|
||||
return _FakeResult()
|
||||
|
||||
|
||||
async def test_completed_shadow_run_sets_run_state_not_null_defaults() -> None:
|
||||
session = _FakeSession()
|
||||
run_id = build_grouped_alert_run_id("awoooi", "provider-event")
|
||||
|
||||
inserted = await ensure_completed_shadow_run(
|
||||
session, # type: ignore[arg-type]
|
||||
project_id="awoooi",
|
||||
run_id=run_id,
|
||||
agent_id="legacy-telegram-gateway",
|
||||
trigger_type="legacy_outbound",
|
||||
trigger_ref="12713",
|
||||
input_payload={"message_type": "final"},
|
||||
)
|
||||
|
||||
assert inserted is True
|
||||
assert "attempt_count, max_attempts, cost_usd, step_count" in session.statement
|
||||
assert "0, 3, 0.0000, 0" in session.statement
|
||||
assert session.params["project_id"] == "awoooi"
|
||||
assert session.params["run_id"] == run_id
|
||||
|
||||
Reference in New Issue
Block a user