check-safety/check_segmentation.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

53 lines
1.7 KiB
Go

package main
import "fmt"
func init() {
register(Check{
Seq: 180,
ID: "18",
Title: "Plugin segmentation (safety-rules.yml)",
Run: func(ctx *ScanContext, rep *Reporter) {
// Check 18: Plugin segmentation (safety-rules.yml)
fmt.Println("=== Check 18: Plugin segmentation (safety-rules.yml) ===")
var segViolations []segmentationViolation
segPluginsChecked := 0
for _, target := range ctx.resolvedPluginTargets {
rules, loadErr := loadSafetyRules(target.root)
if loadErr != nil {
fmt.Printf(" ERROR: %s: %v\n", target.display, loadErr)
rep.Fail()
continue
}
if rules == nil || rules.Segmentation == nil {
continue // No safety-rules.yml or no segmentation section — skip
}
segPluginsChecked++
vs := checkSegmentation(target.root, target.display, rules.Segmentation)
segViolations = append(segViolations, vs...)
}
if len(segViolations) > 0 {
fmt.Printf(" FAIL: %d segmentation violation(s) found:\n", len(segViolations))
for _, v := range segViolations {
if v.line > 0 {
fmt.Printf(" %s/%s:%d [%s] %s\n", v.pluginName, v.file, v.line, v.rule, v.detail)
} else {
fmt.Printf(" %s/%s [%s] %s\n", v.pluginName, v.file, v.rule, v.detail)
}
}
rep.Fail()
} else if segPluginsChecked > 0 {
fmt.Printf(" OK: Plugin segmentation clean (%d plugin(s) checked)\n", segPluginsChecked)
for _, target := range ctx.resolvedPluginTargets {
rules, _ := loadSafetyRules(target.root)
if rules != nil && rules.Segmentation != nil {
fmt.Printf(" OK: %s\n", target.display)
}
}
} else {
fmt.Println(" OK: No plugins define safety-rules.yml segmentation rules")
}
},
})
}