package shipped import ( "bytes" "encoding/json" "os" "path/filepath" "strings" "testing" "amadan.net/oficina/estilo.git/colophon" ) // The Colophon and what Docs ships cannot differ (Paul, 2026-10-26: "I'd // be happy if that were exhaustive"). Each test regenerates its Colophon // from the builds themselves (shipped.go) and fails unless it is the // committed one. estilo's colophon.Build, inside Generate, fails on a // shipped package the catalog does not know, a project without a usage // note for the app, a usage note for something no longer shipped, and a // shipped package without its licence text. So a new dependency, a // dropped one, a rebuilt bundle or an upgraded crate all fail here until // `go run ./cmd/docs-colophon` is run and the catalog has its words. // // This builds on, rather than repeats, the Go-module check other Oficina // apps have (TestCreditsMatchProductionDependencies): the Go part is the // same go list -deps of the production entry point through estilo's // credits/catalog.Collect. func TestColophonsMatchWhatShips(t *testing.T) { root := filepath.Join("..", "..") web, native, err := Generate(root) if err != nil { t.Fatal(err) } for _, c := range []struct { path string want []byte }{{WebPath, web}, {NativePath, native}} { got, err := os.ReadFile(filepath.Join(root, c.path)) if err != nil { t.Fatal(err) } if !bytes.Equal(got, c.want) { t.Errorf("%s differs from what Docs ships; run `go run ./cmd/docs-colophon`", c.path) } } } // The parts are each non-empty, so a collector that silently found // nothing (a bundle list that moved, a manifest renamed) cannot pass. func TestEveryCollectorFindsSomething(t *testing.T) { root := filepath.Join("..", "..") web, err := Web(root) if err != nil { t.Fatal(err) } native, err := Native(root) if err != nil { t.Fatal(err) } count := func(packages []colophon.Package, ecosystem string, tool bool) int { n := 0 for _, p := range packages { if p.Ecosystem == ecosystem && p.Tool == tool { n++ } } return n } for _, c := range []struct { name string packages []colophon.Package ecosystem string tool bool atLeast int }{ {"server Go modules", web, colophon.Go, false, 15}, {"bundled npm packages", web, colophon.NPM, false, 10}, {"core crates", web, colophon.Cargo, false, 20}, {"server typefaces", web, colophon.Font, false, 17}, {"npm tools", web, colophon.NPM, true, 1}, {"Go tools", web, colophon.Go, true, 1}, {"pip tools", web, colophon.Pip, true, 1}, {"app crates", native, colophon.Cargo, false, 40}, {"app typefaces", native, colophon.Font, false, 16}, {"Swift packages", native, colophon.Swift, false, 2}, } { if n := count(c.packages, c.ecosystem, c.tool); n < c.atLeast { t.Errorf("%s: %d, want at least %d", c.name, n, c.atLeast) } } } func TestHTMLTextKeepsLinesAndDecodesEntities(t *testing.T) { got := htmlText("

Notices

A & B

