oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package plan3test
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo"
5 "amadan.net/rastrillo/rastrillo/db"
6 "amadan.net/rastrillo/rastrillo/migrate"
7 "io"
8 "log/slog"
9 "path/filepath"
10 "testing"
11)
12
13func TestOnboardingAccountMigration(t *testing.T) {
14 d, e := db.Open(filepath.Join(t.TempDir(), "accounts.db"), slog.New(slog.NewTextHandler(io.Discard, nil)))
15 must(t, e)
16 t.Cleanup(func() { must(t, d.Close()) })
17 old := &migrate.Set{}
18 for _, m := range equipo.BootSchema.All() {
19 if m.ID != "equipo/0028_setup_accounts" {
20 old.Add(m)
21 }
22 }
23 _, e = migrate.Apply(ctx, d, old)
24 must(t, e)
25 _, e = d.Writer().Exec("INSERT INTO onboarding_states(person,revision,provider_choice,completed) VALUES('saved',7,'claude','{\"welcome\":true}')")
26 must(t, e)
27 result, e := migrate.Apply(ctx, d, equipo.BootSchema)
28 must(t, e)
29 if len(result.Applied) != 1 || result.Applied[0] != "equipo/0028_setup_accounts" {
30 t.Fatal(result.Applied)
31 }
32 var rev int
33 must(t, d.Writer().QueryRow("SELECT revision FROM onboarding_states WHERE person='saved'").Scan(&rev))
34 if rev != 7 {
35 t.Fatal("setup migration lost progress")
36 }
37 fresh := newFixture(t)
38 up, e := migrate.Read(ctx, d.Writer())
39 must(t, e)
40 clean, e := migrate.Read(ctx, fresh.DB.Writer())
41 must(t, e)
42 if !up.Equal(clean) {
43 t.Fatal(up.Diff(clean))
44 }
45 result, e = migrate.Apply(ctx, d, equipo.BootSchema)
46 must(t, e)
47 if len(result.Applied) != 0 {
48 t.Fatal("migration repeated")
49 }
50}
51