mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 02:05:22 -04:00
fix: detect HuggingFace token when downloading cookbook models (#3459)
Co-authored-by: Alexandre Teixeira <111787685+alteixeira20@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Cookbook HF token persistence and lookup."""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from routes.cookbook_helpers import load_stored_hf_token
|
||||
from src.secret_storage import encrypt
|
||||
|
||||
|
||||
def test_load_stored_hf_token_reads_encrypted_state(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
||||
state_path = tmp_path / "cookbook_state.json"
|
||||
state_path.write_text(
|
||||
json.dumps({"env": {"hfToken": encrypt("hf_test_token_12345")}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert load_stored_hf_token() == "hf_test_token_12345"
|
||||
assert load_stored_hf_token(state_path=state_path) == "hf_test_token_12345"
|
||||
|
||||
|
||||
def test_load_stored_hf_token_falls_back_to_env_when_state_missing(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
||||
monkeypatch.setenv("HF_TOKEN", "hf_from_env")
|
||||
assert load_stored_hf_token() == "hf_from_env"
|
||||
|
||||
|
||||
def test_load_stored_hf_token_prefers_state_over_env(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
||||
monkeypatch.setenv("HF_TOKEN", "hf_from_env")
|
||||
state_path = tmp_path / "cookbook_state.json"
|
||||
state_path.write_text(
|
||||
json.dumps({"env": {"hfToken": encrypt("hf_from_state")}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert load_stored_hf_token() == "hf_from_state"
|
||||
Reference in New Issue
Block a user