Skip to content

refactor(anthropic): deduplicate sequencing, media-type, and test helpers#2019

Open
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/providers-45bd2b31
Open

refactor(anthropic): deduplicate sequencing, media-type, and test helpers#2019
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/providers-45bd2b31

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 9, 2026

Summary

Simplify and deduplicate code in the Anthropic provider without changing any behavior.

Changes

  • Move hashFile to test file — It was only used in tests; removed from files.go, added to files_test.go.
  • Remove marshalToMapBeta/contentArrayBeta aliases — These were trivial aliases (var marshalToMapBeta = marshalToMap). All call sites now use the originals directly.
  • Unify sequencing validation/repair with generics — Extract validateSequencing[T] and repairSequencing[T] to replace the nearly identical standard and beta implementations, eliminating ~80 lines of duplicated logic.
  • Replace duplicated media-type switch with extractMediaType — Both convertUserMultiContent and convertBetaUserMultiContent had identical inline switch blocks for parsing data: image URLs. Now they call the existing extractMediaType helper.

Result

-87 lines net across 6 files. No features changed, all tests pass, linter clean.

…pers

- Move hashFile from files.go to files_test.go (only used in tests)
- Remove marshalToMapBeta/contentArrayBeta aliases; use originals directly
- Extract generic validateSequencing[T] and repairSequencing[T] to unify
  standard and beta sequencing validation/repair logic
- Replace duplicated inline media-type switch with extractMediaType in
  both convertUserMultiContent and convertBetaUserMultiContent

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner March 9, 2026 19:51
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Assessment: 🟢 APPROVE

This refactoring PR successfully deduplicates code in the Anthropic provider without introducing any bugs:

hashFile moved to test file — Correctly relocated to files_test.go since it's only used in tests
Removed trivial aliasesmarshalToMapBeta/contentArrayBeta were just aliases; tests now use originals directly
Generic sequencing functionsvalidateSequencing[T] and repairSequencing[T] correctly unify standard and Beta API logic using marshal-to-map inspection
extractMediaType helper — Properly eliminates duplicated media-type switch statements in both converters

The generic implementations maintain identical behavior to the original code while reducing duplication. The makeSynthetic callback correctly constructs type-appropriate synthetic messages for each API variant.

Result: -87 lines net with no behavioral changes. All changed code is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant