Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.1 KB
Raw Blame
import { ArtboardIdentifier } from '@lobechat/builtin-tool-artboard';
import { DashboardIdentifier, LegacyDashboardIdentifier } from '@lobechat/builtin-tool-dashboard';
import { WebhookIdentifier } from '@lobechat/builtin-tool-webhook';
import { describe, expect, it } from 'vitest';

import { getFeatureDisabledToolIds, isToolEnabledByFeatureFlags } from './featureGates';

describe('feature-gated builtin tools', () => {
  it('drops the dashboard tool unless the dashboard flag is on', () => {
    expect(getFeatureDisabledToolIds(undefined)).toContain(DashboardIdentifier);
    expect(getFeatureDisabledToolIds(undefined)).toContain(LegacyDashboardIdentifier);
    expect(getFeatureDisabledToolIds({ enableDashboard: false })).toContain(DashboardIdentifier);
    expect(getFeatureDisabledToolIds({ enableDashboard: true })).not.toContain(DashboardIdentifier);
    expect(getFeatureDisabledToolIds({ enableDashboard: true })).not.toContain(
      LegacyDashboardIdentifier,
    );
  });

  it('drops the artboard tool unless the artboard flag is on', () => {
    expect(getFeatureDisabledToolIds(undefined)).toContain(ArtboardIdentifier);
    expect(getFeatureDisabledToolIds({ enableArtboard: true })).not.toContain(ArtboardIdentifier);
  });

  it('only gates tools that declare a flag', () => {
    expect(isToolEnabledByFeatureFlags(DashboardIdentifier, {})).toBe(false);
    expect(isToolEnabledByFeatureFlags(DashboardIdentifier, { enableDashboard: true })).toBe(true);
    expect(isToolEnabledByFeatureFlags('lobe-web-browsing', {})).toBe(true);
  });

  it('drops the webhook tool unless the webhook flag is on', () => {
    expect(getFeatureDisabledToolIds(undefined)).toContain(WebhookIdentifier);
    expect(getFeatureDisabledToolIds({ enableWebhook: false })).toContain(WebhookIdentifier);
    expect(getFeatureDisabledToolIds({ enableWebhook: true })).not.toContain(WebhookIdentifier);
    expect(isToolEnabledByFeatureFlags(WebhookIdentifier, { enableDashboard: true })).toBe(false);
    expect(isToolEnabledByFeatureFlags(WebhookIdentifier, { enableWebhook: true })).toBe(true);
  });
});