mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-11 03:13:24 +00:00
fix(web): catch unhandled promise rejections on config save buttons (#1346)
fix(web): catch unhandled promise rejections on config save buttons (#1346)
This commit is contained in:
1 parent
150c2b3c01
commit
6d24147a38
17 files changed
+87
-35
No files matched your search
@@ -106,6 +106,20 @@ func seedTenantAgent(t *testing.T, db *sql.DB) (tenantID, agentID uuid.UUID) {
|
||||
|
||||
// Cleanup after test — delete in FK order (children first, parents last).
|
||||
t.Cleanup(func() {
|
||||
// Knowledge stores — must run BEFORE agent_teams is deleted. vault_documents.team_id
|
||||
// is ON DELETE SET NULL with a BEFORE UPDATE trigger that force-sets scope='personal',
|
||||
// which violates vault_documents_scope_consistency for team-scoped docs whose agent_id
|
||||
// is NULL. Deleting the rows outright avoids the trigger entirely.
|
||||
// vault_links has no tenant_id column (it links vault_documents by from/to_doc_id) and
|
||||
// cascades automatically via vault_links_{from,to}_doc_id_fkey ON DELETE CASCADE, so no
|
||||
// explicit delete is needed here.
|
||||
db.Exec("DELETE FROM vault_documents WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_dedup_candidates WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_relations WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_entities WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_chunks WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_documents WHERE tenant_id = $1", tenantID)
|
||||
|
||||
// Team-related (deepest children first)
|
||||
db.Exec("DELETE FROM team_task_comments WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM team_task_events WHERE tenant_id = $1", tenantID)
|
||||
@@ -121,15 +135,6 @@ func seedTenantAgent(t *testing.T, db *sql.DB) (tenantID, agentID uuid.UUID) {
|
||||
db.Exec("DELETE FROM cron_run_logs WHERE job_id IN (SELECT id FROM cron_jobs WHERE tenant_id = $1)", tenantID)
|
||||
db.Exec("DELETE FROM cron_jobs WHERE tenant_id = $1", tenantID)
|
||||
|
||||
// Knowledge stores
|
||||
db.Exec("DELETE FROM vault_links WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM vault_documents WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_dedup_candidates WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_relations WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_entities WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_chunks WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_documents WHERE tenant_id = $1", tenantID)
|
||||
|
||||
// Sessions
|
||||
db.Exec("DELETE FROM sessions WHERE tenant_id = $1", tenantID)
|
||||
|
||||
@@ -156,7 +161,9 @@ func seedTenantAgent(t *testing.T, db *sql.DB) (tenantID, agentID uuid.UUID) {
|
||||
db.Exec("DELETE FROM agent_context_files WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM user_context_files WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM user_agent_overrides WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM agent_user_profiles WHERE agent_id = $1", agentID)
|
||||
// Note: agent_user_profiles does not exist in the current schema (the table is
|
||||
// user_agent_profiles, scoped by tenant_id + agent_id; there is nothing per-agent
|
||||
// to clean here beyond what tenant-scoped deletes below already cover).
|
||||
db.Exec("DELETE FROM agent_evolution_suggestions WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM agent_evolution_metrics WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM agents WHERE id = $1", agentID)
|
||||
|
||||
@@ -173,6 +173,21 @@ func assertNotEmpty(t *testing.T, result any, msg string) {
|
||||
|
||||
// cleanupTenant removes all tenant data in FK order.
|
||||
func cleanupTenant(db *sql.DB, tenantID, agentID uuid.UUID) {
|
||||
// Knowledge stores — must run BEFORE agent_teams is deleted. vault_documents.team_id
|
||||
// is ON DELETE SET NULL with a BEFORE UPDATE trigger that force-sets scope='personal',
|
||||
// which violates vault_documents_scope_consistency for team-scoped docs whose agent_id
|
||||
// is NULL. Deleting the rows outright avoids the trigger entirely.
|
||||
// vault_links has no tenant_id column (it links vault_documents by from/to_doc_id) and
|
||||
// cascades automatically via vault_links_{from,to}_doc_id_fkey ON DELETE CASCADE, so no
|
||||
// explicit delete is needed here.
|
||||
db.Exec("DELETE FROM episodic_summaries WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM vault_documents WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_dedup_candidates WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_relations WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_entities WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_chunks WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_documents WHERE tenant_id = $1", tenantID)
|
||||
|
||||
// Team-related
|
||||
db.Exec("DELETE FROM team_task_comments WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM team_task_events WHERE tenant_id = $1", tenantID)
|
||||
@@ -181,16 +196,6 @@ func cleanupTenant(db *sql.DB, tenantID, agentID uuid.UUID) {
|
||||
db.Exec("DELETE FROM agent_team_members WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM agent_teams WHERE tenant_id = $1", tenantID)
|
||||
|
||||
// Knowledge stores
|
||||
db.Exec("DELETE FROM episodic_summaries WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM vault_links WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM vault_documents WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_dedup_candidates WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_relations WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM kg_entities WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_chunks WHERE tenant_id = $1", tenantID)
|
||||
db.Exec("DELETE FROM memory_documents WHERE tenant_id = $1", tenantID)
|
||||
|
||||
// Sessions
|
||||
db.Exec("DELETE FROM sessions WHERE tenant_id = $1", tenantID)
|
||||
|
||||
@@ -218,7 +223,9 @@ func cleanupTenant(db *sql.DB, tenantID, agentID uuid.UUID) {
|
||||
db.Exec("DELETE FROM agent_context_files WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM user_context_files WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM user_agent_overrides WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM agent_user_profiles WHERE agent_id = $1", agentID)
|
||||
// Note: agent_user_profiles does not exist in the current schema (the table is
|
||||
// user_agent_profiles, agent_id REFERENCES agents(id) ON DELETE CASCADE — cleaned up
|
||||
// automatically when the agents row below is deleted).
|
||||
db.Exec("DELETE FROM agent_evolution_suggestions WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM agent_evolution_metrics WHERE agent_id = $1", agentID)
|
||||
db.Exec("DELETE FROM agents WHERE id = $1", agentID)
|
||||
|
||||
@@ -347,7 +347,8 @@ func TestTenantIsolation_VaultStore(t *testing.T) {
|
||||
t.Fatalf("create vault doc: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
db.Exec("DELETE FROM vault_links WHERE tenant_id = $1", tenantA)
|
||||
// vault_links has no tenant_id column; it cascades via
|
||||
// vault_links_{from,to}_doc_id_fkey ON DELETE CASCADE when vault_documents is deleted.
|
||||
db.Exec("DELETE FROM vault_documents WHERE id = $1", docID)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user