refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -22,6 +22,29 @@ vi.mock("../../telegram/send.js", () => ({
}));
describe("handleTelegramAction", () => {
const defaultReactionAction = {
action: "react",
chatId: "123",
messageId: "456",
emoji: "✅",
} as const;
function reactionConfig(reactionLevel: "minimal" | "extensive" | "off" | "ack"): OpenClawConfig {
return {
channels: { telegram: { botToken: "tok", reactionLevel } },
} as OpenClawConfig;
}
async function expectReactionAdded(reactionLevel: "minimal" | "extensive") {
await handleTelegramAction(defaultReactionAction, reactionConfig(reactionLevel));
expect(reactMessageTelegram).toHaveBeenCalledWith(
"123",
456,
"✅",
expect.objectContaining({ token: "tok", remove: false }),
);
}
beforeEach(() => {
reactMessageTelegram.mockClear();
sendMessageTelegram.mockClear();
@@ -39,24 +62,7 @@ describe("handleTelegramAction", () => {
});
it("adds reactions when reactionLevel is minimal", async () => {
const cfg = {
channels: { telegram: { botToken: "tok", reactionLevel: "minimal" } },
} as OpenClawConfig;
await handleTelegramAction(
{
action: "react",
chatId: "123",
messageId: "456",
emoji: "✅",
},
cfg,
);
expect(reactMessageTelegram).toHaveBeenCalledWith(
"123",
456,
"✅",
expect.objectContaining({ token: "tok", remove: false }),
);
await expectReactionAdded("minimal");
});
it("surfaces non-fatal reaction warnings", async () => {
@@ -64,18 +70,7 @@ describe("handleTelegramAction", () => {
ok: false,
warning: "Reaction unavailable: ✅",
});
const cfg = {
channels: { telegram: { botToken: "tok", reactionLevel: "minimal" } },
} as OpenClawConfig;
const result = await handleTelegramAction(
{
action: "react",
chatId: "123",
messageId: "456",
emoji: "✅",
},
cfg,
);
const result = await handleTelegramAction(defaultReactionAction, reactionConfig("minimal"));
const textPayload = result.content.find((item) => item.type === "text");
expect(textPayload?.type).toBe("text");
const parsed = JSON.parse((textPayload as { type: "text"; text: string }).text) as {
@@ -91,24 +86,7 @@ describe("handleTelegramAction", () => {
});
it("adds reactions when reactionLevel is extensive", async () => {
const cfg = {
channels: { telegram: { botToken: "tok", reactionLevel: "extensive" } },
} as OpenClawConfig;
await handleTelegramAction(
{
action: "react",
chatId: "123",
messageId: "456",
emoji: "✅",
},
cfg,
);
expect(reactMessageTelegram).toHaveBeenCalledWith(
"123",
456,
"✅",
expect.objectContaining({ token: "tok", remove: false }),
);
await expectReactionAdded("extensive");
});
it("removes reactions on empty emoji", async () => {
@@ -167,9 +145,7 @@ describe("handleTelegramAction", () => {
});
it("removes reactions when remove flag set", async () => {
const cfg = {
channels: { telegram: { botToken: "tok", reactionLevel: "extensive" } },
} as OpenClawConfig;
const cfg = reactionConfig("extensive");
await handleTelegramAction(
{
action: "react",
@@ -189,9 +165,7 @@ describe("handleTelegramAction", () => {
});
it("blocks reactions when reactionLevel is off", async () => {
const cfg = {
channels: { telegram: { botToken: "tok", reactionLevel: "off" } },
} as OpenClawConfig;
const cfg = reactionConfig("off");
await expect(
handleTelegramAction(
{
@@ -206,9 +180,7 @@ describe("handleTelegramAction", () => {
});
it("blocks reactions when reactionLevel is ack", async () => {
const cfg = {
channels: { telegram: { botToken: "tok", reactionLevel: "ack" } },
} as OpenClawConfig;
const cfg = reactionConfig("ack");
await expect(
handleTelegramAction(
{