mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 15:21:06 +00:00
72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { validateConfigObjectRaw } from "./validation.js";
|
|
|
|
describe("config validation allowed-values metadata", () => {
|
|
it("adds allowed values for invalid union paths", () => {
|
|
const result = validateConfigObjectRaw({
|
|
update: { channel: "nightly" },
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
const issue = result.issues.find((entry) => entry.path === "update.channel");
|
|
expect(issue).toBeDefined();
|
|
expect(issue?.message).toContain('(allowed: "stable", "beta", "dev")');
|
|
expect(issue?.allowedValues).toEqual(["stable", "beta", "dev"]);
|
|
expect(issue?.allowedValuesHiddenCount).toBe(0);
|
|
}
|
|
});
|
|
|
|
it("keeps native enum messages while attaching allowed values metadata", () => {
|
|
const result = validateConfigObjectRaw({
|
|
channels: { signal: { dmPolicy: "maybe" } },
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
const issue = result.issues.find((entry) => entry.path === "channels.signal.dmPolicy");
|
|
expect(issue).toBeDefined();
|
|
expect(issue?.message).toContain("expected one of");
|
|
expect(issue?.message).not.toContain("(allowed:");
|
|
expect(issue?.allowedValues).toEqual(["pairing", "allowlist", "open", "disabled"]);
|
|
expect(issue?.allowedValuesHiddenCount).toBe(0);
|
|
}
|
|
});
|
|
|
|
it("includes boolean variants for boolean-or-enum unions", () => {
|
|
const result = validateConfigObjectRaw({
|
|
channels: {
|
|
telegram: {
|
|
botToken: "x",
|
|
allowFrom: ["*"],
|
|
dmPolicy: "allowlist",
|
|
streaming: "maybe",
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
const issue = result.issues.find((entry) => entry.path === "channels.telegram");
|
|
expect(issue).toBeDefined();
|
|
expect(issue?.message).toContain('channels.telegram.streaming="off|partial|block"');
|
|
expect(issue?.allowedValues).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("skips allowed-values hints for unions with open-ended branches", () => {
|
|
const result = validateConfigObjectRaw({
|
|
cron: { sessionRetention: true },
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
const issue = result.issues.find((entry) => entry.path === "cron.sessionRetention");
|
|
expect(issue).toBeDefined();
|
|
expect(issue?.allowedValues).toBeUndefined();
|
|
expect(issue?.allowedValuesHiddenCount).toBeUndefined();
|
|
expect(issue?.message).not.toContain("(allowed:");
|
|
}
|
|
});
|
|
});
|