quality

package
v0.120.5 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package quality runs read-only coverage and verification checks for a local repository fleet. It deliberately reports every selected repository instead of stopping at the first failure, so people and AI agents can act on one complete index.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveValidationCache added in v0.98.3

func SaveValidationCache(cacheRoot string, key ValidationCacheKey, report VerificationReport) error

SaveValidationCache writes terminal evidence atomically. Failed writes are returned to the caller; a cache failure never changes validation semantics.

func SingleWorkerNodeEnv added in v0.88.0

func SingleWorkerNodeEnv() []string

SingleWorkerNodeEnv is the environment a single-worker Node run must carry. It is exported so a caller that composes its own command still states the same environment the profile does.

func SortVerificationReports

func SortVerificationReports(reports []VerificationReport)

SortVerificationReports orders reports for deterministic output.

func ValidationCacheDir added in v0.98.3

func ValidationCacheDir(root string) string

ValidationCacheDir is kept in one place so all merge baseline callers share the same private WB state and tests can replace it without touching a user repository.

Types

type Check

type Check string

Check selects a conventional verification class.

const (
	CheckLint  Check = "lint"
	CheckTest  Check = "test"
	CheckBuild Check = "build"
	CheckSpec  Check = "spec"
)

func ParseChecks

func ParseChecks(value string) ([]Check, error)

ParseChecks validates the explicit --checks list. A missing list defaults to the conventional lint, test, build sequence.

type CoverageDiagnostic added in v0.67.9

type CoverageDiagnostic struct {
	Manifest string `yaml:"manifest" json:"manifest"`
	SHA256   string `yaml:"sha256" json:"sha256"`
}

CoverageDiagnostic points at the private manifest containing lossless raw output for failed coverage jobs.

type CoverageDiagnosticFile added in v0.67.9

type CoverageDiagnosticFile struct {
	Label  string `yaml:"label" json:"label"`
	Path   string `yaml:"path" json:"path"`
	Bytes  int    `yaml:"bytes" json:"bytes"`
	SHA256 string `yaml:"sha256" json:"sha256"`
}

type CoverageDiagnosticManifest added in v0.67.9

type CoverageDiagnosticManifest struct {
	SchemaVersion int    `yaml:"schema_version" json:"schema_version"`
	Repository    string `yaml:"repository" json:"repository"`
	Module        string `yaml:"module" json:"module"`
	// Ambient names the machine-state signals present in the gate's own
	// environment and in the ancestors of TMPDIR and Module when the shard
	// failures below were recorded. Empty when none were observed.
	Ambient envguard.AmbientInputs   `yaml:"ambient,omitempty" json:"ambient,omitempty"`
	Files   []CoverageDiagnosticFile `yaml:"files" json:"files"`
}

CoverageDiagnosticManifest is intentionally separate from CoverageReport: it contains unbounded command output and therefore stays in the private report root rather than crossing the bounded hook/session boundary.

type CoverageReport

type CoverageReport struct {
	SchemaVersion int                  `yaml:"schema_version" json:"schema_version"`
	Repositories  []RepositoryCoverage `yaml:"repositories" json:"repositories"`
	Statements    int                  `yaml:"statements" json:"statements"`
	Covered       int                  `yaml:"covered" json:"covered"`
	Percentage    float64              `yaml:"percentage" json:"percentage"`
}

CoverageReport is a deterministic, machine-readable coverage index.

func NewCoverageReport

func NewCoverageReport(repositories []RepositoryCoverage) CoverageReport

NewCoverageReport aggregates reports in deterministic repository order.

type ModuleCoverage

type ModuleCoverage struct {
	Path       string  `yaml:"path" json:"path"`
	Statements int     `yaml:"statements" json:"statements"`
	Covered    int     `yaml:"covered" json:"covered"`
	Percentage float64 `yaml:"percentage" json:"percentage"`
	Attempts   int     `yaml:"attempts,omitempty" json:"attempts,omitempty"`
}

ModuleCoverage records the statement totals from one Go module's generated coverage profile.

