Compare commits

...

1 Commits

Author SHA1 Message Date
core-be 872df8e619 test(handlers): add missing DB-error tests for Record and SessionSearch
CI / Platform (Go) (pull_request) Waiting to run
CI / Canvas (Next.js) (pull_request) Waiting to run
CI / Canvas Deploy Reminder (pull_request) Blocked by required conditions
CI / all-required (pull_request) Blocked by required conditions
E2E API Smoke Test / detect-changes (pull_request) Waiting to run
E2E API Smoke Test / E2E API Smoke Test (pull_request) Blocked by required conditions
Handlers Postgres Integration / detect-changes (pull_request) Waiting to run
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Blocked by required conditions
lint-required-no-paths / lint-required-no-paths (pull_request) Waiting to run
publish-runtime-autobump / pr-validate (pull_request) Waiting to run
publish-runtime-autobump / bump-and-tag (pull_request) Waiting to run
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 36s
Harness Replays / detect-changes (pull_request) Successful in 44s
MCP Stdio Transport Regression / MCP stdio with regular-file stdout (pull_request) Successful in 2m14s
Check migration collisions / Migration version collision check (pull_request) Successful in 2m20s
CI / Detect changes (pull_request) Successful in 2m13s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 38s
gate-check-v3 / gate-check (pull_request) Successful in 44s
qa-review / approved (pull_request) Successful in 48s
security-review / approved (pull_request) Successful in 37s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 1m47s
sop-tier-check / tier-check (pull_request) Successful in 36s
Harness Replays / Harness Replays (pull_request) Successful in 11s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 36s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 4m19s
CI / Python Lint & Test (pull_request) Successful in 8m4s
sop-checklist / all-items-acked (pull_request) [info tier:low] acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, l
audit-force-merge / audit (pull_request) Has been skipped
Cherry-pick of PR #1094 (test/delegate-record-db-errors) test functions
onto current staging. Original PR was stale (branched before 4bdb10b5).
Closes #1094.

New tests:
- TestSessionSearch_DBError: verifies SessionSearch returns 500 when
  the DB query returns an error
- TestDelegationRecord_DBInsertFails: verifies Record returns 500 when
  the activity_logs INSERT fails

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 07:50:43 +00:00
2 changed files with 52 additions and 0 deletions
@@ -63,6 +63,31 @@ func TestSessionSearchReturnsActivityAndMemory(t *testing.T) {
}
}
func TestSessionSearch_DBError(t *testing.T) {
mock := setupTestDB(t)
setupTestRedis(t)
broadcaster := newTestBroadcaster()
handler := NewActivityHandler(broadcaster)
mock.ExpectQuery("WITH session_items AS").
WillReturnError(context.DeadlineExceeded)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/workspaces/ws-123/session-search?q=test", bytes.NewBufferString(""))
c.Request.Header.Set("Content-Type", "application/json")
c.Params = gin.Params{{Key: "id", Value: "ws-123"}}
handler.SessionSearch(c)
if w.Code != http.StatusInternalServerError {
t.Errorf("expected 500 on DB error, got %d", w.Code)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unmet sqlmock expectations: %v", err)
}
}
// ---------- Activity List source filter ----------
func TestActivityList_SourceCanvas(t *testing.T) {
@@ -543,6 +543,33 @@ func TestDelegationRecord_RejectsInvalidUUID(t *testing.T) {
}
}
func TestDelegationRecord_DBInsertFails(t *testing.T) {
mock := setupTestDB(t)
setupTestRedis(t)
broadcaster := newTestBroadcaster()
wh := NewWorkspaceHandler(broadcaster, nil, "http://localhost:8080", t.TempDir())
h := NewDelegationHandler(wh, broadcaster)
mock.ExpectExec("INSERT INTO activity_logs").
WillReturnError(fmt.Errorf("connection refused"))
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "550e8400-e29b-41d4-a716-446655440000"}}
body := `{"target_id":"550e8400-e29b-41d4-a716-446655440001","task":"hello","delegation_id":"del-xyz"}`
c.Request = httptest.NewRequest("POST", "/delegations/record", bytes.NewBufferString(body))
c.Request.Header.Set("Content-Type", "application/json")
h.Record(c)
if w.Code != http.StatusInternalServerError {
t.Errorf("expected 500 on DB insert failure, got %d", w.Code)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unmet expectations: %v", err)
}
}
func TestDelegationUpdateStatus_CompletedInsertsResultRow(t *testing.T) {
mock := setupTestDB(t)
setupTestRedis(t)