Skip to content

fix: make hook registration idempotent#198

Merged
jcfischer merged 1 commit into
mainfrom
fix/issue-183-idempotent-hooks
Jun 2, 2026
Merged

fix: make hook registration idempotent#198
jcfischer merged 1 commit into
mainfrom
fix/issue-183-idempotent-hooks

Conversation

@jcfischer
Copy link
Copy Markdown
Contributor

Summary

Fixes #183.

Verification

  • rtk bun test test/unit/hooks.test.ts
  • rtk bun test test/commands/remove-hooks-137.test.ts
  • rtk bun test test/commands/install.test.ts
  • rtk bunx tsc --noEmit
  • rtk bun run lint
  • rtk bun test

Copy link
Copy Markdown
Contributor Author

@jcfischer jcfischer left a comment

Choose a reason for hiding this comment

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

Review: CodeQuality + Architecture

Lenses applied: CodeQuality, Architecture

Analysis

Clean, well-scoped fix for #183 (duplicate hook registrations from arc install/upgrade).

Core change: registerHooks shifts from append-with-skip to filter-then-push (replace-by-tag). Three small helpers (matcherKey, hookGroupHasCommand, shouldReplaceHookGroup) keep the predicate readable and testable.

Correctness verified:

  • shouldReplaceHookGroup matches on (matcher, command, pkg) — replaces same-pkg entries AND legacy untagged entries (_pai_pkg === undefined), preserves entries from other packages. ✓
  • Existing "deduplicates identical hook commands" test still holds: filter removes the old entry, push adds fresh → net 1. Idempotent. ✓
  • New test covers the exact scenario from #183: multiple untagged duplicates + one tagged + different matcher + different package → collapsed to 3 entries (OtherPkg/Bash, Cortex/Bash, Read). ✓
  • matcherKey normalizes undefined"" via nullish coalescing (also handles null from malformed JSON). ✓

Minor behavior change (acceptable): Old code was a no-op on re-register (skip if found). New code always removes-then-pushes, rewriting the entry. End state is identical; settings.json gets touched on every install even when unchanged. Not a problem — arc install already rewrites settings.json unconditionally.

No findings. blockers=0 majors=0 nits=0 — recommend: approve ✅

@jcfischer jcfischer merged commit 1b75973 into main Jun 2, 2026
3 checks passed
@jcfischer jcfischer deleted the fix/issue-183-idempotent-hooks branch June 2, 2026 22:22
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.

arc install/upgrade re-appends provides.hooks non-idempotently → duplicate PreToolUse registrations

1 participant