feat(apps): add cache debug commands (+cache-get/-delete/-clear)#1896
feat(apps): add cache debug commands (+cache-get/-delete/-clear)#1896chenxingyang1019 wants to merge 2 commits into
Conversation
Add three apps-domain cache debug shortcuts for inspecting/clearing an app's runtime cache: - +cache-get: read a business key's value + metadata (hit/miss) - +cache-delete: delete a single key (idempotent, write) - +cache-clear: clear all cache in an environment (high-risk-write, --yes) value renders raw on --format json, deserialized on --format pretty; value_size_bytes is computed CLI-side; --environment auto-selects the branch when omitted. Includes unit tests (hit/miss/dry-run/confirmation) and the lark-apps cache skill reference.
Follow-up hardening for the cache debug commands (+cache-get/-delete/-clear): - Normalize ttl_ms / deleted_key_count via a new cacheInt() helper so --format json emits a stable JSON number (or null) regardless of whether the server sends the value as a number or a string. Aligns with the repo convention that numeric wire fields may arrive as strings; previously these were passed through raw, leaving the output type at the server's mercy. - Add unit tests locking the string-wire -> JSON number contract for both cache-get ttl_ms and cache-delete deleted_key_count. - Tidy two comments: soften cacheBool's speculative "historical wire form" claim to a defensive-tolerance note, and drop implementation jargon from cache-delete's risk-level rationale.
📝 WalkthroughWalkthroughAdds ChangesApplication runtime cache
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant CacheShortcut
participant CacheAPI
participant Renderer
CLI->>CacheShortcut: invoke cache command
CacheShortcut->>CacheAPI: read, delete, or clear cache
CacheAPI-->>CacheShortcut: cache result
CacheShortcut->>Renderer: format normalized output
Renderer-->>CLI: JSON or pretty result
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/apps/apps_cache_test.go (1)
217-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winError-path tests only check
err != nil, no typed metadata assertion.Both tests exercise error paths (required
--key, missing--yesconfirmation) but only assert that an error occurred, not its typed classification. As per coding guidelines,**/*_test.goerror-path tests must assert typed metadata viaerrs.ProblemOf(category/subtype/param) and cause preservation, not just error presence.
shortcuts/apps/apps_cache_test.go#L217-L223: inTestAppsCacheGet_RequiresKey, asserterrs.ProblemOf(err)category/subtype (e.g. validation/invalid-argument) in addition to the non-nil check.shortcuts/apps/apps_cache_test.go#L311-L317: inTestAppsCacheClear_RequiresConfirmation, assert the confirmation-gate error's typed category/subtype similarly.Note: if the required-flag/confirmation-gate errors at this layer are raw framework errors rather than
errs.*typed problems, this guideline may not cleanly apply here — worth confirming the actual error type returned by the flag/confirmation middleware before making this change.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/apps/apps_cache_test.go` around lines 217 - 223, Update TestAppsCacheGet_RequiresKey in shortcuts/apps/apps_cache_test.go:217-223 and TestAppsCacheClear_RequiresConfirmation in shortcuts/apps/apps_cache_test.go:311-317 to assert errs.ProblemOf(err) typed category/subtype and preserved cause in addition to checking err is non-nil. First confirm the flag/confirmation middleware returns an errs.* problem; if it returns a raw framework error, use the appropriate typed assertion or adjust only as needed to preserve the actual error contract.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/apps/apps_cache_test.go`:
- Around line 217-223: Update TestAppsCacheGet_RequiresKey in
shortcuts/apps/apps_cache_test.go:217-223 and
TestAppsCacheClear_RequiresConfirmation in
shortcuts/apps/apps_cache_test.go:311-317 to assert errs.ProblemOf(err) typed
category/subtype and preserved cause in addition to checking err is non-nil.
First confirm the flag/confirmation middleware returns an errs.* problem; if it
returns a raw framework error, use the appropriate typed assertion or adjust
only as needed to preserve the actual error contract.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 324e8e91-08b2-41af-a15d-4bf25b9bbf38
📒 Files selected for processing (9)
shortcuts/apps/apps_cache_clear.goshortcuts/apps/apps_cache_delete.goshortcuts/apps/apps_cache_get.goshortcuts/apps/apps_cache_test.goshortcuts/apps/cache_common.goshortcuts/apps/shortcuts.goshortcuts/apps/shortcuts_test.goskills/lark-apps/SKILL.mdskills/lark-apps/references/lark-apps-cache.md
What
Adds three Miaoda app runtime cache debug commands to the
appsdomain, mirroring the db/file command family conventions:+cache-getspark:app:read+cache-deletespark:app:write+cache-clearspark:app:write--yes)GET/DELETE /apps/{app_id}/cache,POST /apps/{app_id}/cache/clear.--environment dev|online; omit to let the server auto-select the branch (multi-env app → dev, single-env → online). Env goes in query for get/delete, in body for clear.+cache-getoutput: on hit{key, environment, exists, ttl_ms, value_size_bytes, value}; on missexists:falsewithttl_ms/value_size_bytesnull and novalue.value_size_bytesis computed CLI-side;valueis raw passthrough under--format jsonand deserialized/indented under--format pretty(raw fallback for non-JSON).ttl_ms,deleted_key_count) are normalized to a stable JSON number/null so the output type does not drift with the server's wire form.Testing
Notes
Summary by CodeRabbit
New Features
Documentation
Tests