test: clean remaining residual rows across db, agent, and server test suites

This commit is contained in:
BaaRai
2026-11-20 22:54:57 +01:00
parent 79119ae9bd
commit 752d0cfab4
12 changed files with 34 additions and 12 deletions
+3
View File
@@ -73,6 +73,9 @@ func TestCoreTaskLifecyclePG(t *testing.T) {
if id == "" || expID == 0 {
t.Fatalf("bad task payload: %v", out)
}
defer func() {
_, _ = m.pg.Exec(`DELETE FROM assets WHERE type = 'ip' AND ip = '127.0.0.1'`)
}()
// the exploration owns goal node(s) — goal seeding is async, poll briefly
var goals []*db.Node
+1
View File
@@ -282,6 +282,7 @@ func TestFindingTrafficArchiveV3RoundTripAndRetry(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer s.m.pg.DeleteFinding(shared.FindingID)
if _, err = s.m.traffic.DeleteHost("evidence.local"); err != nil {
t.Fatal(err)
}
+5 -1
View File
@@ -286,15 +286,19 @@ func TestDeepenAdmissionFailureDiscardsFollowUpIntent(t *testing.T) {
t.Fatal(err)
}
taskID, _ := strconv.ParseInt(task.ID, 10, 64)
var findingID int64
defer func() {
_, _ = m.pg.Exec(`UPDATE tasks SET deleted_at=NULL WHERE id=$1`, taskID)
if findingID > 0 {
_, _ = m.pg.DeleteFinding(findingID)
}
_, _ = m.DeleteTask(task.ID, DeleteTaskOptions{})
}()
findingNodeID, err := task.Store.AddNode(db.KindFinding, map[string]any{"summary": "source"}, 5, "confirmed", "worker", nil)
if err != nil {
t.Fatal(err)
}
findingID, err := m.pg.AddFinding(taskID, findingNodeID, "test", "source", db.SeverityHigh, "source", "", "worker", nil)
findingID, err = m.pg.AddFinding(taskID, findingNodeID, "test", "source", db.SeverityHigh, "source", "", "worker", nil)
if err != nil {
t.Fatal(err)
}
+1
View File
@@ -74,6 +74,7 @@ func TestRecorderPersistsRawWireBodies(t *testing.T) {
if _, err := pg.Exec(`DELETE FROM llm_records WHERE session_id = $1`, session); err != nil {
t.Logf("cleanup: %v", err)
}
_, _ = pg.Exec(`DELETE FROM llm_usage WHERE task_id = '999999' AND profile_name = 'raw-test-profile'`)
}()
ctx := transcript.WithSessionID(context.Background(), session)
+1
View File
@@ -83,6 +83,7 @@ func (g *gateServer) cleanupTask(t *testing.T, id string) {
_ = g.m.pg.DeleteTask(n)
_, _ = g.m.pg.Exec(`DELETE FROM target_pins WHERE task_id=$1`, n)
_, _ = g.m.pg.Exec(`DELETE FROM intercept_pending WHERE task_id=$1`, id)
_, _ = g.m.pg.Exec(`DELETE FROM assets WHERE type = 'ip' AND ip = '127.0.0.1'`)
})
}
+8 -2
View File
@@ -49,8 +49,14 @@ func TestTaskCredentialsFlow(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = s.m.pg.DeleteTask(id) })
t.Cleanup(func() { s.m.PG().Exec(`DELETE FROM tasks WHERE id=$1`, id) })
t.Cleanup(func() {
_ = s.m.pg.DeleteTask(id)
// The first POST with an invalid credential entry returns 400 after
// creating a task/exploration row; remove any remaining fixture rows.
_, _ = s.m.PG().Exec(`DELETE FROM tasks WHERE description = 'credential flow test'`)
_, _ = s.m.PG().Exec(`DELETE FROM explorations WHERE description = 'credential flow test'`)
_, _ = s.m.PG().Exec(`DELETE FROM assets WHERE type = 'ip' AND ip = '127.0.0.1'`)
})
// List: both rows, user source, order stable.
resp = request("GET", fmt.Sprintf("/api/tasks/%s/credentials", created.ID), "")
+1 -1
View File
@@ -21,7 +21,7 @@ func TestReviveClearsBudgetEndReason(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { pg.Exec(`DELETE FROM tasks WHERE id=$1`, id) })
t.Cleanup(func() { _ = pg.DeleteTask(id) })
endReason := func() string {
t.Helper()
var r string
+8 -2
View File
@@ -75,7 +75,10 @@ func TestRotationConcurrentProvidersAndPrecedence(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer m.DeleteTask(task.ID, DeleteTaskOptions{})
defer func() {
_, _ = m.pg.Exec(`DELETE FROM llm_usage WHERE task_id = $1`, task.ID)
_, _ = m.DeleteTask(task.ID, DeleteTaskOptions{})
}()
s := &Server{m: m, provByProfile: map[int64]*provEntry{}}
runtime := &taskLLMRuntime{s: s, taskID: task.ID, agentKey: "worker"}
done := make(chan error, 3)
@@ -343,7 +346,10 @@ func TestRunIntentRotatesPinnedProfileWithCachedExecCtx(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer m.DeleteTask(task.ID, DeleteTaskOptions{})
defer func() {
_, _ = m.pg.Exec(`DELETE FROM llm_usage WHERE task_id = $1`, task.ID)
_, _ = m.DeleteTask(task.ID, DeleteTaskOptions{})
}()
e := NewEngine(m)
// Warm the per-task cached execCtx before any worker intent runs.
+1 -1
View File
@@ -24,7 +24,7 @@ func TestPauseShiftsTaskDeadlineOnResume(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { pg.Exec(`DELETE FROM tasks WHERE id=$1`, id) })
t.Cleanup(func() { _ = pg.DeleteTask(id) })
// A running task with a stamped deadline (first_run_at + 1h budget).
if _, err := m.StampTaskFirstRun(task.ID); err != nil {