fix: preserve correction and legacy authority semantics

This commit is contained in:
2026-10-06 09:05:54 +00:00
parent 921f130fb0
commit a4cad342a6
4 changed files with 60 additions and 6 deletions
+3 -1
View File
@@ -61,7 +61,9 @@ def test_snapshot_rows_are_append_only_and_timeseries_uses_same_formula(tmp_path
may = service.get_asset_snapshot_report("2026-05-31", db_path=db_path)
assert may["success"] is True
assert may["source"] == "asset_snapshots"
assert may["source"] == "legacy_asset_snapshots"
assert may["is_closed_snapshot"] is False
assert may["close_status"] == "legacy_read_only"
assert may["snapshot_count"] == 3
assert may["net_worth"] == 121_000_000
+36
View File
@@ -180,6 +180,26 @@ def test_candidate_idempotency_rejects_changed_payload(tmp_path):
assert conflict["error_code"] == "idempotency_conflict"
def test_correction_idempotency_compares_effective_preserved_payload(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
account = service.create_ledger_account("계좌", db_path=path)["account"]["id"]
original = service.register_account_valuation(
account, "2026-06-30", 100, memo="original",
verification_status="verified", idempotency_key="original", db_path=path,
)["valuation"]
first = service.correct_account_valuation(
original["id"], 200, "정정", memo="override",
idempotency_key="correction", db_path=path,
)
retry_with_omitted_memo = service.correct_account_valuation(
original["id"], 200, "정정",
idempotency_key="correction", db_path=path,
)
assert first["success"] is True
assert retry_with_omitted_memo["success"] is False
assert retry_with_omitted_memo["error_code"] == "idempotency_conflict"
def test_valuation_currency_and_loan_kind_are_rejected(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
bank = service.create_ledger_account("은행", currency="KRW", db_path=path)["account"]["id"]
@@ -331,6 +351,22 @@ def test_snapshot_rejects_bogus_selection_policy_and_manual_usd_is_excluded(tmp_
assert any(item.get("reason") == "non_krw_without_fx" for item in report["excluded_items"])
def test_legacy_snapshot_rows_do_not_override_live_authority_or_claim_closed(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
service.create_asset_snapshot(
"2026-06-30", "account", "legacy", "legacy", 999, "cash", db_path=path,
)
account = service.create_ledger_account("현재 계좌", db_path=path)["account"]["id"]
service.register_account_valuation(
account, "2026-06-30", 100, verification_status="verified", db_path=path,
)
report = service.get_asset_snapshot_report("2026-06-30", db_path=path)
assert report["source"] == "live_authority"
assert report["is_closed_snapshot"] is False
assert report["total_assets"] == 100
assert report["legacy_snapshot_row_count"] == 1
def test_account_write_rolls_back_when_conn_level_candidate_write_fails(tmp_path, monkeypatch):
path = str(tmp_path / "ledger.sqlite3")
import jarca_ledger_mcp.application.accounts_write_services as writes