approval

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 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 approval persists Approval records as one file per approval under .devsys/approvals/<id>.yaml (方案 §4.9/§5.8, 实施计划 M3.7) and implements the request → decide → consume lifecycle.

Every write goes through the storage transaction path with an in-tx read and ExpectHash guard, so no caller can bypass version checking. Consumption happens inside the advancing work item's transaction via ConsumeTx: the approval flips to consumed only when the status change that needed it commits.

Index

Constants

View Source
const (
	ScopeStageGate = "stage_gate"
	ScopeAction    = "action"

	StatusPending  = "pending"
	StatusApproved = "approved"
	StatusRejected = "rejected"
)

Lifecycle states and scopes.

Variables

View Source
var (
	ErrNotFound        = errors.New("approval: not found")
	ErrBadID           = errors.New("approval: bad id")
	ErrInvalidInput    = errors.New("approval: invalid input")
	ErrNotPending      = errors.New("approval: not pending")
	ErrNotApproved     = errors.New("approval: not approved")
	ErrAlreadyConsumed = errors.New("approval: already consumed")
	ErrInvalidated     = errors.New("approval: invalidated")
	ErrMismatch        = errors.New("approval: does not match the gate")
)

Errors reported to callers.

Functions

func ConsumeTx

func ConsumeTx(tx *storage.Tx, id, workItemID, stage, status string, now time.Time, actor, reason string) (*domain.Event, error)

ConsumeTx marks an approval consumed inside an open transaction and re-verifies every condition the gate relied on: the approval must be approved, unconsumed, for the same work item, for the same gate stage and still requested from the work item's current status. Any mismatch aborts the whole transaction (fail closed). The returned event is staged by the caller in the same batch as the status change, so a transaction keeps one append per JSONL shard.

func DecideTx

func DecideTx(tx *storage.Tx, id string, opts DecideOptions) (*domain.Approval, *domain.Event, error)

DecideTx approves or rejects a pending approval inside an open transaction and returns the decision event for the caller to stage in the same batch. Invalidated approvals can never be decided into use.

func InvalidateForStatusTx

func InvalidateForStatusTx(tx *storage.Tx, devsysDir, workItemID, status string, now time.Time, reason string) ([]*domain.Event, error)

InvalidateForStatusTx marks every unconsumed approval requested from a work item status as invalidated once the work item leaves that status (方案 §4.9 离开阶段即作废): even a later return to the same status needs a fresh request. The returned events join the status-change batch so the invalidation is atomic with the transition that caused it.

func InvalidatedFor

func InvalidatedFor(ctx context.Context, root, workItemID, stage string) (*domain.Approval, error)

InvalidatedFor returns the most recently invalidated stage-gate approval requested for (workItemID, stage), or ErrNotFound. It explains a require_approval gate that an earlier approval used to satisfy: 方案 §4.9 voids an approval the moment the work item leaves the status it was requested from, and the gate error should say so instead of only "an approved, unconsumed approval is required".

func MatchingGate

func MatchingGate(ctx context.Context, root, workItemID, stage, status string) (*domain.Approval, error)

MatchingGate returns the approved, unconsumed approval whose stage matches the gate being entered and whose request status matches the work item's current status (方案 §4.9 有效期).

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a well-formed approval identifier.

Types

type DecideOptions

type DecideOptions struct {
	Approve   bool
	DecidedBy string
	Comment   string
	Now       time.Time
}

DecideOptions is the input to Decide.

type Filter

type Filter struct {
	WorkItemID string
	Status     string
}

Filter selects approvals for List; zero fields match everything.

type RequestOptions

type RequestOptions struct {
	Scope           string
	WorkItemID      string
	RunID           string
	Stage           string
	RequestedStatus string
	ProjectID       string
	RequestedBy     string
	Reason          string
	Now             time.Time
}

RequestOptions is the input to Request.

type Store

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

Store binds approval operations to a project root.

func New

func New(root string) *Store

New binds the approval layer to a project root (the directory containing .devsys, which must exist).

func (*Store) Decide

func (s *Store) Decide(ctx context.Context, id string, opts DecideOptions) (*domain.Approval, error)

Decide approves or rejects a pending approval in its own transaction.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*domain.Approval, error)

Get decodes one approval.

func (*Store) List

func (s *Store) List(ctx context.Context, f Filter) ([]*domain.Approval, error)

List returns approvals ordered by numeric id.

func (*Store) Request

func (s *Store) Request(ctx context.Context, opts RequestOptions) (*domain.Approval, error)

Request creates a pending approval for a gate stage or a dangerous action.

Jump to

Keyboard shortcuts

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