The dashboard's Run read the watchdog's phase-2 report off local disk and put it on the activity stream. That is a host-local file read in the process that is moving off the host: the watchdog restarts archied and leaves its verdict beside archied, so archied is what can read it. The daemon now polls and relays it, publishing the same event through the same bus, so it persists with every other event and reaches whichever dashboard is watching. The event builder moves to releaseupdate, which owns Report and its verification; the dashboard keeps only what it needs to tell an installer where to write. The startup poll stays: the watchdog writes its result only once the process answers /healthz, so a single read at boot can always miss the report describing that very boot. persistAndBroadcastEvents takes the daemon context and detaches it for the insert, which is what it always did with context.Background() -- the last events of a run are the ones an operator reads afterwards.
79 lines
3.2 KiB
Go
79 lines
3.2 KiB
Go
package webui
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/releaseupdate"
|
|
)
|
|
|
|
// TestHandleChatUpdateInstallSetsReportPath is the regression proof: before
|
|
// this fix, the webui install handler passed
|
|
// releaseupdate.InstallMeta{Channel: "webui"} with no ReportPath, so the
|
|
// watchdog's write_report() (scripts/archie-update-watchdog) silently
|
|
// returned without ever writing a phase-2 report.
|
|
func TestHandleChatUpdateInstallSetsReportPath(t *testing.T) {
|
|
reportPath := filepath.Join(t.TempDir(), "update-report.json")
|
|
updates := &chatUpdateStub{snapshot: releaseupdate.Snapshot{
|
|
Components: []releaseupdate.Component{{ID: "gateway", Label: "Gateway", Installed: "1.0", Available: "1.1"}},
|
|
}}
|
|
sessions := gateway.NewSessionStoreMemory()
|
|
t.Cleanup(func() { _ = sessions.Close() })
|
|
router := gateway.NewRouter(chatStatusStub{}, nil, "web")
|
|
server := &Server{Chat: testChatService(router, sessions, nil, nil, nil, updates, nil), UpdateReportPath: reportPath}
|
|
|
|
body, err := json.Marshal(chatUpdateRequest{Snapshot: updates.snapshot})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
res := httptest.NewRecorder()
|
|
server.Handler().ServeHTTP(res, httptest.NewRequestWithContext(context.Background(), http.MethodPost, "/api/chat/update/install", bytes.NewReader(body)))
|
|
if res.Code != http.StatusOK || !updates.installed {
|
|
t.Fatalf("update install = %d, body = %s", res.Code, res.Body.String())
|
|
}
|
|
if updates.installedMeta.ReportPath != reportPath {
|
|
t.Errorf("ReportPath = %q, want %q", updates.installedMeta.ReportPath, reportPath)
|
|
}
|
|
}
|
|
|
|
func TestHandleChatUpdateInstallRoutesRestartReportToTelegram(t *testing.T) {
|
|
reportPath := filepath.Join(t.TempDir(), "telegram-update-report.json")
|
|
updates := &chatUpdateStub{snapshot: releaseupdate.Snapshot{
|
|
Components: []releaseupdate.Component{{ID: "gateway", Label: "Gateway", Installed: "1.0", Available: "1.1"}},
|
|
}}
|
|
sessions := gateway.NewSessionStoreMemory()
|
|
t.Cleanup(func() { _ = sessions.Close() })
|
|
router := gateway.NewRouter(chatStatusStub{}, nil, "web")
|
|
server := &Server{
|
|
Chat: testChatService(router, sessions, nil, nil, nil, updates, nil),
|
|
UpdateReportPath: filepath.Join(t.TempDir(), "webui-update-report.json"),
|
|
TelegramUpdateReportPath: reportPath,
|
|
TelegramUpdateChatID: 42,
|
|
}
|
|
|
|
body, err := json.Marshal(chatUpdateRequest{Snapshot: updates.snapshot})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
res := httptest.NewRecorder()
|
|
server.Handler().ServeHTTP(res, httptest.NewRequestWithContext(context.Background(), http.MethodPost, "/api/chat/update/install", bytes.NewReader(body)))
|
|
if res.Code != http.StatusOK || !updates.installed {
|
|
t.Fatalf("update install = %d, body = %s", res.Code, res.Body.String())
|
|
}
|
|
if updates.installedMeta.Channel != "telegram" {
|
|
t.Errorf("Channel = %q, want telegram", updates.installedMeta.Channel)
|
|
}
|
|
if updates.installedMeta.ChatID != 42 {
|
|
t.Errorf("ChatID = %d, want 42", updates.installedMeta.ChatID)
|
|
}
|
|
if updates.installedMeta.ReportPath != reportPath {
|
|
t.Errorf("ReportPath = %q, want %q", updates.installedMeta.ReportPath, reportPath)
|
|
}
|
|
}
|