mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
* fix cli alias * 🐛 fix(cli): fix gen text non-streaming mode and streaming SSE parsing - Add `responseMode: 'json'` for non-streaming requests to get plain JSON instead of SSE - Fix streaming SSE parser to handle LobeHub's JSON string format (e.g. `"Hello"`) - Support both OpenAI and Anthropic response formats in non-streaming mode - Add E2E tests for all generate commands (text, list, tts, asr, alias) - Update skills knowledge.md docs with new kb commands Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ✨ feat(cli): unify skill install command and add e2e tests Merge import-github/import-url/import-market into a single `skill install <source>` command with auto-detection (GitHub URL/shorthand, ZIP URL, or marketplace identifier). Add alias `skill i`. Add comprehensive e2e and unit tests for skill commands. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * 🔨 chore: fix linter formatting in memory e2e test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * 🐛 fix: add vitest-environment node declaration to aiProvider test Fix server-side env variable access error by declaring node environment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix cli review * fix test --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
182 lines
6.4 KiB
TypeScript
182 lines
6.4 KiB
TypeScript
import { execSync } from 'node:child_process';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/**
|
|
* E2E tests for `lh skill` agent skill management commands.
|
|
*
|
|
* Prerequisites:
|
|
* - `lh` CLI is installed and linked globally
|
|
* - User is authenticated (`lh login` completed)
|
|
* - Network access to the LobeHub server
|
|
*
|
|
* These tests create a real skill, verify CRUD operations, then clean up.
|
|
*/
|
|
|
|
const CLI = process.env.LH_CLI_PATH || 'lh';
|
|
const TIMEOUT = 30_000;
|
|
|
|
function run(args: string): string {
|
|
return execSync(`${CLI} ${args}`, {
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, PATH: `${process.env.HOME}/.bun/bin:${process.env.PATH}` },
|
|
timeout: TIMEOUT,
|
|
}).trim();
|
|
}
|
|
|
|
function runJson<T = any>(args: string): T {
|
|
const output = run(args);
|
|
return JSON.parse(output) as T;
|
|
}
|
|
|
|
describe('lh skill - E2E', () => {
|
|
const testName = `E2E-Skill-${Date.now()}`;
|
|
const testDescription = 'Created by E2E test';
|
|
const testContent = 'You are a helpful test skill.';
|
|
const testIdentifier = `e2e-test-skill-${Date.now()}`;
|
|
let createdId: string;
|
|
|
|
// ── create ────────────────────────────────────────────
|
|
|
|
describe('create', () => {
|
|
it('should create a skill and return its id', () => {
|
|
const output = run(
|
|
`skill create -n "${testName}" -d "${testDescription}" -c "${testContent}" -i "${testIdentifier}"`,
|
|
);
|
|
expect(output).toContain('Created skill');
|
|
|
|
// Extract id from output like "✓ Created skill xxx"
|
|
const match = output.match(/Created skill\s+(\S+)/);
|
|
expect(match).not.toBeNull();
|
|
createdId = match![1];
|
|
});
|
|
|
|
it('should be viewable after creation', () => {
|
|
const result = runJson<{ id: string; name: string }>(
|
|
`skill view ${createdId} --json id,name`,
|
|
);
|
|
expect(result.id).toBe(createdId);
|
|
expect(result.name).toBe(testName);
|
|
});
|
|
});
|
|
|
|
// ── list ──────────────────────────────────────────────
|
|
|
|
describe('list', () => {
|
|
it('should return valid output (table or empty message)', () => {
|
|
const output = run('skill list');
|
|
// May return table or "No skills found." depending on backend state
|
|
expect(output).toBeTruthy();
|
|
});
|
|
|
|
it('should output JSON array', () => {
|
|
const list = runJson<any[]>('skill list --json id,name');
|
|
expect(Array.isArray(list)).toBe(true);
|
|
if (list.length > 0) {
|
|
expect(list[0]).toHaveProperty('id');
|
|
expect(list[0]).toHaveProperty('name');
|
|
expect(list[0]).not.toHaveProperty('content');
|
|
}
|
|
});
|
|
|
|
it('should filter by source', () => {
|
|
const list = runJson<{ id: string; source: string }[]>(
|
|
'skill list --source user --json id,source',
|
|
);
|
|
expect(Array.isArray(list)).toBe(true);
|
|
for (const item of list) {
|
|
expect(item.source).toBe('user');
|
|
}
|
|
});
|
|
});
|
|
|
|
// ── view ──────────────────────────────────────────────
|
|
|
|
describe('view', () => {
|
|
it('should view skill details', () => {
|
|
const output = run(`skill view ${createdId}`);
|
|
expect(output).toContain(testName);
|
|
expect(output).toContain(testDescription);
|
|
});
|
|
|
|
it('should output JSON with --json flag', () => {
|
|
const result = runJson<{
|
|
description: string;
|
|
id: string;
|
|
name: string;
|
|
}>(`skill view ${createdId} --json id,name,description`);
|
|
expect(result.id).toBe(createdId);
|
|
expect(result.name).toBe(testName);
|
|
expect(result.description).toBe(testDescription);
|
|
});
|
|
});
|
|
|
|
// ── edit ──────────────────────────────────────────────
|
|
|
|
describe('edit', () => {
|
|
const updatedName = `${testName}-Updated`;
|
|
const updatedDesc = 'Updated by E2E test';
|
|
const updatedContent = 'Updated content for test skill.';
|
|
|
|
it('should update skill name and description', () => {
|
|
const output = run(`skill edit ${createdId} -n "${updatedName}" -d "${updatedDesc}"`);
|
|
expect(output).toContain('Updated skill');
|
|
expect(output).toContain(createdId);
|
|
});
|
|
|
|
it('should reflect name/description updates when viewed', () => {
|
|
const result = runJson<{ description: string; name: string }>(
|
|
`skill view ${createdId} --json name,description`,
|
|
);
|
|
expect(result.name).toBe(updatedName);
|
|
expect(result.description).toBe(updatedDesc);
|
|
});
|
|
|
|
it('should update skill content', () => {
|
|
const output = run(`skill edit ${createdId} -c "${updatedContent}"`);
|
|
expect(output).toContain('Updated skill');
|
|
expect(output).toContain(createdId);
|
|
});
|
|
|
|
it('should reflect content update when viewed', () => {
|
|
const result = runJson<{ content: string }>(`skill view ${createdId} --json content`);
|
|
expect(result.content).toBe(updatedContent);
|
|
});
|
|
|
|
it('should error when no changes specified', () => {
|
|
expect(() => run(`skill edit ${createdId}`)).toThrow();
|
|
});
|
|
});
|
|
|
|
// ── search ────────────────────────────────────────────
|
|
|
|
describe('search', () => {
|
|
it('should search skills in table format', () => {
|
|
const output = run(`skill search "${testName}"`);
|
|
// May or may not find results depending on indexing, but should not throw
|
|
expect(typeof output).toBe('string');
|
|
});
|
|
|
|
it('should output JSON with --json flag', () => {
|
|
const list = runJson<any[]>(`skill search "${testName}" --json id,name`);
|
|
expect(Array.isArray(list)).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ── delete ────────────────────────────────────────────
|
|
|
|
describe('delete', () => {
|
|
it('should delete the skill', () => {
|
|
const output = run(`skill delete ${createdId} --yes`);
|
|
expect(output).toContain('Deleted skill');
|
|
expect(output).toContain(createdId);
|
|
});
|
|
|
|
it('should no longer appear in the list', () => {
|
|
const list = runJson<{ id: string }[]>('skill list --source user --json id');
|
|
const found = list.find((s) => s.id === createdId);
|
|
expect(found).toBeUndefined();
|
|
});
|
|
});
|
|
});
|