Skip to content
Open
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
1 change: 1 addition & 0 deletions .surface
Original file line number Diff line number Diff line change
Expand Up @@ -15002,6 +15002,7 @@ FLAG basecamp reports overdue --markdown type=bool
FLAG basecamp reports overdue --md type=bool
FLAG basecamp reports overdue --no-hints type=bool
FLAG basecamp reports overdue --no-stats type=bool
FLAG basecamp reports overdue --page type=int32
FLAG basecamp reports overdue --profile type=string
FLAG basecamp reports overdue --project type=string
FLAG basecamp reports overdue --quiet type=bool
Expand Down
9 changes: 5 additions & 4 deletions ACCOUNT-WIDE-LISTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ under project rules before the account-wide branch is reached is a defect: the
paginated aggregates accept **any positive page**, while several project-scoped
commands only permit page 1.

Conversely `--page` must return `ErrUsage` against the **unpaginated** overdue
endpoints, which take no page argument at all.
Conversely `--page` must return `ErrUsage` against the overdue listings, which
the CLI reads whole, following every page, so there is no page to address.

### I2 — Scope precedence

Expand Down Expand Up @@ -230,7 +230,7 @@ rows that differ for stated reasons. `--all` is how you ask for the account.
| `checkins answers` | cap 100 | **changed** from "all pages" |
| `forwards list` | cap 100 | **changed** from "all pages" |
| `files list` | cap 100 | **changed** from "all pages" |
| `todos list --overdue` | cap 100 | unpaginated endpoint; accepts `--all`, rejects `--page` |
| `todos list --overdue` | cap 100 | read whole, every page followed; accepts `--all`, rejects `--page` |
| `cards list --overdue` | cap 100 | **changed** from uncapped; same rules as above |
| `bookmarks list` | cap 100 | personal feed — see below |
| `drafts list` | cap 100 | personal feed; server caps the full listing at 250 |
Expand Down Expand Up @@ -259,7 +259,8 @@ options struct does not honor a page number at all, so it takes `--limit` (a
real SDK-side bound) and deliberately registers no `--page`. Under I3 a flag
that cannot act on its value is worse than an absent one.

**The two overdue rows.** Both endpoints are unpaginated, so `--page` has
**The two overdue rows.** The CLI reads both listings whole, following every
page Basecamp sends (50 a page since basecamp/bc3#14537), so `--page` has
nothing to address and stays an error. `--all` is a different question: it means
"skip the cap", and since the complete array is already in hand it costs no
extra request. Previously `todos --overdue` capped at 100 *and* rejected `--all`,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
charm.land/bubbles/v2 v2.2.1
charm.land/bubbletea/v2 v2.1.0
charm.land/lipgloss/v2 v2.0.6
github.com/basecamp/basecamp-sdk/go v0.36.0
github.com/basecamp/basecamp-sdk/go v0.37.1-0.20261120012501-1d0f5e04225d
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9
github.com/basecamp/mcp v0.0.0-20261118214004-663b2e5d2836
github.com/basecamp/surfguard/go v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/basecamp/actioncable-go v1.2.0 h1:t0MxlfMTcmaGXZ5ztgKRs7ZiY1MwXtBRwSSSAh1ofVg=
github.com/basecamp/actioncable-go v1.2.0/go.mod h1:ezaV5z1GXQAsqyejqTs6wCFl2D8Wj+COLQkHc/kwoRs=
github.com/basecamp/basecamp-sdk/go v0.36.0 h1:mkAcJQlh+5Vz64OmpImSda/pfa/usWPJ6gDTuZYVaTI=
github.com/basecamp/basecamp-sdk/go v0.36.0/go.mod h1:ynVJME8mVV3UHMUMnzBgygTnMtadQFxz1iYg7fqwUeM=
github.com/basecamp/basecamp-sdk/go v0.37.1-0.20261120012501-1d0f5e04225d h1:HOnC8h7DRBSlsiaZn1kCRXLYgYdoKZ+gWR0grlXwXXo=
github.com/basecamp/basecamp-sdk/go v0.37.1-0.20261120012501-1d0f5e04225d/go.mod h1:ynVJME8mVV3UHMUMnzBgygTnMtadQFxz1iYg7fqwUeM=
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9 h1:3NfGs+zx23Tp6cf+97+UewrJHlzZMLzmvEXOmOJyQAk=
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9/go.mod h1:iTBTaWvsPEFIcZfkxQHEfISyJ6sZ7036K6bNx0RY3EE=
github.com/basecamp/mcp v0.0.0-20261118214004-663b2e5d2836 h1:ND4te8b+HVFFrgcm7+n8P83MKKPqBpIyoJ63tT9liRU=
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,11 @@ func newAssignmentsCompletedCmd() *cobra.Command {
return err
}

items, err := app.Account().MyAssignments().Completed(cmd.Context())
result, err := app.Account().MyAssignments().Completed(cmd.Context(), 0)
if err != nil {
return convertSDKError(err)
}
items := result.Assignments

return app.OK(items,
output.WithSummary(fmt.Sprintf("%d completed assignment(s)", len(items))),
Expand Down
24 changes: 14 additions & 10 deletions internal/commands/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ func cardsAccountWideSelector(opts cardsListOptions) (selector, flag string, err
}

// runCardsListAccountWide lists cards across every accessible project. The
// paginated aggregates come back grouped by project; --overdue comes back flat
// and unpaginated.
// paginated aggregates come back grouped by project; --overdue comes back flat,
// every page followed.
func runCardsListAccountWide(cmd *cobra.Command, app *appctx.App, opts cardsListOptions, selector string) error {
if err := rejectAccountWideTodolist(app, "card"); err != nil {
return err
Expand Down Expand Up @@ -313,12 +313,12 @@ func runCardsListAccountWide(cmd *cobra.Command, app *appctx.App, opts cardsList
}

if selector == cardsSelectorOverdue {
// --page has nothing to address on an unpaginated endpoint, but --all
// --page has nothing to address on a listing read whole, but --all
// does: the listing is capped by default, and --all is how you reach
// past the cap. Rejecting both would leave card 101 unreachable.
if opts.pageSet {
return output.ErrUsageHint(
"--page is not supported with --overdue (the overdue listing is not paginated)",
"--page is not supported with --overdue (the overdue listing is read whole)",
"Cap the results instead: basecamp cards list --overdue --limit <n>",
)
}
Expand Down Expand Up @@ -432,8 +432,8 @@ func runCardsListAccountWide(cmd *cobra.Command, app *appctx.App, opts cardsList
return app.OK(groups, respOpts...)
}

// runCardsListOverdue lists overdue cards across every project. The endpoint
// returns a flat, oldest-due-first array, so it renders like the
// runCardsListOverdue lists overdue cards across every project. The SDK follows
// every page of a flat, oldest-due-first list, so it renders like the
// project-scoped path and accepts the sort flags.
func runCardsListOverdue(cmd *cobra.Command, app *appctx.App, opts cardsListOptions) error {
if opts.sortField == "position" {
Expand All @@ -450,18 +450,19 @@ func runCardsListOverdue(cmd *cobra.Command, app *appctx.App, opts cardsListOpti
return err
}

cards, err := app.Account().Everything().OverdueCards(cmd.Context(), taskFilters)
result, err := app.Account().Everything().OverdueCards(cmd.Context(), 0, taskFilters)
if err != nil {
return convertSDKError(err)
}
cards := result.Cards

// Sort before truncating: truncating first would sort only the survivors.
if opts.sortField != "" {
sortCards(cards, opts.sortField, opts.reverse)
}

// The endpoint is unpaginated, so the complete array is already in hand and
// --all costs nothing beyond skipping the cap. --limit trims locally.
// The complete list is already in hand, so --all costs nothing beyond
// skipping the cap. --limit trims locally.
total := len(cards)
limit := opts.limit
if limit == 0 {
Expand All @@ -476,7 +477,10 @@ func runCardsListOverdue(cmd *cobra.Command, app *appctx.App, opts cardsListOpti
output.WithBreadcrumbs(cardsAccountWideBreadcrumbs()...),
output.WithDisplayData(flattenOverdueCards(cards)),
}
if len(cards) < total {
switch {
case result.Meta.Truncated:
respOpts = append(respOpts, output.WithNotice("More pages are available; results were truncated"))
case len(cards) < total:
respOpts = append(respOpts, output.WithNotice(fmt.Sprintf(
"Showing the first %d of %d overdue cards (use --all for the complete list, or --limit to raise the cap)",
len(cards), total)))
Expand Down
12 changes: 6 additions & 6 deletions internal/commands/cards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ const cardsGroupsFixture = `[
{"id":22,"title":"Beta two","status":"active","due_on":"2026-03-01"}]}
]`

// cardsOverdueFixture is the flat, unpaginated overdue payload.
// cardsOverdueFixture is the flat overdue payload, on one page.
const cardsOverdueFixture = `[
{"id":31,"title":"Zeta late","status":"active","due_on":"2025-02-01"},
{"id":32,"title":"Alpha late","status":"active","due_on":"2025-01-01"}
Expand Down Expand Up @@ -2800,7 +2800,7 @@ func TestCardsListAccountWideRejectsBadPaging(t *testing.T) {
}

// TestCardsListOverdueRejectsPage tests that --page is refused rather than
// accepted and dropped: there is no page to address on an unpaginated endpoint.
// accepted and dropped: the overdue listing is read whole, every page followed.
func TestCardsListOverdueRejectsPage(t *testing.T) {
app, _ := setupRecordingTestApp(t, cardsAllAggregateRoutes()...)
err := executeRecordingCommand(NewCardsCmd(), app, "list", "--all-projects", "--overdue", "--page", "1")
Expand All @@ -2809,9 +2809,9 @@ func TestCardsListOverdueRejectsPage(t *testing.T) {

// --all is a different question from --page. The overdue listing is capped at
// 100 by default, so rejecting --all as well would leave card 101 unreachable —
// capped with no escape hatch is the defect, not the fix. The endpoint is
// unpaginated, so honoring --all costs nothing: the complete array is already
// in hand.
// capped with no escape hatch is the defect, not the fix. The listing is read
// whole, so honoring --all costs nothing: the complete array is already in
// hand.
func TestCardsListOverdueAcceptsAll(t *testing.T) {
app, transport, buf := setupCardsAccountWideApp(t, output.FormatJSON, cardsAllAggregateRoutes()...)
require.NoError(t, executeRecordingCommand(NewCardsCmd(), app, "list", "--all-projects", "--overdue", "--all"))
Expand All @@ -2824,7 +2824,7 @@ func TestCardsListOverdueAcceptsAll(t *testing.T) {
assert.Len(t, envelope.Data, 2, "--all returns the complete array")
assert.Empty(t, envelope.Notice, "nothing was withheld, so there is nothing to warn about")
assert.Len(t, transport.queriesFor(cardsAggregatePath("overdue")), 1,
"--all costs no extra request on an unpaginated endpoint")
"--all costs no extra request on a listing already read whole")
}

// TestCardsListAccountWideSorting tests that sorting is rejected for the
Expand Down
81 changes: 81 additions & 0 deletions internal/commands/paged_lists_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package commands

import (
"net/http"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/basecamp/basecamp-cli/internal/output"
)

func TestAccountWideListsReadEveryPage(t *testing.T) {
cases := []struct {
name string
cmd func() *cobra.Command
args []string
path string
pages []string
ids func(records any) []any
also []stubRoute
}{
{
name: "overdue todos", cmd: NewTodosCmd, args: []string{"list", "--overdue"},
path: "/99999/todos/overdue.json",
pages: []string{`[{"id":1,"title":"Alpha","due_on":"2020-01-01"}]`, `[{"id":2,"title":"Bravo","due_on":"2020-02-01"}]`},
ids: listIDs,
},
{
name: "overdue cards", cmd: NewCardsCmd, args: []string{"list", "--all-projects", "--overdue"},
path: "/99999/cards/overdue.json",
pages: []string{`[{"id":1,"title":"Alpha","due_on":"2020-01-01"}]`, `[{"id":2,"title":"Bravo","due_on":"2020-02-01"}]`},
ids: listIDs,
},
{
name: "completed assignments", cmd: NewAssignmentsCmd, args: []string{"completed"},
path: "/99999/my/assignments/completed.json",
pages: []string{`[{"id":1,"content":"Alpha"}]`, `[{"id":2,"content":"Bravo"}]`},
ids: listIDs,
},
{
name: "timesheet report", cmd: NewTimesheetCmd, args: []string{"report"},
path: "/99999/reports/timesheet.json",
pages: []string{`[{"id":1,"hours":"1.0"}]`, `[{"id":2,"hours":"2.0"}]`},
ids: listIDs,
},
{
name: "assigned todos", cmd: NewReportsCmd, args: []string{"assigned", "42"},
path: "/99999/reports/todos/assigned/42",
pages: []string{
`{"person":{"id":42,"name":"Ann"},"grouped_by":"","todos":[{"id":1,"title":"Alpha"}]}`,
`{"person":{"id":42,"name":"Ann"},"grouped_by":"","todos":[{"id":2,"title":"Bravo"}]}`,
},
ids: func(report any) []any { return listIDs(report.(map[string]any)["todos"]) },
also: []stubRoute{{method: http.MethodGet, path: "/99999/people.json", status: http.StatusOK,
body: `[{"id":42,"name":"Ann"}]`}},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
listRoute := stubRoute{method: http.MethodGet, path: tc.path, status: http.StatusOK, pages: tc.pages, linked: true}
app, transport, buf := setupAccountWideTodosApp(t, output.FormatJSON, append(tc.also, listRoute)...)

require.NoError(t, executeRecordingCommand(tc.cmd(), app, tc.args...))

assert.Equal(t, []string{"", "page=2"}, transport.queriesFor(tc.path))
assert.Equal(t, []any{float64(1), float64(2)}, tc.ids(decodeTodosEnvelope(t, buf)["data"]))
})
}
}

func listIDs(records any) []any {
list := records.([]any)
ids := make([]any, 0, len(list))
for _, record := range list {
ids = append(ids, record.(map[string]any)["id"])
}
return ids
}
45 changes: 45 additions & 0 deletions internal/commands/recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type stubRoute struct {
// would walk all the way to the cap and hide the behavior under test.
pages []string

// linked, with pages, serves pages the way Basecamp's Link-paged lists do:
// no page number is page 1, and every page but the last names the next in
// a Link rel="next" header, so the SDK follows them.
linked bool

// bodies, when set, serves bodies[i] to the i-th request this route
// matches and repeats the last entry past the end. Routes match on method
// and path alone, so a walk that re-requests one path with a different
Expand All @@ -76,6 +81,39 @@ func pagedBody(route stubRoute, rawPage string) string {
return route.pages[n-1]
}

// linkedPageNumber is the page a request to a linked route asks for, 1 when it
// names none.
func linkedPageNumber(req *http.Request) int {
n, err := strconv.Atoi(req.URL.Query().Get("page"))
if err != nil || n < 1 {
return 1
}
return n
}

// linkedPage serves a linked route's page, or an empty array past its end.
func linkedPage(route stubRoute, req *http.Request) string {
n := linkedPageNumber(req)
if n > len(route.pages) {
return "[]"
}
return route.pages[n-1]
}

// linkedNextPage is the URL of the page after the one requested, or "" on the
// last page.
func linkedNextPage(route stubRoute, req *http.Request) string {
n := linkedPageNumber(req)
if n >= len(route.pages) {
return ""
}
next := *req.URL
query := next.Query()
query.Set("page", strconv.Itoa(n+1))
next.RawQuery = query.Encode()
return next.String()
}

// recordingTransport is an http.RoundTripper that records every request and
// serves canned responses from its route table. Unmatched requests get an
// error response — a wrong route fails the command rather than passing
Expand Down Expand Up @@ -115,10 +153,17 @@ func (t *recordingTransport) RoundTrip(req *http.Request) (*http.Response, error
switch {
case route.bodies != nil:
responseBody = route.bodies[t.nextBody(index, len(route.bodies))]
case route.linked:
responseBody = linkedPage(route, req)
case route.pages != nil:
responseBody = pagedBody(route, req.URL.Query().Get("page"))
}
header := http.Header{"Content-Type": []string{"application/json"}}
if route.linked {
if next := linkedNextPage(route, req); next != "" {
header.Set("Link", fmt.Sprintf(`<%s>; rel="next"`, next))
}
}
for name, values := range route.header {
header[name] = values
}
Expand Down
Loading
Loading