55 lines
2.2 KiB
Python
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("estimatedChf", 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["estimatedChf"], 0.0)
|
|
|
|
def test_chf_is_rounded_4_decimals(self):
|
|
result = _costEstimate.estimateBootstrapCost({"maxBytes": 1024 * 1024}, kind="files")
|
|
rounded = round(result["estimatedChf"], 4)
|
|
self.assertEqual(result["estimatedChf"], 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()
|