From 6ab92ec30ec2f1d83af535c3811dc4112f0a8151 Mon Sep 17 00:00:00 2001 From: Julian lechner Date: Wed, 30 Sep 2026 10:33:51 +0200 Subject: [PATCH] fix(config): preserve TOML table indentation --- scripts/lib/install-options.py | 4 ++-- scripts/tests/test-install-options.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/lib/install-options.py b/scripts/lib/install-options.py index 23ab677..0be2c2e 100644 --- a/scripts/lib/install-options.py +++ b/scripts/lib/install-options.py @@ -152,7 +152,7 @@ def merge_toml(current_text, managed_text, statusline_enabled=True): result = ''.join(managed_root).rstrip() if root_extras: - result += '\n' + ''.join(root_extras).strip() + result += '\n' + ''.join(root_extras).strip('\r\n') result += '\n' for header, block in managed_sections: result += ''.join(block) @@ -161,7 +161,7 @@ def merge_toml(current_text, managed_text, statusline_enabled=True): if not result.endswith('\n\n'): result += '\n' if extras: - result = result.rstrip() + '\n\n' + ''.join(extras).lstrip() + result = result.rstrip() + '\n\n' + ''.join(extras).lstrip('\r\n') tomllib.loads(result) return result diff --git a/scripts/tests/test-install-options.py b/scripts/tests/test-install-options.py index 50395ec..12988a6 100644 --- a/scripts/tests/test-install-options.py +++ b/scripts/tests/test-install-options.py @@ -16,6 +16,21 @@ SPEC.loader.exec_module(OPTIONS) class InstallOptionsTests(unittest.TestCase): + def test_merge_toml_preserves_local_plugin_table_indentation(self): + plugin_state = (' [marketplaces.ponytail]\n' + ' source_type = "git"\n' + ' source = "https://github.com/DietrichGebert/ponytail.git"\n' + ' [plugins."ponytail@ponytail"]\n' + ' enabled = true\n' + ' [plugins."disabled@market"]\n' + ' enabled = false') + current = "model = 'old'\napprovals_reviewer = 'user'\n" + plugin_state + '\n' + managed = "approvals_reviewer = 'auto_review'\n\n[tui]\n" + + result = OPTIONS.merge_toml(current, managed) + + self.assertIn(plugin_state, result) + def test_filter_preserves_other_claude_hooks_and_status(self): with tempfile.TemporaryDirectory() as directory: path = Path(directory) / 'settings.json'