Simplify plugin-helper state configuration
This commit is contained in:
+89
-38
@@ -17,7 +17,7 @@ from plugin_helper.bootstrap import _run_ipa
|
||||
from plugin_helper.beatmods import by_version_id, normalize_mods
|
||||
from plugin_helper.checker import check_lock
|
||||
from plugin_helper.cli import installed_plugins_report, run
|
||||
from plugin_helper.config import load_profiles, profile_by_id, resolve_runtime_config
|
||||
from plugin_helper.config import load_local_config, resolve_runtime_config
|
||||
from plugin_helper.fsutil import sha256_file
|
||||
from plugin_helper.installer import apply_plan, disable_plugin, uninstall_plugin
|
||||
from plugin_helper.instances import get_instance, list_instances
|
||||
@@ -125,61 +125,112 @@ class PluginHelperTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "ambiguous"):
|
||||
get_instance([windows, local], "1.44.1")
|
||||
|
||||
def test_profile_config_loads_and_resolves_paths(self) -> None:
|
||||
def test_local_config_loads_top_level_paths(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
config = root / "plugin-helper.local.toml"
|
||||
config.write_text(
|
||||
"""
|
||||
[[profiles]]
|
||||
id = "linux"
|
||||
label = "Linux"
|
||||
instances_root = "~/BSInstances"
|
||||
state_dir = ".state"
|
||||
|
||||
[[profiles]]
|
||||
id = "windows"
|
||||
label = "Windows"
|
||||
instances_root = "mounted/BSInstances"
|
||||
state_dir = ".state-windows"
|
||||
""".lstrip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
profiles, loaded_path, loaded = load_profiles(config, root=root)
|
||||
local_config, loaded_path, loaded = load_local_config(config, root=root)
|
||||
|
||||
self.assertTrue(loaded)
|
||||
self.assertEqual(loaded_path, config)
|
||||
self.assertEqual(profile_by_id(profiles, "linux").instances_root, Path("~/BSInstances").expanduser())
|
||||
self.assertEqual(profile_by_id(profiles, "windows").instances_root, root / "mounted" / "BSInstances")
|
||||
self.assertEqual(profile_by_id(profiles, "windows").state_dir, root / ".state-windows")
|
||||
self.assertEqual(local_config.instances_roots, [Path("~/BSInstances").expanduser()])
|
||||
self.assertEqual(local_config.state_root, root / ".state")
|
||||
|
||||
def test_profile_runtime_explicit_overrides(self) -> None:
|
||||
def test_runtime_explicit_overrides_env_and_config(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
config = root / "plugin-helper.local.toml"
|
||||
config.write_text(
|
||||
(root / "plugin-helper.local.toml").write_text(
|
||||
"""
|
||||
[[profiles]]
|
||||
id = "linux"
|
||||
label = "Linux"
|
||||
instances_root = "profile-root"
|
||||
state_dir = ".state"
|
||||
instances_root = "config-root"
|
||||
state_dir = "config-state"
|
||||
""".lstrip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
runtime = resolve_runtime_config(
|
||||
instances_root_value=str(root / "explicit-root"),
|
||||
state_dir_value="explicit-state",
|
||||
profile_id="linux",
|
||||
config_path=config,
|
||||
root=root,
|
||||
)
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"PLUGIN_HELPER_INSTANCES_ROOT": str(root / "env-root"),
|
||||
"PLUGIN_HELPER_STATE_DIR": str(root / "env-state"),
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
runtime = resolve_runtime_config(
|
||||
instances_root_value=str(root / "explicit-root"),
|
||||
state_dir_value="explicit-state",
|
||||
root=root,
|
||||
)
|
||||
|
||||
self.assertEqual(runtime.instances_roots, [root / "explicit-root"])
|
||||
self.assertEqual(runtime.state_root, root / "explicit-state")
|
||||
self.assertEqual(runtime.selected_profile.id, "linux")
|
||||
|
||||
def test_runtime_env_overrides_config(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
(root / "plugin-helper.local.toml").write_text(
|
||||
"""
|
||||
instances_root = "config-root"
|
||||
state_dir = "config-state"
|
||||
""".lstrip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"PLUGIN_HELPER_INSTANCES_ROOT": f"{root / 'env-root-a'}{os.pathsep}{root / 'env-root-b'}",
|
||||
"PLUGIN_HELPER_STATE_DIR": str(root / "env-state"),
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
runtime = resolve_runtime_config(root=root)
|
||||
|
||||
self.assertEqual(runtime.instances_roots, [root / "env-root-a", root / "env-root-b"])
|
||||
self.assertEqual(runtime.state_root, root / "env-state")
|
||||
|
||||
def test_runtime_uses_local_config_before_defaults(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
(root / "plugin-helper.local.toml").write_text(
|
||||
"""
|
||||
instances_root = "config-root"
|
||||
state_dir = "config-state"
|
||||
""".lstrip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
runtime = resolve_runtime_config(root=root)
|
||||
|
||||
self.assertEqual(runtime.instances_roots, [root / "config-root"])
|
||||
self.assertEqual(runtime.state_root, root / "config-state")
|
||||
|
||||
def test_runtime_default_state_uses_xdg_state_home(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
xdg = root / "xdg-state"
|
||||
|
||||
with patch.dict(os.environ, {"XDG_STATE_HOME": str(xdg)}, clear=True):
|
||||
runtime = resolve_runtime_config(root=root)
|
||||
|
||||
self.assertEqual(runtime.state_root, xdg / "plugin-helper")
|
||||
|
||||
def test_runtime_default_state_uses_home_local_state(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
runtime = resolve_runtime_config(root=root)
|
||||
|
||||
self.assertEqual(runtime.state_root, Path.home() / ".local" / "state" / "plugin-helper")
|
||||
|
||||
def test_no_args_prints_help_when_not_interactive(self) -> None:
|
||||
output = StringIO()
|
||||
@@ -196,7 +247,7 @@ state_dir = ".state"
|
||||
patch("sys.stdout.isatty", return_value=True),
|
||||
patch("plugin_helper.cli._run_menu", return_value=0) as run_menu,
|
||||
):
|
||||
status = run(["--profile", "linux"])
|
||||
status = run([])
|
||||
|
||||
self.assertEqual(status, 0)
|
||||
run_menu.assert_called_once()
|
||||
@@ -1063,8 +1114,8 @@ sha256 = "{sha256_file(asset)}"
|
||||
{"instance": "1.40.8", "plugins": plugins, "disabledPlugins": disabled_plugins},
|
||||
)
|
||||
choice = InstallationChoice(
|
||||
profile_id="test",
|
||||
profile_label="Test Profile",
|
||||
install_id="test",
|
||||
install_label="Test Install",
|
||||
instance_name="1.40.8",
|
||||
instance_path=instance,
|
||||
state_root=state,
|
||||
@@ -1076,15 +1127,15 @@ class PluginHelperTuiTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_installation_picker_shows_duplicate_instances_with_state_dirs(self) -> None:
|
||||
choices = [
|
||||
InstallationChoice(
|
||||
profile_id="linux",
|
||||
profile_label="Linux",
|
||||
install_id="linux",
|
||||
install_label="Linux",
|
||||
instance_name="1.44.1",
|
||||
instance_path=Path("/tmp/linux/1.44.1"),
|
||||
state_root=Path("/tmp/state-linux"),
|
||||
),
|
||||
InstallationChoice(
|
||||
profile_id="windows",
|
||||
profile_label="Windows",
|
||||
install_id="windows",
|
||||
install_label="Windows",
|
||||
instance_name="1.44.1",
|
||||
instance_path=Path("/tmp/windows/1.44.1"),
|
||||
state_root=Path("/tmp/state-windows"),
|
||||
|
||||
Reference in New Issue
Block a user