mirror of
https://github.com/Niko1221/Strata.git
synced 2026-11-07 06:15:58 -10:00
status and logs find the running launch when no address is given (F02)
This commit is contained in:
1 parent
a14e85d8e6
commit
217ddda0eb
2 files changed
+46
-1
No files matched your search
@@ -192,7 +192,7 @@ def run(a: argparse.Namespace) -> int:
|
||||
return _error("JSON monitor output requires --once; interactive monitor uses a terminal", 2, machine)
|
||||
if a.command == "monitor" and not a.once and not sys.stdout.isatty():
|
||||
return _error("interactive monitor needs a terminal; use --once or strata status --json", 2, machine)
|
||||
found = running_launch() if a.command == "monitor" and not (a.url or a.connection) else None
|
||||
found = running_launch() if a.command in ("monitor", "status", "logs") and not (a.url or a.connection) else None
|
||||
resolved = connections.resolve(url=found["url"] if found else a.url, connection=a.connection,
|
||||
credential_env=a.credential_env, timeout=a.timeout)
|
||||
endpoint = Endpoint(resolved["url"], os.environ.get(resolved["credential_env"]) or (found or {}).get("key"),
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Fixes from the owner's TUI stress test of the 0.2.3 RC (status/logs discovery, key reuse, retune, folder, quit keys, --model-path)."""
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from unittest import mock
|
||||
|
||||
from strata_cli.cli import main
|
||||
|
||||
|
||||
class StatusLogsDiscoveryTests(unittest.TestCase):
|
||||
"""#7 (F02): status and logs find the running launch without --url."""
|
||||
|
||||
def _run(self, *argv):
|
||||
info = {"running": True, "url": "http://127.0.0.1:8080", "key": "k-launch"}
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("STRATA_URL", "STRATA_CONNECTION")}
|
||||
out = io.StringIO()
|
||||
with mock.patch.dict(os.environ, env, clear=True), \
|
||||
mock.patch("strata_cli.launch.cmd.launch_info", return_value=info), \
|
||||
mock.patch("strata_cli.monitor_commands.Endpoint") as endpoint, redirect_stdout(out):
|
||||
endpoint.return_value.snapshot.return_value = {"schema_version": 1}
|
||||
code = main(list(argv))
|
||||
return code, endpoint
|
||||
|
||||
def test_status_uses_the_running_launch(self):
|
||||
code, endpoint = self._run("status", "--json")
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(endpoint.call_args[0][0], "http://127.0.0.1:8080")
|
||||
self.assertEqual(endpoint.call_args[0][1], "k-launch")
|
||||
|
||||
def test_logs_use_the_running_launch(self):
|
||||
with mock.patch("strata_cli.logs.run", return_value=0) as run:
|
||||
code, endpoint = self._run("logs")
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(endpoint.call_args[0][0], "http://127.0.0.1:8080")
|
||||
|
||||
def test_explicit_url_wins(self):
|
||||
code, endpoint = self._run("status", "--json", "--url", "http://127.0.0.1:9999")
|
||||
self.assertEqual(endpoint.call_args[0][0], "http://127.0.0.1:9999")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user