Files
felhom.eu/hub/cmd/hub/r133_wiring_test.go
T

52 lines
1.6 KiB
Go

package main
import (
"go/ast"
"go/parser"
"go/token"
"testing"
)
// R-133 seam wiring: main() must CALL SealLegacyRecoverySecrets (a comment or a string does not count —
// the AST is walked). Without the call, every console password written before v0.135.0 stays in plaintext.
// RED-PROOF: comment the call out → this test fails.
func TestR133_MainSealsLegacyRecoverySecrets(t *testing.T) {
f, err := parser.ParseFile(token.NewFileSet(), "main.go", nil, 0)
if err != nil {
t.Fatal(err)
}
found := false
ast.Inspect(f, func(n ast.Node) bool {
if c, ok := n.(*ast.CallExpr); ok {
if sel, ok := c.Fun.(*ast.SelectorExpr); ok && sel.Sel.Name == "SealLegacyRecoverySecrets" {
found = true
}
}
return true
})
if !found {
t.Fatal("cmd/hub/main.go never calls SealLegacyRecoverySecrets — legacy console passwords stay in plaintext")
}
}
// R-604 seam wiring: main() must hand the web server the dispatcher (SetEventEmitter), or the "floor raise skipped
// boxes" mail is logged and never sent. RED-PROOF: delete the call → this test fails.
func TestR604_MainWiresTheWebEventEmitter(t *testing.T) {
f, err := parser.ParseFile(token.NewFileSet(), "main.go", nil, 0)
if err != nil {
t.Fatal(err)
}
found := false
ast.Inspect(f, func(n ast.Node) bool {
if c, ok := n.(*ast.CallExpr); ok {
if sel, ok := c.Fun.(*ast.SelectorExpr); ok && sel.Sel.Name == "SetEventEmitter" && len(c.Args) == 1 {
found = true
}
}
return true
})
if !found {
t.Fatal("cmd/hub/main.go never calls webServer.SetEventEmitter — the R-604 mail is never sent")
}
}