Skip to content

Commit d1d4c69

Browse files
committed
test(e2e): guard LM Studio suite hooks by replay mode and clear provider fields
Addresses CodeRabbit review on PR #1322: compute the replay-mode flag once at suite scope and guard suiteSetup/suiteTeardown so a skipped suite no longer patches globalThis.fetch or writes provider configuration; teardown now explicitly clears lmStudioBaseUrl and lmStudioModelId because setConfiguration only updates supplied keys.
1 parent bbbe1b7 commit d1d4c69

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

‎apps/vscode-e2e/src/suite/providers/lmstudio.test.ts‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,40 +79,50 @@ function installLmStudioRequestCapture(capture: CapturedLmStudioRequest[], baseU
7979
suite("LM Studio provider", function () {
8080
setDefaultSuiteTimeout(this)
8181

82+
// Only replay mode can serve the reasoning fixture: record mode has no
83+
// real LM Studio upstream to proxy to, and live runs have no aimock.
84+
// Computed once at suite scope so the suite hooks can be guarded as well:
85+
// a skipped suite must not touch shared fetch or provider configuration.
86+
const isReplay = !!process.env.AIMOCK_URL && process.env.AIMOCK_RECORD !== "true"
87+
8288
let restoreFetch: (() => void) | undefined
8389
const requests: CapturedLmStudioRequest[] = []
8490

8591
/** Skips the suite when aimock replay mode is not active (no fixture source). */
8692
setup(function () {
87-
const aimockUrl = process.env.AIMOCK_URL
88-
// Only replay mode can serve the reasoning fixture: record mode has no
89-
// real LM Studio upstream to proxy to, and live runs have no aimock.
90-
const isReplay = !!aimockUrl && process.env.AIMOCK_RECORD !== "true"
91-
9293
if (!isReplay) {
9394
this.skip()
9495
}
9596
})
9697

9798
/** Captures chat completions requests sent to the aimock origin for later assertions. */
9899
suiteSetup(() => {
99-
restoreFetch = installLmStudioRequestCapture(requests, process.env.AIMOCK_URL || "http://localhost:1234")
100+
if (!isReplay) {
101+
return
102+
}
103+
104+
restoreFetch = installLmStudioRequestCapture(requests, process.env.AIMOCK_URL!)
100105
})
101106

102107
/** Restores the original fetch and the default OpenRouter provider configuration. */
103108
suiteTeardown(async () => {
109+
if (!isReplay) {
110+
return
111+
}
112+
104113
restoreFetch?.()
105114
restoreFetch = undefined
106115

107116
// Restore the default OpenRouter config so subsequent suites are unaffected.
117+
// Explicitly clear the LM Studio fields: setConfiguration only updates
118+
// supplied keys, so omitting them would leave them set for later suites.
108119
await globalThis.api.setConfiguration({
109120
apiProvider: "openrouter" as const,
110-
openRouterApiKey:
111-
process.env.AIMOCK_URL && process.env.AIMOCK_RECORD !== "true"
112-
? "mock-key"
113-
: process.env.OPENROUTER_API_KEY!,
121+
lmStudioBaseUrl: undefined,
122+
lmStudioModelId: undefined,
123+
openRouterApiKey: "mock-key",
114124
openRouterModelId: "openai/gpt-4.1",
115-
...(process.env.AIMOCK_URL && { openRouterBaseUrl: `${process.env.AIMOCK_URL}/v1` }),
125+
openRouterBaseUrl: `${process.env.AIMOCK_URL}/v1`,
116126
})
117127
})
118128

0 commit comments

Comments
 (0)