Skip to content

feat: add docs history shortcuts#1612

Open
caojie0621 wants to merge 1 commit into
mainfrom
feat/docs_revert
Open

feat: add docs history shortcuts#1612
caojie0621 wants to merge 1 commit into
mainfrom
feat/docs_revert

Conversation

@caojie0621

@caojie0621 caojie0621 commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add docs history shortcuts so users and agents can list Docx history versions, revert to a selected history_version_id, and poll revert task status through structured CLI flows.

Changes

  • Add docs +history-list, docs +history-revert, and docs +history-revert-status shortcuts backed by Docs AI history APIs.
  • Validate Docx-only document refs, page size, positive history_version_id, wait timeout, and task ID with typed errs.* validation errors.
  • Register the new shortcuts and extend dry-run output coverage for history list/revert/status request shapes.
  • Add unit tests, dry-run E2E coverage, and a gated live history workflow E2E for create -> update -> list history -> revert -> fetch verification.
  • Update lark-doc skill documentation and coverage notes with the history workflow and revision_id to history_version_id guidance.

Test Plan

  • make unit-test

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added document history commands to list versions, revert to a prior version, and check revert task status.
  • Documentation

    • Added a new document history reference and expanded docs usage/help text with examples and safe rollback workflow.
    • Updated docs coverage notes for the new history flow.
  • Tests

    • Added unit tests for validation, dry-run request shaping, and API execution results.
    • Added end-to-end history workflow tests (gated) and updated CLI dry-run expectations.
    • Extended shortcut registration tests to include the new commands.

@coderabbitai

coderabbitai Bot commented Jun 26, 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: 73b00419-9020-4419-b2e8-8c6b29588bd9

📥 Commits

Reviewing files that changed from the base of the PR and between f8fc948 and 78a2d43.

📒 Files selected for processing (11)
  • .gitignore
  • cmd/api/api_test.go
  • shortcuts/doc/docs_history.go
  • shortcuts/doc/docs_history_test.go
  • shortcuts/doc/shortcuts.go
  • shortcuts/register_test.go
  • skills/lark-doc/SKILL.md
  • skills/lark-doc/references/lark-doc-history.md
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_history_workflow_test.go
  • tests/cli_e2e/docs/docs_update_dryrun_test.go
✅ Files skipped from review due to trivial changes (3)
  • skills/lark-doc/references/lark-doc-history.md
  • .gitignore
  • skills/lark-doc/SKILL.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • shortcuts/doc/shortcuts.go
  • shortcuts/doc/docs_history.go
  • tests/cli_e2e/docs/docs_history_workflow_test.go
  • shortcuts/register_test.go
  • tests/cli_e2e/docs/docs_update_dryrun_test.go
  • shortcuts/doc/docs_history_test.go

📝 Walkthrough

Walkthrough

Adds docs history list, revert, and revert-status shortcuts, wires them into docs help and skill references, adds shortcut and dry-run tests, and adds a gated end-to-end history workflow with coverage updates.

Changes

Doc history CLI

Layer / File(s) Summary
History shortcuts
shortcuts/doc/docs_history.go
Adds three docs history shortcuts with shared doc/version parsing, request construction, dry-run output, and HTTP execution.
Help wiring and registration
shortcuts/doc/shortcuts.go, shortcuts/register_test.go
Maps the new history shortcuts into docs skill/help lookup and verifies they mount under the docs service with the expected long help.
Skill and reference docs
skills/lark-doc/SKILL.md, skills/lark-doc/references/lark-doc-history.md
Updates the lark-doc skill guide and adds the history reference page with the list, revert, and status flows.
Shortcut tests
shortcuts/doc/docs_history_test.go, tests/cli_e2e/docs/docs_update_dryrun_test.go
Adds validation, dry-run, execution, and URL-parsing tests for the docs history shortcuts and updates the dry-run expectations for history requests.
E2E workflow and coverage
.gitignore, tests/cli_e2e/docs/docs_history_workflow_test.go, tests/cli_e2e/docs/coverage.md
Adds the gated live history workflow test, updates the docs E2E coverage report, and adds ignore patterns for the docs E2E directory.

