refactor(anthropic): deduplicate sequencing, media-type, and test helpers#2019
refactor(anthropic): deduplicate sequencing, media-type, and test helpers#2019dgageot wants to merge 1 commit intodocker:mainfrom
Conversation
…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
There was a problem hiding this comment.
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 aliases — marshalToMapBeta/contentArrayBeta were just aliases; tests now use originals directly
✅ Generic sequencing functions — validateSequencing[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.
Summary
Simplify and deduplicate code in the Anthropic provider without changing any behavior.
Changes
hashFileto test file — It was only used in tests; removed fromfiles.go, added tofiles_test.go.marshalToMapBeta/contentArrayBetaaliases — These were trivial aliases (var marshalToMapBeta = marshalToMap). All call sites now use the originals directly.validateSequencing[T]andrepairSequencing[T]to replace the nearly identical standard and beta implementations, eliminating ~80 lines of duplicated logic.extractMediaType— BothconvertUserMultiContentandconvertBetaUserMultiContenthad identical inline switch blocks for parsingdata:image URLs. Now they call the existingextractMediaTypehelper.Result
-87 lines net across 6 files. No features changed, all tests pass, linter clean.