Skip to content

fix: add atomic overwrite for whiteboard +update#483

Open
syh-cpdsss wants to merge 1 commit intomainfrom
feat/whiteboard-dev
Open

fix: add atomic overwrite for whiteboard +update#483
syh-cpdsss wants to merge 1 commit intomainfrom
feat/whiteboard-dev

Conversation

@syh-cpdsss
Copy link
Copy Markdown
Collaborator

@syh-cpdsss syh-cpdsss commented Apr 15, 2026

Summary

This PR updates the whiteboard update functionality to use the new backend API's overwrite parameter for atomic overwrite operations, replacing the previous approach of first reading and then deleting nodes.

Changes

  • Added overwrite field to API request bodies for both raw nodes and PlantUML/Mermaid updates
  • Removed the separate node reading and deletion logic in dry run and execution paths

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark whiteboard +update command works as expected with --overwrite flag

Summary by CodeRabbit

  • Improvements
    • Streamlined whiteboard overwrite flow to create-with-overwrite instead of clearing then recreating content.
    • Removed deleted-node count/details from overwrite operation results and messages.
  • Tests
    • Simplified overwrite tests to reflect the new create-with-overwrite behavior (no pre-delete stubbing).

@github-actions github-actions bot added the size/M Single-domain feat or fix with limited business impact label Apr 15, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d76c9a0-a08d-4db4-b7c9-73b47c900e9a

📥 Commits

Reviewing files that changed from the base of the PR and between 62cbff5 and ea4fe46.

📒 Files selected for processing (3)
  • shortcuts/whiteboard/shortcuts.go
  • shortcuts/whiteboard/whiteboard_update.go
  • shortcuts/whiteboard/whiteboard_update_test.go
✅ Files skipped from review due to trivial changes (1)
  • shortcuts/whiteboard/shortcuts.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/whiteboard/whiteboard_update_test.go

📝 Walkthrough

Walkthrough

The update replaces explicit node-read/delete steps with overwrite flags in create requests, restructures WbCliOutputData.Result to an object containing nodes, and simplifies tests by removing pre-delete stubs.

Changes

Cohort / File(s) Summary
Data Structure Change
shortcuts/whiteboard/shortcuts.go
Changed WbCliOutputData.Result from interface{} to struct { Nodes []interface{} 'json:"nodes"' }, causing JSON (un)marshalling of result to expect an object with a nodes array.
Whiteboard Update Logic
shortcuts/whiteboard/whiteboard_update.go
Removed clearWhiteboardContent deletion workflow and scopes board:whiteboard:node:read/...:delete; added Overwrite into DryRun and execution request bodies (rawNodesCreateReq, plantumlCreateReq); simplified parseWBcliNodes to return []interface{}.
Tests
shortcuts/whiteboard/whiteboard_update_test.go
Removed stubbing of GET .../nodes and DELETE batch endpoints; tests now only stub POST create-nodes for overwrite scenarios and no longer manipulate sleep override.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰
A tiny hop, a cleaner flow,
Nodes now bundled where they go.
Overwrite flags softly sing,
No more clearing — let creation bring.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding atomic overwrite functionality for whiteboard updates using the backend API's overwrite parameter.
Description check ✅ Passed The description follows the template with all required sections (Summary, Changes, Test Plan) completed with specific details about the implementation and verification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/whiteboard-dev

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 and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/whiteboard-dev -y -g

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/whiteboard/whiteboard_update.go (1)

193-205: ⚠️ Potential issue | 🟠 Major

Fail fast when result.nodes is missing.

With the new typed Result.Nodes shape, a payload like {"code":0,"data":{"to":"openapi"}} now unmarshals successfully and returns nil here. That nil slice is then forwarded as the live request body in rawNodesCreateReq, so malformed openapi JSON is no longer rejected before the update call. Please validate presence of result.nodes explicitly; you’ll likely need a pointer or json.RawMessage in WbCliOutputData to distinguish “missing” from [].

