CI / checks (push) Skipped
CI / checks (pull_request) Successful in 1m14s
Development Plan M1.1, as discussed. - Schema v4: a work_items table (id, scope, title, status, outcome, position, data) and an agent row whose active_item points at one (NULL: idle). Canonical events and intents carry their work item, and events their actor. Older stores are refused with a clear message: there was no production data, so no migration (the mechanism stays). - The log is reached through a Transcript bound to one work item and one actor: store.transcript(item, actor) reads only that item and writes with both. The planner, executor, delegation and expert desk get one per call from the orchestrator instead of holding the store, so a component can neither read another task's events (the planner read every earlier task's, #78) nor write without attribution. store.all_events() is kept for readers that span items (evaluation capture, dumps). Intents are begun through the transcript or with work_item=, so each belongs to its item. - The orchestrator opens a work item on 'use', closes it with its outcome (completed or abandoned), and carries what the operator said while idle into the new item as copies with their origin, so a task sent before 'use' is still planned from (D1). control.py keeps its state machine through get_state()/transition(), now over the active work item, until M2.6 retires it. - nisse_dev.dump shows work items and each event's item and actor. Tests: test_work_items.py (scoping, attribution, intent ownership, restart, outcomes, carried messages, a second task never seeing the first); the suites updated for the per-call transcript. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPQ14L3LikyefCMFBqEbKE
53 lines
1.6 KiB
Python
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 (architecture L8)."""
|
|
|
|
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.transcript("t", "operator").append(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.all_events()
|
|
assert stored.event.text == "start milestone 2"
|