Skip to content

Commit 7e20dd5

Browse files
authored
Merge branch 'main' into feat/add-unichain-logo
2 parents c296da8 + cafa47a commit 7e20dd5

15 files changed

+94
-35
lines changed

.circleci/scripts/git-diff-default-branch.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ async function gitDiff(): Promise<string> {
105105
return diffResult;
106106
}
107107

108-
function writePrBodyToFile(prBody: string) {
108+
function writePrBodyAndInfoToFile(prInfo: PRInfo) {
109109
const prBodyPath = path.resolve(CHANGED_FILES_DIR, 'pr-body.txt');
110-
fs.writeFileSync(prBodyPath, prBody.trim());
111-
console.log(`PR body saved to ${prBodyPath}`);
110+
const labels = prInfo.labels.map(label => label.name).join(', ');
111+
const updatedPrBody = `PR labels: {${labels}}\nPR base: {${prInfo.base.ref}}\n${prInfo.body.trim()}`;
112+
fs.writeFileSync(prBodyPath, updatedPrBody);
113+
console.log(`PR body and info saved to ${prBodyPath}`);
112114
}
113115

114116
/**
@@ -135,17 +137,9 @@ async function storeGitDiffOutputAndPrBody() {
135137
if (!baseRef) {
136138
console.log('Not a PR, skipping git diff');
137139
return;
138-
} else if (baseRef !== GITHUB_DEFAULT_BRANCH) {
139-
console.log(`This is for a PR targeting '${baseRef}', skipping git diff`);
140-
writePrBodyToFile(prInfo.body);
141-
return;
142-
} else if (
143-
prInfo.labels.some((label) => label.name === 'skip-e2e-quality-gate')
144-
) {
145-
console.log('PR has the skip-e2e-quality-gate label, skipping git diff');
146-
return;
147140
}
148-
141+
// We perform git diff even if the PR base is not main or skip-e2e-quality-gate label is applied
142+
// because we rely on the git diff results for other jobs
149143
console.log('Attempting to get git diff...');
150144
const diffOutput = await gitDiff();
151145
console.log(diffOutput);
@@ -155,7 +149,7 @@ async function storeGitDiffOutputAndPrBody() {
155149
fs.writeFileSync(outputPath, diffOutput.trim());
156150
console.log(`Git diff results saved to ${outputPath}`);
157151

158-
writePrBodyToFile(prInfo.body);
152+
writePrBodyAndInfoToFile(prInfo);
159153

160154
process.exit(0);
161155
} catch (error: any) {

.github/workflows/validate-page-object-usage.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Validate E2E Page Object usage on modified files
22

33
on:
44
pull_request:
5+
branches:
6+
- main
57
types:
68
- opened
79
- reopened

app/scripts/controller-init/messengers/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { noop } from 'lodash';
12
import {
23
getPPOMControllerMessenger,
34
getPPOMControllerInitMessenger,
@@ -26,35 +27,43 @@ import {
2627
export const CONTROLLER_MESSENGERS = {
2728
CronjobController: {
2829
getMessenger: getCronjobControllerMessenger,
30+
getInitMessenger: noop,
2931
},
3032
ExecutionService: {
3133
getMessenger: getExecutionServiceMessenger,
34+
getInitMessenger: noop,
3235
},
3336
MultichainAssetsController: {
3437
getMessenger: getMultichainAssetsControllerMessenger,
38+
getInitMessenger: noop,
3539
},
3640
MultichainBalancesController: {
3741
getMessenger: getMultichainBalancesControllerMessenger,
42+
getInitMessenger: noop,
3843
},
3944
MultichainTransactionsController: {
4045
getMessenger: getMultichainTransactionsControllerMessenger,
46+
getInitMessenger: noop,
4147
},
4248
RateLimitController: {
4349
getMessenger: getRateLimitControllerMessenger,
4450
getInitMessenger: getRateLimitControllerInitMessenger,
4551
},
4652
SnapsRegistry: {
4753
getMessenger: getSnapsRegistryMessenger,
54+
getInitMessenger: noop,
4855
},
4956
SnapController: {
5057
getMessenger: getSnapControllerMessenger,
5158
getInitMessenger: getSnapControllerInitMessenger,
5259
},
5360
SnapInsightsController: {
5461
getMessenger: getSnapInsightsControllerMessenger,
62+
getInitMessenger: noop,
5563
},
5664
SnapInterfaceController: {
5765
getMessenger: getSnapInterfaceControllerMessenger,
66+
getInitMessenger: noop,
5867
},
5968
PPOMController: {
6069
getMessenger: getPPOMControllerMessenger,

app/scripts/controller-init/multichain/multichain-assets-controller-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function buildInitRequestMock(): jest.Mocked<
2020
controllerMessenger: getMultichainAssetsControllerMessenger(
2121
baseControllerMessenger,
2222
),
23+
initMessenger: undefined,
2324
};
2425
}
2526

app/scripts/controller-init/multichain/multichain-balances-controller-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function buildInitRequestMock(): jest.Mocked<
2020
controllerMessenger: getMultichainBalancesControllerMessenger(
2121
baseControllerMessenger,
2222
),
23+
initMessenger: undefined,
2324
};
2425
}
2526

app/scripts/controller-init/multichain/multichain-transactions-controller-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function buildInitRequestMock(): jest.Mocked<
2020
controllerMessenger: getMultichainTransactionsControllerMessenger(
2121
baseControllerMessenger,
2222
),
23+
initMessenger: undefined,
2324
};
2425
}
2526

app/scripts/controller-init/snaps/cronjob-controller-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function getInitRequestMock(): jest.Mocked<
2121
const requestMock = {
2222
...buildControllerInitRequestMock(),
2323
controllerMessenger: getCronjobControllerMessenger(baseMessenger),
24+
initMessenger: undefined,
2425
};
2526

2627
return requestMock;

app/scripts/controller-init/snaps/execution-service-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function getInitRequestMock(): jest.Mocked<
2424
const requestMock = {
2525
...buildControllerInitRequestMock(),
2626
controllerMessenger: getExecutionServiceMessenger(baseMessenger),
27+
initMessenger: undefined,
2728
};
2829

2930
return requestMock;

app/scripts/controller-init/snaps/snap-insights-controller-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function getInitRequestMock(): jest.Mocked<
1818
const requestMock = {
1919
...buildControllerInitRequestMock(),
2020
controllerMessenger: getSnapInsightsControllerMessenger(baseMessenger),
21+
initMessenger: undefined,
2122
};
2223

2324
return requestMock;

app/scripts/controller-init/snaps/snap-interface-controller-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function getInitRequestMock(): jest.Mocked<
1818
const requestMock = {
1919
...buildControllerInitRequestMock(),
2020
controllerMessenger: getSnapInterfaceControllerMessenger(baseMessenger),
21+
initMessenger: undefined,
2122
};
2223

2324
return requestMock;

app/scripts/controller-init/snaps/snaps-registry-init.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function getInitRequestMock(): jest.Mocked<
1818
const requestMock = {
1919
...buildControllerInitRequestMock(),
2020
controllerMessenger: getSnapsRegistryMessenger(baseMessenger),
21+
initMessenger: undefined,
2122
};
2223

2324
return requestMock;

app/scripts/controller-init/types.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,13 @@ export type ControllerInitRequest<
161161
message: string,
162162
url?: string,
163163
) => Promise<void>;
164-
} & (InitMessengerType extends BaseRestrictedControllerMessenger
165-
? {
166-
/**
167-
* Required initialization messenger instance.
168-
* Generated using the callback specified in `getInitMessengerCallback`.
169-
*/
170-
initMessenger: InitMessengerType;
171-
}
172-
: unknown);
164+
165+
/**
166+
* Required initialization messenger instance.
167+
* Generated using the callback specified in `getInitMessengerCallback`.
168+
*/
169+
initMessenger: InitMessengerType;
170+
};
173171

