Files
nisse/tests/integration/test_crash_durability.py
T
dongarandClaude Fable 5 18d4fcd701
CI / checks (push) Successful in 9s
CI / checks (pull_request) Successful in 8s
Implement A9 state-change logging in the state store
Retrofit for the conventions merged in #4 (issue #3):

- OpLog: JSON-lines emitter with the fixed envelope (ts, agent,
  event, task_id, cause); task_id set by the orchestrator at
  unit-of-work start
- StateStore owns emission: transition, intent begin/commit/abort,
  and schema migrations each emit their event right after the
  durable write commits; callers pass the cause
- reconcile_on_boot emits boot.reconcile with action and verdicts,
  and resolves intents with reconciliation-verdict causes
- Failed resolutions emit nothing (a line exists iff the write
  committed)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-05 21:13:36 +00:00

48 lines
1.4 KiB
Python

"""Integration: state written before an abrupt process death must be intact
and the in-flight intent visible on the next boot (spec A2/A3)."""
import subprocess
import sys
from pathlib import Path
import pytest
from nisse_dev.reconcile import reconcile_on_boot
from nisse_dev.state import StateStore
pytestmark = pytest.mark.integration
CRASH_SCRIPT = """
import os
import sys
from nisse_dev.state import StateStore
store = StateStore(sys.argv[1])
store.transition("EXECUTING", cause="test", project="demo", data={"milestone": 2})
store.begin_intent("push_branch", {"branch": "milestone-2"}, cause="test")
os._exit(1) # die without closing anything, as a power cut would
"""
def test_state_survives_process_death(tmp_path: Path) -> None:
db = tmp_path / "state.db"
result = subprocess.run(
[sys.executable, "-c", CRASH_SCRIPT, str(db)],
capture_output=True,
text=True,
timeout=30,
check=False,
)
assert result.returncode == 1, result.stderr
with StateStore(db) as store:
state = store.get_state()
assert state is not None
assert state.state == "EXECUTING"
assert state.data == {"milestone": 2}
report = reconcile_on_boot(store, {"push_branch": lambda intent: None})
assert report.action == "await_input"
[pending] = store.pending_intents()
assert pending.payload == {"branch": "milestone-2"}