sourceobservation

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 18 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 sourceobservation captures the mutable source state that produced a generation. A publication stores that observation and compares it again before CURRENT moves, so readers never receive a graph as current when one of its inputs changed while it was being built.

Index

Constants

View Source
const (
	// LegacyVersion is the source observation schema written before published
	// topology compositions were recorded. It remains readable as incomplete.
	LegacyVersion = 1
	// CompositionVersion is the source observation schema that first recorded
	// a generation-owned topology composition. It remains readable because it
	// cannot contain an overlay declaration introduced later.
	CompositionVersion = 2
	// CurrentVersion is the schema version of a stored source observation.
	CurrentVersion = 3
	// FileName is the fixed filename a generation uses for its source inputs.
	FileName = "source-observations.json"
)

Variables

View Source
var (
	// ErrAbsent reports an input that was not present while an observation was
	// captured. It is distinct from an unreadable input: both stop publication,
	// but the remedy is different.
	ErrAbsent = errors.New("source input is absent")
	// ErrUnreadable reports an input that existed but could not be read
	// completely and therefore cannot support a truthful publication.
	ErrUnreadable = errors.New("source input is unreadable")
	// ErrChanged reports that the source state captured before analysis no
	// longer agrees with the state observed before publication.
	ErrChanged = errors.New("source observations changed during indexing")
	// ErrInvalid reports a stored source observation document that could be
	// read but does not satisfy its persisted schema or integrity checks.
	ErrInvalid = errors.New("source observations are invalid")
)

Functions

func CaptureReusing

func CaptureReusing(
	ctx context.Context,
	profile, resolverVersion, analyzerFingerprint string,
	repositories []workspace.Repository,
	signatures Signatures,
) (Manifest, []workspace.Repository, Reuse, error)

CaptureReusing observes the repositories again, taking the digest of a tree from its signature when the signature can prove that reading the tree would give the digest it already has, and reading the tree otherwise. A repository is decided on its own: one that moved is read, one that did not is not.

The manifest it returns is the manifest Capture would return. Everything that is not the content digest -- the Git state, the policy, the composition -- is observed again exactly as Capture does it.

func CaptureWithSignatures

func CaptureWithSignatures(
	ctx context.Context,
	profile, resolverVersion, analyzerFingerprint string,
	repositories []workspace.Repository,
) (Manifest, []workspace.Repository, Signatures, error)

CaptureWithSignatures is CaptureWithRepositories that also returns the signature of every tree it read. It is the first observation of a pass that will verify with CaptureReusing.

func Compare

func Compare(expected, actual Manifest) error

Compare reports a source state change with the first affected input. The caller supplies observations captured before and after a full pass.

func FileDigest

func FileDigest(ctx context.Context, path string) (string, error)

FileDigest hashes one source input with its byte length, matching the file fingerprint used by the fact cache.

func IsAnalyzedSource

func IsAnalyzedSource(name string) bool

IsAnalyzedSource reports whether a path can change the facts produced by a supported language or the manifests that select those facts.

func IsComponentFile added in v0.10.1

func IsComponentFile(name string) bool

IsComponentFile reports whether a path is a file a TypeScript project is made of that the engine cannot read: a template with a script in it.

It is an analysed source although no analyzer reads it. A pass records which exported names such a file writes (`COMPONENT_FILE_NOT_READ`), so editing, adding or removing one changes the facts: a cached unit or a generation that did not notice kept rows about a file that no longer said that.

func TreeDigest

func TreeDigest(ctx context.Context, root string) (string, error)

TreeDigest hashes every source file and build manifest a language provider may read below root. It deliberately over-approximates language-specific exclusions: omitting a source that a provider may have read could publish a graph that cannot be reproduced, while an extra rebuild is safe.

func Write

func Write(candidatePath string, manifest Manifest) error

Write atomically places one validated manifest in a candidate generation. The generation store syncs the candidate tree before publishing it, so this helper only has to ensure no partial file is observable inside the candidate.

Types

type Manifest

type Manifest struct {
	Version             int      `json:"version"`
	Profile             string   `json:"profile"`
	ResolverVersion     string   `json:"resolver_version"`
	AnalyzerFingerprint string   `json:"analyzer_fingerprint"`
	Sources             []Source `json:"sources"`
	// Composition is optional so generations written before composition
	// persistence remain readable and can be reported as incomplete.
	Composition *TopologyComposition `json:"composition,omitempty"`
}

Manifest is the complete input record for one profile generation. AnalyzerFingerprint identifies the actual analyzer configuration and build; ResolverVersion identifies the graph resolver whose rules produced the facts. Neither is inferred from timestamps.

func Capture

func Capture(
	ctx context.Context,
	profile, resolverVersion, analyzerFingerprint string,
	repositories []workspace.Repository,
) (Manifest, error)

