diff --git a/e2e/mock-config.test.mjs b/e2e/mock-config.test.mjs new file mode 100644 index 0000000000..c27710ea7f --- /dev/null +++ b/e2e/mock-config.test.mjs @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { spawnSync } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; + +const require = createRequire(import.meta.url); +const yaml = createRequire(new URL('../packages/api/package.json', import.meta.url))('js-yaml'); +const root = fileURLToPath(new URL('../', import.meta.url)); + +// Listing tests loads the real config and writes its runtime YAML without starting services. +test('mock config keeps the HTTP MCP URL aligned with its fixture port', () => { + for (const overrides of [ + { E2E_MCP_HTTP_PORT: '', E2E_MCP_OAUTH_PORT: '' }, + { E2E_MCP_HTTP_PORT: '24005', E2E_MCP_OAUTH_PORT: '' }, + { E2E_MCP_HTTP_PORT: '8767', E2E_MCP_OAUTH_PORT: '24007' }, + ]) { + const result = spawnSync( + process.execPath, + [ + require.resolve('@playwright/test/cli'), + 'test', + '--config=e2e/playwright.config.mock.ts', + '--list', + 'mcp-allowlist-override.spec.ts', + ], + { + cwd: root, + env: { ...process.env, ...overrides }, + encoding: 'utf8', + timeout: 30000, + }, + ); + assert.equal(result.status, 0, result.stderr || result.stdout); + const config = yaml.load( + readFileSync(new URL('.generated/librechat.e2e.yaml', import.meta.url), 'utf8'), + ); + assert.equal( + config.mcpServers['e2e-http'].url, + `http://127.0.0.1:${overrides.E2E_MCP_HTTP_PORT || '8765'}/mcp`, + ); + assert.equal( + config.mcpServers['e2e-oauth'].url, + `http://127.0.0.1:${overrides.E2E_MCP_OAUTH_PORT || '8767'}/mcp`, + ); + } +}); diff --git a/e2e/playwright.config.mock.ts b/e2e/playwright.config.mock.ts index 1d7f605792..54e0c9f2a6 100644 --- a/e2e/playwright.config.mock.ts +++ b/e2e/playwright.config.mock.ts @@ -260,10 +260,13 @@ const preservedCredentialEnvKeys = new Set([ */ function writeRuntimeMockConfig() { const template = fs.readFileSync(configTemplatePath, 'utf8'); + // Keep this URL out of the other substitutions when the override uses another fixture's default port. + const httpMcpPlaceholder = '__E2E_HTTP_MCP_URL__'; let config = process.env.E2E_MODEL_SPECS_ENFORCE === 'true' ? template.replace('\n enforce: false\n', '\n enforce: true\n') : template; + config = config.replace('http://127.0.0.1:8765/mcp', httpMcpPlaceholder); config = config.replace( ' agents:\n', ` agents:\n managementApi: ${JSON.stringify({ auth: managementAuth })}\n`, @@ -408,6 +411,7 @@ function writeRuntimeMockConfig() { if (MCP_OAUTH_PORT !== '8767') { config = config.split('127.0.0.1:8767').join(`127.0.0.1:${MCP_OAUTH_PORT}`); } + config = config.replace(httpMcpPlaceholder, `http://127.0.0.1:${MCP_HTTP_PORT}/mcp`); fs.mkdirSync(path.dirname(configPath), { recursive: true }); fs.writeFileSync(configPath, config); if (enableDynamicMcp) {