Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import type { ServerConfigStreamEvent } from "@akeru/contracts";
import { describe, expect, it } from "vite-plus/test";
import {
createKeybindingsUpdateToastController,
KEYBINDINGS_SUCCESS_TOAST_COOLDOWN_MS,
} from "./KeybindingsUpdateToast.logic";
function keybindingsEvent(
overrides: Partial<Extract<ServerConfigStreamEvent, { type: "keybindingsUpdated" }>> = {},
): Extract<ServerConfigStreamEvent, { type: "keybindingsUpdated" }> {
return {
version: 1,
type: "keybindingsUpdated",
payload: {
keybindings: [],
issues: [],
},
...overrides,
};
}
describe("keybindings update toast policy", () => {
it("coalesces repeated successful reload notifications during the cooldown", () => {
let now = 1_000;
const controller = createKeybindingsUpdateToastController({
now: () => now,
});
expect(controller.handle(keybindingsEvent())).toEqual({ _tag: "Success" });
now += KEYBINDINGS_SUCCESS_TOAST_COOLDOWN_MS - 1;
expect(controller.handle(keybindingsEvent())).toBeNull();
now += 1;
expect(controller.handle(keybindingsEvent())).toEqual({ _tag: "Success" });
});
it("surfaces keybinding configuration issues", () => {
const controller = createKeybindingsUpdateToastController({});
expect(
controller.handle(
keybindingsEvent({
payload: {
keybindings: [],
issues: [
{
kind: "keybindings.malformed-config",
message: "Expected JSON array",
},
],
},
}),
),
).toEqual({
_tag: "InvalidConfiguration",
message: "Expected JSON array",
});
});
it("ignores unrelated server config notifications", () => {
const controller = createKeybindingsUpdateToastController({});
expect(
controller.handle({
version: 1,
type: "settingsUpdated",
payload: { settings: {} as never },
}),
).toBeNull();
});
});