spotcheck

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 25 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 spotcheck keeps the spot-check's record (itd-2610301750162657, spc-2610301925429250): the work abcd decided with no person involved, recorded as it happens, for a later draw to read.

THE STORE. The record lives on one branch of the shared remote, BranchRef on origin, tracked at TrackingRef. It is an orphan whose tree holds folders of small JSON files, each written once and never edited: handbacks/ holds the drain's hand-backs and decisions/ the automated facilitator's decisions (the drain's judgements a model answered and the merge gate's in auto mode). Each file's name ends in a short hash of its content, so a name stands for one content: two records that differ in anything are two files, and two writers never write one file two ways.

A write is committed on this checkout's local copy, LocalRef, at once, touching no HEAD, index or working tree, and reaches no network. LocalRef lives outside refs/heads/ and refs/remotes/, so no fetch moves it and every worktree of the checkout shares it: a lane's worktree removed after its landing takes none of its records with it. A record counts as kept only when the local copy holds a file of its name with its content; nothing read from origin's copy makes a record count as kept. One write commits all the records it is handed together, as one commit.

push, which no verb calls yet, carries the local copy to origin: one fetch of the branch, the records origin lacks laid over its tip, and one plain push, never forced, so nothing another writer pushed is dropped; a push origin rejects is tried once more after a fresh fetch, and one that fails again leaves every record on the local copy for the next push. The lay-over never moves the local copy, which holds only this checkout's own writes.

Everything read from the store was written by another session, account or machine, so it is read strictly: names are checked against the forms this package writes and against the hash of their content, each file is bounded and strictly decoded, the number of files a read takes is bounded, and a store that cannot be read is an error, never an empty store.

FREE TEXT. A record's free text is cleaned by one rule that depends on nothing of the machine or account writing or reading it (clean): the text holds no "\" and no "~", and a word that holds a "/" begins with an ASCII letter or digit, has one right before every "/", and holds nothing but ASCII letters, digits, ".", "_", "-" and "/". A run of non-space characters that would break the rule is replaced whole by one fixed placeholder, so a bare repository-relative path such as internal/core/x_test.go stays, and every other word holding a "/" goes: an absolute or home-relative path, an address such as file:// or https://, an option or a name written straight against a path (-I/usr/include, CFLAGS=-I/x, file=a/b), a path in quotes, brackets or backticks, a path with a line number or punctuation written against it (internal/x.go:12, internal/x.go,), and a path that begins with a dot (.abcd/config.json). Control and invisible characters separate words and are removed. A text over its bound is cut between words: the word the cut falls in goes whole and the cut is marked by a word of its own, so a text cleaned twice reads the same as one cleaned once. The read side checks a stored text with the same function, so two readers of one store agree on what it holds.

WHO A COMMIT NAMES. Every git command that makes an object or moves a ref runs through one helper (storeGit) whose environment names abcd's fixed identity as author and committer, whatever the environment held, with the dates in UTC. The record names its writer only by its holder id, the form the reservations use.

Index

Constants

View Source
const (
	// Branch is the store's branch on origin.
	Branch = claim.SpotcheckBranch
	// BranchRef is the branch as a full ref on origin.
	BranchRef = "refs/heads/" + Branch
	// TrackingRef is where a fetch keeps origin's copy.
	TrackingRef = "refs/remotes/" + claim.Remote + "/" + Branch
	// LocalRef is this checkout's local copy: every record this checkout
	// wrote, and nothing another writer wrote.
	LocalRef = "refs/abcd/spotcheck"
)

The store's refs.

View Source
const (
	HandBacksDir = "handbacks"
	DecisionsDir = "decisions"
)

The store's folders.

View Source
const (
	KindDrainJudgement = "drain-judgement"
	KindMergeGate      = "merge-gate"
)

The kinds of decision a decisions/ file holds.

View Source
const (
	SiteLand = "land"
	SiteLane = "lane"
)

The sites a merge-gate decision is recorded from.

View Source
const SchemaVersion = 1

SchemaVersion is the version every record this package writes carries; a record of any other version is not read.

View Source
const (
	// WriteTimeout bounds one write, all of its git commands together. Each
	// is local, so a write that takes longer is a git that hangs, and the
	// write is given up rather than hold its caller.
	WriteTimeout = 10 * time.Second
)

Bounds.

Variables

View Source
var ErrNoOrigin = errors.New("this checkout has no remote named " + claim.Remote + ", so the spot-check keeps no record here")

ErrNoOrigin is a checkout with no remote named origin: there is no shared remote to keep the record on, and nothing is written.

Functions

func Holder

func Holder() string

Holder is this account's holder id, the form a reservation names its holder by (claim.KeptHolderID: read, never minted), or "" when none can be read: a record then names no writer.

Types

type Batch

type Batch struct {
	HandBacks []HandBack
	Decisions []Decision
}

