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
169 changes: 167 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/lib/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import type { BotloftApi } from "./api";
import { FakeAllow } from "./fakeAllow";
import { backupHandlers } from "./fakeBackup";
import { botHandlers } from "./fakeBots";
import { FakeBrowser } from "./fakeBrowser";
import { FakeChat } from "./fakeChat";
Expand Down Expand Up @@ -282,6 +283,7 @@ export class FakeBotloft implements BotloftApi {
...this.reactions.handlers(),
...this.lesson.handlers(),
...usageHandlers(this),
...backupHandlers(this),
...searchHandlers(this),
};
}
54 changes: 54 additions & 0 deletions app/src/lib/fakeBackup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// The fake daemon's backups (spec 14.2): what an export would hold, from
// the fake crews, at a made-up path, and a backup that opens only with
// `FAKE_PASSPHRASE`. Nothing is sealed, written or restored.

import type { FakeBotloft, Handlers } from "./fake";
import { type BackupManifest, RpcErrorCode } from "./protocol.gen";
import { RpcError } from "./rpc";

type BackupMethods = Extract<keyof Handlers, `backup.${string}`>;

/** The passphrase the fake's backups open with. */
export const FAKE_PASSPHRASE = "correct horse";

function refused(reason: string, message: string): RpcError {
return new RpcError(RpcErrorCode.validation, message, reason);
}

function manifestOf(fake: FakeBotloft): BackupManifest {
return {
format: 1,
createdAt: fake.now,
version: "0.10.0",
crews: [...fake.crews.values()].map((crew) => ({
name: crew.name,
bots: [...fake.bots.values()]
.filter((bot) => bot.crewId === crew.id && bot.archivedAt === null)
.map((bot) => bot.name),
workFolder: crew.workFolderChosen ? crew.workFolder : null,
})),
};
}

export function backupHandlers(fake: FakeBotloft): Pick<Handlers, BackupMethods> {
return {
"backup.export": ({ passphrase }) => {
if ([...passphrase].length < 8) {
throw refused("short_passphrase", "the passphrase must have at least 8 characters");
}
return {
path: "C:\\Users\\owner\\AppData\\Local\\Botloft\\exports\\botloft-2026-10-05-1430.botloft",
size: 1_234_567,
manifest: manifestOf(fake),
};
},
"backup.stage": ({ passphrase }) => {
if (passphrase !== FAKE_PASSPHRASE) {
throw refused("wrong_passphrase", "the passphrase is wrong, or the file is damaged");
}
return manifestOf(fake);
},
"backup.confirm": () => null,
"backup.cancel": () => null,
};
}
Loading
Loading