Skip to content

Commit 0f5e414

Browse files
authored
Add todolists position to reorder to-do lists (#484) (#562)
* Add `todolists position` to reorder to-do lists (#484) Adds `basecamp todolists position <id|url>...` to reorder a to-do list within its todoset — the one repositioning gap in the to-do family (`todos` and `todolistgroups` already had it). Single-list mode sets one explicit position (`--to N`, 1-based). Bulk mode accepts several incomplete lists from the same todoset and sets their visible order top-to-bottom; it is restricted to position 1 because reverse-iterating onto any other slot cannot reconstruct the typed order once loose to-dos or hidden completed lists shift the base. Bulk preflight enforces a shared todoset/bucket and rejects completed lists before issuing any PUT, and application stops at the first failure (a half-applied reorder is a wrong order), reporting applied-vs-attempted. Uses the dedicated `PUT /todosets/todolists/{id}/position.json` route, not the generic `/recordings/{id}/position.json` the issue's workaround used — the generic one skips the to-do-list position math and mis-places lists when loose to-dos or hidden completed lists exist. Naming follows the to-do family (`position`, aliases `move`/`reorder`, `--to` leading with `--position` accepted); a to-do list has no destination container, so `--to N` is unambiguously an index. SDK bumped to 93ace8d5 (basecamp-sdk#398), which also absorbs #396 (Templates.CreateProject envelope fix, signature unchanged) and #392 (SDK tests only). Closes #484 * Preserve error classification on partial reposition failure The bulk-apply failure path reclassified every non-*output.Error (raw transport/runtime failures, context cancellation) as code=usage via ErrUsageHint, overwrote the SDK's structured hint with the rerun hint, and claimed the todoset was left in an intermediate order even when the failing PUT was the first/only one and nothing had been mutated. Now: when zero PUTs have landed (always true in single-list mode, and when a bulk run's first PUT fails), surface the underlying error unchanged — its code, HTTP status, and hint intact, no false intermediate-order claim. Only once a partial reorder has actually landed does it add the applied-count accounting and rerun hint, and even then it preserves the underlying error's classification (appending the rerun text to the original hint rather than replacing it) and wraps raw errors with %w instead of reclassifying them as usage. Adds regression coverage for Code/HTTPStatus preservation, original-hint preservation, and the zero-applied single-list and bulk-first-PUT paths. * Reject wrong-type URL args to todolists position A pasted Basecamp URL for a different recording type (a todo, a card, or a todolists *collection* URL) still yields a trailing numeric ID via ExtractIDs, which — because this command mutates — would silently reposition an unrelated todolist that happens to share that ID. Validate any URL argument up front: it must be a non-collection `todolists` URL, mirroring the guard todos position already applies to its --list destination URL. Bare numeric IDs are unaffected. * Warn of partial reorder when a transport failure interrupts a bulk run The raw-error branch of the partial-failure path wrapped the cause with %w and the applied-count prefix, but dropped the recovery hint entirely. After one successful PUT followed by a transport failure (a dropped connection, a canceled context), the operator saw the count but was never told the todoset was left partially reordered and needs a rerun. Return a non-usage structured error that carries the applied-count message, the rerun/intermediate-order hint, and the raw cause (via Cause, so errors.Is/As still unwrap). Code is api_error, never usage. Adds a regression test that drops the connection on the second applied PUT and asserts the non-usage code, the accounting message, the rerun hint, the preserved cause, and that the third list is never touched. * Reconcile SDK pin references and surface after rebase onto e2c1abea Rebasing onto main (#554) advanced the SDK pin to e2c1abea, five commits past the 93ace8d5 this branch first pinned. Refresh the API-COVERAGE SDK line to the merged pin (which additionally carries create-time visible_to_clients support) and regenerate the CLI surface so it reflects both todolists position and main's todolists create --visible-to-clients.
1 parent 9a243c3 commit 0f5e414

9 files changed

Lines changed: 1195 additions & 6 deletions

File tree

‎.surface‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ ARG basecamp tlgroups update 00 <id>
308308
ARG basecamp tlgroups update 01 <name>
309309
ARG basecamp todolist archive 00 <id|url>
310310
ARG basecamp todolist create 00 <name>
311+
ARG basecamp todolist move 00 <id|url>...
312+
ARG basecamp todolist position 00 <id|url>...
313+
ARG basecamp todolist reorder 00 <id|url>...
311314
ARG basecamp todolist restore 00 <id|url>
312315
ARG basecamp todolist show 00 <id|url>
313316
ARG basecamp todolist trash 00 <id|url>
@@ -330,6 +333,9 @@ ARG basecamp todolistgroups update 00 <id>
330333
ARG basecamp todolistgroups update 01 <name>
331334
ARG basecamp todolists archive 00 <id|url>
332335
ARG basecamp todolists create 00 <name>
336+
ARG basecamp todolists move 00 <id|url>...
337+
ARG basecamp todolists position 00 <id|url>...
338+
ARG basecamp todolists reorder 00 <id|url>...
333339
ARG basecamp todolists restore 00 <id|url>
334340
ARG basecamp todolists show 00 <id|url>
335341
ARG basecamp todolists trash 00 <id|url>
@@ -896,6 +902,9 @@ CMD basecamp todolist
896902
CMD basecamp todolist archive
897903
CMD basecamp todolist create
898904
CMD basecamp todolist list
905+
CMD basecamp todolist move
906+
CMD basecamp todolist position
907+
CMD basecamp todolist reorder
899908
CMD basecamp todolist restore
900909
CMD basecamp todolist show
901910
CMD basecamp todolist trash
@@ -920,6 +929,9 @@ CMD basecamp todolists
920929
CMD basecamp todolists archive
921930
CMD basecamp todolists create
922931
CMD basecamp todolists list
932+
CMD basecamp todolists move
933+
CMD basecamp todolists position
934+
CMD basecamp todolists reorder
923935
CMD basecamp todolists restore
924936
CMD basecamp todolists show
925937
CMD basecamp todolists trash
@@ -12482,6 +12494,75 @@ FLAG basecamp todolist list --styled type=bool
1248212494
FLAG basecamp todolist list --todolist type=string
1248312495
FLAG basecamp todolist list --todoset type=string
1248412496
FLAG basecamp todolist list --verbose type=count
12497+
FLAG basecamp todolist move --account type=string
12498+
FLAG basecamp todolist move --agent type=bool
12499+
FLAG basecamp todolist move --cache-dir type=string
12500+
FLAG basecamp todolist move --count type=bool
12501+
FLAG basecamp todolist move --help type=bool
12502+
FLAG basecamp todolist move --hints type=bool
12503+
FLAG basecamp todolist move --ids-only type=bool
12504+
FLAG basecamp todolist move --in type=string
12505+
FLAG basecamp todolist move --jq type=string
12506+
FLAG basecamp todolist move --json type=bool
12507+
FLAG basecamp todolist move --markdown type=bool
12508+
FLAG basecamp todolist move --md type=bool
12509+
FLAG basecamp todolist move --no-hints type=bool
12510+
FLAG basecamp todolist move --no-stats type=bool
12511+
FLAG basecamp todolist move --position type=int
12512+
FLAG basecamp todolist move --profile type=string
12513+
FLAG basecamp todolist move --project type=string
12514+
FLAG basecamp todolist move --quiet type=bool
12515+
FLAG basecamp todolist move --stats type=bool
12516+
FLAG basecamp todolist move --styled type=bool
12517+
FLAG basecamp todolist move --to type=int
12518+
FLAG basecamp todolist move --todolist type=string
12519+
FLAG basecamp todolist move --verbose type=count
12520+
FLAG basecamp todolist position --account type=string
12521+
FLAG basecamp todolist position --agent type=bool
12522+
FLAG basecamp todolist position --cache-dir type=string
12523+
FLAG basecamp todolist position --count type=bool
12524+
FLAG basecamp todolist position --help type=bool
12525+
FLAG basecamp todolist position --hints type=bool
12526+
FLAG basecamp todolist position --ids-only type=bool
12527+
FLAG basecamp todolist position --in type=string
12528+
FLAG basecamp todolist position --jq type=string
12529+
FLAG basecamp todolist position --json type=bool
12530+
FLAG basecamp todolist position --markdown type=bool
12531+
FLAG basecamp todolist position --md type=bool
12532+
FLAG basecamp todolist position --no-hints type=bool
12533+
FLAG basecamp todolist position --no-stats type=bool
12534+
FLAG basecamp todolist position --position type=int
12535+
FLAG basecamp todolist position --profile type=string
12536+
FLAG basecamp todolist position --project type=string
12537+
FLAG basecamp todolist position --quiet type=bool
12538+
FLAG basecamp todolist position --stats type=bool
12539+
FLAG basecamp todolist position --styled type=bool
12540+
FLAG basecamp todolist position --to type=int
12541+
FLAG basecamp todolist position --todolist type=string
12542+
FLAG basecamp todolist position --verbose type=count
12543+
FLAG basecamp todolist reorder --account type=string
12544+
FLAG basecamp todolist reorder --agent type=bool
12545+
FLAG basecamp todolist reorder --cache-dir type=string
12546+
FLAG basecamp todolist reorder --count type=bool
12547+
FLAG basecamp todolist reorder --help type=bool
12548+
FLAG basecamp todolist reorder --hints type=bool
12549+
FLAG basecamp todolist reorder --ids-only type=bool
12550+
FLAG basecamp todolist reorder --in type=string
12551+
FLAG basecamp todolist reorder --jq type=string
12552+
FLAG basecamp todolist reorder --json type=bool
12553+
FLAG basecamp todolist reorder --markdown type=bool
12554+
FLAG basecamp todolist reorder --md type=bool
12555+
FLAG basecamp todolist reorder --no-hints type=bool
12556+
FLAG basecamp todolist reorder --no-stats type=bool
12557+
FLAG basecamp todolist reorder --position type=int
12558+
FLAG basecamp todolist reorder --profile type=string
12559+
FLAG basecamp todolist reorder --project type=string
12560+
FLAG basecamp todolist reorder --quiet type=bool
12561+
FLAG basecamp todolist reorder --stats type=bool
12562+
FLAG basecamp todolist reorder --styled type=bool
12563+
FLAG basecamp todolist reorder --to type=int
12564+
FLAG basecamp todolist reorder --todolist type=string
12565+
FLAG basecamp todolist reorder --verbose type=count
1248512566
FLAG basecamp todolist restore --account type=string
1248612567
FLAG basecamp todolist restore --agent type=bool
1248712568
FLAG basecamp todolist restore --cache-dir type=string
@@ -13025,6 +13106,75 @@ FLAG basecamp todolists list --styled type=bool
1302513106
FLAG basecamp todolists list --todolist type=string
1302613107
FLAG basecamp todolists list --todoset type=string
1302713108
FLAG basecamp todolists list --verbose type=count
13109+
FLAG basecamp todolists move --account type=string
13110+
FLAG basecamp todolists move --agent type=bool
13111+
FLAG basecamp todolists move --cache-dir type=string
13112+
FLAG basecamp todolists move --count type=bool
13113+
FLAG basecamp todolists move --help type=bool
13114+
FLAG basecamp todolists move --hints type=bool
13115+
FLAG basecamp todolists move --ids-only type=bool
13116+
FLAG basecamp todolists move --in type=string
13117+
FLAG basecamp todolists move --jq type=string
13118+
FLAG basecamp todolists move --json type=bool
13119+
FLAG basecamp todolists move --markdown type=bool
13120+
FLAG basecamp todolists move --md type=bool
13121+
FLAG basecamp todolists move --no-hints type=bool
13122+
FLAG basecamp todolists move --no-stats type=bool
13123+
FLAG basecamp todolists move --position type=int
13124+
FLAG basecamp todolists move --profile type=string
13125+
FLAG basecamp todolists move --project type=string
13126+
FLAG basecamp todolists move --quiet type=bool
13127+
FLAG basecamp todolists move --stats type=bool
13128+
FLAG basecamp todolists move --styled type=bool
13129+
FLAG basecamp todolists move --to type=int
13130+
FLAG basecamp todolists move --todolist type=string
13131+
FLAG basecamp todolists move --verbose type=count
13132+
FLAG basecamp todolists position --account type=string
13133+
FLAG basecamp todolists position --agent type=bool
13134+
FLAG basecamp todolists position --cache-dir type=string
13135+
FLAG basecamp todolists position --count type=bool
13136+
FLAG basecamp todolists position --help type=bool
13137+
FLAG basecamp todolists position --hints type=bool
13138+
FLAG basecamp todolists position --ids-only type=bool
13139+
FLAG basecamp todolists position --in type=string
13140+
FLAG basecamp todolists position --jq type=string
13141+
FLAG basecamp todolists position --json type=bool
13142+
FLAG basecamp todolists position --markdown type=bool
13143+
FLAG basecamp todolists position --md type=bool
13144+
FLAG basecamp todolists position --no-hints type=bool
13145+
FLAG basecamp todolists position --no-stats type=bool
13146+
FLAG basecamp todolists position --position type=int
13147+
FLAG basecamp todolists position --profile type=string
13148+
FLAG basecamp todolists position --project type=string
13149+
FLAG basecamp todolists position --quiet type=bool
13150+
FLAG basecamp todolists position --stats type=bool
13151+
FLAG basecamp todolists position --styled type=bool
13152+
FLAG basecamp todolists position --to type=int
13153+
FLAG basecamp todolists position --todolist type=string
13154+
FLAG basecamp todolists position --verbose type=count
13155+
FLAG basecamp todolists reorder --account type=string
13156+
FLAG basecamp todolists reorder --agent type=bool
13157+
FLAG basecamp todolists reorder --cache-dir type=string
13158+
FLAG basecamp todolists reorder --count type=bool
13159+
FLAG basecamp todolists reorder --help type=bool
13160+
FLAG basecamp todolists reorder --hints type=bool
13161+
FLAG basecamp todolists reorder --ids-only type=bool
13162+
FLAG basecamp todolists reorder --in type=string
13163+
FLAG basecamp todolists reorder --jq type=string
13164+
FLAG basecamp todolists reorder --json type=bool
13165+
FLAG basecamp todolists reorder --markdown type=bool
13166+
FLAG basecamp todolists reorder --md type=bool
13167+
FLAG basecamp todolists reorder --no-hints type=bool
13168+
FLAG basecamp todolists reorder --no-stats type=bool
13169+
FLAG basecamp todolists reorder --position type=int
13170+
FLAG basecamp todolists reorder --profile type=string
13171+
FLAG basecamp todolists reorder --project type=string
13172+
FLAG basecamp todolists reorder --quiet type=bool
13173+
FLAG basecamp todolists reorder --stats type=bool
13174+
FLAG basecamp todolists reorder --styled type=bool
13175+
FLAG basecamp todolists reorder --to type=int
13176+
FLAG basecamp todolists reorder --todolist type=string
13177+
FLAG basecamp todolists reorder --verbose type=count
1302813178
FLAG basecamp todolists restore --account type=string
1302913179
FLAG basecamp todolists restore --agent type=bool
1303013180
FLAG basecamp todolists restore --cache-dir type=string
@@ -16545,6 +16695,9 @@ SUB basecamp todolist
1654516695
SUB basecamp todolist archive
1654616696
SUB basecamp todolist create
1654716697
SUB basecamp todolist list
16698+
SUB basecamp todolist move
16699+
SUB basecamp todolist position
16700+
SUB basecamp todolist reorder
1654816701
SUB basecamp todolist restore
1654916702
SUB basecamp todolist show
1655016703
SUB basecamp todolist trash
@@ -16569,6 +16722,9 @@ SUB basecamp todolists
1656916722
SUB basecamp todolists archive
1657016723
SUB basecamp todolists create
1657116724
SUB basecamp todolists list
16725+
SUB basecamp todolists move
16726+
SUB basecamp todolists position
16727+
SUB basecamp todolists reorder
1657216728
SUB basecamp todolists restore
1657316729
SUB basecamp todolists show
1657416730
SUB basecamp todolists trash

‎API-COVERAGE.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ Coverage of Basecamp 3 API endpoints. Source: [bc3-api/sections](https://github.
66

77
| Status | Sections | Endpoints |
88
|--------|----------|-----------|
9-
| ✅ Implemented | 43 | 162 |
9+
| ✅ Implemented | 43 | 163 |
1010
| ⏭️ Out of scope | 4 | 12 |
11-
| **Total (docs)** | **47** | **174** |
11+
| **Total (docs)** | **47** | **175** |
1212

13-
**100% coverage of in-scope API** (162/162 endpoints)
13+
**100% coverage of in-scope API** (163/163 endpoints)
1414

1515
Out-of-scope sections are excluded from parity totals and scripts: chatbots (different auth), legacy Clientside (deprecated)
1616

1717
> Note: the per-row `Endpoints` column in the Coverage by Section table sums higher than the Summary totals above. The discrepancy predates the BC5 baseline; the row count (47 sections) is authoritative for the `Since` column. Reconciling endpoint counts is pre-existing maintenance, tracked separately.
1818
19-
**SDK version:** v0.8.0 — adds `Campfires.UpdateLine` (`PUT /chats/{c}/lines/{l}`, basecamp/basecamp-sdk#295), consumed by `chat update`; also carries the BC5 `Tools.Create` create-by-type reshape. API date advanced to 2026-07-22.
19+
**SDK version:** v0.8.1-0.20260724184307-e2c1abea4aea — adds `Todolists.Reposition` (`PUT /todosets/todolists/{id}/position.json`, basecamp/basecamp-sdk#398), consumed by `todolists position`; also carries the create-time `visible_to_clients` support behind `todolists create --visible-to-clients`, `Campfires.UpdateLine` (`PUT /chats/{c}/lines/{l}`, basecamp/basecamp-sdk#295), consumed by `chat update`, and the BC5 `Tools.Create` create-by-type reshape. API date 2026-07-24.
2020

2121
## Coverage by Section
2222

@@ -27,7 +27,7 @@ The **Since** column tags each row with the Basecamp version that introduced its
2727
| **Core** |
2828
| projects | 9 | `projects` | ✅ | BC4 | - | list, show, create, update, delete |
2929
| todos | 11 | `todos`, `todo`, `done`, `reopen` | ✅ | BC4 | - | list, show, create, update, complete, uncomplete, position (BC5: `steps` shown on `todos show`; edit via `cards step`) |
30-
| todolists | 8 | `todolists` | ✅ | BC4 | - | list, show, create, update |
30+
| todolists | 9 | `todolists` | ✅ | BC4 | - | list, show, create, update, position |
3131
| todosets | 3 | `todosets` | ✅ | BC4 | - | Container for todolists, accessed via project dock (BC5: `todos_count`, `completed_loose_todos_count`, `todos_url`, `app_todos_url`) |
3232
| todolist_groups | 8 | `todolistgroups` | ✅ | BC4 | - | list, show, create, update, position |
3333
| dock_tools | 7 | `tools` | ✅ | BC4 | - | Dock tool management: show, update, trash, enable, disable, reposition. `create` is BC5-only (create-by-type: `POST /buckets/{id}/dock/tools.json`), replacing the removed clone call |

‎e2e/errors.bats‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,44 @@ load test_helper
348348
assert_output_contains "required"
349349
}
350350

351+
@test "todolists position without id shows error" {
352+
create_credentials
353+
create_global_config '{"account_id": 99999, "project_id": 123}'
354+
355+
run basecamp todolists position --to 1
356+
assert_failure
357+
assert_json_value '.error' '<id|url>... required'
358+
assert_json_value '.code' 'usage'
359+
}
360+
361+
@test "todolists position without --to shows error" {
362+
create_credentials
363+
create_global_config '{"account_id": 99999, "project_id": 123}'
364+
365+
run basecamp todolists position 123
366+
assert_failure
367+
assert_output_contains "required"
368+
}
369+
370+
@test "todolists position multiple ids with --to 2 shows error" {
371+
create_credentials
372+
create_global_config '{"account_id": 99999, "project_id": 123}'
373+
374+
run basecamp todolists position 123 456 --to 2
375+
assert_failure
376+
assert_output_contains "position 1"
377+
}
378+
379+
@test "todolists position with only a comma shows error" {
380+
create_credentials
381+
create_global_config '{"account_id": 99999, "project_id": 123}'
382+
383+
run basecamp todolists position ","
384+
assert_failure
385+
assert_json_value '.error' '<id|url>... required'
386+
assert_json_value '.code' 'usage'
387+
}
388+
351389
@test "comments without subcommand shows help" {
352390
create_credentials
353391
create_global_config '{"account_id": 99999, "project_id": 123}'

‎e2e/smoke/smoke_aliases.bats‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ load smoke_helper
223223
mark_out_of_scope "Alias for todos position — tested via canonical form"
224224
}
225225

226+
# --- todolists ---
227+
228+
@test "todolists move is out of scope" {
229+
mark_out_of_scope "Alias for todolists position — tested via canonical form"
230+
}
231+
232+
@test "todolists reorder is out of scope" {
233+
mark_out_of_scope "Alias for todolists position — tested via canonical form"
234+
}
235+
226236
# --- todolistgroups ---
227237

228238
@test "todolistgroups move is out of scope" {

‎e2e/smoke/smoke_todos_write.bats‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ setup_file() {
237237
echo "$tl_id" > "$BATS_FILE_TMPDIR/todolist_target_id"
238238
}
239239

240+
@test "todolists position repositions a todolist" {
241+
local id_file="$BATS_FILE_TMPDIR/todolist_target_id"
242+
[[ -f "$id_file" ]] || mark_unverifiable "No todolist created in prior test"
243+
local tl_id
244+
tl_id=$(<"$id_file")
245+
246+
# Runs before archive/trash so the target list is still active.
247+
run_smoke basecamp todolists position "$tl_id" --to 1 -p "$QA_PROJECT" --json
248+
assert_success
249+
assert_json_value '.ok' 'true'
250+
}
251+
240252
@test "todolists archive archives a todolist" {
241253
local id_file="$BATS_FILE_TMPDIR/todolist_target_id"
242254
[[ -f "$id_file" ]] || mark_unverifiable "No todolist created in prior test"

‎internal/commands/commands.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func CommandCategories() []CommandCategory {
3636
Commands: []CommandInfo{
3737
{Name: "projects", Category: "core", Description: "Manage projects", Actions: []string{"list", "show", "create", "update", "delete"}},
3838
{Name: "todos", Category: "core", Description: "Manage to-dos", Actions: []string{"list", "show", "create", "update", "complete", "uncomplete", "position", "trash", "archive", "restore"}},
39-
{Name: "todolists", Category: "core", Description: "Manage to-do lists", Actions: []string{"list", "show", "create", "update", "trash", "archive", "restore"}},
39+
{Name: "todolists", Category: "core", Description: "Manage to-do lists", Actions: []string{"list", "show", "create", "update", "position", "trash", "archive", "restore"}},
4040
{Name: "todosets", Category: "core", Description: "Manage to-do set containers", Actions: []string{"list", "show"}},
4141
{Name: "hillcharts", Category: "core", Description: "Manage hill charts", Actions: []string{"show", "track", "untrack"}},
4242
{Name: "gauges", Category: "core", Description: "Manage gauges", Actions: []string{"list", "needles", "needle", "create", "update", "delete", "enable", "disable"}},

0 commit comments

Comments
 (0)