check-safety/check_protoownership.go
Alex Dunmow cd88c808b0 initial: standalone check-safety module hoisted from CMS
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>
2026-06-06 13:04:02 +08:00

52 lines
1.7 KiB
Go

package main
import (
"fmt"
"os"
)
func init() {
register(Check{
Seq: 21,
ID: "2b",
Title: "Plugin proto ownership",
Run: func(ctx *ScanContext, rep *Reporter) {
// Check 2b: Plugin proto ownership
fmt.Println("=== Check 2b: Plugin proto ownership ===")
var protoOwnershipViolations []protoOwnershipViolation
for _, target := range ctx.backendTargets {
if !isPluginModuleRoot(target.root) {
continue
}
violations, err := checkPluginProtoOwnership(target.root, target.displayOrRoot())
if err != nil {
fmt.Printf(" ERROR: failed to check proto ownership for %s: %v\n", target.displayOrRoot(), err)
os.Exit(2)
}
protoOwnershipViolations = append(protoOwnershipViolations, violations...)
}
for _, target := range ctx.pluginTargets {
violations, err := checkPluginProtoOwnership(target.root, target.display)
if err != nil {
fmt.Printf(" ERROR: failed to check proto ownership for %s: %v\n", target.display, err)
os.Exit(2)
}
protoOwnershipViolations = append(protoOwnershipViolations, violations...)
}
if len(protoOwnershipViolations) > 0 {
fmt.Printf(" FAIL: %d plugin proto ownership violation(s):\n", len(protoOwnershipViolations))
for _, v := range protoOwnershipViolations {
fmt.Printf(" %s [%s] local proto missing; matching proto exists in %s\n", v.root, v.namespace, v.coreProto)
}
fmt.Println("\n Fix: move plugin proto sources into the plugin repo and generate api/ from there.")
rep.Fail()
} else {
fmt.Println(" OK: Plugin proto ownership is clean")
printPerTargetOKLines(pluginTargetLabels(ctx.pluginTargets))
}
fmt.Println()
},
})
}