feat(ai): add tenant-safe hierarchical expense learning
This commit is contained in:
@@ -7,6 +7,7 @@ from sqlalchemy import Column, Integer, MetaData, Table, create_engine, text
|
||||
from sqlalchemy.engine import Engine
|
||||
|
||||
from app.db.migration_preflight import (
|
||||
LEGACY_ADOPTABLE_HISTORICAL_CASE_TABLES,
|
||||
MIGRATION_OWNED_TABLES_BY_REVISION,
|
||||
MigrationPreflightError,
|
||||
validate_migration_state,
|
||||
@@ -46,9 +47,29 @@ def test_unversioned_database_without_migration_owned_tables_is_safe(engine: Eng
|
||||
assert state.owned_tables == frozenset()
|
||||
|
||||
|
||||
def test_unversioned_database_can_adopt_legacy_historical_case_tables(engine: Engine) -> None:
|
||||
_create_tables(engine, LEGACY_ADOPTABLE_HISTORICAL_CASE_TABLES)
|
||||
|
||||
state = validate_migration_state(engine)
|
||||
|
||||
assert state.revision is None
|
||||
assert state.owned_tables == LEGACY_ADOPTABLE_HISTORICAL_CASE_TABLES
|
||||
|
||||
|
||||
def test_revision_0007_accepts_partial_legacy_historical_case_tables(engine: Engine) -> None:
|
||||
expected = MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0007"]
|
||||
adopted = frozenset({"risk_observations", "risk_observation_feedback"})
|
||||
_create_tables(engine, expected | adopted)
|
||||
_create_version_table(engine, "20260716_0007")
|
||||
|
||||
state = validate_migration_state(engine)
|
||||
|
||||
assert state.owned_tables == expected | adopted
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"owned_table",
|
||||
sorted(MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0006"]),
|
||||
sorted(MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0007"]),
|
||||
)
|
||||
def test_unversioned_database_with_any_migration_owned_table_is_rejected(
|
||||
engine: Engine,
|
||||
@@ -102,8 +123,19 @@ def test_known_revision_requires_and_accepts_its_exact_owned_table_set(
|
||||
),
|
||||
(
|
||||
"20260716_0006",
|
||||
MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0006"]
|
||||
- {"attachment_association_jobs"},
|
||||
MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0006"] - {"attachment_association_jobs"},
|
||||
),
|
||||
(
|
||||
"20260716_0007",
|
||||
MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0007"] - {"memory_entries"},
|
||||
),
|
||||
(
|
||||
"20260716_0008",
|
||||
MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0008"] - {"few_shot_samples"},
|
||||
),
|
||||
(
|
||||
"20260716_0009",
|
||||
MIGRATION_OWNED_TABLES_BY_REVISION["20260716_0009"] - {"memory_entries"},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user