cone

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cone computes a change's cone within one estate (GitHub issue #1956): the blocks a git diff changes, deletes or refactors, and every block that reads one of them in the head configuration. A plan given the cone as targets lets the plan graph add the ancestors itself, so this package writes no second targeting rule.

The diff is block-level over the root module: two blocks with the same type and labels are the same node, and a node changed when its source text, whitespace aside, differs. A local module call changed when any file under its source directory did. tfvars change the variables they set. A guard names the conditions under which a cone cannot be trusted, and a caller that sees one plans the whole estate instead.

Index

Constants

View Source
const (
	GuardNoBase       = "no-base"
	GuardProvider     = "provider-changed"
	GuardLockFile     = "lock-file-changed"
	GuardLiveBlock    = "live-block-changed"
	GuardTerraform    = "terraform-block-changed"
	GuardShare        = "cone-too-large"
	GuardUnplaced     = "refactor-unplaced"
	GuardEmpty        = "empty-cone"
	GuardParse        = "config-unreadable"
	GuardSweep        = "sweep-outside-cone"
	GuardNonNative    = "json-config"
	GuardModuleRemote = "remote-module-changed"
)

Guard reasons, as the JSON document and the plan note name them.

View Source
const DefaultShare = 0.30

DefaultShare is the largest share of the estate's blocks a cone may hold before the guard plans everything instead (the research's 30%).

Variables

This section is empty.

Functions

func CoManaged

func CoManaged(typ string) []string

CoManaged exposes the table for tests and docs.

func MissedUpdates

func MissedUpdates(fullChanges, targets []string) []string

MissedUpdates is the claim's check (GitHub issue #1956): given the addresses a full plan changes and the cone's targets, it returns the changes no cone target covers. A cone that drops a dependent leaves that dependent's update here; an empty answer is the cone holding.

Types

type Guard

type Guard struct {
	Full   bool   `json:"full"`
	Kind   string `json:"kind,omitempty"`
	Reason string `json:"reason,omitempty"`
}

Guard is the verdict: Full means plan everything, for Reason.

type Options

type Options struct {
	// Dir is the root module's directory, inside a git working tree. The
	// head side is the working tree as it is now, uncommitted edits included,
	// because that is what a plan in Dir reads.
	Dir string
	// Base is the git revision the change is measured against.
	Base string
	// Share overrides DefaultShare when positive.
	Share float64
}

Options is one cone computation.

type Result

type Result struct {
	Schema  int    `json:"schema"`
	Base    string `json:"base"`
	BaseSHA string `json:"base_sha,omitempty"`
	// Changed are the nodes whose source differs, in head-graph terms
	// (resource, data.x.y, module.m, var.v, local.l, output.o).
	Changed []string `json:"changed"`
	// Deleted are block addresses present at Base and absent now.
	Deleted []string `json:"deleted"`
	// Refactor are moved from/to, removed from and import to addresses.
	Refactor []string `json:"refactor"`
	// Widened are blocks added by the co-managed type-pair table.
	Widened []string `json:"widened"`
	// Reach is every node in the cone: Changed plus descendants plus
	// Widened, of every kind.
	Reach []string `json:"reach"`
	// Targets are the resource and module addresses to pass as -target:
	// Reach's targetable members, Deleted and Refactor.
	Targets []string `json:"targets"`
	// Blocks and ConeBlocks size the estate and the cone for the share.
	Blocks     int   `json:"blocks"`
	ConeBlocks int   `json:"cone_blocks"`
	Guard      Guard `json:"guard"`
}

Result is the cone.

func Compute

func Compute(ctx context.Context, o Options) (*Result, error)

Compute reads the diff and returns the cone. An error is returned only when Dir cannot be read at all; everything else that defeats a cone is a guard verdict on the result.

func (*Result) JSON

func (r *Result) JSON() (string, error)

JSON renders the document. Every list is an array, never null.

func (*Result) Text

func (r *Result) Text() string

Text renders the targets one per line, as -target-file reads them, followed by the guard as a comment line.

Jump to

Keyboard shortcuts

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