Build-order step 1: the critical path everything else sits on. - StateStore: SQLite in WAL mode with synchronous=FULL, so every state transition and intent-log write is committed and fsynced before returning; a power cut cannot tear state - Durable intent log: begin_intent records a unit of work before it starts; commit/abort resolve it; pending intents survive restart - schema_version stamped from the first commit, with a sequential migration hook; a newer state file than the code supports is refused rather than misread - reconcile_on_boot (A3 first cut): pending intents are checked against external truth by registered reconcilers (observable checks, never model self-assessment); verified effects are committed, verified no-ops aborted, anything unverifiable gates to AWAIT_INPUT — never blind-resume - Lives in nisse_dev per spec 0.1: the library is extracted after the dev agent works, not designed up front - Integration test kills a subprocess mid-work with os._exit and verifies state integrity and intent visibility on reopen Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
48 lines
1.4 KiB
Python
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", project="demo", data={"milestone": 2})
|
|
store.begin_intent("push_branch", {"branch": "milestone-2"})
|
|
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"}
|