import pytest

from zbt.infrastructure.redis.keys import RedisKeyBuilder


def test_redis_key_builder_uses_stage_prefix_and_rejects_unsafe_segments() -> None:
    keys = RedisKeyBuilder("ins:s2:")

    assert keys.auth_otp("mobile-sha256") == "ins:s2:auth:otp:mobile-sha256"
    assert keys.auth_session("session-01") == "ins:s2:auth:session:session-01"
    assert keys.agent_run_events("run-01") == "ins:s2:agent:run:run-01:events"
    assert keys.payment_lock("payment-01") == "ins:s2:lock:payment:payment-01"

    with pytest.raises(ValueError, match="Redis Key"):
        keys.auth_session("other:namespace")
