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(models): preserve distinct displayed price range endpoints

fmfsaisai509971991b8a
diff --git a/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts b/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts
index e7d8a2b973..32213aff0c 100644
--- a/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts
+++ b/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts
@@ -37,6 +37,17 @@ it('discounts both range endpoints without marking a zero lower bound as free',
expect(displayPricingAmount({ price: 0, maxPrice: 10 }, 'USD', 1, 'en'))
.toEqual({ current: '$0', original: '$0–$10', free: true });
});
+// Unit regression: distinct range endpoints rounded to the same visible amount ($1–$1).
+// Existing ranges differed within eight significant digits; exercise close and adjacent doubles
+// through displayPricingAmount, for both discounted and original prices.
+it.each([
+ [1.000000002, '$0.5–$0.500000001', '$1–$1.000000002'],
+ [1 + Number.EPSILON, '$0.5–$0.5000000000000001', '$1–$1.0000000000000002'],
+])('keeps the upper bound %s distinguishable after rounding', (maxPrice, current, original) => {
+ expect(displayPricingAmount({ price: 1, maxPrice: maxPrice as number }, 'USD', 0.5, 'en'))
+ .toEqual({ current, original, free: false });
+});
+
// Unit contract: quantity 1 is omitted; million is localized; arbitrary values retain their basis.
it.each([
[1, 'en', '1M', ''], [1000000, 'zh-CN', '百万', '百万'],
diff --git a/apps/desktop/src/renderer/lib/displayPricingFormat.ts b/apps/desktop/src/renderer/lib/displayPricingFormat.ts
index e8776c247a..faef3009e1 100644
--- a/apps/desktop/src/renderer/lib/displayPricingFormat.ts
+++ b/apps/desktop/src/renderer/lib/displayPricingFormat.ts
@@ -23,8 +23,22 @@ export function displayPricingAmount(
const symbol = currency === 'CNY' ? '¥' : '$';
const money = (value: number) => `${symbol}${number.format(value)}`;
const upper = item.maxPrice ?? item.price;
- const range = (low: number, high: number) =>
- low === high ? money(low) : `${money(low)}–${money(high)}`;
+ const range = (low: number, high: number) => {
+ if (low === high) return money(low);
+ let lowText = number.format(low);
+ let highText = number.format(high);
+ // Raise precision only when rounding would hide a distinct upper bound.
+ // Seventeen significant digits distinguish all finite JavaScript numbers.
+ for (let digits = 9; lowText === highText && digits <= 17; digits++) {
+ const precise = new Intl.NumberFormat(locale, {
+ maximumSignificantDigits: digits,
+ useGrouping: false,
+ });
+ lowText = precise.format(low);
+ highText = precise.format(high);
+ }
+ return `${symbol}${lowText}–${symbol}${highText}`;
+ };
return {
current: range(amount, upper * (1 - discount)),
...(discount > 0 && upper > 0 ? { original: range(item.price, upper) } : {}),