Crosswake.Companions.Rulestead.MockFlagSource (crosswake v0.1.2)

View Source

Named Agent storing flag state for local dev and hermetic proof tests.

This module is mock-only for Phase 42. Production code uses Rulestead.Snapshot to read flag values from the real rulestead library — that adapter is deferred to Phase 43.

State is a plain map of %{flag_atom => gate_state}. The Agent is registered under its module name so it is reachable via Process.whereis/1.

Summary

Functions

Returns a specification to start this module under a supervisor.

Removes the stored gate state for the given flag key.

Returns the gate state for the given flag key, or nil if not set.

Resets all stored flag state to an empty map.

Sets the gate state for the given flag key.

Starts the MockFlagSource Agent with an empty flag map.

Types

gate_state()

@type gate_state() :: :gated | {:rolling_out, non_neg_integer()} | :killed

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete_flag(flag_key)

@spec delete_flag(atom()) :: :ok

Removes the stored gate state for the given flag key.

get_flag(flag_key)

@spec get_flag(atom()) :: gate_state() | nil

Returns the gate state for the given flag key, or nil if not set.

reset()

@spec reset() :: :ok

Resets all stored flag state to an empty map.

Useful for test cleanup between runs. Callers using start_supervised!/1 in ExUnit setup get a fresh Agent per test automatically, making reset/0 a belt-and-suspenders option.

set_flag(flag_key, gate_state)

@spec set_flag(atom(), gate_state()) :: :ok

Sets the gate state for the given flag key.

gate_state must be :gated, {:rolling_out, n}, or :killed.

start_link(opts \\ [])

@spec start_link(keyword()) :: {:ok, pid()} | {:error, term()}

Starts the MockFlagSource Agent with an empty flag map.

The _opts argument is accepted (and ignored) so the module can be used as a supervisor child spec directly — use Agent generates child_spec/1 which calls start_link/1 with an arg.