Skip to content

Refresh zsh completion cache after lets updates#6

Open
kindermax wants to merge 1 commit into
masterfrom
refresh-completion-cache
Open

Refresh zsh completion cache after lets updates#6
kindermax wants to merge 1 commit into
masterfrom
refresh-completion-cache

Conversation

@kindermax

@kindermax kindermax commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Refresh and cache the zsh completion script for the lets CLI based on changes to the lets executable and its version metadata.

Enhancements:

  • Track a signature of the resolved lets executable, its metadata, and version output to decide when to regenerate the zsh completion file, avoiding unnecessary refreshes.
  • Improve plugin initialization to use the absolute plugin directory path consistently and clean up the temporary refresh helper function after use.

Documentation:

  • Document that plugin-managed zsh completions are refreshed automatically when lets changes and instruct users to reload their shell after updating the lets binary.

Tests:

  • Add a zsh test script that verifies completions are regenerated only when the lets binary, its version, or file characteristics change, and not on every plugin load.

@sourcery-ai

sourcery-ai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a robust cache-refresh mechanism for the zsh completion script so it is regenerated when the underlying lets executable or its version/metadata changes, documents the behavior, and introduces a regression test to verify the refresh logic.

File-Level Changes

Change Details Files
Replace one-time completion generation with a signature-based refresh function that re-runs lets completion when the resolved lets binary, its metadata, or reported version changes.
  • Ensure PLUGIN_BIN uses the absolute directory of the plugin file instead of dirname-based resolution.
  • Introduce _lets_zsh_plugin_refresh_completion that resolves the lets executable (configurable via LETS_EXECUTABLE), derives a signature from its path, --version output, and file mtime/size, and compares it to a stored signature file.
  • Regenerate the _lets completion file and update a .lets-completion-signature file using temporary files and atomic mv when the signature changes or cache is missing, otherwise keep the existing cache.
  • After successful refresh, unfunction the old _lets to force the shell to pick up the new completion definition, and clean up temporary files on failure paths.
  • Invoke the refresh helper at plugin load and immediately unfunction the helper to avoid polluting the user namespace.
lets.plugin.zsh
Document automatic completion cache refresh semantics and how to trigger them after updating lets.
  • Explain that plugin-managed completions are refreshed automatically when the resolved lets executable, its metadata, or lets --version output changes.
  • Document that users should reload their shell (e.g., exec $SHELL -l) after updating the lets binary to trigger a refresh.
  • Fix the README to end with a newline character.
Readme.md
Add an automated zsh test that validates the completion cache is only regenerated when the lets binary, its version, or its file size changes.
  • Create an isolated temporary test environment with a fake plugin directory and fake lets binary on PATH.
  • Implement a write_fake_lets helper that writes a stub lets script whose --version and completion -s zsh behaviors are controllable and increments a counter file on each completion invocation.
  • Verify that sourcing the plugin the first time generates the completion file and increments the counter, re-sourcing without changes does not regenerate, and modifying the fake binary (version change or same version with different content/size) causes regeneration and counter increment.
  • Provide assertion helpers for file contents and numeric values, plus cleanup and failure reporting utilities.
tests/refresh-completion-cache.zsh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant