drift

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package drift compares a resolved plan against the live system. All checks are read-only probes; nothing is installed, written, or ensured.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorDiff added in v0.16.0

func ColorDiff(diff string, color bool) string

ColorDiff adds ANSI colors to unified diff output. When color is false the input is returned unchanged. + lines (not +++) get green, - lines (not ---) get red, @@ hunk headers get cyan.

func Render

func Render(w io.Writer, findings []Finding)

Render writes the drift report. Sections appear in fixed order and only when they have ≥1 finding. Non-OK findings print as ` <module>: <item> — <detail>`; the owning module replaces the status prefix (drift is implied for listed items; unknown items get a (?) suffix). A section whose findings are all OK prints ` ok: all N checks passed`. On a TTY, finding lines are colored by issue type: orange (missing/version drift), red (not-a-symlink/unknown), yellow (content differs). The final line is `no drift` when nothing drifted, otherwise `drift: N item(s)` with `, K unknown` appended when there are unknowns.

func UnifiedDiff added in v0.16.0

func UnifiedDiff(targetName, targetContent, sourceName, sourceContent string) string

UnifiedDiff computes a unified diff between current (live) and desired (profile) file content. Returns empty string when content is identical. targetName/sourceName label the --- and +++ header lines.

Types

type CheckOptions

type CheckOptions struct {
	// Jobs bounds concurrent probe workers; <= 0 uses runtime.NumCPU().
	Jobs int
	// Verbose, when non-nil, receives one "checking <section>: <item>" line
	// per probe as it starts. Writes are serialized internally.
	Verbose io.Writer
}

CheckOptions controls how Check runs its probes.

type Finding

type Finding struct {
	Section string // "packages" | "tools" | "dotfiles" | "mounts" | "smb"
	Item    string // package name, tool name, target path, unit name, share name
	Status  Status
	Detail  string
	Module  string // owning module ID (empty if unknown)
}

Finding is one checked item. Detail is empty for OK.

func Check

func Check(ctx context.Context, plan *resolve.Plan, profileRoot string, pr Probes, opts CheckOptions) []Finding

Check runs every read-only probe for the plan concurrently (bounded by opts.Jobs; <= 0 → runtime.NumCPU) and returns findings in fixed section order (packages → tools → dotfiles → mounts → smb). Each worker writes only its own indexed result slot, so output order is deterministic regardless of completion order. opts.Verbose, when non-nil, receives one "checking <section>: <item>" line per probe as it starts. A nil plan returns nil.

type Probes

type Probes struct {
	IsInstalled func(ctx context.Context, pkg string) (bool, error)
	ToolCurrent func(ctx context.Context, tool string) (string, error) // err or "" → Unknown
	Run         func(ctx context.Context, name string, args ...string) (string, error)
	HomeDir     string
	Readlink    func(path string) (string, error)
	ReadFile    func(path string) ([]byte, error)
	StatDir     func(path string) (bool, error) // exists and is a directory
}

Probes are the side-effect seams. DefaultProbes fills OS-backed defaults; tests override individual fields. IsInstalled and ToolCurrent have no generic OS default (they need a package backend / mise) and must be set by the caller before Check.

func DefaultProbes

func DefaultProbes() Probes

DefaultProbes returns OS-backed probes for Run, Readlink, ReadFile, StatDir, and HomeDir. IsInstalled and ToolCurrent are left nil — wire them to a package backend and mise before calling Check.

type Status

type Status int

Status is the outcome of one drift check.

const (
	OK Status = iota
	Drift
	// Unknown means a probe failed or the result was not decidable (e.g. mise
	// missing, permission denied).
	Unknown
)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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