Files
backnotprop__plannotator/packages/ui/utils/agentSwitch.test.ts
Brad Beebe ac3a84ba5a fix(opencode): Fix hardcoding default build OpenCode agent when sending responses (#1131)
* fix(opencode): default agent switching to disabled

* fix(opencode): keep plan-approval build handoff; default no-switch for review feedback only

The agent switch cookie is shared by plan approval and code review, so
flipping the stored default to `disabled` also removed OpenCode's
plan-approval hand-off for every user who never configured the setting.

Make the unset default surface-aware instead: `getAgentSwitchSettings('plan')`
keeps the historical build hand-off, `getAgentSwitchSettings('review')`
stays on the current agent. An explicit user choice still applies to both
surfaces. Settings and the agent warning resolve the default from the mode
they render in, and the OpenCode "agent not available" warning now names
plan approval on the plan path.

Claude-Session: https://claude.ai/code/session_01H5KQWqXqjrPxyxUNso1QHS

---------

Co-authored-by: Michael Ramos <mdramos8@gmail.com>
2026-07-26 22:08:04 -07:00

61 lines
2.0 KiB
TypeScript

import { afterEach, describe, expect, test } from "bun:test";
import { resetStorageBackend, setStorageBackend, type StorageBackend } from "./storage";
import { getAgentSwitchSettings, getEffectiveAgentName, saveAgentSwitchSettings } from "./agentSwitch";
function memoryStorage(initial: Record<string, string> = {}): StorageBackend {
const values = new Map(Object.entries(initial));
return {
getItem: (key) => values.get(key) ?? null,
setItem: (key, value) => { values.set(key, value); },
removeItem: (key) => { values.delete(key); },
};
}
afterEach(() => {
resetStorageBackend();
});
describe("agent switch settings", () => {
test("review feedback defaults to no switch/current agent when unset", () => {
setStorageBackend(memoryStorage());
const settings = getAgentSwitchSettings("review");
expect(settings.switchTo).toBe("disabled");
expect(getEffectiveAgentName(settings)).toBeUndefined();
});
test("plan approval defaults to the build hand-off when unset", () => {
setStorageBackend(memoryStorage());
const settings = getAgentSwitchSettings("plan");
expect(settings.switchTo).toBe("build");
expect(getEffectiveAgentName(settings)).toBe("build");
expect(getAgentSwitchSettings().switchTo).toBe("build");
});
test("an explicit choice overrides the surface default everywhere", () => {
setStorageBackend(memoryStorage());
saveAgentSwitchSettings({ switchTo: "disabled" });
expect(getAgentSwitchSettings("plan").switchTo).toBe("disabled");
expect(getAgentSwitchSettings("review").switchTo).toBe("disabled");
});
test("keeps an explicitly saved target agent", () => {
setStorageBackend(memoryStorage());
saveAgentSwitchSettings({ switchTo: "build" });
const settings = getAgentSwitchSettings("review");
expect(settings.switchTo).toBe("build");
expect(getEffectiveAgentName(settings)).toBe("build");
});
test("does not emit custom as an agent when no custom name is set", () => {
expect(getEffectiveAgentName({ switchTo: "custom" })).toBeUndefined();
});
});