mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-13 05:07:40 +02:00
* [haik]: ckpt, added in the test runner skelton i made in another repo -> still gotta make tweaks to fold it onto the current repo * [haik]: restructure backend test layout: move 37 test files from backend/tests/ into backend/tests/test_cases/, add backend/tests/run.sh one-command launcher that auto-provisions both runner and test venvs with stamp-based caching, update runner config.json to point test_paths at test_cases/ and fix venv_python path, revise runner README with run.sh usage and clearer setup instructions, and gitignore the .runner-venv directory * [haik]: refactor: reorganize backend/tests/test_cases from flat structure into domain subdirectories — moved 36 test files into auth/, browser/, labeling/, service/, settings/, and web_search/ for better discoverability and grouping * [haik]: overhaul test picker UI and add post-run rerun loop: replace checkbox glyphs with fzf-style row recolouring (coral=full, lighter coral=partial) and a right-pinned selection dot, add config-driven icon tiers (nerd/emoji/unicode/ascii) with per-glyph graceful degradation, replace the modal -k keyword screen with an inline live-filtering search bar that prunes the tree on every keystroke, add warm Anthropic-dark coral theme, toolbar flag chips replacing the old status line, and a floating help badge overlay; add rerun_prompt.py with inline Textual pill prompt (rerun all/failed/passed/exit) shown after each TTY run, wire it into main.py as a post-run loop; change run_tests to return (exit_code, RunSummary) tracking collected/passed/failed node IDs via new Dashboard methods; add icons field to config.py and config.json (set to nerd), document icon tiers and Nerd Font setup in README, set Hack Nerd Font in .vscode/settings.json, add .runner-venv to linter excludes
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
"""Free-trial dispatch injection: the pure-logic pieces that decide routing."""
|
|
|
|
import backend # noqa: F401 (path sanity asserted below)
|
|
|
|
from backend.apps.settings.models import AppSettings
|
|
from backend.apps.settings.credentials import proxy_auth
|
|
from backend.apps.agents.core.error_classify import (
|
|
is_free_trial_exhausted,
|
|
is_transient_capacity_error,
|
|
)
|
|
from backend.apps.agents.providers.registry import resolve_model_id_for_sdk
|
|
from backend.apps.subscription.free_trial import has_own_model
|
|
|
|
|
|
def test_proxy_auth_for_each_mode():
|
|
assert proxy_auth(AppSettings()) == (None, None)
|
|
|
|
pro = AppSettings(
|
|
connection_mode="openswarm-pro",
|
|
openswarm_bearer_token="bear",
|
|
openswarm_proxy_url="https://api.openswarm.com",
|
|
)
|
|
assert proxy_auth(pro) == ("bear", "https://api.openswarm.com")
|
|
|
|
free = AppSettings(
|
|
connection_mode="free-trial",
|
|
free_trial_token="ftk",
|
|
openswarm_proxy_url="https://api.openswarm.com",
|
|
)
|
|
# Free-trial carries the /free segment so the same SDK lands on the metered route.
|
|
assert proxy_auth(free) == ("ftk", "https://api.openswarm.com/free")
|
|
|
|
|
|
def test_free_trial_resolves_to_a_bare_anthropic_id():
|
|
s = AppSettings(connection_mode="free-trial", free_trial_token="ftk")
|
|
mid = resolve_model_id_for_sdk("sonnet", s)
|
|
# The bug this fixes: without the free-trial branch this returns a cc/-prefixed
|
|
# id that 401s when no Claude subscription is connected.
|
|
assert "cc/" not in mid
|
|
assert mid.startswith("claude-")
|
|
|
|
|
|
def test_exhaustion_is_classified_and_not_retried():
|
|
assert is_free_trial_exhausted(Exception("error type free_trial_exhausted"))
|
|
assert is_free_trial_exhausted(Exception("You've used your free OpenSwarm runs"))
|
|
assert not is_free_trial_exhausted(Exception("overloaded, try again"))
|
|
# Must NOT look transient, or the agent loop would retry a spent trial forever.
|
|
assert not is_transient_capacity_error(Exception("free_trial_exhausted"))
|
|
|
|
|
|
def test_has_own_model_never_shadows_a_real_provider():
|
|
assert not has_own_model(AppSettings(connection_mode="free-trial", free_trial_token="x"))
|
|
assert not has_own_model(AppSettings())
|
|
assert has_own_model(AppSettings(anthropic_api_key="sk-ant-x"))
|
|
assert has_own_model(
|
|
AppSettings(connection_mode="openswarm-pro", openswarm_bearer_token="b")
|
|
)
|