// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package app import ( "context" "log/slog" "os" "path/filepath" "testing" "git.stormux.org/storm/cthulhu/internal/config" "git.stormux.org/storm/cthulhu/internal/speech" "github.com/godbus/dbus/v5" ) type acceptingRemoteSpeechSettings struct{} func (acceptingRemoteSpeechSettings) UpdateSettings(context.Context, speech.Settings) error { return nil } func TestRemoteSettingsUseWorkerWithoutSaving(t *testing.T) { settings := config.DefaultSettings() settings.Path = filepath.Join(t.TempDir(), "settings.toml") live := &liveSettings{} live.Store(settings) worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, acceptingRemoteSpeechSettings{}) worker.live = live if err := worker.Start(context.Background()); err != nil { t.Fatal(err) } t.Cleanup(func() { worker.Stop(context.Background()) }) presenter := remoteSpeech{live: live, preferences: worker} if !presenter.RemoteSet("TypingEchoManager", "KeyEchoEnabled", dbus.MakeVariant(true)) { t.Fatal("key echo setting rejected") } value, ok := presenter.RemoteGet("TypingEchoManager", "KeyEchoEnabled") if !ok || value.Value() != true { t.Fatalf("live key echo = %v, %v", value, ok) } if !presenter.RemoteSet("SpeechManager", "PunctuationLevel", dbus.MakeVariant("none")) { t.Fatal("punctuation setting rejected") } value, ok = presenter.RemoteGet("SpeechManager", "PunctuationLevel") if !ok || value.Value() != "none" { t.Fatalf("live punctuation = %v, %v", value, ok) } if presenter.RemoteSet("SpeechManager", "PunctuationLevel", dbus.MakeVariant("invalid")) { t.Fatal("invalid punctuation accepted") } if presenter.RemoteSet("TypingEchoManager", "KeyEchoEnabled", dbus.MakeVariant("wrong type")) { t.Fatal("wrong type accepted") } if !presenter.RemoteCommand("SpeechManager", "IncreaseRate", false) { t.Fatal("rate command rejected") } value, ok = presenter.RemoteGet("SpeechManager", "Rate") if !ok || value.Value() != int32(51) { t.Fatalf("rate after command = %v, %v", value, ok) } if presenter.RemoteCommand("SpeechManager", "Unknown", false) { t.Fatal("unknown command accepted") } if _, err := os.Stat(settings.Path); !os.IsNotExist(err) { t.Fatalf("remote setter wrote settings file: %v", err) } }