Step 5 + Review
This commit is contained in:
committed by
Peter Steinberger
parent
2cf444be02
commit
1eab8fa9b0
@@ -59,4 +59,84 @@ describe("applyPluginAutoEnable", () => {
|
||||
expect(result.config.plugins?.entries?.slack?.enabled).toBeUndefined();
|
||||
expect(result.changes).toEqual([]);
|
||||
});
|
||||
|
||||
describe("BlueBubbles over imessage prioritization", () => {
|
||||
it("prefers bluebubbles: skips imessage auto-enable when both are configured", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: {
|
||||
channels: {
|
||||
bluebubbles: { serverUrl: "http://localhost:1234", password: "x" },
|
||||
imessage: { cliPath: "/usr/local/bin/imsg" },
|
||||
},
|
||||
},
|
||||
env: {},
|
||||
});
|
||||
|
||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(true);
|
||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBeUndefined();
|
||||
expect(result.changes.join("\n")).toContain('Enabled plugin "bluebubbles"');
|
||||
expect(result.changes.join("\n")).not.toContain('Enabled plugin "imessage"');
|
||||
});
|
||||
|
||||
it("keeps imessage enabled if already explicitly enabled (non-destructive)", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: {
|
||||
channels: {
|
||||
bluebubbles: { serverUrl: "http://localhost:1234", password: "x" },
|
||||
imessage: { cliPath: "/usr/local/bin/imsg" },
|
||||
},
|
||||
plugins: { entries: { imessage: { enabled: true } } },
|
||||
},
|
||||
env: {},
|
||||
});
|
||||
|
||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(true);
|
||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("allows imessage auto-enable when bluebubbles is explicitly disabled", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: {
|
||||
channels: {
|
||||
bluebubbles: { serverUrl: "http://localhost:1234", password: "x" },
|
||||
imessage: { cliPath: "/usr/local/bin/imsg" },
|
||||
},
|
||||
plugins: { entries: { bluebubbles: { enabled: false } } },
|
||||
},
|
||||
env: {},
|
||||
});
|
||||
|
||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(false);
|
||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||
expect(result.changes.join("\n")).toContain('Enabled plugin "imessage"');
|
||||
});
|
||||
|
||||
it("allows imessage auto-enable when bluebubbles is in deny list", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: {
|
||||
channels: {
|
||||
bluebubbles: { serverUrl: "http://localhost:1234", password: "x" },
|
||||
imessage: { cliPath: "/usr/local/bin/imsg" },
|
||||
},
|
||||
plugins: { deny: ["bluebubbles"] },
|
||||
},
|
||||
env: {},
|
||||
});
|
||||
|
||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBeUndefined();
|
||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("enables imessage normally when only imessage is configured", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: {
|
||||
channels: { imessage: { cliPath: "/usr/local/bin/imsg" } },
|
||||
},
|
||||
env: {},
|
||||
});
|
||||
|
||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||
expect(result.changes.join("\n")).toContain('Enabled plugin "imessage"');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -267,6 +267,23 @@ function isPluginDenied(cfg: ClawdbotConfig, pluginId: string): boolean {
|
||||
return Array.isArray(deny) && deny.includes(pluginId);
|
||||
}
|
||||
|
||||
/**
|
||||
* When both BlueBubbles and iMessage are configured, prefer BlueBubbles:
|
||||
* skip auto-enabling iMessage unless BlueBubbles is explicitly disabled/denied.
|
||||
* This is non-destructive: if iMessage is already enabled, it won't be touched.
|
||||
*/
|
||||
function shouldSkipImsgForBlueBubbles(
|
||||
cfg: ClawdbotConfig,
|
||||
pluginId: string,
|
||||
configured: PluginEnableChange[],
|
||||
): boolean {
|
||||
if (pluginId !== "imessage") return false;
|
||||
const blueBubblesConfigured = configured.some((e) => e.pluginId === "bluebubbles");
|
||||
if (!blueBubblesConfigured) return false;
|
||||
// Skip imessage auto-enable if bluebubbles is configured and not blocked
|
||||
return !isPluginExplicitlyDisabled(cfg, "bluebubbles") && !isPluginDenied(cfg, "bluebubbles");
|
||||
}
|
||||
|
||||
function ensureAllowlisted(cfg: ClawdbotConfig, pluginId: string): ClawdbotConfig {
|
||||
const allow = cfg.plugins?.allow;
|
||||
if (!Array.isArray(allow) || allow.includes(pluginId)) return cfg;
|
||||
@@ -317,6 +334,8 @@ export function applyPluginAutoEnable(params: {
|
||||
for (const entry of configured) {
|
||||
if (isPluginDenied(next, entry.pluginId)) continue;
|
||||
if (isPluginExplicitlyDisabled(next, entry.pluginId)) continue;
|
||||
// Prefer BlueBubbles over imessage: skip imsg auto-enable if bluebubbles is configured
|
||||
if (shouldSkipImsgForBlueBubbles(next, entry.pluginId, configured)) continue;
|
||||
const allow = next.plugins?.allow;
|
||||
const allowMissing = Array.isArray(allow) && !allow.includes(entry.pluginId);
|
||||
const alreadyEnabled = next.plugins?.entries?.[entry.pluginId]?.enabled === true;
|
||||
|
||||
Reference in New Issue
Block a user