11import { describe , expect , it } from 'vitest'
22import { AshbyBlock } from './ashby'
33
4+ const blockParams = AshbyBlock . tools . config ?. params
5+ if ( ! blockParams ) throw new Error ( 'AshbyBlock has no params mapper' )
6+
47describe ( 'AshbyBlock' , ( ) => {
58 const buildParams = ( operation : string , extra : Record < string , unknown > ) => ( {
69 operation,
@@ -9,7 +12,7 @@ describe('AshbyBlock', () => {
912
1013 describe ( 'alternateEmailAddresses parsing (create_candidate)' , ( ) => {
1114 it ( 'parses a comma-separated string into an array' , ( ) => {
12- const result = AshbyBlock . tools . config . params ! (
15+ const result = blockParams (
1316 buildParams ( 'create_candidate' , {
1417 alternateEmailAddresses : 'a@x.com, b@x.com' ,
1518 } )
@@ -20,34 +23,28 @@ describe('AshbyBlock', () => {
2023
2124 describe ( 'socialLinks parsing (update_candidate)' , ( ) => {
2225 it ( 'preserves an empty JSON array so users can clear all social links' , ( ) => {
23- const result = AshbyBlock . tools . config . params ! (
24- buildParams ( 'update_candidate' , { socialLinks : '[]' } )
25- )
26+ const result = blockParams ( buildParams ( 'update_candidate' , { socialLinks : '[]' } ) )
2627 expect ( result . socialLinks ) . toEqual ( [ ] )
2728 } )
2829
2930 it ( 'throws instead of silently dropping the field when the JSON is malformed' , ( ) => {
3031 // A silent [] here would let the Ashby update proceed without applying
3132 // the requested links and with no error shown to the workflow author.
3233 expect ( ( ) =>
33- AshbyBlock . tools . config . params ! (
34- buildParams ( 'update_candidate' , { socialLinks : 'not json' } )
35- )
34+ blockParams ( buildParams ( 'update_candidate' , { socialLinks : 'not json' } ) )
3635 ) . toThrow ( / I n v a l i d J S O N i n A s h b y s o c i a l l i n k s / )
3736 } )
3837
3938 it ( 'throws when the parsed JSON is not an array' , ( ) => {
4039 expect ( ( ) =>
41- AshbyBlock . tools . config . params ! (
42- buildParams ( 'update_candidate' , { socialLinks : '{"type":"Twitter"}' } )
43- )
40+ blockParams ( buildParams ( 'update_candidate' , { socialLinks : '{"type":"Twitter"}' } ) )
4441 ) . toThrow ( / e x p e c t e d a J S O N a r r a y / )
4542 } )
4643 } )
4744
4845 describe ( 'nullable candidate updates' , ( ) => {
4946 it ( 'preserves nulls from dynamic references for aliased update fields' , ( ) => {
50- const result = AshbyBlock . tools . config . params ! (
47+ const result = blockParams (
5148 buildParams ( 'update_candidate' , {
5249 updateName : null ,
5350 candidateLocation : null ,
@@ -63,17 +60,14 @@ describe('AshbyBlock', () => {
6360 describe ( 'archiveEmail parsing (change_application_stage)' , ( ) => {
6461 it ( 'rejects non-object archive email input' , ( ) => {
6562 expect ( ( ) =>
66- AshbyBlock . tools . config . params ! (
67- buildParams ( 'change_application_stage' , { archiveEmail : 'true' } )
68- )
63+ blockParams ( buildParams ( 'change_application_stage' , { archiveEmail : 'true' } ) )
6964 ) . toThrow ( / e x p e c t e d a J S O N o b j e c t / )
7065 } )
7166 } )
7267
7368 describe ( 'fieldValue parsing (set_custom_field_value)' , ( ) => {
7469 const parse = ( fieldValue : unknown ) =>
75- AshbyBlock . tools . config . params ! ( buildParams ( 'set_custom_field_value' , { fieldValue } ) )
76- . fieldValue
70+ blockParams ( buildParams ( 'set_custom_field_value' , { fieldValue } ) ) . fieldValue
7771
7872 it ( 'decodes null so the annotation can be cleared' , ( ) => {
7973 // Ashby clears a custom field when it receives an explicit null, which is
@@ -106,17 +100,13 @@ describe('AshbyBlock', () => {
106100 describe ( 'fieldValues parsing (set_custom_field_values)' , ( ) => {
107101 it ( 'throws instead of silently dropping the writes when the JSON is malformed' , ( ) => {
108102 expect ( ( ) =>
109- AshbyBlock . tools . config . params ! (
110- buildParams ( 'set_custom_field_values' , { fieldValues : 'not json' } )
111- )
103+ blockParams ( buildParams ( 'set_custom_field_values' , { fieldValues : 'not json' } ) )
112104 ) . toThrow ( / I n v a l i d J S O N i n A s h b y c u s t o m f i e l d v a l u e s / )
113105 } )
114106
115107 it ( 'throws when the parsed JSON is not an array' , ( ) => {
116108 expect ( ( ) =>
117- AshbyBlock . tools . config . params ! (
118- buildParams ( 'set_custom_field_values' , { fieldValues : '{"fieldId":"abc"}' } )
119- )
109+ blockParams ( buildParams ( 'set_custom_field_values' , { fieldValues : '{"fieldId":"abc"}' } ) )
120110 ) . toThrow ( / e x p e c t e d a J S O N a r r a y / )
121111 } )
122112 } )
@@ -126,7 +116,7 @@ describe('AshbyBlock', () => {
126116 // The Source ID field is hidden once the clear switch is on, but a value
127117 // typed beforehand is still stored. Sending both would trip the tool's
128118 // exclusivity guard and surface as an error the user cannot see the cause of.
129- const result = AshbyBlock . tools . config . params ! (
119+ const result = blockParams (
130120 buildParams ( 'change_application_source' , {
131121 changeSourceId : 'src-left-over' ,
132122 unsetSource : 'true' ,
@@ -146,7 +136,7 @@ describe('AshbyBlock', () => {
146136 // result, not just the mapping, since that gap is where the bug lived.
147137 const merge = ( inputs : Record < string , unknown > ) => ( {
148138 ...inputs ,
149- ...AshbyBlock . tools . config . params ! ( inputs ) ,
139+ ...blockParams ( inputs ) ,
150140 } )
151141
152142 const cleared = merge (
@@ -182,7 +172,7 @@ describe('AshbyBlock', () => {
182172 describe ( 'agent tool calls (operation only in context)' , ( ) => {
183173 const toolCall = ( operation : string , args : Record < string , unknown > ) => ( {
184174 ...args ,
185- ...AshbyBlock . tools . config . params ! ( args , { operation } ) ,
175+ ...blockParams ( args , { operation } ) ,
186176 } )
187177
188178 it ( 'maps block-only fields saved on the tool row to the tool params' , ( ) => {
0 commit comments