profilefixture

package
v1.9.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package profilefixture builds the controlled environment that profile-resolution parity tests require: a known AGENTDECK_PROFILE, CLAUDE_CONFIG_DIR, agent-deck config-dir override, and isolated tempdir.

It implements the harness from TEST-PLAN.md §6.3 and TUI-TEST-PLAN.md §6.7 (profileFixture). The five-way probe and AssertParity are transport-agnostic — callers pass closures that exercise CLI, web /api/settings, web /api/profiles, /healthz, and a TUI snapshot.

Usage:

f := profilefixture.New(t, profilefixture.Options{EnvProfile: "work"})
f.AssertParity(t, profilefixture.Probes{
    CLI:        func() string { return cliJSON("list").Profile },
    WebAPI:     func() string { return getJSON("/api/settings").Profile },
    WebProfile: func() string { return getJSON("/api/profiles").Current },
    Healthz:    func() string { return getJSON("/healthz").Profile },
    TUI:        func() string { return tuiSnapshot.Profile },
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fixture

type Fixture struct {
	Home string // resolved HOME (the scratch dir)
	Opts Options
}

Fixture is the active test scaffold. Cleanup is registered via t.Cleanup automatically.

func New

func New(t *testing.T, opts Options) *Fixture

New seeds env vars and on-disk state, returning a Fixture. All originals are restored by t.Cleanup.

func (*Fixture) AssertParity

func (f *Fixture) AssertParity(t TB, p Probes)

AssertParity runs Probe and fails the test if any two probes return different values. The failure message lists every probe so the diagnosis is one glance.

func (*Fixture) Probe

func (f *Fixture) Probe(p Probes) map[string]string

Probe runs every non-nil probe and returns a {name -> reported profile} map. The map is also useful for diagnostic dumps.

type Options

type Options struct {
	// EnvProfile, if non-empty, sets AGENTDECK_PROFILE. Highest precedence
	// in session.GetEffectiveProfile.
	EnvProfile string

	// ClaudeConfigDir, if non-empty, sets CLAUDE_CONFIG_DIR. Used to
	// exercise the "infer profile from claude config dir" branch.
	ClaudeConfigDir string

	// ConfigDefault, if non-empty, writes a config file at
	// <Home>/.agent-deck/config.json with `default_profile` set to this
	// value. Lowest precedence — only matters when env / inference are
	// both empty.
	ConfigDefault string

	// AgentDeckHome overrides the agent-deck config root via HOME. If
	// empty, a fresh t.TempDir() is used so the test never touches the
	// developer's real ~/.agent-deck.
	AgentDeckHome string
}

Options controls how the fixture seeds the environment.

type Probes

type Probes struct {
	CLI        func() string // `agent-deck list --json | .profile`
	WebAPI     func() string // `GET /api/settings | .profile`
	WebProfile func() string // `GET /api/profiles | .current`
	Healthz    func() string // `GET /healthz | .profile`
	TUI        func() string // tuitest snapshot's profile field
}

Probes is the five-way probe suite from §6.7. Each field is a thunk that returns the profile string the relevant surface reports. Tests pass concrete closures bound to live CLI / HTTP clients / TUI models.

Any field left nil is skipped during AssertParity (so a unit test can exercise a subset of surfaces).

type TB

type TB interface {
	Errorf(format string, args ...any)
	Helper()
}

TB is the subset of testing.TB used by Assert helpers. We avoid pulling in *testing.T so the package can be exercised under stub Ts in its own unit tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL