quality

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package quality holds the pure logic of Daisybell's quality gate: the thresholds file (.quality/thresholds.yaml), the committed token baseline (.quality/token-baseline.json) and the mutation reports with their accepted survivors (.quality/mutation-exclusions.yaml).

The integration suite applies the token rules to real responses; tools/qualitygate applies the mutation rules to gremlins reports. Keeping the rules here means they are unit-tested (and mutated) like any other pure package. The structure follows Vitral's gate; the numbers are Daisybell's own, measured on its fixtures.

Index

Constants

View Source
const (
	ThresholdsFile = ".quality/thresholds.yaml"
	BaselineFile   = ".quality/token-baseline.json"
	ExclusionsFile = ".quality/mutation-exclusions.yaml"
)

Default file locations, relative to the module root.

Variables

This section is empty.

Functions

func ChangedPackages

func ChangedPackages(files, scope []string) []string

ChangedPackages intersects changed files (git paths) with the mutation scope: a package is in when one of its non-test Go files changed. Sorted, without duplicates.

func CheckMedian

func CheckMedian(c TokenConfig, actions []int) (median int, failure string)

CheckMedian fails when the median action response exceeds tokens.medianAction.

func EvaluateMutation

func EvaluateMutation(results []MutationResult, cfg MutationConfig) []string

EvaluateMutation compares each score with its package minimum.

func FormatMutation

func FormatMutation(results []MutationResult, cfg MutationConfig) string

FormatMutation renders the score of each package.

func FormatTokens

func FormatTokens(rows []TokenRow) string

FormatTokens renders value, baseline, difference and ceiling of each response.

func MarshalBaseline

func MarshalBaseline(m map[string]int) ([]byte, error)

MarshalBaseline encodes the baseline with sorted keys, one per line, so diffs stay readable.

func Median

func Median(xs []int) int

Median is the middle value (upper middle for an even count); 0 for no values.

func ParseBaseline

func ParseBaseline(data []byte) (map[string]int, error)

ParseBaseline decodes the baseline JSON (an object of key → tokens).

func ReadBaseline

func ReadBaseline(root string) (map[string]int, error)

ReadBaseline reads the committed baseline under root. A missing file is an empty baseline.

func StaleBaseline

func StaleBaseline(current, base map[string]int) []string

StaleBaseline lists the keys whose measured value differs from the baseline, or that are missing on either side, sorted. Empty means the baseline is current.

func WriteBaseline

func WriteBaseline(root string, m map[string]int) error

WriteBaseline writes the baseline under root.

Types

type Exclusion

type Exclusion struct {
	File    string `yaml:"file"` // package-relative path: internal/guard/url.go
	Line    int    `yaml:"line"`
	Mutator string `yaml:"mutator"` // gremlins type: CONDITIONALS_BOUNDARY, ARITHMETIC_BASE…
	Reason  string `yaml:"reason"`
}

Exclusion is an accepted surviving mutant (equivalent or not worth a test), with the reason.

func ParseExclusions

func ParseExclusions(data []byte) ([]Exclusion, error)

ParseExclusions decodes .quality/mutation-exclusions.yaml; every entry needs a reason.

type MutationConfig

type MutationConfig struct {
	// TimeoutCoefficient is passed to gremlins (test timeout = coefficient × normal run).
	TimeoutCoefficient int `yaml:"timeoutCoefficient"`
	// Packages maps a package directory ("internal/guard") to its rule.
	Packages map[string]MutationPackage `yaml:"packages"`
}

MutationConfig scopes mutation testing to the pure packages, each with its minimum score.

type MutationPackage

type MutationPackage struct {
	// Min is the minimum score in percent: killed / (killed + lived), excluded survivors left out.
	Min float64 `yaml:"min"`
}

MutationPackage is the rule of one package.

type MutationResult

type MutationResult struct {
	Package  string
	Killed   int
	Lived    int
	Excluded int
	// Ignored are mutants that say nothing about the tests: not covered, timed out, not viable.
	Ignored int
	LivedAt []string // file:line MUTATOR of each counted survivor, sorted
}

MutationResult is the score of one package.

func ParseMutation

func ParseMutation(pkg string, data []byte, exclusions []Exclusion) (MutationResult, error)

ParseMutation reads the gremlins report of pkg and applies the exclusions.

func (MutationResult) Score

func (m MutationResult) Score() float64

Score is killed / (killed + lived) in percent; 100 when nothing countable was mutated.

type Thresholds

type Thresholds struct {
	Tokens   TokenConfig    `yaml:"tokens"`
	Mutation MutationConfig `yaml:"mutation"`
}

Thresholds is the content of .quality/thresholds.yaml.

func LoadThresholds

func LoadThresholds(root string) (Thresholds, error)

LoadThresholds reads the thresholds file under root.

func ParseThresholds

func ParseThresholds(data []byte) (Thresholds, error)

ParseThresholds decodes and validates the thresholds file.

func (Thresholds) MutationScope

func (t Thresholds) MutationScope() []string

MutationScope lists the packages in scope for mutation, sorted.

type TokenConfig

type TokenConfig struct {
	// MedianAction caps the median of all action responses (SPEC §5).
	MedianAction int `yaml:"medianAction"`
	// Rules are per-response ceilings; the first rule whose pattern matches the key wins.
	Rules []TokenRule `yaml:"rules"`
}

TokenConfig holds the response budgets of the integration suite (tokens ≈ chars/4).

func (TokenConfig) Rule

func (c TokenConfig) Rule(key string) (TokenRule, bool)

Rule returns the first rule whose pattern matches key.

type TokenRow

type TokenRow struct {
	Key     string
	Value   int
	Base    int
	HasBase bool
	Max     int // 0 when no rule matched
	Problem string
}

TokenRow is one measured response compared with its ceiling and with the committed baseline.

func EvaluateTokens

func EvaluateTokens(c TokenConfig, current, base map[string]int) (rows []TokenRow, failures []string)

EvaluateTokens compares measured responses with the ceilings and the baseline. A key without a rule fails (every response must have a budget); the baseline is informational, shown so a budget change is visible in review. Rows come back sorted by key, failures in the same order.

func (TokenRow) OK

func (r TokenRow) OK() bool

OK reports that the response is within its ceiling.

type TokenRule

type TokenRule struct {
	Match string `yaml:"match"`
	Max   int    `yaml:"max"`
}

TokenRule is one ceiling. Match is a path.Match pattern over keys such as "login.navigate".

Jump to

Keyboard shortcuts

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