Always register network diagnostics

This commit is contained in:
Christof Marti
2026-07-12 18:47:24 +02:00
parent 240f241712
commit efe8a5dafd
2 changed files with 85 additions and 3 deletions
@@ -252,6 +252,9 @@ async function main(): Promise<void> {
const agentService = new AgentService(logService, fileService, sessionDataService, productService, gitService, checkpointService, rootConfigResource, telemetryService, fileMonitorService, undefined, fetchFn);
disposables.add(agentService);
diServices.set(IAgentService, agentService);
const networkDiagnosticsService = instantiationService.createInstance(NetworkDiagnosticsService);
diServices.set(INetworkDiagnosticsService, networkDiagnosticsService);
agentService.setNetworkDiagnosticsService(networkDiagnosticsService);
// Register agents
let sdkDownloadProgress: Event<IAgentSdkDownloadProgress> | undefined;
@@ -296,9 +299,6 @@ async function main(): Promise<void> {
// to satisfy CopilotAgent / CopilotSessionLauncher DI.
diServices.set(IByokLmBridgeRegistry, new NullByokLmBridgeRegistry());
diServices.set(IByokLmProxyService, new NullByokLmProxyService());
const networkDiagnosticsService = instantiationService.createInstance(NetworkDiagnosticsService);
diServices.set(INetworkDiagnosticsService, networkDiagnosticsService);
agentService.setNetworkDiagnosticsService(networkDiagnosticsService);
const copilotAgent = disposables.add(instantiationService.createInstance(CopilotAgent));
agentService.registerProvider(copilotAgent);
log('CopilotAgent registered');
@@ -0,0 +1,82 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import assert from 'assert';
import type * as http from 'http';
import type { AddressInfo } from 'net';
import type { IAgentHostNetworkDiagnosticsInfo, IAgentHostNetworkFetchResult } from '../../../common/agentService.js';
import { PROTOCOL_VERSION } from '../../../common/state/protocol/version/registry.js';
import { ROOT_STATE_URI } from '../../../common/state/sessionState.js';
import { IServerHandle, startServer, TestProtocolClient } from './testHelpers.js';
suite('Protocol WebSocket - quiet network diagnostics', function () {
let server: IServerHandle;
let client: TestProtocolClient;
let target: http.Server;
let targetUrl: string;
suiteSetup(async function () {
this.timeout(15_000);
server = await startServer({ quiet: true });
const httpModule = await import('http');
target = httpModule.createServer((_request, response) => {
response.writeHead(200, { 'content-type': 'text/plain' });
response.end('pong');
});
await new Promise<void>((resolve, reject) => {
target.once('error', reject);
target.listen(0, '127.0.0.1', resolve);
});
targetUrl = `http://127.0.0.1:${(target.address() as AddressInfo).port}/ping`;
});
suiteTeardown(async function () {
server.process.kill();
await new Promise<void>(resolve => target.close(() => resolve()));
});
setup(async function () {
this.timeout(10_000);
client = new TestProtocolClient(server.port);
await client.connect();
await client.call('initialize', {
protocolVersions: [PROTOCOL_VERSION],
clientId: 'test-quiet-network-diagnostics',
initialSubscriptions: [ROOT_STATE_URI],
});
});
teardown(function () {
client.close();
});
test('serves host info and freeform fetch without production agents', async function () {
this.timeout(10_000);
const info = await client.call<IAgentHostNetworkDiagnosticsInfo>('getNetworkDiagnosticsInfo');
const result = await client.call<IAgentHostNetworkFetchResult>('diagnosticsFetch', { url: targetUrl });
assert.deepStrictEqual({
hasVersion: typeof info.version === 'string',
os: info.os,
arch: info.arch,
endpoints: info.endpoints,
url: result.url,
statusCode: result.statusCode,
body: result.body,
error: result.error,
}, {
hasVersion: true,
os: process.platform,
arch: process.arch,
endpoints: [],
url: targetUrl,
statusCode: 200,
body: 'pong',
error: undefined,
});
});
});