Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions shortcuts/task/task_get_my_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var GetMyTasks = common.Shortcut{

Flags: []common.Flag{
{Name: "query", Desc: "search for tasks by summary (exact match first, then partial match)"},
{Name: "complete", Type: "bool", Desc: "if true, query completed tasks; default is false"},
{Name: "complete", Type: "bool", Desc: "if true, query completed tasks; if false or omitted, query incomplete tasks"},
{Name: "created_at", Desc: "query tasks created after this time (date/relative/ms)"},
{Name: "due-start", Desc: "query tasks with due date after this time (date/relative/ms)"},
{Name: "due-end", Desc: "query tasks with due date before this time (date/relative/ms)"},
Expand All @@ -44,9 +44,7 @@ var GetMyTasks = common.Shortcut{
"type": "my_tasks",
"user_id_type": "open_id",
"page_size": 50,
}
if runtime.Cmd.Flags().Changed("complete") {
params["completed"] = runtime.Bool("complete")
"completed": runtime.Bool("complete"),
}

return d.GET("/open-apis/task/v2/tasks").Params(params)
Expand All @@ -59,13 +57,7 @@ var GetMyTasks = common.Shortcut{
queryParams.Set("type", "my_tasks")
queryParams.Set("user_id_type", "open_id")
queryParams.Set("page_size", "50")
if runtime.Cmd.Flags().Changed("complete") {
if runtime.Bool("complete") {
queryParams.Set("completed", "true")
} else {
queryParams.Set("completed", "false")
}
}
queryParams.Set("completed", strconv.FormatBool(runtime.Bool("complete")))

// parse time flags to ms timestamp if provided
var createdAfterMs, dueStartMs, dueEndMs int64
Expand Down
51 changes: 51 additions & 0 deletions shortcuts/task/task_get_my_tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,54 @@ func TestGetMyTasks_LocalTimeFormatting(t *testing.T) {
})
}
}

func TestGetMyTasks_CompletionFilterDefaultsToIncomplete(t *testing.T) {
tests := []struct {
name string
args []string
wantQueryURL string
}{
{
name: "omitted flag defaults to incomplete",
args: []string{"+get-my-tasks", "--format", "json", "--as", "bot"},
wantQueryURL: "completed=false",
},
{
name: "explicit false remains incomplete",
args: []string{"+get-my-tasks", "--complete=false", "--format", "json", "--as", "bot"},
wantQueryURL: "completed=false",
},
{
name: "explicit true requests completed tasks",
args: []string{"+get-my-tasks", "--complete=true", "--format", "json", "--as", "bot"},
wantQueryURL: "completed=true",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, stdout, _, reg := taskShortcutTestFactory(t)
warmTenantToken(t, f, reg)

Comment on lines +118 to +120

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether task test factory helper follows required test setup conventions.

# 1) Locate helper definition and inspect nearby lines.
rg -n -C4 'func\s+taskShortcutTestFactory\s*\('

# 2) Check usage of required factory constructor.
rg -n -C3 'cmdutil\.TestFactory\s*\('

# 3) Check test config isolation via temp config dir env var.
rg -n -C3 'LARKSUITE_CLI_CONFIG_DIR'

Repository: larksuite/cli

Length of output: 50370


🏁 Script executed:

#!/bin/bash
# Search for taskTestConfig definition and nearby code
rg -n -B2 -A10 'func\s+taskTestConfig\s*\('

Repository: larksuite/cli

Length of output: 926


🏁 Script executed:

#!/bin/bash
# Check other test config functions
rg -n -B1 -A8 'func\s+(driveTestConfig|mailTestConfig|defaultConfig)\s*\(' shortcuts/

# Also check the internal registry test pattern mentioned in learnings
rg -n -B2 -A8 'func\s+ensureFreshRegistry\s*\('

Repository: larksuite/cli

Length of output: 3307


🏁 Script executed:

#!/bin/bash
# Search for ensureFreshRegistry in internal/registry
rg -n -B2 -A10 'ensureFreshRegistry' internal/registry/

Repository: larksuite/cli

Length of output: 39


🏁 Script executed:

#!/bin/bash
# Search for the pattern in internal/registry/registry_test.go
rg -n -A10 'LARKSUITE_CLI_CONFIG_DIR' internal/registry/

Repository: larksuite/cli

Length of output: 5165


🏁 Script executed:

#!/bin/bash
# Check the actual test function at lines 118-120 in task_get_my_tasks_test.go
rg -n -B10 -A5 'taskShortcutTestFactory' shortcuts/task/task_get_my_tasks_test.go | head -40

Repository: larksuite/cli

Length of output: 1005


Add config state isolation to test setup helper.

The taskShortcutTestFactory helper correctly uses cmdutil.TestFactory(t, config), satisfying the first guideline. However, taskTestConfig(t) does not isolate config state per coding guidelines. Add t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) to the helper to prevent machine-local cache interference, following the pattern established in internal/registry/remote_test.go.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/task/task_get_my_tasks_test.go` around lines 118 - 120, The test
helper doesn't isolate CLI config state causing machine-local cache
interference; modify taskTestConfig (used by taskShortcutTestFactory) to set a
dedicated temp config dir for each test by calling
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) so config state is isolated,
ensuring taskShortcutTestFactory and any callers (e.g.,
task_get_my_tasks_test.go helpers) use cmdutil.TestFactory(t, config) with the
per-test env override.

reg.Register(&httpmock.Stub{
Method: "GET",
URL: tt.wantQueryURL,
Body: map[string]interface{}{
"code": 0, "msg": "success",
"data": map[string]interface{}{
"items": []interface{}{},
"has_more": false,
"page_token": "",
},
},
})

s := GetMyTasks
s.AuthTypes = []string{"bot", "user"}

if err := runMountedTaskShortcut(t, s, tt.args, f, stdout); err != nil {
t.Fatalf("expected no error, got %v", err)
}
})
}
}
2 changes: 1 addition & 1 deletion skills/lark-task/references/lark-task-get-my-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lark-cli task +get-my-tasks --page-limit 10
| Parameter | Required | Description |
|-----------|----------|-------------|
| `--query <string>` | No | Search for tasks by summary. Returns exact matches if any; otherwise returns partial matches. |
| `--complete=<bool>` | No | Optional. If not provided, it fetches all tasks (both incomplete and completed). Set to `true` to fetch only completed tasks, or `false` for incomplete tasks. |
| `--complete=<bool>` | No | Optional. If omitted, it defaults to incomplete tasks (`false`). Set to `true` to fetch only completed tasks, or `false` for incomplete tasks. |
| `--created_at <string>` | No | Query tasks created after this time. Supports date: `YYYY-MM-DD`, relative: `-2d`, or ms timestamp. |
| `--due-start <string>` | No | Query tasks with a due date after this time. Supports date: `YYYY-MM-DD`, relative: `-2d`, or ms timestamp. |
| `--due-end <string>` | No | Query tasks with a due date before this time. Supports date: `YYYY-MM-DD`, relative: `-2d`, or ms timestamp. |
Expand Down
Loading