Skip to content

Refactor and optimize sdd-cache and simplify-ignore hooks - #524

Open
gotaku3737-sketch wants to merge 15 commits into
addyosmani:mainfrom
gotaku3737-sketch:main
Open

gotaku3737-sketch wants to merge 15 commits into
addyosmani:mainfrom
gotaku3737-sketch:main

Conversation

@gotaku3737-sketch

Copy link
Copy Markdown

No description provided.

google-labs-jules Bot and others added 11 commits May 10, 2026 00:37
This change extracts shared functions from hooks/simplify-ignore.sh and hooks/simplify-ignore-test.sh into a new library file hooks/simplify-ignore-lib.sh.

- Created hooks/simplify-ignore-lib.sh with shared functions: hash_cmd, file_id, block_hash, escape_glob, and filter_file.
- Refactored hooks/simplify-ignore.sh to source the new library.
- Refactored hooks/simplify-ignore-test.sh to source the new library, removing duplicated code and the sed-based extraction of filter_file.
- Verified that all 21 tests in hooks/simplify-ignore-test.sh continue to pass.

This improves maintainability and readability by eliminating code duplication and using a cleaner approach for testing internal functions.

Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…ing-3354849194174339719

🧹 Refactor simplify-ignore hook to use shared library
Consolidate four separate jq calls into a single invocation in
hooks/sdd-cache-pre.sh to improve performance. This reduces
process spawning overhead and redundant JSON parsing.

In a benchmark of 100 iterations, this optimization improved the
parsing block's performance by approximately 77%.

Also ensured correct executable permissions for hook scripts.

Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…n-14547555509703486068

⚡ Optimize SDD cache revalidation with consolidated jq calls
- Create hooks/sdd-cache-post-test.sh
- Extract extract_header logic via sed/eval for isolation
- Add test cases for header extraction, case insensitivity,
  whitespace handling, and redirect chain (multi-block) logic.

Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…act-header-6684154648123603817

🧪 Add unit tests for extract_header in sdd-cache-post.sh
- Created `hooks/sdd-cache-lib.sh` to hold shared logic (`hash_key`, `get_final_headers`, `extract_header`).
- Updated `sdd-cache-pre.sh`, `sdd-cache-post.sh`, and `sdd-cache-post-test.sh` to source the library file.
- Removed the vulnerable `eval "$(sed ...)"` block from the tests.
- Modified `extract_header` to take `final_headers` as an explicit argument.

Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
Pre-compute the list of block files into a bash array (`block_files`) to avoid doing directory globbing (`"$CACHE/${ID}".block.*`) and `stat` checks (`[ -f "$bf" ]`) on every matched placeholder inside the main file processing loop. This significantly cuts down I/O operations and speeds up performance on large files with many placeholders.

Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…b-8750890728215505428

⚡ Optimize simplify-ignore block matching performance
…d-injection-sdd-cache-post-test-17580226835029995061

🔒 Fix eval command injection vulnerability in sdd-cache-post-test.sh

@addyosmani addyosmani 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.

The refactor is clean and I verified it preserves behavior: both hook suites pass against it (simplify-ignore 21/21, sdd-cache-post 9/9). Two things before it lands though. First, the tests still aren't wired into CI (nothing runs the hook tests in any workflow), so the coverage you're adding wouldn't actually run, same gap as #501 and #510. Second, this overlaps both of those: #501 adds sdd-cache-test.sh and #510 touches session-start, so three PRs are refactoring and testing the same hooks. Let's coordinate them (whoever lands first, the others rebase, and reconcile the sdd-cache-test.sh vs sdd-cache-post-test.sh naming) and wire the tests into the workflow in the same pass. One question: what does 'optimize' buy here concretely? Refactoring working hooks is worth it for the shared -lib.sh and the tests, but I want the win stated so it isn't churn on load-bearing code.

google-labs-jules Bot and others added 4 commits September 5, 2026 22:12
Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…tion-2652106886605059279

⚡ Optimize renderProducts performance by extracting sort outside loop
…p-6966854946476841801

🧹 Refactor duplicated test setup code into test-utils.js

@addyosmani addyosmani 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.

I can't take this as-is. It commits seven patch_*.js files to the repo root that shouldn't be in the tree, and it's a broad refactor of shared hook and script files in one PR, which CLAUDE.md specifically asks us to avoid since those wide files collide with in-flight work, and there's a lot of that in the hook area right now. If there's a real improvement here, please drop the stray files and split it into small focused PRs, one behavior at a time, and I'll review those. Note #578 is fixing a data-loss bug in simplify-ignore.sh in parallel.

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