snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,303 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import type {Page, Route} from '@playwright/test';
|
||||
|
||||
interface MockTranslateRequest {
|
||||
q?: string;
|
||||
text?: string;
|
||||
source?: string;
|
||||
target?: string;
|
||||
}
|
||||
|
||||
interface MockTranslateResponse {
|
||||
translatedText: string;
|
||||
detectedLanguage: {language: string; confidence: number};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks the source language for mock translation responses
|
||||
* Used to simulate language detection behavior
|
||||
*/
|
||||
let mockSourceLanguage = 'es';
|
||||
|
||||
/**
|
||||
* Simple language detection from text content
|
||||
* Simulates how real LibreTranslate detects language from actual message text
|
||||
*/
|
||||
function detectLanguageFromText(text: string): string {
|
||||
if (!text) {
|
||||
return mockSourceLanguage;
|
||||
}
|
||||
|
||||
const lowerText = text.toLowerCase();
|
||||
|
||||
// Spanish patterns
|
||||
const spanishIndicators = [
|
||||
'el ',
|
||||
'la ',
|
||||
'de ',
|
||||
'que ',
|
||||
'para ',
|
||||
'con ',
|
||||
'una ',
|
||||
'este ',
|
||||
'está',
|
||||
'muy',
|
||||
'en ',
|
||||
'aquí',
|
||||
'gracias',
|
||||
'hola',
|
||||
'adiós',
|
||||
];
|
||||
const spanishMatches = spanishIndicators.filter((indicator) => lowerText.includes(indicator)).length;
|
||||
|
||||
// English patterns
|
||||
const englishIndicators = [
|
||||
'the ',
|
||||
'and ',
|
||||
'is ',
|
||||
'to ',
|
||||
'of ',
|
||||
'that ',
|
||||
'this ',
|
||||
'for ',
|
||||
'with ',
|
||||
'hello',
|
||||
'thanks',
|
||||
'please',
|
||||
'translation',
|
||||
];
|
||||
const englishMatches = englishIndicators.filter((indicator) => lowerText.includes(indicator)).length;
|
||||
|
||||
// French patterns
|
||||
const frenchIndicators = [
|
||||
'le ',
|
||||
'la ',
|
||||
'de ',
|
||||
'est ',
|
||||
'que ',
|
||||
'pour ',
|
||||
'avec ',
|
||||
'un ',
|
||||
'une ',
|
||||
'ça',
|
||||
'bonjour',
|
||||
'merci',
|
||||
];
|
||||
const frenchMatches = frenchIndicators.filter((indicator) => lowerText.includes(indicator)).length;
|
||||
|
||||
// Return the language with most matches
|
||||
if (spanishMatches > englishMatches && spanishMatches > frenchMatches) {
|
||||
return 'es';
|
||||
}
|
||||
if (englishMatches > frenchMatches) {
|
||||
return 'en';
|
||||
}
|
||||
if (frenchMatches > 0) {
|
||||
return 'fr';
|
||||
}
|
||||
|
||||
// Default to configured mock language
|
||||
return mockSourceLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source language that the mock will detect
|
||||
* Useful for testing language detection and filtering logic
|
||||
*/
|
||||
export function setMockSourceLanguage(language: string): void {
|
||||
mockSourceLanguage = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current mock source language
|
||||
*/
|
||||
export function getMockSourceLanguage(): string {
|
||||
return mockSourceLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset mock source language to default
|
||||
*/
|
||||
export function resetMockSourceLanguage(): void {
|
||||
mockSourceLanguage = 'es';
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock the autotranslation API route using Playwright's route interception.
|
||||
* This replaces the need for an external mock server.
|
||||
*
|
||||
* Returns a `Disposable` to remove the mock routes. Use with `await using`
|
||||
* for automatic cleanup or call `.dispose()` manually:
|
||||
*
|
||||
* ```ts
|
||||
* await using mock = await mockAutotranslationRoute(page);
|
||||
* ```
|
||||
*
|
||||
* @param page - Playwright Page object
|
||||
* @param options - Optional configuration
|
||||
* @param options.sourceLanguage - Initial detected source language (default: 'es')
|
||||
* @param options.supportedLanguages - List of supported target languages (default: ['en', 'es', 'fr', 'de'])
|
||||
*/
|
||||
export async function mockAutotranslationRoute(
|
||||
page: Page,
|
||||
options?: {
|
||||
sourceLanguage?: string;
|
||||
supportedLanguages?: string[];
|
||||
},
|
||||
): Promise<{dispose(): Promise<void>; [Symbol.asyncDispose](): Promise<void>}> {
|
||||
// Reset mockSourceLanguage to avoid state leakage between tests
|
||||
mockSourceLanguage = options?.sourceLanguage || 'es';
|
||||
|
||||
const supportedLanguages = options?.supportedLanguages || ['en', 'es', 'fr', 'de'];
|
||||
|
||||
// Named handler so it can be passed to page.unroute() for cleanup
|
||||
const translateHandler = async (route: Route): Promise<void> => {
|
||||
const request = route.request();
|
||||
const method = request.method();
|
||||
|
||||
if (method === 'POST') {
|
||||
let postData: MockTranslateRequest;
|
||||
try {
|
||||
postData = (await request.postDataJSON()) as MockTranslateRequest;
|
||||
} catch {
|
||||
// If POST data is not JSON, try to parse as form-encoded data
|
||||
const postDataBuffer = request.postData();
|
||||
if (!postDataBuffer) {
|
||||
await route.abort('failed');
|
||||
return;
|
||||
}
|
||||
// Parse form-encoded data (application/x-www-form-urlencoded)
|
||||
const formData = new URLSearchParams(postDataBuffer.toString());
|
||||
postData = {
|
||||
q: formData.get('q') || undefined,
|
||||
text: formData.get('text') || undefined,
|
||||
source: formData.get('source') || undefined,
|
||||
target: formData.get('target') || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const textToTranslate = postData.q || postData.text || '';
|
||||
// When source is empty or "auto", detect language from text (simulates real LibreTranslate)
|
||||
// Otherwise use the provided source language
|
||||
const sourceLanguage =
|
||||
postData.source && postData.source !== 'auto'
|
||||
? postData.source
|
||||
: detectLanguageFromText(textToTranslate);
|
||||
const targetLanguage = postData.target || 'en';
|
||||
|
||||
// Validate target language is supported
|
||||
if (!supportedLanguages.includes(targetLanguage)) {
|
||||
await route.fulfill({
|
||||
status: 400,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
error: `Target language '${targetLanguage}' is not supported`,
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Mock response: only "translate" if source differs from target
|
||||
let translatedText = textToTranslate;
|
||||
const shouldTranslate = sourceLanguage !== targetLanguage;
|
||||
|
||||
if (shouldTranslate) {
|
||||
// Prepend language code to simulate translation
|
||||
translatedText = `[${targetLanguage}] ${textToTranslate}`;
|
||||
}
|
||||
|
||||
const response: MockTranslateResponse = {
|
||||
translatedText,
|
||||
detectedLanguage: {
|
||||
language: sourceLanguage,
|
||||
confidence: 0.95,
|
||||
},
|
||||
};
|
||||
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(response),
|
||||
});
|
||||
} else if (method === 'GET') {
|
||||
// Handle GET requests (e.g., /translate?q=hello&source=es&target=en)
|
||||
const url = new URL(request.url());
|
||||
const textToTranslate = url.searchParams.get('q') || '';
|
||||
const sourceParam = url.searchParams.get('source');
|
||||
// When source is empty or "auto", detect language from text (simulates real LibreTranslate)
|
||||
const sourceLanguage =
|
||||
sourceParam && sourceParam !== 'auto' ? sourceParam : detectLanguageFromText(textToTranslate);
|
||||
const targetLanguage = url.searchParams.get('target') || 'en';
|
||||
|
||||
if (!supportedLanguages.includes(targetLanguage)) {
|
||||
await route.fulfill({
|
||||
status: 400,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
error: `Target language '${targetLanguage}' is not supported`,
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let translatedText = textToTranslate;
|
||||
const shouldTranslate = sourceLanguage !== targetLanguage;
|
||||
|
||||
if (shouldTranslate) {
|
||||
translatedText = `[${targetLanguage}] ${textToTranslate}`;
|
||||
}
|
||||
|
||||
const response: MockTranslateResponse = {
|
||||
translatedText,
|
||||
detectedLanguage: {
|
||||
language: sourceLanguage,
|
||||
confidence: 0.95,
|
||||
},
|
||||
};
|
||||
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(response),
|
||||
});
|
||||
} else {
|
||||
await route.abort('failed');
|
||||
}
|
||||
};
|
||||
|
||||
// Named handler so it can be passed to page.unroute() for cleanup
|
||||
const detectHandler = async (route: Route): Promise<void> => {
|
||||
// Language detection is mocked to always return the configured source language
|
||||
// regardless of the input text
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
result: [
|
||||
{
|
||||
language: mockSourceLanguage,
|
||||
confidence: 0.95,
|
||||
},
|
||||
],
|
||||
detectedLanguage: {language: mockSourceLanguage, confidence: 0.95},
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
// Mock LibreTranslate API endpoints
|
||||
await page.route('**/api/translate', translateHandler);
|
||||
await page.route('**/api/detect', detectHandler);
|
||||
|
||||
return {
|
||||
async dispose() {
|
||||
await page.unroute('**/api/translate', translateHandler);
|
||||
await page.unroute('**/api/detect', detectHandler);
|
||||
},
|
||||
async [Symbol.asyncDispose]() {
|
||||
await page.unroute('**/api/translate', translateHandler);
|
||||
await page.unroute('**/api/detect', detectHandler);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user