Skip to content

refactor(DCT-266): migrate remaining client methods to ExecuteBuilder - #486

Open
script-this wants to merge 5 commits into
mainfrom
refactor/dct-266-execute-builder-migration-part2
Open

refactor(DCT-266): migrate remaining client methods to ExecuteBuilder#486
script-this wants to merge 5 commits into
mainfrom
refactor/dct-266-execute-builder-migration-part2

Conversation

@script-this

Copy link
Copy Markdown
Contributor

Summary

Second and final PR for the ExecuteBuilder migration (DCT-266). Stacked on #485 — migrates the remaining methods so every one of the 88 Client methods that makes an HTTP call now uses ExecuteBuilder (up from 44/90 in #485; the other 2 of 90, userAgent and Execute itself, don't call Execute and have nothing to migrate).

Migrated

Filter sets, surveys, UpdateCollection, messages, bonus payments, and the full AI Task Builder + credential pool surface (batches, datasets, instructions, setup, sync, export). Added PutRequest to ExecuteBuilder for UpdateCollection's PUT request.

The tricky part: typed error inspection

UpdateAITaskBuilderBatch and CreateAITaskBuilderBatch both do errors.As(err, *UnrecognizedAPIError) directly on the raw error from Client.Execute to special-case INVALID_BATCH_ITEMS validation errors into a readable message. This only worked because that error wasn't wrapped before the check — ExecuteBuilder.Execute wrapped errors with %s, which would have silently destroyed the type and broken that formatting. formatBatchErrorBody's existing unit tests wouldn't have caught this, since they test the formatter directly, not the errors.As wiring around it.

Before touching either method, added TestUpdateAITaskBuilderBatch and TestCreateAITaskBuilderBatch to characterize the full error-branching behaviour end-to-end (4xx + INVALID_BATCH_ITEMS, non-4xx-but-wrong-status + INVALID_BATCH_ITEMS, a recognized error shape that should not get special formatting, and the success path). Then fixed ExecuteBuilder.Execute to wrap with %w instead of %s — identical Error() text, but preserves the chain for errors.Is/errors.As — and migrated both methods, verified against the same tests.

Testing

New TestUpdateAITaskBuilderBatch/TestCreateAITaskBuilderBatch characterization tests, full suite (make test), make lint, and contract_test's spec-matching test all pass.

@script-this
script-this requested review from a team as code owners August 14, 2026 15:12
@script-this
script-this marked this pull request as draft August 14, 2026 15:12
@prolific-snyk

prolific-snyk commented Aug 14, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

… methods

Add PutRequest to ExecuteBuilder for UpdateCollection's PUT request, and
migrate GetFilterSets, GetFilterSet, CreateFilterSet, GetSurveys, GetSurvey,
CreateSurvey, DeleteSurvey, GetSurveyResponses, GetSurveyResponse,
CreateSurveyResponse, DeleteSurveyResponse, DeleteAllSurveyResponses,
GetSurveyResponseSummary, UpdateCollection, GetMessages, SendMessage,
GetUnreadMessages, BulkSendMessage, SendGroupMessage, CreateBonusPayments
and PayBonusPayments onto the builder.

65 of 90 client methods now use ExecuteBuilder. Remaining: AI Task Builder
and credential pool methods.
…ilder

Migrate GetAITaskBuilderBatch, GetAITaskBuilderBatchStatus,
GetAITaskBuilderBatches, GetAITaskBuilderResponses, GetAITaskBuilderTasks,
GetAITaskBuilderTaskGroups, InitiateBatchExport, GetBatchExportStatus and
SyncAITaskBuilderBatch onto the builder.

UpdateAITaskBuilderBatch needed more care: it does errors.As(err,
*UnrecognizedAPIError) directly on the raw error from Client.Execute to
special-case INVALID_BATCH_ITEMS validation errors, which only worked
because that error wasn't wrapped before the check. ExecuteBuilder.Execute
wrapped errors with %s, which would have silently broken that type
assertion (formatBatchErrorBody's existing unit tests wouldn't have caught
it, since they test the formatter directly, not the errors.As wiring).

Added TestUpdateAITaskBuilderBatch to characterize the current
error-branching behaviour end-to-end first, then fixed
ExecuteBuilder.Execute to wrap with %w instead of %s (identical Error()
text, but preserves the chain for errors.Is/errors.As) before migrating
the method — verified against the same characterization tests.

74 of 90 client methods now use ExecuteBuilder.
…ool methods

Migrate GetAITaskBuilderDataset, GetAITaskBuilderDatasetStatus,
GetAITaskBuilderDatasetUploadURL, GetAITaskBuilderDatasetImportStatus,
GetAITaskBuilderBatchSyncStatus, CreateAITaskBuilderInstructions,
SetupAITaskBuilderBatch, CreateAITaskBuilderDataset,
CreateAITaskBuilderCollection, CreateCredentialPool, UpdateCredentialPool
and ListCredentialPools onto ExecuteBuilder.

CreateAITaskBuilderBatch had the same errors.As(*UnrecognizedAPIError)
pattern as UpdateAITaskBuilderBatch (see previous commit) — added
TestCreateAITaskBuilderBatch to characterize it first, then migrated using
the same approach now that ExecuteBuilder.Execute preserves the error
chain.

Also caught and migrated GetAITaskBuilderBatchSyncStatus, which was missed
in the earlier AI Task Builder batch.

88 of 90 Client methods now use ExecuteBuilder — every method that makes
an HTTP call. The remaining 2 (userAgent, Execute itself) don't call
Execute and have nothing to migrate. This completes DCT-266.
Same simplification as the base branch: GetFilterSet, GetSurvey,
GetSurveyResponse, GetSurveyResponseSummary, GetBatchExportStatus,
GetAITaskBuilderBatchSyncStatus, GetAITaskBuilderDatasetImportStatus and
ListCredentialPools were reinventing ExecuteBuilder.Get(url, &response)
via its constituent calls instead of using it directly.
@script-this
script-this force-pushed the refactor/dct-266-execute-builder-migration-part2 branch from b9d317a to d1732f3 Compare August 14, 2026 15:20
Base automatically changed from refactor/dct-266-execute-builder-migration to main August 14, 2026 15:59
@script-this
script-this marked this pull request as ready for review August 14, 2026 16:01
@script-this script-this added team-dct customer-facing dct-ready-for-review Triggers Slack notification when PR is ready for review labels Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

customer-facing dct-ready-for-review Triggers Slack notification when PR is ready for review team-dct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants