WIP: preserve background task output API
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -425,6 +426,30 @@ func TestChatShellReadbackSeedsReplacementStream(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatShellOutputVerifiesOwnerAndBoundsPage(t *testing.T) {
|
||||
var outputPath string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.URL.Path {
|
||||
case "/api/shell/sh_1":
|
||||
_, _ = w.Write([]byte(`{"data":{"id":"sh_1","status":"exited","command":"job","metadata":{"sessionID":"ses_1"}}}`))
|
||||
case "/api/shell/sh_1/output":
|
||||
outputPath = r.URL.RawQuery
|
||||
_, _ = w.Write([]byte(`{"data":{"output":"marker","cursor":6,"size":6,"truncated":false}}`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
page, err := NewChat(&Connection{Backend: "v2", URL: srv.URL}).ShellOutput(context.Background(), protocol.ChatShellOutputQuery{SessionID: "ses_1", ShellID: "sh_1", Limit: 64 << 10})
|
||||
if err != nil || page.Output != "marker" || page.Shell.Status != protocol.ChatShellExited {
|
||||
t.Fatalf("ShellOutput = %+v, %v", page, err)
|
||||
}
|
||||
if !strings.Contains(outputPath, "cursor=0") || !strings.Contains(outputPath, "limit=65536") {
|
||||
t.Fatalf("output query = %q", outputPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatReleaseShellsBoundsDisconnectedState(t *testing.T) {
|
||||
chat := NewChat(&Connection{})
|
||||
state := chat.streamState("ses_1")
|
||||
|
||||
Reference in New Issue
Block a user