check

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 16 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 check holds the required checks of a ref, the results that a runner posts, and the delivery of check requests.

Index

Constants

View Source
const (
	StatusPass = runnerproto.Pass
	StatusFail = runnerproto.Fail
)
View Source
const (
	// FilePath is the check file at the tip of a target ref.
	FilePath = ".ward/checks.json"
)
View Source
const ModePull = "pull"

ModePull is the one dispatch mode. An entry may name it, so a list written for an earlier version still loads.

Variables

View Source
var (
	// ErrInvalid means that a posted result breaks a rule of the body.
	ErrInvalid = errors.New("check: invalid result")
	// ErrUnknownRequest means that no request has the posted request_id.
	ErrUnknownRequest = errors.New("check: unknown request")
	// ErrOtherRepo means that the request belongs to another repository.
	ErrOtherRepo = errors.New("check: request of another repository")
	// ErrNotRegistered means that the poster is not a runner that leased the request of a pull repository.
	ErrNotRegistered = errors.New("check: runner not registered for the repository")
)
View Source
var ErrNoRunner = errors.New("check: no runner for the repository")

ErrNoRunner means that no runner is configured for the repository.

Functions

This section is empty.

Types

type Check

type Check = runnerproto.Check

Check is one required check. The runner runs Run at the root of the tree.

func ParseFile

func ParseFile(data []byte) ([]Check, error)

ParseFile decodes and checks the content of a check file. The file is HuJSON: it standardizes to JSON, and then the strict decode runs. It rejects an unknown field and every null, so that a file of the wrong shape never passes as an empty or a valid list.

type Clock

type Clock interface {
	Now() time.Time
	After(d time.Duration) <-chan time.Time
}

Clock is the source of time and of waits.

func RealClock

func RealClock() Clock

RealClock is the clock of the wall.

type LeasedError added in v0.8.0

type LeasedError struct{ Until time.Time }

LeasedError means that a runner holds a live lease on the request, so the request is not replaced. Until is the end of the lease.

func (*LeasedError) Error added in v0.8.0

func (e *LeasedError) Error() string

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager keeps the results and sends the check requests. It has no poll: a result wakes the waiters.

func New

func New(store Store, runners []Runner, wake func(), clock Clock, log *slog.Logger) *Manager

New returns a manager. wake tells the polling runners that a request is open; it may be nil. A nil clock means the wall clock.

func (*Manager) Changed

func (m *Manager) Changed() <-chan struct{}

Changed returns a channel that closes at the next result. Take it before reading the state that the result changes.

func (*Manager) Ensure

func (m *Manager) Ensure(ctx context.Context, repo, tree, commit string, c Check) error

Ensure makes sure that a request for check c of tree is open, and starts its delivery when it opens one.

func (*Manager) Mark

func (m *Manager) Mark(ctx context.Context) (int64, error)

Mark returns the position after the newest result. A fail counts for a land only when it is after its mark.

func (*Manager) Post

func (m *Manager) Post(ctx context.Context, repo, kid string, p Posted) error

Post records a result that the runner kid posted for a repository. A second result for a request changes nothing. For a pull repository, kid must be one of the kids of the repository and must have leased the request.

func (*Manager) Runner

func (m *Manager) Runner(repo string) (Runner, bool)

Runner returns the runner of a repository.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start resumes every open request. The deliveries stop when ctx ends.

func (*Manager) Verdict

func (m *Manager) Verdict(ctx context.Context, repo, tree string, c Check, mark int64) (Verdict, error)

Verdict reads the state of check c for tree. A pass is final. A fail counts only when it is after mark.

func (*Manager) Wait

func (m *Manager) Wait()

Wait returns when every delivery has stopped. Call it after the context of Start ends.

type Posted

type Posted = runnerproto.Result

Posted is the body that a runner posts.

type Request

type Request struct {
	ID         string
	Repo       string
	Tree       string
	Commit     string
	Check      Check
	Hash       string
	Env        string
	AcceptedAt time.Time
	Open       bool
}

Request is one check request to a runner. It is open until a result or a newer request for its key ends it.

type Result

type Result struct {
	ID        int64
	RequestID string
	Repo      string
	Tree      string
	Hash      string
	Env       string
	Status    Status
	Summary   string
	LogURL    string
}

Result is a fact about the content of a tree. Its ID orders results across the store.

type Runner

type Runner struct {
	Repo         string   `json:"repo"`
	Mode         string   `json:"mode,omitempty"`
	Kids         []string `json:"kids"`
	MinIsolation string   `json:"min_isolation,omitempty"`
	Env          string   `json:"env"`
}

Runner names the runners that serve the check requests of one repository. Each kid is a runner identity that polls ward for a lease.

func ParseRunners

func ParseRunners(raw []byte) ([]Runner, error)

ParseRunners decodes and checks the WARD_RUNNERS list. It rejects an unknown field.

type State

type State = wardapi.CheckStatus

State is the state of one check for one tree.

type Status

type Status = runnerproto.Status

Status is the outcome that a runner reports.

type Store

type Store interface {
	// OpenRequest returns the open request for the key of r. With no open request and no pass for the key, it stores r and returns it with true.
	OpenRequest(ctx context.Context, r Request) (Request, bool, error)
	Request(ctx context.Context, id string) (Request, bool, error)
	OpenRequests(ctx context.Context) ([]Request, error)
	// Supersede closes the request old and stores next, an open request for the same key. It does nothing and returns false
	// when old is no longer open or the key has a pass. It does nothing and returns a *LeasedError when a runner holds a
	// lease on old that is live at now.
	Supersede(ctx context.Context, old string, next Request, now time.Time) (bool, error)
	// AddResult stores a result and closes its request. A pass also closes every other open request for the key.
	// It returns false and changes nothing when the request already has a result.
	AddResult(ctx context.Context, r Result) (bool, error)
	// Results returns the results of one key, oldest first.
	Results(ctx context.Context, repo, tree, hash, env string) ([]Result, error)
	MaxResultID(ctx context.Context) (int64, error)
	// Lease gives kid, under leaseID, the oldest open request of one of repos that has no live lease, until the time until.
	// A lease that passed its time is dead, so its request is leasable again with the same ID. The returned request has
	// AcceptedAt set to now.
	Lease(ctx context.Context, repos []string, kid, leaseID string, now, until time.Time) (Request, bool, error)
	// RenewLease moves the end of a lease that kid holds. It returns false when the request is closed, when its repository
	// is not in repos, when a newer lease replaced the lease, or when kid does not hold it.
	RenewLease(ctx context.Context, leaseID, kid string, repos []string, until time.Time) (bool, error)
	// Leased reports whether kid has held a lease on the request.
	Leased(ctx context.Context, requestID, kid string) (bool, error)
}

Store is the transactional state of requests and results. Each method that writes is one transaction.

type Verdict

type Verdict struct {
	State  State
	Result Result
}

Verdict is the state of one check, and the failing result when the state is Fail.

Directories

Path Synopsis
Package checktest is the conformance suite of check.Store.
Package checktest is the conformance suite of check.Store.

Jump to

Keyboard shortcuts

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