Skip to content

fix(drive): support doubao drive inspect URL variants#1106

Merged
liangshuo-1 merged 1 commit into
mainfrom
fix/drive-inspect-doubao-url-pattern
May 26, 2026
Merged

fix(drive): support doubao drive inspect URL variants#1106
liangshuo-1 merged 1 commit into
mainfrom
fix/drive-inspect-doubao-url-pattern

Conversation

@fangshuyu-768
Copy link
Copy Markdown
Collaborator

@fangshuyu-768 fangshuyu-768 commented May 26, 2026

Problem

lark-cli drive +inspect currently 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.

  • Doubao file URLs use /drive/file/{token}
  • Doubao folder URLs use /chat/drive/{token} and /drive/shr/{token}

Today ParseResourceURL recognizes:

  • /file/{token} for files
  • /drive/folder/{token} for folders

but does not recognize the Doubao path variants above, so drive +inspect --url ... fails early with unsupported --url.

Changes

Add the missing URL aliases to ParseResourceURL:

  • /drive/file/ -> file
  • /chat/drive/ -> folder
  • /drive/shr/ -> folder

Canonical URL generation stays unchanged:

  • files still resolve to .../file/{token}
  • folders still resolve to .../drive/folder/{token}

Why this is correct

This matches verified product behavior:

  • file token Gj7hbt9viouYCTxoqYRctqebnWb
    • https://feishu.doubao.com/drive/file/Gj7hbt9viouYCTxoqYRctqebnWb should be accepted
  • folder token Gh4oflX5PlxnSjd0FFvcTmcan1X
    • https://feishu.doubao.com/chat/drive/Gh4oflX5PlxnSjd0FFvcTmcan1X should be accepted
    • https://feishu.doubao.com/drive/shr/Gh4oflX5PlxnSjd0FFvcTmcan1X should be accepted

The 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/drive
  • go 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 DriveInspect

Added coverage for:

  • ParseResourceURL accepting Doubao file and folder path variants
  • drive +inspect validation accepting those URLs
  • drive +inspect --dry-run producing the expected Drive metadata lookup flow for those URLs

Summary by CodeRabbit

  • New Features

    • Recognizes additional Doubao drive URL patterns for file links, chat drive folder links, and share folder links.
  • Tests

    • Added unit and end-to-end tests to validate parsing, validation, and dry-run behavior for the new Doubao URL patterns.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

📝 Walkthrough

Walkthrough

Adds recognition for three Doubao URL path prefixes in ParseResourceURL: /drive/file/ → file, /drive/shr/ → folder, and /chat/drive/ → folder; includes unit, DriveInspect integration, dry-run, and E2E tests verifying parsing and plan generation.

Changes

Doubao URL Pattern Support

Layer / File(s) Summary
URL parser extension for Doubao prefixes
shortcuts/common/resource_url.go, shortcuts/common/resource_url_test.go
The urlPathToType mapping gains new entries for /drive/file/file, /drive/shr/folder, and /chat/drive/folder; unit tests verify parsed Type and Token for feishu.doubao.com URLs.
Integration & E2E validation tests
shortcuts/drive/drive_inspect_test.go, tests/cli_e2e/drive/drive_inspect_dryrun_test.go
DriveInspect.Validate and dry-run tests assert the new Doubao URL patterns are accepted. Dry-run and E2E tests inspect generated API plans and assert a single request_docs/batch_query step with expected doc_token and doc_type values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#947: Introduced the base ParseResourceURL parser logic that this PR extends with Doubao-specific path-prefix mappings.

Suggested labels

size/M, domain/ccm

Suggested reviewers

  • wittam-01

Poem

🐰 I found three paths beneath the moonlit tree,
/drive/file/, /chat/drive/, and /drive/shr/ for me.
Tokens plucked like carrots, types set just right,
Tests hop along through day and night.
Hooray — the parser sings with glee! 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for Doubao Drive URL variants in the drive inspect command.
Description check ✅ Passed The PR description is comprehensive and well-structured, matching the template with clear Problem, Changes, Why this is correct, and Test Plan sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 fix/drive-inspect-doubao-url-pattern

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.

@fangshuyu-768 fangshuyu-768 changed the title fix(drive): support doubao inspect URL patterns fix(drive): support doubao drive inspect URL variants May 26, 2026
@fangshuyu-768 fangshuyu-768 force-pushed the fix/drive-inspect-doubao-url-pattern branch from e0056c4 to 9d0a97d Compare May 26, 2026 11:33
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.

🧹 Nitpick comments (1)
shortcuts/drive/drive_inspect_test.go (1)

277-351: ⚡ Quick win

Harden dry-run assertions and add /chat/drive/ dry-run coverage.

The new dry-run tests should assert len(got.API) == 1 before indexing got.API[0], and add a dry-run case for https://feishu.doubao.com/chat/drive/... to keep alias coverage symmetric with Validate.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e0056c4 and 9d0a97d.

📒 Files selected for processing (4)
  • shortcuts/common/resource_url.go
  • shortcuts/common/resource_url_test.go
  • shortcuts/drive/drive_inspect_test.go
  • tests/cli_e2e/drive/drive_inspect_dryrun_test.go

@liangshuo-1 liangshuo-1 merged commit f00261d into main May 26, 2026
2 checks passed
@liangshuo-1 liangshuo-1 deleted the fix/drive-inspect-doubao-url-pattern branch May 26, 2026 11:51
@liangshuo-1 liangshuo-1 mentioned this pull request May 26, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants