import { describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import {
buildCommandsMessage,
buildCommandsMessagePaginated,
buildHelpMessage,
resolveSenderCommandAuthorization,
} from "./command-auth.js";
const baseCfg = {
commands: { useAccessGroups: true },
} as unknown as OpenClawConfig;
describe("plugin-sdk/command-auth", () => {
it("keeps deprecated command status builders available for compatibility", () => { const cfg = { commands: { config: false, debug: false } } as unknown as OpenClawConfig;
expect(buildHelpMessage(cfg)).toContain("/commands for full list");
expect(buildCommandsMessage(cfg)).toContain("More: /tools for available capabilities");
expect(buildCommandsMessage(cfg)).toContain("/models - List model providers/models.");
expect(buildCommandsMessagePaginated(cfg)).toMatchObject({
currentPage: 1,
totalPages: expect.any(Number),
});
});
it("resolves command authorization across allowlist sources", async () => { const cases = [
{
name: "authorizes group commands from explicit group allowlist",
senderId: "group-owner",
expectedAuthorized: true,
expectedSenderAllowed: true,
},
{
name: "keeps pairing-store identities DM-only for group command auth",
senderId: "paired-user",
expectedAuthorized: false,
expectedSenderAllowed: false,
},
];
for (const testCase of cases) { const result = await resolveAuthorization({ senderId: testCase.senderId });
expect(result.commandAuthorized).toBe(testCase.expectedAuthorized);
expect(result.senderAllowedForCommands).toBe(testCase.expectedSenderAllowed);
expect(result.effectiveAllowFrom).toEqual(["dm-owner"]);
expect(result.effectiveGroupAllowFrom).toEqual(["group-owner"]);
}
});
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.