The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { skillsApi } from '../skillsApi';
vi.mock('../../coreRpcClient', () => ({ callCoreRpc: vi.fn() }));
describe('skillsApi.createWorkflow', () => {
beforeEach(async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockReset();
});
it('forwards inputs to skills_create and rekeys allowedTools', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
workflow: {
id: 'my-skill',
name: 'my-skill',
description: 'does stuff',
version: '',
author: null,
tags: ['alpha'],
tools: ['mcp/fs'],
prompts: [],
location: '/home/u/.openhuman/skills/my-skill/SKILL.md',
resources: [],
scope: 'user',
legacy: false,
warnings: [],
},
});
const result = await skillsApi.createWorkflow({
name: 'My Skill',
description: 'does stuff',
scope: 'user',
tags: ['alpha'],
allowedTools: ['mcp/fs'],
});
expect(callCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.skills_create',
params: {
name: 'My Skill',
description: 'does stuff',
scope: 'user',
tags: ['alpha'],
'allowed-tools': ['mcp/fs'],
},
});
expect(result.id).toBe('my-skill');
expect(result.scope).toBe('user');
});
it('omits optional fields when not provided', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
workflow: {
id: 'minimal',
name: 'minimal',
description: 'd',
version: '',
author: null,
tags: [],
tools: [],
prompts: [],
location: null,
resources: [],
scope: 'user',
legacy: false,
warnings: [],
},
});
await skillsApi.createWorkflow({ name: 'minimal', description: 'd' });
const call = vi.mocked(callCoreRpc).mock.calls[0][0];
expect(call.params).toEqual({ name: 'minimal', description: 'd' });
});
it('unwraps an envelope response', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
data: {
workflow: {
id: 'env',
name: 'env',
description: 'e',
version: '',
author: null,
tags: [],
tools: [],
prompts: [],
location: null,
resources: [],
scope: 'project',
legacy: false,
warnings: [],
},
},
});
const result = await skillsApi.createWorkflow({ name: 'env', description: 'e' });
expect(result.id).toBe('env');
expect(result.scope).toBe('project');
});
});
describe('skillsApi.installWorkflowFromUrl', () => {
beforeEach(async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockReset();
});
it('forwards url and rekeys timeoutSecs to timeout_secs', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
url: 'https://example.com/my-skill.tgz',
stdout: 'added my-skill',
stderr: '',
new_workflows: ['my-skill'],
});
const result = await skillsApi.installWorkflowFromUrl({
url: 'https://example.com/my-skill.tgz',
timeoutSecs: 120,
});
expect(callCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.skills_install_from_url',
params: { url: 'https://example.com/my-skill.tgz', timeout_secs: 120 },
});
expect(result).toMatchObject({
status: 'installed',
newWorkflows: ['my-skill'],
stdout: 'added my-skill',
});
});
it('returns a scan_blocked outcome and forwards the acknowledgement', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
status: 'scan_blocked',
target: 'https://example.com/SKILL.md',
fetched_from: 'https://example.com/SKILL.md',
slug: 'bad',
digest: 'abc',
findings: [{ check: 'invisible_code_points', verdict: 'block', field: 'body', message: 'm' }],
message: 'blocked',
});
const blocked = await skillsApi.installWorkflowFromUrl({ url: 'https://example.com/SKILL.md' });
expect(blocked).toEqual({
status: 'scan_blocked',
scan: {
target: 'https://example.com/SKILL.md',
fetchedFrom: 'https://example.com/SKILL.md',
slug: 'bad',
digest: 'abc',
findings: [
{ check: 'invisible_code_points', verdict: 'block', field: 'body', message: 'm' },
],
message: 'blocked',
},
});
vi.mocked(callCoreRpc).mockResolvedValueOnce({
status: 'installed',
url: 'https://example.com/SKILL.md',
stdout: '',
stderr: '',
new_workflows: ['bad'],
});
await skillsApi.installWorkflowFromUrl({
url: 'https://example.com/SKILL.md',
acknowledgedDigest: 'abc',
});
expect(vi.mocked(callCoreRpc).mock.calls[1][0].params).toEqual({
url: 'https://example.com/SKILL.md',
acknowledged_digest: 'abc',
});
});
it('omits timeout_secs when not provided and normalizes missing new_workflows', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
url: 'https://example.com/x',
stdout: '',
stderr: '',
new_workflows: undefined,
});
const result = await skillsApi.installWorkflowFromUrl({ url: 'https://example.com/x' });
const call = vi.mocked(callCoreRpc).mock.calls[0][0];
expect(call.params).toEqual({ url: 'https://example.com/x' });
expect(result).toMatchObject({ status: 'installed', newWorkflows: [] });
});
it('unwraps an envelope response', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
data: {
url: 'https://example.com/y',
stdout: 'ok',
stderr: 'warn',
new_workflows: ['y-skill'],
},
});
const result = await skillsApi.installWorkflowFromUrl({ url: 'https://example.com/y' });
expect(result).toMatchObject({ newWorkflows: ['y-skill'], stderr: 'warn' });
});
});
describe('skillsApi.updateWorkflow', () => {
beforeEach(async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockReset();
});
it('forwards every optional field and rekeys allowedTools', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
workflow: { id: 'wf', name: 'WF', description: 'd', scope: 'user' as const },
});
await skillsApi.updateWorkflow({
name: 'WF',
description: 'd',
whenToUse: 'when X happens',
scope: 'user',
license: 'MIT',
author: 'me',
tags: ['t'],
allowedTools: ['mcp/fs'],
inputs: [{ name: 'n', required: true }],
});
expect(callCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.skills_update',
params: {
name: 'WF',
description: 'd',
when_to_use: 'when X happens',
scope: 'user',
license: 'MIT',
author: 'me',
tags: ['t'],
'allowed-tools': ['mcp/fs'],
inputs: [{ name: 'n', required: true }],
},
});
});
});
describe('skillsApi.listWorkflows', () => {
beforeEach(async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockReset();
});
it('reads the `workflows` result field', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
workflows: [
{ id: 'a', name: 'A', description: '', scope: 'user' as const },
{ id: 'b', name: 'B', description: '', scope: 'project' as const },
],
});
const result = await skillsApi.listWorkflows();
expect(callCoreRpc).toHaveBeenCalledWith({ method: 'openhuman.skills_list' });
expect(result.map(w => w.id)).toEqual(['a', 'b']);
});
it('unwraps an envelope and defaults to [] when the field is absent', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({ data: {} });
const result = await skillsApi.listWorkflows();
expect(result).toEqual([]);
});
it('normalizes snake_case and legacy discovered workflow fields', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
workflows: [
{
id: 'hermes-demo',
name: 'Hermes Demo',
description: 'Reads Hermes metadata.',
version: '',
author: null,
tags: [],
related_skills: ['browser-automation'],
source_format: 'hermes',
tools: [],
prompts: [],
location: null,
resources: [],
scope: 'user',
legacy: false,
warnings: [],
},
{
id: 'legacy-demo',
name: 'Legacy Demo',
description: 'Old package.',
version: '',
author: null,
tags: [],
tools: [],
prompts: [],
location: null,
resources: [],
scope: 'user',
legacy: true,
warnings: [],
},
],
});
const result = await skillsApi.listWorkflows();
expect(callCoreRpc).toHaveBeenCalledWith({ method: 'openhuman.skills_list' });
expect(result[0].relatedSkills).toEqual(['browser-automation']);
expect(result[0].sourceFormat).toBe('hermes');
expect(result[0].platforms).toEqual([]);
expect(result[1].sourceFormat).toBe('legacy');
});
it('omits params by default (automations-only view)', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({ workflows: [] });
await skillsApi.listWorkflows();
const call = vi.mocked(callCoreRpc).mock.calls[0][0];
expect(call.method).toBe('openhuman.skills_list');
expect(call.params).toBeUndefined();
});
it('passes include_skills when includeSkills is set', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({ workflows: [] });
await skillsApi.listWorkflows({ includeSkills: true });
expect(callCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.skills_list',
params: { include_skills: true },
});
});
});
describe('skillsApi.readWorkflowResource', () => {
beforeEach(async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockReset();
});
it('rekeys params to snake_case and normalizes the response', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
workflow_id: 'wf',
relative_path: 'scripts/run.sh',
content: '#!/bin/sh\n',
bytes: 10,
});
const result = await skillsApi.readWorkflowResource({
workflowId: 'wf',
relativePath: 'scripts/run.sh',
});
expect(callCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.skills_read_resource',
params: { workflow_id: 'wf', relative_path: 'scripts/run.sh' },
});
expect(result).toEqual({
workflowId: 'wf',
relativePath: 'scripts/run.sh',
content: '#!/bin/sh\n',
bytes: 10,
});
});
});
describe('skillsApi.uninstallWorkflow', () => {
beforeEach(async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockReset();
});
it('forwards the name and normalizes removed_path → removedPath', async () => {
const { callCoreRpc } = await import('../../coreRpcClient');
vi.mocked(callCoreRpc).mockResolvedValueOnce({
name: 'weather-helper',
removed_path: '/home/u/.openhuman/skills/weather-helper',
scope: 'user',
});
const result = await skillsApi.uninstallWorkflow('weather-helper');
expect(callCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.skill_registry_uninstall',
params: { name: 'weather-helper' },
});
expect(result).toEqual({
name: 'weather-helper',
removedPath: '/home/u/.openhuman/skills/weather-helper',
scope: 'user',
});
});
});