KVARK is the commercial enterprise product and is not part of the community edition. The agent's KVARK tools were never wired into the server, so removing them changes no runtime behaviour beyond the routes listed here. - agent: delete kvark-tools; CombinedRetrieval and formatCombinedResult now merge workspace and personal memory only (no KVARK lane, no source conflict note); connector substrate is always 'waggle' - agent: promote_skill stops at workspace scope; team and enterprise scopes answer "not available in this edition" instead of an upgrade prompt - server: delete src/kvark and GET /api/marketplace/enterprise-packs - marketplace: delete ENTERPRISE_PACKS - compliance (EU AI Act dashboard, its templates and the KVARK template seeded on every boot): delete core/src/compliance, the /api/compliance/* routes, agent compliance-pdf and the Cockpit compliance panel. The ai_interactions table lives in the memory substrate and goes with P1.5.
161 lines
6.8 KiB
TypeScript
161 lines
6.8 KiB
TypeScript
/**
|
|
* Skills 2.0 gap E — promote_skill tool.
|
|
*
|
|
* Tests the one-step promotion personal → workspace, the refusal of team and
|
|
* enterprise scopes in this edition, frontmatter rewrite with promoted_from
|
|
* history, file move, and skill_promotion improvement signal emission.
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import * as os from 'node:os';
|
|
import { MindDB, ImprovementSignalStore } from '@waggle/core';
|
|
import { createSkillTools, getSkillDirForScope } from '../src/skill-tools.js';
|
|
import { parseSkillFrontmatter } from '../src/skill-frontmatter.js';
|
|
|
|
function seedSkill(dir: string, name: string, scope: string | null, body = 'body content'): void {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
const scopeLine = scope ? `scope: ${scope}\n` : '';
|
|
const content = `---\nname: ${name}\ndescription: seeded test skill\n${scopeLine}---\n${body}`;
|
|
fs.writeFileSync(path.join(dir, `${name}.md`), content, 'utf-8');
|
|
}
|
|
|
|
describe('promote_skill — gap E', () => {
|
|
let tmpDir: string;
|
|
let db: MindDB;
|
|
let signals: ImprovementSignalStore;
|
|
let reloadCount: number;
|
|
|
|
function createTools(overrides: Partial<Parameters<typeof createSkillTools>[0]> = {}) {
|
|
return createSkillTools({
|
|
waggleHome: tmpDir,
|
|
onSkillsChanged: () => { reloadCount++; },
|
|
getWorkspaceId: () => 'ws-alpha',
|
|
getTeamId: () => 'team-bravo',
|
|
improvementSignals: signals,
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
function run(tools: ReturnType<typeof createSkillTools>, name: string, args: Record<string, unknown> = {}) {
|
|
const tool = tools.find(t => t.name === name);
|
|
if (!tool) throw new Error(`Tool ${name} not found`);
|
|
return tool.execute(args);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-promote-test-'));
|
|
db = new MindDB(':memory:');
|
|
signals = new ImprovementSignalStore(db);
|
|
reloadCount = 0;
|
|
});
|
|
|
|
afterEach(() => {
|
|
db.close();
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
describe('happy path', () => {
|
|
it('promotes personal → workspace, moves file, appends history, records signal', async () => {
|
|
const personalDir = getSkillDirForScope(tmpDir, 'personal', {})!;
|
|
seedSkill(personalDir, 'deploy-helper', 'personal');
|
|
const tools = createTools();
|
|
|
|
const out = await run(tools, 'promote_skill', { skill_name: 'deploy-helper' });
|
|
|
|
expect(out).toContain('personal → workspace');
|
|
expect(out).toContain('Signal recorded');
|
|
|
|
// File moved
|
|
expect(fs.existsSync(path.join(personalDir, 'deploy-helper.md'))).toBe(false);
|
|
const wsDir = getSkillDirForScope(tmpDir, 'workspace', { workspaceId: 'ws-alpha' })!;
|
|
const newPath = path.join(wsDir, 'deploy-helper.md');
|
|
expect(fs.existsSync(newPath)).toBe(true);
|
|
|
|
// Frontmatter updated with scope + promoted_from history
|
|
const parsed = parseSkillFrontmatter(fs.readFileSync(newPath, 'utf-8'));
|
|
expect(parsed.frontmatter.scope).toBe('workspace');
|
|
expect(parsed.frontmatter.promoted_from).toEqual(['personal']);
|
|
|
|
// Signal emitted
|
|
const recorded = signals.getByCategory('skill_promotion');
|
|
expect(recorded.length).toBe(1);
|
|
expect(recorded[0].pattern_key).toBe('promote:deploy-helper:personal->workspace');
|
|
|
|
// onSkillsChanged fired
|
|
expect(reloadCount).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe('validation', () => {
|
|
it('errors when skill is not found', async () => {
|
|
const out = await run(createTools(), 'promote_skill', { skill_name: 'ghost' });
|
|
expect(out).toContain('not found in any accessible scope');
|
|
});
|
|
|
|
it('errors when already at enterprise (top)', async () => {
|
|
const entDir = getSkillDirForScope(tmpDir, 'enterprise', {})!;
|
|
seedSkill(entDir, 'top', 'enterprise');
|
|
const out = await run(createTools(), 'promote_skill', { skill_name: 'top' });
|
|
expect(out).toContain('already at the top scope');
|
|
});
|
|
|
|
it('errors when explicit target_scope is not exactly one rung above', async () => {
|
|
const personalDir = getSkillDirForScope(tmpDir, 'personal', {})!;
|
|
seedSkill(personalDir, 'jumpy', 'personal');
|
|
const out = await run(createTools(), 'promote_skill', {
|
|
skill_name: 'jumpy',
|
|
target_scope: 'team', // skip workspace — disallowed
|
|
});
|
|
expect(out).toContain('not exactly one rung up');
|
|
});
|
|
|
|
it('treats a legacy skill without frontmatter scope as its dir-derived scope', async () => {
|
|
const personalDir = getSkillDirForScope(tmpDir, 'personal', {})!;
|
|
seedSkill(personalDir, 'legacy', null); // no scope field
|
|
const out = await run(createTools(), 'promote_skill', { skill_name: 'legacy' });
|
|
expect(out).toContain('personal → workspace');
|
|
});
|
|
});
|
|
|
|
describe('edition limits', () => {
|
|
it('refuses team promotion and leaves the skill in place', async () => {
|
|
const wsDir = getSkillDirForScope(tmpDir, 'workspace', { workspaceId: 'ws-alpha' })!;
|
|
seedSkill(wsDir, 'shared-helper', 'workspace');
|
|
const out = await run(createTools(), 'promote_skill', { skill_name: 'shared-helper' });
|
|
expect(out).toContain('not available in this edition');
|
|
expect(fs.existsSync(path.join(wsDir, 'shared-helper.md'))).toBe(true);
|
|
expect(signals.getByCategory('skill_promotion')).toHaveLength(0);
|
|
});
|
|
|
|
it('refuses enterprise promotion', async () => {
|
|
const teamDir = getSkillDirForScope(tmpDir, 'team', { teamId: 'team-bravo' })!;
|
|
seedSkill(teamDir, 'hot-skill', 'team');
|
|
const out = await run(createTools(), 'promote_skill', { skill_name: 'hot-skill' });
|
|
expect(out).toContain('Cannot promote to enterprise scope');
|
|
expect(out).toContain('not available in this edition');
|
|
});
|
|
|
|
it('denies workspace promotion when no workspace is active', async () => {
|
|
const personalDir = getSkillDirForScope(tmpDir, 'personal', {})!;
|
|
seedSkill(personalDir, 'orphan', 'personal');
|
|
const tools = createTools({ getWorkspaceId: () => null });
|
|
const out = await run(tools, 'promote_skill', { skill_name: 'orphan' });
|
|
expect(out).toContain('no active workspace');
|
|
});
|
|
});
|
|
|
|
describe('safety', () => {
|
|
it('refuses to overwrite an existing skill at the target scope', async () => {
|
|
const personalDir = getSkillDirForScope(tmpDir, 'personal', {})!;
|
|
const wsDir = getSkillDirForScope(tmpDir, 'workspace', { workspaceId: 'ws-alpha' })!;
|
|
seedSkill(personalDir, 'collision', 'personal');
|
|
seedSkill(wsDir, 'collision', 'workspace'); // already exists at target
|
|
const out = await run(createTools(), 'promote_skill', { skill_name: 'collision' });
|
|
expect(out).toContain('already exists at scope');
|
|
// Source file must NOT have been deleted
|
|
expect(fs.existsSync(path.join(personalDir, 'collision.md'))).toBe(true);
|
|
});
|
|
});
|
|
});
|