| 1 | package contratest |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/carlosframework/rastrillo/ui" |
| 10 | ) |
| 11 | |
| 12 | // vendoredTheme is the theme this app was scaffolded with. Change it |
| 13 | // here when you swap static/theme.css for another of ui.ThemeNames(). |
| 14 | const vendoredTheme = "plain" |
| 15 | |
| 16 | // vendoredIsMine names the vendored files this app has edited |
| 17 | // DELIBERATELY. Add one here when you mean to diverge: this test stops |
| 18 | // pinning it, and rastrillo doctor leaves it alone too. The file was |
| 19 | // yours from the moment the scaffold wrote it — this is only where you |
| 20 | // record that the edit was on purpose, so the next reader (and the next |
| 21 | // upgrade) can tell it from drift. |
| 22 | var vendoredIsMine = map[string]bool{ |
| 23 | // theme.css is CONTRA's own from 2026-09-05: `plain` is the theme |
| 24 | // rastrillo scaffolds with while an app works out what it looks |
| 25 | // like, and this app now knows. It is the left-luggage theme — |
| 26 | // ticket stock, black ink, one vermilion for the numbering — and its |
| 27 | // header carries the measured WCAG table for every pair. |
| 28 | // |
| 29 | // tokens.css is NOT ours: structure, spacing and the component rules |
| 30 | // stay pinned to the library, so a rastrillo upgrade still lands |
| 31 | // here and only the colour, type and shape are the app's to defend. |
| 32 | "theme.css": true, |
| 33 | } |
| 34 | |
| 35 | // The scaffold delivered these files once; they are app-owned from |
| 36 | // then on. This test pins each vendored copy byte-identical to the |
| 37 | // library it came from: a reviewer runs the suite instead of reading |
| 38 | // ~56KB of assets as app diff, and a framework upgrade that forgets |
| 39 | // to re-copy is caught instead of drifting silently. |
| 40 | // |
| 41 | // The list is ui.VendoredAssets — the same function rastrillo new |
| 42 | // wrote these files from and rastrillo doctor compares them against — |
| 43 | // so a file added to the library's vendored set is pinned here without |
| 44 | // this file changing. |
| 45 | func TestVendoredAssetsMatchTheLibrary(t *testing.T) { |
| 46 | assets, ok := ui.VendoredAssets(vendoredTheme) |
| 47 | if !ok { |
| 48 | t.Fatalf("unknown theme %q", vendoredTheme) |
| 49 | } |
| 50 | for name, lib := range assets { |
| 51 | if vendoredIsMine[name] { |
| 52 | continue |
| 53 | } |
| 54 | vendored, err := os.ReadFile(filepath.Join("..", "contra", "static", name)) |
| 55 | if err != nil { |
| 56 | t.Errorf("read vendored %s: %v", name, err) |
| 57 | continue |
| 58 | } |
| 59 | if !bytes.Equal(vendored, lib) { |
| 60 | t.Errorf("static/%s differs from the library copy; re-copy it with rastrillo doctor --fix (or add it to vendoredIsMine if the edit was deliberate)", name) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |