contracts

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 9 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 contracts defines the version 1 data and adapter contracts. It does not extract archives, execute tools, or publish output.

Index

Constants

View Source
const (
	SchemaVersion              = 1
	MaxManifestBytes    int64  = 1 << 20
	MaxArchiveBytes     int64  = 2 << 30
	MaxPatches                 = 256
	MaxPatchBytes       int64  = 16 << 20
	MaxArchiveEntries          = 100000
	MaxExtractedBytes   int64  = 2 << 30
	MaxPatchLogBytes    int64  = 1 << 20
	PatchTimeoutSeconds        = 30
	NewFileMode         uint32 = 0644
	DirectoryMode       uint32 = 0755
	DigestDefinition           = "" /* 222-byte string literal not displayed */
	EvidenceLimitations        = "" /* 211-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func StripPatchPath

func StripPatchPath(value string) (string, error)

StripPatchPath validates a diff header path and strips exactly one component. /dev/null returns an empty sentinel; the parser must enforce that exactly one side is this sentinel only for additions/deletions. Whitespace is unsupported in patch target paths, including Unicode whitespace; quoted paths are rejected.

func ValidateBasename

func ValidateBasename(value string) error

func ValidateRelativePath

func ValidateRelativePath(value string) error

ValidateRelativePath checks canonical slash paths. It performs no filesystem operations. Filesystem adapters must also reject symlinks in every component with race-safe descriptor-relative traversal, not a check-then-open sequence.

Types

type ConfinedInputs

type ConfinedInputs interface {
	OpenRegular(context.Context, string) (io.ReadCloser, error)
	ReadDir(context.Context, string) ([]InputEntry, error)
}

ConfinedInputs is a read-only view of one already-open input root. All paths are normalized relative slash paths. Implementations reject every symlink component and nonregular input, using race-safe descriptor-relative opens. ReadDir rejects symlink/special entries and exposes all names (including hidden ones). Callers retain and close the root for the whole preparation, preventing root path substitution between source and patch reads. No implementation is in the foundation; prepared bytes are frozen and hashed while copying privately. Read failures use *InputError with UnsafeInput, IO or Cancelled reasons. The preparation caller supplies Source/Inventory stage via FailureFromError.

type ExecuteRequest

type ExecuteRequest struct {
	Source          PreparedSource
	Patches         []StagedPatch
	PatchExecutable string
}

type ExecutionResult

type ExecutionResult struct {
	Patches         []PatchResult
	Files           []FileRecord
	FinalTreeSHA256 string
	Failure         *Failure
	Diagnostics     string
}

ExecutionResult exposes a digest only after the entire sequence succeeds. Content is hashed while readable with intended modes encoded, then final file modes are restored. New regular files use 0644; directories use 0755. Failure stops the sequence; all later patches are not_run, and Files/digest are empty. Diagnostics are bounded operational stderr material, never deterministic report fields or files inside a successful output package.

type Executor

type Executor interface {
	Execute(context.Context, ExecuteRequest) (ExecutionResult, error)
}

type Failure

type Failure struct {
	Stage  Stage  `json:"stage"`
	Reason Reason `json:"reason"`
}

Failure is deterministic evidence: no host paths, timestamps or raw tool logs. Integrity/inventory/application mismatches are expected failures, returned as values with a nil error. Operational failures additionally return *RunError.

func FailureFromError

func FailureFromError(stage Stage, err error) Failure

FailureFromError extracts portable evidence. Unknown errors map to I/O at the supplied stage; diagnostic error strings are never added to the result.

type FileRecord

type FileRecord struct {
	Path   string `json:"path"`
	Mode   string `json:"mode"`
	SHA256 string `json:"sha256"`
}

FileRecord describes a regular file. Mode is exactly four octal digits of intended final 0777 permission bits, not temporary preparation access bits.

type InputEntry

type InputEntry struct {
	Name      string
	Directory bool
}

type InputError

type InputError struct {
	Reason Reason
	Err    error
}

InputError classifies a confined-read failure without assigning an audit stage. Shared input adapters use only ReasonUnsafeInput, ReasonIO or ReasonCancelled. Source/inventory callers attach their own stage, preserving the typed reason.

func (*InputError) Error

func (e *InputError) Error() string

func (*InputError) Unwrap

func (e *InputError) Unwrap() error

type InventoryResult

type InventoryResult struct {
	Patches []StagedPatch
	Failure *Failure
}

type Manifest

type Manifest struct {
	SchemaVersion int     `json:"schema_version" yaml:"schema_version"`
	Source        Source  `json:"source" yaml:"source"`
	PatchDir      string  `json:"patch_dir" yaml:"patch_dir"`
	Patches       []Patch `json:"patches" yaml:"patches"`
}

Manifest describes only declared inputs. Validate also applies to values constructed directly by callers, not just values returned by LoadManifest.

func (Manifest) Validate

func (m Manifest) Validate() error

Validate checks every manifest invariant without opening any path. Audit must call this for direct library callers, including mutated loaded manifests.

type Operation

type Operation string
const (
	OperationModify Operation = "modify"
	OperationAdd    Operation = "add"
	OperationDelete Operation = "delete"
)

type Options

type Options struct {
	InputRoot       string
	OutputDir       string
	PatchExecutable string
}

Options contains local operational paths. These paths are never report fields. OutputDir must be absent, outside InputRoot, with an existing parent. Audit revalidates Manifest and enforces these filesystem rules before publication.

type Outcome

type Outcome string
const (
	OutcomeReproduced Outcome = "reproduced"
	OutcomeFailed     Outcome = "failed"
)

type Patch

type Patch struct {
	ID       string   `json:"id" yaml:"id"`
	File     string   `json:"file" yaml:"file"`
	SHA256   string   `json:"sha256" yaml:"sha256"`
	Upstream string   `json:"upstream" yaml:"upstream"`
	CVEs     []string `json:"cves,omitempty" yaml:"cves,omitempty"`
}

type PatchInventory

type PatchInventory interface {
	Prepare(context.Context, PatchRequest) (InventoryResult, error)
}

type PatchRequest

type PatchRequest struct {
	Inputs     ConfinedInputs
	PatchDir   string
	Patches    []Patch
	StagingDir string
}

type PatchResult

type PatchResult struct {
	Patch
	Status PatchStatus `json:"status"`
	Reason Reason      `json:"reason"`
}

PatchResult preserves manifest/application order and declared provenance. Status describes application only: every patch is not_run on preparation or tooling failure; after execution stops, all remaining patches stay not_run.

type PatchStatus

type PatchStatus string
const (
	PatchNotRun  PatchStatus = "not_run"
	PatchApplied PatchStatus = "applied"
	PatchFailed  PatchStatus = "failed"
)

type PatchTarget

type PatchTarget struct {
	OldPath   string
	NewPath   string
	Operation Operation
}

PatchTarget has already passed strict header validation. Paths are normalized after strip=1, with empty OldPath for addition and empty NewPath for deletion. Modify requires equal old/new paths; renames and mode changes are unsupported. Descriptive Git regular-file modes do not override intended v1 permissions. Multiple supplied mode descriptors must agree. Targets retain diff order. Hunk parsing belongs to patch inventory.

type PreparedSource

type PreparedSource struct {
	Archive       StagedFile
	WorkspaceDir  string
	IntendedModes map[string]uint32
}

PreparedSource files retain owner-read/write access until final digesting. IntendedModes records archive file permissions masked to 0777; directories eventually use 0755. No uid/gid/timestamps are carried forward.

type Reason

type Reason string
const (
	ReasonNone                   Reason = "none"
	ReasonInvalidManifest        Reason = "invalid_manifest"
	ReasonHashMismatch           Reason = "hash_mismatch"
	ReasonInventoryMismatch      Reason = "inventory_mismatch"
	ReasonPatchFailed            Reason = "patch_failed"
	ReasonUnsafeInput            Reason = "unsafe_input"
	ReasonLimitExceeded          Reason = "limit_exceeded"
	ReasonIO                     Reason = "io_failure"
	ReasonToolUnavailable        Reason = "tool_unavailable"
	ReasonUnsupportedTool        Reason = "unsupported_tool"
	ReasonTimeout                Reason = "timeout"
	ReasonCancelled              Reason = "cancelled"
	ReasonOutputExists           Reason = "output_exists"
	ReasonUnsupportedPublication Reason = "unsupported_publication"
	ReasonOutputWrite            Reason = "output_write_failure"
)

func (Reason) Expected

func (r Reason) Expected() bool

Expected identifies failures that are typed results rather than operational errors. A non-nil error always takes precedence over a prior successful result.

func (Reason) Valid

func (r Reason) Valid() bool

type Report

type Report struct {
	SchemaVersion    int           `json:"schema_version"`
	Outcome          Outcome       `json:"outcome"`
	Stage            Stage         `json:"stage"`
	Reason           Reason        `json:"reason"`
	Source           Source        `json:"source"`
	Patches          []PatchResult `json:"patches"`
	FinalTreeSHA256  string        `json:"final_tree_sha256,omitempty"`
	Files            []FileRecord  `json:"files,omitempty"`
	DigestDefinition string        `json:"digest_definition"`
	Limitations      string        `json:"limitations"`
}

Report is portable deterministic evidence. FinalTreeSHA256 and Files are success-only and must be absent on every failed run. Renderers validate these invariants; they do not recompute execution status. Patches preserve order; Files are sorted lexicographically by UTF-8 path bytes.

func (Report) ExitCode

func (r Report) ExitCode(err error) int

ExitCode returns 0 only for complete success, 1 for an expected run failure, and 2 for operational errors or an invalid/incomplete result. A failed stdout write after publication therefore returns 2 while complete output is retained.

func (Report) Validate

func (r Report) Validate() error

Validate checks evidence structure without recomputing application outcomes. It is shared by renderers and exit mapping, so a partial or contradictory result cannot be emitted or treated as successful evidence.

type RunError

type RunError struct {
	Stage  Stage
	Reason Reason
	Err    error
}

RunError represents invalid input, setup, unsafe input, I/O, tooling or cancellation. Err is diagnostic-only and must never be copied into Report.

func (*RunError) Error

func (e *RunError) Error() string

func (*RunError) Unwrap

func (e *RunError) Unwrap() error

type Source

type Source struct {
	Path    string `json:"path" yaml:"path"`
	SHA256  string `json:"sha256" yaml:"sha256"`
	RootDir string `json:"root_dir" yaml:"root_dir"`
}

type SourcePreparer

type SourcePreparer interface {
	Prepare(context.Context, SourceRequest) (SourceResult, error)
}

type SourceRequest

type SourceRequest struct {
	Inputs       ConfinedInputs
	Source       Source
	StagingDir   string
	WorkspaceDir string
}

type SourceResult

type SourceResult struct {
	Source  PreparedSource
	Failure *Failure
}

type Stage

type Stage string
const (
	StageComplete    Stage = "complete"
	StageManifest    Stage = "manifest"
	StageSource      Stage = "source"
	StageInventory   Stage = "inventory"
	StageTool        Stage = "tool"
	StageExecution   Stage = "execution"
	StageDigest      Stage = "digest"
	StagePublication Stage = "publication"
	StageOutput      Stage = "output"
)

func (Stage) Valid

func (s Stage) Valid() bool

type StagedFile

type StagedFile struct {
	Path   string
	SHA256 string
	Size   int64
}

StagedFile identifies the private immutable bytes used after verification. Path is operational-only. SHA256 and Size describe exactly those frozen bytes.

type StagedPatch

type StagedPatch struct {
	Patch   Patch
	Input   StagedFile
	Targets []PatchTarget
}

Jump to

Keyboard shortcuts

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