Files
goclaw/internal/store/provider_store_test.go
Bruno ClermontandBruno Clermont 8000a1d0f5 feat(providers): add provider-level thinking/reasoning toggle for Ollama (#1355)
Ollama has two separate request-building code paths: OllamaProvider
(native /api/chat, used for num_ctx control) and OpenAIProvider
(OpenAI-compat /v1/chat/completions). An earlier fix disabled thinking
mode by hardcoding think=false, but only in the OpenAI-compat path --
OllamaProvider.buildRequest() never set the think field at all, so
reasoning-capable models (qwq, deepseek-r1) defaulted to visible
chain-of-thought reasoning regardless of that fix. Confirmed live via
a docker-engineer agent streaming full reasoning traces despite the
existing disable.

Replaced the hardcoded always-off behavior with a provider-level
tri-state setting (llm_providers.settings.thinking_enabled: unset =
default off, explicit true/false overrides), configurable via the
provider's Advanced settings dialog. Both OllamaProvider.buildRequest()
and OpenAIProvider.buildRequestBody() now read and respect this same
setting, so the toggle works regardless of which Ollama code path a
given deployment routes through.

Added tests for setting parsing (unset/true/false/malformed) and both
provider request-builders' handling of the override.

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
2026-07-05 02:57:18 +07:00

69 lines
1.3 KiB
Go

package store
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseThinkingEnabled(t *testing.T) {
trueVal := true
falseVal := false
tests := []struct {
name string
settings json.RawMessage
want *bool
}{
{
name: "unset settings",
settings: nil,
want: nil,
},
{
name: "empty object",
settings: json.RawMessage(`{}`),
want: nil,
},
{
name: "explicit true",
settings: json.RawMessage(`{"thinking_enabled":true}`),
want: &trueVal,
},
{
name: "explicit false",
settings: json.RawMessage(`{"thinking_enabled":false}`),
want: &falseVal,
},
{
name: "coexists with other settings keys",
settings: json.RawMessage(`{"num_ctx":8192,"thinking_enabled":true}`),
want: &trueVal,
},
{
name: "malformed json",
settings: json.RawMessage(`{not valid json`),
want: nil,
},
{
name: "wrong type is ignored",
settings: json.RawMessage(`{"thinking_enabled":"yes"}`),
want: nil,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := ParseThinkingEnabled(tc.settings)
if tc.want == nil {
assert.Nil(t, got)
return
}
require.NotNil(t, got)
assert.Equal(t, *tc.want, *got)
})
}
}