Files
nisse/tests/integration/test_crash_durability.py
T
dongarandClaude Fable 5 ac81dd6234
CI / checks (push) Successful in 9s
CI / checks (pull_request) Successful in 8s
Add canonical event log and renderer skeleton (A10)
Build-order step 4, sequenced before the LLM client (step 3) because
the client interface consumes the canonical log.

- canonical.py: typed events for the full A10 table (user_message
  through compaction); canonical tool-call IDs minted locally,
  provider IDs never a join key; strict payload validation on load
- StateStore: canonical_events table via schema v2 — the first real
  migration, exercised in a test against a hand-built v1 database —
  with append_event/read_events on the same fsync-per-commit path
- render.py: request bodies rendered from the log at call time;
  first adapter targets the OpenAI-compatible shape of LiteLLM's
  normalized route; compaction events replace their id range at
  render time while staying in the durable log
- Crash integration test now also verifies transcript appends
  survive process death

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-06 19:51:58 +00:00

53 lines
1.6 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.canonical import UserMessage
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")
store.append_event(UserMessage(text="start milestone 2", source="m:1"))
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"}
[stored] = store.read_events()
assert stored.event.text == "start milestone 2"