mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-15 02:49:18 +08:00
refactor: name /features data as backend flags, not frontend
This commit is contained in:
parent
adb5ad011b
commit
82b4320658
@ -31,7 +31,7 @@ def normalize_comfy_api_base(url: str) -> str:
|
||||
return f"{parsed.scheme or 'https'}://{label}-registry{_TESTENV_HOST_SUFFIX}"
|
||||
|
||||
|
||||
def frontend_config_for_base(base_url: str) -> dict[str, Any] | None:
|
||||
def environment_overrides_for_base(base_url: str) -> dict[str, Any] | None:
|
||||
"""The /features overrides for a staging-tier base, or None for prod."""
|
||||
if not _is_staging_tier(urlparse(base_url).hostname or ""):
|
||||
return None
|
||||
@ -42,5 +42,5 @@ def frontend_config_for_base(base_url: str) -> dict[str, Any] | None:
|
||||
}
|
||||
|
||||
|
||||
def get_frontend_config() -> dict[str, Any] | None:
|
||||
return frontend_config_for_base(getattr(args, "comfy_api_base", "") or "")
|
||||
def get_environment_overrides() -> dict[str, Any] | None:
|
||||
return environment_overrides_for_base(getattr(args, "comfy_api_base", "") or "")
|
||||
|
||||
@ -9,7 +9,6 @@ import logging
|
||||
from typing import Any, TypedDict
|
||||
|
||||
from comfy.cli_args import args
|
||||
from comfy.comfy_api_env import get_frontend_config
|
||||
|
||||
|
||||
class FeatureFlagInfo(TypedDict):
|
||||
@ -165,12 +164,3 @@ def get_server_features() -> dict[str, Any]:
|
||||
Dictionary of server feature flags
|
||||
"""
|
||||
return SERVER_FEATURE_FLAGS.copy()
|
||||
|
||||
|
||||
def get_frontend_features() -> dict[str, Any]:
|
||||
"""Feature flags served by the HTTP ``/features`` endpoint."""
|
||||
features = get_server_features()
|
||||
overrides = get_frontend_config()
|
||||
if overrides:
|
||||
features.update(overrides)
|
||||
return features
|
||||
|
||||
@ -39,6 +39,7 @@ from comfy.deploy_environment import get_deploy_environment
|
||||
import comfy.utils
|
||||
import comfy.model_management
|
||||
from comfy_api import feature_flags
|
||||
from comfy.comfy_api_env import get_environment_overrides
|
||||
import node_helpers
|
||||
from comfyui_version import __version__
|
||||
from app.frontend_management import FrontendManager, parse_version
|
||||
@ -727,7 +728,11 @@ class PromptServer():
|
||||
|
||||
@routes.get("/features")
|
||||
async def get_features(request):
|
||||
return web.json_response(feature_flags.get_frontend_features())
|
||||
features = feature_flags.get_server_features()
|
||||
overrides = get_environment_overrides()
|
||||
if overrides:
|
||||
features.update(overrides)
|
||||
return web.json_response(features)
|
||||
|
||||
@routes.get("/prompt")
|
||||
async def get_prompt(request):
|
||||
|
||||
@ -6,14 +6,14 @@ from comfy_api.feature_flags import (
|
||||
get_connection_feature,
|
||||
supports_feature,
|
||||
get_server_features,
|
||||
get_frontend_features,
|
||||
CLI_FEATURE_FLAG_REGISTRY,
|
||||
SERVER_FEATURE_FLAGS,
|
||||
_coerce_flag_value,
|
||||
_parse_cli_feature_flags,
|
||||
)
|
||||
from comfy.comfy_api_env import (
|
||||
frontend_config_for_base,
|
||||
environment_overrides_for_base,
|
||||
get_environment_overrides,
|
||||
normalize_comfy_api_base,
|
||||
)
|
||||
|
||||
@ -212,35 +212,35 @@ class TestComfyApiEnv:
|
||||
|
||||
def test_config_for_staging_tier_else_none(self):
|
||||
# ephemeral testenv: friendly main host -> -registry, staging platform, dev Firebase env
|
||||
eph = frontend_config_for_base("https://pr-1234.testenvs.comfy.org/")
|
||||
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 = frontend_config_for_base("https://stagingapi.comfy.org")
|
||||
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 frontend_config_for_base("https://api.comfy.org") is None
|
||||
assert environment_overrides_for_base("https://api.comfy.org") is None
|
||||
|
||||
def test_frontend_features_merge_only_for_staging_tier(self, monkeypatch):
|
||||
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 HTTP /features endpoint carries the overrides for staging-tier bases...
|
||||
# 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_frontend_features()
|
||||
assert "comfy_api_base_url" in get_environment_overrides()
|
||||
set_base("https://pr-7.testenvs.comfy.org")
|
||||
assert "comfy_api_base_url" in get_frontend_features()
|
||||
assert "comfy_api_base_url" in get_environment_overrides()
|
||||
# ...but never for prod.
|
||||
set_base("https://api.comfy.org")
|
||||
assert "comfy_api_base_url" not in get_frontend_features()
|
||||
assert get_environment_overrides() is None
|
||||
|
||||
def test_server_features_never_carry_frontend_overrides(self, monkeypatch):
|
||||
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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user