WIP: preserve remaining background task output work
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
func main() {
|
||||
addr := flag.String("addr", "127.0.0.1:0", "Pipelines scratch listen address")
|
||||
scratch := flag.String("scratch-dir", "", "required scratch directory for the database and workspace")
|
||||
exited := flag.Bool("shell-exited", false, "serve the selected fixture shell as observed exited")
|
||||
flag.Parse()
|
||||
if *scratch == "" {
|
||||
fatal(fmt.Errorf("-scratch-dir is required"))
|
||||
@@ -46,7 +47,7 @@ func main() {
|
||||
}
|
||||
defer upstream.Close()
|
||||
upstreamURL := "http://" + upstream.Addr().String()
|
||||
upstreamServer := &http.Server{Handler: server.LargeChatFixtureHandler(workspace), ReadHeaderTimeout: 5 * time.Second}
|
||||
upstreamServer := &http.Server{Handler: server.LargeChatFixtureHandlerWithShell(workspace, *exited), ReadHeaderTimeout: 5 * time.Second}
|
||||
go func() { _ = upstreamServer.Serve(upstream) }()
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
@@ -76,6 +77,9 @@ func main() {
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
if err := verifyShellReadback(ctx, endpoint, *exited); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
info := buildinfo.Current()
|
||||
_ = json.NewEncoder(os.Stdout).Encode(map[string]any{
|
||||
"endpoint": endpoint, "upstream_endpoint": upstreamURL, "backend": attached.Connection.Backend,
|
||||
@@ -89,6 +93,35 @@ func main() {
|
||||
_ = upstreamServer.Shutdown(shutdown)
|
||||
}
|
||||
|
||||
func verifyShellReadback(ctx context.Context, endpoint string, exited bool) error {
|
||||
ws, _, err := websocket.Dial(ctx, "ws"+strings.TrimPrefix(endpoint, "http")+"/connect", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ws.Close(websocket.StatusNormalClosure, "fixture complete")
|
||||
if err := wsjson.Write(ctx, ws, protocol.Message{Type: protocol.ChatShells, ID: "fixture-shells", ChatQuery: &protocol.ChatQuery{SessionID: server.LargeChatFixtureSessionID}}); err != nil {
|
||||
return err
|
||||
}
|
||||
var listed protocol.Message
|
||||
if listed, err = readFixtureResponse(ctx, ws, protocol.ChatShells); err != nil {
|
||||
return err
|
||||
}
|
||||
if !exited && (len(listed.ChatShells) != 1 || listed.ChatShells[0].ID != server.LargeChatFixtureShellID) {
|
||||
return fmt.Errorf("fixture shell is not listed")
|
||||
}
|
||||
if err := wsjson.Write(ctx, ws, protocol.Message{Type: protocol.ChatShellOutput, ID: "fixture-output", ChatShellOutputQuery: &protocol.ChatShellOutputQuery{SessionID: server.LargeChatFixtureSessionID, ShellID: server.LargeChatFixtureShellID, Limit: 64 << 10}}); err != nil {
|
||||
return err
|
||||
}
|
||||
page, err := readFixtureResponse(ctx, ws, protocol.ChatShellOutput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if page.ChatShellOutput == nil || page.ChatShellOutput.Output != server.LargeChatFixtureShellOutput || page.ChatShellOutput.Shell.Status != map[bool]string{true: "exited", false: "running"}[exited] {
|
||||
return fmt.Errorf("unexpected shell readback: %+v", page.ChatShellOutput)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifyBroker(ctx context.Context, endpoint string) ([2]map[string]any, error) {
|
||||
var readbacks [2]map[string]any
|
||||
cursor := ""
|
||||
|
||||
Reference in New Issue
Block a user