mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:34:32 +00:00
refactor(config): dedupe native command setting resolver
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { resolveNativeSkillsEnabled } from "./commands.js";
|
import {
|
||||||
|
isNativeCommandsExplicitlyDisabled,
|
||||||
|
resolveNativeCommandsEnabled,
|
||||||
|
resolveNativeSkillsEnabled,
|
||||||
|
} from "./commands.js";
|
||||||
|
|
||||||
describe("resolveNativeSkillsEnabled", () => {
|
describe("resolveNativeSkillsEnabled", () => {
|
||||||
it("uses provider defaults for auto", () => {
|
it("uses provider defaults for auto", () => {
|
||||||
@@ -46,3 +50,50 @@ describe("resolveNativeSkillsEnabled", () => {
|
|||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("resolveNativeCommandsEnabled", () => {
|
||||||
|
it("follows the same provider default heuristic", () => {
|
||||||
|
expect(resolveNativeCommandsEnabled({ providerId: "discord", globalSetting: "auto" })).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(resolveNativeCommandsEnabled({ providerId: "telegram", globalSetting: "auto" })).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(resolveNativeCommandsEnabled({ providerId: "slack", globalSetting: "auto" })).toBe(
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("honors explicit provider/global booleans", () => {
|
||||||
|
expect(
|
||||||
|
resolveNativeCommandsEnabled({
|
||||||
|
providerId: "slack",
|
||||||
|
providerSetting: true,
|
||||||
|
globalSetting: false,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
resolveNativeCommandsEnabled({
|
||||||
|
providerId: "discord",
|
||||||
|
globalSetting: false,
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("isNativeCommandsExplicitlyDisabled", () => {
|
||||||
|
it("returns true only for explicit false at provider or fallback global", () => {
|
||||||
|
expect(
|
||||||
|
isNativeCommandsExplicitlyDisabled({ providerSetting: false, globalSetting: true }),
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
isNativeCommandsExplicitlyDisabled({ providerSetting: undefined, globalSetting: false }),
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
isNativeCommandsExplicitlyDisabled({ providerSetting: true, globalSetting: false }),
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
isNativeCommandsExplicitlyDisabled({ providerSetting: "auto", globalSetting: false }),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -21,21 +21,21 @@ export function resolveNativeSkillsEnabled(params: {
|
|||||||
providerSetting?: NativeCommandsSetting;
|
providerSetting?: NativeCommandsSetting;
|
||||||
globalSetting?: NativeCommandsSetting;
|
globalSetting?: NativeCommandsSetting;
|
||||||
}): boolean {
|
}): boolean {
|
||||||
const { providerId, providerSetting, globalSetting } = params;
|
return resolveNativeCommandSetting(params);
|
||||||
const setting = providerSetting === undefined ? globalSetting : providerSetting;
|
|
||||||
if (setting === true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (setting === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return resolveAutoDefault(providerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveNativeCommandsEnabled(params: {
|
export function resolveNativeCommandsEnabled(params: {
|
||||||
providerId: ChannelId;
|
providerId: ChannelId;
|
||||||
providerSetting?: NativeCommandsSetting;
|
providerSetting?: NativeCommandsSetting;
|
||||||
globalSetting?: NativeCommandsSetting;
|
globalSetting?: NativeCommandsSetting;
|
||||||
|
}): boolean {
|
||||||
|
return resolveNativeCommandSetting(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveNativeCommandSetting(params: {
|
||||||
|
providerId: ChannelId;
|
||||||
|
providerSetting?: NativeCommandsSetting;
|
||||||
|
globalSetting?: NativeCommandsSetting;
|
||||||
}): boolean {
|
}): boolean {
|
||||||
const { providerId, providerSetting, globalSetting } = params;
|
const { providerId, providerSetting, globalSetting } = params;
|
||||||
const setting = providerSetting === undefined ? globalSetting : providerSetting;
|
const setting = providerSetting === undefined ? globalSetting : providerSetting;
|
||||||
@@ -45,7 +45,6 @@ export function resolveNativeCommandsEnabled(params: {
|
|||||||
if (setting === false) {
|
if (setting === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// auto or undefined -> heuristic
|
|
||||||
return resolveAutoDefault(providerId);
|
return resolveAutoDefault(providerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user