@@ -157,6 +157,72 @@ describe('Knowledge Tools', () => {
157157 } )
158158 } )
159159
160+ describe ( 'knowledgeCreateDocumentTool' , ( ) => {
161+ describe ( 'transformResponse' , ( ) => {
162+ it ( 'exposes the created document ID at both the top level and nested data path' , async ( ) => {
163+ const result = await knowledgeCreateDocumentTool . transformResponse ! (
164+ createMockResponse ( {
165+ data : {
166+ documentsCreated : [ { documentId : 'doc-123' , filename : 'document.txt' } ] ,
167+ } ,
168+ } )
169+ )
170+
171+ expect ( result . success ) . toBe ( true )
172+ expect ( result . output . documentId ) . toBe ( 'doc-123' )
173+ expect ( result . output . data . documentId ) . toBe ( 'doc-123' )
174+ } )
175+
176+ it ( 'uses the legacy document ID fallback for both output paths' , async ( ) => {
177+ const result = await knowledgeCreateDocumentTool . transformResponse ! (
178+ createMockResponse ( {
179+ documentsCreated : [ { id : 'legacy-doc-123' , filename : 'document.txt' } ] ,
180+ } )
181+ )
182+
183+ expect ( result . output . documentId ) . toBe ( 'legacy-doc-123' )
184+ expect ( result . output . data . documentId ) . toBe ( 'legacy-doc-123' )
185+ } )
186+
187+ it . each ( [
188+ [ 'missing documentsCreated' , { data : { } } ] ,
189+ [ 'null documentsCreated' , { data : { documentsCreated : null } } ] ,
190+ [ 'empty documentsCreated' , { data : { documentsCreated : [ ] } } ] ,
191+ [ 'created document without an ID' , { data : { documentsCreated : [ { } ] } } ] ,
192+ ] ) ( 'preserves empty IDs for %s' , async ( _label , responseBody ) => {
193+ const result = await knowledgeCreateDocumentTool . transformResponse ! (
194+ createMockResponse ( responseBody )
195+ )
196+
197+ expect ( result . success ) . toBe ( true )
198+ expect ( result . output . documentId ) . toBe ( '' )
199+ expect ( result . output . data . documentId ) . toBe ( '' )
200+ } )
201+ } )
202+
203+ it . each ( [
204+ [ 'omitted tags' , { } ] ,
205+ [ 'an empty tag array' , { documentTags : [ ] } ] ,
206+ [ 'a serialized empty tag array' , { documentTags : '[]' } ] ,
207+ ] ) ( 'omits tag data and tag provenance for %s' , ( _label , tagParams ) => {
208+ const params = {
209+ knowledgeBaseId : 'kb-1' ,
210+ name : 'document.txt' ,
211+ content : 'document content' ,
212+ ...tagParams ,
213+ }
214+ const body = knowledgeCreateDocumentTool . operation . input ( params ) as {
215+ documents : Array < { documentTagsData ?: string } >
216+ }
217+
218+ expect ( body . documents [ 0 ] ) . not . toHaveProperty ( 'documentTagsData' )
219+ expect ( knowledgeCreateDocumentTool . operation . secretProvenance ?. request ?.( params ) ) . toEqual ( [
220+ { key : 'document-filename:0' , inputPaths : [ [ 'name' ] ] } ,
221+ { key : 'document-content:0' , inputPaths : [ [ 'content' ] ] } ,
222+ ] )
223+ } )
224+ } )
225+
160226 describe ( 'knowledgeSearchTool' , ( ) => {
161227 describe ( 'transformResponse' , ( ) => {
162228 it ( 'should restructure cost information for logging' , async ( ) => {
0 commit comments