verify

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package verify provides hash-verified operations for code graphs.

The verify package implements "paranoid mode" for detecting stale data before graph operations. It uses multiple optimization layers:

  • mtime-first filter (99% of checks become sub-millisecond)
  • Query-scoped verification (only verify files involved in query)
  • Parallel verification (check multiple files concurrently)
  • Verification TTL cache (skip re-verification within short window)

Staleness Detection

Files can become stale through:

  • Agent's own edits (graph immediately outdated)
  • Git operations (checkout, pull, merge)
  • External editors (user edits in VS Code)
  • Build tools (npm install, go generate)

Thread Safety

All types in this package are safe for concurrent use unless documented otherwise.

Index

Constants

View Source
const (
	// InlineSilentThreshold is the max stale files for silent inline rebuild.
	InlineSilentThreshold = 3

	// InlineWithStatusThreshold is the max stale files for inline with status.
	InlineWithStatusThreshold = 10

	// BackgroundPartialThreshold is the max stale files before considering percentage.
	BackgroundPartialThreshold = 50

	// FullRebuildRatio is the percentage of stale files triggering full rebuild.
	FullRebuildRatio = 0.5

	// BackgroundPartialRatio is the percentage triggering background partial rebuild.
	BackgroundPartialRatio = 0.2
)

Strategy thresholds (configurable via environment variables).

View Source
const (
	// DefaultVerificationTTL is how long to cache verification results.
	DefaultVerificationTTL = 500 * time.Millisecond

	// DefaultMtimeResolution is the minimum mtime granularity to trust.
	// Some filesystems (FAT32, NFS) have low resolution (1-2 seconds).
	DefaultMtimeResolution = 2 * time.Second

	// DefaultParallelLimit is the maximum concurrent file verifications.
	DefaultParallelLimit = 10
)

Default configuration values.

Variables

View Source
var ErrNilGraph = errors.New("graph must not be nil")

ErrNilGraph is returned when a nil graph is passed to NewVerifiedQuery.

View Source
var ErrNilManifest = errors.New("manifest must not be nil")

ErrNilManifest is returned when a nil manifest is passed to NewVerifiedQuery.

Functions

func IsInline

func IsInline(strategy RebuildStrategy) bool

IsInline returns true if the strategy can be performed inline.

Inputs:

strategy - The rebuild strategy.

Outputs:

bool - True if inline execution is appropriate.

func NeedsProgress

func NeedsProgress(strategy RebuildStrategy) bool

NeedsProgress returns true if the strategy should show progress.

Inputs:

strategy - The rebuild strategy.

Outputs:

bool - True if progress updates should be shown.

func StrategyDescription

func StrategyDescription(strategy RebuildStrategy) string

StrategyDescription returns a user-friendly description of the strategy.

Inputs:

strategy - The rebuild strategy.

Outputs:

string - Human-readable description.

Types

type CacheOption

type CacheOption func(*VerificationCache)

CacheOption is a functional option for configuring VerificationCache.

func WithCacheTTL

func WithCacheTTL(d time.Duration) CacheOption

WithCacheTTL sets the TTL for cached verification results.

type ErrStaleData

type ErrStaleData struct {
	// StaleFiles contains paths of modified files.
	StaleFiles []string

	// DeletedFiles contains paths of deleted files.
	DeletedFiles []string
}

ErrStaleData is returned when verification detects stale files.

func (*ErrStaleData) Error

func (e *ErrStaleData) Error() string

Error implements the error interface.

func (*ErrStaleData) HasChanges

func (e *ErrStaleData) HasChanges() bool

HasChanges returns true if there are any stale or deleted files.

type ErrVerificationFailed

type ErrVerificationFailed struct {
	// Errors contains individual file verification errors.
	Errors []FileVerifyError
}

ErrVerificationFailed is returned when verification encounters errors.

func (*ErrVerificationFailed) Error

func (e *ErrVerificationFailed) Error() string

Error implements the error interface.

type FileVerifyError

type FileVerifyError struct {
	// Path is the file that couldn't be verified.
	Path string

	// Err is the underlying error.
	Err error
}

FileVerifyError represents an error verifying a specific file.

func (FileVerifyError) Error

func (e FileVerifyError) Error() string

