mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 12:11:34 +00:00
* refactor(channels): canonicalize bundled setup contracts * test(matrix): use scoped environment fixtures
92 lines
2.7 KiB
TypeScript
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();
|
|
});
|
|
});
|