From 99bd9d3a629de6f10e4486adaf4146ab13819d74 Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:23:24 -0800 Subject: [PATCH] Stop a fixed test backend id colliding with a generated one The backend-selection test added a Grafana backend with the fixed id grafana2, and the test helper renames grafana to grafana from a counter shared by the whole package. Once N reached 2 the two ids collided, the loader saw a duplicate and the test got config_invalid instead of ambiguous_backend. Which run hit it depended on test order, so it passed on one OS and failed on the other. The extra backend is now grafana-extra, an id the counter cannot produce. The helper also checks the test config for a repeated id and fails with the cause named, so a future fixed id of that shape says what is wrong. Checked by repeating the selection test 40 times, by sixteen shuffle seeds under the race detector, and by putting the old id back: the helper then names the collision. Signed-off-by: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> --- cmd/vigil/wire_grafana_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/vigil/wire_grafana_test.go b/cmd/vigil/wire_grafana_test.go index 9f2d24c..c9ee93d 100644 --- a/cmd/vigil/wire_grafana_test.go +++ b/cmd/vigil/wire_grafana_test.go @@ -44,6 +44,17 @@ func writeBackends(t *testing.T, cfgBody string, addrs map[string]string) (cfg, cfgBody = strings.ReplaceAll(cfgBody, "id: "+base+"\n", "id: "+id+"\n") fmt.Fprintf(&overlay, " - id: %s\n address: %s\n", id, addr) } + // A fixed id that equals a generated one would read as a duplicate and fail + // as config_invalid, far from its cause. Say so here instead. + seen := map[string]bool{} + for _, line := range strings.Split(cfgBody, "\n") { + if id, ok := strings.CutPrefix(strings.TrimSpace(line), "- id: "); ok { + if seen[id] { + t.Fatalf("writeBackends: the id %q appears twice in the test config; a fixed id collides with a generated one", id) + } + seen[id] = true + } + } dir := t.TempDir() cfg, ov = filepath.Join(dir, "config.yaml"), filepath.Join(dir, "overlay.yaml") if err := os.WriteFile(cfg, []byte(cfgBody), 0o600); err != nil { @@ -187,7 +198,10 @@ func TestGrafanaHealthBackendSelection(t *testing.T) { if got := oneErrorLine(t, "no backend", errs); got != "no_backend" { t.Errorf("code = %q", got) } - two := strings.Replace(grafanaConfig, "authorities:", " - id: grafana2\n kind: grafana\nauthorities:", 1) + // The extra backend's id carries a hyphen. writeBackends renames "grafana" to + // grafana from a package-wide counter, so a fixed id of the form + // grafana collides with it the run that N reaches that digit. + two := strings.Replace(grafanaConfig, "authorities:", " - id: grafana-extra\n kind: grafana\nauthorities:", 1) c, o = writeBackends(t, two, map[string]string{"grafana": g.URL}) code, out, errs = live(t, "grafana", "health", "--config", c, "--overlay", o) if code != exitcode.Usage || out != "" {