Give Kotlin uploads.download and dispatch the download conformance family

Merged
JE
4mo ago
+85-24

Closes the Kotlin download-capability gap (wave 1, rock B5): uploads.download(id) lands as a SPEC §18 composite over the existing downloadURL primitive, and the Kotlin conformance runner dispatches the DownloadURL/UploadsDownload family — five skips removed.

What changed

  • Generator (Config.kt): Uploads joins EXTENSIBLE_SERVICES (generated service becomes open class) and HAND_WRITTEN_SERVICES (the account.uploads accessor constructs and declares the hand-written subclass). Regen diff is exactly the intended two files: the open class keyword in uploads.kt and the accessor rewire in ServiceAccessors.kt — zero timestamp churn.
  • Composite (services/UploadsService.kt, hand-written): download(uploadId) composes the public generated get (GetUpload) with the client-level downloadURL primitive (§14 authenticated hop 1, 302-follow, unauthenticated signed hop 2), throws BasecampException.Usage when the upload has no download_url, and prefers the metadata filename over the URL-derived name — the TypeScript uploads-extensions.ts semantics, delegation shape and all. Hooks observe the constituent operations (GetUpload, then DownloadURL), never a synthetic composite.
  • Runner (Main.kt): DownloadURL dispatch (synthetic storage.3.basecamp.com host + fixture path, rewritten to the mock origin by the SDK — same shape as the Go runner) and UploadsDownload dispatch through account.uploads.download. Also ports the missing headerAbsent assertion (index-aware, present-but-empty fails, mirroring Go's Values check) and gives headerPresent the schema's index semantics — it previously always checked request 0, so per-hop auth assertions (auth'd hop 1, bare hop 2) could not be expressed.
  • Fixtures (uploads_download.json): the two UploadsDownload metadata bodies grow from 3 sparse keys to the canonical spec/fixtures/uploads/get.json shape; each test's id/filename/download_url semantics are untouched (absolute storage URL in the delegate case, null in the error case). Kotlin is the strictest consumer — kotlinx.serialization requires the model's non-optional fields — and the sparse bodies rode the runner's MissingFieldException→SKIP degradation path (the B6 flip target), which would have turned into hard failures later. Inline one-line style preserved: a 2-line diff.
  • SPEC: the five §19 Kotlin roster lines removed; the two remaining download-retry lines now carry the honest reason ("Kotlin download hop 1 does not retry yet (B4)"); §18's "Current composites" list gains the Uploads download entry (already shipped in TS/Go/Python/Ruby, previously unlisted).

Verify-first findings

  • AccountClient.downloadURL(rawURL) already existed in Download.kt with the full two-hop flow: relative-Location resolution, "redirect $status with no Location header" (Api) on missing Location, direct-2xx path, bare unauthenticated hop 2. The gap was purely reachability: no composite, no dispatch.
  • The composite reaches the primitive by capturing its own AccountClient reference (private val client constructor property) — BaseService keeps its accountClient private, so the TodosService/CardsService pattern alone (which only compose inherited methods) was not sufficient; verified against both precedents before writing.
  • Hop 2 shares the SDK engine (HttpClient(httpClient.httpClient.engine)), so MockEngine serves both hops and the relative /signed/logo.png Location lands on the mock.

Red proof (pre-implementation, verbatim)

Five skips removed, before any implementation:

  FAIL: DownloadURL auth'd first hop 302s to signed URL
        Unexpected exception: UnsupportedOperationException: Unknown operation: DownloadURL
  FAIL: DownloadURL direct 2xx body
        Unexpected exception: UnsupportedOperationException: Unknown operation: DownloadURL
  FAIL: DownloadURL surfaces redirect with no Location
        Unexpected exception: UnsupportedOperationException: Unknown operation: DownloadURL
  FAIL: UploadsDownload delegates through DownloadURL primitive
        Unexpected exception: UnsupportedOperationException: Unknown operation: UploadsDownload
  FAIL: UploadsDownload errors when upload has no download_url
        Unexpected exception: UnsupportedOperationException: Unknown operation: UploadsDownload
Passed: 116, Failed: 5, Skipped: 3, Total: 124

Mid-implementation the suite also surfaced two real gaps, both fixed rather than worked around:

  FAIL: DownloadURL auth'd first hop 302s to signed URL
        Unknown assertion type: headerAbsent
  SKIP: UploadsDownload delegates through DownloadURL primitive
        Mock body lacks required Kotlin model fields: Fields [status, visible_to_clients, ...] are required for type ... 'com.basecamp.sdk.generated.models.Upload'

After

  • make conformance-kotlin: Passed: 121, Failed: 0, Skipped: 3, Total: 124 (remaining: link-header architectural + the two B4 download-retry skips).
  • Cross-runner re-verification after the shared-fixture change: Go 122/0/2, Python 122 passed, 0 failed, 2 skipped, Ruby 106 passed, 0 failed, 18 skipped, TypeScript 142 passed | 4 skipped.
  • :basecamp-sdk:jvmTest: BUILD SUCCESSFUL.
  • scripts/check-kotlin-generated-drift.sh: No drift detected.
  • make conformance-fixtures-check: ok.

Summary by cubic

Adds uploads.download(id) to the Kotlin SDK by composing get with downloadURL. The Kotlin conformance runner now dispatches DownloadURL and UploadsDownload, removing five skips.

  • New Features

    • com.basecamp.sdk.services.UploadsService.download(uploadId) uses get + AccountClient.downloadURL, errors when download_url is missing, and prefers the metadata filename.
    • Generator marks Uploads as extensible and rewires AccountClient.uploads to com.basecamp.sdk.services.UploadsService.
    • Runner dispatches DownloadURL (synthetic storage host) and UploadsDownload via account.uploads.download.
  • Bug Fixes

    • Added headerAbsent and fixed headerPresent to honor index, enabling per-hop auth assertions.
    • Expanded uploads_download.json to the canonical upload shape so Kotlin models deserialize cleanly.
    • Updated SPEC.md to list the new composite and adjust Kotlin skip reasons (download hop 1 retry remains deferred).