Todos Update/Edit/Replace: merge-safe writes across all 6 SDKs

Merged
JE
5mo ago
+4580-617

πŸ€– Drafted with agent assistance; submitted by @jeremy.

Closes #372.

What

Every SDK's Todos.Update presented a typed partial-update surface but transmitted a sparse PUT to an endpoint whose contract is full replace, omission clears β€” silently wiping description, dates, and subscribers (two production data-loss incidents; ~80 lines of CLI workaround). This PR replaces that with a three-method, two-state surface in all six languages:

  • update β€” merge-safe: GET β†’ overlay explicitly-set fields β†’ full-representation PUT. An omitted field is untouched, guaranteed; an explicitly-passed empty collection still clears.
  • edit β€” read-modify-write closure over the full writable state (TodoFields), the primary API. Clear = set empty; a closure error aborts before the PUT. Python's form is a context manager with .result.
  • replace β€” the wire operation, verbatim: sparse PUT, no GET, omission clears, content required.

Spec and route

  • UpdateTodo β†’ ReplaceTodo in place (same flat URI), content @required, new @basecampWriteSemantics(mode: "replace", clearsOmitted: true) trait surfaced as x-basecamp-write-semantics and a write clause in behavior-model.json.
  • The canonical flat route stays β€” no bucket-scoped switch. #372's original bucket-route criterion was amended (see the issue): BC3's API tests prove the flat route persists description when content is present, and the maintainer disposition on #259 labels the bucket route legacy. #259 closed separately as misdiagnosed.

Hook contract

update/edit compose the public get + replace, so hooks observe the wire operations under each SDK's native identities (conceptually one GetTodo + one ReplaceTodo) β€” never a synthetic composite. Retry/idempotency policy stays keyed to the wire operation; the mutation is always observable/gateable as a replace. Documented in SPEC.md Β§5 and tested per language.

Full-state serialization (update/edit)

Content, description, and both ID lists are always sent (empties included, so clears survive); dates only when non-empty (the server clears an omitted date, and "" is a format error); notify only when true (send directive, never populated from GET). Go splits this explicitly: public Replace uses a sparse builder, the Update/Edit composites use a full-state builder through a shared private transport with one hook envelope and one generated-call site.

Conformance

Harness upgraded full-width: new requestMethod / requestBody / requestBodyAbsent assertions, requestPath (and all per-request assertions) honor index, and Python/Ruby/TypeScript runners moved to method-agnostic sequential response queues constrained to the active API origin β€” retiring their multi-hop UploadsDownload skips (now passing). New todos_write.json fixtures (update-merge, edit-clear, replace-omission-clears) pass in all five runners; Swift (no runner) mirrors them natively in XCTest.

#355 (partial)

Go Todo gains CompletionSubscribers and CommentsCount, with nil-vs-empty preserved on completion_subscribers (server [] β†’ non-nil empty slice; absent β†’ nil; deliberately not omitempty) for fail-closed consumers like the CLI. description_attachments remains (read-only server-side; not a data-loss risk) β€” issue stays open.

Live incident replay (sandbox, via the SDK β€” no raw HTTP)

Run against a scratch project in a personal account at the release head, Go SDK end-to-end, then cleaned up (todo + project trashed):

create  (description + due/starts + assignee + completion subscriber)  ok
update  content-only β†’ description, due_on, starts_on, assignees,
        completion subscribers ALL preserved                           ok
edit    clear date range β†’ dates cleared, description/assignees kept   ok
replace sparse β†’ description/dates/assignees/subscribers cleared       ok
replace full body on canonical flat route β†’ description persisted      ok
                                                    (0 failures)

Two server-native behaviors surfaced by the replay (documented, not defects): rich-text descriptions are normalized (<div> β†’ <div dir="auto">), and dates are a range β€” clearing due_on alone collapses the range onto starts_on, so a full clear sets both empty.

