verification

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package verification provides output verification capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(components ...string) string

GenerateKey creates a baseline key from components.

Types

type BaseCheck

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

BaseCheck provides a base implementation for checks.

func NewCheck

func NewCheck(name string, level EvaluationLevel, runFn func(ctx context.Context, target any) (*CheckResult, error), opts ...CheckOption) *BaseCheck

NewCheck creates a new check.

func (*BaseCheck) Level

func (c *BaseCheck) Level() EvaluationLevel

func (*BaseCheck) Name

func (c *BaseCheck) Name() string

func (*BaseCheck) Run

func (c *BaseCheck) Run(ctx context.Context, target any) (*CheckResult, error)

func (*BaseCheck) Weight

func (c *BaseCheck) Weight() float64

type BaselineManager

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

BaselineManager manages visual baselines.

func NewBaselineManager

func NewBaselineManager(storage BaselineStorage) *BaselineManager

NewBaselineManager creates a baseline manager.

func (*BaselineManager) Load

func (m *BaselineManager) Load(key string) (*Screenshot, error)

Load retrieves a baseline.

func (*BaselineManager) Save

func (m *BaselineManager) Save(key string, screenshot *Screenshot) error

Save stores a baseline.

type BaselineStorage

type BaselineStorage interface {
	Save(key string, screenshot *Screenshot) error
	Load(key string) (*Screenshot, error)
	Delete(key string) error
	List() ([]string, error)
}

BaselineStorage persists baselines.

type Check

type Check interface {
	// Name returns the check identifier.
	Name() string

	// Level returns the evaluation level.
	Level() EvaluationLevel

	// Run executes the check.
	Run(ctx context.Context, target any) (*CheckResult, error)

	// Weight returns the check's importance (0.0-1.0).
	Weight() float64
}

Check represents a single verification check.

type CheckOption

type CheckOption func(*BaseCheck)

CheckOption configures a check.

func WithCheckWeight

func WithCheckWeight(weight float64) CheckOption

WithCheckWeight sets the check weight.

type CheckResult

type CheckResult struct {
	Name     string          `json:"name"`
	Level    EvaluationLevel `json:"level"`
	Passed   bool            `json:"passed"`
	Score    float64         `json:"score"` // 0.0-1.0
	Message  string          `json:"message"`
	Details  map[string]any  `json:"details,omitempty"`
	Duration int64           `json:"duration_ms"`
}

CheckResult contains the outcome of a check.

type CommonChecks

type CommonChecks struct{}

CommonChecks provides commonly used check implementations.

func (CommonChecks) BuildCheck

func (CommonChecks) BuildCheck(buildFn func(ctx context.Context) error) *BaseCheck

BuildCheck creates a syntax check that verifies build success.

func (CommonChecks) LintCheck

func (CommonChecks) LintCheck(lintFn func(ctx context.Context) ([]string, error)) *BaseCheck

LintCheck creates a syntax check for linting.

func (CommonChecks) TestCheck

func (CommonChecks) TestCheck(testFn func(ctx context.Context) (passed, total int, err error)) *BaseCheck

TestCheck creates a behavioral check for tests.

type DiffRegion

type DiffRegion struct {
	X      int    `json:"x"`
	Y      int    `json:"y"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Type   string `json:"type"` // "added", "removed", "changed"
}

DiffRegion represents a region of difference.

type EvaluationLevel

type EvaluationLevel int

EvaluationLevel represents a tier of verification.

const (
	// LevelSyntax checks syntactic correctness.
	LevelSyntax EvaluationLevel = iota
	// LevelSemantic checks logical correctness.
	LevelSemantic
	// LevelBehavioral checks runtime behavior.
	LevelBehavioral
	// LevelVisual checks visual appearance.
	LevelVisual
)

func (EvaluationLevel) String

func (l EvaluationLevel) String() string

String returns the level name.

type EvaluationResult

type EvaluationResult struct {
	Passed          bool                        `json:"passed"`
	TotalScore      float64                     `json:"total_score"`
	MaxScore        float64                     `json:"max_score"`
	NormalizedScore float64                     `json:"normalized_score"` // 0.0-1.0
	LevelScores     map[EvaluationLevel]float64 `json:"level_scores"`
	CheckResults    []*CheckResult              `json:"check_results"`
	FailedLevel     *EvaluationLevel            `json:"failed_level,omitempty"`
	Message         string                      `json:"message"`
}

EvaluationResult contains the complete evaluation outcome.

type Evaluator

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

Evaluator performs hierarchical evaluation.

func NewEvaluator

func NewEvaluator(opts ...EvaluatorOption) *Evaluator

NewEvaluator creates a new evaluator.

func (*Evaluator) AddCheck

func (e *Evaluator) AddCheck(check Check) *Evaluator

AddCheck adds a check to the evaluator.

func (*Evaluator) AddChecks

func (e *Evaluator) AddChecks(checks ...Check) *Evaluator

AddChecks adds multiple checks.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(ctx context.Context, target any) (*EvaluationResult, error)

Evaluate runs hierarchical evaluation.

type EvaluatorOption

type EvaluatorOption func(*Evaluator)

EvaluatorOption configures an evaluator.

func WithRubric

func WithRubric(rubric *Rubric) EvaluatorOption

WithRubric sets the scoring rubric.

func WithStopOnFail

func WithStopOnFail(stop bool) EvaluatorOption

WithStopOnFail configures early termination.

func WithThreshold

func WithThreshold(level EvaluationLevel, threshold float64) EvaluatorOption

WithThreshold sets a pass threshold for a level.

type ImageComparator

type ImageComparator interface {
	Compare(before, after *Screenshot) (*VisualDiff, error)
	SetThreshold(threshold float64)
}

ImageComparator compares two images.

type PixelComparator

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

PixelComparator provides pixel-based image comparison.

func NewPixelComparator

func NewPixelComparator() *PixelComparator

NewPixelComparator creates a pixel comparator.

func (*PixelComparator) Compare

func (c *PixelComparator) Compare(before, after *Screenshot) (*VisualDiff, error)

Compare compares two screenshots pixel by pixel.

func (*PixelComparator) SetThreshold

func (c *PixelComparator) SetThreshold(threshold float64)

SetThreshold sets the comparison threshold.

type Region

type Region struct {
	X      int `json:"x"`
	Y      int `json:"y"`
	Width  int `json:"width"`
	Height int `json:"height"`
}

Region defines a rectangular area.

type Rubric

type Rubric struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Criteria    []RubricCriteria `json:"criteria"`
	MaxScore    float64          `json:"max_score"`
}

Rubric defines scoring criteria.

func DefaultCodeRubric

func DefaultCodeRubric() *Rubric

DefaultCodeRubric returns a standard code quality rubric.

type RubricCriteria

type RubricCriteria struct {
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Weight      float64      `json:"weight"`
	Levels      []ScoreLevel `json:"levels"`
}

RubricCriteria defines a single criterion.

type RubricEvaluator

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

RubricEvaluator evaluates against a rubric.

func NewRubricEvaluator

func NewRubricEvaluator(rubric *Rubric) *RubricEvaluator

NewRubricEvaluator creates a rubric evaluator.

func (*RubricEvaluator) Evaluate

func (e *RubricEvaluator) Evaluate(scores map[string]float64) *RubricResult

Evaluate scores against the rubric.

type RubricResult

type RubricResult struct {
	Rubric     string        `json:"rubric"`
	Scores     []RubricScore `json:"scores"`
	TotalScore float64       `json:"total_score"`
	MaxScore   float64       `json:"max_score"`
	Percentage float64       `json:"percentage"`
	Grade      string        `json:"grade"`
}

RubricResult contains rubric evaluation results.

type RubricScore

type RubricScore struct {
	Criterion string  `json:"criterion"`
	Score     float64 `json:"score"`
	Level     string  `json:"level"`
	Feedback  string  `json:"feedback"`
}

RubricScore represents a score against rubric criteria.

type ScoreLevel

type ScoreLevel struct {
	Score       float64 `json:"score"`
	Description string  `json:"description"`
}

ScoreLevel defines a scoring level within a criterion.

type Screenshot

type Screenshot struct {
	ID        string `json:"id"`
	Path      string `json:"path,omitempty"`
	Data      []byte `json:"data,omitempty"`
	Format    string `json:"format"` // "png", "jpeg", "webp"
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Timestamp int64  `json:"timestamp"`
	Hash      string `json:"hash,omitempty"`
}

Screenshot represents a captured screenshot.

type ScreenshotCapturer

type ScreenshotCapturer interface {
	Capture(ctx context.Context, target string) (*Screenshot, error)
	CaptureElement(ctx context.Context, selector string) (*Screenshot, error)
	CaptureFullPage(ctx context.Context, url string) (*Screenshot, error)
}

ScreenshotCapturer captures screenshots.

type UIElement

type UIElement struct {
	Type   string `json:"type"` // "button", "input", "text", etc.
	Text   string `json:"text,omitempty"`
	Region Region `json:"region"`
}

UIElement represents a detected UI element.

type VerificationResult

type VerificationResult struct {
	Passed   bool            `json:"passed"`
	Before   *Screenshot     `json:"before"`
	After    *Screenshot     `json:"after"`
	Diff     *VisualDiff     `json:"diff,omitempty"`
	Analysis *VisualAnalysis `json:"analysis,omitempty"`
	Message  string          `json:"message"`
}

VerificationResult contains the result of visual verification.

type VisualAnalysis

type VisualAnalysis struct {
	Description string        `json:"description"`
	Elements    []UIElement   `json:"elements,omitempty"`
	Issues      []VisualIssue `json:"issues,omitempty"`
	Score       float64       `json:"score"` // 0.0-1.0
}

VisualAnalysis contains AI analysis of visual content.

type VisualAnalyzer

type VisualAnalyzer interface {
	Analyze(ctx context.Context, screenshot *Screenshot, prompt string) (*VisualAnalysis, error)
	CompareWithContext(ctx context.Context, before, after *Screenshot, prompt string) (*VisualAnalysis, error)
}

VisualAnalyzer analyzes screenshots using AI.

type VisualConfig

type VisualConfig struct {
	// DiffThreshold is the maximum allowed difference (0.0-1.0).
	DiffThreshold float64

	// IgnoreRegions are areas to exclude from comparison.
	IgnoreRegions []Region

	// CompareMode determines comparison strategy.
	CompareMode string // "pixel", "perceptual", "structural"

	// OutputDir for saving diff images.
	OutputDir string

	// SaveBaselines stores passing screenshots as new baselines.
	SaveBaselines bool
}

VisualConfig configures visual verification.

func DefaultVisualConfig

func DefaultVisualConfig() *VisualConfig

DefaultVisualConfig returns sensible defaults.

type VisualDiff

type VisualDiff struct {
	Before     *Screenshot  `json:"before"`
	After      *Screenshot  `json:"after"`
	DiffPixels int          `json:"diff_pixels"`
	DiffPct    float64      `json:"diff_pct"`
	Regions    []DiffRegion `json:"regions,omitempty"`
	Threshold  float64      `json:"threshold"`
	Passed     bool         `json:"passed"`
}

VisualDiff represents a difference between two screenshots.

type VisualIssue

type VisualIssue struct {
	Severity    string `json:"severity"` // "error", "warning", "info"
	Type        string `json:"type"`     // "alignment", "contrast", "overflow", etc.
	Description string `json:"description"`
	Region      Region `json:"region,omitempty"`
}

VisualIssue represents a detected visual issue.

type VisualVerifier

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

VisualVerifier handles visual verification of UI changes.

func NewVisualVerifier

func NewVisualVerifier(config *VisualConfig, capturer ScreenshotCapturer, comparator ImageComparator) *VisualVerifier

NewVisualVerifier creates a new visual verifier.

func (*VisualVerifier) Analyze

func (v *VisualVerifier) Analyze(ctx context.Context, screenshot *Screenshot, prompt string) (*VisualAnalysis, error)

Analyze performs AI-based visual analysis.

func (*VisualVerifier) Capture

func (v *VisualVerifier) Capture(ctx context.Context, target string) (*Screenshot, error)

Capture takes a screenshot of the target.

func (*VisualVerifier) Compare

func (v *VisualVerifier) Compare(before, after *Screenshot) (*VisualDiff, error)

Compare compares two screenshots.

func (*VisualVerifier) Verify

func (v *VisualVerifier) Verify(ctx context.Context, target string, baseline *Screenshot) (*VerificationResult, error)

Verify captures and compares against a baseline.

func (*VisualVerifier) WithAnalyzer

func (v *VisualVerifier) WithAnalyzer(analyzer VisualAnalyzer) *VisualVerifier

WithAnalyzer adds AI-based analysis capability.

Jump to

Keyboard shortcuts

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