Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { computeDeltaCostCents, normalizeTokenState } from './billing.mjs';
|
||||
|
||||
const config = {
|
||||
useBackendCost: false,
|
||||
usdCnyRate: 7.2,
|
||||
inputCentsPer1k: 2,
|
||||
outputCentsPer1k: 6,
|
||||
minBillCents: 1,
|
||||
};
|
||||
|
||||
test('normalizeTokenState reads camelCase fields', () => {
|
||||
const state = normalizeTokenState({
|
||||
inputTokens: 10,
|
||||
outputTokens: 20,
|
||||
accumulatedInputTokens: 100,
|
||||
accumulatedOutputTokens: 200,
|
||||
});
|
||||
assert.equal(state.accumulatedInputTokens, 100);
|
||||
assert.equal(state.accumulatedOutputTokens, 200);
|
||||
});
|
||||
|
||||
test('computeDeltaCostCents bills token deltas', () => {
|
||||
const previous = { lastInputTokens: 1000, lastOutputTokens: 500 };
|
||||
const current = normalizeTokenState({
|
||||
accumulatedInputTokens: 2000,
|
||||
accumulatedOutputTokens: 1500,
|
||||
});
|
||||
const cost = computeDeltaCostCents(previous, current, config);
|
||||
assert.equal(cost, 8);
|
||||
});
|
||||
|
||||
test('computeDeltaCostCents returns zero when no usage delta', () => {
|
||||
const previous = { lastInputTokens: 1000, lastOutputTokens: 500 };
|
||||
const current = normalizeTokenState({
|
||||
accumulatedInputTokens: 1000,
|
||||
accumulatedOutputTokens: 500,
|
||||
});
|
||||
assert.equal(computeDeltaCostCents(previous, current, config), 0);
|
||||
});
|
||||
Reference in New Issue
Block a user