@@ -7,8 +7,10 @@ import assert from 'assert';
77import { URI , UriComponents } from '../../../../base/common/uri.js' ;
88import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
99import { IconPathDto } from '../../common/extHost.protocol.js' ;
10- import { IconPath } from '../../common/extHostTypeConverters.js' ;
10+ import { ChatRequestModeInstructions , IconPath } from '../../common/extHostTypeConverters.js' ;
1111import { ThemeColor , ThemeIcon } from '../../common/extHostTypes.js' ;
12+ import { IChatRequestModeInstructions } from '../../../contrib/chat/common/model/chatModel.js' ;
13+ import { Dto } from '../../../services/extensions/common/proxyIdentifier.js' ;
1214
1315suite ( 'extHostTypeConverters' , function ( ) {
1416 ensureNoDisposablesAreLeakedInTestSuite ( ) ;
@@ -120,4 +122,125 @@ suite('extHostTypeConverters', function () {
120122 } ) ;
121123 } ) ;
122124 } ) ;
125+
126+ suite ( 'ChatRequestModeInstructions' , function ( ) {
127+ test ( 'to returns undefined for undefined input' , function ( ) {
128+ assert . strictEqual ( ChatRequestModeInstructions . to ( undefined ) , undefined ) ;
129+ } ) ;
130+
131+ test ( 'from returns undefined for undefined input' , function ( ) {
132+ assert . strictEqual ( ChatRequestModeInstructions . from ( undefined ) , undefined ) ;
133+ } ) ;
134+
135+ test ( 'to converts IChatRequestModeInstructions to API type' , function ( ) {
136+ const uri = URI . parse ( 'file:///custom-agent' ) ;
137+ const input : IChatRequestModeInstructions = {
138+ uri,
139+ name : 'test-mode' ,
140+ content : 'test content' ,
141+ toolReferences : [ {
142+ kind : 'tool' ,
143+ id : 'tool1' ,
144+ name : 'tool1' ,
145+ value : undefined ,
146+ range : { start : 0 , endExclusive : 5 } ,
147+ } ] ,
148+ metadata : { key : 'value' } ,
149+ isBuiltin : false ,
150+ } ;
151+
152+ const result = ChatRequestModeInstructions . to ( input ) ! ;
153+ assert . deepStrictEqual ( result , {
154+ uri,
155+ name : 'test-mode' ,
156+ content : 'test content' ,
157+ toolReferences : [ { name : 'tool1' , range : [ 0 , 5 ] } ] ,
158+ metadata : { key : 'value' } ,
159+ isBuiltin : false ,
160+ } ) ;
161+ } ) ;
162+
163+ test ( 'to handles Dto with UriComponents' , function ( ) {
164+ const input : Dto < IChatRequestModeInstructions > = {
165+ uri : { scheme : 'file' , path : '/custom-agent' } as UriComponents ,
166+ name : 'test-mode' ,
167+ content : 'test content' ,
168+ toolReferences : [ ] ,
169+ metadata : undefined ,
170+ isBuiltin : true ,
171+ } ;
172+
173+ const result = ChatRequestModeInstructions . to ( input ) ! ;
174+ assert . ok ( URI . isUri ( result . uri ) ) ;
175+ assert . strictEqual ( result . name , 'test-mode' ) ;
176+ assert . strictEqual ( result . isBuiltin , true ) ;
177+ assert . deepStrictEqual ( result . toolReferences , [ ] ) ;
178+ } ) ;
179+
180+ test ( 'from converts API type to IChatRequestModeInstructions' , function ( ) {
181+ const uri = URI . parse ( 'file:///custom-agent' ) ;
182+ const input = {
183+ uri,
184+ name : 'test-mode' ,
185+ content : 'test content' ,
186+ toolReferences : [ { name : 'tool1' , range : [ 0 , 5 ] as [ number , number ] } ] ,
187+ metadata : { key : 'value' } ,
188+ isBuiltin : false ,
189+ } ;
190+
191+ const result = ChatRequestModeInstructions . from ( input ) ! ;
192+ assert . deepStrictEqual ( result , {
193+ uri,
194+ name : 'test-mode' ,
195+ content : 'test content' ,
196+ toolReferences : [ {
197+ kind : 'tool' ,
198+ id : 'tool1' ,
199+ name : 'tool1' ,
200+ value : undefined ,
201+ range : { start : 0 , endExclusive : 5 } ,
202+ } ] ,
203+ metadata : { key : 'value' } ,
204+ isBuiltin : false ,
205+ } ) ;
206+ } ) ;
207+
208+ test ( 'from handles missing toolReferences' , function ( ) {
209+ const input = {
210+ name : 'test-mode' ,
211+ content : 'test content' ,
212+ } ;
213+
214+ const result = ChatRequestModeInstructions . from ( input ) ! ;
215+ assert . deepStrictEqual ( result . toolReferences , [ ] ) ;
216+ } ) ;
217+
218+ test ( 'roundtrip from -> to preserves data' , function ( ) {
219+ const uri = URI . parse ( 'file:///custom-agent' ) ;
220+ const apiInput = {
221+ uri,
222+ name : 'roundtrip-mode' ,
223+ content : 'roundtrip content' ,
224+ toolReferences : [
225+ { name : 'tool1' } ,
226+ { name : 'tool2' , range : [ 10 , 20 ] as [ number , number ] } ,
227+ ] ,
228+ metadata : { flag : true } ,
229+ isBuiltin : false ,
230+ } ;
231+
232+ const internal = ChatRequestModeInstructions . from ( apiInput ) ! ;
233+ const backToApi = ChatRequestModeInstructions . to ( internal ) ! ;
234+
235+ assert . strictEqual ( backToApi . name , apiInput . name ) ;
236+ assert . strictEqual ( backToApi . content , apiInput . content ) ;
237+ assert . strictEqual ( backToApi . isBuiltin , apiInput . isBuiltin ) ;
238+ assert . strictEqual ( backToApi . uri ?. toString ( ) , uri . toString ( ) ) ;
239+ assert . strictEqual ( backToApi . toolReferences ?. length , 2 ) ;
240+ assert . strictEqual ( backToApi . toolReferences ?. [ 0 ] . name , 'tool1' ) ;
241+ assert . strictEqual ( backToApi . toolReferences ?. [ 0 ] . range , undefined ) ;
242+ assert . strictEqual ( backToApi . toolReferences ?. [ 1 ] . name , 'tool2' ) ;
243+ assert . deepStrictEqual ( backToApi . toolReferences ?. [ 1 ] . range , [ 10 , 20 ] ) ;
244+ } ) ;
245+ } ) ;
123246} ) ;
0 commit comments