Improve remote session management and Windows support
This commit is contained in:
@@ -8,6 +8,7 @@ import tempfile
|
||||
import unittest
|
||||
import uuid
|
||||
|
||||
from herdr_hub.aliases import AliasRegistry
|
||||
from herdr_hub.cli import TmuxHub
|
||||
|
||||
|
||||
@@ -29,6 +30,8 @@ class CliIntegrationTests(unittest.TestCase):
|
||||
"orangepi",
|
||||
"--remote-keybindings",
|
||||
"server",
|
||||
"--transport",
|
||||
"ssh",
|
||||
],
|
||||
cwd=repository_root,
|
||||
env=environment,
|
||||
@@ -45,7 +48,7 @@ class CliIntegrationTests(unittest.TestCase):
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
self.assertEqual(listing.stdout.strip(), "orangepi\tserver")
|
||||
self.assertEqual(listing.stdout.strip(), "orangepi\tserver\tssh")
|
||||
remove = subprocess.run(
|
||||
[str(launcher), "remote", "remove", "orangepi"],
|
||||
cwd=repository_root,
|
||||
@@ -87,7 +90,9 @@ class CliIntegrationTests(unittest.TestCase):
|
||||
"HERDR_HUB_SESSION": "hub",
|
||||
"HERDR_HUB_TMUX_CONFIG": "/dev/null",
|
||||
"HERDR_HUB_PROC_ROOT": str(proc_root),
|
||||
"HERDR_HUB_ALIASES_FILE": str(root / "aliases.json"),
|
||||
}
|
||||
AliasRegistry(root / "aliases.json").set("local:default", "主工作")
|
||||
|
||||
refresh = subprocess.run(
|
||||
[str(launcher), "refresh"],
|
||||
@@ -118,7 +123,11 @@ class CliIntegrationTests(unittest.TestCase):
|
||||
[window.key for window in hub.managed_windows()],
|
||||
["local:default"],
|
||||
)
|
||||
self.assertEqual(hub.managed_windows()[0].name, "主工作")
|
||||
|
||||
# Operational recovery must remain possible even if optional
|
||||
# display-name configuration is later corrupted.
|
||||
(root / "aliases.json").write_text("not json", encoding="utf-8")
|
||||
stop = subprocess.run(
|
||||
[str(launcher), "stop"],
|
||||
cwd=repository_root,
|
||||
@@ -131,6 +140,43 @@ class CliIntegrationTests(unittest.TestCase):
|
||||
self.assertIn("Herdr servers were left running", stop.stdout)
|
||||
self.assertFalse(hub.exists())
|
||||
|
||||
def test_empty_refresh_does_not_leave_a_bootstrap_hub(self) -> None:
|
||||
repository_root = Path(__file__).resolve().parents[1]
|
||||
launcher = repository_root / "bin" / "herdr-hub"
|
||||
socket_name = f"herdr-hub-empty-test-{os.getpid()}-{uuid.uuid4().hex[:8]}"
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
proc_root = root / "proc"
|
||||
proc_root.mkdir()
|
||||
environment = {
|
||||
**os.environ,
|
||||
"HERDR_HUB_HERDR_BIN": "/bin/false",
|
||||
"HERDR_HUB_TMUX_BIN": shutil.which("tmux") or "tmux",
|
||||
"HERDR_HUB_SOCKET": socket_name,
|
||||
"HERDR_HUB_SESSION": "hub",
|
||||
"HERDR_HUB_TMUX_CONFIG": "/dev/null",
|
||||
"HERDR_HUB_PROC_ROOT": str(proc_root),
|
||||
"HERDR_HUB_ALIASES_FILE": str(root / "aliases.json"),
|
||||
"HERDR_HUB_REMOTES_FILE": str(root / "remotes.json"),
|
||||
}
|
||||
refresh = subprocess.run(
|
||||
[str(launcher), "refresh"],
|
||||
cwd=repository_root,
|
||||
env=environment,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
self.assertEqual(refresh.returncode, 0, refresh.stderr)
|
||||
hub = TmuxHub(
|
||||
tmux_bin=shutil.which("tmux") or "tmux",
|
||||
socket_name=socket_name,
|
||||
session_name="hub",
|
||||
config_file="/dev/null",
|
||||
)
|
||||
self.addCleanup(hub.stop)
|
||||
self.assertFalse(hub.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user