feat(slides): add history rollback shortcuts#1714
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds Slides CLI shortcuts for listing presentation history, reverting by ChangesSlides history shortcuts
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as Slides CLI
participant Wiki as Wiki API
participant Slides as Slides API
User->>CLI: Run history command
CLI->>CLI: Validate arguments
alt wiki presentation
CLI->>Wiki: Resolve node
Wiki-->>CLI: Return presentation token
end
alt List history
CLI->>Slides: GET histories
Slides-->>CLI: Return history entries
else Revert history
CLI->>Slides: POST history revert
Slides-->>CLI: Return task status
else Check revert status
CLI->>Slides: GET revert status
Slides-->>CLI: Return task status
end
CLI-->>User: Output API response
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1714 +/- ##
========================================
Coverage 75.00% 75.00%
========================================
Files 898 899 +1
Lines 94912 95068 +156
========================================
+ Hits 71184 71307 +123
- Misses 18269 18287 +18
- Partials 5459 5474 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@deb33275e83931f94cc1a741cc6de6a406f82869🧩 Skill updatenpx skills add larksuite/cli#feat/slides_revert -y -g |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
tests/cli_e2e/slides/slides_history_dryrun_test.go (1)
46-59: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winZero-value assertion can't distinguish "field present as 0" from "field missing".
gjson.Get(stdout, "api.0.body.wait_timeout_ms").Int()returns0both when the field is present with value0and when the path doesn't exist. If the request struct ever addsomitemptyonwait_timeout_ms(or the value is dropped some other way), this assertion would keep passing even though the field silently disappeared from the request body. Recommend also asserting.Exists()for this zero-value case.🔧 Suggested strengthening
assertion: func(t *testing.T, stdout string) { require.Equal(t, "42", gjson.Get(stdout, "api.0.body.history_version_id").String(), stdout) - require.Equal(t, int64(0), gjson.Get(stdout, "api.0.body.wait_timeout_ms").Int(), stdout) + waitTimeout := gjson.Get(stdout, "api.0.body.wait_timeout_ms") + require.True(t, waitTimeout.Exists(), "wait_timeout_ms missing from body: %s", stdout) + require.Equal(t, int64(0), waitTimeout.Int(), stdout) },🤖 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/slides/slides_history_dryrun_test.go` around lines 46 - 59, Strengthen the zero-value check in the slides history dry-run test so it verifies both presence and value of wait_timeout_ms. In the assertion for the revert case, update the gjson-based check on stdout to confirm the path exists before asserting it equals 0, using the existing assertion block in slides_history_dryrun_test.go and the api.0.body.wait_timeout_ms field to keep the test from passing if the field is omitted.tests/cli_e2e/slides/slides_history_workflow_test.go (2)
20-28: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winTight 3-minute context budget vs. cumulative retry/wait timeouts risks flaky failures.
The shared
ctx(line 27) has a 3-minute deadline and is passed to everyRunCmdcall in the test. The retry loops alone can consume up to 45s (history-listEventually, line 138) + 30s (--wait-timeout-ms 30000synchronous wait inside+history-revert, line 146) + 60s (revert-statusEventually, line 172) = 135s, leaving only ~45s of margin for+create, twoapi getfetches,+replace-pages, and the finalapi getfetch. If any step runs slower than usual, the shared ctx can expire mid-poll, causingRunCmd/require.NoErrorfailures unrelated to the actual revert logic and producing misleading failure messages.Consider increasing the ctx timeout (e.g., to 5 minutes) to give real margin over the sum of the retry/wait budgets, since this is an opt-in live E2E test where flakiness costs debugging time rather than CI throughput.
Also applies to: 116-173
🤖 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/slides/slides_history_workflow_test.go` around lines 20 - 28, The shared timeout in TestSlides_HistoryWorkflow is too tight for the cumulative retry and wait budgets used by the RunCmd steps, which can cause unrelated context-deadline failures. Increase the context deadline created with context.WithTimeout in TestSlides_HistoryWorkflow to give enough margin for all eventual/retry waits, and keep using that ctx for the existing RunCmd and require checks so the live E2E flow remains stable under slower conditions.
117-138: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSwallowed errors reduce debuggability on
Eventuallyfailure.Both retry closures discard
listErr/statusErron failure paths (returningfalsewithout recording them). If the loop times out, the failure message only says "did not expose..."/"did not finish" without the underlying CLI error, making root-causing flaky runs harder. Consider capturing the last error/exit code and including it in therequire.Eventuallyfailure message.Also applies to: 158-172
🤖 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/slides/slides_history_workflow_test.go` around lines 117 - 138, The retry closures in the slide history workflow tests are swallowing CLI failures, so `require.Eventually` times out without the underlying error context. Update the `slides_history_workflow_test.go` logic around the `slides +history-list` and related status checks to record the last `listErr`/`statusErr` and non-zero exit code, then include that captured detail in the final `require.Eventually` failure message. Use the existing `require.Eventually` blocks and the `RunCmd` calls as the places to preserve and surface the error for debugging.shortcuts/slides/slides_history_test.go (1)
343-383: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a negative test for wiki resolution to a non-slides node.
TestSlidesHistoryExecuteResolvesWikiPresentationonly covers the happy path whereobj_type == "slides". A test asserting the behavior when a wiki node resolves to a differentobj_type(e.g.,doc) would guard the resolution logic referenced inslides_history.goagainst regressions on this realistic user error path.🤖 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/slides/slides_history_test.go` around lines 343 - 383, Add a negative test around SlidesHistoryList wiki resolution to cover non-slides nodes: extend the existing resolution flow in TestSlidesHistoryExecuteResolvesWikiPresentation or add a sibling test that stubs /open-apis/wiki/v2/spaces/get_node to return an obj_type other than "slides" (for example "doc"), then verify runSlidesShortcut returns the expected error and does not proceed to fetch histories. Use the SlidesHistoryList path and the wiki node resolution logic in slides_history.go to locate the behavior under test.
🤖 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/slides/slides_history_test.go`:
- Around line 106-128: The validation error test in the slides history suite
only checks that the error is typed and matches Param, but it does not verify
the full typed metadata or wrapped cause. Update the test cases in the
`runSlidesShortcut` loop to inspect the `errs.ProblemOf` result for `Category`,
`Subtype`, and `Param`, and add assertions that the original cause is preserved
with `errors.Is` and/or `errors.Unwrap`. Keep using `errs.ValidationError` and
`errs.ProblemOf` to locate the error shape, but strengthen the checks so the
error-path coverage matches the test guidelines.
In `@shortcuts/slides/slides_history.go`:
- Around line 45-65: The three validators in validateSlidesHistoryPageSize,
validateSlidesHistoryVersionID, and validateSlidesHistoryWaitTimeout are putting
recovery guidance into the main error text instead of using .WithHint(...).
Update each errs.NewValidationError call so the message only states the invalid
input and keep the user-facing guidance like the valid range or “returned by
slides +history-list” in a separate .WithHint(...) on the returned error.
---
Nitpick comments:
In `@shortcuts/slides/slides_history_test.go`:
- Around line 343-383: Add a negative test around SlidesHistoryList wiki
resolution to cover non-slides nodes: extend the existing resolution flow in
TestSlidesHistoryExecuteResolvesWikiPresentation or add a sibling test that
stubs /open-apis/wiki/v2/spaces/get_node to return an obj_type other than
"slides" (for example "doc"), then verify runSlidesShortcut returns the expected
error and does not proceed to fetch histories. Use the SlidesHistoryList path
and the wiki node resolution logic in slides_history.go to locate the behavior
under test.
In `@tests/cli_e2e/slides/slides_history_dryrun_test.go`:
- Around line 46-59: Strengthen the zero-value check in the slides history
dry-run test so it verifies both presence and value of wait_timeout_ms. In the
assertion for the revert case, update the gjson-based check on stdout to confirm
the path exists before asserting it equals 0, using the existing assertion block
in slides_history_dryrun_test.go and the api.0.body.wait_timeout_ms field to
keep the test from passing if the field is omitted.
In `@tests/cli_e2e/slides/slides_history_workflow_test.go`:
- Around line 20-28: The shared timeout in TestSlides_HistoryWorkflow is too
tight for the cumulative retry and wait budgets used by the RunCmd steps, which
can cause unrelated context-deadline failures. Increase the context deadline
created with context.WithTimeout in TestSlides_HistoryWorkflow to give enough
margin for all eventual/retry waits, and keep using that ctx for the existing
RunCmd and require checks so the live E2E flow remains stable under slower
conditions.
- Around line 117-138: The retry closures in the slide history workflow tests
are swallowing CLI failures, so `require.Eventually` times out without the
underlying error context. Update the `slides_history_workflow_test.go` logic
around the `slides +history-list` and related status checks to record the last
`listErr`/`statusErr` and non-zero exit code, then include that captured detail
in the final `require.Eventually` failure message. Use the existing
`require.Eventually` blocks and the `RunCmd` calls as the places to preserve and
surface the error for debugging.
🪄 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: fd3fd404-7459-4fdb-bf02-e8803e08359e
📒 Files selected for processing (7)
shortcuts/slides/shortcuts.goshortcuts/slides/slides_history.goshortcuts/slides/slides_history_test.goskills/lark-slides/SKILL.mdskills/lark-slides/references/lark-slides-history.mdtests/cli_e2e/slides/slides_history_dryrun_test.gotests/cli_e2e/slides/slides_history_workflow_test.go
d526aed to
fd365a1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@skills/lark-slides/references/lark-slides-history.md`:
- Around line 29-30: Clarify the edit_time representation in the history
matching guidance and examples. Update the instructions near the edit_time
matching references and the JSON return example so they consistently use one
format, or explicitly state that the CLI converts Unix timestamps to ISO 8601
for display while matching uses the original timestamp value.
🪄 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: 5bb8a2ab-a9b1-401f-8b50-49df62a06a34
📒 Files selected for processing (7)
shortcuts/slides/shortcuts.goshortcuts/slides/slides_history.goshortcuts/slides/slides_history_test.goskills/lark-slides/SKILL.mdskills/lark-slides/references/lark-slides-history.mdtests/cli_e2e/slides/slides_history_dryrun_test.gotests/cli_e2e/slides/slides_history_workflow_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
- shortcuts/slides/shortcuts.go
- tests/cli_e2e/slides/slides_history_dryrun_test.go
- skills/lark-slides/SKILL.md
- tests/cli_e2e/slides/slides_history_workflow_test.go
- shortcuts/slides/slides_history.go
- shortcuts/slides/slides_history_test.go
0a9d282 to
375c73c
Compare
# Conflicts: # skills/lark-slides/SKILL.md
375c73c to
deb3327
Compare
Summary
slides +history-list,slides +history-revert, andslides +history-revert-statusshortcutsTests
go test ./shortcuts/slides -run 'TestSlidesHistory'\n-go test ./tests/cli_e2e/slides -run 'TestSlidesHistoryDryRunE2E'\n\n## Notes\n- live workflow test is gated byLARK_SLIDES_HISTORY_E2E=1and was not run in this PR flow\nSummary by CodeRabbit
+history-list,+history-revert, and+history-revert-status, including wiki-backed presentation support.lark-slides-historyreference covering the rollback workflow and requiredhistory_version_id.wait_timeout_ms.