engine

package
v0.2.0-alpha20251127 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package engine provides the core orchestration layer for uptool. It manages integration registration, manifest scanning, update planning, and update application. The Engine coordinates concurrent operations across multiple integrations while handling errors and logging.

Package engine provides the core orchestration layer for uptool's dependency scanning and updating. It defines the fundamental types and interfaces used across all integrations, including Manifest, Dependency, UpdatePlan, and the Integration interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyResult

type ApplyResult struct {
	Manifest     *Manifest `json:"manifest"`
	ManifestDiff string    `json:"manifest_diff,omitempty"`
	LockfileDiff string    `json:"lockfile_diff,omitempty"`
	Errors       []string  `json:"errors,omitempty"`
	Applied      int       `json:"applied"`
	Failed       int       `json:"failed"`
}

ApplyResult contains the outcome of applying updates.

type CLIFlags

type CLIFlags struct {
	AllowPrerelease *bool
	UpdateLevel     string
}

CLIFlags represents command-line flag overrides for update behavior.

type Dependency

type Dependency struct {
	Name           string `json:"name"`
	CurrentVersion string `json:"current_version"`
	Constraint     string `json:"constraint,omitempty"`
	Type           string `json:"type"` // direct, dev, peer, optional
	Registry       string `json:"registry,omitempty"`
}

Dependency represents a single dependency in a manifest.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine orchestrates the scan, plan, and update operations.

func NewEngine

func NewEngine(logger *slog.Logger) *Engine

NewEngine creates a new engine with the given integrations.

func (*Engine) GetIntegration

func (e *Engine) GetIntegration(name string) (Integration, bool)

GetIntegration retrieves a registered integration by name.

func (*Engine) ListIntegrations

func (e *Engine) ListIntegrations() []string

ListIntegrations returns all registered integration names.

func (*Engine) Plan

func (e *Engine) Plan(ctx context.Context, manifests []*Manifest) (*PlanResult, error)

Plan generates update plans for all manifests. It applies policy precedence: CLI flags > uptool.yaml > manifest constraints.

func (*Engine) Register

func (e *Engine) Register(integration Integration)

Register adds an integration to the engine.

func (*Engine) Scan

func (e *Engine) Scan(ctx context.Context, repoRoot string, only, exclude []string) (*ScanResult, error)

Scan discovers all manifests across registered integrations.

func (*Engine) SetCLIFlags

func (e *Engine) SetCLIFlags(flags *CLIFlags)

SetCLIFlags configures CLI flag overrides for update behavior. These override manifest constraints but not uptool.yaml policies.

func (*Engine) SetPolicies

func (e *Engine) SetPolicies(policies map[string]IntegrationPolicy)

SetPolicies configures integration policies from uptool.yaml. These policies have the highest precedence in determining allowed updates.

func (*Engine) Update

func (e *Engine) Update(ctx context.Context, plans []*UpdatePlan, dryRun bool) (*UpdateResult, error)

Update applies update plans.

type Impact

type Impact string

Impact describes the severity of an update.

const (
	ImpactNone  Impact = "none"
	ImpactPatch Impact = "patch"
	ImpactMinor Impact = "minor"
	ImpactMajor Impact = "major"
)

Impact levels for update severity

type Integration

type Integration interface {
	// Name returns the integration identifier
	Name() string

	// Detect finds manifest files for this integration
	Detect(ctx context.Context, repoRoot string) ([]*Manifest, error)

	// Plan determines available updates for a manifest.
	// The planCtx parameter provides policy configuration following the precedence order:
	// uptool.yaml policy > CLI flags > manifest constraints.
	// If planCtx is nil, the integration should use default behavior (respect constraints only).
	Plan(ctx context.Context, manifest *Manifest, planCtx *PlanContext) (*UpdatePlan, error)

	// Apply executes the update plan
	Apply(ctx context.Context, plan *UpdatePlan) (*ApplyResult, error)

	// Validate checks if changes are valid (optional)
	Validate(ctx context.Context, manifest *Manifest) error
}

Integration defines the interface for ecosystem integrations.

type IntegrationPolicy

type IntegrationPolicy struct {
	Custom          map[string]interface{} `yaml:",inline" json:"custom,omitempty"`
	Update          string                 `yaml:"update" json:"update"`
	Cadence         string                 `yaml:"cadence,omitempty" json:"cadence,omitempty"`
	Enabled         bool                   `yaml:"enabled" json:"enabled"`
	AllowPrerelease bool                   `yaml:"allow_prerelease" json:"allow_prerelease"`
	Pin             bool                   `yaml:"pin" json:"pin"`
}

IntegrationPolicy contains policy settings that apply to a specific integration.

type Manifest

type Manifest struct {
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
	Path         string                 `json:"path"`
	Type         string                 `json:"type"`
	Dependencies []Dependency           `json:"dependencies"`
	Content      []byte                 `json:"-"`
}

