From bb8baaa47325380ef0bc0807e8cc077d4b4c36fd Mon Sep 17 00:00:00 2001 From: gnuxie Date: Tue, 17 Jun 2025 12:25:38 +0100 Subject: [PATCH] Rigidity wrt disposing stores and protections. --- package.json | 2 +- src/appservice/AppService.ts | 7 ++++++- src/backingstore/DraupnirStores.ts | 7 +++++++ test/integration/fixtures.ts | 10 ++-------- test/integration/mjolnirSetupUtils.ts | 2 +- yarn.lock | 8 ++++---- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 35d0e61..173bb65 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "jsdom": "^24.0.0", "matrix-appservice-bridge": "^10.3.1", "matrix-bot-sdk": "npm:@vector-im/matrix-bot-sdk@^0.7.1-element.6", - "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@3.6.0", + "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@3.6.1", "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@3.6.0", "pg": "^8.8.0", "yaml": "^2.3.2" diff --git a/src/appservice/AppService.ts b/src/appservice/AppService.ts index daeaa48..8c74148 100644 --- a/src/appservice/AppService.ts +++ b/src/appservice/AppService.ts @@ -241,7 +241,12 @@ export class MjolnirAppService { dataStore, DefaultEventDecoder, registrationFilePath, - { roomStateBackingStore: backingStore } // we don't support any stores in appservice atm except backing store. + { + roomStateBackingStore: backingStore, + dispose() { + backingStore?.destroy(); + }, + } // we don't support any stores in appservice atm except backing store. ); // The call to `start` MUST happen last. As it needs the datastore, and the mjolnir manager to be initialized before it can process events from the homeserver. await service.start(port); diff --git a/src/backingstore/DraupnirStores.ts b/src/backingstore/DraupnirStores.ts index 41ecbd7..48be0ef 100644 --- a/src/backingstore/DraupnirStores.ts +++ b/src/backingstore/DraupnirStores.ts @@ -15,6 +15,7 @@ export type TopLevelStores = { roomAuditLog?: RoomAuditLog | undefined; roomStateBackingStore?: SqliteRoomStateBackingStore | undefined; userRestrictionAuditLog?: UserRestrictionAuditLog | undefined; + dispose(): void; }; /** @@ -64,5 +65,11 @@ export function makeTopLevelStores( roomAuditLog: SqliteRoomAuditLog.createToplevel(storagePath), userRestrictionAuditLog: SqliteUserRestrictionAuditLog.createToplevel(storagePath), + dispose() { + this.roomStateBackingStore?.destroy(); + this.hashStore?.destroy(); + this.roomAuditLog?.destroy(); + this.userRestrictionAuditLog?.destroy(); + }, } satisfies TopLevelStores); } diff --git a/test/integration/fixtures.ts b/test/integration/fixtures.ts index 68ebda3..a055006 100644 --- a/test/integration/fixtures.ts +++ b/test/integration/fixtures.ts @@ -105,14 +105,7 @@ export const mochaHooks = { this.timeout(10000); await this.toggle?.stopEverything(); draupnirClient()?.stop(); - this.stores?.roomStateBackingStore?.destroy(); - this.stores?.roomAuditLog?.destroy(); - // We forgot to add a destroy method in the interface in MPS - // and we'll probably need to wait until the next release to remove this. - if (this.stores?.hashStore instanceof SqliteHashReversalStore) { - this.stores.hashStore.destroy(); - } - // remove alias from management room and leave it. + this.stores?.dispose(); if (this.draupnir !== undefined) { await Promise.all([ this.draupnir.client.setAccountData( @@ -125,6 +118,7 @@ export const mochaHooks = { ), ]); const client = draupnirClient(); + // remove alias from management room and leave it. if (client !== null && this.managementRoomAlias !== undefined) { await teardownManagementRoom( client, diff --git a/test/integration/mjolnirSetupUtils.ts b/test/integration/mjolnirSetupUtils.ts index c6a70aa..4c1da02 100644 --- a/test/integration/mjolnirSetupUtils.ts +++ b/test/integration/mjolnirSetupUtils.ts @@ -135,7 +135,7 @@ export async function makeBotModeToggle( stores: TopLevelStores; eraseAccountData?: boolean; allowSafeMode?: boolean; - } = { stores: {} } + } = { stores: { dispose() {} } } ): Promise { await configureMjolnir(config); LogService.setLevel(LogLevel.fromString(config.logLevel, LogLevel.DEBUG)); diff --git a/yarn.lock b/yarn.lock index b6c38ee..36b0fd9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2606,10 +2606,10 @@ matrix-appservice@^2.0.0: "@gnuxie/typescript-result" "^1.0.0" await-lock "^2.2.2" -"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@3.6.0": - version "3.6.0" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-3.6.0.tgz#efdac7bd00e8ea7c2a273c290d0533536d6d84c7" - integrity sha512-9Ner82BaWpwguBDZo4roL05k7SkIOzIde56wVKSjLdP+llyNWCer5K3QhslqnLXXCa7jtRyHpnB44xmmRpUjdg== +"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@3.6.1": + version "3.6.1" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-3.6.1.tgz#39739bf127e80fc6b988d8ded34a994727fa12f2" + integrity sha512-jDTS4c3E3k0Hkr8Hy39MV1NRTDw3wO7Xik5LW9ilMoj9fBjZ8FTWGrVWQa72SNH8YMIbXh6LLZ6FZJzA8YPfew== dependencies: "@gnuxie/typescript-result" "^1.0.0" await-lock "^2.2.2"