Merge pull request #7418 from ouchihao/codex/bug-pricing-exponent

fix(pricing): parse scientific notation in token bounds
This commit is contained in:
Wesley Liddick
2026-09-22 20:28:12 +08:00
committed by GitHub
2 changed files with 31 additions and 2 deletions
@@ -136,13 +136,13 @@ function emitField(field: keyof IntervalFormEntry, value: string | number | null
}
function toInt(val: string): number {
const n = parseInt(val, 10)
const n = Math.trunc(Number(val))
return isNaN(n) ? 0 : n
}
function toIntOrNull(val: string): number | null {
if (val === '') return null
const n = parseInt(val, 10)
const n = Math.trunc(Number(val))
return isNaN(n) ? null : n
}
</script>
@@ -0,0 +1,29 @@
import { enableAutoUnmount, mount } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import IntervalRow from '../IntervalRow.vue'
import type { IntervalFormEntry } from '../types'
vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) }))
enableAutoUnmount(afterEach)
const interval: IntervalFormEntry = {
min_tokens: 0, max_tokens: null, tier_label: '', sort_order: 0,
input_price: null, output_price: null, cache_write_price: null, cache_read_price: null,
input_multiplier: null, output_multiplier: null, cache_write_multiplier: null,
cache_read_multiplier: null, per_request_price: null,
}
describe('pricing interval token bounds', () => {
it.each([
['1e6', 1000000, 1000000],
['2.72e5', 272000, 272000],
['128000', 128000, 128000],
['', 0, null],
])('parses %s without losing the exponent', async (value, min, max) => {
const wrapper = mount(IntervalRow, { props: { interval, mode: 'token' } })
const inputs = wrapper.findAll('input[type="number"]')
await inputs[0].setValue(value)
await inputs[1].setValue(value)
expect(wrapper.emitted('update')?.[0]?.[0]).toMatchObject({ min_tokens: min })
expect(wrapper.emitted('update')?.[1]?.[0]).toMatchObject({ max_tokens: max })
})
})