Skip to content

feat: Add CD001-MCP TaxCalc Server Tests (CD001, #27)#319

Open
steadhac wants to merge 1 commit into
GenAI-Security-Project:mainfrom
steadhac:steadhac/feat/taxcalc-server-tests
Open

feat: Add CD001-MCP TaxCalc Server Tests (CD001, #27)#319
steadhac wants to merge 1 commit into
GenAI-Security-Project:mainfrom
steadhac:steadhac/feat/taxcalc-server-tests

Conversation

@steadhac
Copy link
Copy Markdown
Contributor

Description

Add a full unit test suite for the TaxCalc MCP server — a stateless mock tax calculator.
Pure computation, no DB writes. Tests cover tax math correctness for all 7 jurisdictions,
category handling (goods, services, entertainment), tax rate lookups, TIN/EIN format
validation, server config overrides, and string/float edge cases.

Bug-exposing tests document missing input validation for negative amounts, unknown
categories, an unreachable SSN dead-code branch, and whitespace jurisdiction handling.

Tests follow the established pattern with:

  • Title / Basically question / Steps / Expected Results
  • Bug-exposing tests included for each confirmed production defect.

📁 Test Files
tests/unit/mcp/test_taxcalc.py

TestCalculateTax

Test ID Title
test_tc_calc_001 calculate_tax returns correct tax breakdown for US-CA goods
test_tc_calc_002 Services category is tax-exempt when service_tax_exempt=True
test_tc_calc_003 Entertainment category adds the entertainment surcharge
test_tc_calc_004 Unknown jurisdiction returns error with available jurisdictions
test_tc_calc_005 Empty jurisdiction falls back to default_jurisdiction
test_tc_calc_006 US-NY calculation includes state, county, and city taxes
test_tc_calc_007 amount=0 returns zero tax for all components
test_tc_calc_008 ⚠️ Negative amount accepted without validation — produces negative tax
test_tc_calc_009 ⚠️ Unknown category accepted without validation — treated silently as goods
test_tc_calc_010 Fractional amounts rounded to 2 decimal places
test_tc_calc_011 All 7 jurisdictions compute without error
test_tc_calc_012 services not exempt when service_tax_exempt=False in config

TestGetTaxRates

Test ID Title
test_tc_rates_001 get_tax_rates with no jurisdiction returns all 7 rates
test_tc_rates_002 Specific jurisdiction returns single entry
test_tc_rates_003 Unknown jurisdiction returns error
test_tc_rates_004 combined_rate equals sum of state+county+city
test_tc_rates_005 Response includes service_tax_exempt and entertainment_surcharge_pct
test_tc_rates_006 Custom tax_rates in server_config replace default rates

TestValidateTaxId

Test ID Title
test_tc_tin_001 Valid 9-digit EIN returns format_valid=True, id_type=EIN
test_tc_tin_002 EIN with dashes normalized correctly
test_tc_tin_003 Tax ID not 9 digits returns format_valid=False
test_tc_tin_004 ⚠️ SSN validation branch is unreachable dead code
test_tc_tin_005 Unsupported country returns not-supported error
test_tc_tin_006 Empty tax_id returns format_valid=False
test_tc_tin_007 Spaces in tax_id stripped before validation
test_tc_tin_008 Letters in tax_id return format_valid=False

TestTaxCalcServerConfig

Test ID Title
test_tc_cfg_001 DEFAULT_CONFIG contains all expected configuration keys
test_tc_cfg_002 DEFAULT_CONFIG.tax_rates contains exactly 7 jurisdictions
test_tc_cfg_003 Custom entertainment_surcharge_pct applied in calculations
test_tc_cfg_004 Custom default_jurisdiction used when jurisdiction is empty

TestTaxCalcToolDiscovery

Test ID Title
test_tc_tools_001 TaxCalc server exposes exactly 3 tools
test_tc_tools_002 calculate_tax schema has amount parameter
test_tc_tools_003 validate_tax_id schema has tax_id and country

TestFloatEdgeCases

Test ID Title
test_tc_float_001 Very large amounts (1 billion) computed without overflow
test_tc_float_002 Very small amounts (0.01) return rounded totals

TestStrEdgeCases

Test ID Title
test_tc_str_001 SQL injection in jurisdiction handled safely
test_tc_str_002 ⚠️ Whitespace-only jurisdiction not treated as empty — missing strip
test_tc_str_003 Very long tax_id (1000 chars) handled without crash
test_tc_str_004 Unicode in tax_id returns format_valid=False without crash

Related Bug Tickets

Bug_183, Bug_184, Bug_185, Bug_186

@steadhac steadhac force-pushed the steadhac/feat/taxcalc-server-tests branch from 83bce0d to 34baf08 Compare May 27, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant