Compare commits

..
Author SHA1 Message Date
Vasanthdev2004 e871fde39d test(config,tui): stop two tests reading the developer's environment and checkout path
`go test ./...` is red on a developer machine and green in CI, for two tests
that take an input from the machine rather than from the test.

TestResolveReportsExplicitMaxTurns left ResolveOptions.Env nil on four of its
five cases, and a nil Env means "read the real process environment" (envValue).
Any one of the ten variables the resolver reads is enough to break it. With
ANTHROPIC_BASE_URL exported, applyProviderEnv synthesizes a second, keyless
"anthropic" profile from a base URL on its own, the single-provider shortcut in
normalizeProviders no longer applies because there are now two, and Resolve
returns `no active provider configured: active provider "" not found` before the
test reaches its assertion. Measured one variable at a time against a clean
environment, all ten fail the same test: ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY,
ANTHROPIC_MODEL, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL, GEMINI_API_KEY,
GOOGLE_API_KEY, ZERO_PROVIDER and ZERO_MAX_TURNS.

The cases now state an empty environment instead of no environment, which is
what they meant, and the test exports three hostile values itself so it proves
that rather than relying on the machine it runs on being clean. Reverting either
changed case fails the test on a clean environment too, so this cannot regress
silently on CI.

TestAltScreenTranscriptScrollKeepsFooterFixed asserted the branch survives in
the title bar at width 90 while leaving Options.Cwd empty, so newModel took the
real working directory. The outcome is not a monotonic function of that path's
length, which is why this took a measurement rather than a guess. The title bar
picks the widest candidate that fits: workspace carries branch and path, cwdOnly
carries the path alone, compactLeft carries the branch alone. At width 90 with
this branch, a cwd of up to 52 bytes keeps both, 53 to 74 falls to path-only and
drops the branch, and 75 or more falls again to branch-only and restores it. The
test failed from a checkout whose package path is 74 bytes and passed from one
at 80; CI sits at 40. Cwd is now pinned, which also stops newModel reading the
real repository for a branch the test overwrites anyway.

No production code changes. The resolver's nil-Env contract and the header's
candidate ladder are both deliberate; only the tests were leaning on them.
2026-09-24 09:44:35 +05:30
Anandan 99721c762f fix(providers): send stable session headers to OpenCode (#1060) 2026-09-16 07:58:40 +08:00
2 changed files with 37 additions and 2 deletions

No files matched your search

+20 -1
View File
@@ -2254,6 +2254,19 @@ func TestResolveRejectsInvalidCrossSessionInbound(t *testing.T) {
}
func TestResolveReportsExplicitMaxTurns(t *testing.T) {
// A nil ResolveOptions.Env means "read the real process environment" (see
// envValue), so a case that leaves it nil inherits whatever the developer
// happens to export. ANTHROPIC_BASE_URL alone is enough: applyProviderEnv
// synthesizes a second, keyless "anthropic" profile from a base URL on its
// own, the single-provider shortcut in normalizeProviders stops applying,
// and Resolve fails with `active provider "" not found` before this test
// reaches its assertion. Every variable the resolver reads does it, so the
// cases below state an EMPTY environment rather than no environment, and
// these three are set to a hostile value so the test proves it.
t.Setenv("ANTHROPIC_BASE_URL", "https://proxy.example/v1")
t.Setenv("OPENAI_API_KEY", "from-the-developer-shell")
t.Setenv(MaxTurnsEnv, "7")
const providerJSON = `{
"activeProvider": "p",
"providers": [{"name": "p", "provider_kind": "openai-compatible", "base_url": "https://x.example/v1", "apiKey": "k", "model": "m"}]
@@ -2266,10 +2279,15 @@ func TestResolveReportsExplicitMaxTurns(t *testing.T) {
set bool
}{
{"built-in default only", ResolveOptions{
Env: map[string]string{},
Overrides: Overrides{Provider: ProviderProfile{Name: "p", ProviderKind: "openai-compatible", BaseURL: "https://x.example/v1", APIKey: "k", Model: "m"}},
}, false},
{"user config", ResolveOptions{UserConfigPath: writeConfig(t, providerWithTurns)}, true},
{"user config", ResolveOptions{
Env: map[string]string{},
UserConfigPath: writeConfig(t, providerWithTurns),
}, true},
{"project config", ResolveOptions{
Env: map[string]string{},
UserConfigPath: writeConfig(t, providerJSON),
ProjectConfigPath: writeConfig(t, `{"maxTurns": 40}`),
}, true},
@@ -2278,6 +2296,7 @@ func TestResolveReportsExplicitMaxTurns(t *testing.T) {
Overrides: Overrides{Provider: ProviderProfile{Name: "p", ProviderKind: "openai-compatible", BaseURL: "https://x.example/v1", APIKey: "k", Model: "m"}},
}, true},
{"cli override", ResolveOptions{
Env: map[string]string{},
Overrides: Overrides{
MaxTurns: 42,
Provider: ProviderProfile{Name: "p", ProviderKind: "openai-compatible", BaseURL: "https://x.example/v1", APIKey: "k", Model: "m"},
+17 -1
View File
@@ -2,6 +2,7 @@ package tui
import (
"context"
"path/filepath"
"strings"
"testing"
@@ -112,7 +113,22 @@ func TestMouseWheelOnClippedFooterStatusDoesNotMoveComposerCursor(t *testing.T)
}
func TestAltScreenTranscriptScrollKeepsFooterFixed(t *testing.T) {
m := newModel(context.Background(), Options{AltScreen: true, ProviderName: "openai", ModelName: "gpt-4.1"})
// Cwd is pinned because an empty Options.Cwd makes newModel take the real
// working directory, which at test time is this package inside whoever's
// checkout, and the branch assertion below is not a monotonic function of
// that path's length. The title bar picks the widest candidate that fits:
// workspace carries branch AND path, cwdOnly carries only the path, and
// compactLeft carries only the branch. At width 90 with this branch, a cwd
// of up to 52 bytes keeps branch and path, 53 to 74 falls to path-only and
// loses the branch, and 75 or more falls again to branch-only and gets it
// back. So this failed from a checkout 74 bytes deep and passed from one 80
// bytes deep, while CI sits at 40 and never sees it.
m := newModel(context.Background(), Options{
AltScreen: true,
ProviderName: "openai",
ModelName: "gpt-4.1",
Cwd: filepath.Join(string(filepath.Separator), "workspace", "zero"),
})
m.width = 90
m.height = 10
m.gitBranch = "feat/pinned-header"