Make SCUM logs live relay only

This commit is contained in:
npc0-hue
2026-09-01 14:26:00 +08:00
parent 3f348401a9
commit 7d9c1b7e9e
28 changed files with 1011 additions and 175 deletions
@@ -1,7 +1,10 @@
package api
import (
"bufio"
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
@@ -38,6 +41,13 @@ func (core *gameClientBridgeCompanionCore) UploadGameClientBridgeSnapshot(domain
return domain.CopyGameClientBridgeSnapshot(core.snapshot), nil
}
func (core *gameClientBridgeCompanionCore) AuthorizeGameClientBridgeLogStream(request domain.GameClientBridgeLogStreamRequest) (domain.ServerInstance, error) {
if strings.TrimSpace(request.SessionToken) != "component-token" {
return domain.ServerInstance{}, service.ErrUnauthorized
}
return core.Core.GetServerInstance("server-1")
}
func TestGameClientBridgeOperatorRoutes(t *testing.T) {
store := repo.NewMemoryStore()
coreService := service.NewCoreService(store)
@@ -149,3 +159,40 @@ func TestGameClientBridgeCompanionRoutesAreComponentSessionMediated(t *testing.T
diagnostic := performJSON(t, router, http.MethodPost, "/api/v1/game-client-bridge/companion/diagnostics", snapshotRequest)
assertStatus(t, diagnostic, http.StatusAccepted)
}
func TestGameClientBridgeCompanionLogEventsRelaysCurrentRunOutput(t *testing.T) {
coreService := service.NewCoreService(repo.NewMemoryStore())
if err := coreService.SeedLocalPlatformAdmin(); err != nil {
t.Fatal(err)
}
core := &gameClientBridgeCompanionCore{Core: coreService}
router := NewTestRouterWithCore(core)
hello := createLogIngestAPIFixtures(t, router)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
request := httptest.NewRequest(http.MethodPost, "/api/v1/game-client-bridge/companion/logs/events", strings.NewReader("{\"sessionToken\":\"component-token\"}")).WithContext(ctx)
request.Header.Set("Content-Type", "application/json")
streamWriter, streamReader := newSSEPipeResponseWriter()
done := make(chan struct{})
go func() {
router.ServeHTTP(streamWriter, request)
_ = streamWriter.Close()
close(done)
}()
t.Cleanup(func() {
cancel()
_ = streamReader.Close()
<-done
})
if status := <-streamWriter.status; status != http.StatusOK {
t.Fatalf("unexpected companion SSE status: %d", status)
}
reader := bufio.NewReader(streamReader)
assertSSEEvent(t, reader, "session", "\"logSessionId\":\"session-current\"")
assertSSEEvent(t, reader, "stream", "\"id\":\"log-1\"")
assertSSEEvent(t, reader, "ready", "\"streamCount\":1")
live := validLogBatchRequest(t, hello.SessionToken, 5, 5)
assertStatus(t, performJSON(t, router, http.MethodPost, "/api/v1/run/logs/relay", live), http.StatusOK)
assertSSEEvent(t, reader, "log", "\"seq\":5")
}