API test harness

Layer / File(s) Summary
Shared test command helpers
cmd/api/api_test.go
Adds shared Cobra command constructors and rewires API tests to use them with standardized silence settings.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

feature, documentation

Suggested reviewers

  • SunPeiYang996
  • fangshuyu-768

Poem

A rabbit hopped through version trails,
With carrots, notes, and tiny tales. 🐇
+history-list showed the way,
Then done hopped in to save the day.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.92% 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 is concise and clearly summarizes the main change: adding docs history shortcuts.
Description check ✅ Passed The description matches the required template and covers summary, changes, test plan, 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.
✨ 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/docs_revert

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 markdownlint-cli2 (0.22.1)
skills/lark-doc/SKILL.md

markdownlint-cli2 wrapper config was not available before execution

skills/lark-doc/references/lark-doc-history.md

markdownlint-cli2 wrapper config was not available before execution

tests/cli_e2e/docs/coverage.md

markdownlint-cli2 wrapper config was not available before execution


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.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths labels Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/docs_revert -y -g

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{"name":"HttpError","status":500,"request":{"method":"PATCH","url":"https://api.github.com/repos/larksuite/cli/issues/comments/4808214401","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit.js/0.0.0-development octokit-core.js/7.0.6 Node.js/24","content-type":"application/json; charset=utf-8"},"body":{"body":"<!-- This is an auto-generated comment: summarize by coderabbit.ai -->\n<!-- review_stack_entry_start -->\n\n[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/larksuite/cli/pull/1612?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)\n\n<!-- review_stack_entry_end -->\n<!-- This is an auto-generated comment: review in progress by coderabbit.ai -->\n\n> [!NOTE]\n> Currently processing new changes in this PR. This may take a few minutes, please wait...\n> \n> <details>\n> <summary>⚙️ Run configuration</summary>\n> \n> **Configuration used**: defaults\n> \n> **Review profile**: CHILL\n> \n> **Plan**: Pro\n> \n> **Run ID**: `ce3a1429-c7a9-46db-99f9-fee4303fd2fd`\n> \n> </details>\n> \n> <details>\n> <summary>📥 Commits</summary>\n> \n> Reviewing files that changed from the base of the PR and between 39d60cb7061d0771fc88ec0da276e9bf25b48077 and 6982572097dadf96a638c60f3d0967e8eaf45920.\n> \n> </details>\n> \n> <details>\n> <summary>📒 Files selected for processing (10)</summary>\n> \n> * `.gitignore`\n> * `shortcuts/doc/docs_history.go`\n> * `shortcuts/doc/docs_history_test.go`\n> * `shortcuts/doc/shortcuts.go`\n> * `shortcuts/register_test.go`\n> * `skills/lark-doc/SKILL.md`\n> * `skills/lark-doc/references/lark-doc-history.md`\n> * `tests/cli_e2e/docs/coverage.md`\n> * `tests/cli_e2e/docs/docs_history_workflow_test.go`\n> * `tests/cli_e2e/docs/docs_update_dryrun_test.go`\n> \n> </details>\n> \n> ```ascii\n>  _________________________________________________\n> < If you only knew now what you didn't know then. >\n>  -------------------------------------------------\n>   \\\n>    \\   \\\n>         \\ /\\\n>         ( )\n>       .( o ).\n> ```\n\n<!-- end of auto-generated comment: review in progress by coderabbit.ai -->\n\n<!-- finishing_touch_checkbox_start -->\n\n<details>\n<summary>✨ Finishing Touches</summary>\n\n<details>\n<summary>📝 Generate docstrings</summary>\n\n- [ ] <!-- {\"checkboxId\": \"7962f53c-55bc-4827-bfbf-6a18da830691\"} --> Create stacked PR\n- [ ] <!-- {\"checkboxId\": \"3e1879ae-f29b-4d0d-8e06-d12b7ba33d98\"} --> Commit on current branch\n\n</details>\n<details>\n<summary>🧪 Generate unit tests (beta)</summary>\n\n- [ ] <!-- {\"checkboxId\": \"f47ac10b-58cc-4372-a567-0e02b2c3d479\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Create PR with unit tests\n- [ ] <!-- {\"checkboxId\": \"6ba7b810-9dad-11d1-80b4-00c04fd430c8\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Commit unit tests in branch `feat/docs_revert`\n\n</details>\n\n</details>\n\n<!-- finishing_touch_checkbox_end -->\n<!-- tips_start -->\n\n---\n\nThanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=larksuite/cli&utm_content=1612)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.\n\n<details>\n<summary>❤️ Share</summary>\n\n- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)\n- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)\n- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)\n- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)\n\n</details>\n\n\n<sub>Comment `@coderabbitai help` to get the list of available commands.</sub>\n\n<!-- tips_end -->"},"request":{"retryCount":3,"signal":{},"retries":3,"retryAfter":16}}}

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/cli_e2e/docs/docs_update_dryrun_test.go (1)

