Files
tutti/services/tuttid/integration/desktop_preferences_initialization_test.go
agent-radar 2ed3415fb7
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
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

113 lines
3.3 KiB
Go

package integration_test
import (
"net/http"
"testing"
tuttigenerated "github.com/tutti-os/tutti/services/tuttid/api/generated"
)
const standaloneAgentModeFeatureFlag = "workspace.standaloneAgentMode"
func TestDesktopPreferencesInitializeIfAbsentAppliesDaemonFreshModeDefault(t *testing.T) {
testCases := []struct {
featureFlags tuttigenerated.DesktopFeatureFlags
name string
}{
{name: "missing mode flag", featureFlags: tuttigenerated.DesktopFeatureFlags{}},
{name: "explicit false mode flag", featureFlags: tuttigenerated.DesktopFeatureFlags{standaloneAgentModeFeatureFlag: false}},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
daemon := startTestDaemon(t)
initial := mustRequestJSON[tuttigenerated.DesktopPreferencesStateResponse](
t,
daemon,
http.MethodGet,
"/v1/preferences/desktop",
nil,
http.StatusOK,
)
if initial.Initialized {
t.Fatal("initial desktop preferences initialized = true, want false")
}
initial.Preferences.FeatureFlags = testCase.featureFlags
writeMode := tuttigenerated.DesktopPreferencesWriteModeInitializeIfAbsent
initialized := mustRequestJSON[tuttigenerated.DesktopPreferencesStateResponse](
t,
daemon,
http.MethodPut,
"/v1/preferences/desktop",
tuttigenerated.PutDesktopPreferencesRequest{
Preferences: initial.Preferences,
WriteMode: &writeMode,
},
http.StatusOK,
)
if !initialized.Initialized {
t.Fatal("initialized desktop preferences initialized = false, want true")
}
if !initialized.Preferences.FeatureFlags[standaloneAgentModeFeatureFlag] {
t.Fatalf("initialized feature flags = %#v, want Agent mode", initialized.Preferences.FeatureFlags)
}
stored := mustRequestJSON[tuttigenerated.DesktopPreferencesStateResponse](
t,
daemon,
http.MethodGet,
"/v1/preferences/desktop",
nil,
http.StatusOK,
)
if !stored.Preferences.FeatureFlags[standaloneAgentModeFeatureFlag] {
t.Fatalf("stored feature flags = %#v, want Agent mode", stored.Preferences.FeatureFlags)
}
})
}
}
func TestDesktopPreferencesInitializeIfAbsentPreservesExistingOSMode(t *testing.T) {
daemon := startTestDaemon(t)
initial := mustRequestJSON[tuttigenerated.DesktopPreferencesStateResponse](
t,
daemon,
http.MethodGet,
"/v1/preferences/desktop",
nil,
http.StatusOK,
)
initial.Preferences.FeatureFlags = tuttigenerated.DesktopFeatureFlags{
standaloneAgentModeFeatureFlag: false,
}
mustRequestJSON[tuttigenerated.DesktopPreferencesStateResponse](
t,
daemon,
http.MethodPut,
"/v1/preferences/desktop",
tuttigenerated.PutDesktopPreferencesRequest{Preferences: initial.Preferences},
http.StatusOK,
)
candidate := initial.Preferences
candidate.FeatureFlags = tuttigenerated.DesktopFeatureFlags{
standaloneAgentModeFeatureFlag: true,
}
writeMode := tuttigenerated.DesktopPreferencesWriteModeInitializeIfAbsent
stored := mustRequestJSON[tuttigenerated.DesktopPreferencesStateResponse](
t,
daemon,
http.MethodPut,
"/v1/preferences/desktop",
tuttigenerated.PutDesktopPreferencesRequest{
Preferences: candidate,
WriteMode: &writeMode,
},
http.StatusOK,
)
if stored.Preferences.FeatureFlags[standaloneAgentModeFeatureFlag] {
t.Fatalf("stored feature flags = %#v, want existing OS mode", stored.Preferences.FeatureFlags)
}
}