validation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package validation provides server-side validation for task inputs.

Index

Constants

This section is empty.

Variables

View Source
var SupportedHarnesses = []string{
	"opencode",
	"claude-code",
	"pi",
	"codewhale",
	"codex",
}

SupportedHarnesses is the set of runner harnesses Chetter can dispatch a task to. An empty harness means "use the runner default" and is always allowed; only non-empty, unrecognized values are rejected so an unknown harness never silently falls back to OpenCode. The set mirrors the runner's own execution.harness validation (see runner/internal/config).

View Source
var SupportedSessionModes = []string{"", "none", "resumable"}

SupportedSessionModes is the set of accepted session_mode values. An empty value is equivalent to "none" (the default).

View Source
var TriggerTypes = []string{"cron", "pr_review", "issue"}

TriggerTypes is the set of recognized trigger types.

Functions

func IsGitHubTriggerType

func IsGitHubTriggerType(t string) bool

IsGitHubTriggerType reports whether the trigger type carries an owner/repo in its config (pr_review or issue).

func ValidOwnerRepo

func ValidOwnerRepo(s string) bool

ValidOwnerRepo reports whether s is a canonical GitHub owner/repo string such as "flatout-works/chetter". It rejects URLs, leading/trailing slashes, empty segments, additional path components, and disallowed characters.

func ValidateTaskEnv

func ValidateTaskEnv(env map[string]string, cfg Config) error

ValidateTaskEnv checks task environment variables against the limits and blocked patterns in cfg. It returns nil if all vars pass, or an error wrapping all violations.

func ValidateTaskInput

func ValidateTaskInput(in TaskInput, limits TaskLimits) error

ValidateTaskInput checks the deterministic fields of a task submission. It returns nil when the input is acceptable, or an error identifying the invalid field. It never inspects secrets: env vars and tokens are out of scope (env is handled by ValidateTaskEnv).

func ValidateTriggerInput

func ValidateTriggerInput(in TriggerInput, limits TaskLimits) error

ValidateTriggerInput checks the deterministic fields of a trigger. It does not duplicate trigger-type-specific required-field checks (cron_expr, repo presence) that the service already enforces; it focuses on shared runtime fields and repo syntax so the same rules apply to every ingress path.

Types

type Config

type Config struct {
	// BlockedPrefixes are name prefixes that are rejected. The check is
	// case-insensitive against the uppercased env var name.
	BlockedPrefixes []string
	// BlockedNames are exact names that are rejected. The check is
	// case-insensitive against the uppercased env var name.
	BlockedNames []string
	// MaxCount is the maximum number of env vars allowed (default 64).
	MaxCount int
	// MaxNameLength is the maximum length of an env var name (default 256).
	MaxNameLength int
	// MaxValueLength is the maximum length of an env var value (default 4096).
	MaxValueLength int
}

Config holds limits and blocked patterns for task environment variable validation. All fields are populated from server configuration at startup.

func Defaults

func Defaults() Config

Defaults returns a Config populated with safe defaults.

type TaskInput

type TaskInput struct {
	Harness     string
	SessionMode string
	PauseReason string
	TTLHours    int
	TimeoutSec  int
}

TaskInput is the validation-relevant subset of a task submission. It is intentionally small so the validation package stays free of service/store imports; callers map their request structs onto it.

type TaskLimits

type TaskLimits struct {
	// MaxTimeoutSec caps a single task's timeout in seconds. Zero disables
	// the upper-bound check.
	MaxTimeoutSec int
	// MaxTTLHours caps a resumable session's TTL in hours. Zero disables the
	// upper-bound check.
	MaxTTLHours int
}

TaskLimits holds documented upper bounds for task/trigger runtime fields. A zero value means "no explicit cap" for that field, so a deployment that does not configure limits only rejects negative/unsupported values.

func DefaultTaskLimits

func DefaultTaskLimits() TaskLimits

DefaultTaskLimits returns documented default limits: a 24h task timeout cap and a 30-day resumable session TTL cap.

type TriggerInput

type TriggerInput struct {
	TriggerType string
	Harness     string
	SessionMode string
	PauseReason string
	TTLHours    int
	TimeoutSec  int
	// Repo is the canonical owner/repo watched by GitHub triggers. It is only
	// validated for pr_review and issue triggers; cron triggers ignore it.
	Repo string
}

TriggerInput is the validation-relevant subset of a trigger create/update.

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError describes a single env var validation failure.

func (ValidationError) Error

func (e ValidationError) Error() string

Jump to

Keyboard shortcuts

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