90-122: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Parse the dry-run JSON instead of matching formatted fragments.

The new history assertions depend on exact serialization details like "page_size": 5 and "task_id": "task_1". A whitespace or pretty-print change will fail this test even if the request shape is still correct. Parse result.Stdout and assert the dry-run api[0] URL/body/params fields directly instead of searching stdout+stderr for substrings.

Also applies to: 136-139

🤖 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 `@tests/cli_e2e/docs/docs_update_dryrun_test.go` around lines 90 - 122, The
dry-run history tests are matching serialized JSON substrings in stdout/stderr,
which makes them brittle to formatting changes. Update the relevant cases in the
CLI e2e test to parse result.Stdout as JSON and assert the dry-run request
fields directly on api[0] (URL, body, and params) instead of using wantContains
substring checks; apply the same change to the history revert and history revert
status cases.
🤖 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.

Inline comments:
In `@shortcuts/doc/docs_history_test.go`:
- Around line 71-80: The failure-path tests in docs_history_test should assert
the full typed metadata, not just that some validation error exists or that the
URL matches a substring. In the relevant test cases, keep the existing errors.As
check against errs.ValidationError for Param, then also use errs.ProblemOf(err)
to verify the expected Category and Subtype, and assert the wrapped cause where
one is expected. Update the URL and other validation cases consistently so
regressions in validation classification are caught.

In `@tests/cli_e2e/docs/docs_history_workflow_test.go`:
- Around line 75-87: The polling closures around the history workflow are only
checking process exit code, so API-level failures with a successful exit can
silently retry until timeout. Update the logic in the history-list and
history-revert-status polling paths to inspect the JSON success/status flag (or
use AssertStdoutStatus) immediately after RunCmd returns, and fail fast with the
captured stdout/stderr instead of returning false. Use the existing
Eventually-based checks and the relevant helper symbols in this test flow to
surface the last API error right away rather than waiting for the timeout.

---

Nitpick comments:
In `@tests/cli_e2e/docs/docs_update_dryrun_test.go`:
- Around line 90-122: The dry-run history tests are matching serialized JSON
substrings in stdout/stderr, which makes them brittle to formatting changes.
Update the relevant cases in the CLI e2e test to parse result.Stdout as JSON and
assert the dry-run request fields directly on api[0] (URL, body, and params)
instead of using wantContains substring checks; apply the same change to the
history revert and history revert status cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61366e69-fa92-46bf-9f04-bfbc924206b0

📥 Commits

Reviewing files that changed from the base of the PR and between 39d60cb and f8fc948.

📒 Files selected for processing (10)
  • .gitignore
  • shortcuts/doc/docs_history.go
  • shortcuts/doc/docs_history_test.go
  • shortcuts/doc/shortcuts.go
  • shortcuts/register_test.go
  • skills/lark-doc/SKILL.md
  • skills/lark-doc/references/lark-doc-history.md
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_history_workflow_test.go
  • tests/cli_e2e/docs/docs_update_dryrun_test.go