Batch is the records one write keeps, all in one commit.

type Decision

type Decision struct {
	SchemaVersion int       `json:"schema_version"`
	Kind          string    `json:"kind"`
	At            time.Time `json:"at"`
	Holder        string    `json:"holder,omitempty"`

	// A drain judgement: the issue, the question put, the answer and the
	// hand-back kind a yes named, the model that answered, the drain's rule
	// record and the reason given.
	Issue      string `json:"issue,omitempty"`
	Question   string `json:"question,omitempty"`
	Answer     string `json:"answer,omitempty"`
	AnswerKind string `json:"answer_kind,omitempty"`
	Model      string `json:"model,omitempty"`
	Rule       string `json:"rule,omitempty"`
	Reason     string `json:"reason,omitempty"`

	// A merge-gate decision: where it was asked, the pull request and its
	// head, and the gate's answer as the gate gave it: whether it armed, the
	// method, its reason, and whether it rests on an answer the gate could
	// not read; and the facts the gate set as it decided: the mode it ran in,
	// whether the author can write to the repository and whether a person's
	// approval counted (both always present on a merge-gate record).
	Site            string `json:"site,omitempty"`
	PR              int    `json:"pr,omitempty"`
	Head            string `json:"head,omitempty"`
	Arm             bool   `json:"arm,omitempty"`
	Method          string `json:"method,omitempty"`
	Why             string `json:"why,omitempty"`
	Unread          bool   `json:"unread,omitempty"`
	Mode            string `json:"mode,omitempty"`
	AuthorCanWrite  *bool  `json:"author_can_write,omitempty"`
	ApprovalCounted *bool  `json:"approval_counted,omitempty"`
}

Decision is one of the automated facilitator's decisions, as decisions/ holds it: the drain's judgement a model answered (KindDrainJudgement) or the merge gate's in auto mode over a pull request whose author can write, with no person's approval counted (KindMergeGate). Each kind sets its own fields and leaves the other's empty.

type HandBack

type HandBack struct {
	SchemaVersion int       `json:"schema_version"`
	At            time.Time `json:"at"`
	Issue         string    `json:"issue"`
	// From, Kind and Route are the drain's own words for where the hand-back
	// came from, what kind it is and where it went.
	From  string `json:"from"`
	Kind  string `json:"kind"`
	Route string `json:"route"`
	// Rule is the rule a field hand-back names; DrainRule the decision record
	// the drain read its rule from.
	Rule      string `json:"rule,omitempty"`
	DrainRule string `json:"drain_rule,omitempty"`
	Reason    string `json:"reason"`
	// PR is the lane's pull request, when the lane opened one; RunID the
	// lane's run.
	PR    int    `json:"pr,omitempty"`
	RunID string `json:"run_id,omitempty"`
	// Blob is the issue record's blob on origin's default branch when the
	// hand-back was routed.
	Blob   string `json:"blob,omitempty"`
	Holder string `json:"holder,omitempty"`
}

HandBack is one of the drain's hand-backs, as handbacks/ holds it.

type PushResult

type PushResult struct {
	// Commit is origin's copy after the push, "" when nothing was pushed.
	Commit string
	// Pushed counts the records the push carried that origin lacked.
	Pushed int
	// Unreadable names each file origin or the local copy held under a
	// record's name whose content its name does not give: the copy whose
	// content it does give is kept, and origin's when neither does.
	Unreadable []string
}

PushResult is what one push carried to origin.

type Records

type Records struct {
	HandBacks  []HandBack
	Decisions  []Decision
	Unreadable []string
}

Records is what the store holds at one ref, read strictly: every file whose name and content are one this package writes, and Unreadable naming each file that is not. A ref that cannot be read is an error.

type Written

type Written struct {
	// Wrote counts the records the write committed, and Kept those the local
	// copy already held.
	Wrote, Kept int
	// Failed counts the records the write tried to commit and could not, and
	// Err says why; Err is ErrNoOrigin, with nothing counted, for a checkout
	// with no remote named origin.
	Failed int
	Err    error
	// Unkeepable says, for each record the store cannot keep at all (no
	// time, an id outside the store's form), why.
	Unkeepable []string
}

Written is what one write did with its batch.

func Write

func Write(parent context.Context, root string, b Batch) Written

Write commits every record of b the local copy does not already hold, as one commit on the local copy, touching no HEAD, index or working tree and reaching no network. A record is already held when the local copy holds a file of its name with its content, and a merge-gate decision when the local copy holds one over the same pull request and head with the same answer, at any time (gateHeld); nothing read from origin's copy is read for either. A file of a record's name with other content is replaced by the record. The local copy is moved only from the value the write read (a compare-and-swap): another writer of the checkout that moved it first makes this one read it again, maxTries times in all. Every git command runs under parent and WriteTimeout.

Jump to

Keyboard shortcuts

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