Skip to content

[codex] Fix model square group pricing display - #5943

Draft
zhukangfeng wants to merge 5 commits into
QuantumNous:mainfrom
zhukangfeng:codex/fix-model-store-group-price-20260706-211601
Draft

[codex] Fix model square group pricing display#5943
zhukangfeng wants to merge 5 commits into
QuantumNous:mainfrom
zhukangfeng:codex/fix-model-store-group-price-20260706-211601

Conversation

@zhukangfeng

@zhukangfeng zhukangfeng commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 本 PR 描述已按模板整理,没有直接粘贴未经整理的 AI 输出。
  • AI-assisted disclosure: current git user is 沐峰 <zhukangfeng.zkf@antgroup.com>, which is not among the recurring top authors seen in git log (for example CaIon / Calcium-Ion, JustSong, t0ng7u, Seefs). This code was AI-assisted by Codex automation.

📝 变更描述 / Description

新版模型广场按分组筛选时,卡片和表格仍使用最低分组倍率展示价格,导致用户选择高倍率分组后看到的价格不变。

本 PR 将当前选中的分组和 /api/pricing 返回的全局 group_ratio 传入模型广场的卡片、表格和动态定价展示路径。未选择具体分组时仍保留原有最低可用分组价格展示;选择具体分组时展示该分组倍率下的 token/request 价格。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

bun test src/features/pricing/lib/price.test.ts
bun test
bun run typecheck
bunx oxlint -c .oxlintrc.json src/features/pricing/index.tsx src/features/pricing/components/model-card.tsx src/features/pricing/components/model-card-grid.tsx src/features/pricing/components/pricing-table.tsx src/features/pricing/components/pricing-columns.tsx src/features/pricing/lib/price.ts src/features/pricing/lib/dynamic-price.ts src/features/pricing/lib/price.test.ts
bunx oxfmt --check src/features/pricing/index.tsx src/features/pricing/components/model-card.tsx src/features/pricing/components/model-card-grid.tsx src/features/pricing/components/pricing-table.tsx src/features/pricing/components/pricing-columns.tsx src/features/pricing/lib/price.ts src/features/pricing/lib/dynamic-price.ts src/features/pricing/lib/price.test.ts
bun run build

Summary by CodeRabbit

  • Tests
    • Added automated frontend test checks for relevant pull requests.
    • Tests run with a locked dependency setup and read-only repository access.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 58fc5e0a-80cf-4c18-b116-3d0d35de2501

📥 Commits

Reviewing files that changed from the base of the PR and between 1e72b4a and 84e2348.

📒 Files selected for processing (1)
  • .github/workflows/frontend-test.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/frontend-test.yml

Walkthrough

