Files
openclaw/extensions/buzz/src/setup-core.test.ts
Peter Steinberger 9e4381eb1c refactor(channels): unify bundled channel setup contracts (#117106)
* refactor(channels): canonicalize bundled setup contracts

* test(matrix): use scoped environment fixtures
2026-07-31 16:57:29 -07:00

92 lines
2.7 KiB
TypeScript

import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { afterEach, describe, expect, it, vi } from "vitest";
import { buzzSetupContract } from "./setup-core.js";
describe("buzzSetupContract", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("removes a stored private key when switching to BUZZ_PRIVATE_KEY", () => {
vi.stubEnv("BUZZ_PRIVATE_KEY", "22".repeat(32));
const cfg = {
channels: {
buzz: {
enabled: true,
relayUrl: "wss://old.example.com",
privateKey: "11".repeat(32),
},
},
} as OpenClawConfig;
const result = buzzSetupContract.applyAccountConfig({
cfg,
accountId: "default",
input: { relayUrl: "wss://buzz.example.com", useEnv: true },
});
expect(result.channels?.buzz).toEqual({
enabled: true,
relayUrl: "wss://buzz.example.com",
});
});
it("rejects --use-env when BUZZ_PRIVATE_KEY is unset", () => {
vi.stubEnv("BUZZ_PRIVATE_KEY", "");
if (!buzzSetupContract.validateInput) {
throw new Error("Expected buzzSetupContract.validateInput to be defined");
}
expect(
buzzSetupContract.validateInput({
cfg: {} as OpenClawConfig,
accountId: "default",
input: { relayUrl: "wss://buzz.example.com", useEnv: true },
}),
).toBe("BUZZ_PRIVATE_KEY is not set.");
});
it("clears an identity-bound auth tag when changing the private key", () => {
const cfg = {
channels: {
buzz: {
relayUrl: "wss://buzz.example.com",
privateKey: "11".repeat(32),
authTag: '["auth","owner","kind=9","signature"]',
},
},
} as OpenClawConfig;
const result = buzzSetupContract.applyAccountConfig({
cfg,
accountId: "default",
input: { relayUrl: "wss://buzz.example.com", privateKey: "22".repeat(32) },
});
expect(result.channels?.buzz?.privateKey).toBe("22".repeat(32));
expect(result.channels?.buzz?.authTag).toBeUndefined();
});
it("clears an auth tag when replacing an unresolved SecretRef with the environment", () => {
vi.stubEnv("BUZZ_PRIVATE_KEY", "22".repeat(32));
const cfg = {
channels: {
buzz: {
relayUrl: "wss://buzz.example.com",
privateKey: { source: "env", provider: "default", id: "OTHER_BUZZ_KEY" },
authTag: '["auth","owner","kind=9","signature"]',
},
},
} as OpenClawConfig;
const result = buzzSetupContract.applyAccountConfig({
cfg,
accountId: "default",
input: { relayUrl: "wss://buzz.example.com", useEnv: true },
});
expect(result.channels?.buzz?.privateKey).toBeUndefined();
expect(result.channels?.buzz?.authTag).toBeUndefined();
});
});