mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 16:30:30 +00:00
fix: restore channel sdk schema typing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { buildChannelConfigSchema } from "./config-schema.js";
|
||||
import { buildChannelConfigSchema, emptyChannelConfigSchema } from "./config-schema.js";
|
||||
|
||||
describe("buildChannelConfigSchema", () => {
|
||||
it("builds json schema when toJSONSchema is available", () => {
|
||||
@@ -46,3 +46,22 @@ describe("buildChannelConfigSchema", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("emptyChannelConfigSchema", () => {
|
||||
it("accepts undefined and empty objects only", () => {
|
||||
const result = emptyChannelConfigSchema();
|
||||
|
||||
expect(result.runtime?.safeParse(undefined)).toEqual({
|
||||
success: true,
|
||||
data: undefined,
|
||||
});
|
||||
expect(result.runtime?.safeParse({})).toEqual({
|
||||
success: true,
|
||||
data: {},
|
||||
});
|
||||
expect(result.runtime?.safeParse({ enabled: true })).toEqual({
|
||||
success: false,
|
||||
issues: [{ path: [], message: "config must be empty" }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,3 +104,33 @@ export function buildChannelConfigSchema(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function emptyChannelConfigSchema(): ChannelConfigSchema {
|
||||
return {
|
||||
schema: {
|
||||
type: "object",
|
||||
additionalProperties: false,
|
||||
properties: {},
|
||||
},
|
||||
runtime: {
|
||||
safeParse(value) {
|
||||
if (value === undefined) {
|
||||
return { success: true, data: undefined };
|
||||
}
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
return {
|
||||
success: false,
|
||||
issues: [{ path: [], message: "expected config object" }],
|
||||
};
|
||||
}
|
||||
if (Object.keys(value as Record<string, unknown>).length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
issues: [{ path: [], message: "config must be empty" }],
|
||||
};
|
||||
}
|
||||
return { success: true, data: value };
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user