mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-12-03 03:29:51 +00:00
fix(models): verbose unknown warning names both hatches
Extra High: calculateCost still told users to model-alias an unknown SKU unconditionally. Route that warning through unpricedModelHint so alias and model-flat-rate are both named.
This commit is contained in:
parent
4228c87595
commit
21ef46523d
2 changed files with 41 additions and 5 deletions
|
|
@ -584,9 +584,12 @@ export function isFlatRateModel(model: string): boolean {
|
|||
}
|
||||
|
||||
/// Shared unpriced-warning copy. Never tell the user to alias unconditionally:
|
||||
/// mapping a subscription SKU onto a priced row invents spend.
|
||||
export function unpricedModelHint(): string {
|
||||
return 'If a model is billed per token, map it with: codeburn model-alias "<model>" <known-model>. If $0 is correct (subscription / flat-rate): codeburn model-flat-rate "<model>".'
|
||||
/// mapping a subscription SKU onto a priced row invents spend. Optional `model`
|
||||
/// interpolates the sanitized id so the verbose calculateCost path names the
|
||||
/// same two hatches.
|
||||
export function unpricedModelHint(model = '<model>'): string {
|
||||
const safe = model.replace(/[\x00-\x1F\x7F-\x9F]/g, '?').slice(0, 200)
|
||||
return `If a model is billed per token, map it with: codeburn model-alias "${safe}" <known-model>. If $0 is correct (subscription / flat-rate): codeburn model-flat-rate "${safe}".`
|
||||
}
|
||||
|
||||
/// Stable hash of the model-alias map, for the same staleness class as the
|
||||
|
|
@ -995,10 +998,9 @@ export function calculateCost(
|
|||
// payloads written by external tools, so a hostile or corrupt file
|
||||
// could embed terminal escape sequences here.
|
||||
const safeName = sanitizeModelForDisplay(model)
|
||||
const aliasHint = `Map it with: codeburn model-alias "${safeName}" <known-model>, or track local-model savings with: codeburn model-savings "${safeName}" <baseline-model>`
|
||||
process.stderr.write(
|
||||
`codeburn: no pricing data for model "${safeName}" — costs for this model will show $0. ` +
|
||||
`${aliasHint}, or update with: npx codeburn@latest.\n`
|
||||
`${unpricedModelHint(safeName)} Or track local-model savings with: codeburn model-savings "${safeName}" <baseline-model>, or update with: npx codeburn@latest.\n`,
|
||||
)
|
||||
}
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -1108,4 +1108,38 @@ describe('unpricedModelHint', () => {
|
|||
expect(unpricedModelHint()).toContain('model-flat-rate')
|
||||
expect(unpricedModelHint()).not.toContain('Fix: codeburn model-alias')
|
||||
})
|
||||
|
||||
it('names both hatches for a concrete unknown SKU', () => {
|
||||
const hint = unpricedModelHint('zz-new-subscription-pass-sku')
|
||||
expect(hint).toContain('codeburn model-alias "zz-new-subscription-pass-sku"')
|
||||
expect(hint).toContain('codeburn model-flat-rate "zz-new-subscription-pass-sku"')
|
||||
expect(hint).toContain('If a model is billed per token')
|
||||
expect(hint).toContain('If $0 is correct')
|
||||
})
|
||||
})
|
||||
|
||||
describe('calculateCost verbose unknown-model warning', () => {
|
||||
it('does not present model-alias as the only fix for an unknown SKU', () => {
|
||||
const previous = process.env['CODEBURN_VERBOSE']
|
||||
process.env['CODEBURN_VERBOSE'] = '1'
|
||||
const chunks: string[] = []
|
||||
const originalWrite = process.stderr.write.bind(process.stderr)
|
||||
process.stderr.write = ((chunk: string | Uint8Array, ...args: unknown[]) => {
|
||||
chunks.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString())
|
||||
return (originalWrite as (chunk: string | Uint8Array, ...rest: unknown[]) => boolean)(chunk, ...args)
|
||||
}) as typeof process.stderr.write
|
||||
try {
|
||||
expect(calculateCost('zz-new-subscription-pass-sku', 10, 10, 0, 0, 0)).toBe(0)
|
||||
} finally {
|
||||
process.stderr.write = originalWrite
|
||||
if (previous === undefined) delete process.env['CODEBURN_VERBOSE']
|
||||
else process.env['CODEBURN_VERBOSE'] = previous
|
||||
}
|
||||
const text = chunks.join('')
|
||||
expect(text).toContain('zz-new-subscription-pass-sku')
|
||||
expect(text).toContain('If a model is billed per token')
|
||||
expect(text).toContain('model-flat-rate')
|
||||
expect(text).toContain('model-alias')
|
||||
expect(text).not.toMatch(/Map it with: codeburn model-alias/)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue