doctor

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package doctor is nova-doctor's frame: a registry of checks, each one a name, the dependency it covers, a Run over an Env, and a result of ok, warn or fail with evidence and, when not ok, the one fix line. The contract is docs/SPEC-DOCTOR.md.

A check lives in its own file, check_<dependency>.go, and registers itself from an init, so a new dependency adds one file and edits nothing here. Every outside fact a check reads (a process, a file, a network address, the clock, the environment) comes through Env, so a test fakes all of them and no test starts a service or opens a socket.

Index

Constants

This section is empty.

Variables

View Source
var Default = NewRegistry()

Default is the registry the check_<dependency>.go files register into from an init.

Functions

func ExitCode

func ExitCode(results []Result, strict bool) int

ExitCode is the exit by the worst result: 2 for a fail, 1 for a warn under strict, else 0 (docs/SPEC-DOCTOR.md, "The exit").

func Main

func Main(reg *Registry, env Env, stamp string, args []string, stdin io.Reader, stdout, stderr io.Writer) int

Main runs nova-doctor over args. No arguments is refused at exit 2 with the verbs and `run: nova-doctor help` (pkg/tool's Run), never a run: a bare command is no invocation (docs/ONBOARDING.md point 1).

func Tool

func Tool(reg *Registry, env Env, stamp string) *tool.Tool

Tool is nova-doctor on the nova tool skeleton: one verb, run, which is also the default, so `nova-doctor --local` is a run. A bare `nova-doctor` is no run: it is refused naming the verbs and the door, as every tool's bare command is (docs/ONBOARDING.md point 1).

Types

type Check

type Check struct {
	Name       string
	Dependency string
	Fleet      bool
	Run        func(ctx context.Context, env Env) Result
}

Check is one dependency's check. Fleet marks a check only a fleet needs: --local skips it and says so.

type Env

type Env interface {
	Getenv(key string) string
	Now() time.Time
	ReadFile(path string) ([]byte, error)
	ReadDir(path string) ([]fs.DirEntry, error)
	Exec(ctx context.Context, name string, args ...string) (string, error)
	Dial(ctx context.Context, network, addr string) error
}

Env is everything a check may reach outside itself. Paths are the real ones in the real Env and a tree under t.TempDir() in a fake.

type OSEnv

type OSEnv struct{}

OSEnv is the real Env: the process's environment, files, clock, children and network.

func (OSEnv) Dial

func (OSEnv) Dial(ctx context.Context, network, addr string) error

func (OSEnv) Exec

func (OSEnv) Exec(ctx context.Context, name string, args ...string) (string, error)

func (OSEnv) Getenv

func (OSEnv) Getenv(k string) string

func (OSEnv) Now

func (OSEnv) Now() time.Time

func (OSEnv) ReadDir

func (OSEnv) ReadDir(p string) ([]fs.DirEntry, error)

func (OSEnv) ReadFile

func (OSEnv) ReadFile(p string) ([]byte, error)

type Options

type Options struct {
	Only  []string // check names; empty is every check
	Local bool     // skip the checks only a fleet needs
}

Options select which checks run.

type ProviderProbe

type ProviderProbe interface {
	// Models asks the provider for its models list with key, a call that costs nothing.
	// errNoModels says the provider has no endpoint the probe knows.
	Models(ctx context.Context, provider, key string) error
	// Funds is the dollars the provider reports left, and whether it reports any; a
	// provider that reports none is not judged on its funds.
	Funds(ctx context.Context, provider, key string) (dollars float64, known bool, err error)
}

ProviderProbe is the outside call the providers check makes: the provider's no-cost models list and the funds it reports. Env may carry one (a test's fake); otherwise the check builds the real HTTP probe, so no test opens a socket.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is the set of checks. Default is the one the checks register into.

func NewRegistry

func NewRegistry() *Registry

NewRegistry is an empty registry.

func (*Registry) Names

func (r *Registry) Names() []string

Names are the registered check names, sorted.

func (*Registry) Register

func (r *Registry) Register(c Check)

Register adds a check; an unnamed check, one with no Run, or a name taken is a programming error and panics at init, never at a stranger's run.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, env Env, o Options) (results []Result, skipped []string, err error)

Run runs the selected checks in name order and returns their results and the names --local skipped. A name that is no check is an error naming the ones there are.

type Result

type Result struct {
	Check      string `json:"check"`
	Dependency string `json:"dependency"`
	Status     Status `json:"status"`
	Evidence   string `json:"evidence"`
	Fix        string `json:"fix,omitempty"`
}

Result is what one check found. Fix is required when Status is not OK: a nova verb when one exists, never a hand script.

func (Result) Line

func (r Result) Line() string

Line is one result as printed: `DOCTOR <check> ok|warn|fail <evidence> [fix: <line>]`.

type Status

type Status string

Status is one check's verdict.

const (
	OK   Status = "ok"
	Warn Status = "warn"
	Fail Status = "fail"
)

Jump to

Keyboard shortcuts

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