fix: centralize resource URL parsing#1812
Conversation
📝 WalkthroughWalkthroughThis PR centralizes resource URL parsing by adding a ChangesURL Parsing Refactor and Wiki Scope Enforcement
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1812 +/- ##
==========================================
- Coverage 74.44% 74.43% -0.01%
==========================================
Files 860 860
Lines 89855 89840 -15
==========================================
- Hits 66891 66872 -19
- Misses 17780 17783 +3
- Partials 5184 5185 +1 ☔ 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@f437118473cf497aeb25885567e350043611f2c7🧩 Skill updatenpx skills add larksuite/cli#fix/unify-resource-url-wiki-resolve -y -g |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/drive/drive_add_comment.go`:
- Around line 575-577: Add test coverage for the new wiki-scope pre-flight in
the wiki comment resolution flow. Update the add-comment tests around
resolve-comment-target/wiki-resolution to exercise the
`runtime.EnsureScopes([]string{"wiki:node:retrieve"})` branch and assert the
missing-scope failure path returns the expected error. Use the existing
`resolvedCommentTarget` and wiki-resolution helpers in `drive_add_comment.go` so
the test targets this exact check.
In `@shortcuts/drive/drive_apply_permission_test.go`:
- Around line 90-96: Update TestResolvePermApplyTarget_UnsupportedURLType to
assert the returned error as *errs.ValidationError from resolvePermApplyTarget,
then verify Subtype equals errs.SubtypeInvalidArgument and Param equals "--type"
instead of relying on strings.Contains; use the ValidationError fields directly
to validate the typed error behavior.
🪄 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: d1d58cdb-162b-42ba-b09a-0da33c5af5d5
📒 Files selected for processing (11)
shortcuts/base/base_resolve.goshortcuts/common/resource_url.goshortcuts/common/resource_url_test.goshortcuts/doc/doc_media_insert.goshortcuts/doc/doc_resource_cover.goshortcuts/doc/helpers.goshortcuts/doc/helpers_test.goshortcuts/drive/drive_add_comment.goshortcuts/drive/drive_add_comment_test.goshortcuts/drive/drive_apply_permission.goshortcuts/drive/drive_apply_permission_test.go
| if err := runtime.EnsureScopes([]string{"wiki:node:retrieve"}); err != nil { | ||
| return resolvedCommentTarget{}, err | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Look for existing test coverage of the wiki scope enforcement path.
rg -nP -C3 'EnsureScopes|wiki:node:retrieve' shortcuts/drive/Repository: larksuite/cli
Length of output: 5639
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find tests related to drive_add_comment and scope enforcement.
rg -n --glob '*_test.go' 'drive_add_comment|EnsureScopes|wiki:node:retrieve|wiki resolution|Resolving wiki node' shortcuts/drive/
# Show test file names in the drive shortcut area.
git ls-files 'shortcuts/drive/*_test.go'
# Inspect the add-comment test file(s) if present.
for f in $(git ls-files 'shortcuts/drive/*_test.go' | rg 'add_comment|comment'); do
echo "===== $f ====="
wc -l "$f"
sed -n '1,260p' "$f"
doneRepository: larksuite/cli
Length of output: 151
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Enumerate drive shortcut tests and inspect the relevant ones for comment/wiki coverage.
git ls-files 'shortcuts/drive/*_test.go'
# Search all drive tests for add-comment, wiki resolution, or scope-enforcement coverage.
rg -n -C 2 'drive_add_comment|Resolving wiki node|wiki:node:retrieve|EnsureScopes|missing_scope|conditional scope|ConditionalScopes' shortcuts/drive/*_test.go
# If there is a dedicated add-comment test file, show it.
for f in $(git ls-files 'shortcuts/drive/*_test.go' | rg 'add_comment|comment'); do
echo "===== $f ====="
wc -l "$f"
sed -n '1,260p' "$f"
doneRepository: larksuite/cli
Length of output: 8479
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the wiki-related tests inside the add-comment test file.
rg -n -C 4 'wiki|EnsureScopes|missing_scope|scope|Resolve.*wiki|resolve.*wiki|comment target|resolvedCommentTarget' shortcuts/drive/drive_add_comment_test.go
# Show the surrounding sections for any wiki-related matches.
for n in $(rg -n 'wiki|EnsureScopes|missing_scope|scope' shortcuts/drive/drive_add_comment_test.go | cut -d: -f1 | head -n 20); do
start=$((n-20))
end=$((n+40))
echo "===== lines ${start}-${end} ====="
sed -n "${start},${end}p" shortcuts/drive/drive_add_comment_test.go
doneRepository: larksuite/cli
Length of output: 50369
Add a test for the wiki-scope pre-flight. The new runtime.EnsureScopes([]string{"wiki:node:retrieve"}) check in the wiki-resolution path still needs coverage for the missing-scope failure; the current add-comment tests cover URL parsing and successful wiki resolution, but not this branch.
🤖 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/drive/drive_add_comment.go` around lines 575 - 577, Add test
coverage for the new wiki-scope pre-flight in the wiki comment resolution flow.
Update the add-comment tests around resolve-comment-target/wiki-resolution to
exercise the `runtime.EnsureScopes([]string{"wiki:node:retrieve"})` branch and
assert the missing-scope failure path returns the expected error. Use the
existing `resolvedCommentTarget` and wiki-resolution helpers in
`drive_add_comment.go` so the test targets this exact check.
Source: Coding guidelines
| func TestResolvePermApplyTarget_UnsupportedURLType(t *testing.T) { | ||
| t.Parallel() | ||
| _, _, err := resolvePermApplyTarget("https://example.feishu.cn/drive/folder/fldTok123", "") | ||
| if err == nil || !strings.Contains(err.Error(), "unsupported --type") { | ||
| t.Fatalf("expected unsupported type error, got: %v", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
ast-grep outline --items all --type struct --match 'ValidationError' $(fd -t f -e go . | rg -l 'ValidationError' | head -20) 2>/dev/null
rg -nP 'type ValidationError struct' -A 12 $(fd -e go)Repository: larksuite/cli
Length of output: 992
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the test target and the error construction path.
rg -n "resolvePermApplyTarget|unsupported --type|SubtypeInvalidArgument|ValidationError|NewValidationError|WithParam|Param:" shortcuts/drive errs -S
# Show the relevant implementation snippets with line numbers.
for f in shortcuts/drive/drive_apply_permission.go shortcuts/drive/drive_apply_permission_test.go errs/types.go errs/*.go; do
[ -f "$f" ] && { echo "===== $f ====="; sed -n '1,260p' "$f" | cat -n; }
doneRepository: larksuite/cli
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,120p' shortcuts/drive/drive_apply_permission.go | cat -n
printf '\n===== test =====\n'
sed -n '1,140p' shortcuts/drive/drive_apply_permission_test.go | cat -n
printf '\n===== validation error =====\n'
sed -n '1,100p' errs/types.go | cat -nRepository: larksuite/cli
Length of output: 16127
Assert the typed validation error here
Match *errs.ValidationError and check Subtype == errs.SubtypeInvalidArgument plus Param == "--type" instead of strings.Contains(...); ValidationError exposes Param directly.
🤖 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/drive/drive_apply_permission_test.go` around lines 90 - 96, Update
TestResolvePermApplyTarget_UnsupportedURLType to assert the returned error as
*errs.ValidationError from resolvePermApplyTarget, then verify Subtype equals
errs.SubtypeInvalidArgument and Param equals "--type" instead of relying on
strings.Contains; use the ValidationError fields directly to validate the typed
error behavior.
Sources: Path instructions, Learnings
Summary
Tests
Summary by CodeRabbit
New Features
/sheets/and/spreadsheets/formats.Bug Fixes