Comment on lines +71 to +80
_, ok := errs.ProblemOf(err)
if !ok {
t.Fatalf("error is not typed: %T %v", err, err)
}
var validationErr *errs.ValidationError
if !errors.As(err, &validationErr) {
t.Fatalf("expected validation error, got %T: %v", err, err)
}
if validationErr.Param != tt.param {
t.Fatalf("param = %q, want %q (err: %v)", validationErr.Param, tt.param, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert error category/subtype in these failure-path tests.

These cases currently pass as long as they get some typed validation error, and the URL test passes on a substring alone. A regression from the expected validation category/subtype would slip through unnoticed. Keep the ValidationError.Param assertion, but also check errs.ProblemOf(err) for the expected Category/Subtype (and cause when a wrapped cause is expected).

As per coding guidelines, **/*_test.go: Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone. Based on learnings, errs.ProblemOf does not expose Param, so keep errors.As(..., *errs.ValidationError) for Param and add Category/Subtype assertions via errs.ProblemOf.

Also applies to: 299-305

🤖 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/doc/docs_history_test.go` around lines 71 - 80, The failure-path
tests in docs_history_test should assert the full typed metadata, not just that
some validation error exists or that the URL matches a substring. In the
relevant test cases, keep the existing errors.As check against
errs.ValidationError for Param, then also use errs.ProblemOf(err) to verify the
expected Category and Subtype, and assert the wrapped cause where one is
expected. Update the URL and other validation cases consistently so regressions
in validation classification are caught.

Sources: Coding guidelines, Learnings

Comment on lines +75 to +87
if listErr != nil || listResult.ExitCode != 0 {
return false
}
for _, entry := range gjson.Get(listResult.Stdout, "data.entries").Array() {
revisionID := entry.Get("revision_id").Int()
historyVersionID := entry.Get("history_version_id").String()
if revisionID > 0 && revisionID < currentRevision && historyVersionID != "" {
revertHistoryVersionID = historyVersionID
return true
}
}
return false
}, 45*time.Second, 3*time.Second, "history list did not expose a prior revision")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Fail fast on API-level errors inside the polling loops.

RunCmd only tells you the process exited cleanly. If +history-list or +history-revert-status returns exit 0 with status:false, these closures just keep returning false until the Eventually timeout, which turns a deterministic API failure into a slow, misleading timeout. Check the JSON success flag in the loop (or assert AssertStdoutStatus) and surface the last stdout/stderr when it fails.

Also applies to: 116-121

🤖 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 `@tests/cli_e2e/docs/docs_history_workflow_test.go` around lines 75 - 87, The
polling closures around the history workflow are only checking process exit
code, so API-level failures with a successful exit can silently retry until
timeout. Update the logic in the history-list and history-revert-status polling
paths to inspect the JSON success/status flag (or use AssertStdoutStatus)
immediately after RunCmd returns, and fail fast with the captured stdout/stderr
instead of returning false. Use the existing Eventually-based checks and the
relevant helper symbols in this test flow to surface the last API error right
away rather than waiting for the timeout.

Add docs +history-list, +history-revert, and +history-revert-status backed by docs_ai history OpenAPI endpoints.

Document the safe history workflow and extend dry-run/live E2E coverage for the new shortcuts.
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.66%. Comparing base (39d60cb) to head (78a2d43).

Files with missing lines Patch % Lines
shortcuts/doc/docs_history.go 90.97% 6 Missing and 6 partials ⚠️
shortcuts/doc/shortcuts.go 45.45% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1612      +/-   ##
==========================================
+ Coverage   74.64%   74.66%   +0.02%     
==========================================
  Files         806      807       +1     
  Lines       81386    81530     +144     
==========================================
+ Hits        60752    60878     +126     
- Misses      16101    16113      +12     
- Partials     4533     4539       +6     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant