Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(billing): 统一余额文案并补充模型列表入口 (#4674)

GaoWei Liuf79e4f561e7c
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
index fcadd0b7a4..80c1bf8d9f 100644
--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx
+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
@@ -2360,7 +2360,7 @@ function BillingOfferDialog({
}),
)}
freeAction={t('billing.comparison.topup')}
- freeHint={t('billing.comparison.topupUnlock')}
+ onViewModels={onClose}
onFreeAction={() => onTopup?.()}
/>
)}
diff --git a/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx b/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx
index 8948028651..79766ba0ef 100644
--- a/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx
+++ b/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx
@@ -308,7 +308,7 @@ export function PlanChangeTargetDialog({
<PlanComparison
plans={sortedPlans}
freeAction={t('billing.comparison.topup')}
- freeHint={t('billing.comparison.topupUnlock')}
+ onViewModels={onClose}
freeDisabled={topupDisabled || !onTopup}
onFreeAction={() => onTopup?.()}
/>
diff --git a/apps/desktop/src/renderer/features/billing/PlanComparison.tsx b/apps/desktop/src/renderer/features/billing/PlanComparison.tsx
index fdabd86e4c..e100ecaf3f 100644
--- a/apps/desktop/src/renderer/features/billing/PlanComparison.tsx
+++ b/apps/desktop/src/renderer/features/billing/PlanComparison.tsx
@@ -1,6 +1,6 @@
import type { RefObject } from 'react';
import { Check } from 'lucide-react';
-import { useTranslation } from 'react-i18next';
+import { Trans, useTranslation } from 'react-i18next';
import type { BillingCatalogOffer, BillingCatalogProduct } from '../../../shared/billing';
import { formatBillingAmount } from './money';
@@ -25,13 +25,13 @@ export type ComparisonPlan = {
export function PlanComparison({
plans,
freeAction,
- freeHint,
+ onViewModels,
onFreeAction,
freeDisabled = false,
}: {
plans: ComparisonPlan[];
freeAction: string;
- freeHint: string;
+ onViewModels: () => void;
onFreeAction: () => void;
freeDisabled?: boolean;
}) {
@@ -77,10 +77,19 @@ export function PlanComparison({
const currency = selected[0]?.entry?.offer.currency;
const buttonClass =
'flex min-h-9 w-full items-center justify-center rounded-full border border-[var(--border-default)] px-3 py-2 text-13 font-medium transition-colors enabled:hover:bg-[var(--surface-hover-soft)] enabled:active:bg-[var(--surface-chip)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)] disabled:cursor-not-allowed disabled:opacity-50';
+ const modelsLink = (
+ <a
+ href="#/settings?tab=providers&connect=xd"
+ onClick={onViewModels}
+ className="underline underline-offset-4 hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"
+ >
+ {t('billing.comparison.advancedModels')}
+ </a>
+ );
const feature = (key: string) => (
<li key={key} className="flex items-start gap-2 text-13 leading-relaxed">
<Check size={15} className="mt-0.5 shrink-0 text-[var(--text-secondary)]" aria-hidden />
- <span>{t(`billing.comparison.${key}`)}</span>
+ {key === 'advancedModels' ? modelsLink : <span>{t(`billing.comparison.${key}`)}</span>}
</li>
);
return (
@@ -104,7 +113,9 @@ export function PlanComparison({
{['agent', 'apiKey', 'existingSubscription', 'localModels', 'basicModels'].map(feature)}
</ul>
<div className="mt-auto">
- <p className="mb-3 text-11 leading-relaxed text-[var(--text-secondary)]">{freeHint}</p>
+ <p className="mb-3 text-11 leading-relaxed text-[var(--text-secondary)]">
+ <Trans i18nKey="billing.comparison.topupUnlock" components={{ models: modelsLink }} />
+ </p>
<button
type="button"
className={buttonClass}
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
index 03cb4580b9..1a0fe848d4 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
@@ -53,7 +53,8 @@ const checkout = {
close: vi.fn(),
};
-vi.mock('react-i18next', () => ({
+vi.mock('react-i18next', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('react-i18next')>()),
useTranslation: () => ({
i18n,
t: (key: string, params?: Record<string, string>) => {
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx
index a5c9939cdc..feec1ee4d4 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx
@@ -3,7 +3,8 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
-vi.mock('react-i18next', () => ({
+vi.mock('react-i18next', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('react-i18next')>()),
useTranslation: () => ({
i18n: { language: 'en', resolvedLanguage: 'en' },
t: (key: string, params?: Record<string, string>) =>
@@ -270,6 +271,11 @@ describe('PlanChangeTargetDialog product-first selection', () => {
true,
);
expect(screen.queryByRole('combobox')).toBeNull();
+ const modelLinks = screen.getAllByRole('link', { name: 'billing.comparison.advancedModels' });
+ expect(modelLinks).toHaveLength(2);
+ for (const link of modelLinks) {
+ expect(link.getAttribute('href')).toBe('#/settings?tab=providers&connect=xd');
+ }
fireEvent.click(screen.getByRole('button', { name: 'billing.catalog.currentPlan' }));
expect(onSelect).not.toHaveBeenCalled();
});
@@ -337,7 +343,7 @@ describe('PlanChangeTargetDialog product-first selection', () => {
},
]}
freeAction="Top up"
- freeHint=""
+ onViewModels={vi.fn()}
onFreeAction={vi.fn()}
/>,
);
@@ -346,6 +352,28 @@ describe('PlanChangeTargetDialog product-first selection', () => {
expect(screen.queryByRole('button', { name: 'Select' })).toBeNull();
});
+ it('links model access to Cindy AI and closes the purchase comparison', () => {
+ const onViewModels = vi.fn();
+ render(
+ <PlanComparison
+ plans={[
+ {
+ product: currentPlan.product,
+ defaultOfferCode: currentPlan.offer.code,
+ offers: [{ offer: currentPlan.offer, action: 'Select', onSelect: vi.fn() }],
+ },
+ ]}
+ freeAction="Top up"
+ onViewModels={onViewModels}
+ onFreeAction={vi.fn()}
+ />,
+ );
+ const link = screen.getByRole('link', { name: 'billing.comparison.advancedModels' });
+ expect(link.getAttribute('href')).toBe('#/settings?tab=providers&connect=xd');
+ fireEvent.click(link);
+ expect(onViewModels).toHaveBeenCalledOnce();
+ });
+
it('uses the remaining server Offer when the default Offer disappears', () => {
const onSelect = vi.fn();
const view = render(
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 93e22777d3..f509110ee1 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -12501,37 +12501,37 @@
"undo": "Undo downgrade"
},
"comparison": {
- "select": "Select {{name}}",
- "topup": "Add funds",
- "topupUnlock": "Add funds to unlock extra usage.",
- "rollover": "{{amount}} rolls over to {{period}}",
- "changeUnavailable": "This change is unavailable",
- "upgrade": "Upgrade",
- "downgrade": "Downgrade",
- "free": "Free",
- "freeUsage": "Pay as you go",
- "topupExpiry": "Added funds stay until used",
- "priceFromSuffix": "from",
- "subscription": "Subscription",
- "includesFree": "Includes everything in Free",
- "creditMultiple": "{{multiple}}x the included amount of {{name}}",
- "credits": {
- "MONTH": "{{amount}} per month",
- "YEAR": "{{amount}} per year",
- "OTHER": "{{amount}}"
- },
+ "free": "FREE",
+ "freeUsage": "Free to use",
+ "priceFromSuffix": "and up",
+ "topup": "Top up as needed",
+ "topupExpiry": "Top-up balance never expires",
+ "agent": "Full Agent features",
+ "apiKey": "Bring your own API key",
+ "existingSubscription": "Connect existing subscriptions",
+ "localModels": "Use local models",
+ "basicModels": "Access some models",
+ "subscription": "Subscription plan",
+ "rollover": "Keep up to {{amount}} in unused balance for {{period}}",
"nextPeriod": {
"MONTH": "next month",
"YEAR": "next year",
"OTHER": "the next period"
},
- "agent": "Agent tasks",
- "apiKey": "Bring your own API keys",
- "existingSubscription": "Use existing subscriptions",
- "localModels": "Local models",
- "basicModels": "Basic models",
- "advancedModels": "Advanced models",
- "managedService": "Managed service"
+ "includesFree": "Everything in FREE",
+ "advancedModels": "Unlock more models",
+ "managedService": "Managed service, no setup",
+ "topupUnlock": "Pay as you go to <models>unlock more models</models>",
+ "select": "Choose {{name}}",
+ "upgrade": "Upgrade to {{name}}",
+ "downgrade": "Downgrade to {{name}}",
+ "changeUnavailable": "Unavailable",
+ "creditMultiple": "{{multiple}}× the included amount per period of {{name}}",
+ "credits": {
+ "MONTH": "Includes {{amount}} each month",
+ "YEAR": "Includes {{amount}} each year",
+ "OTHER": "{{amount}}"
+ }
}
},
"fileAccess": {
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 684f4d616c..d58b11e2b6 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -12484,37 +12484,37 @@
"undo": "ダウングレードを取り消す"
},
"comparison": {
- "select": "{{name}} を選択",
- "topup": "チャージ",
- "topupUnlock": "チャージすると追加利用分を解除できます。",
- "rollover": "{{amount}} は{{period}}へ繰り越されます",
- "changeUnavailable": "この変更はできません",
- "upgrade": "アップグレード",
- "downgrade": "ダウングレード",
- "free": "無料",
- "freeUsage": "従量課金",
- "topupExpiry": "チャージ残高は使い切るまで有効",
- "priceFromSuffix": "から",
+ "free": "FREE",
+ "freeUsage": "無料で利用",
+ "priceFromSuffix": "〜",
+ "topup": "必要な分だけチャージ",
+ "topupExpiry": "チャージ残高は無期限",
+ "agent": "Agent の全機能",
+ "apiKey": "自分の API key を使用",
+ "existingSubscription": "既存のサブスクリプションを接続",
+ "localModels": "ローカルモデルに対応",
+ "basicModels": "一部のモデルを利用",
"subscription": "サブスクリプション",
- "includesFree": "無料プランの内容をすべて含みます",
- "creditMultiple": "{{name}} の {{multiple}} 倍の付与額",
- "credits": {
- "MONTH": "毎月 {{amount}}",
- "YEAR": "毎年 {{amount}}",
- "OTHER": "{{amount}}"
- },
+ "rollover": "未使用残高は{{period}}も利用可能(最大 {{amount}})",
"nextPeriod": {
"MONTH": "翌月",
"YEAR": "翌年",
"OTHER": "次の期間"
},
- "agent": "Agent タスク",
- "apiKey": "独自の API キーを利用",
- "existingSubscription": "既存のサブスクリプションを利用",
- "localModels": "ローカルモデル",
- "basicModels": "基本モデル",
- "advancedModels": "高度なモデル",
- "managedService": "マネージドサービス"
+ "includesFree": "FREE の全機能を含む",
+ "advancedModels": "より多くのモデルを利用可能に",
+ "managedService": "公式サービス、設定不要",
+ "topupUnlock": "必要な分だけ支払い、<models>より多くのモデルを利用可能に</models>",
+ "select": "{{name}} を選択",
+ "upgrade": "{{name}} にアップグレード",
+ "downgrade": "{{name}} にダウングレード",
+ "changeUnavailable": "変更不可",
+ "creditMultiple": "各期間に含まれる金額は {{name}} の {{multiple}} 倍",
+ "credits": {
+ "MONTH": "毎月 {{amount}} を含む",
+ "YEAR": "毎年 {{amount}} を含む",
+ "OTHER": "{{amount}}"
+ }
}
},
"fileAccess": {
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 49eb382af4..603c249381 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -12484,37 +12484,37 @@
"undo": "다운그레이드 취소"
},
"comparison": {
- "select": "{{name}} 선택",
- "topup": "충전",
- "topupUnlock": "충전하면 추가 사용량을 해제할 수 있습니다.",
- "rollover": "{{amount}}이(가) {{period}}(으)로 이월됩니다",
- "changeUnavailable": "이 변경은 사용할 수 없습니다",
- "upgrade": "업그레이드",
- "downgrade": "다운그레이드",
- "free": "무료",
- "freeUsage": "사용한 만큼 결제",
- "topupExpiry": "충전 잔액은 소진될 때까지 유효",
+ "free": "FREE",
+ "freeUsage": "무료 사용",
"priceFromSuffix": "부터",
- "subscription": "구독",
- "includesFree": "무료 플랜의 모든 기능을 포함합니다",
- "creditMultiple": "{{name}} 포함 금액의 {{multiple}}배",
- "credits": {
- "MONTH": "매월 {{amount}}",
- "YEAR": "매년 {{amount}}",
- "OTHER": "{{amount}}"
- },
+ "topup": "필요할 때 충전",
+ "topupExpiry": "충전 잔액은 만료되지 않음",
+ "agent": "모든 Agent 기능",
+ "apiKey": "내 API key 사용",
+ "existingSubscription": "기존 구독 연결",
+ "localModels": "로컬 모델 지원",
+ "basicModels": "일부 모델 사용",
+ "subscription": "구독 요금제",
+ "rollover": "남은 잔액은 {{period}}에 최대 {{amount}}까지 사용 가능",
"nextPeriod": {
"MONTH": "다음 달",
- "YEAR": "내년",
+ "YEAR": "다음 해",
"OTHER": "다음 기간"
},
- "agent": "Agent 작업",
- "apiKey": "자체 API 키 사용",
- "existingSubscription": "기존 구독 사용",
- "localModels": "로컬 모델",
- "basicModels": "기본 모델",
- "advancedModels": "고급 모델",
- "managedService": "관리형 서비스"
+ "includesFree": "FREE의 모든 기능 포함",
+ "advancedModels": "더 많은 모델 잠금 해제",
+ "managedService": "공식 서비스, 설정 불필요",
+ "topupUnlock": "필요한 만큼 결제하고 <models>더 많은 모델 잠금 해제</models>",
+ "select": "{{name}} 선택",
+ "upgrade": "{{name}}(으)로 업그레이드",
+ "downgrade": "{{name}}(으)로 다운그레이드",
+ "changeUnavailable": "변경 불가",
+ "creditMultiple": "기간별 포함 금액은 {{name}}의 {{multiple}}배",
+ "credits": {
+ "MONTH": "매월 {{amount}} 포함",
+ "YEAR": "매년 {{amount}} 포함",
+ "OTHER": "{{amount}}"
+ }
}
},
"fileAccess": {
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index dda0b9b403..be46a21c33 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -12484,37 +12484,37 @@
"undo": "撤销降级"
},
"comparison": {
- "select": "选择{{name}}",
- "topup": "充值",
- "topupUnlock": "充值后可解锁额外用量。",
- "rollover": "{{amount}} 可结转至{{period}}",
- "changeUnavailable": "无法进行此变更",
- "upgrade": "升级",
- "downgrade": "降级",
- "free": "免费",
- "freeUsage": "按量使用",
- "topupExpiry": "充值余额用完为止",
+ "free": "FREE",
+ "freeUsage": "免费使用",
"priceFromSuffix": "起",
- "subscription": "订阅",
- "includesFree": "包含免费版全部能力",
- "creditMultiple": "包含金额是{{name}}的 {{multiple}} 倍",
+ "topup": "按需充值",
+ "topupExpiry": "充值余额不过期",
+ "agent": "完整 Agent 功能",
+ "apiKey": "自带 API key",
+ "existingSubscription": "接入已有订阅",
+ "localModels": "支持本地模型",
+ "basicModels": "可用部分模型",
+ "subscription": "订阅套餐",
+ "rollover": "剩余余额可留到{{period}},最多 {{amount}}",
+ "nextPeriod": {
+ "MONTH": "下月",
+ "YEAR": "下一年",
+ "OTHER": "下期"
+ },
+ "includesFree": "包含 FREE 全部能力",
+ "advancedModels": "解锁更多模型",
+ "managedService": "官方服务,免配置",
+ "topupUnlock": "按需付费,<models>解锁更多模型</models>",
+ "select": "选择 {{name}}",
+ "upgrade": "升级至 {{name}}",
+ "downgrade": "降级至 {{name}}",
+ "changeUnavailable": "暂不可切换",
+ "creditMultiple": "每期包含金额为 {{name}} 的 {{multiple}} 倍",
"credits": {
- "MONTH": "每月 {{amount}}",
- "YEAR": "每年 {{amount}}",
+ "MONTH": "每月包含 {{amount}}",
+ "YEAR": "每年包含 {{amount}}",
"OTHER": "{{amount}}"
- },
- "nextPeriod": {
- "MONTH": "下个月",
- "YEAR": "明年",
- "OTHER": "下一周期"
- },
- "agent": "Agent 任务",
- "apiKey": "使用自有 API Key",
- "existingSubscription": "沿用已有订阅",
- "localModels": "本地模型",
- "basicModels": "基础模型",
- "advancedModels": "进阶模型",
- "managedService": "托管服务"
+ }
}
},
"fileAccess": {
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index ac85598855..2177809340 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -12484,37 +12484,37 @@
"undo": "撤銷降級"
},
"comparison": {
- "select": "選擇{{name}}",
- "topup": "儲值",
- "topupUnlock": "儲值後可解鎖額外用量。",
- "rollover": "{{amount}} 可結轉至{{period}}",
- "changeUnavailable": "無法進行此變更",
- "upgrade": "升級",
- "downgrade": "降級",
- "free": "免費",
- "freeUsage": "按量使用",
- "topupExpiry": "儲值餘額用完為止",
+ "free": "FREE",
+ "freeUsage": "免費使用",
"priceFromSuffix": "起",
- "subscription": "訂閱",
- "includesFree": "包含免費版全部能力",
- "creditMultiple": "包含金額是{{name}}的 {{multiple}} 倍",
- "credits": {
- "MONTH": "每月 {{amount}}",
- "YEAR": "每年 {{amount}}",
- "OTHER": "{{amount}}"
- },
+ "topup": "按需儲值",
+ "topupExpiry": "儲值餘額不過期",
+ "agent": "完整 Agent 功能",
+ "apiKey": "自備 API key",
+ "existingSubscription": "接入現有訂閱",
+ "localModels": "支援本機模型",
+ "basicModels": "可用部分模型",
+ "subscription": "訂閱方案",
+ "rollover": "剩餘餘額可留到{{period}},最多 {{amount}}",
"nextPeriod": {
"MONTH": "下個月",
- "YEAR": "明年",
- "OTHER": "下一週期"
- },
- "agent": "Agent 任務",
- "apiKey": "使用自有 API Key",
- "existingSubscription": "沿用既有訂閱",
- "localModels": "本機模型",
- "basicModels": "基礎模型",
- "advancedModels": "進階模型",
- "managedService": "託管服務"
+ "YEAR": "下一年",
+ "OTHER": "下期"
+ },
+ "includesFree": "包含 FREE 全部功能",
+ "advancedModels": "解鎖更多模型",
+ "managedService": "官方服務,免設定",
+ "topupUnlock": "按需付費,<models>解鎖更多模型</models>",
+ "select": "選擇 {{name}}",
+ "upgrade": "升級至 {{name}}",
+ "downgrade": "降級至 {{name}}",
+ "changeUnavailable": "暫不可切換",
+ "creditMultiple": "每期包含金額為 {{name}} 的 {{multiple}} 倍",
+ "credits": {
+ "MONTH": "每月包含 {{amount}}",
+ "YEAR": "每年包含 {{amount}}",
+ "OTHER": "{{amount}}"
+ }
}
},
"fileAccess": {
diff --git a/docs/assets/billing-subscription/model-copy-change-dark.png b/docs/assets/billing-subscription/model-copy-change-dark.png
new file mode 100644
index 0000000000..06d06f9a86
Binary files /dev/null and b/docs/assets/billing-subscription/model-copy-change-dark.png differ
diff --git a/docs/assets/billing-subscription/model-copy-change-light.png b/docs/assets/billing-subscription/model-copy-change-light.png
new file mode 100644
index 0000000000..3ccebbaa21
Binary files /dev/null and b/docs/assets/billing-subscription/model-copy-change-light.png differ
diff --git a/docs/assets/billing-subscription/model-copy-purchase-dark.png b/docs/assets/billing-subscription/model-copy-purchase-dark.png
new file mode 100644
index 0000000000..e731cb5d20
Binary files /dev/null and b/docs/assets/billing-subscription/model-copy-purchase-dark.png differ
diff --git a/docs/assets/billing-subscription/model-copy-purchase-light.png b/docs/assets/billing-subscription/model-copy-purchase-light.png
new file mode 100644
index 0000000000..ac33aed59e
Binary files /dev/null and b/docs/assets/billing-subscription/model-copy-purchase-light.png differ
diff --git a/scripts/__tests__/glossary-rules.test.mjs b/scripts/__tests__/glossary-rules.test.mjs
index b5810f0ea9..344668d597 100644
--- a/scripts/__tests__/glossary-rules.test.mjs
+++ b/scripts/__tests__/glossary-rules.test.mjs
@@ -191,6 +191,57 @@ test('hasAsciiEllipsis: 识别三点省略号', () => {
const glossary = JSON.parse(fs.readFileSync(path.join(ROOT, 'i18n', 'glossary.json'), 'utf8'));
+test('Desktop billing: 金额和余额文案不得恢复 Credits / 点数', () => {
+ // PR #1053 的裁决只约束 Cindy 计费文案,不扫描 ChatGPT / Codex 原生 credits。
+ // 保留 billing.comparison.credits 等 key;检查的是用户看到的值。
+ const credits = glossary.terms.find((term) => term.id === 'credits');
+ assert.ok(credits);
+ const creditMatcher = makeSourceTermMatcher('Credit');
+ const violations = [];
+ for (const locale of glossary.locales) {
+ const file = path.join(
+ ROOT,
+ 'apps',
+ 'desktop',
+ 'src',
+ 'renderer',
+ 'i18n',
+ 'locales',
+ locale,
+ 'common.json',
+ );
+ const { billing } = JSON.parse(fs.readFileSync(file, 'utf8'));
+ assert.ok(
+ billing && typeof billing === 'object',
+ `${locale}: 缺少 billing 文案`,
+ );
+ const scan = (obj, prefix) => {
+ for (const [key, value] of Object.entries(obj)) {
+ const keyPath = `${prefix}.${key}`;
+ if (value && typeof value === 'object') {
+ scan(value, keyPath);
+ } else if (typeof value === 'string') {
+ // Credit card 是支付方式,不是被弃用的计费点数。
+ const prose = stripNonProse(value).replace(/\bcredit cards?\b/gi, '');
+ const translated = credits.translations[locale];
+ if (
+ creditMatcher.test(prose) ||
+ (translated && occursIn(prose, translated))
+ ) {
+ violations.push(`${locale}:${keyPath}: ${value}`);
+ }
+ }
+ }
+ };
+ scan(billing, 'billing');
+ }
+ assert.deepEqual(
+ violations,
+ [],
+ 'Cindy 计费文案须使用金额/余额,详见 glossary 的 credits 条目',
+ );
+});
+
test('glossary.json: id 唯一且格式合法', () => {
const ids = glossary.terms.map((t) => t.id);
assert.equal(new Set(ids).size, ids.length, '术语 id 必须唯一——baseline 用它做锚点');