ci / vet-and-test (pull_request) Successful in 40s
Why: Backend PR #185 merged while the dependency migration was open. Its account transactions, audit behavior and migration tests must remain intact when this branch adopts the new main. Evidence: SELF 343 upstream Go files match after canonical import translation except the two bounded test-reliability corrections; complete Go test and vet passed in /tmp/dependency-backend-after-185-{parity,all-go,vet}-20261014-01a1345f.json. Impact: Disposable integration fixture first; the actual Backend branch can fast-forward to this tested merge without rewriting other task history. No production account logic is changed relative to the new main. Refs: Backend PR #196; upstream Backend PR #185; Dev PR #537; R15
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/store"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestAccountMaintenanceDefaultsToNonCreatingOpen(t *testing.T) {
|
|
t.Setenv("AGENT_SYSTEM_DSN", "")
|
|
for _, tc := range []struct {
|
|
name string
|
|
run func(string) error
|
|
}{
|
|
{"user", func(dir string) error {
|
|
_, _, err := CreateUserAccount("", dir, "ada", "Ada", "", false, false, false)
|
|
return err
|
|
}},
|
|
{"apikey", func(dir string) error {
|
|
_, err := CreateAPIKey("", dir, "ada", "test")
|
|
return err
|
|
}},
|
|
{"identity verify", func(dir string) error {
|
|
_, err := VerifySystemIdentity("", dir, "fixture", "sqlite")
|
|
return err
|
|
}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
dir := filepath.Join(t.TempDir(), "absent")
|
|
if err := tc.run(dir); err == nil {
|
|
t.Error("maintenance created a missing database")
|
|
}
|
|
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
|
t.Error("failed maintenance created a directory")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
func TestAccountMaintenanceCannotImplicitlyMigrate(t *testing.T) {
|
|
t.Setenv("AGENT_SYSTEM_DSN", "")
|
|
dir := t.TempDir()
|
|
st, err := store.OpenSQLite(filepath.Join(dir, "agent-system.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := st.EnsureSystemIdentity("test", "sqlite"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Roll back the newest additive migration in this private fixture only.
|
|
if err := st.MigrateDown(store.SchemaTarget() - 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st.Close()
|
|
if _, _, err := CreateUserAccount("", dir, "ada", "Ada", "", false, false, false); err == nil {
|
|
t.Error("account command implicitly migrated an older schema")
|
|
}
|
|
}
|