Error implements the error interface.

type RebuildCallback

type RebuildCallback func(progress RebuildProgress)

RebuildCallback is called to report rebuild progress.

type RebuildProgress

type RebuildProgress struct {
	// Strategy is the rebuild strategy being used.
	Strategy RebuildStrategy

	// TotalFiles is the total number of files to rebuild.
	TotalFiles int

	// Completed is the number of files successfully rebuilt.
	Completed int

	// Failed is the number of files that failed to rebuild.
	Failed int

	// StartedAt is when the rebuild started (Unix milliseconds UTC).
	StartedAt int64
}

RebuildProgress reports the status of a rebuild operation.

func (RebuildProgress) Elapsed

func (p RebuildProgress) Elapsed() time.Duration

Elapsed returns the time since the rebuild started.

func (RebuildProgress) Percent

func (p RebuildProgress) Percent() float64

Percent returns the completion percentage.

type RebuildStrategy

type RebuildStrategy int

RebuildStrategy determines how to handle stale files.

const (
	// StrategyNone indicates no rebuild is needed.
	StrategyNone RebuildStrategy = iota

	// StrategyInlineSilent indicates 1-3 stale files, rebuild silently.
	StrategyInlineSilent

	// StrategyInlineWithStatus indicates 4-10 stale files, show status message.
	StrategyInlineWithStatus

	// StrategyBackgroundPartial indicates 11-50 stale files or >20% of files,
	// rebuild in background with progress updates.
	StrategyBackgroundPartial

	// StrategyFullRebuild indicates >50% stale files, full rebuild from scratch.
	StrategyFullRebuild
)

func DetermineRebuildStrategy

func DetermineRebuildStrategy(staleCount, totalFiles int) RebuildStrategy

DetermineRebuildStrategy determines the appropriate rebuild strategy based on the number of stale files and total files in the graph.

Description:

Analyzes the verification result to determine how to handle stale files.
The strategy balances user experience (quick responses) with accuracy
(fresh data).

Inputs:

staleCount - Number of stale or deleted files.
totalFiles - Total number of files in the manifest/graph.

Outputs:

RebuildStrategy - The recommended strategy for handling staleness.

Strategy Rules:

0 stale          → StrategyNone (no action needed)
1-3 stale        → StrategyInlineSilent (rebuild silently, ~20-50ms)
4-10 stale       → StrategyInlineWithStatus (show "updating...")
11-50 stale      → StrategyBackgroundPartial (async rebuild)
>20% stale       → StrategyBackgroundPartial (async rebuild)
>50% stale       → StrategyFullRebuild (complete rebuild)

Example:

strategy := DetermineRebuildStrategy(2, 100)  // StrategyInlineSilent
strategy := DetermineRebuildStrategy(15, 100) // StrategyBackgroundPartial
strategy := DetermineRebuildStrategy(60, 100) // StrategyFullRebuild

func DetermineRebuildStrategyFromResult

func DetermineRebuildStrategyFromResult(result *VerifyResult, totalFiles int) RebuildStrategy

DetermineRebuildStrategyFromResult is a convenience function that determines strategy from a VerifyResult.

Description:

Extracts stale count from the VerifyResult and determines the
appropriate rebuild strategy.

Inputs:

result - The verification result.
totalFiles - Total number of files in the manifest/graph.

Outputs:

RebuildStrategy - The recommended strategy.

func (RebuildStrategy) String

func (s RebuildStrategy) String() string

String returns a human-readable strategy description.

type VerificationCache

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

VerificationCache caches recent verification results to avoid redundant checks during rapid-fire queries.

Thread Safety:

VerificationCache is safe for concurrent use.

func NewVerificationCache

func NewVerificationCache(opts ...CacheOption) *VerificationCache

NewVerificationCache creates a new VerificationCache.

Description:

Creates a cache for storing recent verification results. Files verified
within the TTL period will not be re-verified, improving performance
for rapid successive queries.

Inputs:

opts - Optional configuration. Default TTL is 500ms.

Outputs:

*VerificationCache - The new cache instance.

Thread Safety:

The returned cache is safe for concurrent use.

func (*VerificationCache) Cleanup

func (c *VerificationCache) Cleanup() int

Cleanup removes expired entries from the cache.

