Skip to content

Commit a4ebae2

Browse files
Copilotdata-douser
andauthored
fix: apply PR review feedback - env invalidation, +rN version format, vi.spyOn cleanup
Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/b3b84dce-0b52-4c7d-9391-014500df1b9a Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 28f1776 commit a4ebae2

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

extensions/vscode/src/extension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export async function activate(
8282
vscode.workspace.onDidChangeConfiguration((e) => {
8383
if (e.affectsConfiguration('codeql-mcp')) {
8484
logger.info('Configuration changed — requesting MCP server restart');
85-
envBuilder.invalidate();
8685
mcpProvider.requestRestart();
8786
}
8887
}),

extensions/vscode/src/server/mcp-provider.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ export class McpProvider
5252
/**
5353
* Request that VS Code restart the MCP server with a fresh environment.
5454
*
55-
* Bumps the internal revision counter so that the next call to
56-
* `provideMcpServerDefinitions()` returns a definition with a different
57-
* `version` string. VS Code compares the new version to the running
58-
* server's version and, seeing a change, triggers a stop → start cycle.
55+
* Invalidates the cached environment and bumps the internal revision counter
56+
* so that the next call to `provideMcpServerDefinitions()` returns a
57+
* definition with a different `version` string. VS Code compares the new
58+
* version to the running server's version and, seeing a change, triggers a
59+
* stop → start cycle.
5960
*
6061
* Use for changes that require a server restart (configuration changes).
6162
*/
6263
requestRestart(): void {
64+
this.envBuilder.invalidate();
6365
this._revision++;
6466
this.logger.info(
6567
`Requesting ql-mcp restart (revision ${this._revision})...`,
@@ -108,7 +110,7 @@ export class McpProvider
108110
* returns `undefined` (the "latest" / unpinned case), the extension
109111
* version is used as the base instead.
110112
*
111-
* After one or more `requestRestart()` calls, a `.N` revision suffix
113+
* After one or more `requestRestart()` calls, a `+rN` revision suffix
112114
* is appended so that the version is always different from the
113115
* previous one. VS Code uses the version to decide whether to
114116
* restart a running server: a changed version triggers a stop → start
@@ -121,6 +123,6 @@ export class McpProvider
121123
if (this._revision === 0) {
122124
return base;
123125
}
124-
return `${base}.${this._revision}`;
126+
return `${base}+r${this._revision}`;
125127
}
126128
}

extensions/vscode/test/extension.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ describe('Extension', () => {
175175
it('should invalidate env cache on workspace folder changes', async () => {
176176
// Capture the workspace folder change callback
177177
let workspaceFolderChangeCallback: Function | undefined;
178-
const vscodeMock = vi.mocked(vscode);
179-
vscodeMock.workspace.onDidChangeWorkspaceFolders = vi.fn().mockImplementation(
178+
const spy = vi.spyOn(vscode.workspace, 'onDidChangeWorkspaceFolders').mockImplementation(
180179
(cb: Function) => { workspaceFolderChangeCallback = cb; return { dispose: vi.fn() }; },
181180
);
182181

@@ -202,5 +201,7 @@ describe('Extension', () => {
202201
expect(envBuilderInstance.invalidate).toHaveBeenCalledTimes(1);
203202
expect(mcpProviderInstance.fireDidChange).not.toHaveBeenCalled();
204203
expect(mcpProviderInstance.requestRestart).not.toHaveBeenCalled();
204+
205+
spy.mockRestore();
205206
});
206207
});

extensions/vscode/test/server/mcp-provider.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe('McpProvider', () => {
180180
provider.requestRestart();
181181
const definitions = await provider.provideMcpServerDefinitions(token as any);
182182

183-
expect(definitions![0].version).toMatch(/^2\.20\.0\.\d+$/);
183+
expect(definitions![0].version).toMatch(/^2\.20\.0\+r\d+$/);
184184
});
185185

186186
it('should append revision to extension version after requestRestart when version is latest', async () => {
@@ -191,7 +191,7 @@ describe('McpProvider', () => {
191191
provider.requestRestart();
192192
const definitions = await provider.provideMcpServerDefinitions(token as any);
193193

194-
expect(definitions![0].version).toMatch(/^2\.25\.1\.\d+$/);
194+
expect(definitions![0].version).toMatch(/^2\.25\.1\+r\d+$/);
195195
});
196196

197197
it('should fire change event when requestRestart is called', () => {
@@ -203,6 +203,12 @@ describe('McpProvider', () => {
203203
expect(listener).toHaveBeenCalledTimes(1);
204204
});
205205

206+
it('should invalidate env cache when requestRestart is called', () => {
207+
provider.requestRestart();
208+
209+
expect(envBuilder.invalidate).toHaveBeenCalledTimes(1);
210+
});
211+
206212
it('should resolve definition by refreshing environment', async () => {
207213
const updatedEnv = { CODEQL_PATH: '/new/path', TRANSPORT_MODE: 'stdio' };
208214
envBuilder.build.mockResolvedValue(updatedEnv);

0 commit comments

Comments
 (0)