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
- Variables
- func ConsumeTx(tx *storage.Tx, id, workItemID, stage, status string, now time.Time, ...) (*domain.Event, error)
- func DecideTx(tx *storage.Tx, id string, opts DecideOptions) (*domain.Approval, *domain.Event, error)
- func InvalidateForStatusTx(tx *storage.Tx, devsysDir, workItemID, status string, now time.Time, ...) ([]*domain.Event, error)
- func InvalidatedFor(ctx context.Context, root, workItemID, stage string) (*domain.Approval, error)
- func MatchingGate(ctx context.Context, root, workItemID, stage, status string) (*domain.Approval, error)
- func ValidID(id string) bool
- type DecideOptions
- type Filter
- type RequestOptions
- type Store
- func (s *Store) Decide(ctx context.Context, id string, opts DecideOptions) (*domain.Approval, error)
- func (s *Store) Get(ctx context.Context, id string) (*domain.Approval, error)
- func (s *Store) List(ctx context.Context, f Filter) ([]*domain.Approval, error)
- func (s *Store) Request(ctx context.Context, opts RequestOptions) (*domain.Approval, error)
Constants ¶
const ( ScopeStageGate = "stage_gate" ScopeAction = "action" StatusPending = "pending" StatusApproved = "approved" StatusRejected = "rejected" )
Lifecycle states and scopes.
Variables ¶
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 ¶
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 有效期).
Types ¶
type DecideOptions ¶
DecideOptions is the input to Decide.
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 ¶
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.