Spectre.Operation.Runtime.Contract (Spectre v0.3.0)

Copy Markdown View Source

Definition and declaration validation for the operation runtime.

Loads the code-owned Spectre.Operation.Definition behind a committed loop and enforces everything the definition declares: kind and version compatibility, controller callbacks, security policy, branches, blockers, waits, triggers, artifact policy and update fields.

Summary

Functions

Resolves the declared artifact retention limit.

Authorizes a control command against the definition security policy.

Fences a control command against the committed loop revision.

Loads and validates the current definition for a committed loop.

Requires the definition kind to match the requested loop kind.

Stamps definition-owned publication and correlation policy into metadata.

Validates artifact kinds and the retention limit for appended artifacts.

Validates a blocker against the declared blocker ids.

Validates a requested operation against declared branches.

Requires cognitive constraint updates to be maps.

Requires optional controller callbacks implied by the definition.

Validates a non-negative operation cost.

Validates a delivered trigger, always accepting correlated retry timers.

Validates loop origins, destinations and visibility against security policy.

Validates a non-negative integral page count.

Validates a request input against the operation spec, unless reconciling.

Validates a declared Vigil significance value.

Enforces the declared trigger correlation policy for the active wait.

Validates changed update fields against the declared update contract.

Validates a wait against the declared wait kinds.

Functions

artifact_limit(definition)

@spec artifact_limit(Spectre.Operation.Definition.t()) :: pos_integer()

Resolves the declared artifact retention limit.

authorize_control(definition, command)

@spec authorize_control(
  Spectre.Operation.Definition.t(),
  Spectre.Operation.Control.Command.t()
) ::
  :ok | {:error, term()}

Authorizes a control command against the definition security policy.

authorize_revision(loop, revision)

@spec authorize_revision(Spectre.Operation.Loop.t(), non_neg_integer() | nil) ::
  :ok | {:error, term()}

Fences a control command against the committed loop revision.

current_definition(loop)

@spec current_definition(Spectre.Operation.Loop.t()) ::
  {:ok, Spectre.Operation.Definition.t()} | {:error, term()}

Loads and validates the current definition for a committed loop.

ensure_kind(definition, kind)

@spec ensure_kind(Spectre.Operation.Definition.t(), Spectre.Operation.Loop.kind()) ::
  :ok | {:error, term()}

Requires the definition kind to match the requested loop kind.

policy_metadata(metadata, definition)

@spec policy_metadata(map(), Spectre.Operation.Definition.t()) :: map()

Stamps definition-owned publication and correlation policy into metadata.

validate_artifacts(definition, loop, artifacts)

@spec validate_artifacts(
  Spectre.Operation.Definition.t(),
  Spectre.Operation.Loop.t(),
  [term()]
) ::
  :ok | {:error, term()}

Validates artifact kinds and the retention limit for appended artifacts.

validate_blocker(definition, blocker)

@spec validate_blocker(Spectre.Operation.Definition.t(), term()) ::
  :ok | {:error, term()}

Validates a blocker against the declared blocker ids.

validate_branch(definition, request)

@spec validate_branch(Spectre.Operation.Definition.t(), Spectre.Operation.Request.t()) ::
  :ok | {:error, term()}

Validates a requested operation against declared branches.

validate_cognitive_update(value)

@spec validate_cognitive_update(term()) :: :ok | {:error, term()}

Requires cognitive constraint updates to be maps.

validate_controller_contract(definition, controller)

@spec validate_controller_contract(Spectre.Operation.Definition.t(), module()) ::
  :ok | {:error, term()}

Requires optional controller callbacks implied by the definition.

validate_cost(usage, fallback)

@spec validate_cost(map(), term()) :: :ok | {:error, term()}

Validates a non-negative operation cost.

validate_delivered_trigger(definition, loop, trigger, wait_id)

@spec validate_delivered_trigger(
  Spectre.Operation.Definition.t(),
  Spectre.Operation.Loop.t(),
  term(),
  term()
) :: :ok | {:error, term()}

Validates a delivered trigger, always accepting correlated retry timers.

validate_loop_security(definition, loop)

@spec validate_loop_security(
  Spectre.Operation.Definition.t(),
  Spectre.Operation.Loop.t()
) ::
  :ok | {:error, term()}

Validates loop origins, destinations and visibility against security policy.

validate_pages(usage, fallback)

@spec validate_pages(map(), term()) :: :ok | {:error, term()}

Validates a non-negative integral page count.

validate_request_input(spec, request, bool)

@spec validate_request_input(
  Spectre.Operation.Spec.t(),
  Spectre.Operation.Request.t(),
  boolean()
) ::
  :ok | {:error, term()}

Validates a request input against the operation spec, unless reconciling.

validate_significance(arg1, value)

@spec validate_significance(Spectre.Operation.Loop.kind(), term()) ::
  :ok | {:error, term()}

Validates a declared Vigil significance value.

validate_trigger_correlation(definition, arg2, expected_wait, expected_generation)

@spec validate_trigger_correlation(
  Spectre.Operation.Definition.t(),
  Spectre.Operation.Wait.t() | nil,
  term(),
  term()
) :: {:ok, :exact | :legacy} | {:error, term()}

Enforces the declared trigger correlation policy for the active wait.

validate_updated_fields(before, updated, definition)

@spec validate_updated_fields(term(), term(), Spectre.Operation.Definition.t()) ::
  :ok | {:error, term()}

Validates changed update fields against the declared update contract.

validate_wait(definition, wait)

@spec validate_wait(Spectre.Operation.Definition.t(), Spectre.Operation.Wait.t()) ::
  :ok | {:error, term()}

Validates a wait against the declared wait kinds.