feat: allow --comfy-api-base target ephemeral testenvs (#14569)

* feat: allow --comfy-api-base target ephemeral testenvs

Signed-off-by: bigcat88 <bigcat88@icloud.com>

* refactor: name /features data as backend flags, not frontend

---------

Signed-off-by: bigcat88 <bigcat88@icloud.com>
Co-authored-by: guill <jacob.e.segal@gmail.com>
This commit is contained in:
Alexander Piskun
2026-07-09 09:20:10 +03:00
committed by GitHub
parent d0008a8958
commit b35819712e
4 changed files with 121 additions and 2 deletions

View File

@@ -11,6 +11,11 @@ from comfy_api.feature_flags import (
_coerce_flag_value,
_parse_cli_feature_flags,
)
from comfy.comfy_api_env import (
environment_overrides_for_base,
get_environment_overrides,
normalize_comfy_api_base,
)
class TestFeatureFlags:
@@ -183,3 +188,65 @@ class TestCliFeatureFlagRegistry:
assert "type" in info, f"{key} missing 'type'"
assert "default" in info, f"{key} missing 'default'"
assert "description" in info, f"{key} missing 'description'"
class TestComfyApiEnv:
"""--comfy-api-base staging-tier detection + testenv main-host -> -registry rewrite."""
@pytest.mark.parametrize(
"url, expected",
[
# testenv friendly main host -> comfy-api -registry sibling (slash trimmed)
("https://pr-4398.testenvs.comfy.org", "https://pr-4398-registry.testenvs.comfy.org"),
("https://pr-4398.testenvs.comfy.org/", "https://pr-4398-registry.testenvs.comfy.org"),
("https://pr-4398-registry.testenvs.comfy.org", "https://pr-4398-registry.testenvs.comfy.org"),
# staging + everything else -> unchanged (no -registry split)
("https://stagingapi.comfy.org", "https://stagingapi.comfy.org"),
("https://api.comfy.org", "https://api.comfy.org"),
("https://pr-1.testenvs.comfy.org.evil.com", "https://pr-1.testenvs.comfy.org.evil.com"),
("", ""),
],
)
def test_normalize_comfy_api_base(self, url, expected):
assert normalize_comfy_api_base(url) == expected
def test_config_for_staging_tier_else_none(self):
# ephemeral testenv: friendly main host -> -registry, staging platform, dev Firebase env
eph = environment_overrides_for_base("https://pr-1234.testenvs.comfy.org/")
assert eph["comfy_api_base_url"] == "https://pr-1234-registry.testenvs.comfy.org"
assert eph["comfy_platform_base_url"] == "https://stagingplatform.comfy.org"
assert eph["firebase_env"] == "dev"
# staging api host: emitted as-is
stg = environment_overrides_for_base("https://stagingapi.comfy.org")
assert stg["comfy_api_base_url"] == "https://stagingapi.comfy.org"
assert stg["comfy_platform_base_url"] == "https://stagingplatform.comfy.org"
assert stg["firebase_env"] == "dev"
# prod / unknown: nothing
assert environment_overrides_for_base("https://api.comfy.org") is None
def test_environment_overrides_only_for_staging_tier(self, monkeypatch):
def set_base(url):
monkeypatch.setattr(
"comfy.comfy_api_env.args",
type("Args", (), {"comfy_api_base": url})(),
)
# The overrides merged into the HTTP /features response are present for staging-tier bases...
set_base("https://stagingapi.comfy.org")
assert "comfy_api_base_url" in get_environment_overrides()
set_base("https://pr-7.testenvs.comfy.org")
assert "comfy_api_base_url" in get_environment_overrides()
# ...but never for prod.
set_base("https://api.comfy.org")
assert get_environment_overrides() is None
def test_server_features_never_carry_env_overrides(self, monkeypatch):
"""The WebSocket capability handshake must stay free of routing keys."""
monkeypatch.setattr(
"comfy.comfy_api_env.args",
type("Args", (), {"comfy_api_base": "https://pr-7.testenvs.comfy.org"})(),
)
features = get_server_features()
assert "comfy_api_base_url" not in features
assert "comfy_platform_base_url" not in features
assert "firebase_env" not in features