mirror of
https://github.com/langgenius/dify.git
synced 2026-11-25 13:32:43 +08:00
fix(dev): configure one Tokener staging environment
This commit is contained in:
1 parent
d4f4344ef1
commit
d5e4f96f69
7 files changed
+85
-14
No files matched your search
@@ -260,6 +260,13 @@ class TokenerSignupBillingCandidate(StrEnum):
|
||||
SHARED_STAGING = "http://dify-saas-billing:8081"
|
||||
|
||||
|
||||
class AgentDevTokenerEnvironment(StrEnum):
|
||||
"""Agent-dev signup profile; an empty value keeps the existing routing settings."""
|
||||
|
||||
INHERIT = ""
|
||||
STAGING = "staging"
|
||||
|
||||
|
||||
class PluginConfig(BaseSettings):
|
||||
"""
|
||||
Plugin configs
|
||||
@@ -414,6 +421,11 @@ class PluginConfig(BaseSettings):
|
||||
default="",
|
||||
)
|
||||
|
||||
AGENT_DEV_TOKENER_ENVIRONMENT: AgentDevTokenerEnvironment = Field(
|
||||
default=AgentDevTokenerEnvironment.INHERIT,
|
||||
description="Agent dev only: staging selects one shared Billing route for all Tokener signups and metering",
|
||||
)
|
||||
|
||||
TOKENER_SIGNUP_VALIDATION_BILLING_API_URL: TokenerSignupBillingCandidate = Field(
|
||||
default=TokenerSignupBillingCandidate.DISABLED,
|
||||
description="Agent dev only: explicit Billing route for workspaces created by the signup intent flow",
|
||||
@@ -454,6 +466,12 @@ class PluginConfig(BaseSettings):
|
||||
default="",
|
||||
)
|
||||
|
||||
def get_agent_dev_tokener_signup_billing_mode(self) -> TokenerSignupBillingCandidate:
|
||||
"""Resolve the profile or old selector without granting permission to use the target."""
|
||||
if self.AGENT_DEV_TOKENER_ENVIRONMENT == AgentDevTokenerEnvironment.STAGING:
|
||||
return TokenerSignupBillingCandidate.SHARED_STAGING
|
||||
return self.TOKENER_SIGNUP_VALIDATION_BILLING_API_URL
|
||||
|
||||
def get_agent_dev_staging_tokener_billing_url(self) -> TokenerSignupBillingCandidate | None:
|
||||
"""Return an explicitly trusted staging Billing route without network or persistence changes.
|
||||
|
||||
@@ -461,9 +479,9 @@ class PluginConfig(BaseSettings):
|
||||
valid only when the normal Tokener Billing base matches and the
|
||||
signup-only package is an exact staging UID. The global data-plane
|
||||
endpoint and package remain available to legacy paths unchanged.
|
||||
Invalid configuration grants no fallback to shared Billing.
|
||||
Invalid shared configuration grants no fallback to the isolated route.
|
||||
"""
|
||||
configured = self.TOKENER_SIGNUP_VALIDATION_BILLING_API_URL
|
||||
configured = self.get_agent_dev_tokener_signup_billing_mode()
|
||||
if configured == TokenerSignupBillingCandidate.HOSTED_SIGNUP:
|
||||
return TokenerSignupBillingCandidate.HOSTED_SIGNUP
|
||||
if (
|
||||
|
||||
@@ -30,14 +30,16 @@ To use the existing shared agent-dev Billing service for **all future
|
||||
self-signups**, configure these values consistently in the API and signup
|
||||
worker:
|
||||
|
||||
- `TOKENER_SIGNUP_VALIDATION_BILLING_API_URL=http://dify-saas-billing:8081`
|
||||
- `AGENT_DEV_TOKENER_ENVIRONMENT=staging`
|
||||
- `TOKENER_BILLING_API_URL=http://dify-saas-billing:8081`
|
||||
- `TOKENER_SIGNUP_VALIDATION_PLUGIN_UNIQUE_IDENTIFIER` to the exact verified
|
||||
signed `langgenius/tokener-staging:<version>@<sha256>` Marketplace UID.
|
||||
|
||||
Both new ordinary signups and prior staging intents use the explicit shared
|
||||
route for Tokener bootstrap and metering, without redirects. In this mode the
|
||||
old exact-email selector is ignored. The package pin is signup-only; do not
|
||||
This profile selects the explicit shared route for all Tokener bootstrap and
|
||||
metering, including ordinary new signups and prior staging intents, without
|
||||
redirects. It takes precedence over the old signup Billing selector and ignores
|
||||
the old exact-email selector. Without the environment profile, previous
|
||||
selector behavior is unchanged. The package pin is signup-only; do not
|
||||
replace the global Tokener plugin or provider. The shared server uses a single
|
||||
staging Partner for Tokener; it does not choose the environment by tenant or
|
||||
fall back to dev. Existing dev bindings and failed signup rows are not
|
||||
|
||||
@@ -11,7 +11,7 @@ def configured_signup_enrollment(email: str | None = None) -> TokenerSignupEnrol
|
||||
"""Freeze the Cloud signup pin; reject a mismatched staging route before creating an intent."""
|
||||
if dify_config.DEPLOYMENT_EDITION == DeploymentEdition.CLOUD and dify_config.TOKENER_NEW_TENANT_COHORT_ENABLED:
|
||||
default_identifier = dify_config.TOKENER_PLUGIN_UNIQUE_IDENTIFIER.strip()
|
||||
configured = dify_config.TOKENER_SIGNUP_VALIDATION_BILLING_API_URL
|
||||
configured = dify_config.get_agent_dev_tokener_signup_billing_mode()
|
||||
if configured == TokenerSignupBillingCandidate.SHARED_STAGING:
|
||||
if dify_config.get_agent_dev_staging_tokener_billing_url() is None:
|
||||
raise ValueError("The shared staging Tokener signup is not fully configured.")
|
||||
|
||||
@@ -324,7 +324,7 @@ class BillingService:
|
||||
target for all Tokener operations. Outside that mode, isolated
|
||||
validation still uses the original durable intent and fails closed.
|
||||
"""
|
||||
configured = dify_config.TOKENER_SIGNUP_VALIDATION_BILLING_API_URL
|
||||
configured = dify_config.get_agent_dev_tokener_signup_billing_mode()
|
||||
default_base = dify_config.TOKENER_BILLING_API_URL.strip().rstrip("/")
|
||||
if dify_config.DEPLOYMENT_EDITION != DeploymentEdition.CLOUD:
|
||||
return default_base, False
|
||||
|
||||
@@ -5,7 +5,15 @@ import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
import configs.feature as feature_config
|
||||
from configs.feature import AuthConfig, DataSetConfig, FileUploadConfig, LoggingConfig
|
||||
from configs.feature import (
|
||||
AgentDevTokenerEnvironment,
|
||||
AuthConfig,
|
||||
DataSetConfig,
|
||||
FileUploadConfig,
|
||||
LoggingConfig,
|
||||
PluginConfig,
|
||||
TokenerSignupBillingCandidate,
|
||||
)
|
||||
from tests.helpers.unit.configs._isolated_settings import InitSettingsOnly
|
||||
|
||||
|
||||
@@ -17,6 +25,19 @@ class _IsolatedDataSetConfig(InitSettingsOnly, DataSetConfig):
|
||||
pass
|
||||
|
||||
|
||||
def test_agent_dev_tokener_profile_reads_staging_from_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("AGENT_DEV_TOKENER_ENVIRONMENT", "staging")
|
||||
config = PluginConfig(_env_file=None)
|
||||
assert config.AGENT_DEV_TOKENER_ENVIRONMENT == AgentDevTokenerEnvironment.STAGING
|
||||
assert config.get_agent_dev_tokener_signup_billing_mode() == TokenerSignupBillingCandidate.SHARED_STAGING
|
||||
|
||||
|
||||
def test_agent_dev_tokener_profile_rejects_production_value(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("AGENT_DEV_TOKENER_ENVIRONMENT", "production")
|
||||
with pytest.raises(ValidationError, match="AGENT_DEV_TOKENER_ENVIRONMENT"):
|
||||
PluginConfig(_env_file=None)
|
||||
|
||||
|
||||
def test_dataset_description_max_length_defaults_to_400() -> None:
|
||||
assert _IsolatedDataSetConfig().DATASET_DESCRIPTION_MAX_LENGTH == 400
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from blinker import Signal
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from configs.feature import TokenerSignupBillingCandidate
|
||||
from configs.feature import AgentDevTokenerEnvironment, TokenerSignupBillingCandidate
|
||||
from enums import DeploymentEdition
|
||||
from models import TenantCreditPool
|
||||
from models.model_billing import TenantModelBillingProfile
|
||||
@@ -64,7 +64,19 @@ def test_signup_canary_only_pins_the_exact_configured_account(monkeypatch: pytes
|
||||
assert configured_signup_enrollment("another@example.invalid") == TokenerSignupEnrollment(UID)
|
||||
|
||||
|
||||
def test_shared_staging_signup_uses_signup_only_pin_regardless_of_email(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("profile", "validation_route"),
|
||||
[
|
||||
(AgentDevTokenerEnvironment.INHERIT, TokenerSignupBillingCandidate.SHARED_STAGING),
|
||||
(AgentDevTokenerEnvironment.STAGING, TokenerSignupBillingCandidate.DISABLED),
|
||||
(AgentDevTokenerEnvironment.STAGING, TokenerSignupBillingCandidate.HOSTED_SIGNUP),
|
||||
],
|
||||
)
|
||||
def test_shared_staging_signup_uses_signup_only_pin_regardless_of_email(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
profile: AgentDevTokenerEnvironment,
|
||||
validation_route: TokenerSignupBillingCandidate,
|
||||
) -> None:
|
||||
apply_config_overrides(
|
||||
monkeypatch,
|
||||
DEPLOYMENT_EDITION=DeploymentEdition.CLOUD,
|
||||
@@ -72,7 +84,8 @@ def test_shared_staging_signup_uses_signup_only_pin_regardless_of_email(monkeypa
|
||||
TOKENER_PLUGIN_UNIQUE_IDENTIFIER=UID,
|
||||
TOKENER_SIGNUP_VALIDATION_EMAIL="stage-canary@example.invalid",
|
||||
TOKENER_SIGNUP_VALIDATION_PLUGIN_UNIQUE_IDENTIFIER=SHARED_UID,
|
||||
TOKENER_SIGNUP_VALIDATION_BILLING_API_URL=TokenerSignupBillingCandidate.SHARED_STAGING,
|
||||
AGENT_DEV_TOKENER_ENVIRONMENT=profile,
|
||||
TOKENER_SIGNUP_VALIDATION_BILLING_API_URL=validation_route,
|
||||
TOKENER_BILLING_API_URL=TokenerSignupBillingCandidate.SHARED_STAGING.value,
|
||||
TOKENER_ENDPOINT_URL="https://api-dev.tokener.dev",
|
||||
)
|
||||
@@ -171,7 +184,8 @@ def test_shared_staging_ordinary_account_persists_signup_only_package(
|
||||
apply_config_overrides(
|
||||
monkeypatch,
|
||||
TOKENER_SIGNUP_VALIDATION_PLUGIN_UNIQUE_IDENTIFIER=SHARED_UID,
|
||||
TOKENER_SIGNUP_VALIDATION_BILLING_API_URL=TokenerSignupBillingCandidate.SHARED_STAGING,
|
||||
AGENT_DEV_TOKENER_ENVIRONMENT=AgentDevTokenerEnvironment.STAGING,
|
||||
TOKENER_SIGNUP_VALIDATION_BILLING_API_URL=TokenerSignupBillingCandidate.DISABLED,
|
||||
TOKENER_BILLING_API_URL=TokenerSignupBillingCandidate.SHARED_STAGING.value,
|
||||
)
|
||||
account = signup_domain.accounts.create_account_and_tenant(f"{uuid4()}@example.test", "Stage user", "en-US")
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
import pytest
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from configs.feature import TokenerSignupBillingCandidate
|
||||
from configs.feature import AgentDevTokenerEnvironment, TokenerSignupBillingCandidate
|
||||
from enums import DeploymentEdition
|
||||
from models.account import Account, Tenant
|
||||
from models.tokener import AccountTokenerSignupIntent
|
||||
@@ -108,3 +108,19 @@ def test_hosted_candidate_does_not_move_existing_signup_or_fall_back_on_disable(
|
||||
):
|
||||
with pytest.raises(BillingUpstreamUnavailableError):
|
||||
BillingService._tokener_signup_validation_base(hosted.id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_guard", ["base", "uid", None])
|
||||
def test_staging_environment_uses_one_shared_route_without_isolated_fallback(invalid_guard: str | None) -> None:
|
||||
with config_overrides_context(
|
||||
DEPLOYMENT_EDITION=DeploymentEdition.CLOUD,
|
||||
AGENT_DEV_TOKENER_ENVIRONMENT=AgentDevTokenerEnvironment.STAGING,
|
||||
TOKENER_BILLING_API_URL="https://invalid.example" if invalid_guard == "base" else _EXISTING,
|
||||
TOKENER_SIGNUP_VALIDATION_BILLING_API_URL=TokenerSignupBillingCandidate.HOSTED_SIGNUP,
|
||||
TOKENER_SIGNUP_VALIDATION_PLUGIN_UNIQUE_IDENTIFIER="" if invalid_guard == "uid" else _SHARED_UID,
|
||||
):
|
||||
if invalid_guard is None:
|
||||
assert BillingService._tokener_signup_validation_base("any-workspace") == (_EXISTING, True)
|
||||
else:
|
||||
with pytest.raises(BillingUpstreamUnavailableError):
|
||||
BillingService._tokener_signup_validation_base("any-workspace")
|
||||
Reference in new issue
Block a user