Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
100 lines
2.9 KiB
Go
100 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
|
|
tuttigenerated "github.com/tutti-os/tutti/services/tuttid/api/generated"
|
|
"github.com/tutti-os/tutti/services/tuttid/apierrors"
|
|
workspacebiz "github.com/tutti-os/tutti/services/tuttid/biz/workspace"
|
|
workspaceservice "github.com/tutti-os/tutti/services/tuttid/service/workspace"
|
|
)
|
|
|
|
func TestDaemonAPIGeneratedRoutesReplaceWorkspaceAppIconReturnServiceUnavailable(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
RegisterRoutes(mux, NewRoutes(DaemonAPI{}))
|
|
|
|
recorder := performGeneratedRouteRequest(
|
|
t,
|
|
mux,
|
|
http.MethodPost,
|
|
"/v1/workspaces/ws-1/apps/app-1/icon",
|
|
map[string]any{"sourcePath": "/tmp/icon.png"},
|
|
)
|
|
if recorder.Code != http.StatusServiceUnavailable {
|
|
t.Fatalf("status = %d, want %d; body: %s", recorder.Code, http.StatusServiceUnavailable, recorder.Body.String())
|
|
}
|
|
|
|
assertGeneratedRouteError(
|
|
t,
|
|
recorder,
|
|
tuttigenerated.ServiceUnavailable,
|
|
apierrors.ReasonWorkspaceAppUnavailable,
|
|
"workspace app service is unavailable",
|
|
)
|
|
}
|
|
|
|
func TestDaemonAPIGeneratedRoutesLaunchWorkspaceApp(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
RegisterRoutes(mux, NewRoutes(DaemonAPI{
|
|
AppCenterService: stubAppCenterService{
|
|
launchFn: func(_ context.Context, workspaceID string, appID string) (workspacebiz.WorkspaceApp, error) {
|
|
if workspaceID != "ws-1" {
|
|
t.Fatalf("workspaceID = %q, want ws-1", workspaceID)
|
|
}
|
|
if appID != "app-1" {
|
|
t.Fatalf("appID = %q, want app-1", appID)
|
|
}
|
|
return workspaceAppForRouteTest(appID, workspacebiz.AppRuntimeStatusRunning), nil
|
|
},
|
|
},
|
|
}))
|
|
|
|
recorder := performGeneratedRouteRequest(
|
|
t,
|
|
mux,
|
|
http.MethodPost,
|
|
"/v1/workspaces/ws-1/apps/app-1/launch",
|
|
nil,
|
|
)
|
|
if recorder.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want %d; body: %s", recorder.Code, http.StatusOK, recorder.Body.String())
|
|
}
|
|
|
|
var response tuttigenerated.WorkspaceAppResponse
|
|
decodeGeneratedRouteResponse(t, recorder, &response)
|
|
if response.App.AppId != "app-1" || response.App.Status != tuttigenerated.WorkspaceAppRuntimeStatusRunning {
|
|
t.Fatalf("response app = %#v", response.App)
|
|
}
|
|
}
|
|
|
|
func TestDaemonAPIGeneratedRoutesRetryWorkspaceAppMapsInvalidRuntimeState(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
RegisterRoutes(mux, NewRoutes(DaemonAPI{
|
|
AppCenterService: stubAppCenterService{
|
|
retryFn: func(context.Context, string, string) (workspacebiz.WorkspaceApp, error) {
|
|
return workspacebiz.WorkspaceApp{}, workspaceservice.ErrInvalidWorkspaceAppRuntimeState
|
|
},
|
|
},
|
|
}))
|
|
|
|
recorder := performGeneratedRouteRequest(
|
|
t,
|
|
mux,
|
|
http.MethodPost,
|
|
"/v1/workspaces/ws-1/apps/app-1/retry",
|
|
nil,
|
|
)
|
|
if recorder.Code != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want %d; body: %s", recorder.Code, http.StatusBadRequest, recorder.Body.String())
|
|
}
|
|
assertGeneratedRouteError(
|
|
t,
|
|
recorder,
|
|
tuttigenerated.InvalidRequest,
|
|
apierrors.ReasonMalformedRequest,
|
|
workspaceservice.ErrInvalidWorkspaceAppRuntimeState.Error(),
|
|
)
|
|
}
|