platform-core/tests/unit/services/test_costEstimate.py
2026-05-18 07:56:53 +02:00

55 lines
2.2 KiB
Python

"""Unit tests for `_costEstimate` heuristic.
Validates the output shape, basic formulas, and that 'basis' annotations
are always present (the user-facing transparency contract).
"""
from __future__ import annotations
import unittest
from modules.serviceCenter.services.serviceKnowledge import _costEstimate
class TestCostEstimate(unittest.TestCase):
def test_files_shape(self):
result = _costEstimate.estimateBootstrapCost(
{"maxBytes": 200 * 1024 * 1024}, kind="files",
)
self.assertIn("estimatedTokens", result)
self.assertIn("estimatedUsd", result)
self.assertIn("basis", result)
self.assertIn("assumptions", result["basis"])
self.assertIn("formula", result["basis"]["assumptions"])
self.assertIn("notes", result["basis"])
def test_files_doubling_maxBytes_doubles_tokens(self):
low = _costEstimate.estimateBootstrapCost({"maxBytes": 100 * 1024 * 1024}, kind="files")
high = _costEstimate.estimateBootstrapCost({"maxBytes": 200 * 1024 * 1024}, kind="files")
self.assertEqual(high["estimatedTokens"], low["estimatedTokens"] * 2)
def test_clickup_uses_tasks_and_workspaces(self):
result = _costEstimate.estimateBootstrapCost(
{"maxTasks": 100, "maxWorkspaces": 2, "maxListsPerWorkspace": 10},
kind="clickup",
)
expectedTokens = 100 * 2 * _costEstimate.DEFAULT_TOKENS_PER_ITEM
self.assertEqual(result["estimatedTokens"], expectedTokens)
def test_unknown_kind_returns_zero(self):
result = _costEstimate.estimateBootstrapCost({}, kind="totally-unknown")
self.assertEqual(result["estimatedTokens"], 0)
self.assertEqual(result["estimatedUsd"], 0.0)
def test_usd_is_rounded_4_decimals(self):
result = _costEstimate.estimateBootstrapCost({"maxBytes": 1024 * 1024}, kind="files")
rounded = round(result["estimatedUsd"], 4)
self.assertEqual(result["estimatedUsd"], rounded)
def test_basis_includes_input_limits(self):
result = _costEstimate.estimateBootstrapCost({"maxBytes": 42}, kind="files")
self.assertEqual(result["basis"]["limits"]["maxBytes"], 42)
if __name__ == "__main__":
unittest.main()