Skip to content

Commit 0afb064

Browse files
authored
Add a test to ensure that the irc client state doesn't bloat on VERSION (#1753)
* Add a test to ensure that the irc client state doesn't bloat on VERSION * Sensible linting * Update matrix-org-irc
1 parent 5fa23ed commit 0afb064

File tree

9 files changed

+113
-14
lines changed

9 files changed

+113
-14
lines changed

.eslintrc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
},
1111
"env": {
1212
"node": true,
13-
"es6": true,
14-
"jasmine": true
13+
"es6": true
1514
},
1615
"extends": [
1716
"eslint:recommended",
@@ -102,6 +101,11 @@
102101
"files": [
103102
"spec/**/*.js"
104103
],
104+
"env": {
105+
"node": true,
106+
"es6": true,
107+
"jasmine": true
108+
},
105109
"rules": {
106110
"@typescript-eslint/no-this-alias": "off", // I'm unsure if we should disallow this.
107111
"@typescript-eslint/no-empty-function": "off",
@@ -113,6 +117,15 @@
113117
"prefer-const": "off",
114118
"no-var": "off",
115119
}
120+
},
121+
{
122+
"extends": ["plugin:jest/recommended"],
123+
"files": [
124+
"spec/e2e/*.spec.ts"
125+
],
126+
"rules": {
127+
"jest/expect-expect": "off" // E2E tests don't always assert
128+
}
116129
}
117130
],
118131
"ignorePatterns": ["widget/**/*"]

changelog.d/1753.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure we don't bloat irc supported state.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dev:widget": "vite dev --config widget/vite.config.ts",
1818
"test": "ts-node --project spec/tsconfig.json node_modules/jasmine/bin/jasmine --stop-on-failure=true",
1919
"test:e2e": "jest --config spec/e2e/jest.config.js --forceExit",
20-
"lint": "eslint -c .eslintrc --max-warnings 0 'spec/**/*.js' 'src/**/*.ts' && eslint -c ./widget/.eslintrc.js 'widget/src/**/*.{ts,tsx}'",
20+
"lint": "eslint -c .eslintrc --max-warnings 0 'spec/**/*.js' 'spec/**/*.ts' 'src/**/*.ts' && eslint -c ./widget/.eslintrc.js 'widget/src/**/*.{ts,tsx}'",
2121
"check": "yarn test && yarn lint",
2222
"ci-test": "nyc --report text jasmine",
2323
"ci": "yarn lint && yarn ci-test"
@@ -45,7 +45,7 @@
4545
"logform": "^2.4.2",
4646
"matrix-appservice-bridge": "^9.0.0",
4747
"matrix-bot-sdk": "npm:@vector-im/matrix-bot-sdk@^0.6.6-element.1",
48-
"matrix-org-irc": "^2.0.1",
48+
"matrix-org-irc": "^2.1.0",
4949
"matrix-widget-api": "^1.4.0",
5050
"nopt": "^6.0.0",
5151
"p-queue": "^6.6.2",
@@ -54,8 +54,8 @@
5454
"react": "^18.2.0",
5555
"react-dom": "^18.2.0",
5656
"sanitize-html": "^2.7.2",
57-
"typescript": "^5.0.4",
5857
"typed-emitter": "^2.1.0",
58+
"typescript": "^5.0.4",
5959
"url-join": "^5.0.0",
6060
"winston": "^3.8.2",
6161
"winston-daily-rotate-file": "^4.7.1"
@@ -82,6 +82,7 @@
8282
"@vitejs/plugin-react": "^3.0.1",
8383
"autoprefixer": "^10.4.13",
8484
"eslint": "^8.24.0",
85+
"eslint-plugin-jest": "^27.2.3",
8586
"eslint-plugin-react": "^7.32.2",
8687
"eslint-plugin-react-hooks": "^4.6.0",
8788
"homerunner-client": "^0.0.6",

spec/e2e/pooling.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,31 @@ describeif('Connection pooling', () => {
7272
bob.say(channel, "Hi alice!");
7373
await bobMsg;
7474
});
75+
76+
it('should store the IRC client state once', async () => {
77+
const channel = `#${TestIrcServer.generateUniqueNick("test")}`;
78+
const { homeserver, ircBridge } = testEnv;
79+
const { client, userId } = homeserver.users[0];
80+
const adminRoomId = await testEnv.createAdminRoomHelper(client);
81+
82+
// Ensure we join IRC.
83+
const cRoomId = await testEnv.joinChannelHelper(client, adminRoomId, channel);
84+
await client.sendText(cRoomId, "Hello bob!");
85+
86+
87+
const bridgedClient = await ircBridge.getBridgedClient(ircBridge.getServers()[0], userId);
88+
await bridgedClient.waitForConnected();
89+
const ircClient = await bridgedClient.assertConnected();
90+
91+
// This is the original state of supported. We clone the object to be safe.
92+
const expectedState = JSON.parse(JSON.stringify(ircClient.supported));
93+
94+
// Request VERSION to re-request state.
95+
await bridgedClient.sendCommands('VERSION');
96+
await new Promise<void>(resolve => setTimeout(resolve, 2000));
97+
const newState = { ...ircClient.supported };
98+
99+
expect(expectedState).toEqual(newState);
100+
});
101+
75102
});

