ee71abd1d4
Operator ruling 09 §3 decision 139. One exact sudoers rule FELHOM_FSTRIM
(`/usr/sbin/pct ^fstrim [0-9]+$`) + manifest entry guest-fstrim; new
internal/fstrim job: due Wednesday from 10:00 host-local, starts only
10:00-20:59, holds backup.InFlight (busy -> deferred to the next hourly
tick), failed trim retried at most 3x per week, bytes parsed from the
"(N bytes) trimmed" lines, last result per guest persisted in
<state_dir>/guest-disk-trim.json and reported as guest_disk_trim.
Config opt-out: "disk_trim": {"disable": true}.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"testing"
|
|
)
|
|
|
|
// R-444: the weekly trim has the guestnet shape (component + reporter seam + goroutine), so its wiring is asserted
|
|
// from the AST like TestMainWiresGuestNetWatchdog — a unit-green trim job that main.go never starts is the inert-seam
|
|
// defect. It must also share the ONE heavy-op gate (heavyOps), or it could run beside a backup.
|
|
func TestMainWiresGuestDiskTrim(t *testing.T) {
|
|
fset := token.NewFileSet()
|
|
f, err := parser.ParseFile(fset, "main.go", nil, 0)
|
|
if err != nil {
|
|
t.Fatalf("parse main.go: %v", err)
|
|
}
|
|
var constructedWithGate, reporterWired, started bool
|
|
ast.Inspect(f, func(n ast.Node) bool {
|
|
switch node := n.(type) {
|
|
case *ast.CallExpr:
|
|
if fn, ok := node.Fun.(*ast.SelectorExpr); ok {
|
|
switch fn.Sel.Name {
|
|
case "New":
|
|
if pkg, ok := fn.X.(*ast.Ident); ok && pkg.Name == "fstrim" && len(node.Args) >= 3 {
|
|
if id, ok := node.Args[2].(*ast.Ident); ok && id.Name == "heavyOps" {
|
|
constructedWithGate = true
|
|
}
|
|
}
|
|
case "SetGuestDiskTrimReporter":
|
|
reporterWired = true
|
|
}
|
|
}
|
|
case *ast.GoStmt:
|
|
if sel, ok := node.Call.Fun.(*ast.SelectorExpr); ok && sel.Sel.Name == "Run" {
|
|
if id, ok := sel.X.(*ast.Ident); ok && id.Name == "diskTrim" {
|
|
started = true
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
})
|
|
if !constructedWithGate {
|
|
t.Error("main.go never calls fstrim.New(..., heavyOps, ...) — no trim job, or one outside the heavy-op gate")
|
|
}
|
|
if !reporterWired {
|
|
t.Error("main.go never calls collector.SetGuestDiskTrimReporter — the guest_disk_trim stanza never reaches the hub")
|
|
}
|
|
if !started {
|
|
t.Error("main.go never starts the trim job with `go diskTrim.Run(ctx)`")
|
|
}
|
|
}
|