Some checks failed
tamq-ci / test (push) Failing after 6s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
import json
|
|
import sqlite3
|
|
|
|
from tamq.store import Store
|
|
|
|
|
|
def test_message_history_and_jsonl(tmp_path):
|
|
store = Store(tmp_path / "tamq.sqlite3")
|
|
message_id = store.add("net-kingdom", "railiance-platform", "hello")
|
|
rows = store.list(target="railiance-platform")
|
|
assert rows[0]["message_id"] == message_id
|
|
output = tmp_path / "messages.jsonl"
|
|
store.export(rows, output)
|
|
assert json.loads(output.read_text())["body"] == "hello"
|
|
assert store.db.execute("PRAGMA journal_mode").fetchone()[0] == "wal"
|
|
store.close()
|
|
|
|
|
|
def test_store_migrates_legacy_endpoint_rows_to_manual_delivery(tmp_path):
|
|
path = tmp_path / "legacy.sqlite3"
|
|
db = sqlite3.connect(path)
|
|
db.executescript(
|
|
"""
|
|
CREATE TABLE metadata (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
INSERT INTO metadata VALUES('schema_version', '1');
|
|
CREATE TABLE endpoints (
|
|
endpoint_id TEXT PRIMARY KEY,
|
|
pid INTEGER NOT NULL,
|
|
session TEXT NOT NULL,
|
|
repos TEXT NOT NULL,
|
|
connected_at REAL NOT NULL,
|
|
disconnected_at REAL
|
|
);
|
|
INSERT INTO endpoints VALUES('legacy', 1, 'tamq', '[\"repo\"]', 1, NULL);
|
|
"""
|
|
)
|
|
db.commit()
|
|
db.close()
|
|
|
|
store = Store(path)
|
|
assert store.endpoints()[0]["delivery_mode"] == "manual"
|
|
assert store.db.execute(
|
|
"SELECT value FROM metadata WHERE key='schema_version'"
|
|
).fetchone()[0] == "3"
|
|
assert "displayed_at" in {
|
|
row["name"] for row in store.db.execute("PRAGMA table_info(messages)")
|
|
}
|
|
|
|
|
|
def test_mark_displayed_releases_lease_without_acknowledging(tmp_path):
|
|
store = Store(tmp_path / "queue.sqlite3")
|
|
message_id = store.add("a", "b", "hello")
|
|
lease_id = store.claim(message_id, "endpoint")
|
|
assert lease_id is not None
|
|
|
|
assert store.mark_displayed(message_id, lease_id) is True
|
|
row = store.list()[0]
|
|
assert row["state"] == "pending"
|
|
assert row["displayed_at"] is not None
|
|
assert store.db.execute("SELECT COUNT(*) FROM leases").fetchone()[0] == 0
|
|
store.close()
|
|
|
|
|
|
def test_latest_counterparty_uses_latest_inbound_message_regardless_of_state(tmp_path):
|
|
store = Store(tmp_path / "queue.sqlite3")
|
|
store.add("audit-core", "audit-core", "self note")
|
|
older = store.add("flex-auth", "audit-core", "first")
|
|
store.acknowledge(older)
|
|
store.add("railiance-platform", "audit-core", "latest")
|
|
|
|
assert store.latest_counterparty("audit-core") == "railiance-platform"
|
|
assert store.latest_counterparty("unknown") is None
|
|
store.close()
|