The pull-request workflow runs frontend tests when files under web/** or the workflow change. It checks out the repository, installs Bun, installs dependencies with the frozen lockfile, and runs tests from web.

Changes

Frontend test automation

Layer / File(s) Summary
Frontend test workflow
.github/workflows/frontend-test.yml
Adds a pull-request workflow with scoped path triggers, read-only contents permission, pinned checkout and Bun setup actions, frozen-lockfile dependency installation, and frontend test execution.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hops where workflows run,
Bun is ready in the sun.
Locked files guide each test in flight,
Web checks sparkle clean and bright.
“Hop!” says the rabbit, “all is right!”

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes a pricing display fix, but the changeset only adds a frontend test workflow. Update the title to describe the workflow change, or include the pricing display implementation in this pull request.
Linked Issues check ⚠️ Warning The pull request does not implement issue #5341; it only adds a GitHub Actions workflow for frontend tests. Add the frontend changes that display the selected group’s pricing ratio, and retain or update the workflow as needed.
Out of Scope Changes check ⚠️ Warning The added GitHub Actions workflow is unrelated to the pricing display objective in issue #5341. Move the workflow change to a separate pull request or include the required pricing display implementation.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
web/default/src/features/pricing/components/model-card.tsx (2)

92-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a component-level regression test for group-based price switching.

Since this PR's core objective is fixing "model square displays wrong price after changing group," an RTL test rendering ModelCard with different selectedGroup/groupRatio props and asserting the displayed price text changes accordingly would directly protect against this regression recurring. Per path instructions, tests should "focus on user interactions and behavior rather than implementation details" and "protect real user behavior... or explicit regressions."

🤖 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/features/pricing/components/model-card.tsx` around lines 92 -
198, Add a component-level RTL regression test for ModelCard that renders with
different selectedGroup and groupRatio props and verifies the displayed price
text updates when the group changes. Use the ModelCard component and the
price-rendering branches driven by formatPrice/formatRequestPrice to assert
user-visible behavior rather than internals, so the “wrong price after changing
group” bug stays covered.

Source: Path instructions


92-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting priceContent computation into a helper/hook.

This branch chain now spans ~107 lines and repeats near-identical 8-argument formatPrice/formatRequestPrice calls for input/output/cache. Per path instructions, "Keep functions readable by controlling cyclomatic complexity, splitting complex logic into small functions" and "Keep files reasonably small; when a single file grows beyond about 200 lines, consider extracting subcomponents or custom hooks." This file is already near/over that threshold with this addition.

Extracting a small usePriceContent(model, options) hook (or a formatModelPriceLine(type, label) helper to remove the triple-duplicated argument list) would reduce ModelCard's complexity and centralize this rendering logic for reuse (e.g., in future price-display surfaces).

🤖 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/features/pricing/components/model-card.tsx` around lines 92 -
198, The `ModelCard` price rendering logic is too large and duplicated, so
extract the `priceContent` branch chain into a small helper or hook such as
`usePriceContent` or a formatting helper around
`formatPrice`/`formatRequestPrice`. Move the repeated input/output/cache
rendering and shared argument list into a reusable function, keeping `ModelCard`
focused on layout and making the pricing logic easier to read and maintain.

Source: Path instructions

web/default/src/features/pricing/lib/dynamic-price.ts (1)

68-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate ratio-selection logic vs. price.ts's getDisplayGroupRatio.

This function reimplements the same "selected-group-or-min-ratio" algorithm already added in price.ts's getDisplayGroupRatio (lines 77-87 of that file), just with a model-based signature instead of (enableGroups, groupRatio). Both compute the min-ratio fallback independently:

if (selectedGroup && groups.includes(selectedGroup)) {
    return ratios[selectedGroup] ?? 1
}
... inline min-ratio loop ...

vs. price.ts's delegation to getMinGroupRatio. Keeping two independent implementations risks them drifting out of sync (e.g., one gets a bugfix the other doesn't). Consider exporting getDisplayGroupRatio from price.ts and having this function derive enableGroups/ratios from model before delegating to it.

♻️ Suggested consolidation
+import { getDisplayGroupRatio } from './price'
+
 export function getDynamicDisplayGroupRatio(
   model: PricingModel,
   selectedGroup?: string,
   displayGroupRatio?: Record<string, number>
 ): number {
   const groups = Array.isArray(model.enable_groups) ? model.enable_groups : []
   const ratios = displayGroupRatio ?? model.group_ratio ?? {}
-  if (groups.length === 0) return 1
-  if (selectedGroup && groups.includes(selectedGroup)) {
-    return ratios[selectedGroup] ?? 1
-  }
-
-  let minRatio = Number.POSITIVE_INFINITY
-  for (const group of groups) {
-    const ratio = ratios[group]
-    if (ratio !== undefined && ratio < minRatio) {
-      minRatio = ratio
-    }
-  }
-
-  return minRatio === Number.POSITIVE_INFINITY ? 1 : minRatio
+  if (groups.length === 0) return 1
+  return getDisplayGroupRatio(groups, ratios, selectedGroup)
 }

(requires exporting getDisplayGroupRatio from price.ts)

🤖 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/features/pricing/lib/dynamic-price.ts` around lines 68 - 89,
The ratio-selection logic in getDynamicDisplayGroupRatio duplicates the same
selected-group-or-min-ratio behavior already implemented in price.ts’s
getDisplayGroupRatio, so consolidate the shared logic there instead of
maintaining two versions. Refactor getDynamicDisplayGroupRatio to derive
enableGroups and ratios from model, then delegate to the exported
getDisplayGroupRatio from price.ts (or a shared helper used by it), keeping the
model-specific wrapper thin and avoiding a separate min-ratio loop.
🤖 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.

Inline comments:
In `@web/default/src/features/pricing/lib/price.test.ts`:
- Around line 1-2: The pricing test in price.test.ts is using node:test and
node:assert, but it needs to follow the repo’s Vitest setup so it actually runs.
Update the test in price.test.ts to use vitest imports like
describe/test/expect, and add a web/default test script so the package’s tests
are picked up by CI and local runs.

---

Nitpick comments:
In `@web/default/src/features/pricing/components/model-card.tsx`:
- Around line 92-198: Add a component-level RTL regression test for ModelCard
that renders with different selectedGroup and groupRatio props and verifies the
displayed price text updates when the group changes. Use the ModelCard component
and the price-rendering branches driven by formatPrice/formatRequestPrice to
assert user-visible behavior rather than internals, so the “wrong price after
changing group” bug stays covered.
- Around line 92-198: The `ModelCard` price rendering logic is too large and
duplicated, so extract the `priceContent` branch chain into a small helper or
hook such as `usePriceContent` or a formatting helper around
`formatPrice`/`formatRequestPrice`. Move the repeated input/output/cache
rendering and shared argument list into a reusable function, keeping `ModelCard`
focused on layout and making the pricing logic easier to read and maintain.

In `@web/default/src/features/pricing/lib/dynamic-price.ts`:
- Around line 68-89: The ratio-selection logic in getDynamicDisplayGroupRatio
duplicates the same selected-group-or-min-ratio behavior already implemented in
price.ts’s getDisplayGroupRatio, so consolidate the shared logic there instead
of maintaining two versions. Refactor getDynamicDisplayGroupRatio to derive
enableGroups and ratios from model, then delegate to the exported
getDisplayGroupRatio from price.ts (or a shared helper used by it), keeping the
model-specific wrapper thin and avoiding a separate min-ratio loop.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aaea7169-7bdd-4561-b908-b34253414f73

📥 Commits

Reviewing files that changed from the base of the PR and between 153d7f0 and 1672d00.

📒 Files selected for processing (8)
  • web/default/src/features/pricing/components/model-card-grid.tsx
  • web/default/src/features/pricing/components/model-card.tsx
  • web/default/src/features/pricing/components/pricing-columns.tsx
  • web/default/src/features/pricing/components/pricing-table.tsx
  • web/default/src/features/pricing/index.tsx
  • web/default/src/features/pricing/lib/dynamic-price.ts
  • web/default/src/features/pricing/lib/price.test.ts
  • web/default/src/features/pricing/lib/price.ts

Comment on lines +1 to +2
import assert from 'node:assert/strict'
import { describe, test } from 'node:test'

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== repo files of interest =='
git ls-files | rg '(^|/)(package.json|bunfig\.toml|vitest\.config\.[cm]?[jt]s|vite\.config\.[cm]?[jt]s|tsconfig.*json|AGENTS\.md|price\.test\.ts|price\.ts)$'

echo
echo '== package.json scripts =='
sed -n '1,220p' package.json

echo
echo '== web/default package.json scripts (if present) =='
if [ -f web/default/package.json ]; then
  sed -n '1,220p' web/default/package.json
fi

echo
echo '== bun config =='
if [ -f bunfig.toml ]; then
  sed -n '1,200p' bunfig.toml
fi

echo
echo '== vitest / test config candidates =='
for f in $(git ls-files | rg '(^|/)(vitest\.config\.[cm]?[jt]s|vite\.config\.[cm]?[jt]s|package.json|bunfig\.toml)$'); do
  echo "--- $f"
  sed -n '1,220p' "$f"
done

echo
echo '== feature test file =='
sed -n '1,220p' web/default/src/features/pricing/lib/price.test.ts

echo
echo '== search for node:test and vitest usage in tests =='
rg -n --glob '**/*.test.ts' --glob '**/*.test.tsx' "from 'node:test'|from 'vitest'|node:assert|assert\.equal|expect\(" web/default/src

Repository: QuantumNous/new-api

Length of output: 575


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== web/default/package.json =='
sed -n '1,240p' web/default/package.json

echo
echo '== web/default/AGENTS.md =='
sed -n '1,260p' web/default/AGENTS.md

echo
echo '== CI/workflow files mentioning test or bun =='
git ls-files '.github/workflows/*' | while read -r f; do
  if rg -n "bun|vitest|test" "$f" >/dev/null; then
    echo "--- $f"
    rg -n "bun|vitest|test" "$f"
  fi
done

echo
echo '== search for test scripts and vitest config under web/default =='
rg -n --glob 'web/default/**' "vitest|bun run test|bun test|test:" web/default

Repository: QuantumNous/new-api

Length of output: 13813


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== web/package.json =='
sed -n '1,240p' web/package.json

echo
echo '== .github/workflows/pr-check.yml =='
sed -n '1,240p' .github/workflows/pr-check.yml

echo
echo '== search for test commands in workflows =='
rg -n "bun run test|bun test|vitest|node:test|npm test|pnpm test|yarn test" .github/workflows web/package.json web/default/package.json

Repository: QuantumNous/new-api

Length of output: 2072


Wire web/default tests into Vitest
price.test.ts isn’t picked up by any current test script or CI job, so it won’t run as-is. Add a test script for web/default and switch this file to vitest/expect to match the repo’s test convention.

🤖 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/features/pricing/lib/price.test.ts` around lines 1 - 2, The
pricing test in price.test.ts is using node:test and node:assert, but it needs
to follow the repo’s Vitest setup so it actually runs. Update the test in
price.test.ts to use vitest imports like describe/test/expect, and add a
web/default test script so the package’s tests are picked up by CI and local
runs.

Source: Path instructions

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/frontend-test.yml (1)

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

Pin the Bun version.

bun-version: latest changes the CI runtime without a repository change. Use the version declared by the repository, or pin an exact version and update it intentionally.

🤖 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 @.github/workflows/frontend-test.yml around lines 17 - 19, Update the
bun-version setting in the setup-bun step to use the repository’s declared Bun
version, or replace latest with an exact intentionally maintained version. Keep
the existing oven-sh/setup-bun action and other workflow settings unchanged.
🤖 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.

Inline comments:
In @.github/workflows/frontend-test.yml:
- Line 16: Update the actions/checkout step in the workflow to set
persist-credentials to false, unless a later step requires authenticated Git
operations; leave the existing checkout action version unchanged.
- Around line 5-7: Update the pull_request path filters in the frontend-test
workflow to include web/package.json and web/bun.lock alongside the existing
web/default and workflow paths, so workspace installation input changes trigger
the job.

---

Nitpick comments:
In @.github/workflows/frontend-test.yml:
- Around line 17-19: Update the bun-version setting in the setup-bun step to use
the repository’s declared Bun version, or replace latest with an exact
intentionally maintained version. Keep the existing oven-sh/setup-bun action and
other workflow settings unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5a8ebd0-0ddb-4aa2-b98d-63542818c6f4

📥 Commits

Reviewing files that changed from the base of the PR and between 00a236e and 1e72b4a.

📒 Files selected for processing (1)
  • .github/workflows/frontend-test.yml

Comment thread .github/workflows/frontend-test.yml
test-default-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow =="
if [ -f .github/workflows/frontend-test.yml ]; then
  nl -ba .github/workflows/frontend-test.yml | sed -n '1,120p'
else
  echo "missing .github/workflows/frontend-test.yml"
fi

echo
echo "== checkout uses in workflows =="
rg -n "actions/checkout|persist-credentials|git config|GITHUB_TOKEN|bun install|bun test" .github/workflows || true

Repository: QuantumNous/new-api

Length of output: 212


🌐 Web query:

actions checkout persist-credentials default true README

💡 Result:

In the actions/checkout GitHub Action, the persist-credentials input determines whether the authentication token or SSH key used for the checkout is configured within the local git config [1][2]. By default, persist-credentials is set to true [1][3][4]. When enabled, this allows your subsequent workflow steps to run authenticated git commands (such as git push or git fetch) without requiring additional configuration [1][2]. The token or key is automatically removed during the post-job cleanup phase [1][2]. If you wish to prevent the credentials from being configured in the local git config, you can explicitly set persist-credentials: false in your workflow file [1][2]. Note: Recent improvements to the action (as of v6.0.0 and later) have enhanced security by storing these credentials in a separate file under $RUNNER_TEMP rather than directly in.git/config, though the default behavior of enabling persistence remains [1][5]. While there have been discussions and proposals regarding changing this default to false to reduce security risks, it remains true in the current implementation [6][3][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -u

echo "== workflow =="
if [ -f .github/workflows/frontend-test.yml ]; then
  awk '{printf "%4d:%s\n", NR, $0}' .github/workflows/frontend-test.yml | sed -n '1,140p'
else
  echo "missing .github/workflows/frontend-test.yml"
fi

echo
echo "== checkout uses in workflows =="
rg -n "actions/checkout|persist-credentials|git config|GITHUB_TOKEN|bun install|bun test" .github/workflows || true

Repository: QuantumNous/new-api

Length of output: 2965


Disable checkout credential persistence.

actions/checkout persists checkout credentials by default. Add persist-credentials: false unless this workflow needs later authenticated Git operations.

🧰 Tools
🪛 zizmor (1.28.0)

[warning] 16-16: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 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 @.github/workflows/frontend-test.yml at line 16, Update the actions/checkout
step in the workflow to set persist-credentials to false, unless a later step
requires authenticated Git operations; leave the existing checkout action
version unchanged.

Source: Linters/SAST tools

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