ingot

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ingot provides the data model and persistence layer for Ingots.

An Ingot is a compound record that bundles a bead, PR, worker lifecycle, and structured test results into a single queryable record.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearIngotPRCreateError added in v0.21.0

func ClearIngotPRCreateError(db *sql.DB, beadID, anvil string) error

ClearIngotPRCreateError clears the recorded PR-creation error on the ingot. It is called on the recovery path once a PR has been (re)opened so the record no longer surfaces a stale failure. It intentionally does not touch the status — the caller transitions the ingot to pr_open via UpdateIngotPR/Status.

func InsertIngot

func InsertIngot(db *sql.DB, ingot *Ingot) error

InsertIngot inserts a new ingot row. It sets CreatedAt and UpdatedAt to now and writes the generated ID back to ingot.ID.

func InsertTestResult

func InsertTestResult(db *sql.DB, tr *TestResult) error

InsertTestResult inserts a test result row, setting RecordedAt to now if it is zero. It writes the generated ID back to tr.ID.

func UpdateIngotPR

func UpdateIngotPR(db *sql.DB, beadID, anvil string, prNum int, prURL string, prID *int) error

UpdateIngotPR updates pr_number, pr_url, pr_id, and updated_at. prID may be nil when the internal PR row has not yet been resolved, in which case the column is stored as NULL to avoid a FK violation.

func UpdateIngotPRCreateFailed added in v0.21.0

func UpdateIngotPRCreateFailed(db *sql.DB, beadID, anvil, branch, headSHA, classifiedErr string) error

UpdateIngotPRCreateFailed records a failed PR creation on the ingot: it sets the status to pr_create_failed and persists the pushed branch, head SHA, and classified error so the work can be recovered via the manual create-PR-from-existing-branch path without re-running Smith. It also clears any stale pr_number/pr_url/pr_id so the record unambiguously reflects "branch pushed but no PR". The row must already exist (created at dispatch time); this is an UPDATE, not an upsert.

func UpdateIngotStatus

func UpdateIngotStatus(db *sql.DB, beadID, anvil string, status Status) error

UpdateIngotStatus updates the status and updated_at of the ingot identified by (beadID, anvil).

func UpdateIngotTemperResults

func UpdateIngotTemperResults(db *sql.DB, beadID, anvil string, passed bool, failedStep string, durationMs int) error

UpdateIngotTemperResults updates temper fields and updated_at.

Types

type Ingot

type Ingot struct {
	ID               int    `json:"id"`
	BeadID           string `json:"bead_id"`
	Anvil            string `json:"anvil"`
	PRID             *int   `json:"pr_id,omitempty"` // FK to prs.id, NULL until PR created
	WorkerID         string `json:"worker_id"`
	Status           Status `json:"status"`
	TemperPassed     bool   `json:"temper_passed"`
	TemperFailedStep string `json:"temper_failed_step,omitempty"`
	TemperDurationMs int    `json:"temper_duration_ms"`
	PRNumber         *int   `json:"pr_number,omitempty"` // GitHub PR number
	PRURL            string `json:"pr_url,omitempty"`
	Title            string `json:"title"`
	Branch           string `json:"branch"`
	// HeadSHA is the tip commit of the pushed forge branch, recorded when PR
	// creation fails so a recovery can reference the exact pushed work.
	HeadSHA string `json:"head_sha,omitempty"`
	// PRCreateError is the classified error string from the last failed PR
	// creation attempt. Empty when the ingot is not in a pr_create_failed state.
	PRCreateError string       `json:"pr_create_error,omitempty"`
	TestResults   []TestResult `json:"test_results,omitempty"` // eager-loaded
	CreatedAt     time.Time    `json:"created_at"`
	UpdatedAt     time.Time    `json:"updated_at"`
}

Ingot bundles a bead, PR, worker lifecycle, and test results into a single queryable record.

func GetIngot

func GetIngot(db *sql.DB, beadID, anvil string) (*Ingot, error)

GetIngot fetches a single ingot by (beadID, anvil), eager-loading its TestResults. Returns nil, nil if not found.

func GetIngotByBeadID

func GetIngotByBeadID(db *sql.DB, beadID string) ([]Ingot, error)

GetIngotByBeadID fetches all ingots matching beadID across any anvil, ordered deterministically by anvil name. Returns (nil, nil) when not found. When multiple rows are returned the caller should ask the user to supply --anvil to disambiguate.

func GetIngots

func GetIngots(db *sql.DB, anvil string, status string, limit int) ([]Ingot, error)

GetIngots returns ingots with optional filtering by anvil and/or status, ordered by updated_at descending, limited to limit rows.

func GetIngotsByStatus

func GetIngotsByStatus(db *sql.DB, status Status, limit int) ([]Ingot, error)

GetIngotsByStatus returns ingots filtered by status, limited to limit rows.

type Status

type Status string

Status represents the lifecycle stage of an ingot.

const (
	StatusInit     Status = "init"
	StatusSmith    Status = "smith"
	StatusTemper   Status = "temper"
	StatusWarden   Status = "warden"
	StatusApproved Status = "approved"
	StatusPROpen   Status = "pr_open"
	StatusPRMerged Status = "pr_merged"
	StatusFailed   Status = "failed"
	StatusStalled  Status = "stalled"
	// StatusPRCreateFailed marks an ingot whose branch was pushed but for which
	// the final PR creation failed (after transient retries were exhausted). The
	// pushed branch, head SHA, and classified error are persisted alongside it so
	// the bead can be recovered via the manual create-PR-from-existing-branch path
	// without re-running Smith.
	StatusPRCreateFailed Status = "pr_create_failed"
)

type TestResult

type TestResult struct {
	ID         int    `json:"id"`
	IngotID    int    `json:"ingot_id"`
	StepIndex  int    `json:"step_index"`
	StepName   string `json:"step_name"`
	Command    string `json:"command"`
	ExitCode   int    `json:"exit_code"`
	DurationMs int    `json:"duration_ms"`
	Passed     bool   `json:"passed"`
	Optional   bool   `json:"optional"`
	// Skipped is true when the step was path-gated off (no changed files matched its Paths globs).
	Skipped        bool      `json:"skipped"`
	OutputSummary  string    `json:"output_summary,omitempty"` // first ~1000 chars or key errors
	FullOutputPath string    `json:"full_output_path,omitempty"`
	RecordedAt     time.Time `json:"recorded_at"`
}

TestResult stores the outcome of a single temper step for an ingot.

func GetTestResults

func GetTestResults(db *sql.DB, ingotID int) ([]TestResult, error)

GetTestResults fetches all test results for an ingot ordered by step_index.

Jump to

Keyboard shortcuts

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