Path: blob/main/extensions/copilot/test/base/simulationEndpointHealth.ts
13388 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import { SimpleRPC } from '../../src/extension/onboardDebug/node/copilotDebugWorker/rpc';5import { ChatFetchError } from '../../src/platform/chat/common/commonTypes';6import { createServiceIdentifier } from '../../src/util/common/services';7import { CachedTestInfo } from './cachingChatMLFetcher';89export const ISimulationEndpointHealth = createServiceIdentifier<ISimulationEndpointHealth>('ISimulationEndpointHealth');1011export interface ISimulationEndpointHealth {12readonly _serviceBrand: undefined;13readonly failures: { testInfo: CachedTestInfo; request: ChatFetchError }[];14markFailure(testInfo: CachedTestInfo, failedRequest: ChatFetchError): void;15}1617export class SimulationEndpointHealthImpl implements ISimulationEndpointHealth {1819declare readonly _serviceBrand: undefined;2021public readonly failures: { testInfo: CachedTestInfo; request: ChatFetchError }[] = [];2223constructor() { }2425markFailure(testInfo: CachedTestInfo, request: ChatFetchError) {26this.failures.push({ testInfo, request });27}28}2930export class ProxiedSimulationEndpointHealth implements ISimulationEndpointHealth {31declare readonly _serviceBrand: undefined;3233public readonly failures: { testInfo: CachedTestInfo; request: ChatFetchError }[] = [];3435public static registerTo(instance: ISimulationEndpointHealth, rpc: SimpleRPC): ISimulationEndpointHealth {36rpc.registerMethod('ProxiedSimulationEndpointHealth.markFailure', ({ testInfo, request }) => {37instance.markFailure(testInfo, request);38});39return instance;40}4142constructor(43private readonly rpc: SimpleRPC,44) { }4546markFailure(testInfo: CachedTestInfo, request: ChatFetchError): void {47this.failures.push({ testInfo, request });48this.rpc.callMethod('ProxiedSimulationEndpointHealth.markFailure', { testInfo, request });49}50}515253