Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node

import { Octokit } from '@octokit/rest';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ export function partitionSummary(summary) {
export function allocateBucketSlots(topN, counts) {
const { broken = 0, flaky = 0, watch = 0, infra = 0 } = counts;

let maxBroken = Math.min(
const maxBroken = Math.min(
broken,
Math.max(Math.ceil(topN * 0.4), broken > 0 ? 2 : 0),
);
let maxFlaky = Math.min(
const maxFlaky = Math.min(
flaky,
Math.max(Math.ceil(topN * 0.25), flaky > 0 ? 2 : 0),
);
let maxInfra = Math.min(
const maxInfra = Math.min(
infra,
Math.max(Math.ceil(topN * 0.1), infra > 0 ? 1 : 0),
);
let maxWatch = Math.min(watch, topN - maxBroken - maxFlaky - maxInfra);
const maxWatch = Math.min(watch, topN - maxBroken - maxFlaky - maxInfra);

let remaining = topN - (maxBroken + maxFlaky + maxWatch + maxInfra);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,41 @@
* - Optional testDir prefix (e.g. accounts/foo.spec.ts → tests/smoke-appium/accounts/foo.spec.ts)
* - Idempotent when the path already starts with the prefix or `tests/`
*
* @param {string} filePath
* @param {{ prefix?: string }} [options]
* @returns {string}
* @param {string} filePath - The test file path to normalize.
* @param {{ prefix?: string }} [options] - The options, where `prefix` is the test directory prepended to relative paths.
* @returns {string} The normalized repo relative path.
*/
export function normalizeRepoFilePath(filePath, { prefix } = {}) {
if (!filePath) {
return filePath;
}

let normalized = String(filePath).replace(/\\/g, '/');
let normalized = String(filePath).replace(/\\/gu, '/');

const isAbsolute =
normalized.startsWith('/') || /^[A-Za-z]:\//.test(normalized);
normalized.startsWith('/') || /^[A-Za-z]:\//u.test(normalized);
if (isAbsolute) {
const testsMatch = normalized.match(/(?:^|\/)(tests\/.+)$/);
const testsMatch = normalized.match(/(?:^|\/)(tests\/.+)$/u);
if (testsMatch) {
normalized = testsMatch[1];
} else {
const runnerMatch = normalized.match(/\/work\/[^/]+\/[^/]+\/(.+)$/);
const runnerMatch = normalized.match(/\/work\/[^/]+\/[^/]+\/(.+)$/u);
if (runnerMatch) {
normalized = runnerMatch[1];
} else {
normalized = normalized.replace(/^\/+/, '').replace(/^[A-Za-z]:\//, '');
normalized = normalized
.replace(/^\/+/u, '')
.replace(/^[A-Za-z]:\//u, '');
}
}
}

normalized = normalized.replace(/^\/+/, '');
normalized = normalized.replace(/^\/+/u, '');

const cleanPrefix = prefix
?.trim()
.replace(/\\/g, '/')
.replace(/^\/+|\/+$/g, '');
.replace(/\\/gu, '/')
.replace(/^\/+|\/+$/gu, '');
if (cleanPrefix) {
const alreadyPrefixed =
normalized === cleanPrefix ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export function normalizeErrorForSlack(message, maxLength = 120) {
}

const withoutEmojiShortcodes = String(message).replace(
/:[a-z0-9_+\-]+:/gi,
/:[a-z0-9_+-]+:/giu,
' ',
);
const firstMeaningfulLine = withoutEmojiShortcodes
.split(/\r?\n/)
.split(/\r?\n/u)
.map((line) => line.trim())
.find(Boolean);
const normalized = (firstMeaningfulLine || withoutEmojiShortcodes)
.replace(/\s+/g, ' ')
.replace(/\s+/gu, ' ')
.trim();

if (!normalized) {
Expand Down
35 changes: 18 additions & 17 deletions .github/scripts/create-flaky-test-report.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env node

// Based on the original script done by @itsyoboieltr on Extension repo

import { Octokit } from '@octokit/rest';
import { IncomingWebhook } from '@slack/webhook';
import unzipper from 'unzipper';

const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) throw new Error('Missing GITHUB_TOKEN env var');
if (!githubToken) {
throw new Error('Missing GITHUB_TOKEN env var');
}

const env = {
GITHUB_TOKEN: process.env.GITHUB_TOKEN,
LOOKBACK_DAYS: parseInt(process.env.LOOKBACK_DAYS ?? '1'),
LOOKBACK_DAYS: parseInt(process.env.LOOKBACK_DAYS ?? '1', 10),
TEST_RESULTS_FILE_PATTERN:
process.env.TEST_RESULTS_FILE_PATTERN || 'test-runs',
OWNER: process.env.OWNER || 'MetaMask',
Expand Down Expand Up @@ -184,7 +185,7 @@ function extractRealFailures(testData) {
jobId: testSuite.job?.id,
runId: testSuite.job?.runId,
date: new Date(testSuite.date || Date.now()),
retryCount: retryCount,
retryCount,
type: 'real_failure',
});
}
Expand Down Expand Up @@ -237,7 +238,7 @@ function extractFlakyTests(testData) {
jobId: failureInfo.jobId,
runId: failureInfo.runId,
date: failureInfo.date,
retryCount: retryCount,
retryCount,
type: 'flaky',
});
}
Expand Down Expand Up @@ -450,7 +451,7 @@ function createSlackBlocks(
// Each failure
top10
.filter((test) => test.realFailures > 0)
.forEach((test, idx) => {
.forEach((test) => {
const globalIndex = top10.indexOf(test) + 1;
const failText = test.realFailures === 1 ? 'time' : 'times';
const retryText = test.totalRetries === 1 ? 'retry' : 'retries';
Expand Down Expand Up @@ -482,7 +483,7 @@ function createSlackBlocks(
elements: [
{
type: 'rich_text_section',
elements: elements,
elements,
},
],
});
Expand All @@ -491,7 +492,7 @@ function createSlackBlocks(
const error = test.lastRealFailureError;
if (error) {
const errorPreview =
error.length > 150 ? error.substring(0, 150) + '...' : error;
error.length > 150 ? `${error.substring(0, 150)}...` : error;
blocks.push({
type: 'rich_text',
elements: [
Expand All @@ -500,7 +501,7 @@ function createSlackBlocks(
elements: [
{
type: 'text',
text: ` ${errorPreview.replace(/\n/g, ' ')}`,
text: ` ${errorPreview.replace(/\n/gu, ' ')}`,
style: { italic: true },
},
],
Expand Down Expand Up @@ -577,7 +578,7 @@ function createSlackBlocks(
elements: [
{
type: 'rich_text_section',
elements: elements,
elements,
},
],
});
Expand All @@ -586,7 +587,7 @@ function createSlackBlocks(
const error = test.flakyFailureError;
if (error) {
const errorPreview =
error.length > 150 ? error.substring(0, 150) + '...' : error;
error.length > 150 ? `${error.substring(0, 150)}...` : error;
blocks.push({
type: 'rich_text',
elements: [
Expand All @@ -595,7 +596,7 @@ function createSlackBlocks(
elements: [
{
type: 'text',
text: ` ${errorPreview.replace(/\n/g, ' ')}`,
text: ` ${errorPreview.replace(/\n/gu, ' ')}`,
style: { italic: true },
},
],
Expand All @@ -610,7 +611,7 @@ function createSlackBlocks(
}

function displayResults(summary, dateDisplay) {
console.log('\n' + '='.repeat(80));
console.log(`\n${'='.repeat(80)}`);
console.log(`📊 REPORT - ${dateDisplay}`);
console.log('='.repeat(80));

Expand Down Expand Up @@ -662,9 +663,9 @@ function displayResults(summary, dateDisplay) {
if (test.lastRealFailureError) {
const errorPreview =
test.lastRealFailureError.length > 100
? test.lastRealFailureError.substring(0, 100) + '...'
? `${test.lastRealFailureError.substring(0, 100)}...`
: test.lastRealFailureError;
console.log(` 💥 Error: ${errorPreview.replace(/\n/g, ' ')}`);
console.log(` 💥 Error: ${errorPreview.replace(/\n/gu, ' ')}`);
}
} else {
// Flaky tests (failed initially but eventually passed)
Expand All @@ -684,10 +685,10 @@ function displayResults(summary, dateDisplay) {
if (test.flakyFailureError) {
const errorPreview =
test.flakyFailureError.length > 100
? test.flakyFailureError.substring(0, 100) + '...'
? `${test.flakyFailureError.substring(0, 100)}...`
: test.flakyFailureError;
console.log(
` 💥 Initial error: ${errorPreview.replace(/\n/g, ' ')}`,
` 💥 Initial error: ${errorPreview.replace(/\n/gu, ' ')}`,
);
}
}
Expand Down
36 changes: 15 additions & 21 deletions .github/scripts/generate-rc-commits.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ async function getTeam(repository, prNumber) {

const topologyJsonUrl =
'https://raw.githubusercontent.com/MetaMask/MetaMask-planning/refs/heads/main/topology.json';
const githubToken = process.env.GITHUB_TOKEN;
const topologyToken = process.env.GITHUB_TOKEN;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What lint violation does this fix? 😅

@cryptodev-2s cryptodev-2s Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None I left it in purpose because its just more readable which token is this. I can rename it back if we prefer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, was just curious.


const response = await axios.get(topologyJsonUrl, {
headers: { Authorization: `token ${githubToken}` },
headers: { Authorization: `token ${topologyToken}` },
});

// Check if the response is successful and contains data
if (response.status !== 200 || !response.data) {
console.error(
`Invalid response when fetching topology.json: ${response.status}`,
);
return undefined;
return;
}

const topologyJson = response.data;
Expand All @@ -59,13 +59,11 @@ async function getTeam(repository, prNumber) {
}

// Return undefined if author not found in any team
return undefined;
} catch (error) {
console.error(
`Error fetching team for PR #${prNumber}:`,
error.message || error,
);
return undefined;
}
}

Expand All @@ -75,7 +73,7 @@ async function filterCommitsByTeam(platform, refA, refB) {
const MAX_COMMITS = 500; // Limit the number of commits to process
console.log('Filtering commits by team...');

var repository = '';
let repository = '';

switch (platform) {
case 'mobile':
Expand Down Expand Up @@ -163,7 +161,7 @@ function formatAsCSV(commitsByTeam) {
stripDelimiter(commit.author, ','),
commit.prLink,
stripDelimiter(team, ','),
,
'',
assignChangeType(commit.message),
];
csvContent.push(row.join(','));
Expand All @@ -177,35 +175,31 @@ function formatAsCSV(commitsByTeam) {
// Helper function to strip delimiter from CSV fields so they can be properly imported automatically later
function stripDelimiter(inputString, delimiter) {
// Create a regex dynamically based on the provided delimiter
const regex = new RegExp(delimiter, 'g');
const regex = new RegExp(delimiter, 'gu');
return inputString.replace(regex, '');
}

// Helper function to escape CSV fields
function escapeCSV(field) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this unused?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes unused

if (field.includes(',') || field.includes('"') || field.includes('\n')) {
return `"${field.replace(/"/g, '""')}"`; // Encapsulate in double quotes and escape existing quotes
}
return field;
}
// Helper function to create change type
function assignChangeType(field) {
if (field.includes('feat')) return 'Added';
else if (
if (field.includes('feat')) {
return 'Added';
} else if (
field.includes('cherry') ||
field.includes('bump') ||
field.includes('release')
)
) {
return 'Ops';
else if (
} else if (
field.includes('chore') ||
field.includes('test') ||
field.includes('ci') ||
field.includes('docs') ||
field.includes('refactor')
)
) {
return 'Changed';
else if (field.includes('fix')) return 'Fixed';
} else if (field.includes('fix')) {
return 'Fixed';
}

return 'Unknown';
}
Expand Down
6 changes: 3 additions & 3 deletions .github/scripts/post-relay-subsidy-balance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ const validateRelayResponseShape = (data) => {

const computeTotalUsd = (balances) =>
balances
.map((b) => parseAmountUsd(b?.amountUsd))
.filter((v) => Number.isFinite(v))
.reduce((sum, v) => sum + v, 0);
.map((balance) => parseAmountUsd(balance?.amountUsd))
.filter((value) => Number.isFinite(value))
.reduce((sum, value) => sum + value, 0);

const formatAsOfDate = (date) =>
new Intl.DateTimeFormat('en-US', {
Expand Down
Loading
Loading