Static safety/lint runner for the BlockNinja codebase. ~25 invariant
checks across Go and frontend sources. Was at git.dev.alexdunmow.com:block/ninja
in backend/cmd/check-safety/ until the 2026-06-06 consolidation moved
the BlockNinja repos under a shared ~/src/blockninja/ parent.
This repo is the standalone extraction:
- Own go.mod (git.dev.alexdunmow.com/block/check-safety, go 1.26.4)
- Vendored internal/{helpers,theme} from CMS (Go's internal/ rule
blocks cross-module imports; vendoring is the workaround)
- CLI contract unchanged: `check-safety <target-dir> [--flags]`
- CMS Makefile shells into ../check-safety for safety-check /
install-safety-checker targets
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
// TestRegistryOrder locks the run order of all registered checks.
|
|
//
|
|
// main() runs checks sorted by Seq, so the Seq values ARE the contract for
|
|
// output order. The golden characterization test cannot guard every position:
|
|
// the plugin-discovery check ("10disc") prints nothing when no plugin roots are
|
|
// scanned (as in the golden fixtures), so a Seq mistake that reordered it past
|
|
// Check 10b would slip through golden silently. Assert the full canonical order
|
|
// here, and reject duplicate Seq values (which would make order nondeterministic).
|
|
func TestRegistryOrder(t *testing.T) {
|
|
want := []string{
|
|
"1", "2", "2b", "2c", "2d", "2e", "2f", "3", "3b", "4",
|
|
"5", "6", "7", "8", "9", "10", "10b", "10disc", "11", "12",
|
|
"13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
|
|
}
|
|
|
|
ordered := make([]Check, len(registry))
|
|
copy(ordered, registry)
|
|
sort.Slice(ordered, func(i, j int) bool { return ordered[i].Seq < ordered[j].Seq })
|
|
|
|
if len(ordered) != len(want) {
|
|
t.Fatalf("registry has %d checks, want %d", len(ordered), len(want))
|
|
}
|
|
for i, c := range ordered {
|
|
if c.ID != want[i] {
|
|
t.Errorf("position %d: got check %q (Seq %d), want %q", i, c.ID, c.Seq, want[i])
|
|
}
|
|
}
|
|
|
|
seen := map[int]string{}
|
|
for _, c := range registry {
|
|
if prev, ok := seen[c.Seq]; ok {
|
|
t.Errorf("duplicate Seq %d on checks %q and %q", c.Seq, prev, c.ID)
|
|
}
|
|
seen[c.Seq] = c.ID
|
|
}
|
|
}
|