store: remove dead-code branch from ClaimLegacyOwner
Task 3 correction: migration 0003 unconditionally seeds a profile row on every fresh install, and Task 1's migration 0023 preserves this seeded row with user_id = NULL. Therefore, a fresh install always has at least one profile row with user_id IS NULL when users table is empty -- the "no-op on genuinely fresh install" scenario was unreachable dead code. Confirmed with the codebase owner that no scenario requires defending against a missing profile row. Collapse the two-branch error handling into a single `if err != nil` check (matching the pattern used elsewhere in the function), remove the now-unused database/sql import, update the function's doc comment to remove the false claim about fresh installs, and delete the now-unreachable TestClaimLegacyOwner_NoOpOnGenuinelyFreshInstall test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,8 +12,7 @@ import (
|
|||||||
// new user identified by oidcSub. Safe to call on every startup: once the
|
// new user identified by oidcSub. Safe to call on every startup: once the
|
||||||
// users table is non-empty, it's a no-op, so leaving
|
// users table is non-empty, it's a no-op, so leaving
|
||||||
// GENIUSRUN_LEGACY_OWNER_OIDC_SUB set after the first successful run causes
|
// GENIUSRUN_LEGACY_OWNER_OIDC_SUB set after the first successful run causes
|
||||||
// no harm. Also a no-op on a genuinely fresh install (no legacy profile row
|
// no harm.
|
||||||
// to claim at all).
|
|
||||||
func (db *DB) ClaimLegacyOwner(ctx context.Context, oidcSub string) error {
|
func (db *DB) ClaimLegacyOwner(ctx context.Context, oidcSub string) error {
|
||||||
var userCount int
|
var userCount int
|
||||||
if err := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM users`).Scan(&userCount); err != nil {
|
if err := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM users`).Scan(&userCount); err != nil {
|
||||||
@@ -26,9 +24,6 @@ func (db *DB) ClaimLegacyOwner(ctx context.Context, oidcSub string) error {
|
|||||||
|
|
||||||
var displayName string
|
var displayName string
|
||||||
err := db.QueryRowContext(ctx, `SELECT name FROM profile WHERE user_id IS NULL LIMIT 1`).Scan(&displayName)
|
err := db.QueryRowContext(ctx, `SELECT name FROM profile WHERE user_id IS NULL LIMIT 1`).Scan(&displayName)
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return nil // fresh install, no pre-existing singleton profile to claim
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("find legacy profile: %w", err)
|
return fmt.Errorf("find legacy profile: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,15 +95,3 @@ func TestClaimLegacyOwner_NoOpOnceAUserAlreadyExists(t *testing.T) {
|
|||||||
t.Fatalf("expected exactly the 1 pre-existing user to remain, got %+v", users)
|
t.Fatalf("expected exactly the 1 pre-existing user to remain, got %+v", users)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClaimLegacyOwner_NoOpOnGenuinelyFreshInstall(t *testing.T) {
|
|
||||||
db := openTestDB(t)
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
if err := db.ClaimLegacyOwner(ctx, "kriss-sub"); err != nil {
|
|
||||||
t.Fatalf("ClaimLegacyOwner on fresh install: %v", err)
|
|
||||||
}
|
|
||||||
if _, found, err := db.GetUserBySub(ctx, "kriss-sub"); err != nil || found {
|
|
||||||
t.Fatalf("expected no user created on a fresh install with no legacy profile, found=%v err=%v", found, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user