feat(seed): add --ci flag for bare-minimum E2E seed (v1.0.8 C4)
Prep for the upcoming E2E Playwright CI workflow. The full seed (1200 users, 5000 tracks, 100k play events, 10k messages, etc.) takes ~60s and produces a lot of fixture data the suite never reads. A CI run just needs the 5 test accounts the auth fixture logs in as (admin/artist/user/mod/new) plus a small content set so player / playlist tests have something to render. New flag: go run ./cmd/tools/seed --ci CIConfig (cmd/tools/seed/config.go): - TotalUsers = 5 (== len(testAccounts), so SeedUsers' "remaining" branch is a no-op — only the 5 hardcoded accounts get inserted). - Tracks = 10, Playlists = 3 (covers player + playlist suites). - Albums = 0, all social/chat/live/marketplace/analytics/etc. = 0. main.go gates the heavy seeders (Social / Chat / Live / Marketplace / Analytics / Content / Moderation / Notifications / Misc) behind `if !cfg.CIMode`, prints a one-line "skipping ..." banner so the run log makes the choice obvious. The Users / Tracks / Playlists path is unchanged — same code, same validation pass at the end. Time: ~5s in CI mode (bcrypt cost 12 × 5 + a handful of bulk inserts) vs the ~60s minimal mode and ~5min full mode, measured locally against a tmpfs Postgres. Validate() and the SUMMARY printout work unchanged — empty tables just show "0 rows", and the orphan-FK checks remain useful (and pass trivially when the heavy seeders are skipped). modeName() returns "CI" so the boot banner reflects the choice. go build ./... clean. Help output: -ci Bare-minimum seed for E2E CI (...) -minimal Use reduced volumes (50 users, 200 tracks) for fast dev Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
46d21c5cdd
commit
cee850a5aa
2 changed files with 87 additions and 37 deletions
|
|
@ -4,6 +4,13 @@ import "flag"
|
||||||
|
|
||||||
// Config holds all seed volume parameters.
|
// Config holds all seed volume parameters.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// CIMode: when true, main.go only runs SeedUsers / SeedTracks /
|
||||||
|
// SeedPlaylists and skips Chat/Live/Marketplace/Analytics/Content/
|
||||||
|
// Moderation/Notifications/Misc. Used by E2E CI to avoid the ~60s
|
||||||
|
// full seed when all the suite needs is the 5 test accounts and a
|
||||||
|
// handful of tracks/playlists.
|
||||||
|
CIMode bool
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
TotalUsers int
|
TotalUsers int
|
||||||
NormalUsers int
|
NormalUsers int
|
||||||
|
|
@ -163,10 +170,43 @@ func MinimalConfig() Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CIConfig returns the bare-minimum configuration for E2E CI:
|
||||||
|
// just the 5 hardcoded test accounts (admin/artist/user/mod/new) plus
|
||||||
|
// a small fixture set of tracks and playlists. main.go skips the
|
||||||
|
// non-essential seeders when CIMode is true.
|
||||||
|
func CIConfig() Config {
|
||||||
|
return Config{
|
||||||
|
CIMode: true,
|
||||||
|
|
||||||
|
// 5 test accounts only — TotalUsers == len(testAccounts) so
|
||||||
|
// SeedUsers' "remaining" branch is a no-op.
|
||||||
|
TotalUsers: 5,
|
||||||
|
NormalUsers: 2,
|
||||||
|
Artists: 1,
|
||||||
|
Labels: 0,
|
||||||
|
Moderators: 1,
|
||||||
|
Admins: 1,
|
||||||
|
|
||||||
|
// Small fixture set so player / playlist tests have content.
|
||||||
|
Tracks: 10,
|
||||||
|
Albums: 0,
|
||||||
|
Playlists: 3,
|
||||||
|
PlaylistMinTracks: 1,
|
||||||
|
PlaylistMaxTracks: 3,
|
||||||
|
|
||||||
|
// Everything else stays at zero — corresponding seeders are
|
||||||
|
// either skipped via CIMode or run as no-ops on zero counts.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ParseFlags parses CLI flags and returns the appropriate config.
|
// ParseFlags parses CLI flags and returns the appropriate config.
|
||||||
func ParseFlags() Config {
|
func ParseFlags() Config {
|
||||||
minimal := flag.Bool("minimal", false, "Use reduced volumes (50 users, 200 tracks) for fast dev")
|
minimal := flag.Bool("minimal", false, "Use reduced volumes (50 users, 200 tracks) for fast dev")
|
||||||
|
ci := flag.Bool("ci", false, "Bare-minimum seed for E2E CI (5 test accounts + 10 tracks + 3 playlists, skips chat/live/marketplace/analytics)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if *ci {
|
||||||
|
return CIConfig()
|
||||||
|
}
|
||||||
if *minimal {
|
if *minimal {
|
||||||
return MinimalConfig()
|
return MinimalConfig()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,51 +72,58 @@ func main() {
|
||||||
log.Fatalf("seed playlists: %v", err)
|
log.Fatalf("seed playlists: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Social (depends on users, tracks)
|
// CI mode stops here — the E2E suite only needs the test accounts
|
||||||
if err := SeedSocial(db, cfg, users, tracks); err != nil {
|
// + a fixture set of tracks/playlists. Skipping the remaining
|
||||||
log.Fatalf("seed social: %v", err)
|
// seeders shaves ~50s off the typical CI seed time.
|
||||||
}
|
if cfg.CIMode {
|
||||||
|
fmt.Println("\n═══ CI MODE: skipping social/chat/live/marketplace/analytics/content/moderation/notifications/misc ═══")
|
||||||
|
} else {
|
||||||
|
// Level 2: Social (depends on users, tracks)
|
||||||
|
if err := SeedSocial(db, cfg, users, tracks); err != nil {
|
||||||
|
log.Fatalf("seed social: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Level 2: Chat (depends on users)
|
// Level 2: Chat (depends on users)
|
||||||
_, err = SeedChat(db, cfg, users)
|
_, err = SeedChat(db, cfg, users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("seed chat: %v", err)
|
log.Fatalf("seed chat: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Live streams (depends on users)
|
// Level 2: Live streams (depends on users)
|
||||||
if err := SeedLive(db, cfg, users, tracks); err != nil {
|
if err := SeedLive(db, cfg, users, tracks); err != nil {
|
||||||
log.Fatalf("seed live: %v", err)
|
log.Fatalf("seed live: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Marketplace (depends on users, tracks)
|
// Level 2: Marketplace (depends on users, tracks)
|
||||||
_, err = SeedMarketplace(db, cfg, users, tracks)
|
_, err = SeedMarketplace(db, cfg, users, tracks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("seed marketplace: %v", err)
|
log.Fatalf("seed marketplace: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 3: Analytics (depends on users, tracks — heaviest step)
|
// Level 3: Analytics (depends on users, tracks — heaviest step)
|
||||||
if err := SeedAnalytics(db, cfg, users, tracks); err != nil {
|
if err := SeedAnalytics(db, cfg, users, tracks); err != nil {
|
||||||
log.Fatalf("seed analytics: %v", err)
|
log.Fatalf("seed analytics: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Content (depends on users, tracks)
|
// Level 2: Content (depends on users, tracks)
|
||||||
if err := SeedContent(db, cfg, users, tracks); err != nil {
|
if err := SeedContent(db, cfg, users, tracks); err != nil {
|
||||||
log.Fatalf("seed content: %v", err)
|
log.Fatalf("seed content: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Moderation (depends on users, tracks)
|
// Level 2: Moderation (depends on users, tracks)
|
||||||
if err := SeedModeration(db, cfg, users, tracks); err != nil {
|
if err := SeedModeration(db, cfg, users, tracks); err != nil {
|
||||||
log.Fatalf("seed moderation: %v", err)
|
log.Fatalf("seed moderation: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Notifications (depends on users)
|
// Level 2: Notifications (depends on users)
|
||||||
if err := SeedNotifications(db, cfg, users); err != nil {
|
if err := SeedNotifications(db, cfg, users); err != nil {
|
||||||
log.Fatalf("seed notifications: %v", err)
|
log.Fatalf("seed notifications: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Misc (depends on users)
|
// Level 2: Misc (depends on users)
|
||||||
if err := SeedMisc(db, cfg, users); err != nil {
|
if err := SeedMisc(db, cfg, users); err != nil {
|
||||||
log.Fatalf("seed misc: %v", err)
|
log.Fatalf("seed misc: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── VALIDATION ───────────────────────────────────────────────────────────
|
// ── VALIDATION ───────────────────────────────────────────────────────────
|
||||||
|
|
@ -170,6 +177,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func modeName(cfg Config) string {
|
func modeName(cfg Config) string {
|
||||||
|
if cfg.CIMode {
|
||||||
|
return "CI"
|
||||||
|
}
|
||||||
if cfg.TotalUsers <= 100 {
|
if cfg.TotalUsers <= 100 {
|
||||||
return "MINIMAL"
|
return "MINIMAL"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue