1- import { describe , expect , it } from 'vitest'
1+ import { describe , expect , it , vi } from 'vitest'
2+
3+ vi . mock ( '@/lib/internal/workflows/read-tool-enrichment' , ( ) => ( {
4+ readWorkflowInputFieldsForTool : vi . fn ( ) ,
5+ readWorkflowMetadataForTool : vi . fn ( ) ,
6+ } ) )
7+
28import { AffinityBlock } from '@/blocks/blocks/affinity'
9+ import { ToolCallParamsError } from '@/providers/tool-params-error'
10+ import { prepareToolExecution , transformBlockTool } from '@/providers/utils'
11+ import { affinityCreateListFieldDropdownOptionTool } from '@/tools/affinity/create_list_field_dropdown_option'
312
413/** Runs the mapper the way an Agent tool call does: its result is spread over the merged args. */
514function toolCall ( args : Record < string , unknown > , operation : string ) {
@@ -22,3 +31,49 @@ describe('AffinityBlock agent tool calls', () => {
2231 ) . toMatchObject ( { name : 'Deals' , type : 'company' , isPublic : true } )
2332 } )
2433} )
34+
35+ describe ( 'AffinityBlock dropdown option rank and win rate on a tool call' , ( ) => {
36+ const operation = 'create_list_field_dropdown_option'
37+
38+ async function prepare ( stored : Record < string , string > , modelArgs : Record < string , unknown > ) {
39+ const providerTool = await transformBlockTool (
40+ { type : AffinityBlock . type , operation, params : { apiKey : 'key' , ...stored } } ,
41+ {
42+ selectedOperation : operation ,
43+ getAllBlocks : ( ) => [ AffinityBlock ] ,
44+ getTool : ( ) => affinityCreateListFieldDropdownOptionTool ,
45+ }
46+ )
47+ if ( ! providerTool ) throw new Error ( 'Affinity agent tool was not created' )
48+ return prepareToolExecution ( providerTool , modelArgs , { } , undefined ) . executionParams
49+ }
50+
51+ const pinnedStatusOption = {
52+ listId : 'l1' ,
53+ fieldId : 'f1' ,
54+ optionType : 'status-dropdown' ,
55+ optionText : 'Won' ,
56+ optionColor : 'green' ,
57+ optionStatusCategory : 'won' ,
58+ }
59+
60+ it ( 'fails the call instead of sending the model fields over the pinned option' , async ( ) => {
61+ await expect (
62+ prepare ( pinnedStatusOption , { rank : 2 , winRate : 150 , type : 'ranked-dropdown' , text : 'X' } )
63+ ) . rejects . toThrow ( ToolCallParamsError )
64+ } )
65+
66+ it . each ( [
67+ [ 'Option Rank' , { optionRank : ' ' } , { rank : 2.5 } ] ,
68+ [ 'Win Rate' , { optionWinRate : ' ' } , { rank : 1 , winRate : 250 } ] ,
69+ ] ) ( 'validates the model value behind a blank %s' , async ( _label , stored , modelArgs ) => {
70+ await expect ( prepare ( { ...pinnedStatusOption , ...stored } , modelArgs ) ) . rejects . toThrow (
71+ ToolCallParamsError
72+ )
73+ } )
74+
75+ it ( 'sends a valid model rank behind a blank Option Rank' , async ( ) => {
76+ const params = await prepare ( { ...pinnedStatusOption , optionRank : ' ' } , { rank : 3 } )
77+ expect ( params ) . toMatchObject ( { type : 'status-dropdown' , text : 'Won' , rank : 3 } )
78+ } )
79+ } )
0 commit comments