* Studio: show HF token tick only after validation * Studio: prevent stale HF token validation state * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""Contracts for the Hugging Face token validation indicator."""
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
GENERAL_TAB = REPO / "studio/frontend/src/features/settings/tabs/general-tab.tsx"
|
|
VALIDATION_HOOK = REPO / "studio/frontend/src/hooks/use-hf-token-validation.ts"
|
|
|
|
|
|
def test_success_tick_requires_the_current_token_to_be_validated():
|
|
source = GENERAL_TAB.read_text(encoding = "utf-8")
|
|
|
|
assert "tokenIsCurrent && tokenValidation.isValid === true" in source
|
|
assert 'tokenValidated ? "pr-14" : "pr-8"' in source
|
|
assert "{tokenValidated ? (" in source
|
|
assert 'aria-label={t("settings.general.tokenValidated")}' in source
|
|
assert 'aria-label={t("settings.general.tokenSaved")}' not in source
|
|
|
|
|
|
def test_validation_result_must_belong_to_the_current_normalized_token():
|
|
source = VALIDATION_HOOK.read_text(encoding = "utf-8")
|
|
|
|
assert "const normalizedToken = token.trim()" in source
|
|
assert "useDebouncedValue(normalizedToken, 500)" in source
|
|
assert "if (!COMPLETE_HF_TOKEN.test(normalizedToken)) return INITIAL" in source
|
|
assert "if (completed.token !== normalizedToken)" in source
|
|
assert "if (completed.token !== debouncedToken)" not in source
|