Skip to content

feat(apps): add cache debug commands (+cache-get/-delete/-clear) - #1896

Merged
chenxingyang1019 merged 7 commits into
mainfrom
feat/apps-cache-cli
Jul 31, 2026
Merged

feat(apps): add cache debug commands (+cache-get/-delete/-clear)#1896
chenxingyang1019 merged 7 commits into
mainfrom
feat/apps-cache-cli

Conversation

@chenxingyang1019

@chenxingyang1019 chenxingyang1019 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

What

Adds three Miaoda app runtime cache debug commands to the apps domain, mirroring the db/file command family conventions:

Command Risk Scope Behavior
+cache-get read spark:app:read Read a single key's value + metadata
+cache-delete write spark:app:write Delete a single key (idempotent)
+cache-clear high-risk-write spark:app:write Clear all keys for the app/env (requires --yes)
  • Routes: GET/DELETE /apps/{app_id}/cache, POST /apps/{app_id}/cache/clear.
  • Environment via --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-get output: on hit {key, environment, exists, ttl_ms, value_size_bytes, value}; on miss exists:false with ttl_ms/value_size_bytes null and no value. value_size_bytes is computed CLI-side; value is raw passthrough under --format json and deserialized/indented under --format pretty (raw fallback for non-JSON).
  • Numeric output fields (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.
  • Path/query inputs are properly encoded (no injection); risk grading and scope split verified.

Testing

  • Unit tests for all three commands: hit/miss, idempotent delete, confirmation gate, dry-run method/path/params/body, env omit/explicit, pretty rendering (JSON deserialize + non-JSON fallback), exists-as-string tolerance, and numeric string-wire → JSON number normalization.

Summary by CodeRabbit

  • New Features
    • Added +cache-get to retrieve an app runtime cache key (hit/miss, TTL, value size, pretty/raw output) with --environment.
    • Added +cache-delete to delete a single key (idempotent: missing keys succeed) with pretty-mode messaging and --environment.
    • Added +cache-clear to clear all cache entries for an app/environment (requires confirmation, supports dry-run, reports deleted count).
  • Documentation
    • Added command reference for application runtime cache management and usage examples.
  • Tests
    • Added coverage for formatting, normalization, dry-run request details, confirmation gating, and idempotency.

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.
@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds +cache-get, +cache-delete, and +cache-clear app shortcuts with shared environment handling, typed cache API calls, normalized output, dry-run support, tests, registration, and operational documentation.

Changes

Application runtime cache

Layer / File(s) Summary
Shared cache routing and normalization
shortcuts/apps/cache_common.go
Adds cache endpoint builders, environment selection, response normalization, TTL formatting, and JSON-aware value rendering helpers.
Cache get command
shortcuts/apps/apps_cache_get.go, shortcuts/apps/apps_cache_test.go
Adds +cache-get with hit/miss handling, JSON and pretty output, dry-run behavior, validation, and normalization tests.
Cache delete and clear commands
shortcuts/apps/apps_cache_delete.go, shortcuts/apps/apps_cache_clear.go, shortcuts/apps/apps_cache_test.go
Adds idempotent single-key deletion and confirmation-gated cache clearing with structured output, pretty renderers, and dry-run tests.
Shortcut registration and operational reference
shortcuts/apps/shortcuts.go, shortcuts/apps/shortcuts_test.go, skills/lark-apps/SKILL.md, skills/lark-apps/references/lark-apps-cache.md
Registers the three commands, updates the shortcut count, and documents cache command usage and rules.

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: return cache result
  CacheShortcut->>Renderer: format normalized output
  Renderer-->>CLI: emit JSON or pretty result
Loading

Suggested labels: feature

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Title check ✅ Passed The title clearly identifies the three new apps cache debug commands and matches the main change.
Description check ✅ Passed The description clearly covers the command scope, API behavior, risks, environments, output, and comprehensive testing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/apps-cache-cli

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.

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

🧹 Nitpick comments (1)
shortcuts/apps/apps_cache_test.go (1)

217-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Error-path tests only check err != nil, no typed metadata assertion.

Both tests exercise error paths (required --key, missing --yes confirmation) but only assert that an error occurred, not its typed classification. As per coding guidelines, **/*_test.go error-path tests must assert typed metadata via errs.ProblemOf (category/subtype/param) and cause preservation, not just error presence.

  • shortcuts/apps/apps_cache_test.go#L217-L223: in TestAppsCacheGet_RequiresKey, assert errs.ProblemOf(err) category/subtype (e.g. validation/invalid-argument) in addition to the non-nil check.
  • shortcuts/apps/apps_cache_test.go#L311-L317: in TestAppsCacheClear_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

📥 Commits

Reviewing files that changed from the base of the PR and between e9dabb2 and 881ab63.

📒 Files selected for processing (9)
  • shortcuts/apps/apps_cache_clear.go
  • shortcuts/apps/apps_cache_delete.go
  • shortcuts/apps/apps_cache_get.go
  • shortcuts/apps/apps_cache_test.go
  • shortcuts/apps/cache_common.go
  • shortcuts/apps/shortcuts.go
  • shortcuts/apps/shortcuts_test.go
  • skills/lark-apps/SKILL.md
  • skills/lark-apps/references/lark-apps-cache.md

Resolve shortcut-count test conflict (cache 3 + automation 6 + role 9 → 82)
and update the cache dry-run test helper to the new data.api envelope shape.
Resolve SKILL.md routing conflict (keep cache row + adopt main's updated
release row) and fix the lark-apps-cache.md lark-shared link path to satisfy
main's new skill-link contract test.
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f174c3d199a2e4b185ad643d03435011b49db2aa

🧩 Skill update

npx skills add larksuite/cli#feat/apps-cache-cli -y -g

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.41%. Comparing base (1e682bd) to head (f174c3d).
⚠️ Report is 50 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/apps/cache_common.go 80.00% 6 Missing and 2 partials ⚠️
shortcuts/apps/apps_cache_clear.go 86.66% 2 Missing and 2 partials ⚠️
shortcuts/apps/apps_cache_delete.go 87.87% 2 Missing and 2 partials ⚠️
shortcuts/apps/apps_cache_get.go 92.59% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1896      +/-   ##
==========================================
+ Coverage   75.08%   75.41%   +0.33%     
==========================================
  Files         905      928      +23     
  Lines       96066    98165    +2099     
==========================================
+ Hits        72128    74035    +1907     
- Misses      18387    18490     +103     
- Partials     5551     5640      +89     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chenxingyang1019
chenxingyang1019 merged commit 41692b7 into main Jul 31, 2026
42 checks passed
@chenxingyang1019
chenxingyang1019 deleted the feat/apps-cache-cli branch July 31, 2026 06:13
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 31, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants