domain

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package domain defines the diagnostics domain's ports, DTOs, and constants — the operator-tooling contracts (preflight doctor, config CLI, smoke delivery). It imports only the standard library, the shared kernel, and the validation and routing domains.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMapping means the repository is absent from mappings. Returned
	// before any network call so the operator fixes config first.
	ErrNoMapping = errors.New("smoke: repository not present in mappings")
	// ErrSignatureRejected means the server answered 401 — the secret this
	// command signed with does not match the one the server runs with.
	ErrSignatureRejected = errors.New("smoke: server rejected the signature")
	// ErrUnreachable means the POST never reached a server.
	ErrUnreachable = errors.New("smoke: could not reach the server")
	// ErrUnexpectedStatus means the server answered with a non-200, non-401 code.
	ErrUnexpectedStatus = errors.New("smoke: unexpected response status")
)

Sentinel errors let callers render clear remediation messages and pick exit codes without parsing strings or leaking a stack trace.

Functions

This section is empty.

Types

type ConfigSnapshot

type ConfigSnapshot struct {
	ConfigFile     string
	DatabaseURL    string
	Domain         string
	MessageTTLDays int
	// WebhookSecretSet reports whether the selected git provider's webhook secret
	// is set; WebhookSecretVar names that env var (e.g. GITHUB_WEBHOOK_SECRET,
	// BITBUCKET_WEBHOOK_SECRET) for the report.
	WebhookSecretSet bool
	WebhookSecretVar string
	SlackTokenSet    bool
	// TokenSet reports whether the selected provider's optional read token is set;
	// TokenVar names that env var (GITHUB_TOKEN, BITBUCKET_TOKEN).
	TokenSet         bool
	TokenVar         string
	DatabaseOpenable bool
	DatabaseDetail   string
	Entries          []routingdomain.Entry
	HasPathRules     bool
}

ConfigSnapshot carries the facts the doctor validates about the runtime configuration — never raw secret values, only whether each is set. Built by the infrastructure layer from config.Config so the application stays free of config/store imports.

type Doctor

type Doctor interface {
	Run(ctx context.Context, target string) []Section
}

Doctor runs the preflight checks and returns one Section per group. A non-empty target additionally validates that repository against Slack/GitHub.

type EntrySource

type EntrySource interface {
	Entries() []routingdomain.Entry
}

EntrySource provides the current mapping entries to config-CLI use cases. The routing Provider satisfies this interface.

type ForgedWebhook added in v0.22.0

type ForgedWebhook struct {
	EventHeader string // e.g. "X-GitHub-Event" or "X-Event-Key"
	EventValue  string // e.g. "pull_request" or "pullrequest:created"
	Body        []byte
}

ForgedWebhook is a provider-specific webhook ready to sign and POST: the provider event header (name + value) and the JSON body.

type LockGateway

type LockGateway interface {
	Plan(entries []routingdomain.Entry, force bool) (LockPlan, error)
	Commit(successes []validationdomain.EntryResult, stale []string) error
	CommitTargeted(entry routingdomain.Entry) error
}

