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 TestSpecialistLibraryMigration(t *testing.T) {
14 d, err := db.Open(filepath.Join(t.TempDir(), "library.db"), slog.New(slog.NewTextHandler(io.Discard, nil)))
15 must(t, err)
16 t.Cleanup(func() { must(t, d.Close()) })
17 old := &migrate.Set{}
18 for _, m := range equipo.BootSchema.All() {
19 if m.ID != "equipo/0024_specialist_library" {
20 old.Add(m)
21 }
22 }
23 _, err = migrate.Apply(ctx, d, old)
24 must(t, err)
25 f := &fixture{DB: d, Store: equipo.NewStore(d), TeamID: "saved-team"}
26 f.exec(t, "INSERT INTO teams(id,name,roster_epoch) VALUES('saved-team','Saved team',4)")
27 f.exec(t, "INSERT INTO members(address,role,revision,active) VALUES(?,'owner',3,1)", owner.Address)
28 f.exec(t, "INSERT INTO specialists(key,model_selection,standing_instructions,max_concurrent,revision) VALUES('engineering','best_fit','Saved instructions',3,7)")
29 result, err := migrate.Apply(ctx, d, equipo.BootSchema)
30 must(t, err)
31 if len(result.Applied) != 1 || result.Applied[0] != "equipo/0024_specialist_library" {
32 t.Fatal(result.Applied)
33 }
34 row, err := f.Store.Specialist(ctx, owner, "engineering")
35 must(t, err)
36 if row.TeamID != f.TeamID || !row.Required || row.Role != "engineering" || row.StandingInstructions != "Saved instructions" || row.Revision != 7 || row.MaxConcurrent != 3 {
37 t.Fatal("migration changed saved settings", row)
38 }
39 if f.count(t, "SELECT count(*) FROM specialist_requests") != 0 {
40 t.Fatal("migration fabricated requests")
41 }
42 fresh := newFixture(t)
43 upgraded, err := migrate.Read(ctx, d.Writer())
44 must(t, err)
45 clean, err := migrate.Read(ctx, fresh.DB.Writer())
46 must(t, err)
47 if !upgraded.Equal(clean) {
48 t.Fatal(upgraded.Diff(clean))
49 }
50 result, err = migrate.Apply(ctx, d, equipo.BootSchema)
51 must(t, err)
52 if len(result.Applied) != 0 {
53 t.Fatal("migration repeated")
54 }
55}
56