fix(api): include health-check reason payload

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-03-31 19:53:19 +00:00
parent 7c3801e741
commit cd16b014da
2 changed files with 28 additions and 0 deletions

View file

@ -236,10 +236,15 @@ func (p *ProcessProvider) healthCheck(c *gin.Context) {
}
healthy := process.WaitForHealth(entry.Health, 2000)
reason := ""
if !healthy {
reason = "health endpoint did not report healthy"
}
result := map[string]any{
"healthy": healthy,
"address": entry.Health,
"reason": reason,
}
// Emit health event
@ -247,6 +252,7 @@ func (p *ProcessProvider) healthCheck(c *gin.Context) {
"code": code,
"daemon": daemon,
"healthy": healthy,
"reason": reason,
})
statusCode := http.StatusOK

View file

@ -5,6 +5,7 @@ package api_test
import (
"net/http"
"net/http/httptest"
"os"
"testing"
process "dappco.re/go/core/process"
@ -89,6 +90,27 @@ func TestProcessProvider_GetDaemon_Bad(t *testing.T) {
assert.Equal(t, http.StatusNotFound, w.Code)
}
func TestProcessProvider_HealthCheck_NoEndpoint_Good(t *testing.T) {
dir := t.TempDir()
registry := newTestRegistry(dir)
require.NoError(t, registry.Register(process.DaemonEntry{
Code: "test",
Daemon: "nohealth",
PID: os.Getpid(),
}))
p := processapi.NewProvider(registry, nil)
r := setupRouter(p)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/process/daemons/test/nohealth/health", nil)
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
assert.Contains(t, w.Body.String(), "no health endpoint configured")
assert.Contains(t, w.Body.String(), "\"reason\"")
}
func TestProcessProvider_RegistersAsRouteGroup_Good(t *testing.T) {
p := processapi.NewProvider(nil, nil)