quality

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 13 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 deterministic analyses behind `idea verify`'s quality dimensions (domain.QualityDimension): an OpenAPI 3 diff, a Go exported-API diff, documented-command extraction, docs and operational- readiness heuristics, and performance-budget arithmetic. Everything here is a pure function of file contents -- no store, no Docker, no model -- so each rule is unit-testable against a fixture, and the workflow package owns the parts that run commands or ask the verification_engineer role.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BudgetVerdict

func BudgetVerdict(name, unit string, value float64, max *float64, maxRegressionPct float64, baseline *float64) (domain.QualityStatus, string)

BudgetVerdict judges one measured value against a budget's absolute ceiling (max, nil for none) and its allowed regression over the previous measurement (maxRegressionPct, 0 for none; baseline nil when there is no previous measurement). Over either threshold is a fail. With no baseline the regression half is recorded as "no baseline yet" -- this measurement becomes the baseline -- and does not fail.

func DefaultModes

func DefaultModes(rigor string) map[domain.QualityDimension]domain.QualityMode

DefaultModes is each dimension's mode at an effective review rigor, before verify.dimensions overrides it.

  • quick: every dimension off. A small change to a small project is verified by its tests and acceptance evidence, as before this existed.
  • standard: setup_reproducibility, docs_completeness and api_compatibility advisory -- the three that are cheap, deterministic and almost never wrong about what they report -- and the rest off.
  • thorough: those three gated; api_ergonomics, security, performance and operational_readiness advisory.

An unrecognized rigor gets standard's modes, the same "safe middle" fallback findingCap uses.

func DocsChecks

func DocsChecks(in DocsInput) []domain.QualityCheck

DocsChecks runs docs_completeness's deterministic checks:

  1. readme: a README exists at the workspace root (fail otherwise).
  2. readme_install / readme_usage: it has a section whose heading names installation/setup and one naming usage/examples (warn otherwise).
  3. readme_configuration: when the change added environment-variable reads, the README has a configuration/environment section (warn).
  4. routes_documented / flags_documented: every HTTP route and CLI flag the change added in source is mentioned in some doc or OpenAPI spec (fail, citing the declaring line).
  5. env_documented: every environment variable the change started reading is mentioned in some doc (warn).
  6. go_doc_comments: every exported Go func, method, type, const or var the change added carries a doc comment (warn).
  7. openapi_described: every operation the change added to a spec has a summary or description (warn).

A check with nothing to judge is not_applicable.

func ExportedGoAPI

func ExportedGoAPI(files map[string][]byte) (map[string]GoSymbol, error)

ExportedGoAPI parses the given files (workspace path -> content; every file must belong to the package of its directory) and returns their exported API keyed by GoSymbol.Key. It uses go/parser only: no type checker, no module loading, nothing that needs the network or a build. A file that does not parse is reported in the error and skipped; package main is skipped silently (it exports nothing importable).

func ExtractMetric

func ExtractMetric(metric, output string) (float64, error)

ExtractMetric reads a performance budget's number from command output: the first capture group of the first match of metric. Thousands separators (`1,234`) are tolerated; anything else that does not parse as a float is an error, never a zero.

func FindReadme

func FindReadme(paths []string) string

FindReadme returns the root README's path among files, preferring README.md. "" when the project has none at its root.

func GateUnmet

func GateUnmet(p Policy, results map[domain.QualityDimension]domain.QualityResult, current string) []string

GateUnmet lists, for every gated dimension, why it does not satisfy the gate: its latest result failed, was not measured, or is missing or stale (measured against different applied work or a different policy -- which is not measured either). results holds the latest result per dimension; a result whose InputDigest differs from current is treated as stale.

func IsDocPath

func IsDocPath(p string) bool

IsDocPath reports whether p is documentation the docs checks read for mentions: Markdown/MDX/reStructuredText/AsciiDoc anywhere, plus OpenAPI specs (callers add those by content).

func IsMigrationPath

func IsMigrationPath(p string) bool

IsMigrationPath reports whether p is a database migration: any .sql file, or any file in a directory named migrations/migration/migrate/db/migrate.

func IsPublicGoPath

func IsPublicGoPath(p string) bool

IsPublicGoPath reports whether a .go file is part of an importable public API: not a test, not under internal/ (unimportable outside its module), not under testdata/ or vendor/. A package main is excluded later, from its package clause.

func IsSourcePath

func IsSourcePath(p string) bool

IsSourcePath reports whether p is a source file the surface scan reads. Tests are excluded: a route a test registers is not product surface.

func LooksLikeOpenAPI

func LooksLikeOpenAPI(content []byte) bool

