Tribunal.Batch.Policy (Tribunal v3.0.0)

Copy Markdown View Source

Loads and resolves versioned batch evaluation policy files.

Policy files use string keys at the YAML boundary and are normalized into a fixed atom-keyed shape. Dataset paths are expanded relative to the current working directory, not relative to the policy file.

Summary

Functions

Loads a YAML policy from path.

Parses YAML policy content into the normalized policy shape.

Resolves runtime settings with explicit values taking precedence over the policy, and policy values taking precedence over defaults.

Types

pass_rule()

@type pass_rule() :: :all | :any | :majority | {:rate, float()}

t()

@type t() :: %{
  version: 1,
  datasets: [String.t()],
  sampling: %{
    optional(:repeat) => pos_integer(),
    optional(:pass_rule) => pass_rule()
  },
  gates: %{
    optional(:overall) => %{threshold: float()},
    optional(:groups) => %{by: String.t(), threshold: float()}
  }
}

Functions

load(path, opts \\ [])

@spec load(Path.t(), keyword()) :: {:ok, t()} | {:error, String.t()}

Loads a YAML policy from path.

:cwd controls both policy and dataset path expansion. Set allow_empty_datasets: true when positional CLI datasets will be supplied to resolve/3 later.

parse(content, opts \\ [])

@spec parse(String.t(), keyword()) :: {:ok, t()} | {:error, String.t()}

Parses YAML policy content into the normalized policy shape.

resolve(policy, explicit, defaults \\ %{})

@spec resolve(t(), map() | keyword(), map() | keyword()) ::
  {:ok, map()} | {:error, String.t()}

Resolves runtime settings with explicit values taking precedence over the policy, and policy values taking precedence over defaults.

A nonempty explicit :datasets list represents positional CLI files and replaces the policy dataset list rather than appending to it.