Description:

Removes entries older than the TTL. This can be called periodically
to prevent memory growth in long-running processes.

Outputs:

int - The number of entries removed.

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) Invalidate

func (c *VerificationCache) Invalidate(path string)

Invalidate removes a single file from the cache.

Description:

Removes the verification record for a specific file, forcing
re-verification on the next check.

Inputs:

path - The file path to invalidate.

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) InvalidateAll

func (c *VerificationCache) InvalidateAll()

InvalidateAll clears all cached verification results.

Description:

Removes all verification records. This should be called after
operations that may change many files (git checkout, pull, etc.).

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) MarkVerified

func (c *VerificationCache) MarkVerified(path string)

MarkVerified records that a file has been verified.

Description:

Records the current time as the verification time for the file.
Subsequent calls to NeedsVerification will return false until
the TTL expires.

Inputs:

path - The file path that was verified.

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) MarkVerifiedBatch

func (c *VerificationCache) MarkVerifiedBatch(paths []string)

MarkVerifiedBatch records multiple files as verified.

Description:

Efficiently records verification for multiple files with a single
lock acquisition.

Inputs:

paths - The file paths that were verified.

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) NeedsVerification

func (c *VerificationCache) NeedsVerification(path string) bool

NeedsVerification returns true if the file should be verified.

Description:

Checks if a file's cached verification has expired. Files verified
within the TTL period return false (no verification needed).

Inputs:

path - The file path to check.

Outputs:

bool - True if verification is needed, false if recently verified.

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) Size

func (c *VerificationCache) Size() int

Size returns the number of entries in the cache.

Thread Safety:

Safe for concurrent use.

func (*VerificationCache) TTL

func (c *VerificationCache) TTL() time.Duration

TTL returns the configured TTL duration.

type VerifiedQuery

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

VerifiedQuery wraps a Graph with automatic pre-query verification.

Description:

VerifiedQuery provides the same query interface as Graph, but
verifies that source files haven't changed before returning results.
This ensures queries never return stale data.

Thread Safety:

VerifiedQuery is safe for concurrent use.

func NewVerifiedQuery

func NewVerifiedQuery(g *graph.Graph, m *manifest.Manifest, v *Verifier) (*VerifiedQuery, error)

NewVerifiedQuery creates a new VerifiedQuery wrapper.

Description:

Wraps a graph and manifest with automatic verification.
All query methods will verify relevant files before execution.

Inputs:

g - The graph to query. Must not be nil.
m - The manifest for verification. Must not be nil.
v - The verifier. If nil, uses a default verifier.

Outputs:

*VerifiedQuery - The wrapped query interface. Never nil on success.
error - ErrNilGraph or ErrNilManifest if inputs are invalid.

Example:

vq, err := NewVerifiedQuery(g, m, nil)
if err != nil {
    return fmt.Errorf("creating verified query: %w", err)
}
result, err := vq.FindCallersByID(ctx, "main.go:main")

Limitations:

Does not clone the graph or manifest. Caller must ensure
these are not modified during the lifetime of VerifiedQuery.

Assumptions:

Graph and manifest are consistent (manifest was built from graph's project).

Thread Safety:

The returned VerifiedQuery is safe for concurrent use.

func (*VerifiedQuery) FindCalleesByID

func (vq *VerifiedQuery) FindCalleesByID(ctx context.Context, symbolID string, opts ...graph.QueryOption) (*graph.QueryResult, error)

FindCalleesByID returns all symbols called by the given function/method.

Description:

Verifies the target symbol's file before finding callees.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
symbolID - ID of the function/method to find callees for.
opts - Query options (Limit, Timeout).

Outputs:

*graph.QueryResult - Symbols called by the target.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) FindCalleesByName

func (vq *VerifiedQuery) FindCalleesByName(ctx context.Context, name string, opts ...graph.QueryOption) (map[string]*graph.QueryResult, error)

FindCalleesByName returns callees for all symbols with the given name.

Description:

Verifies all files containing symbols with the given name.
Returns ErrStaleData if any relevant file has changed.

Inputs:

ctx - Context for cancellation.
name - Symbol name to find callees for.
opts - Query options (Limit, Timeout).

Outputs:

