Add restart command to safe mode.

Currently integration tests will be broken because we took control
over "who starts Draupnir?" away and gave it to the `SafeModeToggle`.

So we need to fix that.
This commit is contained in:
gnuxie
2024-09-18 15:28:05 +01:00
parent 4f1b789501
commit de6e4d7416
8 changed files with 35 additions and 15 deletions
+4 -1
View File
@@ -14,6 +14,7 @@ import {
setGlobalLoggerProvider,
RoomStateBackingStore,
ClientsInRoomMap,
Task,
} from "matrix-protection-suite";
import {
BotSDKLogServiceLogger,
@@ -158,6 +159,7 @@ export class DraupnirBotModeToggle implements SafeModeToggle {
this.safeModeDraupnir?.stop();
this.safeModeDraupnir = null;
this.draupnir = draupnirResult.ok;
void Task(this.draupnir.start());
return draupnirResult;
}
public async switchToSafeMode(
@@ -172,7 +174,8 @@ export class DraupnirBotModeToggle implements SafeModeToggle {
this.clientUserID,
this.managementRoom,
this.config,
cause
cause,
this
);
if (isError(safeModeResult)) {
return safeModeResult;
+3 -1
View File
@@ -95,7 +95,8 @@ export class DraupnirFactory {
clientUserID: StringUserID,
managementRoom: MatrixRoomID,
config: IConfig,
cause: SafeModeCause
cause: SafeModeCause,
toggle: SafeModeToggle
): Promise<ActionResult<SafeModeDraupnir>> {
const client = await this.clientProvider(clientUserID);
const clientRooms = await this.clientsInRoomMap.makeClientRooms(
@@ -117,6 +118,7 @@ export class DraupnirFactory {
clientPlatform,
managementRoom,
clientRooms.ok,
toggle,
config
)
);
+3 -10
View File
@@ -8,12 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
ActionError,
ActionResult,
Task,
isError,
} from "matrix-protection-suite";
import { ActionError, ActionResult, isError } from "matrix-protection-suite";
import { IConfig } from "../config";
import { DraupnirFactory } from "./DraupnirFactory";
import { Draupnir } from "../Draupnir";
@@ -86,9 +81,6 @@ export class StandardDraupnirManager {
);
return draupnir;
}
// FIXME: This is a little more than suspect that there are no handlers if starting fails?
// unclear to me what can fail though.
void Task(draupnir.ok.start());
this.draupnir.set(clientUserID, draupnir.ok);
this.failedDraupnir.delete(clientUserID);
return draupnir;
@@ -109,7 +101,8 @@ export class StandardDraupnirManager {
clientUserID,
managementRoom,
config,
cause
cause,
this.makeSafeModeToggle(clientUserID, managementRoom, config)
);
if (isError(safeModeDraupnir)) {
this.reportUnstartedDraupnir(
-1
View File
@@ -119,7 +119,6 @@ void (async function () {
throw err;
}
try {
await bot.start();
await config.RUNTIME.client.start();
void Task(bot.startupComplete());
await apis.start();
+2
View File
@@ -26,6 +26,7 @@ import {
makeListenerForPromptDefault,
} from "../commands/interface-manager/MatrixPromptForAccept";
import { makeCommandDispatcherTimelineListener } from "./ManagementRoom";
import { SafeModeToggle } from "./SafeModeToggle";
export class SafeModeDraupnir implements MatrixAdaptorContext {
public reactionHandler: MatrixReactionHandler;
@@ -44,6 +45,7 @@ export class SafeModeDraupnir implements MatrixAdaptorContext {
public readonly clientPlatform: ClientPlatform,
public readonly managementRoom: MatrixRoomID,
private readonly clientRooms: ClientRooms,
public readonly safeModeToggle: SafeModeToggle,
public readonly config: IConfig
//private readonly roomStateManager: RoomStateManager,
//private readonly policyRoomManager: PolicyRoomManager,
@@ -1,3 +1,23 @@
// SPDX-FileCopyrightText: 2024 Gnuxie <Gnuxie@protonmail.com>
//
// SPDX-License-Identifier: AFL-3.0
import { describeCommand } from "@the-draupnir-project/interface-manager";
import { Draupnir } from "../../Draupnir";
import { SafeModeDraupnir } from "../DraupnirSafeMode";
import { Result } from "@gnuxie/typescript-result";
import { SafeModeInterfaceAdaptor } from "./SafeModeAdaptor";
export const SafeModeRestartCommand = describeCommand({
summary: "Restart Draupnir, quitting safe mode.",
parameters: [],
async executor({
safeModeToggle,
}: SafeModeDraupnir): Promise<Result<Draupnir>> {
return safeModeToggle.switchToDraupnir();
},
});
SafeModeInterfaceAdaptor.describeRenderer(SafeModeRestartCommand, {
isAlwaysSupposedToUseDefaultRenderer: true,
});
+3 -1
View File
@@ -5,7 +5,9 @@
import { StandardCommandTable } from "@the-draupnir-project/interface-manager";
import { SafeModeHelpCommand } from "./HelpCommand";
import { SafeModeStatusCommand } from "./StatusCommand";
import { SafeModeRestartCommand } from "./RestartDraupnirCommand";
export const SafeModeCommands = new StandardCommandTable("safe mode")
.internCommand(SafeModeHelpCommand, ["draupnir", "help"])
.internCommand(SafeModeStatusCommand, ["draupnir", "status"]);
.internCommand(SafeModeStatusCommand, ["draupnir", "status"])
.internCommand(SafeModeRestartCommand, ["draupnir", "restart"]);
-1
View File
@@ -29,7 +29,6 @@ void (async () => {
)
);
console.info(`management room ${mjolnir.managementRoom.toPermalink()}`);
await mjolnir.start();
const apis = constructWebAPIs(mjolnir);
await draupnirClient()?.start();
await apis.start();