health

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package health composes read-only diagnostics for `semantica doctor`.

Each check returns one or more Check results without mutating state. Run combines them into a Report, and render.go formats the result.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the JSON schema version for the doctor report. Increment on breaking changes to the JSON shape.

Variables

This section is empty.

Functions

func RenderJSON

func RenderJSON(w io.Writer, r Report) error

RenderJSON writes the report as pretty-printed JSON.

func RenderText

func RenderText(w io.Writer, r Report) error

RenderText writes a human-readable diagnostic to w.

Types

type Check

type Check struct {
	Category    string `json:"category"`
	ID          string `json:"id"`
	Status      Status `json:"status"`
	Message     string `json:"message"`
	Remediation string `json:"remediation,omitempty"`
}

Check is a single diagnostic result.

type Options

type Options struct {
	// RepoPath is the working repository (default: cwd). Hook,
	// git-hook, and connect/auth checks are scoped to this repo.
	RepoPath string

	// DoctorBinary overrides `os.Executable()` for self-binary
	// matching. Used by tests.
	DoctorBinary string

	// LookPath overrides exec.LookPath. Used by tests.
	LookPath func(string) (string, error)

	// Registry is the explicit hook-provider registry used by the
	// hook-related checks (footguns, SQL inspection, provider hook
	// installation). Production callers must set this from
	// providers.NewHookRegistry(); the doctor command does so. A
	// nil Registry is treated as the empty set: hook-related
	// checks become no-ops and report no findings, which is
	// useful only for tests that exercise the non-hook paths
	// without wiring providers.
	Registry *hooks.Registry
}

Options configure a doctor run. All fields are optional; zero values are safe defaults. Tests inject DoctorBinary and lookPath to avoid touching the real PATH.

type Report

type Report struct {
	SchemaVersion int     `json:"schema_version"`
	Result        Status  `json:"result"`
	Summary       Summary `json:"summary"`
	Checks        []Check `json:"checks"`
}

Report is the full doctor result.

func Run

func Run(ctx context.Context, opts Options) (Report, error)

Run executes the health checks and returns a Report. Individual check errors are represented as Check results.

func (Report) ExitCode

func (r Report) ExitCode() int

ExitCode maps the report's overall result to a process exit code. 0 = ok, 1 = warn, 2 = fail. CI gates can choose `< 2` to allow warns through or `== 0` to require fully clean.

type Status

type Status string

Status describes a single check's outcome.

const (
	StatusOK   Status = "ok"
	StatusWarn Status = "warn"
	StatusFail Status = "fail"
)

type Summary

type Summary struct {
	OK   int `json:"ok"`
	Warn int `json:"warn"`
	Fail int `json:"fail"`
}

Summary aggregates check counts by status.

Jump to

Keyboard shortcuts

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