mirror of
https://github.com/hanzoai/bot.git
synced 2026-11-01 07:38:30 +00:00
The automated rebrand sed script replaced "OpenClaw" with "Hanzo Bot" (with space) instead of "HanzoBot" in 8,315 TypeScript identifier occurrences across 1,632 files. This fixes all broken class names, type names, function names, and variable names. Co-authored-by: Hanzo Dev <[email protected]>
104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { createTestPluginApi } from "../../test/helpers/extensions/plugin-api.js";
|
|
import registerPhoneControl from "./index.js";
|
|
import type {
|
|
HanzoBotPluginApi,
|
|
HanzoBotPluginCommandDefinition,
|
|
PluginCommandContext,
|
|
} from "./runtime-api.js";
|
|
|
|
function createApi(params: {
|
|
stateDir: string;
|
|
getConfig: () => Record<string, unknown>;
|
|
writeConfig: (next: Record<string, unknown>) => Promise<void>;
|
|
registerCommand: (command: HanzoBotPluginCommandDefinition) => void;
|
|
}): HanzoBotPluginApi {
|
|
return createTestPluginApi({
|
|
id: "phone-control",
|
|
name: "phone-control",
|
|
source: "test",
|
|
config: {},
|
|
pluginConfig: {},
|
|
runtime: {
|
|
state: {
|
|
resolveStateDir: () => params.stateDir,
|
|
},
|
|
config: {
|
|
loadConfig: () => params.getConfig(),
|
|
writeConfigFile: (next: Record<string, unknown>) => params.writeConfig(next),
|
|
},
|
|
} as HanzoBotPluginApi["runtime"],
|
|
registerCommand: params.registerCommand,
|
|
}) as HanzoBotPluginApi;
|
|
}
|
|
|
|
function createCommandContext(args: string): PluginCommandContext {
|
|
return {
|
|
channel: "test",
|
|
isAuthorizedSender: true,
|
|
commandBody: `/phone ${args}`,
|
|
args,
|
|
config: {},
|
|
requestConversationBinding: async () => ({
|
|
status: "error",
|
|
message: "unsupported",
|
|
}),
|
|
detachConversationBinding: async () => ({ removed: false }),
|
|
getCurrentConversationBinding: async () => null,
|
|
};
|
|
}
|
|
|
|
describe("phone-control plugin", () => {
|
|
it("arms sms.send as part of the writes group", async () => {
|
|
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-phone-control-test-"));
|
|
try {
|
|
let config: Record<string, unknown> = {
|
|
gateway: {
|
|
nodes: {
|
|
allowCommands: [],
|
|
denyCommands: ["calendar.add", "contacts.add", "reminders.add", "sms.send"],
|
|
},
|
|
},
|
|
};
|
|
const writeConfigFile = vi.fn(async (next: Record<string, unknown>) => {
|
|
config = next;
|
|
});
|
|
|
|
let command: HanzoBotPluginCommandDefinition | undefined;
|
|
registerPhoneControl.register(
|
|
createApi({
|
|
stateDir,
|
|
getConfig: () => config,
|
|
writeConfig: writeConfigFile,
|
|
registerCommand: (nextCommand) => {
|
|
command = nextCommand;
|
|
},
|
|
}),
|
|
);
|
|
|
|
expect(command?.name).toBe("phone");
|
|
|
|
const res = await command?.handler(createCommandContext("arm writes 30s"));
|
|
const text = String(res?.text ?? "");
|
|
const nodes = (
|
|
config.gateway as { nodes?: { allowCommands?: string[]; denyCommands?: string[] } }
|
|
).nodes;
|
|
|
|
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
|
expect(nodes?.allowCommands).toEqual([
|
|
"calendar.add",
|
|
"contacts.add",
|
|
"reminders.add",
|
|
"sms.send",
|
|
]);
|
|
expect(nodes?.denyCommands).toEqual([]);
|
|
expect(text).toContain("sms.send");
|
|
} finally {
|
|
await fs.rm(stateDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|