feat(common): backfill resource URL when create APIs omit it#680
feat(common): backfill resource URL when create APIs omit it#680fangshuyu-768 merged 1 commit intomainfrom
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:
📝 WalkthroughWalkthroughAdds an exported BuildResourceURL helper and uses it across shortcuts (docs, sheets, drive, wiki) to populate output URL fields from tokens when backend responses omit tenant-provided links; includes unit and integration tests validating fallback and preservation behavior. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI Shortcut
participant API as Backend API
participant Builder as BuildResourceURL
CLI->>API: Create resource (doc/sheet/folder/wiki/upload/import)
API-->>CLI: Response { token, url? }
alt url present and non-empty
CLI->>CLI: Preserve API-provided url in output
else url missing or blank
CLI->>Builder: BuildResourceURL(brand, kind, token)
Builder-->>CLI: url (or "")
alt url returned
CLI->>CLI: Emit derived url in output envelope
else no url
CLI->>CLI: Leave url unset
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 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 #680 +/- ##
==========================================
+ Coverage 63.04% 63.25% +0.21%
==========================================
Files 437 492 +55
Lines 38847 42305 +3458
==========================================
+ Hits 24491 26761 +2270
- Misses 12184 13210 +1026
- Partials 2172 2334 +162 ☔ 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@6a1c4003d8377707d9c77a9fdc5519b08f73f96e🧩 Skill updatenpx skills add larksuite/cli#feat/url -y -g |
fangshuyu-768
left a comment
There was a problem hiding this comment.
Nice helper and clean fallback strategy — the create paths definitely benefit from a stable url field. A few inline comments below; one is a real inconsistency with how the rest of the repo parses legacy doc URLs, and the others are about hardening the contract and shoring up test coverage.
02d1c88 to
3fa4cbc
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/drive/drive_create_folder.go`:
- Around line 95-99: The current check uses common.GetString(data, "url") != ""
which treats whitespace-only strings as non-empty; change the logic where url is
assigned (variable url in the block using common.GetString and
common.BuildResourceURL) to treat whitespace-only values as empty by trimming
whitespace (e.g., use strings.TrimSpace on the result of common.GetString)
before deciding to set out["url"], and fall back to
common.BuildResourceURL(runtime.Config.Brand, "folder", folderToken) when the
trimmed url is empty.
In `@shortcuts/drive/drive_import.go`:
- Around line 122-127: The code currently checks status.URL != "" which treats
whitespace-only URLs as present and prevents fallback; update the check to trim
whitespace first (e.g., use strings.TrimSpace) and only use status.URL when the
trimmed value is non-empty, otherwise fall back to building the resource URL
from status.Token via common.BuildResourceURL (reference symbols: status.URL,
status.Token, common.BuildResourceURL, normalizeDriveImportKindForURL,
resultType, spec.DocType, out map).
🪄 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: 43ca52ae-817a-44a5-b94b-f99805a0b9af
⛔ Files ignored due to path filters (1)
span.logis excluded by!**/*.log
📒 Files selected for processing (15)
shortcuts/common/resource_url.goshortcuts/common/resource_url_test.goshortcuts/doc/docs_create.goshortcuts/doc/docs_create_test.goshortcuts/doc/docs_create_v2.goshortcuts/drive/drive_create_folder.goshortcuts/drive/drive_create_folder_test.goshortcuts/drive/drive_import.goshortcuts/drive/drive_import_test.goshortcuts/drive/drive_io_test.goshortcuts/drive/drive_upload.goshortcuts/sheets/sheet_create.goshortcuts/sheets/sheet_create_test.goshortcuts/wiki/wiki_node_create.goshortcuts/wiki/wiki_node_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 (9)
- shortcuts/wiki/wiki_node_create.go
- shortcuts/drive/drive_upload.go
- shortcuts/doc/docs_create_v2.go
- shortcuts/drive/drive_create_folder_test.go
- shortcuts/drive/drive_io_test.go
- shortcuts/sheets/sheet_create_test.go
- shortcuts/doc/docs_create_test.go
- shortcuts/common/resource_url.go
- shortcuts/drive/drive_import_test.go
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/drive/drive_import_test.go`:
- Around line 400-406: The tests always use driveImportTestConfig which
hardcodes BrandFeishu, so they never hit BuildResourceURL's larksuite.com
branch; update or add a variant of driveImportTestConfig to accept/return
core.BrandLark (or core.BrandLarkSuite) and modify the four tests
(TestDriveImportFallbackURLWhenBackendOmitsIt,
TestDriveImportPreservesBackendURL,
TestDriveImportFallbackURLWhenServerURLIsWhitespace,
TestDriveImportFallbackURLWhenServerTypeIsAlias) to run each assertion for both
brands (Feishu and Lark) so BuildResourceURL is exercised for the larksuite.com
path. Ensure you pass the brand through runtime.Config (as production code does)
when invoking the code under test so assertions expect larksuite.com for the
Lark brand.
In `@shortcuts/sheets/sheet_create.go`:
- Around line 113-116: The stored URL is not trimmed before being written to
out, so whitespace-padded backend URLs slip through; update the branch that
reads spreadsheet["url"] to trim the value into a local (e.g., trimmedURL :=
strings.TrimSpace(url)) then check trimmedURL != "" and set out["url"] =
trimmedURL; keep the existing fallback to
common.BuildResourceURL(runtime.Config.Brand, "sheet", token) only when the
trimmed value is empty.
🪄 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: 9c9f5f4d-386b-4b8f-87bf-a2a976346613
⛔ Files ignored due to path filters (1)
span.logis excluded by!**/*.log
📒 Files selected for processing (15)
shortcuts/common/resource_url.goshortcuts/common/resource_url_test.goshortcuts/doc/docs_create.goshortcuts/doc/docs_create_test.goshortcuts/doc/docs_create_v2.goshortcuts/drive/drive_create_folder.goshortcuts/drive/drive_create_folder_test.goshortcuts/drive/drive_import.goshortcuts/drive/drive_import_test.goshortcuts/drive/drive_io_test.goshortcuts/drive/drive_upload.goshortcuts/sheets/sheet_create.goshortcuts/sheets/sheet_create_test.goshortcuts/wiki/wiki_node_create.goshortcuts/wiki/wiki_node_create_test.go
✅ Files skipped from review due to trivial changes (3)
- shortcuts/wiki/wiki_node_create_test.go
- shortcuts/drive/drive_io_test.go
- shortcuts/common/resource_url.go
🚧 Files skipped from review as they are similar to previous changes (3)
- shortcuts/wiki/wiki_node_create.go
- shortcuts/drive/drive_import.go
- shortcuts/common/resource_url_test.go
Add BuildResourceURL helper and wire it into doc/sheets/drive/base/wiki create paths so callers always receive a clickable link, even when the backend response (MCP degraded path or upstream OpenAPI) returns an empty URL field. The fallback uses the brand-standard host (www.feishu.cn / www.larksuite.com), which redirects to the tenant domain. Affected entries: - docs +create v1 / v2 - sheets +create - drive +create-folder / +import / +upload (newly exposes url) - wiki +node-create (newly exposes url) drive +create-shortcut is intentionally skipped because the URL form depends on the underlying file kind, which the shortcut payload does not carry.
Summary
common.BuildResourceURL(brand, kind, token)helper that returns brand-standard URLs (www.feishu.cn/www.larksuite.com) for known resource kinds (docx/doc/sheet/wiki/file/folder). The standard host transparently redirects to the tenant domain.urlfield even when the backend response omits one — e.g. degraded MCP responses whereExtractMCPResultcollapsesmulti-content into a plain string, the drive upload API which never returns a URL, or wiki node create which only returns tokens.
urlwhen the backend value is empty, so tenant-specific URLs returned by the API are preserved.Affected entries
docs +create --api-version v1doc_urlfalls back to/docx/<doc_id>when MCP omits itdocs +create --api-version v2data.document.urlfalls back to/docx/<document_id>sheets +createout.urlfalls back to/sheets/<token>(also fixes a pre-existing bug where missing url produced a literalnullfield)drive +create-folder/drive/folder/<token>drive +import/<docx|sheets|base>/<token>based on resolvedresultTypedrive +uploadurl, only whenparent_type=explorer(wiki-hosted files have no standalone URL)wiki +node-createurl=/wiki/<node_token>drive +create-shortcutis intentionally not covered: shortcut URL form depends on the underlying file kind, which the create payload does not carry — better to omit than to guess wrong.Test plan
go test ./shortcuts/common/ ./shortcuts/doc/ ./shortcuts/sheets/ ./shortcuts/drive/ ./shortcuts/wiki/— all greenBuildResourceURLhelper has 16 table-driven cases covering brand/kind/token edge caseswiki_node_create_test.goextended to assert the newurlfield on outputSummary by CodeRabbit
New Features
Bug Fixes
Tests