| 1 | package home |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "log/slog" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/home/internal/home/sealtest" |
| 10 | ) |
| 11 | |
| 12 | func TestSchemaInventoryEmitsOnlyCompiledNames(t *testing.T) { |
| 13 | pair := newExchangePair(t) |
| 14 | cfg := *pair.directory.runtime |
| 15 | expected := map[string]bool{} |
| 16 | for _, m := range cfg.Schema().All() { |
| 17 | expected[m.ID] = true |
| 18 | } |
| 19 | extra := "" |
| 20 | for _, m := range (Runtime{role: "credential"}).Schema().All() { |
| 21 | if !expected[m.ID] { |
| 22 | extra = m.ID |
| 23 | break |
| 24 | } |
| 25 | } |
| 26 | if extra == "" { |
| 27 | t.Fatal("no cross-role fixture") |
| 28 | } |
| 29 | for _, id := range []string{extra, sealtest.CanaryAddress, strings.Repeat("x", 300)} { |
| 30 | if _, err := pair.directory.db.Writer().Exec("INSERT INTO rastrillo_migrations(id,applied_at,checksum) VALUES(?,'2026-01-01T00:00:00Z','fixture')", id); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | } |
| 34 | var out bytes.Buffer |
| 35 | logger := slog.New(slog.NewJSONHandler(&out, nil)) |
| 36 | LogSchemaInventory(t.Context(), pair.directory.db, cfg, logger) |
| 37 | if !bytes.Contains(out.Bytes(), []byte(extra)) || !bytes.Contains(out.Bytes(), []byte(`"unclassified":2`)) { |
| 38 | t.Fatal("inventory missed known migration or count") |
| 39 | } |
| 40 | if bytes.Contains(out.Bytes(), []byte(sealtest.CanaryAddress)) || bytes.Contains(out.Bytes(), []byte(strings.Repeat("x", 300))) || bytes.Contains(out.Bytes(), []byte("fixture")) { |
| 41 | t.Fatal("inventory leaked database strings") |
| 42 | } |
| 43 | } |
| 44 | |