Release notes / migration hazards (0.8.0)

  • update never clears by omission anymore. Callers relying on omission-clears through the old sparse PUT (e.g. basecamp-cli's clear paths) must move to edit/replace in the same change that bumps the SDK.
  • The generated update is now replace, with content required; UpdateTodoRequest/UpdateTodoBody compat types remain for the merge-safe surface.
  • Kotlin: source-compatible but binary-incompatible for already-compiled consumers β€” the todos accessor's declared type is now the hand-written subclass.

Verification

  • make check (full umbrella: all six languages, drift gates, conformance) β€” green.
  • Targeted assertions: no operation UpdateTodo in the spec, no UpdateTodo operationId in openapi.json/behavior-model/metadata, ReplaceTodo present in every generated surface.
  • Go 71/71 conformance; Kotlin 61 pass/10 skipped (pre-existing); TS 67 pass/4 skipped (pre-existing); Ruby 63 pass/8 skipped (pre-existing); Python 68 pass/3 skipped (pre-existing).

Review convergence round (9c6003f8)

Four commits addressing the first review pass; all seven threads replied to and resolved in place.

  • Conformance hardening (07b18640): implicit first-request method invariant in all five runners (restores the wire-verb enforcement the origin-wide queues dropped; mutation-tested by flipping a fixture's GET to POST β€” Python, Ruby, and Go all fail it, pass again on revert); Kotlin requestBodyAbsent now fails on an unresolvable index like the other assertions; Python/Ruby origin interception normalizes mixed-case hosts and explicit default ports, with a new paths.json regression case (Go runner skips it β€” it dials the override origin for real).
  • Lock hygiene (0a7292fa): python/uv.lock and the conformance TS runner's package-lock.json were still at 0.7.3 β€” synced, bump script extended to cover both, and make release now fails on stale locks (uv lock --check + runner-lock version).
  • Architecture disposition (634bc5a0): the composite update/edit surface contradicted the letter of "no hand-written API methods"; SPEC.md Β§18 now defines sanctioned composite methods (generated wire methods only, native hook identities, conformance coverage, declared placement) and AGENTS.md aligns.
  • Kotlin KDoc (9c6003f8): VERB_PATTERNS doc comment reanchored.

Conformance counts after the round (+1 new origin-normalization case): Go 71 pass/1 skipped, Kotlin 62/10, TS 68/4, Ruby 64/8, Python 69/3 β€” all zero failures. make check green at the new head.

Follow-up: #374 rolls the triad across sibling recordables (messages, documents, cards, todolists, schedule entries) with todos as the template.


Summary by cubic

Fixes todo update data loss by making writes merge-safe and adding edit and verbatim replace across all six SDKs; hardens the conformance harness, IPv6 origin handling, and release checks (addresses #372).

  • New Features

    • Merge-safe update (GET β†’ overlay β†’ full PUT), read-modify-write edit, and verbatim replace in Go, TypeScript, Python, Ruby, Kotlin, and Swift.
    • Wire op renamed UpdateTodo β†’ ReplaceTodo; spec documents replace semantics via x-basecamp-write-semantics (mode: replace, clearsOmitted: true). Route stays flat.
    • Conformance: added method/body assertions, indexed per-request checks, origin normalization; new todos_write.json fixtures. Paths fixtures now include full TimesheetEntry bodies. IPv6 origins normalized in Python and TypeScript; MSW path catch-all uses a RegExp; new bracketed-IPv6 regression case added (Go runner skips origin interception cases).
    • Go Todo: adds CompletionSubscribers (nil-vs-empty preserved) and CommentsCount.
    • Release tooling: make release fails on stale locks; syncs Python uv.lock and conformance TS package-lock.json.
    • Python and Ruby full-write paths: edit/update raise UsageError when assignee_ids/completion_subscriber_ids are None/nil (use [] to clear).
    • Architecture: SPEC.md Β§18 and AGENTS.md sanction composite methods and the narrow Go pattern that marshals explicit bodies through generated *WithBody when omitempty cannot express β€œalways-send-empty”.
  • Migration

    • update no longer clears by omission. Use edit or replace to clear fields.
    • Generated update is now replace and requires content; compat shims where needed (e.g., Kotlin UpdateTodoBody).
    • Kotlin: todos accessor now returns a hand-written subclass; source-compatible but binary-incompatible for already-compiled consumers.
    • Version bumped to 0.8.0 across SDKs.