Capture observes every registered repository now. It refreshes Git state instead of trusting state cached when the registry was opened: an edit or a checkout can happen in the interval before indexing starts.

func CaptureWithRepositories

func CaptureWithRepositories(
	ctx context.Context,
	profile, resolverVersion, analyzerFingerprint string,
	repositories []workspace.Repository,
) (Manifest, []workspace.Repository, error)

CaptureWithRepositories returns the provider metadata observed while creating the manifest as well as the manifest itself. The full pass uses the refreshed values when it stamps repository provenance onto merged facts; otherwise a registry opened before a checkout or edit would publish stale commit, branch, or dirty state.

func Read

func Read(generationPath string) (Manifest, error)

Read loads the manifest published with one generation.

func (Manifest) Validate

func (manifest Manifest) Validate() error

Validate checks that the persisted record is complete and each source state retains the deterministic topology observation identity it claims.

type Policy

type Policy struct {
	Languages  []string `json:"languages"`
	Manifests  []string `json:"manifests,omitempty"`
	Roots      []string `json:"roots,omitempty"`
	Exclusions []string `json:"exclusions,omitempty"`
}

Policy records the provider configuration that decides which source files a repository may contribute. The content digest deliberately over-approximates this policy; storing it separately keeps a later diagnostic from guessing whether an excluded or generated input was considered.

type Reuse

type Reuse struct {
	Repositories int
	Reused       int
}

Reuse says how many repositories a CaptureReusing observed and for how many it skipped reading the tree because the signature held.

type Signatures

type Signatures map[string]*TreeSignature

Signatures holds the signature of each repository's tree by repository name.

type Source

type Source struct {
	Repository  string                     `json:"repository"`
	Derived     bool                       `json:"derived,omitempty"`
	Observation topology.SourceObservation `json:"observation"`
	Policy      Policy                     `json:"policy"`
}

Source is one configured repository and the worktree state observed for a generation. Repository is the provider identity used by the graph; the observation carries the mutable worktree identity and its captured state.

type TopologyComposition

type TopologyComposition struct {
	Profile          string               `json:"profile"`
	Repositories     []TopologyRepository `json:"repositories"`
	Worktrees        []TopologyWorktree   `json:"worktrees"`
	OverlayWorktrees []TopologyWorktree   `json:"overlay_worktrees,omitempty"`
}

TopologyComposition is the effective topology membership that selected the sources for a generation. It is separate from the live topology.yaml so a pinned response cannot combine old facts with a later worktree selection.

func NewTopologyComposition

func NewTopologyComposition(value topology.ProfileComposition) (TopologyComposition, error)

NewTopologyComposition converts one validated effective composition into the persisted form stored beside a generation.

func (TopologyComposition) ProfileComposition

func (composition TopologyComposition) ProfileComposition() (topology.ProfileComposition, error)

ProfileComposition reconstructs and validates the effective composition persisted with a generation.

type TopologyRepository

type TopologyRepository struct {
	ID   string `json:"id"`
	Name string `json:"name,omitempty"`
}

TopologyRepository is one stable repository identity recorded with a generation's effective composition.

type TopologyWorktree

type TopologyWorktree struct {
	ID              string `json:"id"`
	Repository      string `json:"repository"`
	Path            string `json:"path"`
	GitDirectory    string `json:"git_directory,omitempty"`
	CommonDirectory string `json:"common_directory,omitempty"`
	Overlays        string `json:"overlays,omitempty"`
}

TopologyWorktree is one selected mutable worktree recorded with a generation's effective composition.

type TreeSignature

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

TreeSignature is the stat of every directory a digest's walk entered and of every analysed file it hashed, taken as the walk went, together with the digest that walk produced. It lives for the length of one pass and is never persisted: the manifest and its digest are the identity of a generation, and this only lets a later observation skip reading a tree it can prove it would read the same.

The stamp of a directory is taken before the directory is listed and the stamp of a file before it is opened, so a change that lands in between leaves a stamp older than the content the digest saw, and the signature reports it.

func TreeDigestSigned

func TreeDigestSigned(ctx context.Context, root string) (string, *TreeSignature, error)

TreeDigestSigned is TreeDigest that also returns the signature of the tree it walked. The signature is recorded by the same walk, so it costs a map insert per entry and no second traversal. A root that is a single file has no signature.

func (*TreeSignature) Unchanged

func (signature *TreeSignature) Unchanged() bool

Unchanged reports whether every directory and file the signature recorded still has the stamp it had. It reads no directory and opens no file.

It answers true only when it can vouch for the tree, and false for everything else: a differing stamp, a missing entry, a failed stat, an entry too new to be trusted, a signature that was never able to vouch. False means "read the tree", never "the tree changed", so it costs time and cannot cost correctness.

Jump to

Keyboard shortcuts

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