ci / vet-and-test (pull_request) Successful in 42s
Why: main #171 claimed migration v26; rebase conflict required
bumping the U1 I3 table and completing copyOrder for both new tables.
Evidence: go test ./internal/store/ ./cmd/storage-migrate/ -run
'SystemIdentity|CopyOrder'
Impact: migrate v27; copyOrder += login_keys + agent_system_identity.
Refs: Backend PR #170; conflict with main 1d9e8f4
Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestSystemIdentityEnsureVerifySQLite(t *testing.T) {
|
|
st, err := OpenSQLite(filepath.Join(t.TempDir(), "id.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer st.Close()
|
|
|
|
if err := st.VerifySystemIdentity("svc-a-aaaaaa", "sqlite"); !errors.Is(err, ErrSystemIdentityMissing) {
|
|
t.Fatalf("empty verify: want missing, got %v", err)
|
|
}
|
|
if err := st.EnsureSystemIdentity("svc-a-aaaaaa", "sqlite"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := st.EnsureSystemIdentity("svc-a-aaaaaa", "sqlite"); err != nil {
|
|
t.Fatalf("idempotent ensure: %v", err)
|
|
}
|
|
if err := st.VerifySystemIdentity("svc-a-aaaaaa", "sqlite"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := st.EnsureSystemIdentity("svc-b-bbbbbb", "sqlite"); !errors.Is(err, ErrSystemIdentityMismatch) {
|
|
t.Fatalf("wrong id ensure: want mismatch, got %v", err)
|
|
}
|
|
if err := st.VerifySystemIdentity("svc-a-aaaaaa", "pg:other"); !errors.Is(err, ErrSystemIdentityMismatch) {
|
|
t.Fatalf("wrong dbref verify: want mismatch, got %v", err)
|
|
}
|
|
row, err := st.GetSystemIdentity()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if row.InstanceID != "svc-a-aaaaaa" || row.DBRef != "sqlite" {
|
|
t.Fatalf("row=%+v", row)
|
|
}
|
|
if row.SchemaVersion != latestMigrationVersion() {
|
|
t.Fatalf("schema_version=%d want %d", row.SchemaVersion, latestMigrationVersion())
|
|
}
|
|
}
|
|
|
|
func TestSystemIdentityMigrationCreatesTable(t *testing.T) {
|
|
st, err := OpenSQLite(filepath.Join(t.TempDir(), "mig.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer st.Close()
|
|
versions, err := st.MigrationStatus()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, v := range versions {
|
|
if v == 27 {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("migration v27 not applied: %v", versions)
|
|
}
|
|
var name string
|
|
if err := st.DB().QueryRow(`SELECT name FROM sqlite_master WHERE type='table' AND name='agent_system_identity'`).Scan(&name); err != nil || name != "agent_system_identity" {
|
|
t.Fatalf("table missing: name=%q err=%v", name, err)
|
|
}
|
|
}
|