resolver

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 18 Imported by: ? 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 resolver completes a Policyfile install: it takes the evaluated intent of a Policyfile.rb (from cli/policyfile/rubyeval) and produces a fully resolved, push-ready Policyfile.lock.json that is byte-for-byte compatible with what `chef install` writes.

It is the dependency-resolution half the evaluation engine deliberately left out, and it reproduces chef exactly in three places that must interoperate with a Chef Infra Server:

  • Cookbook identifiers (identifier.go, computed by cinc-api): the SHA1 content identifier and its dotted-decimal reinterpretation, matching CookbookProfiler::Identifiers.
  • Version/dependency solving (solver.go): a deterministic backtracking solver over cookbook metadata `depends` and the Policyfile's per-cookbook constraints, selecting the same versions chef's Molinillo-based solver does.
  • Lock serialization (yajl.go): FFI_Yajl pretty output and the canonical revision-string SHA256 that becomes the revision_id.

The path: cookbook source is the primary, fully-supported backend; cookbook metadata is read from metadata.json or evaluated from metadata.rb with the embedded Ruby engine. Other sources (git, Supermarket, chef server) are not yet resolved here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint struct {
	Operator string
	Version  Version
	// contains filtered or unexported fields
}

Constraint is a parsed Semverse::Constraint: an operator and a target version. Satisfaction semantics match the gem, including the "~>" pessimistic operator and the greedy-match guard that keeps pre-releases from satisfying a non-pre-release lower bound.

func ParseConstraint

func ParseConstraint(s string) (Constraint, error)

ParseConstraint parses a single version constraint string (e.g. ">= 1.0.0", "~> 2.0", "= 1.2.3", or a bare "1.2.3" which means "= 1.2.3"), matching Semverse::Constraint. For operators other than "~>"/"~", a missing minor or patch defaults to 0.

func (Constraint) Satisfies

func (c Constraint) Satisfies(target Version) bool

Satisfies reports whether target meets the constraint, following Semverse::Constraint#satisfies?.

type CookbookIdentifier

type CookbookIdentifier struct {
	// Content is the SHA1 hex of the cookbook fingerprint (chef's
	// CookbookProfiler::Identifiers#content_identifier).
	Content string
	// DottedDecimal is the X.Y.Z reinterpretation of the SHA1 used as the
	// cookbook_artifacts/<name>/<id> slug for Chef Infra Server 11.x
	// compatibility (#dotted_decimal_identifier).
	DottedDecimal string
}

CookbookIdentifier holds the two content-addressed identifiers chef computes for a Policyfile cookbook lock.

func ComputeIdentifier

func ComputeIdentifier(cookbookDir, version string) (CookbookIdentifier, error)

ComputeIdentifier computes the identifiers of the cookbook in cookbookDir at version (the version the resolver read from its metadata). cinc-api picks the files, exactly as an upload of the cookbook sends them, and fingerprints them the way chef-cli does. version is passed rather than re-read so that a metadata.rb computing its version, which the Ruby engine has already evaluated, is not refused.

type CookbookSummary

type CookbookSummary struct {
	Name       string
	Version    string
	Identifier string
	Source     string
}

CookbookSummary describes one resolved cookbook for display.

type NoSolutionError

type NoSolutionError struct {
	Cookbook    string
	Constraints []string
	// Requirements pairs each of Constraints with what imposed it.
	Requirements []Requirement
	// Available lists the versions of Cookbook the sources offer, highest
	// first. It is empty when no source provides the cookbook at all.
	Available []string
	Detail    string
}

NoSolutionError reports that the demands and the universe cannot be satisfied together. It names the cookbook that could not be resolved and the constraints that conflicted, matching chef's failure mode (a NoSolutionError listing the unsatisfiable requirements) even though the wording differs.

func (*NoSolutionError) Error

func (e *NoSolutionError) Error() string

type Requirement added in v0.30.0

type Requirement struct {
	Constraint string
	From       string
}

Requirement is one constraint on a cookbook and what imposed it ("the Policyfile", or the "name version" of a cookbook whose metadata depends on it), so a failed solve can say which demands clash.

type Result

type Result struct {
	// LockJSON is the Policyfile.lock.json, encoded byte-identically to chef.
	LockJSON []byte
	// RevisionID is the lock's revision_id (SHA256 of the canonical revision
	// string).
	RevisionID string
	// Cookbooks summarizes each resolved cookbook, sorted by name.
	Cookbooks []CookbookSummary
}

Result is a fully resolved Policyfile lock plus a summary of what was resolved, for the command's human output.

func Resolve

func Resolve(ctx context.Context, eng *rubyeval.Engine, eval *rubyeval.EvaluatedPolicy, rawEval []byte, policyfileDir string) (*Result, error)

Resolve turns an evaluated Policyfile into a push-ready lock. rawEval is the engine's canonical JSON output for eval, used to preserve chef's exact attribute key ordering. policyfileDir is the directory the Policyfile lives in, used to resolve relative path: sources.

type Version

type Version struct {
	Major, Minor, Patch int
	PreRelease          string
	// contains filtered or unexported fields
}

Version is a parsed semantic version. It mirrors Semverse::Version (the gem chef uses), so comparison and constraint satisfaction match chef's resolver bit for bit. Only the major/minor/patch and an optional pre-release are modeled; build metadata is parsed but, like chef, ignored for ordering.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a version string the way Semverse::Version does: a missing minor or patch defaults to 0.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns -1, 0, or +1 as v sorts before, equal to, or after other, following Semverse's ordering: numeric major/minor/patch, then a present pre-release sorts BEFORE the same version without one.

func (Version) IsZero

func (v Version) IsZero() bool

IsZero reports whether the version is 0.0.0 with no pre-release, matching Semverse::Version#zero?, which the constraint's greedy-match guard checks.

func (Version) String

func (v Version) String() string

String renders the version as MAJOR.MINOR.PATCH (with an optional -PRERELEASE), which is the form chef writes into a lock's cookbook version.

Jump to

Keyboard shortcuts

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