pythonf8555a15 | 1 | """CASA journal contract on native SQL backend.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import tempfile |
| 6 | from pathlib import Path |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from pywitdb._native.sql import sql_native_available |
| 11 | from pywitdb.sql import connect |
| 12 | from tests.contract.test_casa_journal_sql import ( |
| 13 | JOURNAL_CREATE_SQL, |
| 14 | _insert_skill_trace, |
| 15 | _prune, |
| 16 | ) |
| 17 | |
| 18 | pytestmark = pytest.mark.skipif( |
| 19 | not sql_native_available(), reason="libwitdb SQL exports not built" |
| 20 | ) |
| 21 | |
| 22 | |
| 23 | def test_native_journal_prune_one_liner() -> None: |
| 24 | with tempfile.TemporaryDirectory() as tmp: |
| 25 | path = str(Path(tmp) / "journal_native.witdb") |
| 26 | with connect(path, backend="native", create=True) as conn: |
| 27 | conn.executescript(JOURNAL_CREATE_SQL) |
| 28 | conn.commit() |
| 29 | for i in range(5): |
| 30 | _insert_skill_trace(conn, {"skill": f"s{i}", "situation": {"goal_id": "g"}}, prune_max=0) |
| 31 | conn.commit() |
| 32 | _prune(conn, "skill_trace", max_rows=3) |
| 33 | conn.commit() |
| 34 | total = conn.execute("SELECT COUNT(*) AS c FROM skill_trace").fetchone() |
| 35 | assert total is not None |
| 36 | assert int(total["c"]) == 3 |
| 37 | |
View only · write via MCP/CIDE