Add schedule smoke test routine

This commit is contained in:
2026-06-06 15:32:57 +02:00
parent e926636617
commit 418eb4ffda
8 changed files with 472 additions and 3 deletions

View File

@@ -338,6 +338,27 @@ def test_execute_instruction_with_audit_accepts_report_payload():
assert result.output_validated is True
def test_execute_instruction_with_audit_accepts_fenced_report_payload():
report_data = {
"summary": "State Hub has loose ends.",
"recommendations": [{"action": "revisit", "candidate": "CUST-WP-0045"}],
}
llm = _CountingLLM([f"```json\n{json.dumps(report_data)}\n```"])
instr = _instr(
id="daily-triage-report",
prompt="Report.",
trusted_fields=[],
output_schema="schemas/daily-triage-report.json",
)
result = execute_instruction_with_audit(instr, _Event(), {}, llm)
assert result.tasks == []
assert result.report == report_data
assert result.output_validated is True
assert llm.call_count == 1
def test_execute_instruction_with_audit_rejects_invalid_report_schema():
report_data = {"summary": "Missing recommendations."}
llm = _CountingLLM([json.dumps(report_data), json.dumps(report_data)])

View File

@@ -13,6 +13,7 @@ from __future__ import annotations
import asyncio
import uuid
from datetime import datetime, timedelta, timezone
import pytest
from temporalio.client import ScheduleOverlapPolicy
@@ -21,8 +22,11 @@ from temporalio.testing import WorkflowEnvironment
from activity_core.models import ActivityDefinition, CronTriggerConfig
from activity_core.schedule_manager import (
delete_schedule,
delete_smoke_test_schedule,
list_schedules,
schedule_id,
schedule_smoke_test,
smoke_schedule_id,
upsert_schedule,
)
@@ -180,3 +184,30 @@ async def test_misfire_policy_compress_sets_overlap_buffer_one(env: WorkflowEnvi
assert desc.schedule.policy.overlap == ScheduleOverlapPolicy.BUFFER_ONE
await delete_schedule(env.client, defn.id)
@pytest.mark.asyncio
async def test_schedule_smoke_test_creates_one_shot_schedule(
env: WorkflowEnvironment,
) -> None:
defn = _make_defn()
fire_base = datetime(2026, 6, 6, 12, 0, tzinfo=timezone.utc)
sid, workflow_id, fire_at = await schedule_smoke_test(
env.client,
defn,
delay=timedelta(minutes=1),
now=fire_base,
)
assert sid == smoke_schedule_id(defn.id)
assert workflow_id == f"activity-{defn.id}:smoke-20260606T120100Z"
assert fire_at == datetime(2026, 6, 6, 12, 1, tzinfo=timezone.utc)
handle = env.client.get_schedule_handle(sid)
desc = await handle.describe()
assert desc.schedule.state.limited_actions is True
assert desc.schedule.state.remaining_actions == 1
assert desc.schedule.spec.time_zone_name == "UTC"
await delete_smoke_test_schedule(env.client, defn.id)

View File

@@ -0,0 +1,32 @@
from __future__ import annotations
import importlib.util
from pathlib import Path
def _load_script():
path = Path(__file__).parent.parent / "scripts" / "smoke_test_schedule.py"
spec = importlib.util.spec_from_file_location("smoke_test_schedule", path)
assert spec is not None
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
return module
def test_schedule_smoke_script_dry_run_contract() -> None:
script = _load_script()
args = script.parse_args([
"--activity-id",
"00000000-0000-0000-0000-000000000123",
"--recreate-recurring",
"--dry-run",
])
report = script.build_dry_run_report(args)
assert report["mode"] == "dry-run"
assert report["activity_id"] == "00000000-0000-0000-0000-000000000123"
assert report["recreate_recurring"] is True
assert report["delay_seconds"] == 60
assert "create a one-shot smoke Temporal Schedule one minute in the future" in report["checks"]