mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
Keep launcher locale changes from mutating shared web-search routing (#2573)
The launcher wired UI language changes into a process-global backend switch that changed auto web-search provider selection and the reported current service for every handler in the same process. This narrows the fix to the validated leak: remove backend sync from frontend locale changes, drop the now-unused UI endpoint, and make auto selection fall back to a stable default when the query itself does not contain a script hint. Constraint: Keep the patch small and mergeable without redesigning per-user preference storage Rejected: Add per-user backend language state | larger scope than the validated bug and unclear maintainer preference Rejected: Persist preferred language in config | still shares mutable state across clients of the same instance Confidence: high Scope-risk: narrow Reversibility: clean Directive: If locale-aware provider routing is reintroduced later, scope it to explicit config or request context instead of package-global state Tested: go test ./web/backend/api ./pkg/tools -count=1; pnpm lint; pnpm build Not-tested: Full make check; live multi-browser manual launcher run after the backend endpoint removal
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/config"
|
||||
picotools "github.com/sipeed/picoclaw/pkg/tools"
|
||||
)
|
||||
|
||||
func TestHandleListTools(t *testing.T) {
|
||||
@@ -517,22 +516,12 @@ func TestResolveCurrentWebSearchProvider_FallsBackWhenProviderIsUnknown(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveCurrentWebSearchProvider_UsesPreferredLanguageForSogouAndDuckDuckGo(t *testing.T) {
|
||||
func TestResolveCurrentWebSearchProvider_PrefersStableDefaultForSogouAndDuckDuckGo(t *testing.T) {
|
||||
cfg := config.DefaultConfig()
|
||||
cfg.Tools.Web.Provider = "auto"
|
||||
cfg.Tools.Web.Sogou.Enabled = true
|
||||
cfg.Tools.Web.DuckDuckGo.Enabled = true
|
||||
|
||||
picotools.SetPreferredWebSearchLanguage("en")
|
||||
t.Cleanup(func() {
|
||||
picotools.SetPreferredWebSearchLanguage("")
|
||||
})
|
||||
|
||||
if got := resolveCurrentWebSearchProvider(cfg); got != "duckduckgo" {
|
||||
t.Fatalf("resolveCurrentWebSearchProvider() = %q, want duckduckgo", got)
|
||||
}
|
||||
|
||||
picotools.SetPreferredWebSearchLanguage("zh")
|
||||
if got := resolveCurrentWebSearchProvider(cfg); got != "sogou" {
|
||||
t.Fatalf("resolveCurrentWebSearchProvider() = %q, want sogou", got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user