map[string]*graph.QueryResult - Map of symbolID to callees.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) FindCallersByID

func (vq *VerifiedQuery) FindCallersByID(ctx context.Context, symbolID string, opts ...graph.QueryOption) (*graph.QueryResult, error)

FindCallersByID returns all symbols that call the given function/method.

Description:

Verifies the target symbol's file before finding callers.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation. Must not be nil.
symbolID - ID of the function/method to find callers for.
opts - Query options (Limit, Timeout).

Outputs:

*graph.QueryResult - Symbols that call the target.
error - ErrStaleData if file changed, or other error.

Limitations:

Only verifies the target symbol's file, not caller files.
Callers from stale files may still be returned.

Assumptions:

symbolID format is "filepath:name" or similar graph-specific format.

Thread Safety:

Safe for concurrent use.

func (*VerifiedQuery) FindCallersByName

func (vq *VerifiedQuery) FindCallersByName(ctx context.Context, name string, opts ...graph.QueryOption) (map[string]*graph.QueryResult, error)

FindCallersByName returns callers for all symbols with the given name.

Description:

Verifies all files containing symbols with the given name.
Returns ErrStaleData if any relevant file has changed.

Inputs:

ctx - Context for cancellation.
name - Symbol name to find callers for.
opts - Query options (Limit, Timeout).

Outputs:

map[string]*graph.QueryResult - Map of symbolID to callers.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) FindImplementationsByID

func (vq *VerifiedQuery) FindImplementationsByID(ctx context.Context, interfaceID string, opts ...graph.QueryOption) (*graph.QueryResult, error)

FindImplementationsByID returns all implementations of the given interface.

Description:

Verifies the interface's file before finding implementations.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
interfaceID - ID of the interface to find implementations for.
opts - Query options (Limit, Timeout).

Outputs:

*graph.QueryResult - Types that implement the interface.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) FindImplementationsByName

func (vq *VerifiedQuery) FindImplementationsByName(ctx context.Context, name string, opts ...graph.QueryOption) (map[string]*graph.QueryResult, error)

FindImplementationsByName returns implementations for all interfaces with the given name.

Description:

Verifies all files containing interfaces with the given name.
Returns ErrStaleData if any relevant file has changed.

Inputs:

ctx - Context for cancellation.
name - Interface name to find implementations for.
opts - Query options (Limit, Timeout).

Outputs:

map[string]*graph.QueryResult - Map of interfaceID to implementations.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) FindImporters

func (vq *VerifiedQuery) FindImporters(ctx context.Context, packagePath string, opts ...graph.QueryOption) ([]string, error)

FindImporters returns all files that import the given package.

Description:

Verifies the manifest before finding importers.
This is a lightweight verification since we're looking for imports.

Inputs:

ctx - Context for cancellation.
packagePath - Package path to find importers for.
opts - Query options (Limit, Timeout).

Outputs:

[]string - File paths that import the package.
error - ErrStaleData if verification fails, or other error.

func (*VerifiedQuery) FindReferencesByID

func (vq *VerifiedQuery) FindReferencesByID(ctx context.Context, symbolID string, opts ...graph.QueryOption) ([]ast.Location, error)

FindReferencesByID returns all locations where the given symbol is used.

Description:

Verifies the symbol's file before finding references.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
symbolID - ID of the symbol to find references for.
opts - Query options (Limit, Timeout).

Outputs:

[]ast.Location - Locations where the symbol is referenced.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) GetCallGraph

func (vq *VerifiedQuery) GetCallGraph(ctx context.Context, symbolID string, opts ...graph.QueryOption) (*graph.TraversalResult, error)

GetCallGraph returns the call graph rooted at the given symbol.

Description:

Verifies the root symbol's file before traversing.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
symbolID - ID of the symbol to start traversal from.
opts - Query options (MaxDepth, Limit, Timeout).

Outputs:

*graph.TraversalResult - The call graph.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) GetDependencyTree

func (vq *VerifiedQuery) GetDependencyTree(ctx context.Context, filePath string, opts ...graph.QueryOption) (*graph.TraversalResult, error)

GetDependencyTree returns the dependency tree for the given file.

Description:

Verifies the file before analyzing dependencies.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
filePath - Path of the file to analyze.
opts - Query options (MaxDepth, Limit, Timeout).

