generated from coulomb/repo-seed
Close the dangling MVP pilots task with H1 provider-switch test, pilot validation report, and resolver tenant-override fix. Add credential routing guidance to AGENTS.md and Claude rules.
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""
|
|
Basic tests for feature-control-sdk wrapper + local provider.
|
|
|
|
Run with: pytest tests/test_sdk_wrapper.py
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from feature_control_sdk import FeatureControlClient, LocalProvider
|
|
|
|
|
|
def test_local_provider_boolean():
|
|
provider = LocalProvider({"test.feature": True})
|
|
client = FeatureControlClient()
|
|
client.set_provider(provider)
|
|
|
|
assert client.get_boolean_value("test.feature", False) is True
|
|
assert client.get_boolean_value("missing.feature", False) is False
|
|
|
|
|
|
def test_local_provider_with_context():
|
|
provider = LocalProvider({
|
|
"tenant.feature": False,
|
|
"agent.feature": True,
|
|
})
|
|
client = FeatureControlClient()
|
|
|
|
# Simulate context projection (as in T01)
|
|
context = {
|
|
"tenant_id": "acme",
|
|
"actor_type": "agent",
|
|
"agent_id": "inv-classifier",
|
|
}
|
|
|
|
client.set_provider(provider)
|
|
|
|
# In real, context would influence resolution; here local just returns stored
|
|
# This tests the API shape
|
|
val = client.get_boolean_value("agent.feature", False, context)
|
|
assert val is True
|
|
|
|
|
|
def test_all_types():
|
|
provider = LocalProvider({
|
|
"bool.f": True,
|
|
"str.f": "hello",
|
|
"num.f": 42,
|
|
"obj.f": {"a": 1},
|
|
})
|
|
client = FeatureControlClient()
|
|
client.set_provider(provider)
|
|
|
|
assert client.get_boolean_value("bool.f", False) is True
|
|
assert client.get_string_value("str.f", "x") == "hello"
|
|
assert client.get_number_value("num.f", 0) == 42
|
|
assert client.get_object_value("obj.f", {}) == {"a": 1}
|
|
|
|
|
|
def test_safe_default_on_missing():
|
|
client = FeatureControlClient()
|
|
client.set_provider(LocalProvider({}))
|
|
|
|
assert client.get_boolean_value("no.such", False) is False
|
|
assert client.get_string_value("no.such", "def") == "def"
|
|
|
|
|
|
def test_h1_provider_switch_without_business_code_change():
|
|
"""UC-H1: swap provider backends without changing evaluation call sites."""
|
|
client = FeatureControlClient()
|
|
context = {"tenant_id": "acme", "actor_type": "human"}
|
|
|
|
client.set_provider(LocalProvider({"tenant.preview": True}))
|
|
assert client.get_boolean_value("tenant.preview", False, context) is True
|
|
|
|
# Simulate migration to a different backend with the same OpenFeature contract
|
|
client.set_provider(LocalProvider({"tenant.preview": False}))
|
|
assert client.get_boolean_value("tenant.preview", True, context) is False
|