feat(wiki): add +node-get / +node-delete / +space-create shortcuts#904
feat(wiki): add +node-get / +node-delete / +space-create shortcuts#904liujinkun2025 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds three wiki shortcuts (+space-create, +node-get, +node-delete), extracts shared async-task parsing/polling helpers used by delete flows, refactors delete-space to use the shared helpers, updates the shortcut registry, and adds comprehensive tests for the new commands and async polling. ChangesWiki node operations
Sequence Diagram(s)sequenceDiagram
participant ComponentA
participant ComponentB
ComponentA->>ComponentB: observable interaction
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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 #904 +/- ##
==========================================
+ Coverage 65.95% 66.09% +0.14%
==========================================
Files 523 527 +4
Lines 49590 50060 +470
==========================================
+ Hits 32707 33088 +381
- Misses 14090 14153 +63
- Partials 2793 2819 +26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@eeda44798629ecfd07e38d31be86696ce8521b38🧩 Skill updatenpx skills add larksuite/cli#feat/wiki-node-shortcuts -y -g |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
shortcuts/wiki/wiki_node_create_test.go (1)
114-126: ⚡ Quick winStrengthen this test to assert the newly added commands explicitly.
Checking only
len(shortcuts) == 9won’t catch a wrong/missing command if count stays the same. Add assertions for+space-create,+node-get, and+node-delete(or assert the full expected command list).Suggested test hardening
func TestWikiShortcutsIncludeAllCommands(t *testing.T) { t.Parallel() shortcuts := Shortcuts() if len(shortcuts) != 9 { t.Fatalf("len(Shortcuts()) = %d, want 9", len(shortcuts)) } + got := make([]string, 0, len(shortcuts)) + for _, sc := range shortcuts { + got = append(got, sc.Command) + } + want := []string{ + "+move", + "+node-create", + "+delete-space", + "+space-list", + "+space-create", + "+node-list", + "+node-copy", + "+node-get", + "+node-delete", + } + for i := range want { + if got[i] != want[i] { + t.Fatalf("shortcuts[%d].Command = %q, want %q", i, got[i], want[i]) + } + } - if shortcuts[0].Command != "+move" { - t.Fatalf("shortcuts[0].Command = %q, want %q", shortcuts[0].Command, "+move") - } - if shortcuts[1].Command != "+node-create" { - t.Fatalf("shortcuts[1].Command = %q, want %q", shortcuts[1].Command, "+node-create") - } - if shortcuts[2].Command != "+delete-space" { - t.Fatalf("shortcuts[2].Command = %q, want %q", shortcuts[2].Command, "+delete-space") - } }🤖 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/wiki/wiki_node_create_test.go` around lines 114 - 126, The test in wiki_node_create_test.go currently only checks len(shortcuts) and a few commands; strengthen it by asserting the full expected command list or at minimum add explicit checks for the newly added commands: verify that shortcuts contains "+space-create", "+node-get", and "+node-delete" (in addition to existing checks for "+move", "+node-create", "+delete-space"), using the same pattern as the existing assertions against shortcuts[n].Command so the test fails if any command is missing or out of order.
🤖 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/wiki/wiki_async_task.go`:
- Around line 165-172: The retry logic currently calls output.ErrWithHint which
rebuilds and loses structured API detail; instead, detect when lastErr is an
*output.ExitError (the existing exitErr variable) and preserve its Detail fields
(Code, ConsoleURL, Risk, nested Detail, etc.) while only appending the retry
hint to the message/hint field, then return the original or a minimally-updated
ExitError so structured fields are retained; update the branch handling
lastErr/exitErr around the existing output.ErrWithHint call to reuse
exitErr.Detail rather than reconstructing the error.
- Around line 65-73: The StatusCode method on wikiAsyncTaskStatus returns raw
non-empty statuses which can conflict with Failed(); update StatusCode() to
align with the helper's non-terminal classification by returning
wikiAsyncStatusProcessing for any status that is not explicitly ready/successful
or explicitly failed/terminal. In practice, inside StatusCode() (on
wikiAsyncTaskStatus) trim the value, then use the same readiness/terminal logic
used by Failed() (or call a shared helper) to detect non-terminal states and
coerce them to wikiAsyncStatusProcessing, otherwise return the original terminal
status.
---
Nitpick comments:
In `@shortcuts/wiki/wiki_node_create_test.go`:
- Around line 114-126: The test in wiki_node_create_test.go currently only
checks len(shortcuts) and a few commands; strengthen it by asserting the full
expected command list or at minimum add explicit checks for the newly added
commands: verify that shortcuts contains "+space-create", "+node-get", and
"+node-delete" (in addition to existing checks for "+move", "+node-create",
"+delete-space"), using the same pattern as the existing assertions against
shortcuts[n].Command so the test fails if any command is missing or out of
order.
🪄 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: 5a211eba-1323-42a1-9667-4ef59fe458ee
📒 Files selected for processing (10)
shortcuts/wiki/shortcuts.goshortcuts/wiki/wiki_async_task.goshortcuts/wiki/wiki_delete.goshortcuts/wiki/wiki_node_create_test.goshortcuts/wiki/wiki_node_delete.goshortcuts/wiki/wiki_node_delete_test.goshortcuts/wiki/wiki_node_get.goshortcuts/wiki/wiki_node_get_test.goshortcuts/wiki/wiki_space_create.goshortcuts/wiki/wiki_space_create_test.go
| // StatusCode returns a never-empty status value for the output envelope. If | ||
| // the backend response omits delete_*_result.status (or sends whitespace), | ||
| // fall back to "processing" so the documented timeout-shape stays accurate. | ||
| func (s wikiAsyncTaskStatus) StatusCode() string { | ||
| if status := strings.TrimSpace(s.Status); status != "" { | ||
| return status | ||
| } | ||
| return wikiAsyncStatusProcessing | ||
| } |
There was a problem hiding this comment.
Keep status aligned with the helper's non-terminal classification.
Failed() intentionally treats unknown non-success values as “still processing”, but StatusCode() returns those raw values unchanged. That can yield an internally inconsistent result like status="canceled", failed=false while the command prints “still in progress”. Either classify additional terminal states explicitly or coerce any non-ready/non-failed status to processing here.
♻️ Suggested change
func (s wikiAsyncTaskStatus) StatusCode() string {
- if status := strings.TrimSpace(s.Status); status != "" {
- return status
- }
- return wikiAsyncStatusProcessing
+ switch status := s.normalizedStatus(); {
+ case status == "":
+ return wikiAsyncStatusProcessing
+ case s.Ready():
+ return wikiAsyncStatusSuccess
+ case s.Failed():
+ return wikiAsyncStatusFailure
+ default:
+ return wikiAsyncStatusProcessing
+ }
}🤖 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/wiki/wiki_async_task.go` around lines 65 - 73, The StatusCode
method on wikiAsyncTaskStatus returns raw non-empty statuses which can conflict
with Failed(); update StatusCode() to align with the helper's non-terminal
classification by returning wikiAsyncStatusProcessing for any status that is not
explicitly ready/successful or explicitly failed/terminal. In practice, inside
StatusCode() (on wikiAsyncTaskStatus) trim the value, then use the same
readiness/terminal logic used by Failed() (or call a shared helper) to detect
non-terminal states and coerce them to wikiAsyncStatusProcessing, otherwise
return the original terminal status.
- +node-get: wrap wiki.spaces.get_node; accepts node_token, obj_token, or a Lark URL (URL path auto-infers obj_type); formatted output with creator / updated_at / url - +node-delete: wrap space.node delete; high-risk-write (--yes gated), async delete-node task polling, auto-resolves space_id via get_node when --space-id omitted, actionable hints for codes 131011 / 131003 - +space-create: wrap spaces.create; user-only identity, --name required (no empty-name spaces), flattened space output, no url - factor the shared wiki async-task poll loop into wiki_async_task.go and refactor +delete-space onto it (no behavior change) Change-Id: Ib7bcb9ab826c71b0aa943303f6eb34a5d993cf10
f282650 to
eeda447
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/wiki/wiki_space_create.go (1)
108-119: ⚡ Quick winReuse the shared space-record formatter here.
This open-codes the flattened
spacefields even though the file already referencesparseWikiSpaceRecord. Composing the shared parser/formatter and then overlayingdescriptionwould keep+space-createaligned with the other wiki space outputs and avoid future drift.🤖 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/wiki/wiki_space_create.go` around lines 108 - 119, Replace the manual field extraction in wikiSpaceCreateOutput with a call to the shared parser/formatter parseWikiSpaceRecord(raw) and then overlay or set the "description" key from the raw map so the create output stays consistent with other wiki space outputs; specifically, inside wikiSpaceCreateOutput call parseWikiSpaceRecord(raw) to get the base map, copy/merge that into the returned map, and ensure "description" is taken from common.GetString(raw, "description") to override or preserve the caller-provided description.
🤖 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/wiki/wiki_space_create.go`:
- Around line 108-119: Replace the manual field extraction in
wikiSpaceCreateOutput with a call to the shared parser/formatter
parseWikiSpaceRecord(raw) and then overlay or set the "description" key from the
raw map so the create output stays consistent with other wiki space outputs;
specifically, inside wikiSpaceCreateOutput call parseWikiSpaceRecord(raw) to get
the base map, copy/merge that into the returned map, and ensure "description" is
taken from common.GetString(raw, "description") to override or preserve the
caller-provided description.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2154a194-f9ac-466c-8175-f64a619eadf2
📒 Files selected for processing (11)
shortcuts/wiki/shortcuts.goshortcuts/wiki/wiki_async_task.goshortcuts/wiki/wiki_async_task_test.goshortcuts/wiki/wiki_delete.goshortcuts/wiki/wiki_node_create_test.goshortcuts/wiki/wiki_node_delete.goshortcuts/wiki/wiki_node_delete_test.goshortcuts/wiki/wiki_node_get.goshortcuts/wiki/wiki_node_get_test.goshortcuts/wiki/wiki_space_create.goshortcuts/wiki/wiki_space_create_test.go
✅ Files skipped from review due to trivial changes (1)
- shortcuts/wiki/wiki_node_create_test.go
🚧 Files skipped from review as they are similar to previous changes (8)
- shortcuts/wiki/shortcuts.go
- shortcuts/wiki/wiki_space_create_test.go
- shortcuts/wiki/wiki_node_get_test.go
- shortcuts/wiki/wiki_node_get.go
- shortcuts/wiki/wiki_delete.go
- shortcuts/wiki/wiki_async_task.go
- shortcuts/wiki/wiki_node_delete.go
- shortcuts/wiki/wiki_node_delete_test.go
Summary
Fills the wiki node/space CRUD gaps. Three new shortcuts plus a shared async-task helper:
wiki +node-get— wrapswiki.spaces.get_node. Accepts a rawnode_token/obj_tokenor a Lark URL (URL path auto-infersobj_type; conflicting explicit--obj-typeis rejected). Optional--space-idcross-check. Formatted output:title / obj_type / obj_token / node_token / space_id / parent_node_token / creator / updated_at / url.wiki +node-delete— wraps thespace.nodedelete API.high-risk-write(--yesgated), bounded asyncdelete_nodetask polling, auto-resolvesspace_idviaget_nodewhen--space-idis omitted,--include-childrendefaults totrue. Maps Lark codes131011(UI-approval required) and131003(subtree too large) to actionable hints; other codes pass through with the original code preserved.wiki +space-create— wrapsspaces.create. User-only identity (the API rejects tenant/bot tokens; frameworkCheckIdentityenforces it).--namerequired (no empty-name spaces),--descriptionoptional. Flattened space output, nourl(the API returns none and there is no space-home URL builder).wiki_async_task.go(pollWikiAsyncTask/parseWikiAsyncTaskStatus/wikiAsyncTaskStatus).+delete-spacenow delegates to it via thin wrappers — no behavior change, ~110 lines of duplication removed.Also renames the originally-proposed
+get-nodeto+node-getfor consistency with the+node-*family.Risk-level note:
spaces.createcarriesdanger:truein the registry, but that flag only drives thelark-cli schemabrowser's red[danger]tag — it is not a runtime confirmation gate (onlyrisk:high-risk-writeis). The raw API runs without--yestoday, so+space-createatRisk:writeis runtime-consistent; a help Tip surfaces the danger flag and points to+delete-spacefor undo.Test plan
go test ./shortcuts/...(and full suite excludingtests/cli_e2e) greengofmt -lclean,go vet ./shortcuts/wiki/...clean,./build.shOK--yesgating, bot-identity rejection, output flattening--help,--dry-run, validation failures, identity rejection for each shortcutgolangci-lintnot run (not installed in dev env) — please confirm in CItests/cli_e2e/wikinot run locally (hits real Feishu) — verify in CI/stagingSummary by CodeRabbit
New Features
Tests