From 254afdbad98320ee99780ee75983ae856699927d Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 16:00:41 +0000 Subject: [PATCH] fix(billing): say "1 Credit" for a one-credit activity charge (#22472) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *PR Created by the Glary-Bot Agent* --- Fixes FRONT-3751. Follow-up to #22470 (merged). ## Problem In Settings > Plan & Credits > Activity, a charge that rounds to one credit shows `Charge: 1 Credits`. The unit word was always `t('credits.credits')`. ## Change - New plural key `credits.creditUnit`: `"Credit | Credits"`. - The charge tooltip now picks the unit by the whole number it shows, `t('credits.creditUnit', Math.round(credits))`: - 1 → `1 Credit` - 0 and 2+ → `Credits` - under one credit → `<1 Credits` (unchanged) - #17858 moved the tooltip from `UsageLogsTable.vue` into `customerEventsService.ts` after this PR was opened. Main is merged in and the change now lives in `formatChargeCredits` there. The unit word is appended, not built into a `{amount} Credit` message: vue-i18n HTML-escapes named params here, so passing the amount as a param would turn `<1` into `<1`. ## Locales `creditUnit` is also added to the other locales with each locale's existing word for "credits" (one form), so non-English users keep their own word instead of the English fallback. The release translation pass can add plural forms. ## Tests - `customerEventsService.test.ts`: every charge row now pins the plural count passed (7, 8, 0, 1, and 2 for `<1`), plus the English `Credit`/`Credits` forms for 0, 1, 2 and 7. Seen failing before the fix (9 failures), green after: 103/103 with `UsageLogsTable.test.ts`. - Browser test `usageLogsChargeTooltip.spec.ts`: new one-credit case (4,740 micro USD, GPU Usage row) asserts `Charge: 1 Credit` and no `1 Credits`, with a snapshot. - Typecheck (app and browser tests), oxfmt and lint clean. ## Screenshot One-credit tooltip baseline from CI (4,740 micro USD), rendered `Charge: 1 Credit`: ![one-credit tooltip](https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/5c5a10383921c8424c1726bff5a93d020120e2c7/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts-snapshots/activity-charge-tooltip-one-credit-chromium-linux.png) --------- Co-authored-by: github-actions Co-authored-by: Glary-Bot --- browser_tests/fixtures/data/customerEvents.ts | 14 +++++- .../dialogs/usageLogsChargeTooltip.spec.ts | 15 +++++++ ...arge-tooltip-one-credit-chromium-linux.png | Bin 0 -> 2915 bytes src/locales/ar/main.json | 1 + src/locales/de/main.json | 1 + src/locales/en/main.json | 1 + src/locales/es/main.json | 1 + src/locales/fa/main.json | 1 + src/locales/fr/main.json | 1 + src/locales/he/main.json | 1 + src/locales/it/main.json | 1 + src/locales/ja/main.json | 1 + src/locales/ko/main.json | 1 + src/locales/pt-BR/main.json | 1 + src/locales/ru/main.json | 1 + src/locales/tr/main.json | 1 + src/locales/zh-TW/main.json | 1 + src/locales/zh/main.json | 1 + src/services/customerEventsService.test.ts | 40 +++++++++++++----- src/services/customerEventsService.ts | 17 ++++---- 20 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts-snapshots/activity-charge-tooltip-one-credit-chromium-linux.png diff --git a/browser_tests/fixtures/data/customerEvents.ts b/browser_tests/fixtures/data/customerEvents.ts index 797b68ad0d1..a84e7efcc0a 100644 --- a/browser_tests/fixtures/data/customerEvents.ts +++ b/browser_tests/fixtures/data/customerEvents.ts @@ -4,8 +4,9 @@ import type { BillingEventsResponse } from '@comfyorg/ingest-types' export const AGENT_USAGE_EVENT_TYPE = 'Agent Usage' export const PARTNER_NODE_USAGE_EVENT_TYPE = 'Partner Node Usage' export const API_USAGE_EVENT_TYPE = 'API Usage' +export const GPU_USAGE_EVENT_TYPE = 'GPU Usage' -/** `/api/billing/events` page with whole, sub-credit and non-numeric `charge_micro_usd`. */ +/** `/api/billing/events` page with whole, one-credit, sub-credit and non-numeric `charge_micro_usd`. */ export const AGENT_USAGE_CUSTOMER_EVENTS = { events: [ { @@ -28,6 +29,15 @@ export const AGENT_USAGE_CUSTOMER_EVENTS = { input_tokens: 96 } }, + { + event_id: 'evt-gpu-usage-one-credit', + event_type: 'gpu_usage', + createdAt: '2026-09-20T11:15:00Z', + params: { + charge_micro_usd: 4_740, + gpu_seconds: 3 + } + }, { event_id: 'evt-partner-node-usage', event_type: 'api_node_usage', @@ -40,6 +50,6 @@ export const AGENT_USAGE_CUSTOMER_EVENTS = { ], page: 1, limit: 7, - total: 3, + total: 4, totalPages: 1 } satisfies BillingEventsResponse diff --git a/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts b/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts index 43cc5b17d42..dcb50185d77 100644 --- a/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts +++ b/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts @@ -6,6 +6,7 @@ import { AGENT_USAGE_CUSTOMER_EVENTS, AGENT_USAGE_EVENT_TYPE, API_USAGE_EVENT_TYPE, + GPU_USAGE_EVENT_TYPE, PARTNER_NODE_USAGE_EVENT_TYPE } from '@e2e/fixtures/data/customerEvents' import { localAuthFixture as test } from '@e2e/fixtures/localAuthFixture' @@ -51,6 +52,20 @@ test.describe( ) }) + test('says Credit for a one-credit charge', async ({ comfyPage }) => { + const table = new UsageLogsTable(comfyPage.settingDialog) + const tooltip = new Tooltip(comfyPage.page) + + await table.additionalInfoButton(GPU_USAGE_EVENT_TYPE).hover() + + await expect(tooltip.open).toContainText('Charge: 1 Credit') + await expect(tooltip.open).not.toContainText('1 Credits') + await expectElementScreenshot( + tooltip.surface(tooltip.open), + 'activity-charge-tooltip-one-credit.png' + ) + }) + test('passes a non-numeric charge through unchanged', async ({ comfyPage }) => { diff --git a/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts-snapshots/activity-charge-tooltip-one-credit-chromium-linux.png b/browser_tests/tests/dialogs/usageLogsChargeTooltip.spec.ts-snapshots/activity-charge-tooltip-one-credit-chromium-linux.png new file mode 100644 index 0000000000000000000000000000000000000000..f9de651ca51da53653ba5f98d7dbe0226737c68f GIT binary patch literal 2915 zcmV-p3!LQFJ2WQfL_!MU-8G zmMn_k3W$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Tim;3{q*Tu#4@#80`FQ8>RyRZIC%BAQ5 ze)3cB{P}a7@sK|+SpKYc!Rohn!9~R)FRwsY^faK=w$@f|BcHF-`RiOPdKRGE_>B$R zii$EGPlK@NY4CVj<>h5^pcd8Ccq*!D4Gq5%7CnS7zAykiR9;>p$J5Z{^Xqx)_|ZT{ z+R^bAAS`48Vy>#HnvSj>lKaxK*SO^9=^MNg0Q8l*mS%s%VnxM2*54;+Z*RMsmo4$u zh>_NRsLdJddt)QNva+JSzK%oi!}$*Y00960LmnQr00006Nkl { const { createI18n } = await import('vue-i18n') return { d: mockI18n.d, - t: (key: string) => key, + t: (key: string, plural?: unknown) => + typeof plural === 'number' ? `${key}[${plural}]` : key, i18n: createI18n({ legacy: false, locale: 'en' }) } }) @@ -231,27 +232,27 @@ describe('useCustomerEventsService', () => { }) it.for([ - { charge: 33_044, expected: 'credits.charge: 7 credits.credits' }, - { charge: '36209', expected: 'credits.charge: 8 credits.credits' }, + { charge: 33_044, expected: 'credits.charge: 7 credits.creditUnit[7]' }, + { charge: '36209', expected: 'credits.charge: 8 credits.creditUnit[8]' }, { charge: 10_000_000_000, - expected: 'credits.charge: 2,110,000 credits.credits' + expected: 'credits.charge: 2,110,000 credits.creditUnit[2110000]' }, - { charge: 0, expected: 'credits.charge: 0 credits.credits' }, + { charge: 0, expected: 'credits.charge: 0 credits.creditUnit[0]' }, { charge: 1, - expected: 'credits.charge: credits.lessThanOne credits.credits' + expected: 'credits.charge: credits.lessThanOne credits.creditUnit[2]' }, { charge: 1_000, - expected: 'credits.charge: credits.lessThanOne credits.credits' + expected: 'credits.charge: credits.lessThanOne credits.creditUnit[2]' }, { charge: 3_318, - expected: 'credits.charge: credits.lessThanOne credits.credits' + expected: 'credits.charge: credits.lessThanOne credits.creditUnit[2]' }, - { charge: 4_740, expected: 'credits.charge: 1 credits.credits' }, - { charge: 6_636, expected: 'credits.charge: 1 credits.credits' }, + { charge: 4_740, expected: 'credits.charge: 1 credits.creditUnit[1]' }, + { charge: 6_636, expected: 'credits.charge: 1 credits.creditUnit[1]' }, { charge: 'n/a', expected: 'Charge Micro Usd: n/a' } ])( 'should render charge_micro_usd $charge as $expected', @@ -262,6 +263,25 @@ describe('useCustomerEventsService', () => { } ) + it.for([ + [0, 'Credits'], + [1, 'Credit'], + [2, 'Credits'], + [7, 'Credits'] + ] as const)( + 'English charge unit for a count of %s is %s', + async ([count, unit]) => { + const { createI18n } = await import('vue-i18n') + const { default: en } = await import('@/locales/en/main.json') + const english = createI18n({ + legacy: false, + locale: 'en', + messages: { en } + }) + expect(english.global.t('credits.creditUnit', count)).toBe(unit) + } + ) + const withNothingToRender: ParamsCase[] = [ ['params carry only non-allowlisted keys', unrenderableParams], [ diff --git a/src/services/customerEventsService.ts b/src/services/customerEventsService.ts index 06c52639cd5..9aa3bbad02e 100644 --- a/src/services/customerEventsService.ts +++ b/src/services/customerEventsService.ts @@ -91,14 +91,15 @@ export const useCustomerEventsService = () => { function formatChargeCredits(microUsd: number) { const credits = microUsdToCredits(microUsd) - const amount = isSubCreditCharge(credits) - ? t('credits.lessThanOne') - : formatCredits({ - value: credits, - locale: i18n.global.locale.value, - numberOptions: { minimumFractionDigits: 0, maximumFractionDigits: 0 } - }) - return `${amount} ${t('credits.credits')}` + if (isSubCreditCharge(credits)) { + return `${t('credits.lessThanOne')} ${t('credits.creditUnit', 2)}` + } + const amount = formatCredits({ + value: credits, + locale: i18n.global.locale.value, + numberOptions: { minimumFractionDigits: 0, maximumFractionDigits: 0 } + }) + return `${amount} ${t('credits.creditUnit', Math.round(credits))}` } function formatTooltipParam(key: string, value: unknown) {