@@ -23,10 +23,12 @@ type CapturedLmStudioRequest = {
2323 lastUserMessage : string
2424}
2525
26+ /** Returns the URL string for a fetch request input (string, URL, or Request). */
2627function getRequestUrl ( input : RequestInfo | URL ) : string {
2728 return typeof input === "string" ? input : input instanceof URL ? input . href : ( input as Request ) . url
2829}
2930
31+ /** True if the raw URL parses and its origin equals the expected origin. */
3032function isUrlWithOrigin ( rawUrl : string , expectedOrigin : string ) : boolean {
3133 try {
3234 return new URL ( rawUrl ) . origin === expectedOrigin
@@ -35,6 +37,7 @@ function isUrlWithOrigin(rawUrl: string, expectedOrigin: string): boolean {
3537 }
3638}
3739
40+ /** True if the raw URL points at an OpenAI-compatible /chat/completions endpoint. */
3841function isChatCompletionsUrl ( rawUrl : string ) : boolean {
3942 try {
4043 return new URL ( rawUrl ) . pathname . endsWith ( "/chat/completions" )
@@ -43,6 +46,11 @@ function isChatCompletionsUrl(rawUrl: string): boolean {
4346 }
4447}
4548
49+ /**
50+ * Installs a global fetch capture that records the model and last user message of every
51+ * chat completions request sent to the given base URL. Returns a function that restores
52+ * the original fetch.
53+ */
4654function installLmStudioRequestCapture ( capture : CapturedLmStudioRequest [ ] , baseUrl : string ) : ( ) => void {
4755 const originalFetch = globalThis . fetch
4856 const targetOrigin = new URL ( baseUrl ) . origin
@@ -74,6 +82,7 @@ suite("LM Studio provider", function () {
7482 let restoreFetch : ( ( ) => void ) | undefined
7583 const requests : CapturedLmStudioRequest [ ] = [ ]
7684
85+ /** Skips the suite when aimock replay mode is not active (no fixture source). */
7786 setup ( function ( ) {
7887 const aimockUrl = process . env . AIMOCK_URL
7988 // Only replay mode can serve the reasoning fixture: record mode has no
@@ -85,10 +94,12 @@ suite("LM Studio provider", function () {
8594 }
8695 } )
8796
97+ /** Captures chat completions requests sent to the aimock origin for later assertions. */
8898 suiteSetup ( ( ) => {
8999 restoreFetch = installLmStudioRequestCapture ( requests , process . env . AIMOCK_URL || "http://localhost:1234" )
90100 } )
91101
102+ /** Restores the original fetch and the default OpenRouter provider configuration. */
92103 suiteTeardown ( async ( ) => {
93104 restoreFetch ?.( )
94105 restoreFetch = undefined
@@ -105,6 +116,10 @@ suite("LM Studio provider", function () {
105116 } )
106117 } )
107118
119+ /**
120+ * Runs an ask-mode task against the aimock LM Studio fixture and asserts the reasoning
121+ * stream surfaces as a separate finalized reasoning message ahead of the completion.
122+ */
108123 test ( "should surface the LM Studio thinking stream as a separate reasoning message" , async ( ) => {
109124 requests . length = 0
110125
0 commit comments