"""Tests for command modules — registration and target parsing.""" from flow.commands.enter import _parse_target, _terminfo_fix_command from flow.commands.container import _cname, _parse_image_ref class TestParseTarget: def test_full_target(self): user, ns, plat = _parse_target("root@personal@orb") assert user == "root" assert ns == "personal" assert plat == "orb" def test_no_user(self): user, ns, plat = _parse_target("personal@orb") assert user is None assert ns == "personal" assert plat == "orb" def test_namespace_only(self): user, ns, plat = _parse_target("personal") assert user is None assert ns == "personal" assert plat is None class TestTerminfoFixCommand: def test_ghostty_command(self): cmd = _terminfo_fix_command("xterm-ghostty", "devbox.core.lan") assert cmd == "infocmp -x xterm-ghostty | ssh devbox.core.lan -- tic -x -" def test_wezterm_command(self): cmd = _terminfo_fix_command("wezterm", "user@devbox.core.lan") assert cmd is not None assert "wezterm.terminfo" in cmd assert "ssh user@devbox.core.lan" in cmd def test_unknown_term(self): assert _terminfo_fix_command("xterm-256color", "devbox.core.lan") is None class TestCname: def test_adds_prefix(self): assert _cname("api") == "dev-api" def test_no_double_prefix(self): assert _cname("dev-api") == "dev-api" class TestParseImageRef: def test_simple_image(self): ref, repo, tag, label = _parse_image_ref("node") assert ref == "registry.tomastm.com/node:latest" assert tag == "latest" def test_tm0_shorthand(self): ref, repo, tag, label = _parse_image_ref("tm0/node") assert "registry.tomastm.com" in ref assert "node" in ref def test_docker_shorthand(self): ref, repo, tag, label = _parse_image_ref("docker/python") assert "docker.io" in ref assert "python" in ref def test_with_tag(self): ref, repo, tag, label = _parse_image_ref("node:20") assert tag == "20" assert ":20" in ref def test_full_registry(self): ref, repo, tag, label = _parse_image_ref("ghcr.io/user/image:v1") assert ref == "ghcr.io/user/image:v1" assert tag == "v1"