fix(lib.sh): load_state_json strict treats a missing DB table as unreadable (Issue #71)

A DB without its sessions table (or without both tables) was read as an
empty registry in strict mode, so stop closed a registered session
row-less and exited 0. Strict mode now fails on any OperationalError;
the non-strict reader is unchanged.

Refs #71

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GodopuandClaude Opus 5.5 committed 2026-10-25 22:15:02 +00:00
1 parent a47a4683f3
commit 5f6065344f
2 files changed
+16 -8

No files matched your search

+10 -2
View File
@@ -511,7 +511,7 @@ def test_stop_does_not_take_an_unreadable_row_for_no_row(mam_sandbox, mock_herdr
assert "orphan74" in json.loads(Path(mock_herdr).read_text())["agents"]
@pytest.mark.parametrize("broken", ["yaml-without-db", "db"])
@pytest.mark.parametrize("broken", ["yaml-without-db", "db", "no-sessions-table", "no-tables"])
def test_stop_does_not_take_an_unreadable_registry_for_no_row(mam_sandbox, mock_herdr, broken):
"""load_state_json's {} on a read error is not "no row": a registered session is not closed row-less."""
name = "orphan75-creator-claude"
@@ -522,10 +522,18 @@ def test_stop_does_not_take_an_unreadable_registry_for_no_row(mam_sandbox, mock_
for f in mam.glob("agent-sessions.db*"):
f.unlink()
(mam / "agent-sessions.yaml").write_text("herdr_sessions: [\n - {name: " + name + "\n")
else:
elif broken == "db":
for f in mam.glob("agent-sessions.db-*"):
f.unlink()
(mam / "agent-sessions.db").write_bytes(b"this is not a database" * 64)
else:
# a missing table is not an empty registry
conn = sqlite3.connect(str(mam / "agent-sessions.db"))
conn.execute("DROP TABLE sessions")
if broken == "no-tables":
conn.execute("DROP TABLE state")
conn.commit()
conn.close()
_set_mock(mock_herdr, agents={name: _agent(mam_sandbox, "w1:p76")})
res = _stop(mam_sandbox, name)
assert res.returncode == 1, res.stdout + res.stderr