package fichastest import ( "go/parser" "go/token" "io/fs" "os" "path/filepath" "regexp" "strconv" "strings" "testing" ) // preMoveRastrillo is rastrillo's module path before it moved to // amadan.net/rastrillo/rastrillo (2026-08-31). Nothing after v0.23.0 was // released under it, so code importing it gets no rastrillo fix — and the // vendored-asset test cannot tell, because it compares against the same // frozen ui. That is how Fichas kept iOS zooming on every tap until it // carried its own copy of the fix (polish audit r3, S13). const preMoveRastrillo = "github.com/carlosframework/rastrillo" // rastrilloPath is where it lives now. const rastrilloPath = "amadan.net/rastrillo/rastrillo" // repoRoot is the module root, two levels above this package. func repoRoot(t *testing.T) string { t.Helper() root, err := filepath.Abs(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } if _, err := os.Stat(filepath.Join(root, "go.mod")); err != nil { t.Fatalf("no go.mod at %s: %v", root, err) } return root } // goImports is every import of every .go file under root, by file. func goImports(t *testing.T, root string) map[string][]string { t.Helper() out := map[string][]string{} fset := token.NewFileSet() err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { if err != nil { return err } if d.IsDir() && (d.Name() == ".git" || d.Name() == "releases") { return filepath.SkipDir } if d.IsDir() || !strings.HasSuffix(path, ".go") { return nil } f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly) if err != nil { return err } rel, _ := filepath.Rel(root, path) for _, imp := range f.Imports { p, _ := strconv.Unquote(imp.Path.Value) out[rel] = append(out[rel], p) } return nil }) if err != nil { t.Fatal(err) } return out } // TestNoPreMoveRastrillo fails on any import of rastrillo's frozen // pre-move path, test files, scripts and browser-tagged files included. func TestNoPreMoveRastrillo(t *testing.T) { for file, imps := range goImports(t, repoRoot(t)) { for _, imp := range imps { if imp == preMoveRastrillo || strings.HasPrefix(imp, preMoveRastrillo+"/") { t.Errorf("%s imports %q, rastrillo's frozen pre-move path; use %s", file, imp, rastrilloPath) } } } } // TestReleaseStampsTheServedVersion: `make release` stamps BuildVersion // with -X, and the Go linker ignores an -X naming a package the binary // does not contain — no error, no warning. Stamp the old path while the // binary serves the new one and /api/version answers "dev" for every // release, which is exactly the answer the platform's deploy check // cannot tell from a binary that was never recycled. The stamped package // must be the rastrillo cmd/fichas serves through. func TestReleaseStampsTheServedVersion(t *testing.T) { root := repoRoot(t) mk, err := os.ReadFile(filepath.Join(root, "Makefile")) if err != nil { t.Fatal(err) } m := regexp.MustCompile(`-X '?([^'=\s]+)\.BuildVersion=`).FindSubmatch(mk) if m == nil { t.Fatal("the Makefile's release does not stamp BuildVersion with -X") } stamped := string(m[1]) if stamped != rastrilloPath { t.Errorf("make release stamps %s.BuildVersion; the served version is %s.BuildVersion", stamped, rastrilloPath) } served := false for _, imp := range goImports(t, root)[filepath.Join("cmd", "fichas", "main.go")] { served = served || imp == stamped } if !served { t.Errorf("cmd/fichas does not import %s, so -X %s.BuildVersion stamps nothing", stamped, stamped) } }