spec/e2e/powerlevels.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ describe('Ensure powerlevels are appropriately applied', () => {
4646

4747
await charlieJoinPromise;
4848
await bob.send('MODE', channel, '+o', charlie.nick);
49-
await plEvent;
49+
expect(await plEvent).toBeDefined();
5050
});
5151
});

spec/integ/provisioning.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { ErrCode } from "matrix-appservice-bridge";
23

34
import { defer } from "../../src/promiseutil";
@@ -137,7 +138,7 @@ describe("Provisioning API", function() {
137138
let sentReply = false;
138139
if (shouldOpRespond) {
139140
// Listen for message from bot
140-
env.ircMock._whenClient(config._server, config._botnick, "say", (self: any, message: any) => {
141+
env.ircMock._whenClient(config._server, config._botnick, "say", (self: any) => {
141142
// Say yes back to the bot
142143
if (sentReply) {
143144
return;
@@ -537,7 +538,7 @@ describe("Provisioning API", function() {
537538
linkBody.remote_room_server,
538539
nickForDisplayName,
539540
"say",
540-
(client, channel, text) => {
541+
(client, channel) => {
541542
expect(client.nick).toEqual(nickForDisplayName);
542543
expect(client.addr).toEqual(linkBody.remote_room_server);
543544
expect(channel).toEqual(linkBody.remote_room_channel);
@@ -583,7 +584,7 @@ describe("Provisioning API", function() {
583584
linkBody.remote_room_server,
584585
nickForDisplayName,
585586
"say",
586-
(client, channel, text) => {
587+
(client, channel) => {
587588
expect(client.nick).toEqual(nickForDisplayName);
588589
expect(client.addr).toEqual(linkBody.remote_room_server);
589590
expect(channel).toEqual(linkBody.remote_room_channel);

spec/unit/pool-service/IrcClientRedisState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IrcClientRedisState, IrcClientStateDehydrated } from "../../../src/pool
33

44
const userId = "@foo:bar";
55

6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
67
function fakeRedis(existingData: string|null = null): any {
78
return {
89
async hget(key, clientId) {

src/irc/BridgedClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ export class BridgedClient extends EventEmitter {
11691169
return this.connectDefer.promise;
11701170
}
11711171

1172-
private assertConnected(): Client {
1172+
public assertConnected(): Client {
11731173
if (this.state.status !== BridgedClientStatus.CONNECTED) {
11741174
throw Error('Client is not connected');
11751175
}

yarn.lock

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,14 @@
12021202
"@typescript-eslint/types" "5.59.1"
12031203
"@typescript-eslint/visitor-keys" "5.59.1"
12041204

1205+
"@typescript-eslint/scope-manager@5.62.0":
1206+
version "5.62.0"
1207+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c"
1208+
integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==
1209+
dependencies:
1210+
"@typescript-eslint/types" "5.62.0"
1211+
"@typescript-eslint/visitor-keys" "5.62.0"
1212+
12051213
"@typescript-eslint/type-utils@5.59.1":
12061214
version "5.59.1"
12071215
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.59.1.tgz#63981d61684fd24eda2f9f08c0a47ecb000a2111"
@@ -1217,6 +1225,11 @@
12171225
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.59.1.tgz#03f3fedd1c044cb336ebc34cc7855f121991f41d"
12181226
integrity sha512-dg0ICB+RZwHlysIy/Dh1SP+gnXNzwd/KS0JprD3Lmgmdq+dJAJnUPe1gNG34p0U19HvRlGX733d/KqscrGC1Pg==
12191227

1228+
"@typescript-eslint/types@5.62.0":
1229+
version "5.62.0"
1230+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f"
1231+
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==
1232+
12201233
"@typescript-eslint/typescript-estree@5.59.1":
12211234
version "5.59.1"
12221235
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.1.tgz#4aa546d27fd0d477c618f0ca00b483f0ec84c43c"
@@ -1230,6 +1243,19 @@
12301243
semver "^7.3.7"
12311244
tsutils "^3.21.0"
12321245

1246+
"@typescript-eslint/typescript-estree@5.62.0":
1247+
version "5.62.0"
1248+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b"
1249+
integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==
1250+
dependencies:
1251+
"@typescript-eslint/types" "5.62.0"
1252+
"@typescript-eslint/visitor-keys" "5.62.0"
1253+
debug "^4.3.4"
1254+
globby "^11.1.0"
1255+
is-glob "^4.0.3"
1256+
semver "^7.3.7"
1257+
tsutils "^3.21.0"
1258+
12331259
"@typescript-eslint/utils@5.59.1":
12341260
version "5.59.1"
12351261
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.59.1.tgz#d89fc758ad23d2157cfae53f0b429bdf15db9473"
@@ -1244,6 +1270,20 @@
12441270
eslint-scope "^5.1.1"
12451271
semver "^7.3.7"
12461272

1273+
"@typescript-eslint/utils@^5.10.0":
1274+
version "5.62.0"
1275+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86"
1276+
integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==
1277+
dependencies:
1278+
"@eslint-community/eslint-utils" "^4.2.0"
1279+
"@types/json-schema" "^7.0.9"
1280+
"@types/semver" "^7.3.12"
1281+
"@typescript-eslint/scope-manager" "5.62.0"
1282+
"@typescript-eslint/types" "5.62.0"
1283+
"@typescript-eslint/typescript-estree" "5.62.0"
1284+
eslint-scope "^5.1.1"
1285+
semver "^7.3.7"
1286+
12471287
"@typescript-eslint/visitor-keys@5.59.1":
12481288
version "5.59.1"
12491289
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.1.tgz#0d96c36efb6560d7fb8eb85de10442c10d8f6058"
@@ -1252,6 +1292,14 @@
12521292
"@typescript-eslint/types" "5.59.1"
12531293
eslint-visitor-keys "^3.3.0"
12541294

1295+
"@typescript-eslint/visitor-keys@5.62.0":
1296+
version "5.62.0"
1297+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e"
1298+
integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==
1299+
dependencies:
1300+
"@typescript-eslint/types" "5.62.0"
1301+
eslint-visitor-keys "^3.3.0"
1302+
12551303
"@vitejs/plugin-react@^3.0.1":
12561304
version "3.1.0"
12571305
resolved "https://registry.yarnpkg.com/@vitejs/plugin-react/-/plugin-react-3.1.0.tgz#d1091f535eab8b83d6e74034d01e27d73c773240"
@@ -2378,6 +2426,13 @@ escape-string-regexp@^4.0.0:
23782426
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
23792427
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
23802428

2429+
eslint-plugin-jest@^27.2.3:
2430+
version "27.2.3"
2431+
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-27.2.3.tgz#6f8a4bb2ca82c0c5d481d1b3be256ab001f5a3ec"
2432+
integrity sha512-sRLlSCpICzWuje66Gl9zvdF6mwD5X86I4u55hJyFBsxYOsBCmT5+kSUjf+fkFWVMMgpzNEupjW8WzUqi83hJAQ==
2433+
dependencies:
2434+
"@typescript-eslint/utils" "^5.10.0"
2435+
23812436
eslint-plugin-react-hooks@^4.6.0:
23822437
version "4.6.0"
23832438
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"
@@ -4249,10 +4304,10 @@ matrix-appservice@^2.0.0:
42494304
request-promise "^4.2.6"
42504305
sanitize-html "^2.8.0"
42514306

4252-
matrix-org-irc@^2.0.1:
4253-
version "2.0.1"
4254-
resolved "https://registry.yarnpkg.com/matrix-org-irc/-/matrix-org-irc-2.0.1.tgz#80cc1ce3abb3e8f240bbc3b4acf1a0fe0f1057e7"
4255-
integrity sha512-Qnzx1r5QjTtm63oGUY/XyE3t+1xH43CaC8r3QifkKmBihrYyhHq4bpMsnxNYb558sc2j52pixJ5CUsQ8zMediQ==
4307+
matrix-org-irc@^2.1.0:
4308+
version "2.1.0"
4309+
resolved "https://registry.yarnpkg.com/matrix-org-irc/-/matrix-org-irc-2.1.0.tgz#513d284d081a01ef752a29cd410c11fce0c5d2c5"
4310+
integrity sha512-MV9Q8Mt8RTKf72U0D5zNbBL9P4JQJzU63HTeomguq6a+Zb5QZJvnBHfrdLJXtJyTsWGCtSbJ6rcSFJVrFmKUxA==
42564311
dependencies:
42574312
chardet "^1.5.1"
42584313
iconv-lite "^0.6.3"

0 commit comments

Comments
 (0)