mirror of
https://github.com/larksuite/cli.git
synced 2026-07-07 17:45:15 +08:00
Wrap the POST /drive/v1/permissions/:token/members/apply endpoint as a user-only shortcut. --token accepts either a bare token or a document URL, with type auto-inferred from the URL path (/docx/, /sheets/, /base/, /bitable/, /file/, /wiki/, /doc/, /mindnote/, /minutes/, /slides/); an explicit --type always wins. --perm is limited to view or edit; full_access is rejected client-side to match the spec. Classifier gains two domain-specific hints for the endpoint's newly documented error codes: 1063006 (per-user-per-document quota of 5/day reached) and 1063007 (document does not accept apply requests — covers disallow-external-apply, already-has-access, and unsupported-type). test(drive): add dry-run E2E for +apply-permission Invoke the real CLI binary via clie2e.RunCmd under --dry-run and parse the rendered request JSON with gjson to lock in method, URL path (including the token segment), type query parameter (auto-inferred for docx / sheet / slides URLs, taken from explicit --type for bare tokens), perm body field, and remark presence/omission. A separate test asserts --perm full_access is rejected by the enum validator before reaching the server. Fake LARKSUITE_CLI_APP_ID / APP_SECRET / BRAND are enough because dry-run short-circuits before any API call. Update drive coverage.md to add a row and refresh metrics. test(drive): isolate E2E dry-run subprocess from local CLI config Set LARKSUITE_CLI_CONFIG_DIR to t.TempDir() in both +apply-permission dry-run tests so the subprocess can't read a developer's real credentials/profile instead of the fake env vars the tests inject. test(drive): add E2E case that exercises URL inference override Previous "bare token with explicit type wins over inference" row used a bare token, which has no URL-derived type to override. Replace it with a /docx/ URL + --type wiki combo that actually forces the explicit flag to win over URL inference, and add a separate bare-token row to keep the simpler path covered. Refresh coverage.md wording to match.
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package output
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestClassifyLarkError_DriveCreateShortcutConstraints verifies known Drive shortcut errors map to actionable hints.
|
|
func TestClassifyLarkError_DriveCreateShortcutConstraints(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
code int
|
|
wantExitCode int
|
|
wantType string
|
|
wantHint string
|
|
}{
|
|
{
|
|
name: "resource contention",
|
|
code: LarkErrDriveResourceContention,
|
|
wantExitCode: ExitAPI,
|
|
wantType: "conflict",
|
|
wantHint: "avoid concurrent duplicate requests",
|
|
},
|
|
{
|
|
name: "cross tenant unit",
|
|
code: LarkErrDriveCrossTenantUnit,
|
|
wantExitCode: ExitAPI,
|
|
wantType: "cross_tenant_unit",
|
|
wantHint: "same tenant and region/unit",
|
|
},
|
|
{
|
|
name: "cross brand",
|
|
code: LarkErrDriveCrossBrand,
|
|
wantExitCode: ExitAPI,
|
|
wantType: "cross_brand",
|
|
wantHint: "same brand environment",
|
|
},
|
|
{
|
|
name: "sheets float image invalid dims",
|
|
code: LarkErrSheetsFloatImageInvalidDims,
|
|
wantExitCode: ExitAPI,
|
|
wantType: "invalid_params",
|
|
wantHint: "--width / --height / --offset-x / --offset-y",
|
|
},
|
|
{
|
|
name: "drive permission apply rate limit",
|
|
code: LarkErrDrivePermApplyRateLimit,
|
|
wantExitCode: ExitAPI,
|
|
wantType: "rate_limit",
|
|
wantHint: "5 times per day",
|
|
},
|
|
{
|
|
name: "drive permission apply not applicable",
|
|
code: LarkErrDrivePermApplyNotApplicable,
|
|
wantExitCode: ExitAPI,
|
|
wantType: "invalid_params",
|
|
wantHint: "does not accept a permission-apply request",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
gotExitCode, gotType, gotHint := ClassifyLarkError(tt.code, "raw msg")
|
|
if gotExitCode != tt.wantExitCode {
|
|
t.Fatalf("exitCode=%d, want %d", gotExitCode, tt.wantExitCode)
|
|
}
|
|
if gotType != tt.wantType {
|
|
t.Fatalf("type=%q, want %q", gotType, tt.wantType)
|
|
}
|
|
if gotHint == "" {
|
|
t.Fatal("expected non-empty hint")
|
|
}
|
|
if !strings.Contains(gotHint, tt.wantHint) {
|
|
t.Fatalf("hint=%q, want substring %q", gotHint, tt.wantHint)
|
|
}
|
|
})
|
|
}
|
|
}
|