Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(cli): stop issue list misreporting its page (#7896)

Firerf11121c6136d
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.md
index a0c787e38e..b4e2cd4a2c 100644
--- a/CLI_AND_DAEMON.md
+++ b/CLI_AND_DAEMON.md
@@ -508,12 +508,16 @@ multica issue list --output json --fields=id,title,status,priority # narrow the
multica issue list --output json --resolve-properties # property names beside the ids
```
-Table output shows a routable issue `KEY` such as `MUL-123`; copy that key into follow-up commands like `issue get`, `issue comment list`, `issue status`, or `--parent`. Add `--full-id` when you need canonical UUIDs. Available filters: `--status`, `--priority`, `--assignee` / `--assignee-id`, `--project`, `--metadata`, `--property`, `--limit`. Use `--assignee-id <uuid>` for unambiguous filtering when names overlap.
+Table output shows a routable issue `KEY` such as `MUL-123`; copy that key into follow-up commands like `issue get`, `issue comment list`, `issue status`, or `--parent`. Add `--full-id` when you need canonical UUIDs. Available filters: `--status`, `--priority`, `--assignee` / `--assignee-id`, `--project`, `--metadata`, `--property`, plus `--limit` and `--offset` for paging. Use `--assignee-id <uuid>` for unambiguous filtering when names overlap.
`--fields` (JSON output only) whitelists which top-level issue keys come back — pass a comma-separated list such as `--fields=id,title,status,priority`. Omit it for the full issue object, unchanged from before this flag existed. Filtering happens client-side after the CLI fetches the full response, so this shrinks CLI output size and agent context cost — not network transfer or server-side work. Field names are the real API keys, not table-display labels — assignee is `assignee_type`/`assignee_id` rather than a single `assignee` field. An unknown name is rejected up front with the valid list rather than silently dropped. Has no effect on `--output table`.
Results come back in board order (`position`, ascending) by default. Pass `--sort` to change the column (`position`, `title`, `created_at`, `start_date`, `due_date`, `priority`, or `property:<name-or-id>` for a custom property — select properties order by option order, and issues without the property sort last) and `--direction asc|desc` to flip the order. `position` is always ascending (it is the manual drag order), so `--direction` is rejected when `--sort` is `position` or omitted — use it only with `title`, `created_at`, `start_date`, `due_date`, `priority`, or a `property:` sort.
+One call returns one page. `--limit` is the page size, 1 to 100 (the server returns at most 100 issues per request), and `--offset` is how many issues to skip. A limit outside 1 to 100 or a negative offset is rejected rather than quietly clamped. In table mode a line on stderr says when you are looking at a page of a larger set (`Showing 1-50 of 2706 issues. Next page: --offset 50`). It prints whenever the JSON `has_more` described below would be true or `--offset` is above zero, and stays silent otherwise. The `of N` is dropped when the server's count cannot be trusted (`Showing issues 1-100. Next page: --offset 100`), for the reasons below.
+
+With `--output json` the envelope carries `total`, `limit`, `offset` and `has_more`. `limit` and `offset` echo the request, so `limit` holds steady across a walk and `offset` is the one you passed. The number of issues in this page is `issues | length`, and that is what to advance `--offset` by: it equals `limit` on a full page and stays right on any page that comes back shorter. An empty page always reports `has_more: false`. `total` cannot end a walk on its own: when the server's count query fails it reports the size of the page it just returned, and a newer backend may drop the field. So a full page reports `has_more: true` whenever `total` is missing or no larger than the page itself. That rule means a list that fills exactly one page costs one extra request that comes back empty; the alternative is a walk that ends one page in whenever the count is unhealthy. To walk a whole list, sort by `created_at` (`--sort created_at --direction asc`): the default `position` order is re-ranked by board drags and status changes, so pages can shift under a walk. Sorting by `created_at` keeps them still, but no offset walk is a consistent snapshot while others are writing.
+
Use `--metadata key=value` (repeatable; combined with AND) to filter by per-issue metadata. The value is JSON-parsed: `true`/`false` become bool, numbers become numbers, anything else is a string. Wrap as `'"42"'` to force a string when the value would otherwise sniff as a number:
```bash
diff --git a/server/cmd/multica/cmd_issue.go b/server/cmd/multica/cmd_issue.go
index da2e81719d..085167ee1e 100644
--- a/server/cmd/multica/cmd_issue.go
+++ b/server/cmd/multica/cmd_issue.go
@@ -397,6 +397,10 @@ var validIssuePriorities = []string{
"urgent", "high", "medium", "low", "none",
}
+// issueListMaxPageSize mirrors the page clamp in the server's ListIssues
+// handler; the two must move together.
+const issueListMaxPageSize = 100
+
// validIssueSortColumns are the sort keys `issue list --sort` accepts. They
// mirror the server's ListIssues handler. "position" is the default and is
// always sorted ascending (the board's manual drag order), so --direction is
@@ -512,8 +516,8 @@ func init() {
issueListCmd.Flags().String("project", "", "Filter by project ID")
issueListCmd.Flags().StringSlice("metadata", nil, "Filter by metadata key=value (repeatable; combined with AND). Value is JSON-parsed: 'true'/'false' → bool, numbers → number, otherwise string. Wrap as '\"42\"' to force a string when the value would otherwise sniff as a number.")
issueListCmd.Flags().StringArray("property", nil, `Filter by custom property, written as "Name=Value" (repeatable, one value per flag). Name is a property name (case-insensitive) or its UUID. Value depends on the type: an option name or id for select and multi_select, true or false for checkbox, a member name, email, or id for actor types, and the value itself for text, url, number, and date (YYYY-MM-DD). Use __none__ to match issues where the property is unset; it works for every type, so an option or member actually named __none__ has to be given by id, as does a property whose name contains "=" or ends in <, > or ! (the >=, <=, and != spellings are reserved for comparison filters). Repeating a property matches ANY of its values; different properties must ALL match.`)
- issueListCmd.Flags().Int("limit", 50, "Maximum number of issues to return in one page (the server caps a page at 100; use --offset to page through more)")
- issueListCmd.Flags().Int("offset", 0, "Number of issues to skip (for pagination)")
+ issueListCmd.Flags().Int("limit", 50, fmt.Sprintf("Page size, 1 to %d (the server returns at most %d issues per request; use --offset to page through more)", issueListMaxPageSize, issueListMaxPageSize))
+ issueListCmd.Flags().Int("offset", 0, "Number of issues to skip (for pagination; while --output json reports has_more, advance it by the number of issues in that same response)")
issueListCmd.Flags().String("sort", "", "Sort column: position (default, manual board order), title, created_at, start_date, due_date, priority, or property:<name-or-id> to sort by a custom property (select properties sort by option order)")
issueListCmd.Flags().String("direction", "", "Sort direction (asc or desc); requires --sort to be a non-position column or a property sort (position is always ascending)")
issueListCmd.Flags().String("fields", "", "JSON output only: comma-separated list of issue fields to include (e.g. id,title,status,priority). Filtering happens client-side after the full response is fetched, so this shrinks CLI output size and agent context cost, not network/server-side cost. Omit for the full issue object (default, unchanged). Valid fields: "+strings.Join(validIssueFields, ", "))
@@ -665,6 +669,19 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
}
}
+ // The server clamps limit and applies its own default when the flag is
+ // missing, so reject a value it cannot honour up front (before any
+ // request) rather than report a page that was never returned. Same
+ // reasoning as the --direction guard below.
+ limit, _ := cmd.Flags().GetInt("limit")
+ if limit < 1 || limit > issueListMaxPageSize {
+ return fmt.Errorf("--limit must be between 1 and %d (the server returns at most %d issues per request); use --offset to page through more", issueListMaxPageSize, issueListMaxPageSize)
+ }
+ offset, _ := cmd.Flags().GetInt("offset")
+ if offset < 0 {
+ return fmt.Errorf("--offset must be zero or greater")
+ }
+
params := url.Values{}
params.Set("workspace_id", client.WorkspaceID)
if v, _ := cmd.Flags().GetString("status"); v != "" {
@@ -673,8 +690,9 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
if v, _ := cmd.Flags().GetString("priority"); v != "" {
params.Set("priority", v)
}
- if v, _ := cmd.Flags().GetInt("limit"); v > 0 {
- params.Set("limit", fmt.Sprintf("%d", v))
+ params.Set("limit", fmt.Sprintf("%d", limit))
+ if offset > 0 {
+ params.Set("offset", fmt.Sprintf("%d", offset))
}
_, aID, hasAssignee, resolveErr := pickAssigneeFromFlags(ctx, client, cmd, "assignee", "assignee-id", issueAssigneeKinds)
if resolveErr != nil {
@@ -683,9 +701,6 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
if hasAssignee {
params.Set("assignee_id", aID)
}
- if v, _ := cmd.Flags().GetInt("offset"); v > 0 {
- params.Set("offset", fmt.Sprintf("%d", v))
- }
if v, _ := cmd.Flags().GetString("project"); v != "" {
project, err := resolveProjectID(ctx, client, v)
if err != nil {
@@ -800,6 +815,26 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
}
issuesRaw, _ := result["issues"].([]any)
+ total, totalOK := result["total"].(float64)
+ returned := len(issuesRaw)
+ // total cannot end a walk on its own. The server answers with the row
+ // count it just returned when its count query fails, and a newer backend
+ // may drop the field; either one reports has_more false beside a full page
+ // and truncates the walk in silence. So total is trusted only when it is
+ // larger than this page, which a failed count never is; otherwise the page
+ // decides. The one cost is a first page that fills exactly: it cannot tell
+ // a genuine total from a failed count, so it probes onward and the next
+ // request comes back empty.
+ totalTrusted := totalOK && int(total) > returned
+ hasMore := false
+ switch {
+ case returned == 0:
+ // An empty page ends a walk whatever total says.
+ case totalTrusted:
+ hasMore = offset+returned < int(total)
+ default:
+ hasMore = returned == limit
+ }
output, _ := cmd.Flags().GetString("output")
if output == "json" {
@@ -815,10 +850,6 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
return err
}
}
- total, _ := result["total"].(float64)
- limit, _ := cmd.Flags().GetInt("limit")
- offset, _ := cmd.Flags().GetInt("offset")
- hasMore := offset+len(issuesRaw) < int(total)
wrapped := map[string]any{
"issues": issuesRaw,
"total": int(total),
@@ -874,6 +905,27 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
rows = append(rows, row)
}
cli.PrintTable(os.Stdout, headers, rows)
+ // Page footer on stderr so stdout stays a plain table. It speaks whenever
+ // there is more or the page was offset, and stays silent for a short
+ // first page. "of N" appears only while total is trusted, so the line
+ // never claims a page is the whole list beside a pointer to the next one.
+ switch {
+ case returned == 0 && offset > 0:
+ if totalTrusted {
+ fmt.Fprintf(os.Stderr, "No issues at --offset %d (%d total).\n", offset, int(total))
+ } else {
+ fmt.Fprintf(os.Stderr, "No issues at --offset %d.\n", offset)
+ }
+ case hasMore || offset > 0:
+ line := fmt.Sprintf("Showing issues %d-%d.", offset+1, offset+returned)
+ if totalTrusted {
+ line = fmt.Sprintf("Showing %d-%d of %d issues.", offset+1, offset+returned, int(total))
+ }
+ if hasMore {
+ line += fmt.Sprintf(" Next page: --offset %d", offset+returned)
+ }
+ fmt.Fprintln(os.Stderr, line)
+ }
return nil
}
@@ -1865,10 +1917,10 @@ func fetchIssue(ctx context.Context, client *cli.APIClient, id string) (map[stri
// fetchIssueColumn returns every issue in a status column ordered by position
// ascending, paginating through the list endpoint so columns larger than one
-// page (the server caps a page at 100) still produce a complete, correctly
-// ordered set. A non-empty projectID scopes the column to that project,
-// matching a project board; an empty projectID lists the whole workspace
-// column.
+// page (the server caps a page at issueListMaxPageSize) still produce a
+// complete, correctly ordered set. A non-empty projectID scopes the column to
+// that project, matching a project board; an empty projectID lists the whole
+// workspace column.
func fetchIssueColumn(ctx context.Context, client *cli.APIClient, workspaceID, projectID, status string) ([]map[string]any, error) {
var all []map[string]any
offset := 0
@@ -1880,7 +1932,7 @@ func fetchIssueColumn(ctx context.Context, client *cli.APIClient, workspaceID, p
params.Set("project_id", projectID)
}
params.Set("sort", "position")
- params.Set("limit", "100")
+ params.Set("limit", fmt.Sprintf("%d", issueListMaxPageSize))
params.Set("offset", fmt.Sprintf("%d", offset))
var result map[string]any
diff --git a/server/cmd/multica/cmd_issue_test.go b/server/cmd/multica/cmd_issue_test.go
index 6cee266f9d..11153f2fee 100644
--- a/server/cmd/multica/cmd_issue_test.go
+++ b/server/cmd/multica/cmd_issue_test.go
@@ -4405,3 +4405,310 @@ func TestRunIssueRunsWarnsOnTruncatedFamilyRead(t *testing.T) {
})
}
}
+
+// fakeIssueRows builds n minimal issue rows for a fake /api/issues response.
+func fakeIssueRows(n int) []map[string]any {
+ rows := make([]map[string]any, 0, n)
+ for i := 0; i < n; i++ {
+ rows = append(rows, map[string]any{
+ "id": fmt.Sprintf("issue-%d", i+1),
+ "identifier": fmt.Sprintf("MUL-%d", i+1),
+ "title": fmt.Sprintf("Issue %d", i+1),
+ "status": "todo",
+ "priority": "none",
+ })
+ }
+ return rows
+}
+
+// newFakeIssueListServer serves /api/issues with the given rows and total
+// (nil omits the field); other paths get an empty object. It returns the
+// /api/issues request count and the last request's query.
+func newFakeIssueListServer(t *testing.T, rows []map[string]any, total any) (*httptest.Server, *int, *url.Values) {
+ t.Helper()
+ var (
+ requests int
+ query url.Values
+ )
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/api/issues" {
+ _, _ = w.Write([]byte(`{}`))
+ return
+ }
+ requests++
+ query = r.URL.Query()
+ body := map[string]any{"issues": rows}
+ if total != nil {
+ body["total"] = total
+ }
+ _ = json.NewEncoder(w).Encode(body)
+ }))
+ t.Cleanup(srv.Close)
+ return srv, &requests, &query
+}
+
+// TestRunIssueListRejectsOutOfRangeLimitAndOffset guards that --limit outside
+// 1..100 and a negative --offset are rejected before any request is made. The
+// --assignee case pins that the guard runs before the assignee resolver.
+func TestRunIssueListRejectsOutOfRangeLimitAndOffset(t *testing.T) {
+ srv, requests, _ := newFakeIssueListServer(t, nil, 0)
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cases := []struct {
+ name string
+ flag string
+ value string
+ assignee string
+ wantErr string
+ }{
+ {name: "limit zero", flag: "limit", value: "0", wantErr: "--limit must be between 1 and 100"},
+ {name: "limit negative", flag: "limit", value: "-5", wantErr: "--limit must be between 1 and 100"},
+ {name: "limit above the page cap", flag: "limit", value: "101", wantErr: "--limit must be between 1 and 100"},
+ {name: "limit checked before assignee resolution", flag: "limit", value: "500", assignee: "someone", wantErr: "--limit must be between 1 and 100"},
+ {name: "offset negative", flag: "offset", value: "-1", wantErr: "--offset must be zero or greater"},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set(tc.flag, tc.value)
+ if tc.assignee != "" {
+ _ = cmd.Flags().Set("assignee", tc.assignee)
+ }
+ err := runIssueList(cmd, nil)
+ if err == nil {
+ t.Fatalf("runIssueList: expected error for --%s %s", tc.flag, tc.value)
+ }
+ if !strings.Contains(err.Error(), tc.wantErr) {
+ t.Fatalf("error = %q, want it to contain %q", err, tc.wantErr)
+ }
+ if *requests != 0 {
+ t.Fatalf("server received %d request(s); a rejected flag must not reach the API", *requests)
+ }
+ })
+ }
+}
+
+// TestRunIssueListSendsLimitAndOffset guards that limit and offset reach the
+// query as given.
+func TestRunIssueListSendsLimitAndOffset(t *testing.T) {
+ srv, _, query := newFakeIssueListServer(t, nil, 0)
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+ if err := runIssueList(cmd, nil); err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+ if got := query.Get("limit"); got != "50" {
+ t.Fatalf("default limit query = %q, want 50", got)
+ }
+ if query.Has("offset") {
+ t.Fatalf("offset query = %q, want it omitted at the default of 0", query.Get("offset"))
+ }
+
+ cmd = newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+ _ = cmd.Flags().Set("limit", "100")
+ _ = cmd.Flags().Set("offset", "200")
+ if err := runIssueList(cmd, nil); err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+ if got := query.Get("limit"); got != "100" {
+ t.Fatalf("limit query = %q, want 100", got)
+ }
+ if got := query.Get("offset"); got != "200" {
+ t.Fatalf("offset query = %q, want 200", got)
+ }
+}
+
+// TestRunIssueListJSONEnvelopeReportsPage guards the --output json paging
+// contract: limit and offset echo the request on every page, has_more is
+// false on an empty page and true on a full one whatever total says, and
+// nothing is written to stderr.
+func TestRunIssueListJSONEnvelopeReportsPage(t *testing.T) {
+ cases := []struct {
+ name string
+ limit string
+ offset string
+ rows int
+ total any
+ wantTotal float64
+ wantLimit float64
+ wantHasMore bool
+ }{
+ {name: "full page", limit: "100", offset: "0", rows: 100, total: 145, wantTotal: 145, wantLimit: 100, wantHasMore: true},
+ {name: "last partial page", limit: "100", offset: "100", rows: 45, total: 145, wantTotal: 145, wantLimit: 100, wantHasMore: false},
+ {name: "server applied a smaller page than requested", limit: "100", offset: "0", rows: 20, total: 145, wantTotal: 145, wantLimit: 100, wantHasMore: true},
+ {name: "empty page past the end", limit: "100", offset: "500", rows: 0, total: 145, wantTotal: 145, wantLimit: 100, wantHasMore: false},
+ {name: "empty page while total still claims more", limit: "100", offset: "100", rows: 0, total: 145, wantTotal: 145, wantLimit: 100, wantHasMore: false},
+ {name: "total missing from the response", limit: "100", offset: "0", rows: 3, total: nil, wantTotal: 0, wantLimit: 100, wantHasMore: false},
+ {name: "full page ending exactly on a later page boundary", limit: "100", offset: "100", rows: 100, total: 200, wantTotal: 200, wantLimit: 100, wantHasMore: false},
+ // total cannot end a walk on its own: the server answers with the row
+ // count it just returned when its count query fails, and a newer
+ // backend may drop the field. A total no larger than the page is one
+ // of those, so a full page carries the walk on and a short one ends it.
+ {name: "full page while total equals the page at a later offset", limit: "10", offset: "20", rows: 10, total: 10, wantTotal: 10, wantLimit: 10, wantHasMore: true},
+ {name: "full page while total undercounts the page", limit: "10", offset: "20", rows: 10, total: 5, wantTotal: 5, wantLimit: 10, wantHasMore: true},
+ {name: "full page with total missing", limit: "10", offset: "0", rows: 10, total: nil, wantTotal: 0, wantLimit: 10, wantHasMore: true},
+ // On the first page a failed count is indistinguishable from a genuine
+ // single-page total, so a full first page probes onward; a short one
+ // still ends the walk.
+ {name: "full first page while total equals the page", limit: "100", offset: "0", rows: 100, total: 100, wantTotal: 100, wantLimit: 100, wantHasMore: true},
+ {name: "short first page while total equals the page", limit: "100", offset: "0", rows: 45, total: 45, wantTotal: 45, wantLimit: 100, wantHasMore: false},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ srv, _, _ := newFakeIssueListServer(t, fakeIssueRows(tc.rows), tc.total)
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ stderr := captureStderr(t)
+ defer stderr.restore()
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+ _ = cmd.Flags().Set("limit", tc.limit)
+ _ = cmd.Flags().Set("offset", tc.offset)
+ out, err := captureStdout(t, func() error { return runIssueList(cmd, nil) })
+ if err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+
+ var env map[string]any
+ if err := json.Unmarshal([]byte(out), &env); err != nil {
+ t.Fatalf("decode envelope: %v\n%s", err, out)
+ }
+ if issues, _ := env["issues"].([]any); len(issues) != tc.rows {
+ t.Errorf("issues = %d rows, want %d", len(issues), tc.rows)
+ }
+ if got := env["limit"]; got != tc.wantLimit {
+ t.Errorf("limit = %v, want %v", got, tc.wantLimit)
+ }
+ wantOffset, _ := strconv.ParseFloat(tc.offset, 64)
+ if got := env["offset"]; got != wantOffset {
+ t.Errorf("offset = %v, want %v", got, wantOffset)
+ }
+ if got := env["total"]; got != tc.wantTotal {
+ t.Errorf("total = %v, want %v", got, tc.wantTotal)
+ }
+ if got := env["has_more"]; got != tc.wantHasMore {
+ t.Errorf("has_more = %v, want %v", got, tc.wantHasMore)
+ }
+ if got := stderr.read(); got != "" {
+ t.Errorf("stderr = %q, want nothing in JSON mode", got)
+ }
+ })
+ }
+}
+
+// TestRunIssueListJSONEnvelopePagingSurvivesFieldFiltering pins that --fields
+// cannot move the paging numbers. Both write into the same JSON branch, and
+// --fields deletes keys inside each issue rather than dropping issues, so the
+// envelope must still describe the page the server sent.
+func TestRunIssueListJSONEnvelopePagingSurvivesFieldFiltering(t *testing.T) {
+ srv, _, _ := newFakeIssueListServer(t, fakeIssueRows(10), 145)
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+ _ = cmd.Flags().Set("limit", "10")
+ _ = cmd.Flags().Set("fields", "id,title")
+ out, err := captureStdout(t, func() error { return runIssueList(cmd, nil) })
+ if err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+
+ var env map[string]any
+ if err := json.Unmarshal([]byte(out), &env); err != nil {
+ t.Fatalf("decode envelope: %v\n%s", err, out)
+ }
+ if got := env["limit"]; got != float64(10) {
+ t.Errorf("limit = %v, want 10", got)
+ }
+ if got := env["total"]; got != float64(145) {
+ t.Errorf("total = %v, want 145", got)
+ }
+ if got := env["has_more"]; got != true {
+ t.Errorf("has_more = %v, want true", got)
+ }
+ issues, _ := env["issues"].([]any)
+ if len(issues) != 10 {
+ t.Fatalf("issues = %d rows, want 10", len(issues))
+ }
+ // The filter still ran, so the envelope numbers are not just an unfiltered
+ // page slipping through.
+ first, _ := issues[0].(map[string]any)
+ if _, ok := first["status"]; ok {
+ t.Error("issue kept status, want --fields to have dropped it")
+ }
+ if first["id"] != "issue-1" {
+ t.Errorf("issue id = %v, want issue-1", first["id"])
+ }
+}
+
+// TestRunIssueListTableFooterReportsPage guards the table-mode page footer:
+// on stderr, stdout stays a plain table, silent for a short first page.
+func TestRunIssueListTableFooterReportsPage(t *testing.T) {
+ cases := []struct {
+ name string
+ limit string
+ offset string
+ rows int
+ total any
+ wantStderr string
+ }{
+ {name: "first page of many", limit: "3", offset: "0", rows: 3, total: 145, wantStderr: "Showing 1-3 of 145 issues. Next page: --offset 3"},
+ {name: "middle page", limit: "3", offset: "50", rows: 3, total: 145, wantStderr: "Showing 51-53 of 145 issues. Next page: --offset 53"},
+ {name: "server applied a smaller page than requested", limit: "50", offset: "0", rows: 20, total: 145, wantStderr: "Showing 1-20 of 145 issues. Next page: --offset 20"},
+ {name: "last page", limit: "5", offset: "140", rows: 5, total: 145, wantStderr: "Showing 141-145 of 145 issues."},
+ {name: "everything fits", limit: "50", offset: "0", rows: 3, total: 3, wantStderr: ""},
+ {name: "no results", limit: "50", offset: "0", rows: 0, total: 0, wantStderr: ""},
+ {name: "empty page past the end", limit: "50", offset: "500", rows: 0, total: 145, wantStderr: "No issues at --offset 500 (145 total)."},
+ {name: "empty page exactly at the end", limit: "50", offset: "3", rows: 0, total: 3, wantStderr: "No issues at --offset 3 (3 total)."},
+ // Without a trusted total the footer still points at the next page,
+ // but never claims an "of N" it cannot stand behind.
+ {name: "full page with total missing", limit: "3", offset: "50", rows: 3, total: nil, wantStderr: "Showing issues 51-53. Next page: --offset 53"},
+ {name: "full page while total undercounts the walk", limit: "3", offset: "50", rows: 3, total: 3, wantStderr: "Showing issues 51-53. Next page: --offset 53"},
+ {name: "full first page while total equals the page", limit: "3", offset: "0", rows: 3, total: 3, wantStderr: "Showing issues 1-3. Next page: --offset 3"},
+ {name: "last page with total missing", limit: "50", offset: "100", rows: 45, total: nil, wantStderr: "Showing issues 101-145."},
+ {name: "empty page while the count failed", limit: "50", offset: "50", rows: 0, total: 0, wantStderr: "No issues at --offset 50."},
+ {name: "total missing on an empty page", limit: "50", offset: "50", rows: 0, total: nil, wantStderr: "No issues at --offset 50."},
+ {name: "total not a number on an empty page", limit: "50", offset: "50", rows: 0, total: "145", wantStderr: "No issues at --offset 50."},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ srv, _, _ := newFakeIssueListServer(t, fakeIssueRows(tc.rows), tc.total)
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ stderr := captureStderr(t)
+ defer stderr.restore()
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("limit", tc.limit)
+ _ = cmd.Flags().Set("offset", tc.offset)
+ out, err := captureStdout(t, func() error { return runIssueList(cmd, nil) })
+ if err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+
+ if !strings.HasPrefix(out, "KEY") {
+ t.Errorf("stdout should start with the table header, got %q", out)
+ }
+ if strings.Contains(out, "Showing") || strings.Contains(out, "No issues at") {
+ t.Errorf("stdout must stay a plain table, got %q", out)
+ }
+ if got := strings.TrimSpace(stderr.read()); got != tc.wantStderr {
+ t.Errorf("stderr = %q, want %q", got, tc.wantStderr)
+ }
+ })
+ }
+}