refactor(config): dedupe native command setting resolver

This commit is contained in:
Peter Steinberger
2026-02-18 23:08:52 +00:00
parent 8b257703d8
commit f33ecae0bb
2 changed files with 61 additions and 11 deletions

View File

@@ -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);
});
});

View File

@@ -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);
}