Files
archie/internal/container/logs_test.go
T
sam acec5d392d feat(archied): read-only run-scoped sandbox view over the harness contract (#1662)
* feat(archied): read-only run-scoped sandbox view over the harness contract

Serve RunTarget: the daemon resolves a running task and attempt to its Kit
container and follows its output, refusing a finished or unknown task with a
stated reason. The dashboard adds a Sandbox tab behind the task log's read
authority. Takeover stays out of scope until the sod1 authority is wired.

* fix(archied): scope and close sandbox views correctly

Forward harness activity into container output, bind containers and dashboard views to their attempt, enforce the asserted org, and report unavailable dependencies and interrupted streams accurately.

Refs: archie-core-qi91, archie-core-252tj
2026-10-14 02:57:32 +11:00

55 lines
1.3 KiB
Go

package container
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/moby/moby/client"
)
func TestFollowLogsCloseQuietStream(t *testing.T) {
closed := make(chan struct{})
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case strings.HasSuffix(r.URL.Path, "/json"):
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"Id":"running-container","State":{"Running":true}}`))
case strings.HasSuffix(r.URL.Path, "/logs"):
w.WriteHeader(http.StatusOK)
if err := http.NewResponseController(w).Flush(); err != nil {
t.Error(err)
return
}
<-r.Context().Done()
close(closed)
default:
http.NotFound(w, r)
}
}))
defer server.Close()
cli, err := client.New(client.WithHost(server.URL), client.WithAPIVersion("1.54"))
if err != nil {
t.Fatal(err)
}
defer cli.Close()
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
stream, err := FollowLogs(ctx, cli, "task-attempt", 200)
if err != nil {
t.Fatal(err)
}
defer stream.Close()
if err := stream.Close(); err != nil {
t.Fatal(err)
}
select {
case <-closed:
case <-time.After(time.Second):
t.Fatal("closing the reader retained the quiet Docker log stream")
}
}