LockGateway abstracts the config lock file. Plan reads the lock and diffs it against the current entries; Commit merges successful validation results into the lock (recording each entry's hash + validation time) and drops stale keys; CommitTargeted records a single explicit entry's successful validation.

type LockPlan

type LockPlan struct {
	ToValidate []routingdomain.Entry
	Stale      []string
}

LockPlan is the result of diffing the mappings against the lock: the entries that need (re)validation and the stale lock keys no longer backed by an entry.

type Section

type Section struct {
	Name   string
	Checks []validationdomain.CheckResult
}

Section is a named group of preflight checks the doctor emits.

func (Section) OK

func (s Section) OK() bool

OK reports whether the section passed: a skipped check does not fail it.

type Signer

type Signer interface {
	Sign(secret string, body []byte) (header, value string)
}

Signer signs a webhook body, returning the HTTP header name and value.

type Smoke

type Smoke interface {
	Run(ctx context.Context, target string, withReactions bool) (SmokeResult, error)
}

Smoke runs a synthetic webhook delivery (optionally replaying review reactions) against the live endpoint and reports what it observed.

type SmokeCleanup

type SmokeCleanup interface {
	DeletePR(ctx context.Context, repository string, prNumber int) error
}

SmokeCleanup deletes the synthetic pull_requests row the smoke run causes the server to create. It is called deferred so cleanup runs on every exit path once the PR number is known.

type SmokeConfig

type SmokeConfig struct {
	WebhookURL      string
	WebhookSecret   string
	IgnoreAIReviews bool

	// Reactions mirrors the server's reaction configuration.
	Reactions SmokeReactionsConfig
	// Now supplies the clock used to derive a unique PR number per run.
	Now func() time.Time
}

SmokeConfig carries the parameters that drive a smoke run. All are derived from config / environment at wiring time; the application layer stays free of config imports.

type SmokeEvent added in v0.22.0

type SmokeEvent struct {
	Kind  SmokeEventKind
	IsBot bool
}

SmokeEvent is one provider-neutral synthetic event. IsBot marks the actor as a bot (meaningful only for SmokeCommented — the bot-review lifecycle step).

type SmokeEventKind added in v0.22.0

type SmokeEventKind int

SmokeEventKind is the provider-neutral lifecycle event a smoke run replays.

const (
	SmokeOpened SmokeEventKind = iota
	SmokeCommented
	SmokeApproved
	SmokeMerged
)

SmokeOpened through SmokeMerged enumerate the four provider-neutral lifecycle stages the smoke run replays.

type SmokeMappings

type SmokeMappings interface {
	Get(ctx context.Context, repository string) (routingdomain.RepoMapping, error)
}

SmokeMappings resolves a repository to its routing mapping.

type SmokeMessage

type SmokeMessage struct {
	Channel   string
	MessageID string
}

SmokeMessage is the stored-message view smoke reads after delivery.

type SmokeMessages

type SmokeMessages interface {
	Messages(ctx context.Context, repository string, prNumber int) ([]SmokeMessage, error)
}

SmokeMessages reads the stored messages for a PR.

type SmokeReactionCheck

type SmokeReactionCheck struct {
	Step      string
	Emoji     string
	Present   bool
	VerifyErr error
}

SmokeReactionCheck is the outcome of one lifecycle step: the event that was replayed, the emoji the server was expected to add, and whether the Slack readback confirmed it. VerifyErr is set when the reaction could not be read back at all (e.g. the bot token lacks reactions:read) — distinct from a confirmed absence.

type SmokeReactions

type SmokeReactions interface {
	Reactions(ctx context.Context, channel, ts string) ([]string, error)
}

SmokeReactions reads the reaction emoji names on a Slack message.

type SmokeReactionsConfig

type SmokeReactionsConfig struct {
	Enabled       bool
	NewPR         string
	MergedPR      string
	Approved      string
	Commented     string
	RequestChange string
	BotReview     string
}

SmokeReactionsConfig mirrors config.Reactions without importing the config package.

type SmokeResult

type SmokeResult struct {
	Repository string
	Channel    string
	PRNumber   int
	Title      string
	Timestamp  string
	URL        string

	// ReactionsRequested is true when the caller asked for the lifecycle pass.
	ReactionsRequested bool
	// ReactionsEnabled mirrors the server's reactions.enabled. When a caller
	// requests reactions but this is false, the lifecycle is skipped.
	ReactionsEnabled bool
	Reactions        []SmokeReactionCheck

	// IgnoreAIReviews and BotReviewMarker let the CLI explain why the bot-review
	// step was skipped.
	IgnoreAIReviews bool
	BotReviewMarker string
}

SmokeResult describes a completed delivery run.

type WebhookBuilder added in v0.22.0

type WebhookBuilder interface {
	Build(repository string, number int, title string, ev SmokeEvent) (ForgedWebhook, error)
}

WebhookBuilder renders a ForgedWebhook for one neutral SmokeEvent. It owns all provider vocabulary; the use case speaks only neutral SmokeEvents.

type WebhookSender

type WebhookSender interface {
	Send(ctx context.Context, url string, body []byte, headers map[string]string) (status int, err error)
}

WebhookSender POSTs a signed webhook body and returns the HTTP status code. A transport error is returned as a non-nil err with status 0.

Jump to

Keyboard shortcuts

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