@@ -48,14 +48,19 @@ describe("WebFetchExecutor", () => {
4848 await expect ( executor . execute ( { } ) ) . rejects . toThrow ( '缺少必填参数 "url"' ) ;
4949 } ) ;
5050
51+ it ( "should throw for missing prompt" , async ( ) => {
52+ const executor = new WebFetchExecutor ( mockSender ) ;
53+ await expect ( executor . execute ( { url : "https://example.com" } ) ) . rejects . toThrow ( '缺少必填参数 "prompt"' ) ;
54+ } ) ;
55+
5156 it ( "should throw for invalid url" , async ( ) => {
5257 const executor = new WebFetchExecutor ( mockSender ) ;
53- await expect ( executor . execute ( { url : "not-a-url" } ) ) . rejects . toThrow ( "Invalid URL" ) ;
58+ await expect ( executor . execute ( { url : "not-a-url" , prompt : "fetch" } ) ) . rejects . toThrow ( "Invalid URL" ) ;
5459 } ) ;
5560
5661 it ( "should throw for non-http protocol" , async ( ) => {
5762 const executor = new WebFetchExecutor ( mockSender ) ;
58- await expect ( executor . execute ( { url : "ftp://example.com" } ) ) . rejects . toThrow ( "Only http/https" ) ;
63+ await expect ( executor . execute ( { url : "ftp://example.com" , prompt : "fetch" } ) ) . rejects . toThrow ( "Only http/https" ) ;
5964 } ) ;
6065
6166 it ( "should handle JSON response" , async ( ) => {
@@ -67,7 +72,9 @@ describe("WebFetchExecutor", () => {
6772 vi . stubGlobal ( "fetch" , mockFetch ) ;
6873
6974 const executor = new WebFetchExecutor ( mockSender ) ;
70- const result = JSON . parse ( ( await executor . execute ( { url : "https://api.example.com/data" } ) ) as string ) ;
75+ const result = JSON . parse (
76+ ( await executor . execute ( { url : "https://api.example.com/data" , prompt : "extract data" } ) ) as string
77+ ) ;
7178
7279 expect ( result . content_type ) . toBe ( "json" ) ;
7380 expect ( JSON . parse ( result . content ) ) . toEqual ( { key : "value" } ) ;
@@ -84,7 +91,9 @@ describe("WebFetchExecutor", () => {
8491 mockExtractReturnValue = "Hello World long content here for testing extracted properly by offscreen" ;
8592
8693 const executor = new WebFetchExecutor ( mockSender ) ;
87- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
94+ const result = JSON . parse (
95+ ( await executor . execute ( { url : "https://example.com" , prompt : "extract content" } ) ) as string
96+ ) ;
8897
8998 expect ( result . content_type ) . toBe ( "html" ) ;
9099 expect ( result . content ) . toContain ( "Hello World" ) ;
@@ -100,7 +109,9 @@ describe("WebFetchExecutor", () => {
100109 mockExtractReturnValue = null ;
101110
102111 const executor = new WebFetchExecutor ( mockSender ) ;
103- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
112+ const result = JSON . parse (
113+ ( await executor . execute ( { url : "https://example.com" , prompt : "extract content" } ) ) as string
114+ ) ;
104115
105116 expect ( result . content_type ) . toBe ( "text" ) ;
106117 expect ( result . content ) . toBe ( "Simple text" ) ;
@@ -115,7 +126,9 @@ describe("WebFetchExecutor", () => {
115126 vi . stubGlobal ( "fetch" , mockFetch ) ;
116127
117128 const executor = new WebFetchExecutor ( mockSender ) ;
118- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" , max_length : 50 } ) ) as string ) ;
129+ const result = JSON . parse (
130+ ( await executor . execute ( { url : "https://example.com" , prompt : "extract content" , max_length : 50 } ) ) as string
131+ ) ;
119132
120133 expect ( result . content . length ) . toBe ( 50 ) ;
121134 expect ( result . truncated ) . toBe ( true ) ;
@@ -130,7 +143,7 @@ describe("WebFetchExecutor", () => {
130143 vi . stubGlobal ( "fetch" , mockFetch ) ;
131144
132145 const executor = new WebFetchExecutor ( mockSender ) ;
133- await expect ( executor . execute ( { url : "https://example.com" } ) ) . rejects . toThrow ( "HTTP 404" ) ;
146+ await expect ( executor . execute ( { url : "https://example.com" , prompt : "fetch" } ) ) . rejects . toThrow ( "HTTP 404" ) ;
134147 } ) ;
135148
136149 it ( "should fallback to stripHtmlTags when offscreen extraction throws" , async ( ) => {
@@ -143,7 +156,9 @@ describe("WebFetchExecutor", () => {
143156 mockExtractShouldThrow = true ;
144157
145158 const executor = new WebFetchExecutor ( mockSender ) ;
146- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
159+ const result = JSON . parse (
160+ ( await executor . execute ( { url : "https://example.com" , prompt : "extract content" } ) ) as string
161+ ) ;
147162
148163 expect ( result . content_type ) . toBe ( "text" ) ;
149164 expect ( result . content ) . toBe ( "Fallback content" ) ;
@@ -159,7 +174,9 @@ describe("WebFetchExecutor", () => {
159174 mockExtractReturnValue = "Hi" ; // shorter than 50 chars
160175
161176 const executor = new WebFetchExecutor ( mockSender ) ;
162- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
177+ const result = JSON . parse (
178+ ( await executor . execute ( { url : "https://example.com" , prompt : "extract content" } ) ) as string
179+ ) ;
163180
164181 expect ( result . content_type ) . toBe ( "text" ) ;
165182 expect ( result . content ) . toBe ( "Hi" ) ;
@@ -174,7 +191,9 @@ describe("WebFetchExecutor", () => {
174191 vi . stubGlobal ( "fetch" , mockFetch ) ;
175192
176193 const executor = new WebFetchExecutor ( mockSender ) ;
177- const result = JSON . parse ( ( await executor . execute ( { url : "https://api.example.com" } ) ) as string ) ;
194+ const result = JSON . parse (
195+ ( await executor . execute ( { url : "https://api.example.com" , prompt : "extract data" } ) ) as string
196+ ) ;
178197
179198 // Should fall back to text
180199 expect ( result . content_type ) . toBe ( "text" ) ;
@@ -193,7 +212,9 @@ describe("WebFetchExecutor", () => {
193212 mockExtractReturnValue = "Long enough content for extraction to work properly and pass the threshold" ;
194213
195214 const executor = new WebFetchExecutor ( mockSender ) ;
196- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
215+ const result = JSON . parse (
216+ ( await executor . execute ( { url : "https://example.com" , prompt : "extract content" } ) ) as string
217+ ) ;
197218
198219 expect ( result . content_type ) . toBe ( "html" ) ;
199220 expect ( mockSender . sendMessage ) . toHaveBeenCalled ( ) ;
@@ -208,7 +229,9 @@ describe("WebFetchExecutor", () => {
208229 vi . stubGlobal ( "fetch" , mockFetch ) ;
209230
210231 const executor = new WebFetchExecutor ( mockSender ) ;
211- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com/file.txt" } ) ) as string ) ;
232+ const result = JSON . parse (
233+ ( await executor . execute ( { url : "https://example.com/file.txt" , prompt : "extract content" } ) ) as string
234+ ) ;
212235
213236 expect ( result . content_type ) . toBe ( "text" ) ;
214237 expect ( result . content ) . toBe ( "Just plain text" ) ;
@@ -224,7 +247,7 @@ describe("WebFetchExecutor", () => {
224247 vi . stubGlobal ( "fetch" , mockFetch ) ;
225248
226249 const executor = new WebFetchExecutor ( mockSender ) ;
227- await executor . execute ( { url : "https://example.com" } ) ;
250+ await executor . execute ( { url : "https://example.com" , prompt : "fetch" } ) ;
228251
229252 expect ( mockFetch ) . toHaveBeenCalledWith ( "https://example.com" , {
230253 headers : { "User-Agent" : "Mozilla/5.0 (compatible; ScriptCat Agent)" } ,
@@ -242,7 +265,7 @@ describe("WebFetchExecutor", () => {
242265 vi . stubGlobal ( "fetch" , mockFetch ) ;
243266
244267 const executor = new WebFetchExecutor ( mockSender ) ;
245- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
268+ const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" , prompt : "fetch" } ) ) as string ) ;
246269
247270 expect ( result . final_url ) . toBe ( "https://example.com/redirected" ) ;
248271 } ) ;
@@ -257,7 +280,7 @@ describe("WebFetchExecutor", () => {
257280 vi . stubGlobal ( "fetch" , mockFetch ) ;
258281
259282 const executor = new WebFetchExecutor ( mockSender ) ;
260- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
283+ const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" , prompt : "fetch" } ) ) as string ) ;
261284
262285 expect ( result . final_url ) . toBeUndefined ( ) ;
263286 } ) ;
@@ -272,7 +295,7 @@ describe("WebFetchExecutor", () => {
272295 vi . stubGlobal ( "fetch" , mockFetch ) ;
273296
274297 const executor = new WebFetchExecutor ( mockSender ) ;
275- const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" } ) ) as string ) ;
298+ const result = JSON . parse ( ( await executor . execute ( { url : "https://example.com" , prompt : "fetch" } ) ) as string ) ;
276299
277300 expect ( result . content . length ) . toBe ( 15000 ) ;
278301 expect ( result . truncated ) . toBe ( false ) ;
0 commit comments