devharness

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 14 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 devharness is the engine behind `patchy dev`: a local, in-memory stand-in for the pipeline that generic-integration authors test against.

The harness hosts the real receiver code path — the same webhook server, HMAC authenticator, decoder, and validating source handler the integration-controller runs — but where the controller would write Finding resources, the harness keeps findings in memory and immediately exercises the two outbound legs of the contract: the enhancer call and the resolver write-back. No Kubernetes API is involved anywhere.

What is deliberately not emulated: accumulation and duplicate-merge into Finding resources, tracking-issue projection, and the investigation that separates enhancement from dismissal in production. Where the timing or shape differs from the real pipeline (resolve fires immediately, one alert per call), the emitted events say so.

Index

Constants

This section is empty.

Variables

View Source
var CanonicalVerdict = source.Verdict{
	Kind:    source.VerdictIgnore,
	Reason:  "false positive",
	Comment: "Dismissed by patchy: investigation recommended ignore.",
}

CanonicalVerdict is the verdict write-back patchy sends today, verbatim from the integration-controller's resolveAlerts: dismissal after an investigation recommended ignore is the only path that resolves.

Functions

func Enhance

func Enhance(ctx context.Context, c *generic.Client, name string, findings []source.Finding, emit func(Event)) error

Enhance sends one enhancement request per finding, emitting an event per call, and returns the joined failures.

func NewClient

func NewClient(url string, secret []byte, timeout time.Duration) (*generic.Client, error)

NewClient builds the signed outbound client for one leg or a one-shot invocation; the zero timeout means the contract default of 60s.

func ParseFindings

func ParseFindings(ctx context.Context, name string, payload []byte) ([]source.Finding, error)

ParseFindings validates one findings payload — the same wire envelope the webhook receives, so fixture files work in both places — through the real source handler, under the given integration name.

func Resolve

func Resolve(ctx context.Context, c *generic.Client, name string, findings []source.Finding, emit func(Event)) error

Resolve sends one verdict write-back per finding, emitting an event per call, and returns the joined failures.

Types

type Config

type Config struct {
	// Addr is the listen address; ":0" picks an ephemeral port, reported by
	// the listening event.
	Addr string
	// Name is the integration name: the path segment, the source id, and
	// the Integration field of every outbound request.
	Name string
	// Secret is the shared HMAC secret, used in both directions.
	Secret []byte
	// MinSeverity drops findings below this level, exactly as the
	// Integration's spec.generic.source.minSeverity would; empty admits
	// everything.
	MinSeverity string
	// EnhanceURL is the author's enhancer endpoint; empty disables the leg.
	EnhanceURL string
	// EnhanceTimeout bounds each enhancer call; zero means the contract
	// default of 60s.
	EnhanceTimeout time.Duration
	// ResolveURL is the author's resolver endpoint; empty disables the leg.
	ResolveURL string
	// ResolveTimeout bounds each resolver call; zero means 60s.
	ResolveTimeout time.Duration
	// ResolveDelay pauses between a finding's enhance and resolve calls.
	ResolveDelay time.Duration
	// AutoResolve fires the resolver write-back for each ingested finding;
	// off, findings are only retained and the author resolves them with the
	// one-shot command.
	AutoResolve bool
	// Log receives server diagnostics — why a delivery 401'd, handler
	// failures. The wire deliberately gives senders no oracle, so this is
	// where the author looks. Nil discards.
	Log *slog.Logger
	// Events receives every pipeline event for rendering. Deliveries are
	// handled by a single worker, so calls never overlap. Nil discards.
	Events func(Event)
}

Config configures a Harness.

type Event

type Event struct {
	// Kind discriminates: listening, delivery, finding, enhance, resolve,
	// or error.
	Kind string `json:"kind"`
	// WebhookURL is the full inbound URL (listening events).
	WebhookURL string `json:"webhookUrl,omitempty"`
	// DeliveryID identifies the inbound delivery (delivery events).
	DeliveryID string `json:"deliveryId,omitempty"`
	// Delivered and Ingested count a delivery's findings before and after
	// the severity floor — a gap means silent min-severity drops, which is
	// contract behavior worth surfacing.
	Delivered int `json:"delivered,omitempty"`
	Ingested  int `json:"ingested,omitempty"`
	// Finding is the ingested finding (finding events).
	Finding *source.Finding `json:"finding,omitempty"`
	// EnhanceRequest/EnhanceResponse are the enhancer exchange (enhance
	// events); a nil response means 204 or an empty body.
	EnhanceRequest  *pkggeneric.EnhanceRequest  `json:"enhanceRequest,omitempty"`
	EnhanceResponse *pkggeneric.EnhanceResponse `json:"enhanceResponse,omitempty"`
	// ResolveRequest is the write-back sent (resolve events).
	ResolveRequest *pkggeneric.ResolveRequest `json:"resolveRequest,omitempty"`
	// Note carries emulation caveats and contract reminders.
	Note string `json:"note,omitempty"`
	// Err is the failure of this step, when it failed.
	Err string `json:"err,omitempty"`
}

Event is one observable step of the harness pipeline; it doubles as the NDJSON line for machine-readable output.

type Harness

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

Harness hosts the receiver and drives the outbound legs.

func New

func New(cfg Config) (*Harness, error)

New builds a Harness. Clients are built eagerly so a missing secret or a malformed URL fails here, before anything listens.

func (*Harness) Findings

func (h *Harness) Findings() []source.Finding

Findings snapshots the retained findings, in ingest order.

func (*Harness) Run

func (h *Harness) Run(ctx context.Context) error

Run listens, serves until ctx is cancelled, then drains gracefully. The listening event reports the bound address, so ":0" works.

func (*Harness) Summary

func (h *Harness) Summary() Summary

Summary snapshots the run's counters.

type Summary

type Summary struct {
	Deliveries      int `json:"deliveries"`
	Findings        int `json:"findings"`
	EnhanceCalls    int `json:"enhanceCalls"`
	EnhanceFailures int `json:"enhanceFailures"`
	ResolveCalls    int `json:"resolveCalls"`
	ResolveFailures int `json:"resolveFailures"`
}

Summary counts what a run processed, for the shutdown line.

Jump to

Keyboard shortcuts

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