fix: preserve snapshot compatibility and loan fallback

This commit is contained in:
2026-10-06 09:47:58 +00:00
parent 6455c70413
commit 2a6076e86b
3 changed files with 73 additions and 12 deletions
+52
View File
@@ -453,6 +453,58 @@ def test_legacy_snapshot_rows_do_not_override_live_authority_or_claim_closed(tmp
assert report["legacy_snapshot_row_count"] == 1
def test_snapshot_public_api_preserves_legacy_db_path_position(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
preview = service.preview_asset_snapshot_close("2026-06-30", path)
closed = service.close_asset_snapshot("2026-06-30", "", "", "", path)
report = service.get_asset_snapshot_report("2026-06-30", path)
assert preview["success"] is True
assert closed["success"] is True
assert report["success"] is True
assert report["is_closed_snapshot"] is True
def test_legacy_snapshot_requires_explicit_correction_before_new_close(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
service.create_asset_snapshot(
"2026-06-30", "account", "legacy", "legacy", 999, "cash", db_path=path,
)
close = service.close_asset_snapshot("2026-06-30", db_path=path)
report = service.get_asset_snapshot_report("2026-06-30", db_path=path)
assert close["success"] is False
assert close["error_code"] == "legacy_snapshot_correction_required"
assert report["source"] == "legacy_asset_snapshots"
assert report["net_worth"] == 999
assert report["is_closed_snapshot"] is False
def test_loan_balance_fallback_with_representative_definition_is_liability(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
account = service.create_ledger_account("대출", type="loan", db_path=path)["account"]["id"]
recorded = service.register_account_valuation(
account, "2026-06-30", 100, valuation_kind="balance",
representative_liability_definition="principal_only",
verification_status="verified", db_path=path,
)
report = service.get_asset_snapshot_report("2026-06-30", db_path=path)
assert recorded["success"] is True
assert report["total_assets"] == 0
assert report["total_liabilities"] == 100
assert report["net_worth"] == -100
def test_loan_balance_fallback_rejects_unknown_representative_definition(tmp_path):
path = str(tmp_path / "ledger.sqlite3")
account = service.create_ledger_account("대출", type="loan", db_path=path)["account"]["id"]
recorded = service.register_account_valuation(
account, "2026-06-30", 100, valuation_kind="balance",
representative_liability_definition="outstanding_principal",
verification_status="verified", db_path=path,
)
assert recorded["success"] is False
assert recorded["error_code"] == "validation_error"
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