LooksLikeOpenAPI reports whether content is an OpenAPI 3 document: a top-level `openapi` key whose value starts with "3". Swagger 2 is not diffed (its shape differs and it is not what this repository's own tooling speaks), so a `swagger: "2.0"` file is not one.

func MentionedIn

func MentionedIn(it SurfaceItem, docs map[string]string) (string, bool)

MentionedIn reports whether a surface item is mentioned in any of docs (path -> content). A route matches on its normalized shape anywhere in the text; a flag must appear as `--name` (not followed by more name characters, so `--dry` is not satisfied by `--dry-run`); an env var as a whole word.

func NormalizeRoute

func NormalizeRoute(r string) string

NormalizeRoute reduces a route to its comparable shape.

func OpsChecks

func OpsChecks(in OpsInput) []domain.QualityCheck

OpsChecks runs operational_readiness's deterministic checks. The first four apply only to a service (a file that starts a network server by one of serviceRes); for a library or CLI they are not_applicable:

  1. health_endpoint: a route whose last segment is health/healthz/ healthcheck/livez/readyz/ready/ping (warn when absent).
  2. graceful_shutdown: SIGTERM is caught (and, in Go, a Shutdown/ GracefulStop call exists), or a Python server that drains on its own (uvicorn/gunicorn) is used (warn when absent).
  3. structured_logging: a structured logger is imported (log/slog, zap, zerolog, logrus; pino, winston, bunyan; structlog, python-json-logger) (warn when absent).
  4. config_from_env: the code reads configuration from the environment (warn when it reads none).
  5. dockerfile_healthcheck: every Dockerfile has a HEALTHCHECK instruction (warn); not_applicable without a Dockerfile.
  6. migration_safety: a changed migration that was already numbered and present before the change was edited (fail -- a database that applied it will not re-run it), or an added/changed migration contains a destructive statement (DROP TABLE/COLUMN/SCHEMA, TRUNCATE, RENAME, unqualified DELETE) (warn); not_applicable when no migration changed.

func Rollup

func Rollup(checks []domain.QualityCheck) domain.QualityStatus

Rollup derives a dimension's status from its checks, worst first: fail > not_measured > warn > pass > not_applicable.

not_measured outranks warn and pass deliberately. A dimension that passed what it could see and could not look at the rest has not passed; reporting it as pass is exactly the "unmeasured shown as green" failure this exists to prevent. A dimension whose every check is not_applicable is not_applicable; with no checks at all it is not_measured.

func Summarize

func Summarize(checks []domain.QualityCheck) string

Summarize renders a one-line summary of a dimension's checks: the status counts, then the first failing (or unmeasured, or warning) check's detail.

Types

type APIChange

type APIChange struct {
	Breaking bool   `json:"breaking"`
	Kind     string `json:"kind"`
	Subject  string `json:"subject"`
	Detail   string `json:"detail"`
	Path     string `json:"path"`
	Line     int    `json:"line,omitempty"`
}

APIChange is one difference between the before and after versions of a public API surface -- an OpenAPI operation or a Go exported symbol.

Subject is what a requirement or decision would name to acknowledge the change: the HTTP path for an OpenAPI change, the symbol name for a Go one. Path/Line cite where to look: the after file when the thing still exists there, otherwise the before file (a removal has no after line to point at).

func DiffGoAPI

func DiffGoAPI(before, after map[string]GoSymbol) []APIChange

DiffGoAPI compares two exported-API sets. Breaking: a symbol removed, a func/method signature or a field type changed, a type's kind changed, or a method added to an exported interface (every implementation outside the package stops satisfying it). Additions are reported as not breaking.

It does not see changes only a type checker would: a changed underlying type behind a named type used in a signature, method-set changes through embedding, or a constant whose value changed. Those are honest gaps, not "no change".

func DiffOpenAPI

func DiffOpenAPI(beforePath string, before []byte, afterPath string, after []byte) ([]APIChange, error)

DiffOpenAPI compares two versions of an OpenAPI 3 document and reports what changed for a client. It is deliberately focused, not a full semantic diff: it answers "would an existing client of the before spec break against the after spec" for the cases that are unambiguous from the document alone.

Breaking:

  • a path or an operation removed;
  • a parameter removed, a required parameter added, an optional parameter made required, or a parameter's schema type changed;
  • a request body made required, or a request body schema gaining a required property or changing type;
  • a 2xx response removed, a response media type removed, a response schema's type changed, or a property removed from a response object.

Not breaking (reported so a reader sees the whole surface change): a path, operation, optional parameter, or response property added.

Out of scope, on purpose: enum narrowing/widening, format changes, constraint changes (minLength and the like), and anything behind oneOf/anyOf/allOf -- each needs a judgment about the client that the document does not carry. A schema it cannot type is skipped, never guessed at.

beforePath/afterPath are the spec's workspace paths, used for citations.

type ChangedFile

type ChangedFile struct {
	Path         string
	Before       string
	BeforeExists bool
	BeforeKnown  bool
	After        string
	AfterExists  bool
}

ChangedFile is one file the initiative's applied change sets touched, with its content before the first of them and as it is in the workspace now. BeforeKnown is false when the pre-image could not be recovered (it was never persisted); a check that needs it then reports not_measured.

type DocsInput

type DocsInput struct {
	// Paths is every workspace file path (for the README lookup).
	Paths []string
	// Docs is every documentation file's content (IsDocPath, plus OpenAPI
	// specs), path -> text.
	Docs map[string]string
	// Changed are the initiative's changed files.
	Changed []ChangedFile
	// GoAdded are exported Go symbols the change added (from DiffGoAPI's
	// additions, with Documented filled in).
	GoAdded []GoSymbol
	// OpenAPIAdded are operations the change added to a spec, each with
	// whether it carries a summary or description.
	OpenAPIAdded []OpenAPIOperation
}

DocsInput is what docs_completeness judges.

type GoSymbol

type GoSymbol struct {
	Key  string // "<dir>.<Name>", "<dir>.<Type>.<Method>" or "<dir>.<Type>.<Field>"
	Name string // what a requirement would mention: "Parse", "Config.Timeout"
	Kind string // func, method, type, field, interface_method, const, var
	Sig  string
	Path string
	Line int
	// Documented is whether the declaration carries a doc comment (read by
	// docs_completeness, not by the API diff).
	Documented bool
}

GoSymbol is one exported identifier of an importable Go package, rendered so two versions can be compared without type-checking: the shape a client compiles against (a func's parameter and result types, a struct's exported fields, an interface's method set), never names a client cannot see (parameter names, unexported fields).

type Heading

type Heading struct {
	Text string
	Line int
}

Heading is one Markdown heading (ATX `#` or setext underline) and its line.

func Headings

func Headings(text string) []Heading

Headings extracts a Markdown (or reStructuredText-style underlined) document's headings, skipping fenced code blocks so a `# comment` inside a shell example is not read as a section.

type OpenAPIOperation

type OpenAPIOperation struct {
	Method, Route, SpecPath string
	Line                    int
	Described               bool
}

OpenAPIOperation is one operation of an OpenAPI spec.

func OpenAPIOperations

func OpenAPIOperations(specPath string, content []byte) []OpenAPIOperation

OpenAPIOperations lists a spec's operations with whether each is described.

type OpsInput

type OpsInput struct {
	Files   map[string]string
	Changed []ChangedFile
}

OpsInput is what operational_readiness judges: the workspace's source files and build files (path -> text) and the initiative's changed files.

type Policy

type Policy struct {
	Rigor string                                         `json:"rigor"`
	Modes map[domain.QualityDimension]domain.QualityMode `json:"modes"`
	// Overridden lists the dimensions whose mode verify.dimensions set
	// explicitly (the rest are the rigor default).
	Overridden []domain.QualityDimension `json:"overridden,omitempty"`
}

Policy is the resolved mode of every dimension and where it came from.

func ResolvePolicy

func ResolvePolicy(rigor string, overrides map[string]string) Policy

ResolvePolicy applies verify.dimensions overrides to the rigor defaults. An override naming an unknown dimension or mode is ignored here -- the config schema refuses both, so reaching this with one means the schema and the domain disagree, and the default is the safer reading.

func (Policy) Enabled

func (p Policy) Enabled() bool

Enabled reports whether any dimension is measured at all.

type SetupCommand

type SetupCommand struct {
	Cmd  string `json:"cmd"`
	Path string `json:"path"` // README.md, Makefile, package.json, .idea-harness/harness.yaml
	Line int    `json:"line,omitempty"`
	// Skip is "" for a command that runs, or the reason it does not: it
	// fetches dependencies (needs the network), or it starts something
	// long-running (a dev server never exits).
	Skip string `json:"skip,omitempty"`
}

SetupCommand is one documented setup/build/test command, where it was documented, and -- when Skip is set -- why the offline reproducibility run does not execute it.

func MakefileCommands

func MakefileCommands(makefile string) []SetupCommand

MakefileCommands returns `make <target>` for the conventional build/test targets a Makefile declares, in a fixed order (build before test).

func ReadmeCommands

func ReadmeCommands(readmePath, text string, dirExists func(string) bool) []SetupCommand

ReadmeCommands extracts the shell commands documented in a README's setup/build/test sections, in order, each with the README line it is on.

It follows `cd <dir>` within one fenced block (later commands in that block run in <dir>) when dirExists says the directory is part of the workspace; a `cd` into a directory that is not -- the conventional `git clone ... && cd project` -- is dropped, since the fresh copy already is that directory.

func (SetupCommand) Source

func (c SetupCommand) Source() string

Source renders where a command came from, path:line.

type SurfaceItem

type SurfaceItem struct {
	Kind string // "route", "flag", "env"
	Name string // "/v1/items", "--dry-run", "APP_PORT"
	Path string
	Line int
}

SurfaceItem is one public-surface declaration found in source text: an HTTP route, a CLI flag, or an environment variable the code reads.

func AddedSurface

func AddedSurface(before, after []SurfaceItem) []SurfaceItem

AddedSurface returns the items present in after and absent from before, by (kind, name) -- so moving a route between files is not "added".

func SurfaceItems

func SurfaceItems(path, content string) []SurfaceItem

SurfaceItems scans one file for routes, flags and env reads.

Jump to

Keyboard shortcuts

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