Skip to content

fix(playground): prevent model group option stretching#6120

Open
QuentinHsu wants to merge 2 commits into
mainfrom
fix/model-group-option-height
Open

fix(playground): prevent model group option stretching#6120
QuentinHsu wants to merge 2 commits into
mainfrom
fix/model-group-option-height

Conversation

@QuentinHsu

@QuentinHsu QuentinHsu commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

问题描述

  • 模型分组列表使用占满剩余空间的网格布局,网格行会随容器高度均匀拉伸,导致选项高度不固定。

修复方式

  • 将分组选项的网格行固定为 2rem,并使用顶部对齐,避免选项被剩余空间拉伸。
  • 将选择器布局逻辑迁移到 model-group-selector 专属模块。
  • 将相关测试集中放置在模块的 __tests__ 目录,避免测试文件与正式代码平铺。
  • 完善前端测试规范,明确行为变更、目录组织、边界覆盖、可访问性、异步测试、Mock 和提交前验证要求。

测试说明

  • 验证分组选项使用固定高度并从顶部排列。
  • 验证选中分组在独立滚动容器内居中。
  • 验证未提供滚动容器时使用 scrollIntoView 降级处理。
  • 已通过 36 项前端测试、TypeScript 类型检查、Lint、格式检查和生产构建。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes #

✅ 提交前检查项 / Checklist

  • 人工确认:我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交:我已搜索现有 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明:若此 PR 标记为 Bug fix,我已提交或关联对应 Issue。
  • 变更理解:我已理解这些更改的工作原理及可能影响。
  • 范围聚焦:本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证:已在本地运行并通过测试及构建验证。
  • 安全合规:代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

  • bun test:36 项测试全部通过。
  • bun run typecheck:通过。
  • oxlintoxfmt --check:通过。
  • bun run build:生产构建通过。

Summary by CodeRabbit

  • Bug Fixes

    • Improved model group selector scrolling and layout consistency.
    • Selected options now center correctly within the scroll area or fall back to native scrolling when needed.
    • Group options maintain a consistent height and top alignment.
  • Tests

    • Added coverage for scrolling behavior and layout styling.
    • Expanded testing guidance for UI interactions, accessibility, asynchronous states, and regression coverage.

- keep group options at a fixed 2rem height and align them to the top.
- organize layout code in a dedicated module and cover layout and scrolling behavior.
- require regression coverage for behavior changes, bug fixes, and UI states.
- define module-scoped test organization, stable assertions, mocks, and verification rules.
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Testing guidance was expanded, while the model group selector received a nested layout import, fixed grid-row styling, and tests for layout classes and option scrolling behavior.

Changes

Testing guidance

Layer / File(s) Summary
Expanded testing checklist
web/default/AGENTS.md
Testing requirements now cover regression coverage, test organization, stable assertions, edge paths, isolation, snapshots, integration tests, and pre-submit validation.

Model group selector layout

Layer / File(s) Summary
Layout wiring and helper coverage
web/default/src/components/model-group-selector.tsx, web/default/src/components/model-group-selector/layout.ts, web/default/src/components/model-group-selector/__tests__/layout.test.ts
The selector imports the nested layout module, uses fixed grid rows for the scroll area, and tests class output plus container and fallback scrolling behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: seefs001, Calcium-Ion

Poem

I’m a rabbit hopping through the grid,
With tidy rows where options hid.
Tests watch scrolling, calm and bright,
While guidance keeps the checks just right.
Nibble, verify, and ship tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing stretched model group options in the Playground.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/model-group-option-height

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

🧹 Nitpick comments (1)
web/default/src/components/model-group-selector/__tests__/layout.test.ts (1)

19-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Vitest instead of node:test for unit tests in __tests__/ directories.

The coding guidelines for web/default/**/__tests__/**/*.test.ts specify that unit tests for utility functions and pure logic should use Vitest. This file imports from node:test and node:assert/strict instead. Additionally, AGENTS.md line 147 states "工具函数与纯逻辑优先单元测试(Vitest)" and line 164 says "新增或大幅重写测试时优先使用 Vitest 与 React Testing Library 的标准断言和查询方式".

The test logic itself is correct and well-structured — the scroll centering math (scrollTop = 76) and the scrollIntoView fallback assertion are both accurate.

♻️ Proposed refactor: switch to Vitest
-import assert from 'node:assert/strict'
-import { describe, test } from 'node:test'
+import { describe, it, expect } from 'vitest'

 import {
   modelGroupSelectorLayoutClasses,
   scrollSelectedOptionIntoView,
 } from '../layout'

 describe('model group selector layout', () => {
-  test('keeps group options at a fixed height and aligned to the top', () => {
+  it('keeps group options at a fixed height and aligned to the top', () => {
     const groupScrollClasses =
       modelGroupSelectorLayoutClasses.groupScroll.split(' ')

-    assert.ok(groupScrollClasses.includes('auto-rows-[2rem]'))
-    assert.ok(groupScrollClasses.includes('content-start'))
+    expect(groupScrollClasses).toContain('auto-rows-[2rem]')
+    expect(groupScrollClasses).toContain('content-start')
   })

-  test('centers the selected group inside its own scroll container', () => {
+  it('centers the selected group inside its own scroll container', () => {
     const scrollCalls: ScrollToOptions[] = []
     const selectedOption = {
       offsetHeight: 32,
       offsetTop: 160,
       scrollIntoView() {},
     }
     const scrollContainer = {
       clientHeight: 200,
       scrollTop: 0,
       scrollTo(options: ScrollToOptions) {
         scrollCalls.push(options)
       },
     }

     scrollSelectedOptionIntoView(selectedOption, scrollContainer)

-    assert.deepEqual(scrollCalls, [{ top: 76, behavior: 'auto' }])
+    expect(scrollCalls).toEqual([{ top: 76, behavior: 'auto' }])
   })

-  test('falls back to scrollIntoView when no group container is provided', () => {
+  it('falls back to scrollIntoView when no group container is provided', () => {
     const scrollCalls: ScrollIntoViewOptions[] = []
     const selectedOption = {
       scrollIntoView(options?: ScrollIntoViewOptions) {
         scrollCalls.push(options ?? {})
       },
     }

     scrollSelectedOptionIntoView(selectedOption)

-    assert.deepEqual(scrollCalls, [{ block: 'center', inline: 'nearest' }])
+    expect(scrollCalls).toEqual([{ block: 'center', inline: 'nearest' }])
   })
 })

Also applies to: 28-34

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/components/model-group-selector/__tests__/layout.test.ts`
around lines 19 - 20, Update the tests in this file to use Vitest instead of
node:test and node:assert/strict: replace the describe/test imports with Vitest
equivalents and migrate assertions to Vitest assertions, while preserving the
existing scroll-centering and scrollIntoView fallback test behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/default/src/components/model-group-selector/__tests__/layout.test.ts`:
- Around line 19-20: Update the tests in this file to use Vitest instead of
node:test and node:assert/strict: replace the describe/test imports with Vitest
equivalents and migrate assertions to Vitest assertions, while preserving the
existing scroll-centering and scrollIntoView fallback test behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94ebb525-f031-410f-8aed-6acd6113d3de

📥 Commits

Reviewing files that changed from the base of the PR and between c36418c and b6c2e54.

📒 Files selected for processing (4)
  • web/default/AGENTS.md
  • web/default/src/components/model-group-selector.tsx
  • web/default/src/components/model-group-selector/__tests__/layout.test.ts
  • web/default/src/components/model-group-selector/layout.ts

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