Documentation
¶
Overview ¶
Package contracts defines the version 1 data and adapter contracts. It does not extract archives, execute tools, or publish output.
Index ¶
- Constants
- func StripPatchPath(value string) (string, error)
- func ValidateBasename(value string) error
- func ValidateRelativePath(value string) error
- type ConfinedInputs
- type ExecuteRequest
- type ExecutionResult
- type Executor
- type Failure
- type FileRecord
- type InputEntry
- type InputError
- type InventoryResult
- type Manifest
- type Operation
- type Options
- type Outcome
- type Patch
- type PatchInventory
- type PatchRequest
- type PatchResult
- type PatchStatus
- type PatchTarget
- type PreparedSource
- type Reason
- type Report
- type RunError
- type Source
- type SourcePreparer
- type SourceRequest
- type SourceResult
- type Stage
- type StagedFile
- type StagedPatch
Constants ¶
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 ¶
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 ValidateRelativePath ¶
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 ¶
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 ¶
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 InputError ¶
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.
type Options ¶
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 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 ¶
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" ReasonUnsupportedTool Reason = "unsupported_tool" ReasonTimeout Reason = "timeout" ReasonCancelled Reason = "cancelled" ReasonOutputExists Reason = "output_exists" ReasonUnsupportedPublication Reason = "unsupported_publication" ReasonOutputWrite Reason = "output_write_failure" )
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.
type RunError ¶
RunError represents invalid input, setup, unsafe input, I/O, tooling or cancellation. Err is diagnostic-only and must never be copied into Report.
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 StagedFile ¶
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
}