feat: add docs history shortcuts#1612
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughAdds 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. ChangesDoc history CLI
API test harness
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.mdmarkdownlint-cli2 wrapper config was not available before execution skills/lark-doc/references/lark-doc-history.mdmarkdownlint-cli2 wrapper config was not available before execution tests/cli_e2e/docs/coverage.mdmarkdownlint-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. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@78a2d43506a70212efcbe5d7954bcf17036df8bc🧩 Skill updatenpx skills add larksuite/cli#feat/docs_revert -y -g |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
6982572 to
f8fc948
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/cli_e2e/docs/docs_update_dryrun_test.go (1)
90-122: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winParse the dry-run JSON instead of matching formatted fragments.
The new history assertions depend on exact serialization details like
"page_size": 5and"task_id": "task_1". A whitespace or pretty-print change will fail this test even if the request shape is still correct. Parseresult.Stdoutand assert the dry-runapi[0]URL/body/params fields directly instead of searchingstdout+stderrfor 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
📒 Files selected for processing (10)
.gitignoreshortcuts/doc/docs_history.goshortcuts/doc/docs_history_test.goshortcuts/doc/shortcuts.goshortcuts/register_test.goskills/lark-doc/SKILL.mdskills/lark-doc/references/lark-doc-history.mdtests/cli_e2e/docs/coverage.mdtests/cli_e2e/docs/docs_history_workflow_test.gotests/cli_e2e/docs/docs_update_dryrun_test.go
| _, 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) |
There was a problem hiding this comment.
📐 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
| 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") |
There was a problem hiding this comment.
🩺 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.
f8fc948 to
78a2d43
Compare
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Summary
Add
docshistory shortcuts so users and agents can list Docx history versions, revert to a selectedhistory_version_id, and poll revert task status through structured CLI flows.Changes
docs +history-list,docs +history-revert, anddocs +history-revert-statusshortcuts backed by Docs AI history APIs.history_version_id, wait timeout, and task ID with typederrs.*validation errors.lark-docskill documentation and coverage notes with the history workflow andrevision_idtohistory_version_idguidance.Test Plan
make unit-testRelated Issues
Summary by CodeRabbit
New Features
Documentation
Tests