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 ¶
- Variables
- func Enhance(ctx context.Context, c *generic.Client, name string, findings []source.Finding, ...) error
- func NewClient(url string, secret []byte, timeout time.Duration) (*generic.Client, error)
- func ParseFindings(ctx context.Context, name string, payload []byte) ([]source.Finding, error)
- func Resolve(ctx context.Context, c *generic.Client, name string, findings []source.Finding, ...) error
- type Config
- type Event
- type Harness
- type Summary
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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.
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 ¶
New builds a Harness. Clients are built eagerly so a missing secret or a malformed URL fails here, before anything listens.
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.