fix: preserve schema 15 compatibility for v0.1.8
This commit is contained in:
@@ -22,7 +22,7 @@ def _tables(path):
|
||||
|
||||
EXPECTED_TABLES = {
|
||||
# Sourced from schema.py plus migration-created settlement draft tables.
|
||||
"schema_meta",
|
||||
"schema_meta", "manual_assets", "asset_snapshots", "asset_snapshot_runs", "account_valuations",
|
||||
"accounts",
|
||||
"transactions",
|
||||
"budgets",
|
||||
@@ -40,11 +40,11 @@ EXPECTED_TABLES = {
|
||||
}
|
||||
|
||||
|
||||
def test_fresh_init_has_no_account_valuations_and_exact_schema_tables(tmp_path):
|
||||
def test_fresh_init_preserves_account_valuations_and_exact_schema_tables(tmp_path):
|
||||
path = tmp_path / "fresh.sqlite3"
|
||||
init_db(str(path))
|
||||
tables = _tables(path)
|
||||
assert "account_valuations" not in tables
|
||||
assert "account_valuations" in tables
|
||||
assert tables == EXPECTED_TABLES
|
||||
|
||||
|
||||
@@ -55,26 +55,25 @@ def test_init_is_idempotent(tmp_path):
|
||||
assert _tables(path) == EXPECTED_TABLES
|
||||
|
||||
|
||||
def test_legacy_nonempty_account_valuations_row_is_dropped_only(tmp_path):
|
||||
def test_legacy_nonempty_account_valuations_row_is_preserved(tmp_path):
|
||||
path = tmp_path / "legacy.sqlite3"
|
||||
init_db(str(path))
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("create table account_valuations (id text primary key, account_id text, amount integer)")
|
||||
conn.execute("insert into account_valuations values ('legacy-1','acct-1',123)")
|
||||
conn.execute("insert into account_valuations (id,account_id,amount,basis_date,recorded_at) values ('legacy-1','acct-1',123,'2026-09-30','t')")
|
||||
conn.execute("insert into accounts (id,name,type,active,created_at,updated_at) values ('acct-1','Keep me','bank',1,'t','t')")
|
||||
conn.commit()
|
||||
init_db(str(path))
|
||||
with sqlite3.connect(path) as conn:
|
||||
assert conn.execute("select count(*) from accounts where id='acct-1'").fetchone()[0] == 1
|
||||
assert conn.execute("select name from sqlite_master where type='table' and name='account_valuations'").fetchone() is None
|
||||
assert conn.execute("select amount from account_valuations where id='legacy-1'").fetchone() == (123,)
|
||||
|
||||
|
||||
def test_unsupported_valuation_operations_do_not_create_or_access_db(tmp_path):
|
||||
def test_invalid_valuation_operations_do_not_create_db(tmp_path):
|
||||
path = tmp_path / "must-not-exist.sqlite3"
|
||||
result = register_account_valuation("acct", "2026-09-30", 1, db_path=str(path))
|
||||
result = register_account_valuation("acct", "invalid-date", 1, db_path=str(path))
|
||||
listed = list_account_valuations("acct", db_path=str(path))
|
||||
assert result["success"] is False and result["error_code"] == "validation_error"
|
||||
assert listed["success"] is False and listed["error_code"] == "db_error"
|
||||
assert listed["success"] is False and listed["error_code"] == "db_not_initialized"
|
||||
assert not path.exists()
|
||||
|
||||
|
||||
@@ -102,10 +101,11 @@ def test_active_account_draft_returns_review_blocker_without_sql_error(tmp_path)
|
||||
assert not any("sql" in str(v).lower() for v in result.get("review", {}).values())
|
||||
|
||||
|
||||
def test_manual_asset_flow_is_unsupported_after_removal(tmp_path):
|
||||
def test_manual_asset_flow_remains_supported(tmp_path):
|
||||
path = tmp_path / "manual.sqlite3"
|
||||
init_db(str(path))
|
||||
created = create_manual_asset("Emergency fund", 100000, "2026-09-30", "cash", db_path=str(path))
|
||||
listed = list_manual_assets(db_path=str(path))
|
||||
assert created == {"success": False, "error_code": "unsupported", "error": "manual assets are no longer supported"}
|
||||
assert listed == {"success": False, "error_code": "unsupported", "error": "manual assets are no longer supported"}
|
||||
assert created["success"] and listed["success"]
|
||||
assert listed["manual_assets"][0]["id"] == created["manual_asset"]["id"]
|
||||
assert listed["manual_assets"][0]["valuation_amount"] == 100000
|
||||
|
||||
Reference in New Issue
Block a user