feat(settings): add explicit settings dir override for sandboxed runs

Add LORA_MANAGER_SETTINGS_DIR env var and standalone --settings-path to pin
the settings location (settings.json, cache/, wildcards/, backups/, logs/,
stats/) to an arbitrary directory. The override takes precedence over
portable mode and the platform user config dir, and skips legacy migration,
so sandboxed dev/E2E runs no longer need to write settings.json in the repo
root or collide with the real instance.

standalone.py pre-scans argv for --settings-path at import time because the
settings location is resolved before main() parses arguments. SettingsManager
portable-switch migration is a no-op while the directory is pinned.

Update the lora-manager-e2e skill (prefer --settings-path sandboxing;
start_server.py passes it through) and the lora-manager-runtime-context
skill (document precedence; inspect script honors the override).
This commit is contained in:
Will Miao
2026-08-27 00:03:50 +08:00
parent 1d3bcdfe47
commit 574dfbbe55
10 changed files with 383 additions and 30 deletions
+30
View File
@@ -293,6 +293,36 @@ def test_switching_back_to_user_config_moves_subdirectories(tmp_path, monkeypatc
) == "project_wildcard"
def test_portable_switch_ignored_when_settings_dir_pinned(tmp_path, monkeypatch):
"""An explicit settings dir (--settings-path) must never trigger the
portable-mode directory migration between project root and user config."""
project_root, user_dir, user_settings = _setup_storage_paths(tmp_path, monkeypatch)
_populate_settings_dir(user_dir)
custom_dir = tmp_path / "custom_settings"
custom_dir.mkdir()
monkeypatch.setattr(
"py.services.settings_manager.ensure_settings_file",
lambda logger=None: str(custom_dir / "settings.json"),
)
settings_paths.set_settings_dir_override(str(custom_dir))
try:
manager = SettingsManager()
manager.settings_file = str(custom_dir / "settings.json")
manager.set("use_portable_settings", True)
# Settings file stays pinned; no directories are migrated anywhere and
# the settings file is not mirrored to the user config dir.
assert manager.settings_file == str(custom_dir / "settings.json")
assert not (project_root / "cache").exists()
assert not (project_root / "backups").exists()
assert not (project_root / "settings.json").exists()
assert not user_settings.exists()
finally:
settings_paths.set_settings_dir_override(None)
def test_download_path_template_parses_json_string(manager):
templates = {"lora": "{author}", "checkpoint": "{author}", "embedding": "{author}"}
manager.settings["download_path_templates"] = json.dumps(templates)