Class SnapshotAcceptMode
- Namespace
- SnapshotAssertions
- Assembly
- SnapshotAssertions.dll
Detection of accept-mode based on the SNAPSHOT_ACCEPT and CI environment
variables. Pure, no IO; the caller is responsible for actually overwriting the baseline
when accept-mode is active.
public static class SnapshotAcceptMode
- Inheritance
-
SnapshotAcceptMode
- Inherited Members
Remarks
Accept-mode is enabled when SNAPSHOT_ACCEPT is set to a truthy value (one of
1, true, or yes; case-insensitive). It is unconditionally
disabled in CI: if the CI environment variable is set to a truthy value
(which all major hosted CI services do: GitHub Actions, GitLab CI, Azure Pipelines,
CircleCI, etc.), accept-mode is refused even if SNAPSHOT_ACCEPT is set, to prevent
a stray pipeline configuration from silently accepting baseline drift.
The CI guard reads CI rather than the runner-specific variables (GITHUB_ACTIONS,
GITLAB_CI, TF_BUILD, etc.) because CI is the cross-runner canonical signal:
every major runner sets it. This keeps the rule one-line and runner-agnostic.
Fields
AcceptVariableName
The environment variable consulted to enable accept-mode.
public const string AcceptVariableName = "SNAPSHOT_ACCEPT"
Field Value
CiVariableName
The environment variable consulted to detect a CI environment.
public const string CiVariableName = "CI"
Field Value
Methods
IsActive()
Returns true when accept-mode is enabled and the process is not in CI.
public static bool IsActive()
Returns
IsActive(string?, string?)
Pure overload for testability: classify the supplied raw values without touching the process environment.
public static bool IsActive(string? snapshotAcceptValue, string? ciValue)
Parameters
snapshotAcceptValuestringThe raw value of the
SNAPSHOT_ACCEPTenvironment variable, or null if unset.ciValuestringThe raw value of the
CIenvironment variable, or null if unset.
Returns
IsTruthy(string?)
Whether value is one of the recognised truthy strings
(1, true, yes; case-insensitive). null and empty
strings are falsy.
public static bool IsTruthy(string? value)
Parameters
valuestringThe value to classify.