fix: preserve schema 15 compatibility for v0.1.8

This commit is contained in:
2026-10-17 18:27:53 +09:00
parent a97548c36b
commit 1134f058cc
61 changed files with 2650 additions and 644 deletions
+48 -8
View File
@@ -1,4 +1,5 @@
from pathlib import Path
import sqlite3
from jarca_ledger_mcp.db import init_db
from jarca_ledger_mcp.application.monthly_settlement_service import (
@@ -7,17 +8,56 @@ from jarca_ledger_mcp.application.monthly_settlement_service import (
)
def test_monthly_history_is_explicitly_unsupported_in_schema15(tmp_path: Path):
def _seed_history(path: str) -> None:
init_db(path)
with sqlite3.connect(path) as conn:
conn.execute(
"""INSERT INTO asset_snapshot_runs
(id,basis_date,close_status,draft_version,approved_at,correction_of_run_id,
correction_reason,created_at,settlement_month,income_total,expense_total,
net_cashflow,net_worth)
VALUES ('run-1','2026-09-30','complete_exact',3,'2026-10-01','','',
'2026-10-01','2026-09',100,40,60,1000)"""
)
conn.execute(
"""INSERT INTO asset_snapshot_runs
(id,basis_date,close_status,draft_version,approved_at,correction_of_run_id,
correction_reason,created_at,settlement_month,income_total,expense_total,
net_cashflow,net_worth)
VALUES ('run-2','2026-09-30','conditional',4,'2026-10-02','run-1','fix',
'2026-10-02','2026-09',100,45,55,995)"""
)
def test_monthly_history_lists_close_and_correction_records(tmp_path: Path):
path = str(tmp_path / "history.sqlite3")
init_db(path)
result = list_monthly_settlement_history(db_path=path)
assert result["success"] is False
assert result["error_code"] == "unsupported"
_seed_history(path)
result = list_monthly_settlement_history("2026-09", db_path=path)
assert result["success"] is True
assert [row["run_id"] for row in result["history"]] == ["run-2", "run-1"]
assert result["history"][0]["correction_target"] == "run-1"
assert result["read_only"] is True
def test_monthly_history_record_read_is_explicitly_unsupported(tmp_path: Path):
def test_monthly_history_record_reads_exact_run(tmp_path: Path):
path = str(tmp_path / "history-read.sqlite3")
init_db(path)
_seed_history(path)
result = get_monthly_settlement_history_record("run-1", db_path=path)
assert result["success"] is True
assert result["history"]["run_id"] == "run-1"
assert result["history"]["net_cashflow"] == 60
assert result["history"]["net_worth"] == 1000
def test_monthly_history_record_reports_missing_run(tmp_path: Path):
path = str(tmp_path / "history-missing.sqlite3")
init_db(path)
result = get_monthly_settlement_history_record("missing", db_path=path)
assert result["success"] is False
assert result["error_code"] == "unsupported"
assert result["error_code"] == "not_found"