feat(settings): add an explicit opt-out from persisted portable mode

Setting LORA_MANAGER_PORTABLE=1 once wrote use_portable_settings: true
into the plugin's own settings.json, and every later run of every
instance sharing that plugin folder then read and wrote the portable
settings directory. There was no way back except editing the file by
hand, which is exactly the trap a user hit while following the FAQ's
instructions for isolating a second instance (#1114).

LORA_MANAGER_PORTABLE=0 is now the explicit exit:

- _should_use_portable_settings honours "0" as a forced off, so the
  resolved settings directory no longer depends on the persisted flag.
- SettingsManager clears the persisted flag in that case, so later runs
  without the variable stay on the shared settings directory.

Unset or unrecognised values keep the previous behaviour: the persisted
flag decides, so existing portable installs are unaffected.
LORA_MANAGER_SETTINGS_DIR still takes precedence over both.
This commit is contained in:
Will Miao
2026-09-18 00:05:47 +08:00
parent e14a084f0d
commit 8c1c1691e3
4 changed files with 171 additions and 8 deletions
+20 -3
View File
@@ -34,10 +34,12 @@ class TestShouldUsePortableSettings:
@pytest.mark.parametrize(
"env_value, settings_flag, expected",
[
("1", False, True), # env = 1 overrides settings.json false
("1", False, True), # env = 1 forces portable on
("1", True, True), # env = 1 matches settings.json true
("0", False, False), # env = 0 → rely on settings.json
("0", True, True), # env = 0 → rely on settings.json
("0", False, False), # env = 0 forces portable off
("0", True, False), # env = 0 overrides a persisted true
("yes", False, False), # unrecognised value → rely on settings.json
("yes", True, True), # unrecognised value → rely on settings.json
("", False, False), # unset → rely on settings.json
("", True, True), # unset → rely on settings.json
],
@@ -58,6 +60,21 @@ class TestShouldUsePortableSettings:
result = _should_use_portable_settings(str(settings_file), logging.getLogger())
assert result == expected
def test_explicit_zero_is_the_documented_opt_out(self, tmp_path, caplog):
"""`=0` must be honoured even against a persisted true flag."""
settings_file = tmp_path / "settings.json"
settings_file.write_text(json.dumps({"use_portable_settings": True}))
with pytest.MonkeyPatch.context() as mp:
mp.setenv("LORA_MANAGER_PORTABLE", "0")
with caplog.at_level(logging.INFO):
result = _should_use_portable_settings(
str(settings_file), logging.getLogger()
)
assert result is False
assert "Portable mode disabled" in caplog.text
def test_missing_file_without_env(self, tmp_path):
"""Without env var, missing settings file returns False."""
missing = tmp_path / "nonexistent.json"