Skip to content

refactor: move the Anthropic AWS files to the upstream layout - #320

Merged
eric8810 merged 10 commits into
masterfrom
refactor/move-the-anthropic-aws-files-to-the-upstream-layout
Oct 27, 2026
Merged

eric8810 merged 10 commits into
masterfrom
refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Conversation

@cunninghamcard-bit

@cunninghamcard-bit cunninghamcard-bit commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

把 Anthropic AWS 的源文件按 @ai-sdk/anthropic-aws@2.0.63 一个文件对一个文件拆开(RFC-0046 §4.2),老的 tests/anthropic_aws_settings_test.rs 并进厂商测试目录 src/anthropic_aws/tests/(RFC-0046 §5 的新布局)。只搬不改:函数体只改了模块路径,测试数量、模块路径和函数名前后一致。叠在测试 PR #319 上。

已经测试分支 92dc5baa 合上 master b69137eb,冲突按 master 的改动搬到新位置解决(凭证错误改用 AiMuxError::other,文档里的 invalid_argument 落到 provider.rs,老设置测试里的错误模式改成结构体变体,落到 tests/provider.rs);测试数前后仍相等(Anthropic AWS 55 个,测试分支 lib 46 个加老测试程序 9 个,名字多重集相同)。

一、体系现状(概览,测试 PR #319 头 a60cbae9)

aimux_providers::create_anthropic_aws                 src/anthropic_aws/mod.rs:141
 ├ model::authenticated(auth, headers, fetch)         src/anthropic_aws/model.rs:186
 │  ├ AwsHeaders::resolve(anthropic-version、workspace id、x-api-key)   src/anthropic_aws/model.rs:223
 │  └ AnthropicAwsFetch::send → SigV4Fetch(无 x-api-key 时签名)       src/anthropic_aws/model.rs:260
 │     └ Auth(region、workspace id、凭证按请求读取)                   src/anthropic_aws/model.rs:54
 └ AnthropicAwsProvider::language_model → messages    src/anthropic_aws/mod.rs:252 → :236
   └ model_config → AnthropicMessagesModel(共用的 Messages 模型)     src/anthropic_aws/mod.rs:223
      └ AnthropicMessagesModel::do_generate           src/anthropic/model.rs:152
 └ ProviderDiscovery::list_models                     src/anthropic_aws/mod.rs:268

上游同一条路:createAnthropicAws(anthropic-aws-provider.ts)组装设置和模型,createSigV4FetchFunction / createApiKeyFetchFunction(anthropic-aws-fetch.ts)负责鉴权和签名,模型本身来自 @ai-sdk/anthropic。aimux 的工厂和 index.ts 在 mod.rs,鉴权和传输在名字叫 model.rs 的文件里。

测试:#319 的新用例在 src/anthropic_aws/tests/,老用例还在独立测试程序 tests/anthropic_aws_settings_test.rs(9 个,含修复 PR #314–#318 加的)。tests/sigv4_signed_headers_test.rs 和 tests/bedrock_user_agent_test.rs 同时测 Bedrock、Polly 和 Anthropic AWS,属于跨厂商测试。

二、本 PR 改动(细节)

aimux_providers::create_anthropic_aws                 src/anthropic_aws/provider.rs:124     ← anthropic-aws-provider.ts
 ├ fetch::authenticated(auth, headers, fetch)         src/anthropic_aws/fetch.rs:181        ← anthropic-aws-fetch.ts
 │  ├ AwsHeaders::resolve                             src/anthropic_aws/fetch.rs:218
 │  └ AnthropicAwsFetch::send → SigV4Fetch            src/anthropic_aws/fetch.rs:255
 │     └ Auth                                         src/anthropic_aws/fetch.rs:49
 └ AnthropicAwsProvider::language_model → messages    src/anthropic_aws/provider.rs:235 → :219
   └ model_config → AnthropicMessagesModel            src/anthropic_aws/provider.rs:206
      └ AnthropicMessagesModel::do_generate           src/anthropic/model.rs:152(不动)
 └ ProviderDiscovery::list_models                     src/anthropic_aws/provider.rs:251
现在 搬到 上游
mod.rs 模块文档、导出 anthropic_aws/mod.rs(只有模块声明和 pub use) index.ts
mod.rs 鉴权枚举、设置、工厂、默认实例、AnthropicAwsProvider anthropic_aws/provider.rs(AnthropicAwsModel 类型别名也放这里) anthropic-aws-provider.ts
model.rs Auth、authenticated、AwsHeaders、两个传输 anthropic_aws/fetch.rs(git mv) anthropic-aws-fetch.ts
  • 公开路径不变:anthropic_aws::{AnthropicAwsAuth, AnthropicAwsModel, AnthropicAwsProvider, AnthropicAwsProviderSettings, anthropic_aws, create_anthropic_aws, TransformRequestBody} 由 mod.rs 再导出;anthropic/config.rs 用的 Auth、AwsHeaders 仍是 pub(crate) 再导出。
  • 函数体只有三处路径从 model:: 改成 fetch::(Auth、authenticated)。两处文档链接改成全路径。
  • 测试:tests/anthropic_aws_settings_test.rs 并进 src/anthropic_aws/tests/provider.rs 末尾,帮手放在「older settings ports」一节,和 test: port the upstream Anthropic AWS tests #319 同名的 api_key() 改名 key_auth();#[path] 引入的 mock_fetch 改成 crate::test_support::mock_fetch,aimux_providers:: 改成 crate::。tests/fetch.rs 的 import 和注释跟着改到 fetch.rs。两个跨厂商测试留在 tests/。
  • layout.toml 的 rust 字段改到新路径。边界脚本不用改。

验证

  • cargo test -p aimux-providers --lib 加原 --test anthropic_aws_settings_test:前后都是 55 个测试(46 + 9),模块路径(去掉文件前缀后)和函数名完全相同;55 个全过。按文件:tests/provider.rs 30 个、tests/fetch.rs 22 个、tests/region_validation.rs 3 个。
  • 非测试源码逐行比对:去掉 use 和注释后,只有上面三处 model:: → fetch::。
  • cargo +1.99 clippy -p aimux-providers --lib --tests -- -D warnings、cargo doc -D warnings、cargo fmt --check、scripts/check_provider_boundaries.sh 通过。

Type of change

  • Refactor (no behavior change)

Checklist

  • Tests pass locally
  • Commit messages follow Conventional Commits

共享进程状态:测试原来各自是单独的测试程序,现在并进 lib 的同一个测试程序。共 36 个测试带 #[serial]:tests/provider.rs 全部 30 个(经 EnvVar 设置 AWS 相关环境变量,结束时恢复)、tests/region_validation.rs 3 个(同样设置环境变量)、tests/fetch.rs 3 个(改默认传输的路由)。lib 里以后读 AWS 环境变量的测试(Bedrock 搬进来时)也要 #[serial]。没有全局计数器和固定临时路径(RFC-0046 §5)。


Generated by Claude Code

… layout

One Rust file per @ai-sdk/anthropic-aws source file (RFC-0046 §4.2):
mod.rs keeps only the module list (index.ts), the settings, factory and
provider go to provider.rs (anthropic-aws-provider.ts), and model.rs,
which holds the request authentication and the SigV4 transport, becomes
fetch.rs (anthropic-aws-fetch.ts).

tests/anthropic_aws_settings_test.rs joins src/anthropic_aws/tests/
provider.rs; the two cross-vendor tests (SigV4 signed headers, Bedrock
user agents) stay in tests/. Move only: the test count (55) and the test
names are unchanged; function bodies change only in module paths.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
@cunninghamcard-bit
cunninghamcard-bit marked this pull request as ready for review October 24, 2026 11:34

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Anthropic AWS layout refactor:move/rename-only,55 tests 保留,公开 item set 相等;PR 描述写 36 tests,实际 30。Approve。

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…-aws-tests' into refactor/move-the-anthropic-aws-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
@eric8810
eric8810 changed the base branch from test/port-the-upstream-anthropic-aws-tests to master October 27, 2026 07:50
@eric8810
eric8810 merged commit e2b5ca7 into master Oct 27, 2026
16 checks passed
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.

3 participants