package stdio import ( "os" "os/exec" "testing" ) // 1171/AC4: before Serve, a bundle's bus functions still refuse exactly as on main (stdio.go:391-398, // unchanged for bundles). Run in a fresh process: once any other test in this package has called Serve, // current stays set for the rest of the test binary, so "before Serve" can only be checked honestly in a // process of its own (the self-exec pattern Go's own testing package uses for os.Exit). func TestBusFunctionsRefuseBeforeServeInAFreshProcess(t *testing.T) { const marker = "MESH_SDK_TEST_FRESH_PROCESS" if os.Getenv(marker) == "1" { if err := Emit("x", map[string]any{}); err == nil || err.Error() != "emit before Serve: a bundle emits through the runtime that launched it" { t.Fatalf("Emit before Serve: %v", err) } if _, err := Ask("m.t", nil); err == nil || err.Error() != "before Serve: a bundle reaches the bus through the runtime that launched it" { t.Fatalf("Ask before Serve: %v", err) } if err := Subscribe("x", func(Envelope) error { return nil }); err == nil || err.Error() != "before Serve: a bundle reaches the bus through the runtime that launched it" { t.Fatalf("Subscribe before Serve: %v", err) } return } cmd := exec.Command(os.Args[0], "-test.run=^TestBusFunctionsRefuseBeforeServeInAFreshProcess$", "-test.v") cmd.Env = append(os.Environ(), marker+"=1") out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("a fresh process did not refuse every bus function before Serve: %v\n%s", err, out) } }