fix: print config hint when logs token is missing

--once --logs now exits 2 with a clear pointer to SHUSUB2_LOGS_TOKEN /
~/.config/shusub2/logs-token instead of a raw HTTP 401 traceback; the TUI
logs page reuses the same hint.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 02:24:41 +08:00
parent b68d801024
commit 7d78f1ab63
2 changed files with 31 additions and 4 deletions
+20
View File
@@ -469,6 +469,26 @@ class Sub2APILogsTests(unittest.TestCase):
else:
os.environ["SHUSUB2_LOGS_TOKEN_FILE"] = old_value
def test_once_logs_without_token_prints_hint_and_exits_2(self) -> None:
mod = load_module()
old_token = os.environ.pop("SHUSUB2_LOGS_TOKEN", None)
old_file = os.environ.get("SHUSUB2_LOGS_TOKEN_FILE")
os.environ["SHUSUB2_LOGS_TOKEN_FILE"] = "/nonexistent/shusub2/logs-token"
err = io.StringIO()
try:
with contextlib.redirect_stderr(err):
rc = mod.main(["--once", "--logs", "--no-version-check"])
finally:
if old_token is not None:
os.environ["SHUSUB2_LOGS_TOKEN"] = old_token
if old_file is None:
os.environ.pop("SHUSUB2_LOGS_TOKEN_FILE", None)
else:
os.environ["SHUSUB2_LOGS_TOKEN_FILE"] = old_file
self.assertEqual(rc, 2)
self.assertIn("logs token not configured", err.getvalue())
def test_default_logs_url_defaults_to_sub2apicn(self) -> None:
mod = load_module()
old_url = os.environ.pop("SHUSUB2_LOGS_URL", None)