\n\n\n\n
x
link") if got != "Notices\n\nA & B\n\nx\nlink\n" { t.Fatalf("%q", got) } } // Rastrillo Native's server half is linked into cmd/docs (internal/docs // imports it as nativeauth), so it is on the page: it is Rastrillo's code // under its own licence, not Oficina's. func TestTheNativeServerBridgeIsListed(t *testing.T) { if FirstParty["amadan.net/rastrillo/native/server"] { t.Fatal("amadan.net/rastrillo/native/server is excluded as first-party, but it ships") } web, err := Web(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } for _, p := range web { if p.Ecosystem == colophon.Go && p.Name == "amadan.net/rastrillo/native/server" && !p.Tool && len(p.Notices) > 0 { return } } t.Fatal("the native server bridge is not among the server's packages") } // The toolchains the build and check scripts invoke are tools, each found // in the script that invokes it. func TestTheToolchainsTheScriptsRunAreTools(t *testing.T) { root := filepath.Join("..", "..") web, err := Web(root) if err != nil { t.Fatal(err) } native, err := Native(root) if err != nil { t.Fatal(err) } has := func(ps []colophon.Package, name string) bool { for _, p := range ps { if p.Ecosystem == colophon.Toolchain && p.Name == name { return true } } return false } for _, name := range []string{"go", "rust", "rustup", "node", "npm", "python", "docker", "bwrap", "chromium"} { if !has(web, name) { t.Errorf("the server's tools lack %s", name) } } for _, name := range []string{"rust", "npm", "python", "xcodegen", "swift"} { if !has(native, name) { t.Errorf("the apps' tools lack %s", name) } } } // The five Apple targets' crates are marked with the platforms they build // for, so a crate on one target only would show on that app only. func TestAppleCratesAreMarkedByPlatform(t *testing.T) { native, err := Native(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } marked := 0 for _, p := range native { if p.Ecosystem == colophon.Cargo && p.Name == "wasmi" && len(p.Platforms) == 1 { marked++ } } if marked != 5 { t.Fatalf("wasmi is marked for one platform in %d target graphs, want all five", marked) } built, err := colophon.Build("docs-native", native) if err != nil { t.Fatal(err) } e, ok := built.Entry("wasmi") if !ok || strings.Join(e.Packages[0].Platforms, ",") != "ios,mac" { t.Fatalf("built, wasmi is on %v, want ios and mac", e.Packages) } } // Every dependency fixtures/package.json declares is read by a shipped // bundle: one that is not is dead weight the Colophon would not list. func TestEveryFixturesDependencyIsBundled(t *testing.T) { root := filepath.Join("..", "..") raw, err := os.ReadFile(filepath.Join(root, "fixtures", "package.json")) if err != nil { t.Fatal(err) } var p struct{ Dependencies map[string]string } if err := json.Unmarshal(raw, &p); err != nil { t.Fatal(err) } web, err := Web(root) if err != nil { t.Fatal(err) } bundled := map[string]bool{} for _, pkg := range web { if pkg.Ecosystem == colophon.NPM && !pkg.Tool { bundled[pkg.Name] = true } } for name := range p.Dependencies { if !bundled[name] { t.Errorf("fixtures/package.json depends on %s, which no shipped bundle reads", name) } } } // Nothing in the Apple apps draws a Lucide icon (their icons are Oficina's // own and the system's symbols), so they carry no Lucide notice and their // Colophon does not list it. func TestTheAppsCarryNoLucide(t *testing.T) { root := filepath.Join("..", "..") native, err := Native(root) if err != nil { t.Fatal(err) } for _, p := range native { if p.Name == "lucide" { t.Error("the apps' Colophon lists Lucide") } } // Rastrillo Native copies the notice into the Mac bundle only when the // app has the file (rastrillo/native #10, pinned past c24df35), so the // file itself is gone. if _, err := os.Stat(filepath.Join(root, "native", "LICENSE.lucide")); err == nil { t.Error("native/LICENSE.lucide is still here, so the Mac bundle carries it") } for _, spec := range []string{"native/ios/project.yml", "native/macos/project.yml"} { raw, err := os.ReadFile(filepath.Join(root, spec)) if err != nil { t.Fatal(err) } if strings.Contains(string(raw), "LICENSE.lucide") { t.Errorf("%s still bundles LICENSE.lucide", spec) } } } // Each toolchain is found by its invocation, never by a comment that // mentions it: a script that stops running the tool but keeps the comment // must fail TestTheToolchainsTheScriptsRunAreTools. func TestToolchainNeedlesAreInvocations(t *testing.T) { root := filepath.Join("..", "..") for _, tc := range append(append([]toolchain{}, webToolchains...), nativeToolchains...) { raw, err := os.ReadFile(filepath.Join(root, tc.file)) if err != nil { t.Fatal(err) } found := false for _, line := range strings.Split(string(raw), "\n") { at := strings.Index(line, tc.needle) if at < 0 { continue } if comment := strings.Index(line, "#"); comment >= 0 && comment < at { continue } if strings.HasPrefix(strings.TrimSpace(line), "//") { continue } found = true } if !found { t.Errorf("%s: %q is only in a comment in %s, not an invocation", tc.name, tc.needle, tc.file) } } }