The view's tools read their own reach by its bare name, and a test holds every state the commands read to what is issued (issue 1280) #82
@@ -202,7 +202,7 @@ func read(state stdio.KeptState) view.StateRead {
|
||||
func main() {
|
||||
r := view.Reader{State: read(stdio.State("mesh-delivery-indexer.modules")), Builds: read(stdio.State("mesh-delivery-builder.builds")), CandidatesState: read(stdio.State("mesh-delivery-indexer.candidates")),
|
||||
WantsState: read(stdio.State("mesh-delivery-assigner.wants")), DifferencesState: read(stdio.State("mesh-delivery-assigner.differences")), HavesState: read(stdio.State("node-engine.have")),
|
||||
ReachState: read(stdio.State("mesh-delivery-view.reach")),
|
||||
ReachState: read(stdio.State("reach")),
|
||||
PlacementState: read(stdio.State("mesh-delivery-indexer.placement"))}
|
||||
u := view.UsageReader{Haves: r.HavesState, Resolved: read(stdio.State("mesh-config.resolved")), Tries: read(stdio.State("mesh-delivery-checker.tries")),
|
||||
Steps: map[string]view.StateRead{}, Pauses: map[string]view.StateRead{}, Backlog: backlogOf(socket())}
|
||||
|
||||
@@ -3,8 +3,11 @@ package manifest
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -281,3 +284,42 @@ func TestNoDirectoryBelowRootsTrees(t *testing.T) { // 1134/AC10
|
||||
t.Error("the socket's directory is /var/lib/mesh-delivery-view-cli, 0755, owned by mesh-delivery-view")
|
||||
}
|
||||
}
|
||||
|
||||
// TestEveryStateTheCommandsReadIsIssued holds every literal stdio.State name in cmd/ to what the mesh issues this
|
||||
// module: a state of its own by its bare name, another module's by <module>.<name> as `reads` lists it. The tools read
|
||||
// their own reach as "mesh-delivery-view.reach", which the mesh never issued, and view_reach failed on the machines
|
||||
// (issue 1280, note 13).
|
||||
func TestEveryStateTheCommandsReadIsIssued(t *testing.T) {
|
||||
m, _ := load(t)
|
||||
issued := map[string]bool{}
|
||||
for _, s := range m.State {
|
||||
issued[s.Name] = true
|
||||
}
|
||||
for _, r := range m.Reads {
|
||||
issued[r] = true
|
||||
}
|
||||
literal := regexp.MustCompile(`stdio\.State\("([^"]+)"\)`)
|
||||
seen := 0
|
||||
err := filepath.WalkDir("cmd", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() || !strings.HasSuffix(path, ".go") {
|
||||
return err
|
||||
}
|
||||
src, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, match := range literal.FindAllSubmatch(src, -1) {
|
||||
seen++
|
||||
if name := string(match[1]); !issued[name] {
|
||||
t.Errorf("%s reads the state %q, which the mesh does not issue this module (its own by bare name, another's as `reads` lists it)", path, name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if seen == 0 {
|
||||
t.Fatal("no stdio.State literal found under cmd/: the scan reads nothing")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user