node-tools: say whose words a refused event is (hq issue 276)

"plex did not take radarr.download.completed: Unexpected end of JSON input"
read as the runtime failing to parse the bundle's answer. It was plex's own
handler error, relayed. A bundle's error answer is now a launch.Refused, and
the line says the handler answered an error, quotes it, names the event id
and the delay before the next offer; the runtime's own failures (no answer
in time, bundle exited) are said as before.

The rule, unchanged and now tested: any mesh/event answer that is not an
error takes the event, whatever its result says, including none.
This commit is contained in:
jochen
2026-10-06 18:14:50 +02:00
parent f75780f1d0
commit 1792b0d9ba
4 changed files with 142 additions and 2 deletions
@@ -2,12 +2,14 @@ package runtime
import (
"encoding/json"
"errors"
"os"
"strings"
"testing"
"time"
"github.com/novox/mesh-tools/node-tools/internal/bus"
"github.com/novox/mesh-tools/node-tools/internal/launch"
mt "github.com/novox/mesh-tools/node-tools/internal/meshtest"
)
@@ -249,3 +251,18 @@ func TestToolModulesNamesOtherModulesOnly(t *testing.T) {
}
}
}
// A line about an event a bundle did not take says who failed: the handler in its own words, or the
// runtime not reaching it (hq issue 276).
func TestAnUntakenEventSaysWhoFailed(t *testing.T) {
handler := whyNotTaken(&launch.Refused{Method: "mesh/event", Message: "Unexpected end of JSON input"})
if !strings.Contains(handler, `its handler answered an error, in its own words: "Unexpected end of JSON input"`) {
t.Errorf("a handler's error is not said as the handler's: %s", handler)
}
if got := whyNotTaken(errors.New("plex's bundle did not answer mesh/event in 120s")); got != "plex's bundle did not answer mesh/event in 120s" {
t.Errorf("the runtime's own failure is not said as it is: %s", got)
}
if got := eventRef(bus.Envelope{Headers: map[string]string{"x-event-id": "e1"}}); got != " (event e1)" {
t.Errorf("the event is not named by its id: %q", got)
}
}