Outputs:

*graph.TraversalResult - The dependency tree.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) GetReverseCallGraph

func (vq *VerifiedQuery) GetReverseCallGraph(ctx context.Context, symbolID string, opts ...graph.QueryOption) (*graph.TraversalResult, error)

GetReverseCallGraph returns the reverse call graph rooted at the given symbol.

Description:

Verifies the root symbol's file before traversing.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
symbolID - ID of the symbol to start traversal from.
opts - Query options (MaxDepth, Limit, Timeout).

Outputs:

*graph.TraversalResult - The reverse call graph.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) GetTypeHierarchy

func (vq *VerifiedQuery) GetTypeHierarchy(ctx context.Context, typeID string, opts ...graph.QueryOption) (*graph.TraversalResult, error)

GetTypeHierarchy returns the type hierarchy for the given type.

Description:

Verifies the type's file before analyzing hierarchy.
Returns ErrStaleData if the source file has changed.

Inputs:

ctx - Context for cancellation.
typeID - ID of the type to analyze.
opts - Query options (MaxDepth, Limit, Timeout).

Outputs:

*graph.TraversalResult - The type hierarchy.
error - ErrStaleData if file changed, or other error.

func (*VerifiedQuery) Graph

func (vq *VerifiedQuery) Graph() *graph.Graph

Graph returns the underlying graph.

func (*VerifiedQuery) Manifest

func (vq *VerifiedQuery) Manifest() *manifest.Manifest

Manifest returns the underlying manifest.

func (*VerifiedQuery) Verifier

func (vq *VerifiedQuery) Verifier() *Verifier

Verifier returns the underlying verifier.

func (*VerifiedQuery) VerifyAll

func (vq *VerifiedQuery) VerifyAll(ctx context.Context) (*VerifyResult, error)

VerifyAll verifies the entire manifest.

Description:

Performs a full verification of all files in the manifest.
Use this when you need to ensure the entire graph is fresh.

Inputs:

ctx - Context for cancellation.

Outputs:

*VerifyResult - The verification result.
error - Non-nil if verification failed unexpectedly.

type Verifier

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

Verifier performs hash-verified operations on code graphs.

Thread Safety:

Verifier is safe for concurrent use.

func NewVerifier

func NewVerifier(opts ...VerifierOption) *Verifier

NewVerifier creates a new Verifier.

Description:

Creates a verifier for detecting stale files in code graphs.
Uses mtime-first optimization for fast checks, falling back
to hash verification when needed.

Inputs:

opts - Optional configuration.

Outputs:

*Verifier - The new verifier instance.

Thread Safety:

The returned verifier is safe for concurrent use.

func (*Verifier) Cache

func (v *Verifier) Cache() *VerificationCache

Cache returns the verification cache for direct access.

func (*Verifier) FastVerify

func (v *Verifier) FastVerify(ctx context.Context, projectRoot, path string, entry manifest.FileEntry) (VerifyResult, error)

FastVerify performs optimized verification of a single file.

Description:

Uses mtime-first optimization: checks modification time before hashing.
If mtime is unchanged and outside the resolution window, assumes file
is unchanged (fast path). If mtime changed or is within resolution
window, computes hash and compares.

Inputs:

ctx - Context for cancellation.
projectRoot - Absolute path to the project root.
path - Relative file path within the project.
entry - The manifest entry containing expected hash and mtime.

Outputs:

VerifyResult - The verification result.
error - Non-nil if verification failed due to unexpected error.

Behavior:

  • If file deleted → Status=StatusStale, DeletedFiles=[path]
  • If mtime unchanged AND outside resolution window → StatusFresh
  • If mtime in future (clock skew) → always compute hash
  • If mtime changed OR within resolution window → compute hash

Thread Safety:

Safe for concurrent use.

func (*Verifier) InvalidateCache

func (v *Verifier) InvalidateCache()

InvalidateCache invalidates the verification cache for all files.

Description:

Clears the verification cache. Should be called after operations
that may change many files (git checkout, pull, etc.).

func (*Verifier) InvalidatePath

func (v *Verifier) InvalidatePath(path string)

InvalidatePath invalidates the verification cache for a single file.

