mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Adds `ai` to sqlc's `gen.go.initialisms` in `coderd/database/sqlc.yaml` so the generated DB code follows Go's initialism convention. Adds the matching `ai` -> `AI` case to the dbgen PascalCase helper (`scripts/dbgen/main.go`) so the corresponding `dbmem` / mock identifiers stay in sync. `make gen` regenerates the rest; hand-written call sites that consume DB-generated identifiers (`enterprise/audit/table.go`, `coderd/database/modelmethods.go`, `enterprise/coderd/aigatewaykeys.go`, `coderd/database/dbauthz/*`, etc.) are updated to match. Scope is deliberately limited to the database layer: - `coderd/rbac/*` (resource and scope generators) is untouched — `ResourceAi*` / `ScopeAi*` constants stay on main's casing. - `codersdk/*` (Go SDK) is untouched — `codersdk.ResourceAi*` / `codersdk.APIKeyScopeAi*` constants stay on main's casing, so external Go SDK consumers see no source-level break. - `Aibridge*` identifiers (one SQL token `aibridge`, not `ai_bridge`) are out of scope. On-the-wire values are unchanged: enum strings, RBAC resource type strings, API key scope strings, and JSON tags all stay the same. The HTTP/JSON surface is unaffected. Refs: [AIGOV-369](https://linear.app/codercom/issue/AIGOV-369/change-ai-references-in-coderddatabasemodelsgo-to-ai) 🤖 Generated with [Coder Agents](https://coder.com)
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package coderd_test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"database/sql"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"cdr.dev/slog/v3/sloggers/slogtest"
|
|
agplcoderd "github.com/coder/coder/v2/coderd"
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/database/dbgen"
|
|
"github.com/coder/coder/v2/coderd/database/dbtestutil"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/coder/v2/enterprise/dbcrypt"
|
|
"github.com/coder/coder/v2/testutil"
|
|
)
|
|
|
|
func TestBackfillBedrockProviderTypeEncryptedSettings(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
rawDB, _ := dbtestutil.NewDB(t)
|
|
ctx := testutil.Context(t, testutil.WaitShort)
|
|
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
|
|
|
|
key := make([]byte, 32)
|
|
_, _ = rand.Read(key)
|
|
ciphers, err := dbcrypt.NewCiphers(key)
|
|
require.NoError(t, err)
|
|
cryptDB, err := dbcrypt.New(ctx, rawDB, ciphers...)
|
|
require.NoError(t, err)
|
|
|
|
rawSettings, err := json.Marshal(codersdk.AIProviderSettings{
|
|
Bedrock: &codersdk.AIProviderBedrockSettings{Region: "us-east-1"},
|
|
})
|
|
require.NoError(t, err)
|
|
provider := dbgen.AIProvider(t, cryptDB, database.AIProvider{
|
|
Type: database.AIProviderTypeAnthropic,
|
|
Settings: sql.NullString{String: string(rawSettings), Valid: true},
|
|
})
|
|
|
|
agplcoderd.BackfillBedrockProviderType(ctx, cryptDB, logger)
|
|
|
|
// Verify via raw DB: type is not encrypted so it is directly readable.
|
|
row, err := rawDB.GetAIProviderByName(ctx, provider.Name)
|
|
require.NoError(t, err)
|
|
require.Equal(t, database.AIProviderTypeBedrock, row.Type, "encrypted legacy row must be promoted")
|
|
require.True(t, row.SettingsKeyID.Valid, "settings must remain encrypted after backfill")
|
|
}
|