Skip to content

Commit 3aac18e

Browse files
committed
fix(guard): preserve inline table arrays in config
Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
1 parent 1e3fde8 commit 3aac18e

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/codex_plugin_scanner/guard/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,19 @@ def _toml_literal(value: object) -> str:
286286
return json.dumps(value)
287287
if isinstance(value, list):
288288
return "[" + ", ".join(_toml_literal(item) for item in value) + "]"
289+
if isinstance(value, dict):
290+
return _toml_inline_table(value)
289291
return json.dumps(str(value))
290292

291293

294+
def _toml_inline_table(value: dict[object, object]) -> str:
295+
items: list[str] = []
296+
for key, item in sorted(value.items(), key=lambda entry: str(entry[0])):
297+
if isinstance(key, str):
298+
items.append(f"{_toml_key(key)} = {_toml_literal(item)}")
299+
return "{ " + ", ".join(items) + " }"
300+
301+
292302
def overlay_synced_guard_policy(
293303
config: GuardConfig,
294304
payload: dict[str, object] | None,

tests/test_guard_config_paths.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ def test_dashboard_settings_update_preserves_existing_array_config_values(tmp_pa
172172
assert config_payload["trusted_harnesses"] == ["codex", "claude-code"]
173173

174174

175+
def test_dashboard_settings_update_preserves_existing_inline_table_array_config_values(tmp_path):
176+
guard_home = tmp_path / ".hol-guard"
177+
_write_text(
178+
guard_home / "config.toml",
179+
'mode = "prompt"\nrules = [{ name = "canary", action = "review", weight = 0.5 }]\n',
180+
)
181+
182+
updated = update_guard_settings(
183+
guard_home,
184+
{
185+
"mode": "enforce",
186+
},
187+
)
188+
config_payload = guard_config_module._read_toml(guard_home / "config.toml")
189+
190+
assert updated.mode == "enforce"
191+
assert config_payload["rules"] == [{"name": "canary", "action": "review", "weight": 0.5}]
192+
193+
175194
def test_resolve_guard_home_migrates_legacy_directory_into_canonical_home(tmp_path, monkeypatch):
176195
home_dir = tmp_path / "home"
177196
legacy_home = home_dir / ".config" / ".ai-plugin-scanner-guard"

0 commit comments

Comments
 (0)