oficina / memoria Public

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

Plain git — no account needed to clone.

Download

Download this file

1package memoria
2
3import (
4 "bytes"
5 "context"
6 "encoding/json"
7 "os"
8 "os/exec"
9 "path/filepath"
10 "runtime"
11 "sort"
12 "strings"
13 "testing"
14 "time"
15
16 "amadan.net/oficina/estilo.git/credits"
17 "amadan.net/oficina/estilo.git/credits/catalog"
18)
19
20// Check the production package graph, not the test binary's dependencies.
21// A dependency or notice change must update the embedded attribution too.
22// Mutation-checked 2026-09-11: changing the embedded Go version fails.
23func TestCreditsMatchProductionDependencies(t *testing.T) {
24 ctx, cancel := context.WithTimeout(t.Context(), 45*time.Second)
25 defer cancel()
26 command := exec.CommandContext(ctx, "go", "list", "-buildvcs=false", "-deps", "-json", "./cmd/memoria")
27 command.Dir = filepath.Join("..", "..")
28 for _, entry := range os.Environ() {
29 if !strings.HasPrefix(entry, "GOOS=") && !strings.HasPrefix(entry, "GOARCH=") && !strings.HasPrefix(entry, "CGO_ENABLED=") && !strings.HasPrefix(entry, "GOWORK=") {
30 command.Env = append(command.Env, entry)
31 }
32 }
33 command.Env = append(command.Env, "GOOS=linux", "GOARCH=arm64", "CGO_ENABLED=0", "GOWORK=off")
34 raw, err := command.Output()
35 if err != nil {
36 t.Fatal("production dependency graph unavailable", err)
37 }
38 inventory, err := catalog.Collect(bytes.NewReader(raw), map[string]bool{"amadan.net/oficina/estilo.git": true, "amadan.net/oficina/home/handoff": true, "amadan.net/oficina/home/connect": true, "amadan.net/oficina/suite": true, "amadan.net/rastrillo/native/server": true})
39 if err != nil {
40 t.Fatal(err)
41 }
42 goLicense, err := os.ReadFile(filepath.Join(runtime.GOROOT(), "LICENSE"))
43 if err != nil {
44 t.Fatal(err)
45 }
46 inventory.Components = append(inventory.Components, credits.Lucide(), credits.Onest(), credits.Component{Name: "Go", Version: runtime.Version(), SourceURL: "https://go.dev/LICENSE", Notices: []credits.Notice{{Name: "LICENSE", Text: string(goLicense)}}})
47 sort.Slice(inventory.Components, func(i, j int) bool { return inventory.Components[i].Name < inventory.Components[j].Name })
48 var embedded creditInventory
49 if err := json.Unmarshal(creditNotices, &embedded); err != nil {
50 t.Fatal(err)
51 }
52 expected, _ := json.Marshal(creditInventory{Components: inventory.Components, MissingNotices: inventory.MissingNotices})
53 actual, _ := json.Marshal(embedded)
54 if !bytes.Equal(expected, actual) {
55 t.Fatal("embedded credits differ from production dependencies; run make credits")
56 }
57}
58