File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ describe("clawhub helpers", () => {
5959 const originalHome = process . env . HOME ;
6060
6161 afterEach ( ( ) => {
62+ delete process . env . OPENCLAW_CLAWHUB_URL ;
6263 delete process . env . OPENCLAW_CLAWHUB_TOKEN ;
6364 delete process . env . CLAWHUB_TOKEN ;
6465 delete process . env . CLAWHUB_AUTH_TOKEN ;
@@ -275,6 +276,29 @@ describe("clawhub helpers", () => {
275276 await expect ( searchClawHubSkills ( { query : "calendar" , fetchImpl } ) ) . resolves . toStrictEqual ( [ ] ) ;
276277 } ) ;
277278
279+ it ( "preserves the configured ClawHub base URL path prefix" , async ( ) => {
280+ process . env . OPENCLAW_CLAWHUB_URL = "https://internal.example.com/clawhub" ;
281+ let requestedUrl = "" ;
282+
283+ await expect (
284+ searchClawHubSkills ( {
285+ query : "calendar" ,
286+ fetchImpl : async ( input ) => {
287+ requestedUrl = input instanceof Request ? input . url : String ( input ) ;
288+ return new Response ( JSON . stringify ( { results : [ ] } ) , {
289+ status : 200 ,
290+ headers : { "content-type" : "application/json" } ,
291+ } ) ;
292+ } ,
293+ } ) ,
294+ ) . resolves . toStrictEqual ( [ ] ) ;
295+
296+ const url = new URL ( requestedUrl ) ;
297+ expect ( url . origin ) . toBe ( "https://internal.example.com" ) ;
298+ expect ( url . pathname ) . toBe ( "/clawhub/api/v1/search" ) ;
299+ expect ( url . searchParams . get ( "q" ) ) . toBe ( "calendar" ) ;
300+ } ) ;
301+
278302 it ( "fetches typed package readiness reports" , async ( ) => {
279303 let requestedUrl = "" ;
280304 await expect (
Original file line number Diff line number Diff line change @@ -551,7 +551,10 @@ function normalizeCalVerCorrectionForPluginApi(pluginApiVersion: string): string
551551}
552552
553553function buildUrl ( params : Pick < ClawHubRequestParams , "baseUrl" | "path" | "search" > ) : URL {
554- const url = new URL ( params . path , `${ normalizeBaseUrl ( params . baseUrl ) } /` ) ;
554+ const url = new URL ( `${ normalizeBaseUrl ( params . baseUrl ) } /` ) ;
555+ const basePath = url . pathname . replace ( / \/ + $ / , "" ) ;
556+ const requestPath = params . path . startsWith ( "/" ) ? params . path : `/${ params . path } ` ;
557+ url . pathname = `${ basePath } ${ requestPath } ` ;
555558 for ( const [ key , value ] of Object . entries ( params . search ?? { } ) ) {
556559 if ( ! value ) {
557560 continue ;
You can’t perform that action at this time.
0 commit comments