@dizzlkheinz/ynab-mcpb 0.18.3 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/CLAUDE.md +87 -8
- package/bin/ynab-mcp-server.cjs +2 -2
- package/bin/ynab-mcp-server.js +3 -3
- package/biome.json +39 -0
- package/dist/bundle/index.cjs +67 -67
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -27
- package/dist/server/YNABMCPServer.d.ts +3 -4
- package/dist/server/YNABMCPServer.js +111 -116
- package/dist/server/budgetResolver.d.ts +6 -5
- package/dist/server/budgetResolver.js +46 -36
- package/dist/server/cacheKeys.js +6 -6
- package/dist/server/cacheManager.js +14 -11
- package/dist/server/completions.d.ts +2 -2
- package/dist/server/completions.js +20 -15
- package/dist/server/config.d.ts +10 -5
- package/dist/server/config.js +24 -7
- package/dist/server/deltaCache.d.ts +2 -2
- package/dist/server/deltaCache.js +22 -16
- package/dist/server/deltaCache.merge.d.ts +2 -2
- package/dist/server/diagnostics.d.ts +4 -4
- package/dist/server/diagnostics.js +38 -32
- package/dist/server/errorHandler.d.ts +5 -12
- package/dist/server/errorHandler.js +219 -217
- package/dist/server/prompts.d.ts +2 -2
- package/dist/server/prompts.js +45 -45
- package/dist/server/rateLimiter.js +4 -4
- package/dist/server/requestLogger.d.ts +1 -1
- package/dist/server/requestLogger.js +40 -35
- package/dist/server/resources.d.ts +3 -3
- package/dist/server/resources.js +55 -52
- package/dist/server/responseFormatter.js +6 -6
- package/dist/server/securityMiddleware.d.ts +2 -2
- package/dist/server/securityMiddleware.js +22 -20
- package/dist/server/serverKnowledgeStore.js +1 -1
- package/dist/server/toolRegistry.d.ts +3 -3
- package/dist/server/toolRegistry.js +47 -40
- package/dist/tools/__tests__/deltaTestUtils.d.ts +3 -3
- package/dist/tools/__tests__/deltaTestUtils.js +2 -2
- package/dist/tools/accountTools.d.ts +9 -8
- package/dist/tools/accountTools.js +47 -47
- package/dist/tools/adapters.d.ts +13 -8
- package/dist/tools/adapters.js +21 -11
- package/dist/tools/budgetTools.d.ts +8 -7
- package/dist/tools/budgetTools.js +22 -22
- package/dist/tools/categoryTools.d.ts +9 -8
- package/dist/tools/categoryTools.js +68 -59
- package/dist/tools/compareTransactions/formatter.d.ts +3 -3
- package/dist/tools/compareTransactions/formatter.js +9 -9
- package/dist/tools/compareTransactions/index.d.ts +6 -6
- package/dist/tools/compareTransactions/index.js +58 -43
- package/dist/tools/compareTransactions/matcher.d.ts +1 -1
- package/dist/tools/compareTransactions/matcher.js +28 -15
- package/dist/tools/compareTransactions/parser.d.ts +2 -2
- package/dist/tools/compareTransactions/parser.js +144 -138
- package/dist/tools/compareTransactions/types.d.ts +4 -4
- package/dist/tools/compareTransactions.d.ts +1 -1
- package/dist/tools/compareTransactions.js +1 -1
- package/dist/tools/deltaFetcher.d.ts +2 -2
- package/dist/tools/deltaFetcher.js +16 -15
- package/dist/tools/deltaSupport.d.ts +4 -4
- package/dist/tools/deltaSupport.js +35 -41
- package/dist/tools/exportTransactions.d.ts +5 -4
- package/dist/tools/exportTransactions.js +61 -59
- package/dist/tools/monthTools.d.ts +7 -6
- package/dist/tools/monthTools.js +31 -29
- package/dist/tools/payeeTools.d.ts +7 -6
- package/dist/tools/payeeTools.js +28 -28
- package/dist/tools/reconcileAdapter.d.ts +2 -2
- package/dist/tools/reconcileAdapter.js +21 -11
- package/dist/tools/reconciliation/analyzer.d.ts +4 -4
- package/dist/tools/reconciliation/analyzer.js +136 -57
- package/dist/tools/reconciliation/csvParser.d.ts +3 -3
- package/dist/tools/reconciliation/csvParser.js +128 -104
- package/dist/tools/reconciliation/executor.d.ts +4 -4
- package/dist/tools/reconciliation/executor.js +148 -109
- package/dist/tools/reconciliation/index.d.ts +10 -10
- package/dist/tools/reconciliation/index.js +96 -83
- package/dist/tools/reconciliation/matcher.d.ts +3 -3
- package/dist/tools/reconciliation/matcher.js +17 -16
- package/dist/tools/reconciliation/payeeNormalizer.js +19 -8
- package/dist/tools/reconciliation/recommendationEngine.d.ts +1 -1
- package/dist/tools/reconciliation/recommendationEngine.js +40 -40
- package/dist/tools/reconciliation/reportFormatter.d.ts +2 -2
- package/dist/tools/reconciliation/reportFormatter.js +79 -54
- package/dist/tools/reconciliation/signDetector.d.ts +1 -1
- package/dist/tools/reconciliation/types.d.ts +19 -16
- package/dist/tools/reconciliation/ynabAdapter.d.ts +2 -2
- package/dist/tools/schemas/common.d.ts +1 -1
- package/dist/tools/schemas/common.js +1 -1
- package/dist/tools/schemas/outputs/accountOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/accountOutputs.js +24 -18
- package/dist/tools/schemas/outputs/budgetOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/budgetOutputs.js +14 -11
- package/dist/tools/schemas/outputs/categoryOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/categoryOutputs.js +49 -29
- package/dist/tools/schemas/outputs/comparisonOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/comparisonOutputs.js +12 -12
- package/dist/tools/schemas/outputs/index.d.ts +14 -14
- package/dist/tools/schemas/outputs/index.js +14 -14
- package/dist/tools/schemas/outputs/monthOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/monthOutputs.js +56 -41
- package/dist/tools/schemas/outputs/payeeOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/payeeOutputs.js +10 -10
- package/dist/tools/schemas/outputs/reconciliationOutputs.d.ts +2 -2
- package/dist/tools/schemas/outputs/reconciliationOutputs.js +45 -45
- package/dist/tools/schemas/outputs/transactionMutationOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/transactionMutationOutputs.js +28 -22
- package/dist/tools/schemas/outputs/transactionOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/transactionOutputs.js +43 -35
- package/dist/tools/schemas/outputs/utilityOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/utilityOutputs.js +5 -3
- package/dist/tools/schemas/shared/commonOutputs.d.ts +1 -1
- package/dist/tools/schemas/shared/commonOutputs.js +15 -9
- package/dist/tools/transactionReadTools.d.ts +11 -0
- package/dist/tools/transactionReadTools.js +202 -0
- package/dist/tools/transactionSchemas.d.ts +309 -0
- package/dist/tools/transactionSchemas.js +235 -0
- package/dist/tools/transactionTools.d.ts +6 -302
- package/dist/tools/transactionTools.js +7 -2054
- package/dist/tools/transactionUtils.d.ts +31 -0
- package/dist/tools/transactionUtils.js +364 -0
- package/dist/tools/transactionWriteTools.d.ts +20 -0
- package/dist/tools/transactionWriteTools.js +1342 -0
- package/dist/tools/utilityTools.d.ts +5 -4
- package/dist/tools/utilityTools.js +11 -11
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.js +6 -6
- package/dist/types/reconciliation.d.ts +1 -1
- package/dist/types/toolRegistration.d.ts +14 -12
- package/dist/utils/amountUtils.js +1 -1
- package/dist/utils/dateUtils.js +4 -4
- package/dist/utils/errors.d.ts +3 -3
- package/dist/utils/errors.js +4 -4
- package/dist/utils/money.d.ts +2 -2
- package/dist/utils/money.js +8 -8
- package/dist/utils/validationError.d.ts +1 -1
- package/dist/utils/validationError.js +1 -1
- package/docs/assets/examples/reconciliation-with-recommendations.json +66 -66
- package/docs/assets/schemas/reconciliation-v2.json +360 -336
- package/docs/plans/2025-12-25-transaction-tools-refactor-design.md +211 -0
- package/docs/plans/2025-12-25-transaction-tools-refactor.md +905 -0
- package/esbuild.config.mjs +53 -50
- package/meta.json +12548 -12548
- package/package.json +98 -109
- package/scripts/analyze-bundle.mjs +33 -30
- package/scripts/create-pr-description.js +169 -120
- package/scripts/run-all-tests.js +205 -0
- package/scripts/run-domain-integration-tests.js +28 -18
- package/scripts/run-generate-mcpb.js +19 -17
- package/scripts/run-throttled-integration-tests.js +92 -83
- package/scripts/test-delta-params.mjs +149 -120
- package/scripts/test-recommendations.ts +36 -32
- package/scripts/tmpTransaction.ts +80 -43
- package/scripts/validate-env.js +98 -91
- package/scripts/verify-build.js +78 -76
- package/src/__tests__/comprehensive.integration.test.ts +1281 -1154
- package/src/__tests__/performance.test.ts +723 -671
- package/src/__tests__/setup.ts +442 -395
- package/src/__tests__/smoke.e2e.test.ts +41 -39
- package/src/__tests__/testRunner.ts +314 -295
- package/src/__tests__/testUtils.ts +456 -364
- package/src/__tests__/tools/reconciliation/csvParser.integration.test.ts +109 -107
- package/src/__tests__/tools/reconciliation/real-world.integration.test.ts +41 -41
- package/src/index.ts +68 -59
- package/src/server/CLAUDE.md +480 -0
- package/src/server/YNABMCPServer.ts +821 -794
- package/src/server/__tests__/YNABMCPServer.integration.test.ts +929 -893
- package/src/server/__tests__/YNABMCPServer.test.ts +903 -899
- package/src/server/__tests__/budgetResolver.test.ts +466 -423
- package/src/server/__tests__/cacheManager.test.ts +891 -874
- package/src/server/__tests__/completions.integration.test.ts +115 -106
- package/src/server/__tests__/completions.test.ts +334 -313
- package/src/server/__tests__/config.test.ts +98 -86
- package/src/server/__tests__/deltaCache.merge.test.ts +774 -703
- package/src/server/__tests__/deltaCache.swr.test.ts +198 -153
- package/src/server/__tests__/deltaCache.test.ts +946 -759
- package/src/server/__tests__/diagnostics.test.ts +825 -792
- package/src/server/__tests__/errorHandler.integration.test.ts +512 -462
- package/src/server/__tests__/errorHandler.test.ts +402 -397
- package/src/server/__tests__/prompts.test.ts +424 -347
- package/src/server/__tests__/rateLimiter.test.ts +313 -309
- package/src/server/__tests__/requestLogger.test.ts +443 -403
- package/src/server/__tests__/resources.template.test.ts +196 -185
- package/src/server/__tests__/resources.test.ts +294 -288
- package/src/server/__tests__/security.integration.test.ts +487 -421
- package/src/server/__tests__/securityMiddleware.test.ts +519 -444
- package/src/server/__tests__/server-startup.integration.test.ts +509 -490
- package/src/server/__tests__/serverKnowledgeStore.test.ts +174 -173
- package/src/server/__tests__/toolRegistration.test.ts +239 -210
- package/src/server/__tests__/toolRegistry.test.ts +907 -845
- package/src/server/budgetResolver.ts +221 -181
- package/src/server/cacheKeys.ts +6 -6
- package/src/server/cacheManager.ts +498 -484
- package/src/server/completions.ts +267 -243
- package/src/server/config.ts +35 -14
- package/src/server/deltaCache.merge.ts +146 -128
- package/src/server/deltaCache.ts +352 -309
- package/src/server/diagnostics.ts +257 -242
- package/src/server/errorHandler.ts +747 -744
- package/src/server/prompts.ts +181 -176
- package/src/server/rateLimiter.ts +131 -129
- package/src/server/requestLogger.ts +350 -322
- package/src/server/resources.ts +442 -374
- package/src/server/responseFormatter.ts +41 -37
- package/src/server/securityMiddleware.ts +223 -205
- package/src/server/serverKnowledgeStore.ts +67 -67
- package/src/server/toolRegistry.ts +508 -474
- package/src/tools/CLAUDE.md +604 -0
- package/src/tools/__tests__/accountTools.delta.integration.test.ts +128 -111
- package/src/tools/__tests__/accountTools.integration.test.ts +129 -111
- package/src/tools/__tests__/accountTools.test.ts +685 -638
- package/src/tools/__tests__/adapters.test.ts +142 -108
- package/src/tools/__tests__/budgetTools.delta.integration.test.ts +73 -73
- package/src/tools/__tests__/budgetTools.integration.test.ts +132 -124
- package/src/tools/__tests__/budgetTools.test.ts +442 -413
- package/src/tools/__tests__/categoryTools.delta.integration.test.ts +76 -68
- package/src/tools/__tests__/categoryTools.integration.test.ts +314 -288
- package/src/tools/__tests__/categoryTools.test.ts +656 -625
- package/src/tools/__tests__/compareTransactions/formatter.test.ts +535 -462
- package/src/tools/__tests__/compareTransactions/index.test.ts +378 -358
- package/src/tools/__tests__/compareTransactions/matcher.test.ts +497 -398
- package/src/tools/__tests__/compareTransactions/parser.test.ts +765 -747
- package/src/tools/__tests__/compareTransactions.test.ts +352 -332
- package/src/tools/__tests__/compareTransactions.window.test.ts +150 -146
- package/src/tools/__tests__/deltaFetcher.scheduled.integration.test.ts +69 -65
- package/src/tools/__tests__/deltaFetcher.test.ts +325 -265
- package/src/tools/__tests__/deltaSupport.test.ts +211 -184
- package/src/tools/__tests__/deltaTestUtils.ts +37 -33
- package/src/tools/__tests__/exportTransactions.test.ts +205 -200
- package/src/tools/__tests__/monthTools.delta.integration.test.ts +68 -68
- package/src/tools/__tests__/monthTools.integration.test.ts +178 -166
- package/src/tools/__tests__/monthTools.test.ts +561 -512
- package/src/tools/__tests__/payeeTools.delta.integration.test.ts +68 -68
- package/src/tools/__tests__/payeeTools.integration.test.ts +158 -142
- package/src/tools/__tests__/payeeTools.test.ts +486 -434
- package/src/tools/__tests__/transactionSchemas.test.ts +1204 -0
- package/src/tools/__tests__/transactionTools.integration.test.ts +875 -825
- package/src/tools/__tests__/transactionTools.test.ts +4923 -4366
- package/src/tools/__tests__/transactionUtils.test.ts +1016 -0
- package/src/tools/__tests__/utilityTools.integration.test.ts +32 -32
- package/src/tools/__tests__/utilityTools.test.ts +68 -58
- package/src/tools/accountTools.ts +293 -271
- package/src/tools/adapters.ts +120 -63
- package/src/tools/budgetTools.ts +121 -116
- package/src/tools/categoryTools.ts +379 -339
- package/src/tools/compareTransactions/formatter.ts +131 -119
- package/src/tools/compareTransactions/index.ts +249 -214
- package/src/tools/compareTransactions/matcher.ts +259 -209
- package/src/tools/compareTransactions/parser.ts +517 -487
- package/src/tools/compareTransactions/types.ts +38 -38
- package/src/tools/compareTransactions.ts +1 -1
- package/src/tools/deltaFetcher.ts +281 -260
- package/src/tools/deltaSupport.ts +264 -259
- package/src/tools/exportTransactions.ts +230 -218
- package/src/tools/monthTools.ts +180 -165
- package/src/tools/payeeTools.ts +152 -140
- package/src/tools/reconcileAdapter.ts +297 -246
- package/src/tools/reconciliation/CLAUDE.md +506 -0
- package/src/tools/reconciliation/__tests__/adapter.causes.test.ts +135 -112
- package/src/tools/reconciliation/__tests__/adapter.test.ts +249 -227
- package/src/tools/reconciliation/__tests__/analyzer.test.ts +408 -335
- package/src/tools/reconciliation/__tests__/csvParser.test.ts +71 -69
- package/src/tools/reconciliation/__tests__/executor.integration.test.ts +348 -323
- package/src/tools/reconciliation/__tests__/executor.progress.test.ts +503 -457
- package/src/tools/reconciliation/__tests__/executor.test.ts +898 -831
- package/src/tools/reconciliation/__tests__/matcher.test.ts +667 -663
- package/src/tools/reconciliation/__tests__/payeeNormalizer.test.ts +296 -276
- package/src/tools/reconciliation/__tests__/recommendationEngine.integration.test.ts +692 -624
- package/src/tools/reconciliation/__tests__/recommendationEngine.test.ts +1008 -986
- package/src/tools/reconciliation/__tests__/reconciliation.delta.integration.test.ts +187 -146
- package/src/tools/reconciliation/__tests__/reportFormatter.test.ts +583 -530
- package/src/tools/reconciliation/__tests__/scenarios/adapterCurrency.scenario.test.ts +75 -71
- package/src/tools/reconciliation/__tests__/scenarios/extremes.scenario.test.ts +70 -58
- package/src/tools/reconciliation/__tests__/scenarios/repeatAmount.scenario.test.ts +102 -88
- package/src/tools/reconciliation/__tests__/schemaUrl.test.ts +58 -43
- package/src/tools/reconciliation/__tests__/signDetector.test.ts +209 -206
- package/src/tools/reconciliation/__tests__/ynabAdapter.test.ts +66 -60
- package/src/tools/reconciliation/analyzer.ts +582 -406
- package/src/tools/reconciliation/csvParser.ts +656 -609
- package/src/tools/reconciliation/executor.ts +1290 -1128
- package/src/tools/reconciliation/index.ts +580 -528
- package/src/tools/reconciliation/matcher.ts +256 -240
- package/src/tools/reconciliation/payeeNormalizer.ts +92 -78
- package/src/tools/reconciliation/recommendationEngine.ts +357 -345
- package/src/tools/reconciliation/reportFormatter.ts +349 -276
- package/src/tools/reconciliation/signDetector.ts +89 -83
- package/src/tools/reconciliation/types.ts +164 -153
- package/src/tools/reconciliation/ynabAdapter.ts +17 -15
- package/src/tools/schemas/CLAUDE.md +546 -0
- package/src/tools/schemas/common.ts +1 -1
- package/src/tools/schemas/outputs/__tests__/accountOutputs.test.ts +410 -409
- package/src/tools/schemas/outputs/__tests__/budgetOutputs.test.ts +305 -299
- package/src/tools/schemas/outputs/__tests__/categoryOutputs.test.ts +431 -430
- package/src/tools/schemas/outputs/__tests__/comparisonOutputs.test.ts +510 -495
- package/src/tools/schemas/outputs/__tests__/dateValidation.test.ts +179 -153
- package/src/tools/schemas/outputs/__tests__/discrepancyDirection.test.ts +293 -254
- package/src/tools/schemas/outputs/__tests__/monthOutputs.test.ts +457 -457
- package/src/tools/schemas/outputs/__tests__/payeeOutputs.test.ts +362 -356
- package/src/tools/schemas/outputs/__tests__/reconciliationOutputs.test.ts +402 -399
- package/src/tools/schemas/outputs/__tests__/transactionMutationSchemas.test.ts +225 -211
- package/src/tools/schemas/outputs/__tests__/transactionOutputs.test.ts +457 -454
- package/src/tools/schemas/outputs/__tests__/utilityOutputs.test.ts +316 -315
- package/src/tools/schemas/outputs/accountOutputs.ts +40 -34
- package/src/tools/schemas/outputs/budgetOutputs.ts +24 -19
- package/src/tools/schemas/outputs/categoryOutputs.ts +76 -56
- package/src/tools/schemas/outputs/comparisonOutputs.ts +192 -169
- package/src/tools/schemas/outputs/index.ts +163 -163
- package/src/tools/schemas/outputs/monthOutputs.ts +95 -80
- package/src/tools/schemas/outputs/payeeOutputs.ts +18 -18
- package/src/tools/schemas/outputs/reconciliationOutputs.ts +386 -373
- package/src/tools/schemas/outputs/transactionMutationOutputs.ts +259 -231
- package/src/tools/schemas/outputs/transactionOutputs.ts +81 -71
- package/src/tools/schemas/outputs/utilityOutputs.ts +90 -84
- package/src/tools/schemas/shared/commonOutputs.ts +27 -19
- package/src/tools/toolCategories.ts +114 -114
- package/src/tools/transactionReadTools.ts +327 -0
- package/src/tools/transactionSchemas.ts +484 -0
- package/src/tools/transactionTools.ts +107 -2990
- package/src/tools/transactionUtils.ts +621 -0
- package/src/tools/transactionWriteTools.ts +2110 -0
- package/src/tools/utilityTools.ts +46 -41
- package/src/types/CLAUDE.md +477 -0
- package/src/types/__tests__/index.test.ts +51 -51
- package/src/types/index.ts +43 -39
- package/src/types/integration-tests.d.ts +26 -26
- package/src/types/reconciliation.ts +29 -29
- package/src/types/toolAnnotations.ts +30 -30
- package/src/types/toolRegistration.ts +43 -32
- package/src/utils/CLAUDE.md +508 -0
- package/src/utils/__tests__/dateUtils.test.ts +174 -168
- package/src/utils/__tests__/money.test.ts +193 -187
- package/src/utils/amountUtils.ts +5 -5
- package/src/utils/baseError.ts +5 -5
- package/src/utils/dateUtils.ts +29 -26
- package/src/utils/errors.ts +14 -14
- package/src/utils/money.ts +66 -52
- package/src/utils/validationError.ts +1 -1
- package/tsconfig.json +29 -29
- package/tsconfig.prod.json +16 -16
- package/vitest-reporters/split-json-reporter.ts +247 -204
- package/vitest.config.ts +99 -95
- package/.prettierignore +0 -10
- package/.prettierrc.json +0 -10
- package/eslint.config.js +0 -49
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* Performance and load tests for YNAB MCP Server
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import type * as ynab from "ynab";
|
|
7
|
+
import { SecurityErrorCode } from "../server/errorHandler.js";
|
|
8
|
+
import {
|
|
9
|
+
type AccountSnapshot,
|
|
10
|
+
executeReconciliation,
|
|
11
|
+
} from "../tools/reconciliation/executor.js";
|
|
12
|
+
import type { ReconcileAccountRequest } from "../tools/reconciliation/index.js";
|
|
13
|
+
import type { ReconciliationAnalysis } from "../tools/reconciliation/types.js";
|
|
14
|
+
import { executeToolCall, parseToolResult } from "./testUtils.js";
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* Helper function to validate tool responses and extract array data
|
|
@@ -19,705 +22,754 @@ import { SecurityErrorCode } from '../server/errorHandler.js';
|
|
|
19
22
|
* @returns The validated array data
|
|
20
23
|
* @throws Error if response contains errors or invalid data
|
|
21
24
|
*/
|
|
22
|
-
function validateToolResponse<T>(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
function validateToolResponse<T>(
|
|
26
|
+
result: any,
|
|
27
|
+
fieldSelector: (data: any) => T[] | undefined,
|
|
28
|
+
): T[] {
|
|
29
|
+
const parsed = parseToolResult(result);
|
|
30
|
+
|
|
31
|
+
// Check for errors in the response
|
|
32
|
+
const hasError = parsed.error || parsed.data?.error;
|
|
33
|
+
if (hasError) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Tool returned error: ${JSON.stringify(hasError, null, 2)}
|
|
30
36
|
Full response: ${JSON.stringify(parsed, null, 2)}`,
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
);
|
|
38
|
+
}
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
// Ensure data exists
|
|
41
|
+
if (!parsed.data) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Tool returned no data. Full response: ${JSON.stringify(parsed, null, 2)}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
// Select the specific array field
|
|
48
|
+
const arrayData = fieldSelector(parsed.data);
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
// Validate it's a non-empty array
|
|
51
|
+
expect(arrayData).toBeDefined();
|
|
52
|
+
expect(Array.isArray(arrayData)).toBe(true);
|
|
53
|
+
expect(arrayData?.length).toBeGreaterThan(0);
|
|
46
54
|
|
|
47
|
-
|
|
55
|
+
return arrayData!;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
// Mock the YNAB SDK for performance tests
|
|
51
|
-
vi.mock(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
vi.mock("ynab", () => {
|
|
60
|
+
const mockAPI = {
|
|
61
|
+
budgets: {
|
|
62
|
+
getBudgets: vi.fn(),
|
|
63
|
+
getBudgetById: vi.fn(),
|
|
64
|
+
},
|
|
65
|
+
accounts: {
|
|
66
|
+
getAccounts: vi.fn(),
|
|
67
|
+
getAccountById: vi.fn(),
|
|
68
|
+
},
|
|
69
|
+
transactions: {
|
|
70
|
+
getTransactions: vi.fn(),
|
|
71
|
+
getTransactionById: vi.fn(),
|
|
72
|
+
createTransaction: vi.fn(),
|
|
73
|
+
},
|
|
74
|
+
categories: {
|
|
75
|
+
getCategories: vi.fn(),
|
|
76
|
+
},
|
|
77
|
+
user: {
|
|
78
|
+
getUser: vi.fn(),
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
API: vi.fn(() => mockAPI),
|
|
84
|
+
};
|
|
77
85
|
});
|
|
78
86
|
|
|
79
87
|
// NOTE: These performance tests need updated mocking for the reconciliation executor
|
|
80
88
|
// Skipping temporarily - reconciliation functionality is covered by integration tests
|
|
81
|
-
describe.skip(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
89
|
+
describe.skip("Reconciliation Performance - Bulk vs Sequential", () => {
|
|
90
|
+
it("processes 20 transactions in bulk mode in under 8 seconds", async () => {
|
|
91
|
+
const { duration, result } = await measurePerformanceScenario({
|
|
92
|
+
transactionCount: 20,
|
|
93
|
+
bulkDelay: 50,
|
|
94
|
+
});
|
|
95
|
+
console.log(`Bulk benchmark (20 txns): ${duration}ms`);
|
|
96
|
+
expect(duration).toBeLessThan(8000);
|
|
97
|
+
expect(result.summary.transactions_created).toBe(20);
|
|
98
|
+
expect(result.bulk_operation_details?.bulk_successes).toBe(1);
|
|
99
|
+
}, 60000);
|
|
100
|
+
|
|
101
|
+
it("pure sequential mode (single transaction) takes longer than 20 seconds", async () => {
|
|
102
|
+
// Pure sequential baseline: only 1 transaction per "unmatched_bank" to avoid bulk mode
|
|
103
|
+
const { duration, result } = await measurePerformanceScenario({
|
|
104
|
+
transactionCount: 1, // This ensures bulk mode is never entered
|
|
105
|
+
bulkDelay: 50,
|
|
106
|
+
sequentialDelay: 1050,
|
|
107
|
+
multipleRuns: 20, // Run 20 times to simulate 20 sequential transactions
|
|
108
|
+
});
|
|
109
|
+
console.log(
|
|
110
|
+
`Pure sequential baseline (20 txns, 1 at a time): ${duration}ms`,
|
|
111
|
+
);
|
|
112
|
+
expect(duration).toBeGreaterThan(20000);
|
|
113
|
+
expect(result.summary.transactions_created).toBe(1);
|
|
114
|
+
expect(result.bulk_operation_details).toBeUndefined(); // No bulk operations at all
|
|
115
|
+
}, 90000);
|
|
116
|
+
|
|
117
|
+
it("sequential fallback takes longer than 20 seconds for 20 transactions", async () => {
|
|
118
|
+
const { duration, result } = await measurePerformanceScenario({
|
|
119
|
+
transactionCount: 20,
|
|
120
|
+
bulkDelay: 50,
|
|
121
|
+
sequentialDelay: 1050,
|
|
122
|
+
forceSequential: true,
|
|
123
|
+
});
|
|
124
|
+
console.log(`Sequential fallback (20 txns): ${duration}ms`);
|
|
125
|
+
expect(duration).toBeGreaterThan(20000);
|
|
126
|
+
expect(result.summary.transactions_created).toBe(20);
|
|
127
|
+
expect(result.bulk_operation_details?.sequential_fallbacks).toBe(1);
|
|
128
|
+
expect(result.bulk_operation_details?.bulk_successes).toBe(0);
|
|
129
|
+
}, 90000);
|
|
130
|
+
|
|
131
|
+
it("achieves at least a 3x speedup over pure sequential mode", async () => {
|
|
132
|
+
const bulkRun = await measurePerformanceScenario({
|
|
133
|
+
transactionCount: 20,
|
|
134
|
+
bulkDelay: 50,
|
|
135
|
+
});
|
|
136
|
+
// Use pure sequential baseline for canonical comparison
|
|
137
|
+
const pureSequentialRun = await measurePerformanceScenario({
|
|
138
|
+
transactionCount: 1,
|
|
139
|
+
bulkDelay: 50,
|
|
140
|
+
sequentialDelay: 1050,
|
|
141
|
+
multipleRuns: 20,
|
|
142
|
+
});
|
|
143
|
+
const speedup = pureSequentialRun.duration / bulkRun.duration;
|
|
144
|
+
console.log(
|
|
145
|
+
`Bulk vs pure sequential speedup: ${speedup.toFixed(2)}x faster`,
|
|
146
|
+
);
|
|
147
|
+
expect(speedup).toBeGreaterThanOrEqual(3);
|
|
148
|
+
}, 120000);
|
|
149
|
+
|
|
150
|
+
it("handles 150-transaction chunking without significant overhead", async () => {
|
|
151
|
+
const { duration, result } = await measurePerformanceScenario({
|
|
152
|
+
transactionCount: 150,
|
|
153
|
+
bulkDelay: 60,
|
|
154
|
+
});
|
|
155
|
+
console.log(`Chunking benchmark (150 txns): ${duration}ms`);
|
|
156
|
+
expect(duration).toBeLessThan(15000);
|
|
157
|
+
expect(result.summary.transactions_created).toBe(150);
|
|
158
|
+
expect(
|
|
159
|
+
result.bulk_operation_details?.chunks_processed,
|
|
160
|
+
).toBeGreaterThanOrEqual(2);
|
|
161
|
+
}, 60000);
|
|
162
|
+
|
|
163
|
+
it("stays within 10MB of heap growth for 100 bulk transactions", async () => {
|
|
164
|
+
const before = process.memoryUsage().heapUsed;
|
|
165
|
+
const { result } = await measurePerformanceScenario({
|
|
166
|
+
transactionCount: 100,
|
|
167
|
+
bulkDelay: 30,
|
|
168
|
+
});
|
|
169
|
+
const after = process.memoryUsage().heapUsed;
|
|
170
|
+
const deltaMb = (after - before) / (1024 * 1024);
|
|
171
|
+
expect(result.summary.transactions_created).toBe(100);
|
|
172
|
+
expect(deltaMb).toBeLessThan(10);
|
|
173
|
+
});
|
|
160
174
|
});
|
|
161
175
|
|
|
162
176
|
const performanceInitialAccount: AccountSnapshot = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
balance: 0,
|
|
178
|
+
cleared_balance: 0,
|
|
179
|
+
uncleared_balance: 0,
|
|
166
180
|
};
|
|
167
181
|
|
|
168
182
|
function buildPerformanceAnalysis(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
183
|
+
count: number,
|
|
184
|
+
amount = 5,
|
|
185
|
+
statementMultiplier = count,
|
|
172
186
|
): ReconciliationAnalysis {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
187
|
+
const statementBalance = amount * statementMultiplier;
|
|
188
|
+
const baseDate = Date.parse("2025-08-01");
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
success: true,
|
|
192
|
+
phase: "analysis",
|
|
193
|
+
summary: {
|
|
194
|
+
statement_date_range: "Performance suite",
|
|
195
|
+
bank_transactions_count: count,
|
|
196
|
+
ynab_transactions_count: 0,
|
|
197
|
+
auto_matched: 0,
|
|
198
|
+
suggested_matches: 0,
|
|
199
|
+
unmatched_bank: count,
|
|
200
|
+
unmatched_ynab: 0,
|
|
201
|
+
current_cleared_balance: 0,
|
|
202
|
+
target_statement_balance: statementBalance,
|
|
203
|
+
discrepancy: statementBalance,
|
|
204
|
+
discrepancy_explanation: "Synthetic performance delta",
|
|
205
|
+
},
|
|
206
|
+
auto_matches: [],
|
|
207
|
+
suggested_matches: [],
|
|
208
|
+
unmatched_bank: Array.from({ length: count }, (_, index) => {
|
|
209
|
+
const date = new Date(baseDate + index * 24 * 60 * 60 * 1000);
|
|
210
|
+
return {
|
|
211
|
+
id: `perf-bank-${index}`,
|
|
212
|
+
date: date.toISOString().slice(0, 10),
|
|
213
|
+
amount,
|
|
214
|
+
payee: `Performance Payee ${index}`,
|
|
215
|
+
memo: `Performance memo ${index}`,
|
|
216
|
+
original_csv_row: index + 1,
|
|
217
|
+
};
|
|
218
|
+
}),
|
|
219
|
+
unmatched_ynab: [],
|
|
220
|
+
balance_info: {
|
|
221
|
+
current_cleared: 0,
|
|
222
|
+
current_uncleared: 0,
|
|
223
|
+
current_total: 0,
|
|
224
|
+
target_statement: statementBalance,
|
|
225
|
+
discrepancy: statementBalance,
|
|
226
|
+
on_track: false,
|
|
227
|
+
},
|
|
228
|
+
next_steps: [],
|
|
229
|
+
insights: [],
|
|
230
|
+
};
|
|
217
231
|
}
|
|
218
232
|
|
|
219
233
|
function buildPerformanceParams(
|
|
220
|
-
|
|
221
|
-
|
|
234
|
+
statementBalance: number,
|
|
235
|
+
overrides: Partial<ReconcileAccountRequest> = {},
|
|
222
236
|
): ReconcileAccountRequest {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
237
|
+
return {
|
|
238
|
+
budget_id: "budget-performance",
|
|
239
|
+
account_id: "account-performance",
|
|
240
|
+
csv_data: "Date,Description,Amount",
|
|
241
|
+
statement_balance: statementBalance,
|
|
242
|
+
statement_date: "2025-08-31",
|
|
243
|
+
date_tolerance_days: 1,
|
|
244
|
+
amount_tolerance_cents: 1,
|
|
245
|
+
auto_match_threshold: 90,
|
|
246
|
+
suggestion_threshold: 60,
|
|
247
|
+
auto_create_transactions: true,
|
|
248
|
+
auto_update_cleared_status: false,
|
|
249
|
+
auto_unclear_missing: false,
|
|
250
|
+
auto_adjust_dates: false,
|
|
251
|
+
dry_run: false,
|
|
252
|
+
require_exact_match: true,
|
|
253
|
+
confidence_threshold: 0.8,
|
|
254
|
+
max_resolution_attempts: 3,
|
|
255
|
+
include_structured_data: false,
|
|
256
|
+
...overrides,
|
|
257
|
+
};
|
|
244
258
|
}
|
|
245
259
|
|
|
246
260
|
function delay(ms: number): Promise<void> {
|
|
247
|
-
|
|
261
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
248
262
|
}
|
|
249
263
|
|
|
250
264
|
function createPerformanceApi(options: {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
265
|
+
bulkDelay?: number;
|
|
266
|
+
sequentialDelay?: number;
|
|
267
|
+
failBulk?: boolean;
|
|
254
268
|
}) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
269
|
+
const createTransactions = vi
|
|
270
|
+
.fn()
|
|
271
|
+
.mockImplementation(async (_budgetId, body: any) => {
|
|
272
|
+
if (options.failBulk) {
|
|
273
|
+
throw new Error("bulk failure");
|
|
274
|
+
}
|
|
275
|
+
if (options.bulkDelay) {
|
|
276
|
+
await delay(options.bulkDelay);
|
|
277
|
+
}
|
|
278
|
+
const transactions = (body.transactions ?? []).map(
|
|
279
|
+
(txn: any, index: number) => ({
|
|
280
|
+
id: `bulk-${index}-${Date.now()}`,
|
|
281
|
+
account_id: txn.account_id,
|
|
282
|
+
amount: txn.amount,
|
|
283
|
+
date: txn.date,
|
|
284
|
+
cleared: "cleared",
|
|
285
|
+
approved: true,
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
return { data: { transactions } };
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const createTransaction = vi
|
|
292
|
+
.fn()
|
|
293
|
+
.mockImplementation(async (_budgetId, body: any) => {
|
|
294
|
+
if (options.sequentialDelay) {
|
|
295
|
+
const asyncWait = Math.min(options.sequentialDelay, 50);
|
|
296
|
+
await delay(asyncWait);
|
|
297
|
+
const busyWait = Math.max(options.sequentialDelay - asyncWait, 0);
|
|
298
|
+
const start = Date.now();
|
|
299
|
+
while (Date.now() - start < busyWait) {
|
|
300
|
+
// busy-wait to simulate processing overhead
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
data: {
|
|
305
|
+
transaction: {
|
|
306
|
+
id: `seq-${Date.now()}`,
|
|
307
|
+
amount: body.transaction?.amount ?? 0,
|
|
308
|
+
date: body.transaction?.date ?? "2025-09-01",
|
|
309
|
+
cleared: "cleared",
|
|
310
|
+
approved: true,
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const updateTransactions = vi
|
|
317
|
+
.fn()
|
|
318
|
+
.mockResolvedValue({ data: { transactions: [] } });
|
|
319
|
+
const getTransactionsByAccount = vi
|
|
320
|
+
.fn()
|
|
321
|
+
.mockResolvedValue({ data: { transactions: [] } });
|
|
322
|
+
const getAccountById = vi.fn().mockResolvedValue({
|
|
323
|
+
data: {
|
|
324
|
+
account: {
|
|
325
|
+
id: "account-performance",
|
|
326
|
+
balance: performanceInitialAccount.balance,
|
|
327
|
+
cleared_balance: performanceInitialAccount.cleared_balance,
|
|
328
|
+
uncleared_balance: performanceInitialAccount.uncleared_balance,
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const api = {
|
|
334
|
+
transactions: {
|
|
335
|
+
createTransactions,
|
|
336
|
+
createTransaction,
|
|
337
|
+
updateTransactions,
|
|
338
|
+
getTransactionsByAccount,
|
|
339
|
+
},
|
|
340
|
+
accounts: {
|
|
341
|
+
getAccountById,
|
|
342
|
+
},
|
|
343
|
+
} as unknown as ynab.API;
|
|
344
|
+
|
|
345
|
+
return { api, mocks: { createTransactions, createTransaction } };
|
|
322
346
|
}
|
|
323
347
|
|
|
324
348
|
async function measurePerformanceScenario(options: {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
349
|
+
transactionCount: number;
|
|
350
|
+
amount?: number;
|
|
351
|
+
bulkDelay?: number;
|
|
352
|
+
sequentialDelay?: number;
|
|
353
|
+
forceSequential?: boolean;
|
|
354
|
+
multipleRuns?: number;
|
|
331
355
|
}): Promise<{
|
|
332
|
-
|
|
333
|
-
|
|
356
|
+
duration: number;
|
|
357
|
+
result: Awaited<ReturnType<typeof executeReconciliation>>;
|
|
334
358
|
}> {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
359
|
+
const analysis = buildPerformanceAnalysis(
|
|
360
|
+
options.transactionCount,
|
|
361
|
+
options.amount ?? 5,
|
|
362
|
+
);
|
|
363
|
+
const params = buildPerformanceParams(
|
|
364
|
+
analysis.summary.target_statement_balance,
|
|
365
|
+
);
|
|
366
|
+
const { api } = createPerformanceApi({
|
|
367
|
+
bulkDelay: options.bulkDelay,
|
|
368
|
+
sequentialDelay: options.sequentialDelay,
|
|
369
|
+
failBulk: options.forceSequential,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
const start = Date.now();
|
|
373
|
+
let result: Awaited<ReturnType<typeof executeReconciliation>>;
|
|
374
|
+
|
|
375
|
+
if (options.multipleRuns) {
|
|
376
|
+
// Run the scenario multiple times sequentially to measure pure sequential performance
|
|
377
|
+
for (let i = 0; i < options.multipleRuns; i++) {
|
|
378
|
+
result = await executeReconciliation({
|
|
379
|
+
ynabAPI: api,
|
|
380
|
+
analysis,
|
|
381
|
+
params,
|
|
382
|
+
budgetId: params.budget_id,
|
|
383
|
+
accountId: params.account_id,
|
|
384
|
+
initialAccount: performanceInitialAccount,
|
|
385
|
+
currencyCode: "USD",
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
result = await executeReconciliation({
|
|
390
|
+
ynabAPI: api,
|
|
391
|
+
analysis,
|
|
392
|
+
params,
|
|
393
|
+
budgetId: params.budget_id,
|
|
394
|
+
accountId: params.account_id,
|
|
395
|
+
initialAccount: performanceInitialAccount,
|
|
396
|
+
currencyCode: "USD",
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
const duration = Date.now() - start;
|
|
400
|
+
return { duration, result: result! };
|
|
372
401
|
}
|
|
373
402
|
|
|
374
|
-
describe(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
403
|
+
describe("YNAB MCP Server - Performance Tests", () => {
|
|
404
|
+
let server: InstanceType<
|
|
405
|
+
typeof import("../server/YNABMCPServer.js").YNABMCPServer
|
|
406
|
+
>;
|
|
407
|
+
let mockYnabAPI: any;
|
|
408
|
+
|
|
409
|
+
beforeEach(async () => {
|
|
410
|
+
// Ensure YNAB_ACCESS_TOKEN is set for all tests, even if just a placeholder
|
|
411
|
+
process.env.YNAB_ACCESS_TOKEN = "test-token-performance";
|
|
412
|
+
// Clear modules to ensure fresh import of server with new env var
|
|
413
|
+
vi.resetModules();
|
|
414
|
+
const { YNABMCPServer } = await import("../server/YNABMCPServer.js");
|
|
415
|
+
server = new YNABMCPServer();
|
|
416
|
+
|
|
417
|
+
// Mock the YNAB API constructor to ensure it receives the correct access token
|
|
418
|
+
const { API } = await import("ynab");
|
|
419
|
+
mockYnabAPI = new (API as any)("test-token-performance");
|
|
420
|
+
|
|
421
|
+
vi.clearAllMocks();
|
|
422
|
+
// Clear cache to ensure mocks are called in each test
|
|
423
|
+
await executeToolCall(server, "ynab:clear_cache");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe("Response Time Performance", () => {
|
|
427
|
+
it("should respond to budget listing within acceptable time", async () => {
|
|
428
|
+
// Mock quick response
|
|
429
|
+
mockYnabAPI.budgets.getBudgets.mockResolvedValue({
|
|
430
|
+
data: {
|
|
431
|
+
budgets: Array.from({ length: 5 }, (_, i) => ({
|
|
432
|
+
id: `budget-${i}`,
|
|
433
|
+
name: `Budget ${i}`,
|
|
434
|
+
last_modified_on: "2024-01-01T00:00:00Z",
|
|
435
|
+
first_month: "2024-01-01",
|
|
436
|
+
last_month: "2024-12-01",
|
|
437
|
+
})),
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const startTime = Date.now();
|
|
442
|
+
const result = await executeToolCall(server, "ynab:list_budgets");
|
|
443
|
+
const endTime = Date.now();
|
|
444
|
+
|
|
445
|
+
const responseTime = endTime - startTime;
|
|
446
|
+
|
|
447
|
+
expect(result).toBeDefined();
|
|
448
|
+
expect(responseTime).toBeLessThan(1000); // Should respond within 1 second
|
|
449
|
+
|
|
450
|
+
const budgets = parseToolResult(result);
|
|
451
|
+
expect(budgets.data.budgets).toHaveLength(5);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("should handle large transaction lists efficiently", async () => {
|
|
455
|
+
// Use smaller list to avoid size limit and ensure we get 'transactions' not 'preview_transactions'
|
|
456
|
+
const largeTransactionList = Array.from({ length: 100 }, (_, i) => ({
|
|
457
|
+
id: `transaction-${i}`,
|
|
458
|
+
date: "2024-01-01",
|
|
459
|
+
amount: -1000 * (i + 1),
|
|
460
|
+
memo: `Transaction ${i}`,
|
|
461
|
+
cleared: "cleared" as const,
|
|
462
|
+
approved: true,
|
|
463
|
+
account_id: "account-1",
|
|
464
|
+
category_id: "category-1",
|
|
465
|
+
deleted: false,
|
|
466
|
+
payee_name: `Payee ${i}`,
|
|
467
|
+
category_name: `Category ${i}`,
|
|
468
|
+
}));
|
|
469
|
+
|
|
470
|
+
// Mock the method that list_transactions actually uses for budget-wide queries
|
|
471
|
+
// Use mockImplementation to ensure it works with any arguments (including lastKnowledge)
|
|
472
|
+
mockYnabAPI.transactions.getTransactions.mockImplementation(async () => ({
|
|
473
|
+
data: {
|
|
474
|
+
transactions: largeTransactionList,
|
|
475
|
+
server_knowledge: 100,
|
|
476
|
+
},
|
|
477
|
+
}));
|
|
478
|
+
|
|
479
|
+
const startTime = Date.now();
|
|
480
|
+
const result = await executeToolCall(server, "ynab:list_transactions", {
|
|
481
|
+
budget_id: "123e4567-e89b-12d3-a456-426614174000", // Valid UUID
|
|
482
|
+
});
|
|
483
|
+
const endTime = Date.now();
|
|
484
|
+
|
|
485
|
+
const responseTime = endTime - startTime;
|
|
486
|
+
|
|
487
|
+
expect(result).toBeDefined();
|
|
488
|
+
expect(responseTime).toBeLessThan(2000); // Should handle large lists within 2 seconds
|
|
489
|
+
|
|
490
|
+
// Validate response structure
|
|
491
|
+
validateToolResponse(
|
|
492
|
+
result,
|
|
493
|
+
(data) => data.transactions || data.preview_transactions,
|
|
494
|
+
);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it("should handle concurrent requests efficiently", async () => {
|
|
498
|
+
// Mock responses for concurrent requests
|
|
499
|
+
mockYnabAPI.budgets.getBudgets.mockResolvedValue({
|
|
500
|
+
data: { budgets: [{ id: "budget-1", name: "Test Budget" }] },
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
mockYnabAPI.accounts.getAccounts.mockResolvedValue({
|
|
504
|
+
data: {
|
|
505
|
+
accounts: [
|
|
506
|
+
{
|
|
507
|
+
id: "account-1",
|
|
508
|
+
name: "Test Account",
|
|
509
|
+
type: "checking",
|
|
510
|
+
balance: 0,
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
mockYnabAPI.user.getUser.mockResolvedValue({
|
|
517
|
+
data: { user: { id: "user-1", email: "test@example.com" } },
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
const startTime = Date.now();
|
|
521
|
+
|
|
522
|
+
// Execute multiple concurrent requests
|
|
523
|
+
const promises = [
|
|
524
|
+
executeToolCall(server, "ynab:list_budgets"),
|
|
525
|
+
executeToolCall(server, "ynab:list_accounts", {
|
|
526
|
+
budget_id: "test-budget",
|
|
527
|
+
}),
|
|
528
|
+
executeToolCall(server, "ynab:get_user"),
|
|
529
|
+
executeToolCall(server, "ynab:list_budgets"),
|
|
530
|
+
executeToolCall(server, "ynab:list_accounts", {
|
|
531
|
+
budget_id: "test-budget",
|
|
532
|
+
}),
|
|
533
|
+
];
|
|
534
|
+
|
|
535
|
+
const results = await Promise.all(promises);
|
|
536
|
+
const endTime = Date.now();
|
|
537
|
+
|
|
538
|
+
const totalTime = endTime - startTime;
|
|
539
|
+
|
|
540
|
+
expect(results).toHaveLength(5);
|
|
541
|
+
results.forEach((result) => expect(result).toBeDefined());
|
|
542
|
+
expect(totalTime).toBeLessThan(3000); // All concurrent requests within 3 seconds
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
describe("Memory Usage Performance", () => {
|
|
547
|
+
it("should handle memory efficiently with large datasets", async () => {
|
|
548
|
+
// Create a large mock dataset
|
|
549
|
+
const largeCategoryList = Array.from(
|
|
550
|
+
{ length: 100 },
|
|
551
|
+
(_, groupIndex) => ({
|
|
552
|
+
id: `group-${groupIndex}`,
|
|
553
|
+
name: `Category Group ${groupIndex}`,
|
|
554
|
+
hidden: false,
|
|
555
|
+
deleted: false,
|
|
556
|
+
categories: Array.from({ length: 20 }, (_, catIndex) => ({
|
|
557
|
+
id: `category-${groupIndex}-${catIndex}`,
|
|
558
|
+
category_group_id: `group-${groupIndex}`,
|
|
559
|
+
name: `Category ${groupIndex}-${catIndex}`,
|
|
560
|
+
hidden: false,
|
|
561
|
+
deleted: false,
|
|
562
|
+
budgeted: 1000 * catIndex,
|
|
563
|
+
activity: -500 * catIndex,
|
|
564
|
+
balance: 500 * catIndex,
|
|
565
|
+
})),
|
|
566
|
+
}),
|
|
567
|
+
);
|
|
568
|
+
|
|
569
|
+
// Use mockImplementation to ensure it works with any arguments (including lastKnowledge)
|
|
570
|
+
mockYnabAPI.categories.getCategories.mockImplementation(async () => ({
|
|
571
|
+
data: {
|
|
572
|
+
category_groups: largeCategoryList,
|
|
573
|
+
server_knowledge: 100,
|
|
574
|
+
},
|
|
575
|
+
}));
|
|
576
|
+
|
|
577
|
+
const initialMemory = process.memoryUsage();
|
|
578
|
+
|
|
579
|
+
// Process large dataset multiple times
|
|
580
|
+
for (let i = 0; i < 10; i++) {
|
|
581
|
+
const result = await executeToolCall(server, "ynab:list_categories", {
|
|
582
|
+
budget_id: "123e4567-e89b-12d3-a456-426614174000", // Valid UUID
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
// Validate response structure
|
|
586
|
+
validateToolResponse(result, (data) => data.category_groups);
|
|
587
|
+
|
|
588
|
+
// Force garbage collection if available
|
|
589
|
+
if (global.gc) {
|
|
590
|
+
global.gc();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const finalMemory = process.memoryUsage();
|
|
595
|
+
|
|
596
|
+
// Memory usage shouldn't grow excessively (allow for some variance)
|
|
597
|
+
const memoryGrowth = finalMemory.heapUsed - initialMemory.heapUsed;
|
|
598
|
+
// With large datasets (2000 categories × 10 iterations), allow more memory growth
|
|
599
|
+
// Each category has multiple fields, and we're dealing with substantial JSON parsing
|
|
600
|
+
expect(memoryGrowth).toBeLessThan(100 * 1024 * 1024); // Less than 100MB growth
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
describe("Error Handling Performance", () => {
|
|
605
|
+
it("should handle errors quickly without blocking", async () => {
|
|
606
|
+
// Mock API errors
|
|
607
|
+
const apiError = new Error("API Error");
|
|
608
|
+
mockYnabAPI.budgets.getBudgets.mockRejectedValue(apiError);
|
|
609
|
+
mockYnabAPI.accounts.getAccounts.mockRejectedValue(apiError);
|
|
610
|
+
|
|
611
|
+
const startTime = Date.now();
|
|
612
|
+
|
|
613
|
+
// Execute multiple failing requests
|
|
614
|
+
const promises = [
|
|
615
|
+
executeToolCall(server, "ynab:list_budgets"),
|
|
616
|
+
executeToolCall(server, "ynab:list_accounts", { budget_id: "test" }),
|
|
617
|
+
executeToolCall(server, "ynab:list_budgets"),
|
|
618
|
+
];
|
|
619
|
+
|
|
620
|
+
const results = await Promise.all(promises);
|
|
621
|
+
const endTime = Date.now();
|
|
622
|
+
|
|
623
|
+
const totalTime = endTime - startTime;
|
|
624
|
+
|
|
625
|
+
// Check that all results are error responses
|
|
626
|
+
results.forEach((result) => {
|
|
627
|
+
const parsed = parseToolResult(result);
|
|
628
|
+
expect(parsed.error || parsed.data?.error).toBeDefined();
|
|
629
|
+
});
|
|
630
|
+
expect(totalTime).toBeLessThan(1000); // Errors should be handled quickly
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
it("should recover from rate limiting gracefully", async () => {
|
|
634
|
+
let callCount = 0;
|
|
635
|
+
|
|
636
|
+
// Mock rate limiting on first few calls, then success
|
|
637
|
+
mockYnabAPI.budgets.getBudgets.mockImplementation(() => {
|
|
638
|
+
callCount++;
|
|
639
|
+
if (callCount <= 2) {
|
|
640
|
+
const rateLimitError = new Error("Rate Limited");
|
|
641
|
+
(rateLimitError as any).error = { id: "429", name: "rate_limit" };
|
|
642
|
+
return Promise.reject(rateLimitError);
|
|
643
|
+
}
|
|
644
|
+
return Promise.resolve({
|
|
645
|
+
data: { budgets: [{ id: "budget-1", name: "Test Budget" }] },
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
const startTime = Date.now();
|
|
650
|
+
|
|
651
|
+
try {
|
|
652
|
+
// This should fail due to rate limiting
|
|
653
|
+
await executeToolCall(server, "ynab:list_budgets");
|
|
654
|
+
expect.fail("Should have thrown rate limit error");
|
|
655
|
+
} catch (error) {
|
|
656
|
+
expect(error).toBeDefined();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const endTime = Date.now();
|
|
660
|
+
const errorTime = endTime - startTime;
|
|
661
|
+
|
|
662
|
+
expect(errorTime).toBeLessThan(500); // Rate limit errors should be fast
|
|
663
|
+
expect(callCount).toBe(1);
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
describe("Validation Performance", () => {
|
|
668
|
+
it("should validate input parameters quickly", async () => {
|
|
669
|
+
const startTime = Date.now();
|
|
670
|
+
|
|
671
|
+
// Test multiple validation scenarios
|
|
672
|
+
const validationTests = [
|
|
673
|
+
// Invalid parameters (should fail quickly)
|
|
674
|
+
executeToolCall(server, "ynab:get_budget", {
|
|
675
|
+
budget_id: "", // Empty string should fail validation
|
|
676
|
+
}),
|
|
677
|
+
|
|
678
|
+
executeToolCall(server, "ynab:create_transaction", {
|
|
679
|
+
budget_id: "test",
|
|
680
|
+
account_id: "test",
|
|
681
|
+
amount: "not-a-number", // Invalid type
|
|
682
|
+
date: "2024-01-01",
|
|
683
|
+
}),
|
|
684
|
+
];
|
|
685
|
+
|
|
686
|
+
const results = await Promise.all(validationTests);
|
|
687
|
+
const parsed = results.map((result) => parseToolResult(result));
|
|
688
|
+
const endTime = Date.now();
|
|
689
|
+
|
|
690
|
+
const totalTime = endTime - startTime;
|
|
691
|
+
|
|
692
|
+
expect(parsed).toHaveLength(2);
|
|
693
|
+
const firstError = parsed[0].error ?? parsed[0].data?.error;
|
|
694
|
+
const secondError = parsed[1].error ?? parsed[1].data?.error;
|
|
695
|
+
expect(firstError?.code).toBe(SecurityErrorCode.VALIDATION_ERROR); // Invalid calls should fail
|
|
696
|
+
expect(secondError?.code).toBe(SecurityErrorCode.VALIDATION_ERROR);
|
|
697
|
+
expect(totalTime).toBeLessThan(1000); // Validation should be fast
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
describe("Stress Testing", () => {
|
|
702
|
+
it("should handle rapid sequential requests", async () => {
|
|
703
|
+
mockYnabAPI.user.getUser.mockResolvedValue({
|
|
704
|
+
data: { user: { id: "user-1", email: "test@example.com" } },
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
const startTime = Date.now();
|
|
708
|
+
|
|
709
|
+
// Execute 50 rapid sequential requests
|
|
710
|
+
const results = [];
|
|
711
|
+
for (let i = 0; i < 50; i++) {
|
|
712
|
+
const result = await executeToolCall(server, "ynab:get_user");
|
|
713
|
+
results.push(result);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const endTime = Date.now();
|
|
717
|
+
const totalTime = endTime - startTime;
|
|
718
|
+
const averageTime = totalTime / 50;
|
|
719
|
+
|
|
720
|
+
expect(results).toHaveLength(50);
|
|
721
|
+
results.forEach((result) => expect(result).toBeDefined());
|
|
722
|
+
expect(averageTime).toBeLessThan(100); // Average less than 100ms per request
|
|
723
|
+
expect(totalTime).toBeLessThan(5000); // Total less than 5 seconds
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
it("should maintain performance under mixed workload", async () => {
|
|
727
|
+
// Mock various endpoints
|
|
728
|
+
mockYnabAPI.budgets.getBudgets.mockResolvedValue({
|
|
729
|
+
data: { budgets: [{ id: "budget-1", name: "Test Budget" }] },
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
mockYnabAPI.accounts.getAccounts.mockResolvedValue({
|
|
733
|
+
data: { accounts: [{ id: "account-1", name: "Test Account" }] },
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
mockYnabAPI.transactions.getTransactions.mockImplementation(() =>
|
|
737
|
+
Promise.resolve({
|
|
738
|
+
data: { transactions: [] },
|
|
739
|
+
}),
|
|
740
|
+
);
|
|
741
|
+
|
|
742
|
+
mockYnabAPI.categories.getCategories.mockImplementation(() =>
|
|
743
|
+
Promise.resolve({
|
|
744
|
+
data: { category_groups: [] },
|
|
745
|
+
}),
|
|
746
|
+
);
|
|
747
|
+
|
|
748
|
+
const startTime = Date.now();
|
|
749
|
+
|
|
750
|
+
// Mixed workload: different tools with different complexities
|
|
751
|
+
const mixedPromises = [];
|
|
752
|
+
for (let i = 0; i < 20; i++) {
|
|
753
|
+
mixedPromises.push(
|
|
754
|
+
executeToolCall(server, "ynab:list_budgets"),
|
|
755
|
+
executeToolCall(server, "ynab:list_accounts", { budget_id: "test" }),
|
|
756
|
+
executeToolCall(server, "ynab:list_transactions", {
|
|
757
|
+
budget_id: "test",
|
|
758
|
+
}),
|
|
759
|
+
executeToolCall(server, "ynab:list_categories", {
|
|
760
|
+
budget_id: "test",
|
|
761
|
+
}),
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const results = await Promise.all(mixedPromises);
|
|
766
|
+
const endTime = Date.now();
|
|
767
|
+
|
|
768
|
+
const totalTime = endTime - startTime;
|
|
769
|
+
|
|
770
|
+
expect(results).toHaveLength(80); // 20 iterations × 4 tools
|
|
771
|
+
results.forEach((result) => expect(result).toBeDefined());
|
|
772
|
+
expect(totalTime).toBeLessThan(10000); // Should complete within 10 seconds
|
|
773
|
+
});
|
|
774
|
+
});
|
|
723
775
|
});
|