Repository navigation
Keep non-string deny entries on install-hooks --remove - #163
Merged
Merged
Conversation
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
approved these changes
Nov 5, 2026
aminueza
left a comment
Owner
There was a problem hiding this comment.
Verified at b8ff175. Ready to merge.
- Behaviour.
installand then--remove, with or without--force, on{"permissions": {"deny": [{"a": 1}, ["b"]]}}exit 0 and leave the deny list as[{"a": 1}, ["b"]]. Onmainthe same--removeends inTypeError. - Consistent with Claude Code.
claude doctor(2.1.317) reports that file aspermissions.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
oursback into a set fails both cases oftest_uninstall_keeps_a_deny_entry_that_is_not_a_string, plus three existing tests. - Suite. 1251 passed, coverage 98.62%,
guard.pybyte-identical tohooks.py. The 5 failures are local to my machine (fourtest_docker.pyentrypoint tests andtest_installed_exec_form_command_actually_spawns, from a brokenuvshim) and fail onmaintoo. - Merge order. It merges cleanly with #164 and #165 in the order 163, 164, 165. The combined tree passes 1269 tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently,
keyfence install-hooks claude-code --removestops withTypeError: unhashable type: 'dict'when thedenylist insettings.jsonhas 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
pytest tests/test_hooks.py -k test_uninstall_keeps_a_deny_entry_that_is_not_a_string(both cases fail onmainwith theTypeError).{"permissions": {"deny": [{"a": 1}, ["b"]]}}to.claude/settings.json, then runkeyfence install-hooks claude-code --project.keyfence install-hooks claude-code --project --remove. It reports 42 rules removed, and the deny list is back to[{"a": 1}, ["b"]].--remove --force: same result.Implementation record
keyfence/hooks.pyuninstall()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.pykeyfence/hooks.py.tests/test_hooks.pyforce.CHANGELOG.mdVerification at b8ff175, 2026-11-05, macOS, Python 3.12:
pytestwith 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()anduninstall()and found nothing blocking. Two optional test additions (assertresult.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 existingforce=Falsecase 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.PreToolUsethat is not an object raisesAttributeErroron install and on--remove, and adenythat is an object raisesAttributeErroron install. Those are separate malformed shapes that nobody has reported.