Skip to content

refactor: move the Groq files to the upstream layout - #302

Merged
eric8810 merged 8 commits into
masterfrom
refactor/move-the-groq-files-to-the-upstream-layout
Oct 25, 2026
Merged

eric8810 merged 8 commits into
masterfrom
refactor/move-the-groq-files-to-the-upstream-layout

Conversation

@cunninghamcard-bit

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

Copy link
Copy Markdown
Contributor

Summary

按 RFC-0046 §4.2、§5(#294)把 Groq 的文件按 @ai-sdk/groq 逐个对应,做法和 Mistral(#297)、Cohere(#298)、DeepSeek(#300)、Hugging Face(#304)相同。叠在 #301(Groq 测试迁移)上。只挪不改:没有改任何函数体和断言,测试数前后都是 254,测试函数名和 describe 路径一致。测试按 10-20 定下的新布局全部放在 src/groq/tests/。

已经测试分支 bb8b5dd2 合上 master b69137eb,冲突按 master 的改动搬到新位置解决(错误改成 RFC-0047 的结构体变体和 cause,落到 chat_language_model_options.rs、transcription_model_options.rs、provider.rs 和 tests/chat_language_model.rs);测试数前后仍相等(Groq 119 个,测试分支 lib 37 个加老测试程序 82 个,名字多重集相同)。

一、体系概览:一次 Groq 调用经过哪些文件(#301 head c2933999)

create_groq                                         groq/mod.rs:92                上游 groq-provider.ts
 ├ GroqProvider::chat                               groq/mod.rs:152
 │ └ GroqChatLanguageModel::do_generate / do_stream groq/model.rs:276 / :347      上游 groq-chat-language-model.ts
 │   └ get_args                                     groq/model.rs:97
 │     ├ parse_groq_options                         groq/options.rs:85            上游 groq-chat-language-model-options.ts
 │     ├ convert_to_groq_chat_messages              groq/convert.rs:112           上游 convert-to-groq-chat-messages.ts
 │     └ prepare_tools                              groq/prepare_tools.rs:22      上游 groq-prepare-tools.ts
 │   ├ GroqChatResponse / GroqChatChunk / GroqUsage groq/types.rs:88              上游 模型文件里的 zod schema
 │   ├ convert_groq_usage                           groq/usage.rs:9               上游 convert-groq-usage.ts
 │   ├ map_groq_finish_reason                       groq/finish_reason.rs:6       上游 map-groq-finish-reason.ts
 │   ├ response_metadata                            groq/model.rs:42              上游 get-response-metadata.ts
 │   └ groq_failed_response_handler                 groq/error.rs:14              上游 groq-error.ts
 └ GroqProvider::transcription                      groq/mod.rs:159
   └ GroqTranscriptionModel::do_generate            groq/transcription.rs:88      上游 groq-transcription-model.ts
     └ parse_groq_transcription_options             groq/options.rs:122           上游 groq-transcription-model-options.ts

测试:#301 的新用例在 src/groq/tests/(5 个文件,groq/mod.rs 末尾 #[cfg(test)] mod tests;);老用例还在 2 个独立测试程序 tests/groq_test.rs(72 个)、tests/groq_transcription_test.rs(10 个)。

二、本 PR 的改动(细节)

1. 源文件:去掉和目录重复的厂商前缀,kebab-case 换成 snake_case

create_groq                                         groq/provider.rs:62           groq-provider.ts
 ├ GroqProvider::chat                               groq/provider.rs:122
 │ └ GroqChatLanguageModel::do_generate / do_stream groq/chat_language_model.rs:278 / :349
 │   └ get_args                                     groq/chat_language_model.rs:99
 │     ├ parse_groq_options                         groq/chat_language_model_options.rs:85
 │     ├ convert_to_groq_chat_messages              groq/convert_to_chat_messages.rs:112
 │     └ prepare_tools                              groq/prepare_tools.rs:22       不变
 │   ├ GroqChatResponse / GroqChatChunk / GroqUsage groq/api_types.rs:88           RFC-0046 §4.2 第 4 条,上游 groq-api-types.ts
 │   ├ convert_groq_usage                           groq/convert_usage.rs:9
 │   ├ map_groq_finish_reason                       groq/map_finish_reason.rs:6
 │   ├ response_metadata                            groq/chat_language_model.rs:44
 │   └ groq_failed_response_handler                 groq/error.rs:14               不变
 └ GroqProvider::transcription                      groq/provider.rs:129
   └ GroqTranscriptionModel::do_generate            groq/transcription_model.rs:88
     └ parse_groq_transcription_options             groq/transcription_model_options.rs:30   从 options.rs 拆出
groq/mod.rs                                         只剩 mod 声明、pub use 和末尾的 #[cfg(test)] mod tests;   index.ts

layout.toml 的 rust 字段同步改成新文件名(groq-api-types.ts 指向 api_types.rs,groq-config.ts 指向 provider.rs)。

2. 测试都在 src/groq/tests/(RFC-0046 §5),一个上游测试文件一个 Rust 文件

#301 的 5 个文件               只改 use 路径(chat_language_model_options、convert_to_chat_messages、api_types、convert_usage)
tests/groq_test.rs(72 个)按上游测试文件拆开,按 describe 并进同名文件:
  mod groq_chat_language_model     → src/groq/tests/chat_language_model.rs
  文件末尾 aimux 自己的用例         → chat_language_model.rs 末尾
  mod convert_to_groq_chat_messages → src/groq/tests/convert_to_chat_messages.rs
  mod convert_groq_usage            → src/groq/tests/convert_usage.rs
  mod groq_prepare_tools            → src/groq/tests/prepare_tools.rs
  原文件顶部的 wiremock 帮手函数    → src/groq/tests/support.rs(pub(super),各文件 use super::support::*)
tests/groq_transcription_test.rs   → src/groq/tests/transcription_model.rs

原来单个测试程序里有一层"上游文件名"的 mod(groq_chat_language_model、convert_to_groq_chat_messages、groq_prepare_tools、groq_transcription_model),现在这一层就是文件本身,所以去掉;上游 describe 那几层不变(convert_groq_usage、prepare_tools 是上游 describe 名,保留)。aimux_providers:: 改成 crate::,browser_search_models.rs 的 include_str! 路径跟着改。不再有 tests/it/。

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change
  • New provider
  • New / updated binding
  • Docs / RFC
  • Refactor(文件搬移)

Checklist

Notes for reviewers

共享进程状态:测试原来各自是单独的测试程序,现在并进 lib 的同一个测试程序。只有 the_key_is_read_from_the_environment_per_request_not_at_creation 改 GROQ_API_KEY,它带 #[serial],结束时恢复原值;没有全局计数器和固定临时路径(RFC-0046 §5)。

https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW


Generated by Claude Code

One Rust file per @ai-sdk/groq source file (RFC-0046 §4.2): model.rs
becomes chat_language_model.rs, convert.rs convert_to_chat_messages.rs,
usage.rs convert_usage.rs, types.rs api_types.rs, finish_reason.rs
map_finish_reason.rs, transcription.rs transcription_model.rs, and
options.rs splits into chat_language_model_options.rs and
transcription_model_options.rs. mod.rs keeps only the module list
(index.ts); the provider is in provider.rs.

The tests follow: tests/groq_test.rs splits by upstream test file into
tests/it/groq/ (chat_language_model.rs, merged with the snapshot ports,
convert_to_chat_messages.rs, convert_usage.rs and prepare_tools.rs) over a
shared wiremock harness in support.rs, and tests/groq_transcription_test.rs
moves to tests/it/groq/transcription_model.rs. The file-level modules the
single binaries needed become the files themselves. Move only: the test
count (253) and the test function names are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
The Groq test PR now keeps every vendor test in src/groq/tests/ (RFC-0046
§5): the source files lose their `mod tests;` and src/groq/mod.rs declares
the tests module once. This merge keeps the split source files of the move
and lays its tests out the same way:

- the five src/groq/tests/ files import from the renamed source files
  (chat_language_model_options, convert_to_chat_messages, api_types,
  convert_usage);
- tests/groq_test.rs, including the new usage_raw_keeps_null_fields case,
  joins src/groq/tests/{chat_language_model,convert_to_chat_messages,
  convert_usage,prepare_tools}.rs by describe block, its wiremock helpers
  in src/groq/tests/support.rs;
- tests/groq_transcription_test.rs becomes
  src/groq/tests/transcription_model.rs;
- tests/it/ is gone; boundary rule 8 matches the other move PRs.

Move only: 254 tests before and after, same names and describe 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:21

@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.

Groq layout refactor:自身 move-only、213→213 tests;但继承 #301 的部分断言,需在 #301 修复后刷新,并合并 non_object_tool_input 的共享注释改动。

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW

Copy link
Copy Markdown
Contributor Author
eric 的意见(原话) 处理
「继承 #301 的部分断言,需在 #301 修复后刷新」 等 #301 按你的意见改成子集断言后,把 Groq 测试分支合上来,测试数和名字多重集重新核对,再请你看。
「并合并 non_object_tool_input 的共享注释改动」 已改:d68e7328 把 tests/non_object_tool_input_test.rs 第 10 行改成和 #300(e3e3e5d3)完全相同的一行,同时指向 groq/convert_to_chat_messages.rs:88 和 deepseek/chat/convert_to_chat_messages.rs:285,两个 PR 谁先合,另一个在这行都不会冲突。剩下的 CHANGELOG.md 和 layout.toml 冲突是每对搬移 PR 都有的追加冲突,前一个合进 master 后我把 master 合上来解决。

Generated by Claude Code

The test branch reworked tests/groq_test.rs (fixtures read from
src/groq/tests/fixtures, whole-value asserts, partial: markers) and
groq_transcription_test.rs; each change goes to the case where the move
put it (convert_to_chat_messages.rs, convert_usage.rs, prepare_tools.rs,
chat_language_model.rs, transcription_model.rs, support.rs). The snapshot
cases it added to chat_language_model.rs join the existing doGenerate and
doStream text, tool_call, reasoning and raw-chunk modules, so each describe
block stays one module.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW

Copy link
Copy Markdown
Contributor Author
eric 的意见(原话) 处理
「继承 #301 的部分断言,需在 #301 修复后刷新」 已刷新,28169ffa:#301 按你的意见改完(头 dd9c8013,含 #308 修复和 master),合了上来。#301 对 tests/groq_test.rs 的约 50 处改动(夹具改读 src/groq/tests/fixtures/、整值断言、partial: 标注)和 groq_transcription_test.rs 的两处 partial: 标注,逐条搬到这个 PR 放对应用例的文件:convert_to_chat_messages.rs、convert_usage.rs、prepare_tools.rs、chat_language_model.rs、transcription_model.rs、support.rs。
(同上) #301 在 src/groq/tests/chat_language_model.rs 新加的整快照用例(doGenerate 和 doStream 的 text、tool_call、reasoning,以及 raw chunks),并进这个文件里已有的同名 describe 模块,不另开同名模块。
「并合并 non_object_tool_input 的共享注释改动」 上一轮已改(d68e7328),#301 没碰这个文件,这一行仍和 #300 相同。

核对:测试属性数和 partial: 标注数和 #301 相同(全仓 1759 个、12 处);本地 clippy、文档、格式、边界脚本和全部测试通过。


Generated by Claude Code

@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.

Groq refactor 自身 move-only、126→126 tests;但 non_object_tool_input_test.rs:10 现在指向 deepseek/chat/convert_to_chat_messages.rs:285,该路径在本分支不存在。请保留 deepseek/convert.rs 或先合 #300。

…s it is here

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW

Copy link
Copy Markdown
Contributor Author
eric 的意见(原话) 处理
「non_object_tool_input_test.rs:10 现在指向 deepseek/chat/convert_to_chat_messages.rs:285,该路径在本分支不存在。请保留 deepseek/convert.rs 或先合 #300。」 已改,e1cd3f3a:这一行只改 Groq 自己的部分,DeepSeek 留本分支实际存在的 deepseek/convert.rs:284("arguments": input.to_string() 在这一行)。#300 同样只改 DeepSeek 的部分,d6f0f78f 把 Groq 留作 groq/convert.rs:88。两个 PR 先合哪个都行;后合的那个在这一行会有一处冲突,我把 master 合上来时改成两边都指向搬移后的文件。

Generated by Claude Code

…s' into refactor/move-the-groq-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

@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.

指向已改回 groq/convert_to_chat_messages.rs:88 与 deepseek/convert.rs:284;move-only、126→126、无 stale refs。Approve。

…s' into refactor/move-the-groq-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
@eric8810
eric8810 changed the base branch from test/port-the-upstream-groq-tests to master October 25, 2026 17:20
@eric8810
eric8810 merged commit 4f19c34 into master Oct 25, 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