Also applies to: 267-275

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/whiteboard/whiteboard_update.go` around lines 193 - 205,
parseWBcliNodes currently treats a missing result.nodes the same as an empty
slice because WbCliOutputData.Result.Nodes is a concrete slice; change
WbCliOutput/WbCliOutputData so Result.Nodes is a pointer ([]Node) or
json.RawMessage to distinguish "missing" vs present-but-empty, then in
parseWBcliNodes check explicitly that wbOutput.Data.Result.Nodes != nil (or that
RawMessage is non-empty) before assigning wbNodes; if missing, return an
output.Errorf with ExitValidation and the "whiteboard-cli" context (same pattern
used above) to fail fast instead of forwarding a nil slice to rawNodesCreateReq.
🧹 Nitpick comments (1)
shortcuts/whiteboard/whiteboard_update_test.go (1)

480-502: Assert overwrite: true in these requests.

These tests only prove the POST endpoints are hit. If Overwrite stops being serialized in plantumlCreateReq or rawNodesCreateReq, both cases still pass, so the PR’s main behavior change is still untested. Please inspect or match the outbound body here.

Also applies to: 504-525

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/whiteboard/whiteboard_update_test.go` around lines 480 - 502, The
test must assert that the outbound request includes overwrite: true so the
serialization of Overwrite in plantumlCreateReq and rawNodesCreateReq is
validated; modify the httpmock.Stub registration in
TestWhiteboardUpdateExecute_WithOverwrite (and the other test at 504-525) to
inspect the incoming request body (or use a stub BodyMatcher) and assert that
the JSON contains "overwrite": true (or return an error when it's absent),
referencing runUpdateShortcut, WhiteboardUpdate, plantumlCreateReq and
rawNodesCreateReq to locate the requests to validate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/whiteboard/whiteboard_update.go`:
- Line 33: The wbUpdateScopes slice currently includes an unnecessary
permission; remove the "board:whiteboard:node:delete" entry from the
wbUpdateScopes variable so it contains only "board:whiteboard:node:create" to
follow least-privilege requirements; update any related tests or usages that
expect the deleted scope and run the build to ensure no references to
wbUpdateScopes still assume the delete scope.

---

Outside diff comments:
In `@shortcuts/whiteboard/whiteboard_update.go`:
- Around line 193-205: parseWBcliNodes currently treats a missing result.nodes
the same as an empty slice because WbCliOutputData.Result.Nodes is a concrete
slice; change WbCliOutput/WbCliOutputData so Result.Nodes is a pointer ([]Node)
or json.RawMessage to distinguish "missing" vs present-but-empty, then in
parseWBcliNodes check explicitly that wbOutput.Data.Result.Nodes != nil (or that
RawMessage is non-empty) before assigning wbNodes; if missing, return an
output.Errorf with ExitValidation and the "whiteboard-cli" context (same pattern
used above) to fail fast instead of forwarding a nil slice to rawNodesCreateReq.

---

Nitpick comments:
In `@shortcuts/whiteboard/whiteboard_update_test.go`:
- Around line 480-502: The test must assert that the outbound request includes
overwrite: true so the serialization of Overwrite in plantumlCreateReq and
rawNodesCreateReq is validated; modify the httpmock.Stub registration in
TestWhiteboardUpdateExecute_WithOverwrite (and the other test at 504-525) to
inspect the incoming request body (or use a stub BodyMatcher) and assert that
the JSON contains "overwrite": true (or return an error when it's absent),
referencing runUpdateShortcut, WhiteboardUpdate, plantumlCreateReq and
rawNodesCreateReq to locate the requests to validate.
🪄 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: be7b4bee-686f-41ad-be10-40ee21b58f37

📥 Commits

Reviewing files that changed from the base of the PR and between ec9e67c and 62cbff5.

📒 Files selected for processing (3)
  • shortcuts/whiteboard/shortcuts.go
  • shortcuts/whiteboard/whiteboard_update.go
  • shortcuts/whiteboard/whiteboard_update_test.go

Change-Id: I995e9575e333d4c2925eac75a52e4442dc570c5c
@syh-cpdsss syh-cpdsss force-pushed the feat/whiteboard-dev branch from 62cbff5 to ea4fe46 Compare April 15, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant