Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions comfy_api/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class FeatureFlagInfo(TypedDict):
},
"partner_node_token": {
"type": "bool",
"default": False,
"default": True,
"description": "Queue Local API-node prompts with a renewable partner-node token instead of the workspace token",
},
"local_web_sso": {
"type": "bool",
"default": False,
"default": True,
"description": "Offer Sign in with browser (Cloud OAuth + PKCE) on Local ComfyUI opened at localhost or 127.0.0.1",
},
}
Expand Down Expand Up @@ -126,13 +126,17 @@ def _parse_cli_feature_flags() -> dict[str, Any]:
# Owned by app.deploy_to_cloud, which sets it via set_server_feature.
_SERVER_SET_FEATURE_FLAGS = ("deploy_to_cloud",)

# CLI-provided flags cannot overwrite core or server-set flags. Startup code may: main.py sets "assets".
_cli_flags = {
k: v for k, v in _parse_cli_feature_flags().items()
if k not in _CORE_FEATURE_FLAGS and k not in _SERVER_SET_FEATURE_FLAGS
}
def _server_feature_flags() -> dict[str, Any]:
"""Registry defaults, then core flags, then CLI flags. CLI flags cannot overwrite core or server-set flags; main.py may still set "assets"."""
registry_defaults = {k: info["default"] for k, info in CLI_FEATURE_FLAG_REGISTRY.items()}
cli_flags = {
k: v for k, v in _parse_cli_feature_flags().items()
if k not in _CORE_FEATURE_FLAGS and k not in _SERVER_SET_FEATURE_FLAGS
}
return {**registry_defaults, **_CORE_FEATURE_FLAGS, **cli_flags}


SERVER_FEATURE_FLAGS: dict[str, Any] = {**_CORE_FEATURE_FLAGS, **_cli_flags}
SERVER_FEATURE_FLAGS: dict[str, Any] = _server_feature_flags()


def get_connection_feature(
Expand Down
20 changes: 20 additions & 0 deletions tests-unit/feature_flags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SERVER_FEATURE_FLAGS,
_coerce_flag_value,
_parse_cli_feature_flags,
_server_feature_flags,
)
from app.comfy_api_env import (
environment_overrides_for_base,
Expand Down Expand Up @@ -193,6 +194,25 @@ def test_invalid_bool_value_dropped(self, monkeypatch, caplog):
class TestCliFeatureFlagRegistry:
"""Test suite for the CLI feature flag registry."""

@pytest.mark.parametrize("key", ["partner_node_token", "local_web_sso"])
def test_local_sso_flags_are_on_by_default(self, key):
assert CLI_FEATURE_FLAG_REGISTRY[key]["default"] is True

def test_server_features_report_registry_defaults(self, monkeypatch):
monkeypatch.setattr("comfy_api.feature_flags.args", type("Args", (), {"feature_flag": []})())
features = _server_feature_flags()
for key, info in CLI_FEATURE_FLAG_REGISTRY.items():
assert features[key] == info["default"], key

@pytest.mark.parametrize("key", ["partner_node_token", "local_web_sso"])
def test_cli_flag_turns_a_default_on_flag_off(self, monkeypatch, key):
monkeypatch.setattr("comfy_api.feature_flags.args", type("Args", (), {"feature_flag": [f"{key}=false"]})())
assert _server_feature_flags()[key] is False

def test_cli_flags_cannot_override_core_flags(self, monkeypatch):
monkeypatch.setattr("comfy_api.feature_flags.args", type("Args", (), {"feature_flag": ["node_replacements=false"]})())
assert _server_feature_flags()["node_replacements"] is True

def test_registry_entries_have_required_fields(self):
for key, info in CLI_FEATURE_FLAG_REGISTRY.items():
assert "type" in info, f"{key} missing 'type'"
Expand Down
Loading