Help us shape the future of Go! Take the 2026 Go Developer Survey

baseline

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package baseline guards the integrity of a baseline folder: manifest.json holds the SHA-256 of every file and the hash of the last line of the acceptance log, whose lines are chained by the hash of the line before. A baseline changes only through driftgate (first run, import, accept); verify finds any other change.

The manifest is not a signature: anyone can recompute it. It makes a hand edit visible (verify fails, compare refuses), and a legitimate change then shows in the pull request as a new acceptance line next to the files.

Index

Constants

View Source
const (
	ManifestFile = "manifest.json"
	LogFile      = "acceptances.jsonl"
)

File names inside a baseline folder.

View Source
const Version = 1

Variables

View Source
var ErrNoManifest = errors.New("no " + ManifestFile)

ErrNoManifest means the baseline has no manifest.json (made before manifests existed, or the file was removed).

Functions

func Append

func Append(dir string, a Acceptance) error

Append adds an acceptance as the last line of the log, chained to the line before. The manifest is not rewritten; call Write after.

func Digest

func Digest(dir string) (string, error)

Digest identifies the current content of a baseline: the SHA-256 of its manifest. It is meaningful only for a baseline that verifies.

func SetDigest

func SetDigest(dir string) (string, error)

SetDigest identifies the content of a capture: its records and meta.json. Bodies are named by their hash (or ref) in the records, so the records cover them, and are not read.

func Stamp

func Stamp(dir string) (string, error)

Stamp identifies the state of the files under dir without reading them: the path, size, modification time and mode of each. A baseline whose stamp is the one it had when it verified has not been written since.

func Sums

func Sums(dir string) (map[string]string, error)

Sums returns the SHA-256 of every file under dir by slash path, without the manifest and the log.

func Write

func Write(dir string) error

Write computes and writes the manifest of the baseline in dir.

func WriteFrom

func WriteFrom(dir string, written map[string]string) error

WriteFrom writes the manifest of the baseline in dir from the SHA-256 of its files taken while they were written (slash path → SHA-256 of every file), as Write would compute them; files the manifest leaves out are skipped.

Types

type Acceptance

type Acceptance struct {
	Version    int      `json:"version"`
	At         string   `json:"at"`
	By         string   `json:"by"`
	Reason     string   `json:"reason"`
	Ref        string   `json:"ref,omitempty"`
	Requests   []string `json:"requests"`
	Signatures []string `json:"signatures"`
	Capture    string   `json:"capture"`
	Commit     string   `json:"commit,omitempty"`
	// Prev is the SHA-256 of the line before (empty on the first line), so
	// an edited, removed or inserted line breaks the chain.
	Prev string `json:"prev,omitempty"`
}

Acceptance is one line of acceptances.jsonl.

func Log

func Log(dir string) ([]Acceptance, error)

Log reads the acceptances recorded so far.

type LogState

type LogState struct {
	Lines int    `json:"lines"`
	Last  string `json:"last"`
}

LogState pins the acceptance log: its number of lines and the SHA-256 of the last one (empty when there are none).

type Manifest

type Manifest struct {
	Version int               `json:"version"`
	Files   map[string]string `json:"files"` // slash path → SHA-256; without the manifest and the log
	Log     LogState          `json:"acceptances"`
}

Manifest is manifest.json.

func Read

func Read(dir string) (*Manifest, error)

Read reads the manifest; ErrNoManifest when there is none.

type Result

type Result struct {
	Files       int      // files listed in the manifest
	Acceptances int      // lines in the acceptance log
	Problems    []string // empty when the baseline is intact
	// LineEndings: some changed files differ only in their line endings
	// (CRLF where the manifest has LF): git converted them on checkout
	// (core.autocrlf, on by default with Git for Windows).
	LineEndings bool
}

Result is what Verify found.

func Verify

func Verify(dir string) (*Result, error)

Verify checks the files against the manifest (changed, missing, extra) and the acceptance log against its chain and the manifest. A missing manifest returns ErrNoManifest.

func (*Result) OK

func (r *Result) OK() bool

OK reports whether the baseline is intact.

Jump to

Keyboard shortcuts

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