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
75 lines
2.8 KiB
Go
75 lines
2.8 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"testing"
|
|
|
|
agentmaintenance "github.com/tutti-os/tutti/services/tuttid/service/agentmaintenance"
|
|
)
|
|
|
|
type stubAgentMaintenanceService struct {
|
|
result agentmaintenance.PurgeResult
|
|
err error
|
|
purgeWorkspaceFn func(context.Context, string) (agentmaintenance.PurgeResult, error)
|
|
purgeSessionFn func(context.Context, string, string) (agentmaintenance.PurgeResult, error)
|
|
}
|
|
|
|
func (s stubAgentMaintenanceService) PurgeNow(context.Context) (agentmaintenance.PurgeResult, error) {
|
|
return s.result, s.err
|
|
}
|
|
|
|
func (s stubAgentMaintenanceService) PurgeWorkspace(ctx context.Context, workspaceID string) (agentmaintenance.PurgeResult, error) {
|
|
if s.purgeWorkspaceFn != nil {
|
|
return s.purgeWorkspaceFn(ctx, workspaceID)
|
|
}
|
|
return s.result, s.err
|
|
}
|
|
|
|
func (s stubAgentMaintenanceService) PurgeSession(ctx context.Context, workspaceID string, agentSessionID string) (agentmaintenance.PurgeResult, error) {
|
|
if s.purgeSessionFn != nil {
|
|
return s.purgeSessionFn(ctx, workspaceID, agentSessionID)
|
|
}
|
|
return s.result, s.err
|
|
}
|
|
|
|
func TestDaemonAPIPurgeDeletedAgentConversations(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
RegisterRoutes(mux, NewRoutes(DaemonAPI{AgentMaintenanceService: stubAgentMaintenanceService{result: agentmaintenance.PurgeResult{
|
|
RemovedSessions: 2,
|
|
RemovedMessages: 5,
|
|
PayloadBytes: 128,
|
|
}}}))
|
|
recorder := performGeneratedRouteRequest(t, mux, http.MethodPost, "/v1/agent-maintenance/deleted-conversations/purge", nil)
|
|
if recorder.Code != http.StatusOK {
|
|
t.Fatalf("status = %d; body: %s", recorder.Code, recorder.Body.String())
|
|
}
|
|
var response struct {
|
|
RemovedSessions int `json:"removedSessions"`
|
|
RemovedMessages int `json:"removedMessages"`
|
|
}
|
|
decodeGeneratedRouteResponse(t, recorder, &response)
|
|
if response.RemovedSessions != 2 || response.RemovedMessages != 5 {
|
|
t.Fatalf("response = %#v", response)
|
|
}
|
|
}
|
|
|
|
func TestDaemonAPIPurgeDeletedAgentConversationsMapsBusy(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
RegisterRoutes(mux, NewRoutes(DaemonAPI{AgentMaintenanceService: stubAgentMaintenanceService{err: agentmaintenance.ErrBusy}}))
|
|
recorder := performGeneratedRouteRequest(t, mux, http.MethodPost, "/v1/agent-maintenance/deleted-conversations/purge", nil)
|
|
if recorder.Code != http.StatusServiceUnavailable {
|
|
t.Fatalf("busy status = %d; body: %s", recorder.Code, recorder.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestDaemonAPIPurgeDeletedAgentConversationsMapsFailure(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
RegisterRoutes(mux, NewRoutes(DaemonAPI{AgentMaintenanceService: stubAgentMaintenanceService{err: errors.New("storage failed")}}))
|
|
recorder := performGeneratedRouteRequest(t, mux, http.MethodPost, "/v1/agent-maintenance/deleted-conversations/purge", nil)
|
|
if recorder.Code != http.StatusBadGateway {
|
|
t.Fatalf("failure status = %d; body: %s", recorder.Code, recorder.Body.String())
|
|
}
|
|
}
|