Skip to content

refactor(hooks,scripts): extract shared helpers to reduce duplication#882

Open
qte77 wants to merge 1 commit intortk-ai:developfrom
qte77:refactor/deduplicate-hooks-scripts
Open

refactor(hooks,scripts): extract shared helpers to reduce duplication#882
qte77 wants to merge 1 commit intortk-ai:developfrom
qte77:refactor/deduplicate-hooks-scripts

Conversation

@qte77
Copy link
Copy Markdown

@qte77 qte77 commented Mar 27, 2026

Summary

  • Extract _emit_hook_response() helper in hooks/rtk-rewrite.sh to deduplicate JSON response construction
  • Extract shared test harness (scripts/_test_harness.sh) from duplicated
    assert_ok/assert_exit/color/summary code across test-aristote.sh and test-ruby.sh
  • Both test scripts now source _test_harness.sh instead of maintaining ~80 lines of identical boilerplate
    each
  • Added NOTE: comments in hook files explaining why dependency guards remain duplicated (hooks must be
    self-contained for deployment)

Includes same upstream fixes as other branches (truncation accuracy from #833, copilot integration, swift test
support, read default/safety).

Test plan

- Extract _emit_hook_response() in hooks/rtk-rewrite.sh to deduplicate
  the ask (exit 3) and allow (exit 0) JSON output blocks
- Add comment in both hook files explaining dep-check duplication is
  intentional (hooks must be self-contained for deployment)
- Create scripts/_test_harness.sh with shared state vars, color defs,
  assert_ok/contains/output/exit_nonzero/skip_test, section(), and
  report_and_exit()
- Update test-aristote.sh and test-ruby.sh to source the harness and
  remove ~80 lines of duplicated boilerplate each

Co-Authored-By: Claude <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants