67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from gyxx_flow.ops.effects import (
|
|
EffectAlreadyApplied,
|
|
EffectLedger,
|
|
EffectStateAmbiguous,
|
|
)
|
|
|
|
|
|
def test_effect_ledger_blocks_applied_and_ambiguous_replays(tmp_path: Path) -> None:
|
|
ledger = EffectLedger(tmp_path)
|
|
first = ledger.begin(
|
|
workflow_id="product.daily",
|
|
business_date="2026-07-27",
|
|
step_id="legacy_execute",
|
|
run_id="run-001",
|
|
)
|
|
ledger.mark_applied(first)
|
|
|
|
with pytest.raises(EffectAlreadyApplied):
|
|
ledger.begin(
|
|
workflow_id="product.daily",
|
|
business_date="2026-07-27",
|
|
step_id="legacy_execute",
|
|
run_id="run-002",
|
|
)
|
|
|
|
ambiguous = ledger.begin(
|
|
workflow_id="product.daily",
|
|
business_date="2026-07-28",
|
|
step_id="legacy_execute",
|
|
run_id="run-003",
|
|
)
|
|
ledger.mark_ambiguous(ambiguous, reason="nonzero-exit")
|
|
with pytest.raises(EffectStateAmbiguous):
|
|
ledger.begin(
|
|
workflow_id="product.daily",
|
|
business_date="2026-07-28",
|
|
step_id="legacy_execute",
|
|
run_id="run-004",
|
|
)
|
|
|
|
|
|
def test_effect_ledger_leaves_in_progress_claim_ambiguous_after_crash(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
ledger = EffectLedger(tmp_path)
|
|
ledger.begin(
|
|
workflow_id="shop.metrics.weekly",
|
|
business_date="2026-07-27",
|
|
step_id="legacy_collect",
|
|
run_id="run-001",
|
|
)
|
|
|
|
with pytest.raises(EffectStateAmbiguous):
|
|
ledger.begin(
|
|
workflow_id="shop.metrics.weekly",
|
|
business_date="2026-07-27",
|
|
step_id="legacy_collect",
|
|
run_id="run-002",
|
|
)
|
|
|