Skip to content

fix: gate cached meta overlay on version newer than embedded#1376

Open
GeekyMax wants to merge 1 commit into
larksuite:mainfrom
GeekyMax:fix/meta-data-cache-version
Open

fix: gate cached meta overlay on version newer than embedded#1376
GeekyMax wants to merge 1 commit into
larksuite:mainfrom
GeekyMax:fix/meta-data-cache-version

Conversation

@GeekyMax

@GeekyMax GeekyMax commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Cached remote meta was overlaid onto the embedded meta_data.json unconditionally. Because the embedded data version is not bumped on each CLI release, a cache with the same (or older) version would shadow the freshly shipped embedded command definitions — so after upgrading the CLI, newly bundled commands were never used.

Changes

  • Gate the cache overlay in InitWithBrand (internal/registry/loader.go) on update.IsNewer(cached.Version, embeddedVersion): only overlay when the cache version is strictly newer than the embedded baseline
  • Add internal/registry/loader_test.go with unit tests for the gate (equal / older / newer / unparseable / empty-embedded)
  • Decouple two cache-overlay regression tests in internal/registry/remote_test.go from the ambient embedded version (the CI-fetched meta_data.json)

Test Plan

  • make unit-test passed (go test ./internal/registry/, both real and default embedded meta, deterministic)
  • validate passed (build / vet / gofmt clean)
  • local-eval passed — skipped: lite mode, no new E2E and no shortcut/skill change
  • acceptance-reviewer passed (3/3 cases)
  • manual verification: built the binary, injected a stale cache (version == embedded) → injected service absent; bumped cache to a newer version → service overlaid; unparseable version → falls back to embedded, exit 0

Related Issues

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced service metadata loading to ensure cached versions only override embedded definitions when newer. This prevents outdated cached metadata from incorrectly replacing current embedded definitions, maintaining data freshness and accuracy during service initialization.

Change-Id: I4117eaef2c24b91745a7b3cf01af314b1ea47a11
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 68b7a125-a82e-4e1a-808f-c2ae81e2fb4d

📥 Commits

Reviewing files that changed from the base of the PR and between b07be60 and 3a7a543.

📒 Files selected for processing (3)
  • internal/registry/loader.go
  • internal/registry/loader_test.go
  • internal/registry/remote_test.go

📝 Walkthrough

Walkthrough

The PR gates cached service registry overlays on version comparison: embedded baseline definitions are now replaced by cached definitions only when the cache version is strictly newer. The change adds an update package import and conditional version check to InitWithBrand, includes a comprehensive overlay-gating test suite, and hardens existing tests for isolation and proper validation.

Changes

Registry overlay version gating

Layer / File(s) Summary
Version-gated overlay implementation
internal/registry/loader.go
Imports internal/update and changes InitWithBrand to apply cached merged definitions only when update.IsNewer(cached.Version, embeddedVersion) returns true, preventing equal or older cache versions from replacing embedded baselines.
Overlay-gating test suite
internal/registry/loader_test.go
Adds test helpers (seedCache, setEmbedded, clearEmbedded, initWithCache, titleOf) to isolate embedded-vs-cache behavior, and five test cases covering equal versions, older cache, newer cache, unparseable cache version, and empty embedded baseline scenarios.
Existing test updates and hardening
internal/registry/remote_test.go
Updates testRegistry to use semver "1.0.0" with version-gate documentation, hardens TestCacheHit_WithinTTL and TestNetworkError_SilentDegradation with cleanup registration and embedded metadata clearing, and updates TestFetchRemoteMerged_200 version assertion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • larksuite/cli#280: Expands registry test harness state cleanup (resetInit) and overlay re-initialization pollution checks that directly support version-gating scenarios introduced in this PR.

Suggested labels

size/S

Suggested reviewers

  • liangshuo-1

Poem

🐰 A rabbit hops through registries with care,
Checking versions before overlay there,
Cached is newer? Then overlay away,
Equal or older? Embedded stays in play! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: gating the cached metadata overlay on version comparison with embedded version.
Description check ✅ Passed The description follows the template with all required sections: Summary explaining the problem, Changes listing the modifications, Test Plan with verification results, and Related Issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants