fix: align model availability and retail pricing controls

This commit is contained in:
wlx committed 2026-10-13 20:38:12 +08:00
1 parent af505c5596
commit 813b406da4
9 files changed
+130 -47

No files matched your search

+17 -1
View File
@@ -1,6 +1,22 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { calculateTokenRetailPricing, groupDiscountLabel, modelStandardPriceLabel, platformPriceLabel, standardPriceLabel } from '../src/services/pricing.ts'
import { calculateTokenRetailPricing, editRetailAmounts, groupDiscountLabel, modelStandardPriceLabel, platformPriceLabel, standardPriceLabel } from '../src/services/pricing.ts'
test('admin editing fixed prices preserves source and billing metadata without another discount or conversion', () => {
const original = {price:0.4032, unit:'CNY / image', discount:5.6, exchangeRate:7.2, standardPrice:{price:0.1,unit:'USD / image'}, taskBilling:{mode:'fixed'}, evidence:'confirmed'}
const saved = editRetailAmounts(original, original.unit, {price:0.48384,input:'',output:'',cachedInput:'',imageInput:''})
assert.deepEqual(saved, {...original,price:0.48384})
assert.equal(original.price,0.4032)
assert.equal(platformPriceLabel(saved),'平台售价 ¥0.48384 / 张(单张请求)')
})
test('admin token editing preserves image-input rate and removes incompatible fixed price', () => {
const saved = editRetailAmounts({price:1,taskBilling:{mode:'openai-image-tokens'}}, 'CNY / 1M tokens', {price:'',input:20.16,output:'120.96',cachedInput:0,imageInput:'32.256'})
assert.deepEqual(saved, {unit:'CNY / 1M tokens',input:20.16,output:120.96,cachedInput:0,imageInput:32.256,taskBilling:{mode:'openai-image-tokens'}})
assert.equal(editRetailAmounts(undefined,'CNY / image',{price:1e-8,input:'',output:'',cachedInput:'',imageInput:''}).price,1e-8)
for (const price of [-1,NaN,Infinity,1000001,0.000000001]) assert.throws(()=>editRetailAmounts(undefined,'CNY / image',{price,input:'',output:'',cachedInput:'',imageInput:''}),/人民币价格/)
assert.throws(()=>editRetailAmounts(undefined,'USD / image',{price:1,input:'',output:'',cachedInput:'',imageInput:''}),/人民币计费单位/)
})
test('fixed-unit pricing shows platform task price without inventing a standard price or discount', () => {
const tripo = { price: 1.44, unit: 'CNY / task', upstreamCredits: 20, exchangeRate: 7.2, priceSource: 'Tripo 官方', standardPrice: { price: 0.2, unit: 'USD / task', credits: 20 } }