A desktop coding agent with free access to frontier models.
TypeScript
import { describe, expect, test } from "bun:test";
import type { DesktopAppRestrictionChecker } from "../src/app/cloud/desktop-app-restrictions";
import {
computePolicyProviderReconcilePlan,
type PolicyProviderListItem,
} from "../src/react-app/domains/connections/policy-provider-reconcile";
import { afterAll as afterAllUnlocked, beforeAll as beforeAllUnlocked } from "bun:test";
import { setProviderLockState } from "../src/app/lib/provider-lock";
// These cover the app while the server leaves model providers unlocked
// (providers.locked false); tests/provider-lock.test.ts covers the lock.
beforeAllUnlocked(() => setProviderLockState({ locked: false }));
afterAllUnlocked(() => setProviderLockState(null));
function provider(id: string): PolicyProviderListItem {
return { id };
}
function restrictionChecker(blocked: readonly string[]): DesktopAppRestrictionChecker {
return ({ restriction }) => blocked.includes(restriction);
}
describe("computePolicyProviderReconcilePlan", () => {
test("disables a connected custom provider when custom providers are restricted", () => {
expect(
computePolicyProviderReconcilePlan({
allProviders: [provider("openai")],
connectedProviderIds: ["openai"],
disabledProviderIds: [],
markedDisabledProviderIds: [],
checkRestriction: restrictionChecker(["allowCustomProviders"]),
}),
).toEqual({
toDisable: ["openai"],
toReenable: [],
nextMarkedDisabledProviderIds: ["openai"],
});
});
test("re-enables only providers previously disabled by policy", () => {
expect(
computePolicyProviderReconcilePlan({
allProviders: [provider("openai"), provider("anthropic")],
connectedProviderIds: [],
disabledProviderIds: ["openai", "anthropic"],
markedDisabledProviderIds: ["openai"],
checkRestriction: restrictionChecker([]),
}),
).toEqual({
toDisable: [],
toReenable: ["openai"],
nextMarkedDisabledProviderIds: [],
});
});
test("leaves user-disabled providers untouched", () => {
expect(
computePolicyProviderReconcilePlan({
allProviders: [provider("openai")],
connectedProviderIds: [],
disabledProviderIds: ["openai"],
markedDisabledProviderIds: [],
checkRestriction: restrictionChecker([]),
}),
).toEqual({
toDisable: [],
toReenable: [],
nextMarkedDisabledProviderIds: [],
});
});
test("never disables cloud-managed providers under the custom-provider restriction", () => {
expect(
computePolicyProviderReconcilePlan({
allProviders: [provider("lpr_team"), provider("omnirush"), provider("openai")],
connectedProviderIds: ["lpr_team", "omnirush", "openai"],
disabledProviderIds: [],
markedDisabledProviderIds: [],
checkRestriction: restrictionChecker(["allowCustomProviders"]),
}).toDisable,
).toEqual(["openai"]);
});
test("respects the Zen policy while custom providers are restricted", () => {
expect(
computePolicyProviderReconcilePlan({
allProviders: [provider("opencode")],
connectedProviderIds: ["opencode"],
disabledProviderIds: [],
markedDisabledProviderIds: [],
checkRestriction: restrictionChecker(["allowCustomProviders"]),
}).toDisable,
).toEqual([]);
expect(
computePolicyProviderReconcilePlan({
allProviders: [provider("opencode")],
connectedProviderIds: ["opencode"],
disabledProviderIds: [],
markedDisabledProviderIds: [],
checkRestriction: restrictionChecker(["allowCustomProviders", "allowZenModel"]),
}).toDisable,
).toEqual(["opencode"]);
});
});