Path: redb-route/tests/redb.Route.Tests.Llm/TestHelpers/EnvFactAttribute.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Llm/TestHelpers/EnvFactAttribute.cs
----
using Xunit.Sdk;
namespace redb.Route.Tests.Llm.TestHelpers;
///
/// xUnit fact attribute that skips the test when the named environment variable is
/// missing or empty. Used to gate live LLM provider tests so CI runs stay green
/// without secrets while local runs with the variable set hit the real API.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
[XunitTestCaseDiscoverer("Xunit.Sdk.FactDiscoverer", "xunit.execution.{Platform}")]
public sealed class EnvFactAttribute : FactAttribute
{
/// Creates an env-gated fact.
/// Required environment variable. If unset/empty the test is skipped.
/// Additional variables that must also be present.
public EnvFactAttribute(string envVar, params string[] extraEnvVars)
{
var missing = new List();
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(envVar)))
missing.Add(envVar);
foreach (var v in extraEnvVars)
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(v)))
missing.Add(v);
if (missing.Count > 0)
Skip = $"Live LLM test skipped — set env vars: {string.Join(", ", missing)}.";
}
}