Skip to content

Extend no-cache to remote mixins#372

Merged
kindermax merged 3 commits into
masterfrom
no-cache-for-mixins
Jun 14, 2026
Merged

Extend no-cache to remote mixins#372
kindermax merged 3 commits into
masterfrom
no-cache-for-mixins

Conversation

@kindermax

@kindermax kindermax commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • thread no-cache loading through local config loads so remote mixins are re-fetched
  • keep cached remote mixins as fallback when no-cache downloads fail
  • update help text, golden snapshots, and changelog

Tests

  • go test ./internal/config/...
  • go test ./...
  • lets lint
  • lets test-bats

Summary by Sourcery

Extend no-cache behavior to remote mixins and make remote mixin caching more robust when loading configs.

Bug Fixes:

  • Ensure the --no-cache option re-downloads remote mixins for both local and remote configs.
  • Avoid overwriting cached remote mixins when a newly downloaded mixin is invalid, falling back to the last valid cached version instead.

Enhancements:

  • Propagate no-cache configuration through nested mixin loading and only persist remote mixins when a fresh download succeeds.
  • Improve remote mixin persistence by truncating files before writing and standardizing file permissions.
  • Emit a warning when falling back to a cached remote mixin after a download failure.

Documentation:

  • Update CLI help text for --debug and --no-cache flags to reflect current behavior.
  • Document the corrected no-cache behavior for remote mixins in the changelog.

Tests:

  • Add tests covering no-cache behavior for remote mixins, including re-downloads, progress reporting, and fallback to cached mixins on invalid downloads.

@sourcery-ai

sourcery-ai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Extends the --no-cache behavior to remote mixins, ensuring they are re-downloaded for both local and remote configs while preserving cached mixins as a fallback on download failure, and wires this through load options, config handling, CLI flags, plus tests, logging, file mode fixes, and docs/help updates.

Sequence diagram for extended no-cache behavior for remote mixins

sequenceDiagram
    actor User
    participant CLI as Main
    participant Loader as LoadWithContext
    participant Cfg as Config
    participant Mixin as RemoteMixin

    User->>CLI: run lets --no-cache
    CLI->>Loader: LoadWithContext(..., WithNoCache)
    Loader->>Cfg: NewConfig(...)
    Loader->>Cfg: SetDownloadOptions(ctx, progress, noCache=true)

    Cfg->>Cfg: readMixin(mixin)
    Cfg->>Mixin: tryRead()
    alt noCache is true
        Note over Cfg,Mixin: cached read skipped on first attempt
    end
    alt data is nil
        Cfg->>Mixin: download(context, progress)
        alt download succeeds
            Cfg->>Mixin: persist(data)
        else download fails and noCache is true
            Cfg->>Mixin: tryRead()
            alt cachedData exists
                Note over Cfg,Mixin: use cached mixin as fallback
            else no cachedData
                Note over Cfg,Mixin: return download error
            end
        end
    end
Loading

File-Level Changes

Change Details Files
Thread no-cache behavior through config loading so remote mixins are re-downloaded and caching is only updated after successful downloads.
  • Add a noCache field to the Config struct and propagate it via SetDownloadOptions and NewMixinConfig
  • Update remote mixin loading to skip cache reads when noCache is set and to track whether data was freshly downloaded
  • Only persist remote mixin data to disk when it was successfully downloaded and validated
internal/config/config/config.go
Introduce a load option to control no-cache behavior and ensure remote and local loads respect it.
  • Extend loadOptions with a noCache flag and add a WithNoCache() functional option
  • Ensure LoadRemote passes the noCache argument into loadOptions before calling ensureRemoteConfig
  • Propagate the noCache option into Config via loadConfigFromFile
internal/config/load.go
Wire the CLI --no-cache flag into the loader and clarify CLI help text.
  • Append loader.WithNoCache() to loader options when the root no-cache flag is set
  • Update the --no-cache flag help text to mention remote mixins and simplify debug flag wording
internal/cli/cli.go
internal/cmd/root.go
Improve remote mixin cache behavior on failures and fix persistence semantics.
  • On no-cache downloads, fall back to cached mixin content if download fails but a cached file exists, logging a warning
  • Open mixin cache files with truncate and a more appropriate file mode and ensure the file handle is closed
internal/config/config/config.go
internal/config/config/mixin.go
Extend and tighten tests around remote mixin caching and no-cache behavior.
  • Verify that cache hits do not issue additional HTTP requests for remote mixins
  • Add tests to assert that --no-cache triggers re-downloads and proper progress events for remote mixins
  • Add tests to confirm cached mixins are not overwritten by invalid downloads and remain usable after failures
internal/config/load_test.go
Update documentation and golden help output to reflect new behavior.
  • Document the fixed no-cache behavior for remote mixins in the changelog
  • Regenerate or adjust help golden snapshot files for updated flag descriptions
docs/docs/changelog.md
internal/cmd/testdata/TestHelpGolden/basic.golden
internal/cmd/testdata/TestHelpGolden/grouped_commands.golden
internal/cmd/testdata/TestHelpGolden/grouped_commands_long.golden
internal/cmd/testdata/TestHelpGolden/long_command.golden

Possibly linked issues


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
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In config.Config.readMixin you introduce a direct dependency on logrus; consider routing this warning through the existing logging abstraction (or adding one if needed) so the config package doesn’t hard‑depend on a specific logging implementation.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `config.Config.readMixin` you introduce a direct dependency on `logrus`; consider routing this warning through the existing logging abstraction (or adding one if needed) so the config package doesn’t hard‑depend on a specific logging implementation.

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.

@kindermax kindermax merged commit c095457 into master Jun 14, 2026
5 checks passed
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