validate

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package validate checks a pipeline config without running it.

Every check is offline: no broker, no sink, no network, and nothing from the config's commands block executes. That is what lets CI, a pre-commit hook, and an agent loop all call it without consequences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaJSON

func SchemaJSON() []byte

SchemaJSON returns the embedded config schema. `config example` renders it as a commented skeleton.

Types

type Check

type Check struct {
	ID     string `json:"id"`
	Status Status `json:"status"`
	Reason string `json:"reason,omitempty"`
}

Check records that one class of validation ran, and what it concluded.

A check that could not run reports StatusSkipped with a Reason, never StatusPass. A consumer must be able to tell "checked and fine" from "not checked", because a model treats an unqualified pass as proof.

type Diagnostic

type Diagnostic struct {
	Code       string    `json:"code"`
	Class      string    `json:"class"`
	Severity   Severity  `json:"severity"`
	Message    string    `json:"message"`
	Position   *Position `json:"position,omitempty"`
	Context    string    `json:"context,omitempty"`
	DidYouMean []string  `json:"did_you_mean,omitempty"`
	Action     string    `json:"action,omitempty"`
}

Diagnostic is one fault, carrying what a reader needs to fix it without opening the source: the code, where it is, and what to do.

type Position

type Position struct {
	Source   string `json:"source"`
	Line     int    `json:"line"`
	Column   int    `json:"column"`
	Rendered bool   `json:"rendered,omitempty"`
}

Position points at the place in the user's own text a diagnostic refers to.

Rendered marks a position measured against the rendered config rather than the file on disk. A template with control structures shifts line numbers, and reporting a shifted line as a source line sends an editor -- human or model -- to the wrong place.

type Report

type Report struct {
	Config      string       `json:"config,omitempty"`
	OK          bool         `json:"ok"`
	Checks      []Check      `json:"checks"`
	Diagnostics []Diagnostic `json:"diagnostics"`
	Variables   *Variables   `json:"variables,omitempty"`
}

Report is the result of a validation job.

func Validate

func Validate(ctx context.Context, req Request) (Report, error)

Validate checks a config offline and reports everything it finds.

It returns an error only when the request itself is unusable. A config that is wrong is a Report with diagnostics, not an error: the caller wants the whole list, and an agent wants it in one turn.

func (*Report) Add

func (r *Report) Add(d Diagnostic)

Add appends a diagnostic.

func (*Report) Finish

func (r *Report) Finish()

Finish orders the diagnostics and computes OK.

The ordering is not cosmetic. jsonschema builds an error's causes from a map, so the same config reports the same faults in a different order on every run. A report that reorders cannot be diffed between runs, cached, or compared in a test, so diagnostics are sorted by where they are: top of the file first, and anything without a position ahead of everything else.

Only an error clears OK. A warning is advice, and gating CI on advice makes the advice unwelcome.

func (*Report) SetCheck

func (r *Report) SetCheck(id string, status Status, reason string)

SetCheck records a check's outcome, replacing any earlier entry for the same id so a check cannot appear twice.

func (*Report) Vars

func (r *Report) Vars() *Variables

Vars returns the variable report, or nil when the template never parsed.

type Request

type Request struct {
	Path   string            `json:"path,omitempty"`
	Config string            `json:"config"`
	Vars   map[string]string `json:"vars,omitempty"`
}

Request is one validation job.

Config carries the config's text. Path names the file for diagnostics only. The split is deliberate: the pull-based control plane hands a job to an instance that shares no filesystem with the submitter (#178).

type Severity

type Severity string

Severity separates a fault that must block from advice that must not.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
)

type Status

type Status string

Status is the outcome of one check.

const (
	StatusPass    Status = "pass"
	StatusFail    Status = "fail"
	StatusSkipped Status = "skipped"
)

type Variables

type Variables struct {
	Referenced []string `json:"referenced"`
	Provided   []string `json:"provided"`
	Missing    []string `json:"missing"`
	Unused     []string `json:"unused,omitempty"`
}

Variables reports the template's variable use from both sides.

Unused is what makes a typo name itself: a missing SQLFLOW_AZURE_CONNECTION_STRING alongside an unread SQLFLOW_AZURE_STORAGE_CONNECTION_STRING is a misspelling, and reporting only the missing half leaves the reader to guess (#120).

Jump to

Keyboard shortcuts

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