browsermcp: TestVisionBridgePassesLines takes the messages in any order

The bridge passes each stdio message from its own goroutine, so initialize,
the notification and the call reach the fake gateway in any order; the
test read the call's image at index 2 and went red on mote when the call
landed first (images ["" ".../shots/a.png" ""]). It now checks every path
and that the one image named is the call's, made absolute.

Run (mote-run), with a 50ms hold injected before every message but the
call: the old test red 3 of 3, the new one green 3 of 3; without it,
go test ./internal/browsermcp ok.
This commit is contained in:
yetone
2026-11-01 16:10:16 +08:00
parent de74cb53f7
commit 0b783b1ddc
+5 -1
View File
@@ -8,6 +8,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"testing"
@@ -165,7 +166,10 @@ func TestVisionBridgePassesLines(t *testing.T) {
if lines := strings.Split(strings.TrimSpace(out.String()), "\n"); len(lines) != 2 || !strings.Contains(out.String(), `"id":2`) {
t.Fatalf("out: %q", out.String())
}
if len(paths) != 3 || paths[0] != gateway.VisionMCPPath || paths[2] != gateway.VisionMCPPath || images[2] != filepath.Join(wd, "shots", "a.png") {
// the bridge passes messages side by side, so they reach the gateway
// in any order: the one image named is the call's
named := slices.DeleteFunc(slices.Clone(images), func(v string) bool { return v == "" })
if len(paths) != 3 || slices.ContainsFunc(paths, func(p string) bool { return p != gateway.VisionMCPPath }) || len(named) != 1 || named[0] != filepath.Join(wd, "shots", "a.png") {
t.Fatalf("paths %q, images %q", paths, images)
}