Implement A9 state-change logging in the state store
Retrofit for the conventions merged in #4 (issue #3): - OpLog: JSON-lines emitter with the fixed envelope (ts, agent, event, task_id, cause); task_id set by the orchestrator at unit-of-work start - StateStore owns emission: transition, intent begin/commit/abort, and schema migrations each emit their event right after the durable write commits; callers pass the cause - reconcile_on_boot emits boot.reconcile with action and verdicts, and resolves intents with reconciliation-verdict causes - Failed resolutions emit nothing (a line exists iff the write committed) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba848281ec
commit
18d4fcd701
7 files changed
+216
-32
No files matched your search
@@ -26,7 +26,9 @@ def test_fresh_store_stamps_schema_version(db: Path) -> None:
|
||||
|
||||
def test_transition_persists_across_reopen(db: Path) -> None:
|
||||
with StateStore(db) as store:
|
||||
store.transition("EXECUTING", project="demo", data={"milestone": 2})
|
||||
store.transition(
|
||||
"EXECUTING", cause="test", project="demo", data={"milestone": 2}
|
||||
)
|
||||
with StateStore(db) as store:
|
||||
state = store.get_state()
|
||||
assert state is not None
|
||||
@@ -42,18 +44,18 @@ def test_get_state_on_fresh_store_is_none(db: Path) -> None:
|
||||
|
||||
def test_intent_lifecycle(db: Path) -> None:
|
||||
with StateStore(db) as store:
|
||||
intent_id = store.begin_intent("push_branch", {"branch": "m2"})
|
||||
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)
|
||||
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"})
|
||||
store.begin_intent("open_pr", {"title": "hello"}, cause="test")
|
||||
with StateStore(db) as store:
|
||||
[pending] = store.pending_intents()
|
||||
assert pending.kind == "open_pr"
|
||||
@@ -61,19 +63,19 @@ def test_pending_intent_survives_reopen(db: Path) -> None:
|
||||
|
||||
def test_aborted_intent_is_not_pending(db: Path) -> None:
|
||||
with StateStore(db) as store:
|
||||
intent_id = store.begin_intent("push_branch", {})
|
||||
store.abort_intent(intent_id)
|
||||
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", {})
|
||||
store.commit_intent(intent_id)
|
||||
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)
|
||||
store.commit_intent(intent_id, cause="test")
|
||||
with pytest.raises(KeyError):
|
||||
store.abort_intent(9999)
|
||||
store.abort_intent(9999, cause="test")
|
||||
|
||||
|
||||
def test_migration_runs_and_bumps_version(db: Path) -> None:
|
||||
|
||||
Reference in new issue
Block a user