Files
nisse/nisse-dev/tests/test_reconcile.py
T
dongarandClaude Fable 5 4319882f35
CI / checks (push) Successful in 8s
CI / checks (pull_request) Successful in 7s
Add durable state store and boot-time reconciliation (A2/A3)
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>
2026-09-05 18:59:15 +00:00

69 lines
2.3 KiB
Python

from pathlib import Path
import pytest
from nisse_dev.reconcile import reconcile_on_boot
from nisse_dev.state import Intent, StateStore
@pytest.fixture
def store(tmp_path: Path) -> StateStore:
return StateStore(tmp_path / "state.db")
def test_no_pending_intents_resumes(store: StateStore) -> None:
report = reconcile_on_boot(store, {})
assert report.action == "resume"
assert report.notes == []
def test_verified_effect_commits_intent_and_resumes(store: StateStore) -> None:
store.begin_intent("push_branch", {"branch": "m2"})
report = reconcile_on_boot(store, {"push_branch": lambda intent: True})
assert report.action == "resume"
assert store.pending_intents() == []
def test_verified_no_effect_aborts_intent_and_resumes(store: StateStore) -> None:
store.begin_intent("push_branch", {"branch": "m2"})
report = reconcile_on_boot(store, {"push_branch": lambda intent: False})
assert report.action == "resume"
assert store.pending_intents() == []
def test_unverifiable_intent_gates_to_await_input(store: StateStore) -> None:
store.begin_intent("push_branch", {"branch": "m2"})
report = reconcile_on_boot(store, {"push_branch": lambda intent: None})
assert report.action == "await_input"
assert [i.kind for i in store.pending_intents()] == ["push_branch"]
def test_unknown_intent_kind_gates_to_await_input(store: StateStore) -> None:
store.begin_intent("mystery", {})
report = reconcile_on_boot(store, {})
assert report.action == "await_input"
assert "no reconciler registered" in report.notes[0]
def test_reconciler_receives_the_intent(store: StateStore) -> None:
store.begin_intent("push_branch", {"branch": "m2"})
seen: list[Intent] = []
def check(intent: Intent) -> bool:
seen.append(intent)
return True
reconcile_on_boot(store, {"push_branch": check})
assert seen[0].payload == {"branch": "m2"}
def test_mixed_verdicts_still_gate(store: StateStore) -> None:
store.begin_intent("push_branch", {})
store.begin_intent("open_pr", {})
report = reconcile_on_boot(
store,
{"push_branch": lambda intent: True, "open_pr": lambda intent: None},
)
assert report.action == "await_input"
assert [i.kind for i in store.pending_intents()] == ["open_pr"]