From fedc4f176236c81ac319529e7882c7acbc466c38 Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Mon, 18 Mar 2024 10:15:11 +1100 Subject: [PATCH] Use process.env.VITEST_POOL_ID if present --- lib/shared/src/sourcegraph-api/graphql/client.ts | 2 +- .../telemetry/MockServerTelemetryExporter.ts | 4 ++-- vscode/src/configuration.ts | 5 +++-- vscode/test/e2e/helpers.ts | 4 +++- vscode/test/fixtures/.vscode/settings.json | 1 - vscode/test/fixtures/mock-server.ts | 6 +++--- vscode/test/fixtures/multi-root.code-workspace | 1 - 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/shared/src/sourcegraph-api/graphql/client.ts b/lib/shared/src/sourcegraph-api/graphql/client.ts index 6a7b4cada10d..b7ae98d715b8 100644 --- a/lib/shared/src/sourcegraph-api/graphql/client.ts +++ b/lib/shared/src/sourcegraph-api/graphql/client.ts @@ -810,7 +810,7 @@ export class SourcegraphGraphQLAPIClient { // make an anonymous request to the Testing API private fetchSourcegraphTestingAPI(body: Record): Promise { - const url = 'http://localhost:49300/.api/testLogging' + const url = `http://localhost:4930${process.env.VITEST_POOL_ID || '0'}/.api/testLogging` const headers = new Headers({ 'Content-Type': 'application/json', }) diff --git a/lib/shared/src/sourcegraph-api/telemetry/MockServerTelemetryExporter.ts b/lib/shared/src/sourcegraph-api/telemetry/MockServerTelemetryExporter.ts index 36b828c749bc..11f6c147f8e5 100644 --- a/lib/shared/src/sourcegraph-api/telemetry/MockServerTelemetryExporter.ts +++ b/lib/shared/src/sourcegraph-api/telemetry/MockServerTelemetryExporter.ts @@ -3,12 +3,12 @@ import type { TelemetryEventInput, TelemetryExporter } from '@sourcegraph/teleme import { logError } from '../../logger' import { isError } from '../../utils' -const MOCK_URL = 'http://localhost:49300' +const MOCK_URL = `http://localhost:4930${process.env.VITEST_POOL_ID || '0'}` const ENDPOINT = '/.api/mockEventRecording' /** * MockServerTelemetryExporter exports events to a mock endpoint at - * http://localhost:49300/.api/mockEventRecording + * http://localhost:4930${/.api/mockEventRecording */ export class MockServerTelemetryExporter implements TelemetryExporter { constructor(private anonymousUserID: string) {} diff --git a/vscode/src/configuration.ts b/vscode/src/configuration.ts index 0fb5e4ac491b..a6ac586fc4ed 100644 --- a/vscode/src/configuration.ts +++ b/vscode/src/configuration.ts @@ -17,6 +17,8 @@ import { import { localStorage } from './services/LocalStorageProvider' import { getAccessToken } from './services/SecretStorageProvider' +import { SERVER_URL as MOCK_SERVER_URL } from '../test/fixtures/mock-server' + interface ConfigGetter { get(section: (typeof CONFIG_KEY)[ConfigKeys], defaultValue?: T): T } @@ -186,8 +188,7 @@ function sanitizeCodebase(codebase: string | undefined): string { export const getFullConfig = async (): Promise => { const config = getConfiguration() const isTesting = process.env.CODY_TESTING === 'true' - const serverEndpoint = - localStorage?.getEndpoint() || (isTesting ? 'http://localhost:49300/' : DOTCOM_URL.href) + const serverEndpoint = localStorage?.getEndpoint() || (isTesting ? MOCK_SERVER_URL : DOTCOM_URL.href) const accessToken = (await getAccessToken()) || null return { ...config, accessToken, serverEndpoint } } diff --git a/vscode/test/e2e/helpers.ts b/vscode/test/e2e/helpers.ts index f1bbb38b220b..089c517ba80f 100644 --- a/vscode/test/e2e/helpers.ts +++ b/vscode/test/e2e/helpers.ts @@ -12,6 +12,8 @@ import { MockServer, loggedEvents, resetLoggedEvents, sendTestInfo } from '../fi import { installVsCode } from './install-deps' import { buildCustomCommandConfigFile } from './utils/buildCustomCommands' +import { SERVER_URL as MOCK_SERVER_URL } from '../fixtures/mock-server' + // Playwright test extension: The workspace directory to run the test in. export interface WorkspaceDirectory { workspaceDirectory: string @@ -258,7 +260,7 @@ async function buildWorkSpaceSettings( extraSettings: WorkspaceSettings ): Promise { const settings = { - 'cody.serverEndpoint': 'http://localhost:49300', + 'cody.serverEndpoint': MOCK_SERVER_URL, 'cody.commandCodeLenses': true, 'cody.editorTitleCommandIcon': true, ...extraSettings, diff --git a/vscode/test/fixtures/.vscode/settings.json b/vscode/test/fixtures/.vscode/settings.json index ae7a78ff4270..0e28aad4e503 100644 --- a/vscode/test/fixtures/.vscode/settings.json +++ b/vscode/test/fixtures/.vscode/settings.json @@ -1,5 +1,4 @@ { - "cody.codebase": "http://localhost:49300", "cody.debug.enable": true, "cody.debug.verbose": true, } diff --git a/vscode/test/fixtures/mock-server.ts b/vscode/test/fixtures/mock-server.ts index 6886fdc0e285..0dbcfde5cea9 100644 --- a/vscode/test/fixtures/mock-server.ts +++ b/vscode/test/fixtures/mock-server.ts @@ -18,9 +18,9 @@ interface MockRequest { } } -const SERVER_PORT = 49300 - -export const SERVER_URL = 'http://localhost:49300' +// Support vitest parallelism +const SERVER_PORT = Number(`4930${process.env.VITEST_POOL_ID || '0'}`) +export const SERVER_URL = `http://localhost:${SERVER_PORT}` export const VALID_TOKEN = 'sgp_1234567890123456789012345678901234567890' const responses = { diff --git a/vscode/test/fixtures/multi-root.code-workspace b/vscode/test/fixtures/multi-root.code-workspace index 9b10eac4494b..641d861ef7d3 100644 --- a/vscode/test/fixtures/multi-root.code-workspace +++ b/vscode/test/fixtures/multi-root.code-workspace @@ -10,7 +10,6 @@ "settings": { // Settings that should also apply to the single-root workspace tests should also be // included in fixtures\workspace\.vscode\settings.json! - "cody.serverEndpoint": "http://localhost:49300", "cody.commandCodeLenses": true, "cody.editorTitleCommandIcon": true, "cody.experimental.symfContext": false,