docs(judgement,events): state comments plainly
This commit is contained in:
12 files changed
+37
-35
No files matched your search
@@ -172,8 +172,9 @@ type Delivery interface {
|
||||
Notify(ctx context.Context, n deliveries.Notification) error
|
||||
}
|
||||
|
||||
// Action types updates action-type autonomy. Denials reduce autonomy; approvals
|
||||
// count towards an increase that a person must approve separately.
|
||||
// ActionTypes updates the autonomy level of action types. A denial lowers the
|
||||
// level; approvals count towards a proposal to raise it, which a person must
|
||||
// approve separately.
|
||||
type ActionTypes interface {
|
||||
Approved(ctx context.Context, decisionID uuid.UUID, by string, need int, deadline time.Time) (*judgement.AutonomyProposal, error)
|
||||
Denied(ctx context.Context, decisionID uuid.UUID) error
|
||||
|
||||
@@ -132,7 +132,7 @@ func (*startRecorder) CheckTrigger(context.Context, string, string) error { retu
|
||||
|
||||
// TestTriggersStartRunsAsTheWorkload guards that dispatching an event never
|
||||
// starts a run without a principal: the workload principal acts, a policy
|
||||
// refusal or a disabled workflow is final and names its own outcome, and a
|
||||
// refusal or a disabled workflow is final and records its own outcome, and a
|
||||
// chain that can't decide fails the dispatch so the event stays queued instead
|
||||
// of being dropped.
|
||||
func TestTriggersStartRunsAsTheWorkload(t *testing.T) {
|
||||
|
||||
@@ -768,7 +768,7 @@ const (
|
||||
// noRunReason explains why a trigger matched an event but started no run. It
|
||||
// is stored as the dispatch's reason and shown on the capture and the trigger.
|
||||
type noRunReason struct {
|
||||
// outcome is the dispatch outcome the reason is recorded under.
|
||||
// outcome is the dispatch outcome stored with this reason.
|
||||
outcome string
|
||||
|
||||
Code string `json:"code"`
|
||||
|
||||
@@ -102,10 +102,9 @@ func (m Mapping) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Failure describes one field that did not resolve cleanly against a payload --
|
||||
// named by field and path so the operator knows exactly what drifted. Value is
|
||||
// what the payload held at the path when the field was found with the wrong
|
||||
// type; it is absent when the field is missing or null.
|
||||
// Failure describes one mapping field that did not resolve against a payload.
|
||||
// Value is the value found at Path when it has the wrong type. It is empty when
|
||||
// the field is missing or null.
|
||||
type Failure struct {
|
||||
FieldName string `json:"field_name"`
|
||||
Path string `json:"path"`
|
||||
|
||||
@@ -58,11 +58,11 @@ func agentModelRole(alias string) string {
|
||||
}
|
||||
|
||||
// DefaultApprovalDeadline is how long an approval request waits for an answer
|
||||
// when the organisation hasn't said.
|
||||
// when the organisation hasn't set one.
|
||||
const DefaultApprovalDeadline = 24 * time.Hour
|
||||
|
||||
// DefaultProposeAutonomyAfter is how many approvals in a row earn a proposal to
|
||||
// loosen an action type when the organisation hasn't said.
|
||||
// loosen an action type when the organisation hasn't set one.
|
||||
const DefaultProposeAutonomyAfter = 3
|
||||
|
||||
// maxProposeAutonomyAfter bounds the count: past it an action type could never
|
||||
@@ -70,7 +70,7 @@ const DefaultProposeAutonomyAfter = 3
|
||||
const maxProposeAutonomyAfter = 100
|
||||
|
||||
// DefaultRecurrenceThreshold is how many incidents with one cause on one target
|
||||
// it takes to propose a root-cause fix when the organisation hasn't said.
|
||||
// it takes to propose a root-cause fix when the organisation hasn't set one.
|
||||
const DefaultRecurrenceThreshold = 5
|
||||
|
||||
// The bounds on the recurrence threshold. One incident is no pattern; past a
|
||||
@@ -81,7 +81,7 @@ const (
|
||||
)
|
||||
|
||||
// DefaultAttemptsPerRun is how many steps an agent may take in one run when the
|
||||
// organisation hasn't said.
|
||||
// organisation hasn't set one.
|
||||
const DefaultAttemptsPerRun = 20
|
||||
|
||||
// The bounds on attempts per run. An agent needs a few steps to look anything
|
||||
|
||||
@@ -40,8 +40,9 @@ type Outcome struct {
|
||||
At time.Time
|
||||
}
|
||||
|
||||
// Outcomes says what became of decisions that were held for approval. It is
|
||||
// the approvals module's to answer, so an action type's history can show it.
|
||||
// Outcomes reports the result of each decision that was held for approval. The
|
||||
// approvals module implements it, so an action type's history can show the
|
||||
// results.
|
||||
type Outcomes interface {
|
||||
Outcomes(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]Outcome, error)
|
||||
}
|
||||
@@ -60,9 +61,9 @@ func NewActionTypes(db *sqlx.DB, log *slog.Logger, orgID string) *ActionTypes {
|
||||
return &ActionTypes{orgID: orgID, store: store.New(db), log: log, now: time.Now}
|
||||
}
|
||||
|
||||
// Level returns the level c stands at, making the action type at its default if this
|
||||
// is the first action of it. readOnly is the action's own declaration and is
|
||||
// kept with the action type, so a reset knows what its default is.
|
||||
// Level returns the level of action type c, creating it at its default level
|
||||
// on its first action. readOnly is the action's own declaration and is stored
|
||||
// with the action type, so a reset knows its default level.
|
||||
func (c *ActionTypes) Level(ctx context.Context, actionType ActionType, readOnly bool) (Level, error) {
|
||||
row, err := c.store.EnsureActionType(ctx, store.ActionType{
|
||||
ID: uuid.New(), OrgID: c.orgID, Connector: actionType.Connector, Action: actionType.Action,
|
||||
@@ -148,8 +149,8 @@ type ActionTypeDetail struct {
|
||||
ActionTypeView
|
||||
History []HistoryEntry `json:"history"`
|
||||
Resets []ResetView `json:"resets"`
|
||||
// Autonomy proposals are the proposals to loosen the action type, newest first. One whose
|
||||
// state is pending waits for an answer.
|
||||
// AutonomyProposals lists the proposals to loosen the action type, newest
|
||||
// first. A proposal in the pending state is waiting for an answer.
|
||||
AutonomyProposals []AutonomyProposalView `json:"autonomy_proposals"`
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,17 @@ const (
|
||||
proposalRefused
|
||||
)
|
||||
|
||||
// standing is what an action type has earned: its level, the approvals counted since
|
||||
// it was last tightened or raised, and the level an autonomy proposal waiting for an
|
||||
// answer would take it to (zero when none waits).
|
||||
// standing is the autonomy an action type has earned: its level, the approvals
|
||||
// counted since its level last changed, and the level a pending autonomy
|
||||
// proposal would set (zero when no proposal is pending).
|
||||
type standing struct {
|
||||
level Level
|
||||
count int
|
||||
proposedLevel Level
|
||||
}
|
||||
|
||||
// after returns the standing the event leaves, and whether it earns a new
|
||||
// autonomy proposal for the action type by one level once need approvals in a row have
|
||||
// after returns the standing after event e, and whether to propose loosening
|
||||
// the action type by one level because need approvals in a row have been
|
||||
// counted. Autonomy is lost at once and earned only through a person: a
|
||||
// denial or failure never loosens an action type, and approvals never loosen it
|
||||
// themselves.
|
||||
@@ -194,8 +194,8 @@ type Answerer struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// cause is why apply moves an action type: who answered an autonomy proposal,
|
||||
// or why the action type was tightened.
|
||||
// cause records who answered an autonomy proposal, or why an action type was
|
||||
// tightened.
|
||||
type cause struct {
|
||||
answerer Answerer
|
||||
because string
|
||||
@@ -273,8 +273,8 @@ func closedProposalState(e event, loosened bool) string {
|
||||
return "superseded"
|
||||
}
|
||||
|
||||
// closedBy is who closed a proposal: the answerer when a person answered it,
|
||||
// and nobody when it was withdrawn.
|
||||
// closedBy returns the account that answered a proposal, or an empty Answerer
|
||||
// when the proposal was withdrawn.
|
||||
func closedBy(e event, who Answerer) Answerer {
|
||||
if e == proposalApproved || e == proposalRefused {
|
||||
return who
|
||||
|
||||
@@ -34,7 +34,7 @@ func (Reversibility) Judge(_ context.Context, a Action) (Verdict, error) {
|
||||
return Verdict{}, errors.New("the connector declares no reversibility for this action")
|
||||
}
|
||||
|
||||
// ActionTypeLevels says what level an action type stands at.
|
||||
// ActionTypeLevels reports the level of an action type.
|
||||
type ActionTypeLevels interface {
|
||||
Level(ctx context.Context, c ActionType, readOnly bool) (Level, error)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ type Reset struct {
|
||||
|
||||
const actionTypeColumns = `id, org_id, connector, action, target_kind, environment, read_only, level, created_at, reset_at, tightened_at, tightened_because`
|
||||
|
||||
// EnsureActionType returns the action type c names, creating it at c.Level when it is
|
||||
// EnsureActionType returns the action type c identifies, creating it at c.Level when it is
|
||||
// new. An existing action type keeps its level.
|
||||
func (s *Store) EnsureActionType(ctx context.Context, c ActionType) (ActionType, error) {
|
||||
var out ActionType
|
||||
@@ -67,7 +67,7 @@ func (s *Store) EnsureActionType(ctx context.Context, c ActionType) (ActionType,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Action types returns every action type, most recently decided first.
|
||||
// ActionTypes returns every action type, most recently decided first.
|
||||
func (s *Store) ActionTypes(ctx context.Context, orgID string) ([]ActionTypeSummary, error) {
|
||||
var out []ActionTypeSummary
|
||||
err := s.db.SelectContext(ctx, &out, `
|
||||
|
||||
@@ -53,7 +53,8 @@ func (s *Store) ActionTypeOfDecision(ctx context.Context, orgID string, decision
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ActionTypeByKey returns the action type named by its four names.
|
||||
// ActionTypeByKey returns the action type with c's connector, action, target
|
||||
// kind and environment.
|
||||
func (s *Store) ActionTypeByKey(ctx context.Context, c ActionType) (ActionType, error) {
|
||||
var out ActionType
|
||||
err := s.db.GetContext(ctx, &out, `
|
||||
|
||||
@@ -50,8 +50,8 @@ type Action struct {
|
||||
Effect connectors.Effect `json:"effect"`
|
||||
}
|
||||
|
||||
// ActionType is what an action's earned autonomy belongs to: one connector's
|
||||
// action on one kind of target in one environment.
|
||||
// ActionType identifies the actions that share an autonomy level: one
|
||||
// connector's action on one kind of target in one environment.
|
||||
type ActionType struct {
|
||||
Connector string `json:"connector"`
|
||||
Action string `json:"action"`
|
||||
|
||||
Reference in new issue
Block a user