启动种子不再依赖固定用户 id=1,并把白名单工作流的 retired 状态恢复为 active。 Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
2.1 KiB
Go
90 lines
2.1 KiB
Go
package workflowdef
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"chat-agent-system/internal/db"
|
|
)
|
|
|
|
func openSeedPool(t *testing.T) *pgxpool.Pool {
|
|
t.Helper()
|
|
dsn := db.SkipIfNoTestDatabaseURL(t)
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
pool, err := pgxpool.New(ctx, dsn)
|
|
if err != nil {
|
|
t.Skip(err)
|
|
}
|
|
if err := pool.Ping(ctx); err != nil {
|
|
pool.Close()
|
|
t.Skip(err)
|
|
}
|
|
if !TablesReady(ctx, pool) {
|
|
pool.Close()
|
|
t.Skip("workflowdef tables not migrated")
|
|
}
|
|
return pool
|
|
}
|
|
|
|
func TestResolveSeedActor_FallsBackWhenUserMissing(t *testing.T) {
|
|
pool := openSeedPool(t)
|
|
defer pool.Close()
|
|
ctx := context.Background()
|
|
|
|
var minID int64
|
|
if err := pool.QueryRow(ctx, `SELECT id FROM users ORDER BY id ASC LIMIT 1`).Scan(&minID); err != nil {
|
|
t.Skip("no users to fall back to")
|
|
}
|
|
|
|
got, err := resolveSeedActor(ctx, pool, minID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != minID {
|
|
t.Fatalf("existing user: got %d want %d", got, minID)
|
|
}
|
|
|
|
const missing int64 = 9_000_000_001
|
|
got, err = resolveSeedActor(ctx, pool, missing)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != minID {
|
|
t.Fatalf("missing user fallback: got %d want %d", got, minID)
|
|
}
|
|
}
|
|
|
|
func TestBootstrapSeeds_RestoresRetiredOfficialStatus(t *testing.T) {
|
|
pool := openSeedPool(t)
|
|
defer pool.Close()
|
|
ctx := context.Background()
|
|
|
|
var exists bool
|
|
if err := pool.QueryRow(ctx, `SELECT EXISTS (SELECT 1 FROM workflow_definitions WHERE def_key = 'rdev')`).Scan(&exists); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !exists {
|
|
t.Skip("rdev definition not present")
|
|
}
|
|
|
|
if _, err := pool.Exec(ctx, `UPDATE workflow_definitions SET status = 'retired' WHERE def_key = 'rdev'`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := BootstrapSeeds(ctx, pool, nil, t.TempDir(), 9_000_000_001); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var status string
|
|
if err := pool.QueryRow(ctx, `SELECT status FROM workflow_definitions WHERE def_key = 'rdev'`).Scan(&status); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if status != "active" {
|
|
t.Fatalf("rdev status = %q, want active", status)
|
|
}
|
|
}
|