Description:

Removes a single file from the verification cache. Should be called
when a file is known to have changed.

Inputs:

path - The relative file path to invalidate.

func (*Verifier) VerifyFiles

func (v *Verifier) VerifyFiles(ctx context.Context, projectRoot string, entries map[string]manifest.FileEntry) (*VerifyResult, error)

VerifyFiles verifies multiple files in parallel.

Description:

Verifies multiple files concurrently, bounded by parallelLimit.
Individual file errors are collected separately from staleness results.

Inputs:

ctx - Context for cancellation.
projectRoot - Absolute path to the project root.
entries - Map of path to manifest entry for files to verify.

Outputs:

*VerifyResult - Aggregated verification result.
error - Non-nil if context was cancelled.

Behavior:

  • Files are checked concurrently (bounded by GOMAXPROCS or parallelLimit)
  • Latency is max(files), not sum(files)
  • Individual errors add to Errors, don't stop other checks
  • Context cancellation returns partial result

Thread Safety:

Safe for concurrent use.

func (*Verifier) VerifyManifest

func (v *Verifier) VerifyManifest(ctx context.Context, projectRoot string, m *manifest.Manifest) (*VerifyResult, error)

VerifyManifest verifies all files in a manifest against current disk state.

Description:

Compares all files in the manifest against their current state on disk.
Uses parallel verification for performance.

Inputs:

ctx - Context for cancellation.
projectRoot - Absolute path to the project root.
m - The manifest containing expected file hashes.

Outputs:

*VerifyResult - The verification result.
error - Non-nil if context was cancelled.

type VerifierOption

type VerifierOption func(*Verifier)

VerifierOption is a functional option for configuring Verifier.

func WithManifestManager

func WithManifestManager(m *manifest.ManifestManager) VerifierOption

WithManifestManager sets a custom manifest manager.

func WithMtimeResolution

func WithMtimeResolution(d time.Duration) VerifierOption

WithMtimeResolution sets the minimum mtime granularity to trust.

Description:

Some filesystems (FAT32, NFS) have low mtime resolution (1-2 seconds).
Files modified within this window will always be hash-verified even
if mtime appears unchanged.

Inputs:

d - The resolution duration. Default is 2 seconds.

func WithParallelLimit

func WithParallelLimit(limit int) VerifierOption

WithParallelLimit sets the maximum concurrent file verifications.

func WithRebuildCallback

func WithRebuildCallback(fn RebuildCallback) VerifierOption

WithRebuildCallback sets the callback for rebuild progress updates.

func WithVerificationCache

func WithVerificationCache(c *VerificationCache) VerifierOption

WithVerificationCache sets a custom verification cache.

type VerifyResult

type VerifyResult struct {
	// Status is the overall verification status.
	Status VerifyStatus

	// StaleFiles contains paths of files whose content has changed.
	StaleFiles []string

	// DeletedFiles contains paths of files that no longer exist.
	DeletedFiles []string

	// Errors contains files that couldn't be verified.
	Errors []FileVerifyError

	// AllFresh is true if all checked files are unchanged.
	AllFresh bool

	// CheckedAt is when the verification was performed (Unix milliseconds UTC).
	CheckedAt int64

	// Duration is how long the verification took.
	Duration time.Duration

	// FilesChecked is the number of files verified.
	FilesChecked int
}

VerifyResult contains the results of file verification.

func (*VerifyResult) HasChanges

func (r *VerifyResult) HasChanges() bool

HasChanges returns true if any files are stale or deleted.

func (*VerifyResult) StaleCount

func (r *VerifyResult) StaleCount() int

StaleCount returns the total number of changed/deleted files.

type VerifyStatus

type VerifyStatus int

VerifyStatus represents the result of verification.

const (
	// StatusFresh indicates all checked files are unchanged.
	StatusFresh VerifyStatus = iota

	// StatusStale indicates one or more files have changed or been deleted.
	StatusStale

	// StatusPartiallyStale indicates some files are stale, some are fresh.
	StatusPartiallyStale

	// StatusError indicates verification failed due to errors.
	StatusError
)

func (VerifyStatus) String

func (s VerifyStatus) String() string

String returns a human-readable status description.

Jump to

Keyboard shortcuts

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