# fix(trail): repair test build after auth-fallback demolition

`708725e`→[main](/content/gh/entireio/cli/commits/main/index.html)·Soph·1mo ago·1 file·+26 added/-18 removed

trail_cmd_test.go referenced auth test helpers (newAuthMemStore, newResolveTestManager, auth.SetManagerForTest, auth.DiscoveryUnavailableForTest) that were deleted in #1410 (COR-393, "demolish auth fallbacks", commit 10aa97eec). The trail PR that added these tests (#... merged separately) and the demolition PR were both green in isolation, so the semantic conflict only surfaced on main once both had merged — `mise run lint` fails with typecheck errors.

Rewrite the two affected tests to use the surviving discovery seam (auth.SetResolveContextForAPIForTest) plus tokenstore.UseFileBackendForTesting, mirroring the working pattern already used by activity_cmd_test.go. Behaviour asserted is unchanged: not-logged-in still surfaces ErrNotLoggedIn + the login hint, and option validation still short-circuits before any auth resolution.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

## Changes

1

- cmd/entire/cli

- Mtrail_cmd_test.go+26/-18

```plaintext
3 unmodified lines

... 17 unmodified lines

```

```go
package cli

import (
	"bytes"
	"context"
	"errors"
	"net/http"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
	"time"

"github.com/entireio/auth-go/sts"
	"github.com/entireio/auth-go/tokens"
	"github.com/entireio/cli/cmd/entire/cli/auth"
	"github.com/entireio/cli/cmd/entire/cli/testutil"
	"github.com/entireio/cli/cmd/entire/cli/trail"
	"github.com/entireio/cli/internal/entireclient/clusterdiscovery"
	"github.com/entireio/cli/internal/entireclient/contexts"
	"github.com/entireio/cli/internal/entireclient/tokenstore"
)

const (

)

func TestRunTrailListAll_PrintsLoginHintWhenNotLoggedIn(t *testing.T) {
	// No t.Parallel: SetManagerForTest mutates package-level auth state.
	store := newAuthMemStore()
	mgr := newResolveTestManager(t, store, func(context.Context, sts.ExchangeRequest) (*tokens.TokenSet, error) {
		t.Fatal("exchange should not run when no core token is stored")
		return nil, errors.New("unreachable")
	})
	t.Cleanup(auth.SetManagerForTest(t, mgr))
	t.Cleanup(auth.SetResolveContextForAPIForTest(t, auth.DiscoveryUnavailableForTest))
	// No t.Parallel: SetResolveContextForAPIForTest mutates package-level
	// auth state.
	//
	// Discovery selects a context whose keyring slot holds nothing, so the
	// per-context provider reports ErrNotLoggedIn.
	t.Cleanup(tokenstore.UseFileBackendForTesting(filepath.Join(t.TempDir(), "tokens.json")))
	c := &contexts.Context{Name: "me@core", CoreURL: "https://core.example", Handle: "me", KeychainService: "kc:me"}
	t.Cleanup(auth.SetResolveContextForAPIForTest(t,
		func(context.Context, string, string, string, *http.Client, clusterdiscovery.DebugFunc) (*contexts.Context, error) {
			return c, nil
		}))

var out, errOut bytes.Buffer
	err := runTrailListAll(t.Context(), &out, &errOut, defaultTrailListOptions(false))
}

func TestRunTrailListAll_ValidatesOptionsBeforeAuth(t *testing.T) {
	// No t.Parallel: SetManagerForTest mutates package-level auth state.
	store := newAuthMemStore()
	mgr := newResolveTestManager(t, store, func(context.Context, sts.ExchangeRequest) (*tokens.TokenSet, error) {
		t.Fatal("exchange should not run for invalid local options")
		return nil, errors.New("unreachable")
	})
	t.Cleanup(auth.SetManagerForTest(t, mgr))
	t.Cleanup(auth.SetResolveContextForAPIForTest(t, auth.DiscoveryUnavailableForTest))
	// No t.Parallel: SetResolveContextForAPIForTest mutates package-level
	// auth state.
	//
	// Discovery must never run for invalid local options: validation has to
	// short-circuit before any auth resolution.
	t.Cleanup(auth.SetResolveContextForAPIForTest(t,
		func(context.Context, string, string, string, *http.Client, clusterdiscovery.DebugFunc) (*contexts.Context, error) {
			t.Fatal("discovery should not run for invalid local options")
			return nil, errors.New("unreachable")
		}))

opts := defaultTrailListOptions(false)
	opts.Limit = 0
}

```