type Progress added in v0.50.0

type Progress struct {
	Repository string
	Language   string
	Module     string
	Check      Check
	Command    string
	Detail     string
	State      ProgressState
	Status     Status
	Attempts   int
	Completed  int
	Total      int
}

Progress describes one external check or a completed repository. Repository is filled by the fleet runner, which owns cross-repository scheduling.

type ProgressState added in v0.50.0

type ProgressState string

ProgressState identifies a visible quality-work transition.

const (
	ProgressStarted             ProgressState = "started"
	ProgressRetrying            ProgressState = "retrying"
	ProgressCompleted           ProgressState = "completed"
	ProgressRepositoryCompleted ProgressState = "repository_completed"
)

type RepositoryCoverage

type RepositoryCoverage struct {
	Repository string              `yaml:"repository" json:"repository"`
	Path       string              `yaml:"path" json:"path"`
	Status     Status              `yaml:"status" json:"status"`
	Modules    []ModuleCoverage    `yaml:"modules,omitempty" json:"modules,omitempty"`
	Statements int                 `yaml:"statements" json:"statements"`
	Covered    int                 `yaml:"covered" json:"covered"`
	Percentage float64             `yaml:"percentage" json:"percentage"`
	Error      string              `yaml:"error,omitempty" json:"error,omitempty"`
	Diagnostic *CoverageDiagnostic `yaml:"diagnostic,omitempty" json:"diagnostic,omitempty"`
}

RepositoryCoverage records aggregate Go coverage for one repository.

func Cover

func Cover(ctx context.Context, repository, path string) RepositoryCoverage

Cover measures all Go modules below path. It creates profiles in the system temporary directory, never in the repository.

func CoverWithOptions

func CoverWithOptions(ctx context.Context, repository, path string, options RunOptions) RepositoryCoverage

CoverWithOptions measures coverage with a deadline and retries for each Go module's test command.

type RunOptions

type RunOptions struct {
	Timeout time.Duration
	Retry   int
	// CheckTimeout bounds one logical verification check, including all of its
	// command attempts and any process-isolated Go shards. Zero leaves the
	// existing per-command Timeout behavior unchanged.
	CheckTimeout time.Duration
	// ShardAttemptTimeout bounds one process-isolated Go test shard attempt.
	// Zero retains Timeout as the shard-attempt bound when Timeout is set.
	ShardAttemptTimeout time.Duration
	// GoTestShards runs each explicitly named Go package in this many
	// process-isolated shards. It is opt-in because TestMain and process-global
	// fixtures run once per shard; callers must name packages whose contract
	// permits that isolation. Discovery invokes TestMain once before each shard
	// process invokes it again.
	GoTestShards int
	// GoShardPackages are module-relative package patterns such as
	// ./internal/worktrees. Packages not named here still run exactly once.
	GoShardPackages []string
	// CoverageProfile retains the exact merged Go profile for one module.
	// Fleet and multi-module adapters reject it rather than inventing names.
	CoverageProfile string
	// CoverageDiagnosticsDir retains raw output from failed process-isolated
	// coverage jobs beside the durable coverage report. The human-facing error
	// remains bounded; this private artifact is the lossless recovery path.
	CoverageDiagnosticsDir string
	// CoverageDiagnosticsRepository identifies the owning repository in the
	// private manifest when a fleet runner executes several repositories.
	CoverageDiagnosticsRepository string
	// SingleWorker constrains every check to one worker, so a verification
	// run cannot exceed the workstation's concurrency cap on its own. Go tests
	// gain `-p 1` and never `-race`; Node runs gain `--parallel=1` and
	// `--maxWorkers=1` with the Nx daemon and cache disabled.
	//
	// Serialization is deliberately *not* a substitute for per-file
	// isolation: nothing here relaxes an isolation flag, because a serialized
	// leak is worse than a flake — it is reproducible and misattributed.
	SingleWorker bool
	// Env is appended to each check's environment as KEY=VALUE entries. It is
	// how a caller states the environment a run must carry (GOWORK=off,
	// NX_DAEMON=false) rather than leaving it to the shell that invoked wb.
	Env []string
	// Progress receives lifecycle events for external checks. Callers may use it
	// for terminal diagnostics; reports remain the authoritative output.
	Progress func(Progress)
}

