fix(drive): support doubao drive inspect URL variants#1106
Conversation
📝 WalkthroughWalkthroughAdds recognition for three Doubao URL path prefixes in ParseResourceURL: ChangesDoubao URL Pattern Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
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)
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 |
e0056c4 to
9d0a97d
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/drive/drive_inspect_test.go (1)
277-351: ⚡ Quick winHarden dry-run assertions and add
/chat/drive/dry-run coverage.The new dry-run tests should assert
len(got.API) == 1before indexinggot.API[0], and add a dry-run case forhttps://feishu.doubao.com/chat/drive/...to keep alias coverage symmetric withValidate.Proposed test updates
func TestDriveInspectDryRun_DoubaoDriveFileURL(t *testing.T) { @@ if err := json.Unmarshal(data, &got); err != nil { t.Fatalf("unmarshal dry run: %v", err) } + if len(got.API) != 1 { + t.Fatalf("expected 1 API step, got %d", len(got.API)) + } reqDocs, ok := got.API[0].Body["request_docs"].([]interface{}) @@ } +func TestDriveInspectDryRun_DoubaoChatDriveFolderURL(t *testing.T) { + cmd := &cobra.Command{Use: "drive +inspect"} + cmd.Flags().String("url", "", "") + cmd.Flags().String("type", "", "") + _ = cmd.Flags().Set("url", "https://feishu.doubao.com/chat/drive/fldcnABC") + + runtime := common.TestNewRuntimeContext(cmd, &core.CliConfig{}) + dry := DriveInspect.DryRun(context.Background(), runtime) + if dry == nil { + t.Fatal("DryRun returned nil") + } + + data, err := json.Marshal(dry) + if err != nil { + t.Fatalf("marshal dry run: %v", err) + } + + var got struct { + API []struct { + Body map[string]interface{} `json:"body"` + } `json:"api"` + } + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("unmarshal dry run: %v", err) + } + if len(got.API) != 1 { + t.Fatalf("expected 1 API step, got %d", len(got.API)) + } + reqDocs, ok := got.API[0].Body["request_docs"].([]interface{}) + if !ok || len(reqDocs) != 1 { + t.Fatalf("expected request_docs with 1 entry, got %v", got.API[0].Body["request_docs"]) + } + doc, _ := reqDocs[0].(map[string]interface{}) + if doc["doc_token"] != "fldcnABC" { + t.Errorf("doc_token = %v, want fldcnABC", doc["doc_token"]) + } + if doc["doc_type"] != "folder" { + t.Errorf("doc_type = %v, want folder", doc["doc_type"]) + } +} + func TestDriveInspectDryRun_DoubaoDriveShareFolderURL(t *testing.T) { @@ if err := json.Unmarshal(data, &got); err != nil { t.Fatalf("unmarshal dry run: %v", err) } + if len(got.API) != 1 { + t.Fatalf("expected 1 API step, got %d", len(got.API)) + } reqDocs, ok := got.API[0].Body["request_docs"].([]interface{})🤖 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_inspect_test.go` around lines 277 - 351, Add a check that the dry-run response contains exactly one API entry before indexing it and add a symmetric dry-run test for the "/chat/drive/" alias: in TestDriveInspectDryRun_DoubaoDriveFileURL and TestDriveInspectDryRun_DoubaoDriveShareFolderURL assert len(got.API) == 1 (or check got.API != nil && len(got.API) == 1) before using got.API[0], and create a new test (e.g., TestDriveInspectDryRun_DoubaoChatDriveFileURL and/or TestDriveInspectDryRun_DoubaoChatDriveShareFolderURL) that calls DriveInspect.DryRun with a url starting with "https://feishu.doubao.com/chat/drive/" and mirrors the existing assertions on request_docs/doc_token/doc_type to ensure alias coverage.
🤖 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/drive/drive_inspect_test.go`:
- Around line 277-351: Add a check that the dry-run response contains exactly
one API entry before indexing it and add a symmetric dry-run test for the
"/chat/drive/" alias: in TestDriveInspectDryRun_DoubaoDriveFileURL and
TestDriveInspectDryRun_DoubaoDriveShareFolderURL assert len(got.API) == 1 (or
check got.API != nil && len(got.API) == 1) before using got.API[0], and create a
new test (e.g., TestDriveInspectDryRun_DoubaoChatDriveFileURL and/or
TestDriveInspectDryRun_DoubaoChatDriveShareFolderURL) that calls
DriveInspect.DryRun with a url starting with
"https://feishu.doubao.com/chat/drive/" and mirrors the existing assertions on
request_docs/doc_token/doc_type to ensure alias coverage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 67d510e3-d715-41e8-abea-bbf0e1c3649f
📒 Files selected for processing (4)
shortcuts/common/resource_url.goshortcuts/common/resource_url_test.goshortcuts/drive/drive_inspect_test.gotests/cli_e2e/drive/drive_inspect_dryrun_test.go
Problem
lark-cli drive +inspectcurrently rejects some valid Doubao Drive URLs during local validation, even though the underlying resource token is valid and the command succeeds when called with a bare token plus--type.This is a URL parsing gap, not a Drive API gap.
/drive/file/{token}/chat/drive/{token}and/drive/shr/{token}Today
ParseResourceURLrecognizes:/file/{token}for files/drive/folder/{token}for foldersbut does not recognize the Doubao path variants above, so
drive +inspect --url ...fails early withunsupported --url.Changes
Add the missing URL aliases to
ParseResourceURL:/drive/file/->file/chat/drive/->folder/drive/shr/->folderCanonical URL generation stays unchanged:
.../file/{token}.../drive/folder/{token}Why this is correct
This matches verified product behavior:
Gj7hbt9viouYCTxoqYRctqebnWbhttps://feishu.doubao.com/drive/file/Gj7hbt9viouYCTxoqYRctqebnWbshould be acceptedGh4oflX5PlxnSjd0FFvcTmcan1Xhttps://feishu.doubao.com/chat/drive/Gh4oflX5PlxnSjd0FFvcTmcan1Xshould be acceptedhttps://feishu.doubao.com/drive/shr/Gh4oflX5PlxnSjd0FFvcTmcan1Xshould be acceptedThe same tokens already work when passed as bare tokens with
--type, so this fix closes the URL parser gap without changing downstream API behavior.Test Plan
go test ./shortcuts/common ./shortcuts/drivego build -o lark-cli .LARK_CLI_BIN=/Users/bytedance/Documents/Codex/2026-05-25/larksuite-cli-1082-https-github-com/lark-cli go test ./tests/cli_e2e/drive -run DriveInspectAdded coverage for:
ParseResourceURLaccepting Doubao file and folder path variantsdrive +inspectvalidation accepting those URLsdrive +inspect --dry-runproducing the expected Drive metadata lookup flow for those URLsSummary by CodeRabbit
New Features
Tests