b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
133 lines
3.5 KiB
Python
133 lines
3.5 KiB
Python
"""Tests for xAI Imagine storage helper behavior."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import yaml
|
|
|
|
|
|
def _invalidate_config_cache():
|
|
try:
|
|
import hermes_cli.config as cfg_mod
|
|
|
|
if hasattr(cfg_mod, "_invalidate_load_config_cache"):
|
|
cfg_mod._invalidate_load_config_cache()
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def test_storage_defaults_to_permanent_public_urls(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
_invalidate_config_cache()
|
|
|
|
from tools.xai_http import build_xai_storage_options
|
|
|
|
storage = build_xai_storage_options(
|
|
"image_gen",
|
|
filename_prefix="hermes-xai-image",
|
|
extension="png",
|
|
)
|
|
|
|
assert storage is not None
|
|
assert storage["public_url"] is True
|
|
assert "expires_after" not in storage
|
|
assert storage["filename"].startswith("hermes-xai-image-")
|
|
assert storage["filename"].endswith(".png")
|
|
|
|
|
|
def test_storage_can_be_disabled(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
(tmp_path / "config.yaml").write_text(yaml.safe_dump({
|
|
"video_gen": {
|
|
"xai": {
|
|
"storage": {
|
|
"enabled": False,
|
|
},
|
|
},
|
|
},
|
|
}))
|
|
_invalidate_config_cache()
|
|
|
|
from tools.xai_http import build_xai_storage_options, xai_storage_notice_text
|
|
|
|
assert build_xai_storage_options(
|
|
"video_gen",
|
|
filename_prefix="hermes-xai-video",
|
|
extension="mp4",
|
|
) is None
|
|
assert xai_storage_notice_text("video_gen") == ""
|
|
|
|
|
|
def test_storage_can_be_permanent(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
(tmp_path / "config.yaml").write_text(yaml.safe_dump({
|
|
"image_gen": {
|
|
"xai": {
|
|
"storage": {
|
|
"expires_after": "permanent",
|
|
},
|
|
},
|
|
},
|
|
}))
|
|
_invalidate_config_cache()
|
|
|
|
from tools.xai_http import build_xai_storage_options
|
|
|
|
storage = build_xai_storage_options(
|
|
"image_gen",
|
|
filename_prefix="hermes-xai-image",
|
|
extension="png",
|
|
)
|
|
|
|
assert storage is not None
|
|
assert "expires_after" not in storage
|
|
|
|
|
|
def test_storage_can_use_finite_retention(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
(tmp_path / "config.yaml").write_text(yaml.safe_dump({
|
|
"image_gen": {
|
|
"xai": {
|
|
"storage": {
|
|
"expires_after": 172800,
|
|
},
|
|
},
|
|
},
|
|
}))
|
|
_invalidate_config_cache()
|
|
|
|
from tools.xai_http import build_xai_storage_options
|
|
|
|
storage = build_xai_storage_options(
|
|
"image_gen",
|
|
filename_prefix="hermes-xai-image",
|
|
extension="png",
|
|
)
|
|
|
|
assert storage is not None
|
|
assert storage["expires_after"] == 172800
|
|
|
|
|
|
def test_invalid_storage_retention_falls_back_to_bounded_ttl(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
(tmp_path / "config.yaml").write_text(yaml.safe_dump({
|
|
"video_gen": {
|
|
"xai": {
|
|
"storage": {
|
|
"expires_after": "definitely-not-a-duration",
|
|
},
|
|
},
|
|
},
|
|
}))
|
|
_invalidate_config_cache()
|
|
|
|
from tools.xai_http import build_xai_storage_options
|
|
|
|
storage = build_xai_storage_options(
|
|
"video_gen",
|
|
filename_prefix="hermes-xai-video",
|
|
extension="mp4",
|
|
)
|
|
|
|
assert storage is not None
|
|
assert storage["expires_after"] == 172800
|