Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openclaw/src/auto-reply/reply/   (Openclaw AI Version 22©)  Datei vom 26.3.2026 mit Größe 2 kB image not shown  

Quelle  commands-bash-alias.test.ts

  Sprache: JAVA
 

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { handleBashCommand } from "./commands-bash.js";
import type { HandleCommandsParams } from "./commands-types.js";

const resolveSessionAgentIdMock = vi.hoisted(() => vi.fn(() => "main"));
const handleBashChatCommandMock = vi.hoisted(() =>
  vi.fn(async () => ({ text: "No active bash job" })),
);

vi.mock("../../agents/agent-scope.js", () => ({
  resolveSessionAgentId: resolveSessionAgentIdMock,
}));

vi.mock("./bash-command.js", () => ({
  handleBashChatCommand: handleBashChatCommandMock,
}));

function buildBashParams(commandBodyNormalized: string): HandleCommandsParams {
  return {
    cfg: {
      commands: { bash: true, text: true },
      whatsapp: { allowFrom: ["*"] },
    } as OpenClawConfig,
    ctx: {
      Provider: "whatsapp",
      Surface: "whatsapp",
      CommandSource: "text",
      CommandBody: commandBodyNormalized,
    },
    command: {
      commandBodyNormalized,
      isAuthorizedSender: true,
      senderIsOwner: true,
      senderId: "owner",
      channel: "whatsapp",
      channelId: "whatsapp",
      surface: "whatsapp",
      ownerList: [],
      from: "test-user",
      to: "test-bot",
    },
    sessionKey: "agent:main:whatsapp:direct:test-user",
    elevated: { enabled: true, allowed: true, failures: [] },
    isGroup: false,
  } as unknown as HandleCommandsParams;
}

describe("handleBashCommand alias routing", () => {
  beforeEach(() => {
    vi.clearAllMocks();
    resolveSessionAgentIdMock.mockReturnValue("target");
  });

  it("routes !poll and !stop through the bash chat handler", async () => {
    for (const aliasCommand of ["!poll""!stop"]) {
      const result = await handleBashCommand(buildBashParams(aliasCommand), true);
      expect(result?.shouldContinue).toBe(false);
      expect(result?.reply?.text).toContain("No active bash job");
    }
    expect(handleBashChatCommandMock).toHaveBeenCalledTimes(2);
  });

  it("uses the canonical target session agent for /bash routing", async () => {
    const params = buildBashParams("/bash pwd");
    params.agentId = "main";
    params.sessionKey = "agent:target:whatsapp:direct:test-user";

    const result = await handleBashCommand(params, true);

    expect(result?.shouldContinue).toBe(false);
    expect(handleBashChatCommandMock).toHaveBeenCalledWith(
      expect.objectContaining({
        agentId: "target",
        sessionKey: "agent:target:whatsapp:direct:test-user",
      }),
    );
  });
});

Messung V0.5 in Prozent
C=98 H=97 G=97

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.