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.

1.7 KB
Raw Blame
import { SkillMaintainerExecutionRuntime } from '@lobechat/builtin-tool-skill-maintainer/executionRuntime';
import { describe, expect, it, vi } from 'vitest';

import { SkillManagementDocumentService } from '@/server/services/skillManagement';

import { skillManagementRuntime } from '../skillManagement';

vi.mock('@/server/services/skillManagement');

describe('skillManagementRuntime', () => {
  /**
   * @example
   * The hidden skill-management runtime declares the builtin identifier used by the registry.
   */
  it('declares the skill maintainer runtime identifier', () => {
    expect(skillManagementRuntime.identifier).toBe('lobe-skill-maintainer');
  });

  /**
   * @example
   * Server runtime construction requires persistence context.
   */
  it('throws if required server context is missing', () => {
    expect(() =>
      skillManagementRuntime.factory({ serverDB: {} as never, toolManifestMap: {} }),
    ).toThrow('userId and serverDB are required for Skill Management execution');
    expect(() => skillManagementRuntime.factory({ toolManifestMap: {}, userId: 'user-1' })).toThrow(
      'userId and serverDB are required for Skill Management execution',
    );
  });

  /**
   * @example
   * The registration factory creates a package-level runtime backed by SkillManagementDocumentService.
   */
  it('constructs a SkillMaintainerExecutionRuntime backed by a workspace-scoped document service', () => {
    const runtime = skillManagementRuntime.factory({
      serverDB: {} as never,
      toolManifestMap: {},
      userId: 'user-1',
      workspaceId: 'ws-1',
    });

    expect(runtime).toBeInstanceOf(SkillMaintainerExecutionRuntime);
    expect(SkillManagementDocumentService).toHaveBeenCalledWith({}, 'user-1', 'ws-1');
  });
});