Manifest represents a dependency manifest file.

type PlanContext

type PlanContext struct {
	// Policy contains the integration-specific policy from uptool.yaml.
	// This has medium precedence (after CLI flags) when determining allowed updates.
	Policy *IntegrationPolicy

	// CLIFlags contains any command-line overrides.
	// These have the highest precedence and override all other policy sources.
	CLIFlags *CLIFlags

	// RespectConstraints indicates whether manifest constraints (e.g., ~> 5.0)
	// should be respected when no policy or flag overrides them.
	// Defaults to true.
	RespectConstraints bool
}

PlanContext provides policy and configuration context for planning operations. It implements a precedence order: CLI flags > uptool.yaml policy > manifest constraints. This allows fine-grained control over which updates are allowed.

func NewPlanContext

func NewPlanContext() *PlanContext

NewPlanContext creates a new PlanContext with default settings. By default, constraints are respected when no policy overrides them.

func (*PlanContext) EffectiveAllowPrerelease

func (pc *PlanContext) EffectiveAllowPrerelease() bool

EffectiveAllowPrerelease returns whether prereleases are allowed, following precedence: 1. CLI flags (highest) 2. uptool.yaml policy 3. Default (false)

func (*PlanContext) EffectiveUpdateLevel

func (pc *PlanContext) EffectiveUpdateLevel() string

EffectiveUpdateLevel returns the update level to use, following precedence: 1. uptool.yaml policy (highest) 2. CLI flags 3. Default ("major" - allow all updates, let constraints filter)

func (*PlanContext) GetPolicySource

func (pc *PlanContext) GetPolicySource() PolicySource

GetPolicySource determines the source of the effective policy based on precedence. Returns the policy source following the precedence order: 1. CLI flags (highest) - overrides all other sources 2. uptool.yaml policy - overrides constraints 3. Manifest constraints (when no higher precedence policy exists) 4. Default

func (*PlanContext) ShouldRespectConstraints

func (pc *PlanContext) ShouldRespectConstraints() bool

ShouldRespectConstraints returns whether manifest constraints should be respected. Constraints are always respected unless explicitly disabled.

func (*PlanContext) WithCLIFlags

func (pc *PlanContext) WithCLIFlags(flags *CLIFlags) *PlanContext

WithCLIFlags returns a copy of the context with the given CLI flags.

func (*PlanContext) WithPolicy

func (pc *PlanContext) WithPolicy(p *IntegrationPolicy) *PlanContext

WithPolicy returns a copy of the context with the given policy.

type PlanResult

type PlanResult struct {
	Plans     []*UpdatePlan `json:"plans"`
	Timestamp time.Time     `json:"timestamp"`
	Errors    []string      `json:"errors,omitempty"`
}

PlanResult aggregates all update plans.

type PolicySource

type PolicySource string

PolicySource indicates where the update policy originated from.

const (
	// PolicySourceUptoolYAML indicates the policy came from uptool.yaml (highest precedence)
	PolicySourceUptoolYAML PolicySource = "uptool.yaml"

	// PolicySourceCLIFlag indicates the policy came from a CLI flag
	PolicySourceCLIFlag PolicySource = "cli-flag"

	// PolicySourceConstraint indicates the policy came from manifest constraints (e.g., ~> 5.0)
	PolicySourceConstraint PolicySource = "constraint"

	// PolicySourceDefault indicates the default policy was used
	PolicySourceDefault PolicySource = "default"
)

PolicySource values for policy precedence tracking

type ScanResult

type ScanResult struct {
	Manifests []*Manifest `json:"manifests"`
	Timestamp time.Time   `json:"timestamp"`
	RepoRoot  string      `json:"repo_root"`
	Errors    []string    `json:"errors,omitempty"`
}

ScanResult aggregates all discovered manifests.

type Update

type Update struct {
	Dependency    Dependency   `json:"dependency"`
	TargetVersion string       `json:"target_version"`
	Impact        string       `json:"impact"`
	ChangelogURL  string       `json:"changelog_url,omitempty"`
	PolicySource  PolicySource `json:"policy_source,omitempty"`
	Breaking      bool         `json:"breaking"`
}

Update represents a planned update for a dependency.

type UpdatePlan

type UpdatePlan struct {
	Manifest *Manifest `json:"manifest"`
	Strategy string    `json:"strategy"`
	Updates  []Update  `json:"updates"`
}

UpdatePlan describes planned updates for a manifest.

type UpdateResult

type UpdateResult struct {
	Results   []*ApplyResult `json:"results"`
	Timestamp time.Time      `json:"timestamp"`
	Errors    []string       `json:"errors,omitempty"`
}

UpdateResult aggregates all apply results.

Jump to

Keyboard shortcuts

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