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
- func ChangedPackages(files, scope []string) []string
- func CheckMedian(c TokenConfig, actions []int) (median int, failure string)
- func EvaluateMutation(results []MutationResult, cfg MutationConfig) []string
- func FormatMutation(results []MutationResult, cfg MutationConfig) string
- func FormatTokens(rows []TokenRow) string
- func MarshalBaseline(m map[string]int) ([]byte, error)
- func Median(xs []int) int
- func ParseBaseline(data []byte) (map[string]int, error)
- func ReadBaseline(root string) (map[string]int, error)
- func StaleBaseline(current, base map[string]int) []string
- func WriteBaseline(root string, m map[string]int) error
- type Exclusion
- type MutationConfig
- type MutationPackage
- type MutationResult
- type Thresholds
- type TokenConfig
- type TokenRow
- type TokenRule
Constants ¶
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 ¶
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 ¶
FormatTokens renders value, baseline, difference and ceiling of each response.
func MarshalBaseline ¶
MarshalBaseline encodes the baseline with sorted keys, one per line, so diffs stay readable.
func ParseBaseline ¶
ParseBaseline decodes the baseline JSON (an object of key → tokens).
func ReadBaseline ¶
ReadBaseline reads the committed baseline under root. A missing file is an empty baseline.
func StaleBaseline ¶
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.
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 ¶
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).
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.