RunOptions bounds a single external command and retries only failed attempts. Zero Timeout disables the per-command deadline.

func RepositoryRunOptions added in v0.67.1

func RepositoryRunOptions(root string, base RunOptions) (RunOptions, error)

RepositoryRunOptions applies an explicit repository-owned quality policy to one validation run. Absence is the portable default; malformed or ambiguous policy fails closed rather than silently falling back to a slower or weaker command.

type Status

type Status string

Status is the outcome of a repository or a discrete verification command.

const (
	StatusPassed  Status = "passed"
	StatusFailed  Status = "failed"
	StatusSkipped Status = "skipped"
)

type ValidationCacheKey added in v0.98.3

type ValidationCacheKey struct {
	Repository       string   `json:"repository"`
	TargetRevision   string   `json:"target_revision"`
	Checks           []Check  `json:"checks"`
	QualityConfigSHA string   `json:"quality_config_sha"`
	WBRevision       string   `json:"wb_revision"`
	GoToolchain      string   `json:"go_toolchain"`
	ModuleFiles      []string `json:"module_files"`
}

ValidationCacheKey identifies the exact inputs that make a verification report reusable. Checks remain ordered because the order is part of the command contract and can affect the resulting evidence.

func NewValidationCacheKey added in v0.98.3

func NewValidationCacheKey(repository, targetRevision, root, wbRevision string, checks []Check) (ValidationCacheKey, error)

NewValidationCacheKey fingerprints repository-local policy and module manifests. The caller supplies the exact target revision and WB revision.

type VerificationEntry

type VerificationEntry struct {
	Language string `yaml:"language" json:"language"`
	Module   string `yaml:"module,omitempty" json:"module,omitempty"`
	Check    Check  `yaml:"check" json:"check"`
	Command  string `yaml:"command,omitempty" json:"command,omitempty"`
	Status   Status `yaml:"status" json:"status"`
	Detail   string `yaml:"detail,omitempty" json:"detail,omitempty"`
	Attempts int    `yaml:"attempts,omitempty" json:"attempts,omitempty"`
}

VerificationEntry is one command WB attempted or intentionally skipped.

type VerificationReport

type VerificationReport struct {
	Repository string `yaml:"repository" json:"repository"`
	Path       string `yaml:"path" json:"path"`
	// Revision and WorkspaceClean are populated by the WB command adapter
	// around the complete verification run. They let a downstream receipt bind
	// successful mechanisms to the exact clean Git tree they exercised.
	Revision       string              `yaml:"revision,omitempty" json:"revision,omitempty"`
	WorkspaceClean bool                `yaml:"workspace_clean,omitempty" json:"workspace_clean,omitempty"`
	Status         Status              `yaml:"status" json:"status"`
	Results        []VerificationEntry `yaml:"results" json:"results"`
}

VerificationReport records all conventional checks applicable to a repository. Unsupported stacks and missing optional Node scripts are skipped rather than treated as failures.

func LoadValidationCache added in v0.98.3

func LoadValidationCache(cacheRoot string, key ValidationCacheKey) (VerificationReport, bool, error)

LoadValidationCache returns only an intact terminal report with an exact key. Any malformed, stale, or otherwise incomplete record is a cache miss.

func Verify

func Verify(ctx context.Context, repository, path string, checks []Check) VerificationReport

Verify runs the requested conventional Go and Node checks. The caller owns cross-repository parallelism; checks within one module run in the requested order to keep output and failures clear.

func VerifyWithOptions

func VerifyWithOptions(ctx context.Context, repository, path string, checks []Check, options RunOptions) VerificationReport

VerifyWithOptions runs the requested checks with per-command reliability controls. The returned report includes every attempted, skipped, passed, or failed command.

Jump to

Keyboard shortcuts

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