fix(sheets): normalize single-cell range in +set-style and +batch-set-style#548
fix(sheets): normalize single-cell range in +set-style and +batch-set-style#548caojie0621 wants to merge 1 commit intomainfrom
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 (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughBatch-style Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #548 +/- ##
==========================================
+ Coverage 59.91% 59.93% +0.01%
==========================================
Files 388 388
Lines 33147 33163 +16
==========================================
+ Hits 19859 19875 +16
Misses 11420 11420
Partials 1868 1868 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e2b6773 to
06a10ba
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/sheets/sheet_batch_set_style.go`:
- Around line 87-107: Add unit tests for normalizeBatchStyleRanges to lock its
in-place mutation behavior and edge cases: create tests that call
normalizeBatchStyleRanges with (1) a top-level []interface{} where an entry has
ranges containing the string "xxx!A1" and assert it becomes "xxx!A1:A1"
(single-cell expansion via normalizePointRange), (2) a ranges string "xxx!A1:B2"
remains unchanged, (3) ranges containing non-string entries are ignored, (4) an
entry whose "ranges" is missing or not a []interface{} is skipped without
panicking, and (5) a non-array top-level input (e.g., a map or string) returns
without panic; reference the normalizeBatchStyleRanges function and its use of
normalizePointRange/normalizeSheetRange/splitSheetRange in test names/comments
and assert the original slice objects are mutated in place as expected.
🪄 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: 43dbd7e5-fe6f-4bac-a386-7279d94f7994
📒 Files selected for processing (2)
shortcuts/sheets/sheet_batch_set_style.goshortcuts/sheets/sheet_set_style.go
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e747016a0b1ba1afe0d5ddb8355e2ca0ea1342b1🧩 Skill updatenpx skills add larksuite/cli#fix/sheet_style -y -g |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/sheets/sheet_cell_ops_test.go (1)
566-609: Consider adding a negative/edge-case test for non-conformingdatashapes.
normalizeBatchStyleRangessilently no-ops whendataisn't[]interface{}, when entries aren't maps, or whenrangesisn't[]interface{}. A small test confirming that, e.g., a non-string entry inrangesor a missingrangeskey passes through unchanged (without panicking) would lock in that defensive behavior and protect against future regressions in the type-assertion chain.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/sheets/sheet_cell_ops_test.go` around lines 566 - 609, Add a negative/edge-case unit test(s) that exercises normalizeBatchStyleRanges to ensure it safely no-ops on non-conforming shapes (so we don't regress its defensive type-assertion behavior); specifically write a test in shortcuts/sheets/sheet_cell_ops_test.go that calls the same code path (e.g., via SheetBatchSetStyle.DryRun or by invoking normalizeBatchStyleRanges indirectly) with inputs where top-level data is not []interface{}, an entry is not a map, a ranges key is missing, and a ranges array contains a non-string value, and assert the call completes without panic and the returned value is unchanged (or equal to the original input) for each scenario. Ensure the test names reference the behavior (e.g., TestNormalizeBatchStyleRanges_NonConformingData) so future reviewers can locate normalizeBatchStyleRanges-related tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@shortcuts/sheets/sheet_cell_ops_test.go`:
- Around line 566-609: Add a negative/edge-case unit test(s) that exercises
normalizeBatchStyleRanges to ensure it safely no-ops on non-conforming shapes
(so we don't regress its defensive type-assertion behavior); specifically write
a test in shortcuts/sheets/sheet_cell_ops_test.go that calls the same code path
(e.g., via SheetBatchSetStyle.DryRun or by invoking normalizeBatchStyleRanges
indirectly) with inputs where top-level data is not []interface{}, an entry is
not a map, a ranges key is missing, and a ranges array contains a non-string
value, and assert the call completes without panic and the returned value is
unchanged (or equal to the original input) for each scenario. Ensure the test
names reference the behavior (e.g.,
TestNormalizeBatchStyleRanges_NonConformingData) so future reviewers can locate
normalizeBatchStyleRanges-related tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 99b441dd-70fc-43ec-bb9c-88c4369618ca
📒 Files selected for processing (3)
shortcuts/sheets/sheet_batch_set_style.goshortcuts/sheets/sheet_cell_ops_test.goshortcuts/sheets/sheet_set_style.go
🚧 Files skipped from review as they are similar to previous changes (2)
- shortcuts/sheets/sheet_set_style.go
- shortcuts/sheets/sheet_batch_set_style.go
…-style /style and /styles_batch_update require full "A1:A1" form and reject single-cell shorthand "A1". +set-style was using normalizeSheetRange (prefix-only) and +batch-set-style passed --data through unchanged, so both failed with `wrong range` when callers supplied a single cell. Switch +set-style to normalizePointRange, and walk each ranges[] entry in +batch-set-style through normalizePointRange before sending. Multi-cell spans pass through unchanged.
06a10ba to
e747016
Compare
Summary
The
/styleand/styles_batch_updateendpoints require the fullStart:Endrange form and reject single-cell shorthand likeA1with[90202] wrong range. Neither shortcut wasnormalizing:
+set-styleusednormalizeSheetRange, which only prefixessheetId!but does not expand single cells.+batch-set-stylejson.Unmarshal(--data)and passed the payload through unchanged, soranges[]entries were never touched.Changes
+set-style: swapnormalizeSheetRange→normalizePointRange(already present inhelpers.goand used by+append/+find/+read/+write-image). Single-cellA1isexpanded to
sheetId!A1:A1.+batch-set-style: addnormalizeBatchStyleRanges()and invoke it in bothDryRunandExecute, walking eachdata[].ranges[]entry throughnormalizePointRange.A1:B2) are passed through unchanged bynormalizePointRange, so existing behavior is preserved.Test plan
+set-stylewith single cellA1— dry-run body shows68ef76!A1:A1; live call succeeds withupdatedRange=D1:D1.+set-stylewith multi-cellA1:B2— live call succeeds withupdatedRange=A1:B2,updatedCells=4.+batch-set-stylewith single cells["68ef76!A2","68ef76!B2"]— dry-run shows expansion toA2:A2/B2:B2; live call succeeds.+batch-set-stylemixing["C1:D2", "E3"]— multi-cell span passes through asC1:D2; single cell expands toE3:E3; both applied in one request.Refs
N/A
Summary by CodeRabbit
Bug Fixes
Documentation