Files
nisse/nisse-dev/tests/test_state.py
T
dongarandClaude Opus 5.5 6ae2375194
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 2m16s
CI / e2e (pull_request) Successful in 10m51s
M2.8: switch over to the new loop
nisse-dev now runs only the conversational loop. The gated state machine
it was built alongside is gone:

- Removed control.py, planner.py, executor.py, approvals.py, gates.py
  (command_form moves to loop/reader.py), publish.py and poller.py, the
  old assembly in agent.py (its shared helpers move to loop/build.py),
  the store's state-machine view (get_state, transition), their tests,
  the old end-to-end and live planning/milestone/gate tests, and
  specs/orchestrator.qnt with its scenarios.
- Roles are driver, helper, expert and classifier; driver is required.
  loop:, roles.planner, roles.executor and tuning.executor are refused
  with what to use instead; tuning.driver takes the turn cap and failure
  limit.
- The benchmark and the capability matrix measure the driver: the
  loop's own system prompt and tools, the task's plan as the agreed
  restatement. Task plans end with finish_milestone, so earlier runs
  show as (old); stored runs' executor tuning reads as the driver's.
- A delegation on the loop records what its helper's alias resolved to
  (L9), as the old path's did.
- The dump shows a work item's revision and what it waits for.
- Behaviour the old tests covered and the loop shares stays covered:
  driver runs that fail on a model call, stop mid-turn, reset the
  failure count; go-aheads ignoring case and punctuation; a request too
  big to fit is never sent; the assembly tests, now on build_loop_agent.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPQ14L3LikyefCMFBqEbKE
2026-10-08 03:12:58 +00:00

124 lines
4.2 KiB
Python

import sqlite3
from pathlib import Path
import pytest
from nisse_dev.state import StateSchemaError, StateStore
@pytest.fixture
def db(tmp_path: Path) -> Path:
return tmp_path / "state.db"
def test_wal_mode_and_full_sync(db: Path) -> None:
with StateStore(db) as store:
journal = store._conn.execute("PRAGMA journal_mode").fetchone()[0]
sync = store._conn.execute("PRAGMA synchronous").fetchone()[0]
assert journal == "wal"
assert sync == 2 # FULL
def test_fresh_store_stamps_schema_version(db: Path) -> None:
with StateStore(db, schema_version=1) as store:
assert store.schema_version == 1
def test_a_work_item_persists_across_reopen(db: Path) -> None:
with StateStore(db) as store:
store.open_work_item(
"demo-1", title="t", scope="demo", position="WAITING", cause="test"
)
store.set_active("demo-1", cause="test")
store.update_work_item(
"demo-1", position="RUNNING", data={"milestone": 2}, cause="test"
)
with StateStore(db) as store:
item = store.active_item()
assert item is not None
assert (item.id, item.scope, item.position) == ("demo-1", "demo", "RUNNING")
assert item.data == {"milestone": 2}
def test_a_fresh_store_has_no_active_item(db: Path) -> None:
with StateStore(db) as store:
assert store.active_item() is None
def test_intent_lifecycle(db: Path) -> None:
with StateStore(db) as store:
intent_id = store.begin_intent("push_branch", {"branch": "m2"}, cause="test")
[pending] = store.pending_intents()
assert pending.id == intent_id
assert pending.kind == "push_branch"
assert pending.payload == {"branch": "m2"}
store.commit_intent(intent_id, cause="test")
assert store.pending_intents() == []
def test_pending_intent_survives_reopen(db: Path) -> None:
with StateStore(db) as store:
store.begin_intent("open_pr", {"title": "hello"}, cause="test")
with StateStore(db) as store:
[pending] = store.pending_intents()
assert pending.kind == "open_pr"
def test_aborted_intent_is_not_pending(db: Path) -> None:
with StateStore(db) as store:
intent_id = store.begin_intent("push_branch", {}, cause="test")
store.abort_intent(intent_id, cause="test")
assert store.pending_intents() == []
def test_resolving_nonpending_intent_raises(db: Path) -> None:
with StateStore(db) as store:
intent_id = store.begin_intent("push_branch", {}, cause="test")
store.commit_intent(intent_id, cause="test")
with pytest.raises(KeyError):
store.commit_intent(intent_id, cause="test")
with pytest.raises(KeyError):
store.abort_intent(9999, cause="test")
def test_migration_runs_and_bumps_version(db: Path) -> None:
with StateStore(db, schema_version=1):
pass
def add_notes_table(conn: sqlite3.Connection) -> None:
conn.execute("CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT)")
with StateStore(db, schema_version=2, migrations={1: add_notes_table}) as store:
assert store.schema_version == 2
store._conn.execute("SELECT * FROM notes")
def test_missing_migration_raises(db: Path) -> None:
with StateStore(db, schema_version=1):
pass
with pytest.raises(StateSchemaError, match="no migration"):
StateStore(db, schema_version=2, migrations={})
def test_failed_migration_leaves_version_unchanged(db: Path) -> None:
with StateStore(db, schema_version=1):
pass
def broken(conn: sqlite3.Connection) -> None:
conn.execute("CREATE TABLE notes (id INTEGER PRIMARY KEY)")
raise RuntimeError("boom")
with pytest.raises(RuntimeError, match="boom"):
StateStore(db, schema_version=2, migrations={1: broken})
with StateStore(db, schema_version=1) as store:
assert store.schema_version == 1
with pytest.raises(sqlite3.OperationalError):
store._conn.execute("SELECT * FROM notes")
def test_newer_schema_is_refused(db: Path) -> None:
with StateStore(db, schema_version=3):
pass
with pytest.raises(StateSchemaError, match="newer"):
StateStore(db, schema_version=1)