refactor(config): dedupe native command setting resolver
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveNativeSkillsEnabled } from "./commands.js";
|
||||
import {
|
||||
isNativeCommandsExplicitlyDisabled,
|
||||
resolveNativeCommandsEnabled,
|
||||
resolveNativeSkillsEnabled,
|
||||
} from "./commands.js";
|
||||
|
||||
describe("resolveNativeSkillsEnabled", () => {
|
||||
it("uses provider defaults for auto", () => {
|
||||
@@ -46,3 +50,50 @@ describe("resolveNativeSkillsEnabled", () => {
|
||||
).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;
|
||||
globalSetting?: NativeCommandsSetting;
|
||||
}): boolean {
|
||||
const { providerId, providerSetting, globalSetting } = params;
|
||||
const setting = providerSetting === undefined ? globalSetting : providerSetting;
|
||||
if (setting === true) {
|
||||
return true;
|
||||
}
|
||||
if (setting === false) {
|
||||
return false;
|
||||
}
|
||||
return resolveAutoDefault(providerId);
|
||||
return resolveNativeCommandSetting(params);
|
||||
}
|
||||
|
||||
export function resolveNativeCommandsEnabled(params: {
|
||||
providerId: ChannelId;
|
||||
providerSetting?: NativeCommandsSetting;
|
||||
globalSetting?: NativeCommandsSetting;
|
||||
}): boolean {
|
||||
return resolveNativeCommandSetting(params);
|
||||
}
|
||||
|
||||
function resolveNativeCommandSetting(params: {
|
||||
providerId: ChannelId;
|
||||
providerSetting?: NativeCommandsSetting;
|
||||
globalSetting?: NativeCommandsSetting;
|
||||
}): boolean {
|
||||
const { providerId, providerSetting, globalSetting } = params;
|
||||
const setting = providerSetting === undefined ? globalSetting : providerSetting;
|
||||
@@ -45,7 +45,6 @@ export function resolveNativeCommandsEnabled(params: {
|
||||
if (setting === false) {
|
||||
return false;
|
||||
}
|
||||
// auto or undefined -> heuristic
|
||||
return resolveAutoDefault(providerId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user