Skip to content

Keep non-string deny entries on install-hooks --remove - #163

Merged
aminueza merged 1 commit into
mainfrom
remove-non-string-deny-entries
Nov 5, 2026
Merged

aminueza merged 1 commit into
mainfrom
remove-non-string-deny-entries

Conversation

@felladrin

@felladrin felladrin commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Currently, keyfence install-hooks claude-code --remove stops with TypeError: unhashable type: 'dict' when the deny list in settings.json has an entry that is not a string (an object or a list). This PR keeps that entry in place and removes keyfence's rules around it, with or without --force.

This is the follow-up from the review of #162, which fixed the same problem on install.

How to test

  1. pytest tests/test_hooks.py -k test_uninstall_keeps_a_deny_entry_that_is_not_a_string (both cases fail on main with the TypeError).
  2. In an empty directory, write {"permissions": {"deny": [{"a": 1}, ["b"]]}} to .claude/settings.json, then run keyfence install-hooks claude-code --project.
  3. Run keyfence install-hooks claude-code --project --remove. It reports 42 rules removed, and the deny list is back to [{"a": 1}, ["b"]].
  4. Repeat steps 2 and 3 with --remove --force: same result.
Implementation record
File Change
keyfence/hooks.py uninstall() keeps keyfence's rules in a tuple instead of a set, so checking a deny entry against it no longer hashes the entry.
plugin/hooks/guard.py Byte-identical copy of keyfence/hooks.py.
tests/test_hooks.py One test, parametrized on force.
CHANGELOG.md Unreleased entry.

Verification at b8ff175, 2026-11-05, macOS, Python 3.12: pytest with the coverage gate (keyfence proxy and CA variables cleared from the shell) exits 0, 1256 tests, coverage 98.65%. Steps 2 to 4 above were run through the CLI with the counts as written.

Reviewed in two rounds by two different models before marking ready. Both traced every membership test in install() and uninstall() and found nothing blocking. Two optional test additions (assert result.hook; a record-missing variant) were declined: hook removal has its own tests, and a lookup in an empty set still hashes the entry, so the existing force=False case already fails on regression.

The deny lists are a few dozen entries, so the linear lookup in a tuple costs nothing measurable.

Not changed here, checked at b8ff175: an entry in hooks.PreToolUse that is not an object raises AttributeError on install and on --remove, and a deny that is an object raises AttributeError on install. Those are separate malformed shapes that nobody has reported.

uninstall() looked each deny entry up in a set of keyfence's rules,
which hashes the entry and raised TypeError on an object or a list.
install() stopped doing that in #162; uninstall() now uses a tuple the
same way, so such an entry stays in place with or without --force.

@aminueza aminueza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified at b8ff175. Ready to merge.

  • Behaviour. install and then --remove, with or without --force, on {"permissions": {"deny": [{"a": 1}, ["b"]]}} exit 0 and leave the deny list as [{"a": 1}, ["b"]]. On main the same --remove ends in TypeError.
  • Consistent with Claude Code. claude doctor (2.1.317) reports that file as permissions.deny: Non-string value in deny array was removed. It drops only that value and applies the rest, so leaving the entry in place matches what Claude Code does with it.
  • Teeth. Turning ours back into a set fails both cases of test_uninstall_keeps_a_deny_entry_that_is_not_a_string, plus three existing tests.
  • Suite. 1251 passed, coverage 98.62%, guard.py byte-identical to hooks.py. The 5 failures are local to my machine (four test_docker.py entrypoint tests and test_installed_exec_form_command_actually_spawns, from a broken uv shim) and fail on main too.
  • Merge order. It merges cleanly with #164 and #165 in the order 163, 164, 165. The combined tree passes 1269 tests.

@aminueza
aminueza merged commit 64e6f0d into main Nov 5, 2026
11 checks passed
@aminueza
aminueza deleted the remove-non-string-deny-entries branch November 5, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants