generated from coulomb/repo-seed
vocabulary ref and schema guard test
This commit is contained in:
@@ -37,6 +37,69 @@ def test_initialize_is_idempotent_and_applies_expected_columns(tmp_path):
|
||||
assert "content_chunks" in tables
|
||||
|
||||
|
||||
def test_approved_registry_schema_allows_future_nullable_vocabulary_ref(tmp_path):
|
||||
database_path = tmp_path / "registry.sqlite3"
|
||||
store = RegistryStore(database_path)
|
||||
store.initialize()
|
||||
|
||||
approved_tables = {
|
||||
"approved_abilities",
|
||||
"approved_capabilities",
|
||||
"approved_features",
|
||||
}
|
||||
|
||||
with sqlite3.connect(database_path) as connection:
|
||||
table_sql = {
|
||||
table: connection.execute(
|
||||
"SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?",
|
||||
(table,),
|
||||
).fetchone()[0]
|
||||
for table in approved_tables
|
||||
}
|
||||
indexes = {
|
||||
table: [
|
||||
{
|
||||
"name": row[1],
|
||||
"unique": bool(row[2]),
|
||||
"columns": [
|
||||
column[2]
|
||||
for column in connection.execute(
|
||||
f"PRAGMA index_info({row[1]!r})"
|
||||
)
|
||||
],
|
||||
}
|
||||
for row in connection.execute(f"PRAGMA index_list({table})")
|
||||
]
|
||||
for table in approved_tables
|
||||
}
|
||||
foreign_keys = {
|
||||
table: [
|
||||
{
|
||||
"from": row[3],
|
||||
"to_table": row[2],
|
||||
"to_column": row[4],
|
||||
}
|
||||
for row in connection.execute(f"PRAGMA foreign_key_list({table})")
|
||||
]
|
||||
for table in approved_tables | {"review_decisions"}
|
||||
}
|
||||
review_columns = {
|
||||
row[1] for row in connection.execute("PRAGMA table_info(review_decisions)")
|
||||
}
|
||||
|
||||
assert all("CHECK" not in sql.upper() for sql in table_sql.values())
|
||||
for table_indexes in indexes.values():
|
||||
assert all(
|
||||
not (index["unique"] and index["columns"] == ["name"])
|
||||
for index in table_indexes
|
||||
)
|
||||
for table_foreign_keys in foreign_keys.values():
|
||||
assert all(key["to_column"] != "name" for key in table_foreign_keys)
|
||||
assert all(key["from"] != "name" for key in table_foreign_keys)
|
||||
assert {"repository_id", "analysis_run_id", "action", "notes"} <= review_columns
|
||||
assert not {"ability_name", "capability_name", "feature_name"} & review_columns
|
||||
|
||||
|
||||
def test_delete_repository_cascades_registry_and_review_rows(tmp_path):
|
||||
service = make_service(tmp_path)
|
||||
repository = service.register_repository(
|
||||
|
||||
Reference in New Issue
Block a user