mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
fix: update cost tests to match new calculateApiCost signature
Both calculateApiCostAnthropic and calculateApiCostOpenAI now return a number directly (the total cost) instead of an object with totalCost, totalInputTokens, and totalOutputTokens properties.
This commit is contained in:
parent
1c1ed4ea46
commit
dd6d37ebd1
1 changed files with 8 additions and 24 deletions
|
|
@ -131,9 +131,7 @@ describe("Cost Utility", () => {
|
|||
// Input cost: (3.0 / 1_000_000) * 1000 = 0.003
|
||||
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
|
||||
// Total: 0.003 + 0.0075 = 0.0105
|
||||
expect(result.totalCost).toBe(0.0105)
|
||||
expect(result.totalInputTokens).toBe(1000)
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBe(0.0105)
|
||||
})
|
||||
|
||||
it("should handle cache writes cost", () => {
|
||||
|
|
@ -143,9 +141,7 @@ describe("Cost Utility", () => {
|
|||
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
|
||||
// Cache writes: (3.75 / 1_000_000) * 2000 = 0.0075
|
||||
// Total: 0.003 + 0.0075 + 0.0075 = 0.018
|
||||
expect(result.totalCost).toBeCloseTo(0.018, 6)
|
||||
expect(result.totalInputTokens).toBe(3000) // Total already includes cache
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBeCloseTo(0.018, 6)
|
||||
})
|
||||
|
||||
it("should handle cache reads cost", () => {
|
||||
|
|
@ -155,9 +151,7 @@ describe("Cost Utility", () => {
|
|||
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
|
||||
// Cache reads: (0.3 / 1_000_000) * 3000 = 0.0009
|
||||
// Total: 0.003 + 0.0075 + 0.0009 = 0.0114
|
||||
expect(result.totalCost).toBe(0.0114)
|
||||
expect(result.totalInputTokens).toBe(4000) // Total already includes cache
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBe(0.0114)
|
||||
})
|
||||
|
||||
it("should handle all cost components together", () => {
|
||||
|
|
@ -168,9 +162,7 @@ describe("Cost Utility", () => {
|
|||
// Cache writes: (3.75 / 1_000_000) * 2000 = 0.0075
|
||||
// Cache reads: (0.3 / 1_000_000) * 3000 = 0.0009
|
||||
// Total: 0.003 + 0.0075 + 0.0075 + 0.0009 = 0.0189
|
||||
expect(result.totalCost).toBe(0.0189)
|
||||
expect(result.totalInputTokens).toBe(6000) // Total already includes cache
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBe(0.0189)
|
||||
})
|
||||
|
||||
it("should handle missing prices gracefully", () => {
|
||||
|
|
@ -181,16 +173,12 @@ describe("Cost Utility", () => {
|
|||
}
|
||||
|
||||
const result = calculateApiCostOpenAI(modelWithoutPrices, 1000, 500, 2000, 3000)
|
||||
expect(result.totalCost).toBe(0)
|
||||
expect(result.totalInputTokens).toBe(1000) // Total already includes cache
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBe(0)
|
||||
})
|
||||
|
||||
it("should handle zero tokens", () => {
|
||||
const result = calculateApiCostOpenAI(mockModelInfo, 0, 0, 0, 0)
|
||||
expect(result.totalCost).toBe(0)
|
||||
expect(result.totalInputTokens).toBe(0)
|
||||
expect(result.totalOutputTokens).toBe(0)
|
||||
expect(result).toBe(0)
|
||||
})
|
||||
|
||||
it("should handle undefined cache values", () => {
|
||||
|
|
@ -199,9 +187,7 @@ describe("Cost Utility", () => {
|
|||
// Input cost: (3.0 / 1_000_000) * 1000 = 0.003
|
||||
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
|
||||
// Total: 0.003 + 0.0075 = 0.0105
|
||||
expect(result.totalCost).toBe(0.0105)
|
||||
expect(result.totalInputTokens).toBe(1000)
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBe(0.0105)
|
||||
})
|
||||
|
||||
it("should handle missing cache prices", () => {
|
||||
|
|
@ -217,9 +203,7 @@ describe("Cost Utility", () => {
|
|||
// Input cost: (3.0 / 1_000_000) * (6000 - 2000 - 3000) = 0.003
|
||||
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
|
||||
// Total: 0.003 + 0.0075 = 0.0105
|
||||
expect(result.totalCost).toBe(0.0105)
|
||||
expect(result.totalInputTokens).toBe(6000) // Total already includes cache
|
||||
expect(result.totalOutputTokens).toBe(500)
|
||||
expect(result).toBe(0.0105)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue