diff --git a/tests/test_live_hooks.py b/tests/test_live_hooks.py index 9ee9522..2149747 100644 --- a/tests/test_live_hooks.py +++ b/tests/test_live_hooks.py @@ -1407,6 +1407,20 @@ def test_codex_never_overrides_a_key_the_user_set(tmp_path): assert kept == "[agents] # t\nmax_threads = 4\n" +def test_codex_apply_does_not_record_a_capability_the_user_already_set(repo, tmp_path, + codex_accepts): + st = Store(str(tmp_path / "st")) + path = denylist.settings_path(repo, "codex") + os.makedirs(os.path.dirname(path)) + with open(path, "w", encoding="utf-8") as f: + f.write("[features]\ngoals = true\n") + assert denylist.apply(repo, ["goals"], st, host="codex") == [] + assert denylist.applied(st) == [] + assert open(path, encoding="utf-8").read() == "[features]\ngoals = true\n" + assert denylist.apply(repo, ["goals", "image_media"], st, host="codex") == ["image_media"] + assert denylist.applied(st) == ["image_media"] + + def test_codex_trust_is_read_from_the_users_config(tmp_path, repo): home = tmp_path / "codex-home" home.mkdir() diff --git a/tokeneconomizer/plugin/denylist.py b/tokeneconomizer/plugin/denylist.py index 74ee9c6..7f75a78 100644 --- a/tokeneconomizer/plugin/denylist.py +++ b/tokeneconomizer/plugin/denylist.py @@ -429,9 +429,12 @@ def _apply_codex(repo_root, capabilities, store): for cap in capabilities: if cap not in CODEX_TOGGLES or cap in applied(store, path): continue + changed = False for table, key, value in CODEX_TOGGLES[cap]: - text, _ = _toml_insert(text, table, key, value, f"{MARK}:{cap}") - added.append(cap) + text, did = _toml_insert(text, table, key, value, f"{MARK}:{cap}") + changed = changed or did + if changed: + added.append(cap) if not added: return [] if not _toml_valid(text):