platform-core/tests/unit/services/test_costEstimate.py
ValueOn AG 877f859f6b
All checks were successful
Deploy Plattform-Core (Int) / test (push) Successful in 59s
Deploy Plattform-Core (Int) / deploy (push) Successful in 9s
fix(tests): align test imports with refactored module paths
Fix broken test imports after architecture refactoring:
- mfaService: _buildTotp -> buildTotp, _decryptSecret -> decryptSecret
- _actionSignatureValidator: _validateTypeRef -> validateTypeRef
- fkRegistry: modules.shared -> modules.dbHelpers
- costEstimate/ragLimits: _costEstimate -> costEstimate, _ragLimits -> ragLimits
- udbNodes: _isFeatureAdmin -> isFeatureAdmin
- inheritFlags: _normalisePath -> normalisePath
- methodTrustee: old workflow path -> features/trustee/workflows
- methodDiscovery: fix featuresDir path calculation (4 dirname levels)
- mainGraphicalEditor: wrap template labels with t() for i18n

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 08:25:43 +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 as _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()