fix: unblock bootstrap ownership on dynamic_tools (#2005)

* Fix bootstrap ownership migration for dynamic tools

* Add bootstrap ownership regression coverage
This commit is contained in:
Henry Park
2026-04-03 18:36:55 -07:00
committed by GitHub
parent 0588dd1bc3
commit 5451977683
3 changed files with 19 additions and 3 deletions

View File

@@ -357,13 +357,15 @@ impl Database for LibSqlBackend {
.map_err(|e| DatabaseError::Query(e.to_string()))?;
let result = async {
// Only tables with a real `user_id` column participate in the legacy
// 'default' -> owner rewrite. `dynamic_tools` is intentionally excluded:
// it is ownerless today and scoped by `scope`, not `user_id`.
let tables = [
"conversations",
"memory_documents",
"heartbeat_state",
"secrets",
"wasm_tools",
"dynamic_tools",
"routines",
"settings",
"agent_jobs",

View File

@@ -74,13 +74,15 @@ impl Database for PgBackend {
.transaction()
.await
.map_err(|e| DatabaseError::Query(e.to_string()))?;
// Only tables with a real `user_id` column participate in the legacy
// 'default' -> owner rewrite. `dynamic_tools` is intentionally excluded:
// it is ownerless today and scoped by `scope`, not `user_id`.
let tables = [
"conversations",
"memory_documents",
"heartbeat_state",
"secrets",
"wasm_tools",
"dynamic_tools",
"routines",
"settings",
"agent_jobs",

View File

@@ -138,7 +138,9 @@ mod tests {
create_user(&db, "henry", "admin").await;
// Run twice — should not error
db.migrate_default_owner("henry").await.unwrap();
db.migrate_default_owner("owner-bootstrap-test")
.await
.unwrap();
db.migrate_default_owner("henry").await.unwrap();
// Still exactly one henry row
@@ -155,6 +157,16 @@ mod tests {
db.migrate_default_owner("henry").await.unwrap();
}
#[tokio::test]
async fn test_migrate_default_owner_succeeds_on_fresh_migrated_db() {
let (db, _dir) = setup_db().await;
// Fresh installs include ownerless tables like `dynamic_tools`; the
// bootstrap rewrite should still succeed without assuming every table
// in the schema carries a `user_id` column.
db.migrate_default_owner("henry").await.unwrap();
}
// -----------------------------------------------------------------------
// TenantScope isolation tests
// -----------------------------------------------------------------------