174172
/**
175173
* A single background API method available to the UI.

app/scripts/controller-init/utils.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,26 @@ export type InitControllersResult = {
2929

3030
type BaseControllerInitRequest = ControllerInitRequest<
3131
BaseRestrictedControllerMessenger,
32-
BaseRestrictedControllerMessenger
32+
BaseRestrictedControllerMessenger | void
3333
>;
3434

3535
type ControllerMessengerCallback = (
3636
BaseControllerMessenger: BaseControllerMessenger,
3737
) => BaseRestrictedControllerMessenger;
3838

39-
type ControllersToInitialize = 'PPOMController' | 'TransactionController';
39+
export type ControllersToInitialize =
40+
| 'CronjobController'
41+
| 'ExecutionService'
42+
| 'MultichainAssetsController'
43+
| 'MultichainBalancesController'
44+
| 'MultichainTransactionsController'
45+
| 'RateLimitController'
46+
| 'SnapsRegistry'
47+
| 'SnapController'
48+
| 'SnapInsightsController'
49+
| 'SnapInterfaceController'
50+
| 'PPOMController'
51+
| 'TransactionController';
4052

4153
type InitFunction<Name extends ControllersToInitialize> =
4254
ControllerInitFunction<
@@ -101,7 +113,6 @@ export function initControllers({
101113
const messengerCallbacks = CONTROLLER_MESSENGERS[controllerName];
102114

103115
const controllerMessengerCallback =
104-
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
105116
messengerCallbacks?.getMessenger as ControllerMessengerCallback;
106117

107118
const initMessengerCallback =
@@ -120,11 +131,8 @@ export function initControllers({
120131
initMessenger,
121132
};
122133

123-
// TODO: Remove @ts-expect-error once base-controller version mismatch is resolved
124-
// Instead of suppressing all type errors, we'll be specific about the controllerMessenger mismatch
125134
const result = initFunction({
126135
...finalInitRequest,
127-
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
128136
controllerMessenger: finalInitRequest.controllerMessenger,
129137
});
130138

@@ -144,8 +152,8 @@ export function initControllers({
144152
const memStateKey =
145153
memStateKeyRaw === null ? undefined : memStateKeyRaw ?? controllerName;
146154

147-
partialControllersByName[controllerName] = controller as Controller &
148-
undefined;
155+
// @ts-expect-error: Union too complex.
156+
partialControllersByName[controllerName] = controller;
149157

150158
controllerApi = {
151159
...controllerApi,

test/e2e/changedFilesUtil.js

+40
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const CHANGED_FILES_PATH = path.join(
77
'changed-files',
88
'changed-files.txt',
99
);
10+
const PR_INFO_PATH = path.join(BASE_PATH, 'changed-files', 'pr-body.txt');
1011

1112
/**
1213
* Reads the list of changed files from the git diff file with status (A, M, D).
@@ -80,10 +81,49 @@ function getChangedAndNewFiles(changedFiles) {
8081
return changedFiles.map((file) => file.filePath);
8182
}
8283

84+
/**
85+
* Checks if the E2E quality gate should be skipped based on the PR info.
86+
*
87+
* @returns {boolean} True if the quality gate should be skipped, otherwise false.
88+
*/
89+
function shouldE2eQualityGateBeSkipped() {
90+
try {
91+
const data = fs.readFileSync(PR_INFO_PATH, 'utf8');
92+
const lines = data.split('\n');
93+
const labelsLine = lines.find((line) => line.startsWith('PR labels:'));
94+
const baseLine = lines.find((line) => line.startsWith('PR base:'));
95+
96+
const labels = labelsLine
97+
? labelsLine
98+
.replace(/PR labels: \{/gu, '')
99+
.replace(/\}/gu, '')
100+
.split(',')
101+
.map((label) => label.trim())
102+
: [];
103+
const base = baseLine
104+
? baseLine
105+
.replace(/PR base: \{/gu, '')
106+
.replace(/\}/gu, '')
107+
.trim()
108+
: '';
109+
console.log('PR labels', labels);
110+
console.log('PR base', base);
111+
112+
const skipGate =
113+
labels.includes('skip-e2e-quality-gate') || base !== 'main';
114+
console.log('Should we skip the e2e quality gate:', skipGate);
115+
return skipGate;
116+
} catch (error) {
117+
console.error('Error reading PR body file:', error);
118+
return false;
119+
}
120+
}
121+
83122
module.exports = {
84123
filterE2eChangedFiles,
85124
getChangedAndNewFiles,
86125
getChangedFilesOnly,
87126
getNewFilesOnly,
88127
readChangedAndNewFilesWithStatus,
128+
shouldE2eQualityGateBeSkipped,
89129
};

test/e2e/run-all.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
filterE2eChangedFiles,
1111
getChangedAndNewFiles,
1212
readChangedAndNewFilesWithStatus,
13+
shouldE2eQualityGateBeSkipped,
1314
} = require('./changedFilesUtil');
1415

1516
// These tests should only be run on Flask for now.
@@ -75,10 +76,9 @@ function runningOnCircleCI(testPaths) {
7576
const changedOrNewTests = filterE2eChangedFiles(changedandNewFilesPaths);
7677
console.log('Changed or new test list:', changedOrNewTests);
7778

78-
const fullTestList = applyQualityGate(
79-
testPaths.join('\n'),
80-
changedOrNewTests,
81-
);
79+
const fullTestList = shouldE2eQualityGateBeSkipped()
80+
? testPaths.join('\n')
81+
: applyQualityGate(testPaths.join('\n'), changedOrNewTests);
8282

8383
console.log('Full test list:', fullTestList);
8484
fs.writeFileSync('test/test-results/fullTestList.txt', fullTestList);

0 commit comments

Comments
 (0)