Presets: fill missing built-in defaults on load
PresetManager.load already heals a forward-incompatible presets.json: the block just above repairs the legacy `custom` shape and re-saves the file. But if the file exists and is missing a whole built-in preset (e.g. an older install written before `reason` existed), load returned it as-is, so that built-in stayed permanently absent — silently missing from the picker that GET /api/presets feeds, with no way for the user to get it back. Extend the same self-heal: after the legacy migration, fill in any built-in presets the loaded file is missing, defaults-first so user edits win, and persist the result. This never clobbers an intentional removal — there is no delete path for the built-in keys (only user_templates entries can be deleted), and presets are hidden via an `enabled: False` flag, not removal. Checks: python -m pytest tests/test_preset_fill_missing_defaults.py (3 passed; 2 fail on the pre-fix code), the existing preset cases in tests/test_review_regressions.py still pass, python -m py_compile src/preset_manager.py, git diff --check.
This commit is contained in:
@@ -92,6 +92,18 @@ Use precise language. Show causal relationships explicitly. Quantify uncertainty
|
||||
custom.setdefault("inject_prefix", "")
|
||||
custom.setdefault("inject_suffix", "")
|
||||
self.save(presets)
|
||||
# Heal a forward-incompatible file the same way the legacy `custom`
|
||||
# migration above does: fill in any built-in presets an older or
|
||||
# partial presets.json is missing, so they reach existing installs
|
||||
# (a missing built-in is otherwise silently absent from the picker
|
||||
# served by GET /api/presets). There is no delete path for the
|
||||
# built-in keys, so this never clobbers an intentional removal.
|
||||
# Defaults first, loaded values win — user edits are preserved.
|
||||
if isinstance(presets, dict) and any(
|
||||
k not in presets for k in self.DEFAULT_PRESETS
|
||||
):
|
||||
presets = {**self.DEFAULT_PRESETS, **presets}
|
||||
self.save(presets)
|
||||
return presets
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading presets: {e}")
|
||||
|
||||
Reference in New Issue
Block a user