Skip to content

Import actual costs.ts module in tests instead of duplicating logic #49

@kokevidaurre

Description

@kokevidaurre

Problem

test/costs.test.ts duplicates the MODEL_PRICING constant and calcCost() function instead of importing them from the source module. This means:

  1. Tests won't catch if the pricing values change in the source
  2. Tests could pass even when source is broken
  3. Maintenance burden of keeping two copies in sync

Location

  • Source: src/lib/costs.ts
  • Test: test/costs.test.ts

Current (Bad) Pattern

// test/costs.test.ts - DUPLICATED
const MODEL_PRICING: Record<string, { input: number; output: number }> = {
  'claude-opus-4-5-20251101': { input: 15.0, output: 75.0 },
  // ... duplicate of source
};

function calcCost(model: string, inputTokens: number, outputTokens: number): number {
  // ... duplicate of source
}

Recommended Fix

Export the constant and function from source, then import in tests:

// src/lib/costs.ts
export const MODEL_PRICING = { ... };
export function calcCost(...) { ... }

// test/costs.test.ts
import { calcCost, MODEL_PRICING } from '../src/lib/costs.js';

describe('costs utilities', () => {
  // Now tests the actual implementation
});

Priority

P3 - Test quality improvement. Not blocking but should be fixed before adding more cost-related tests.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions