Files
twenty/packages/twenty-server/test/integration/metadata/suites/skill/failing-skill-update.integration-spec.ts
T
Félix Malfait 21ff42074d feat: implement skills system for AI agents (#16865)
## Summary
This PR introduces a Skills system for AI agents, inspired by the [Agent
Skills specification](https://agentskills.io/specification).

## Changes

### Backend
- **SkillEntity**: New database entity with migration for storing skills
- **V2 Sync Mechanism**: Implemented FlatSkill, builders, validators,
and action handlers following the v2 flat entity pattern
- **Standard Skills**: Pre-defined skills (workflow-building,
data-manipulation, dashboard-building, metadata-building, research,
code-interpreter, xlsx, pdf, docx, pptx)
- **GraphQL API**: CRUD operations for skills with proper guards and
permissions
- **Workspace Cache**: Integrated skills into the workspace cache system

### Frontend  
- **Skills Table**: Searchable table in AI settings showing all skills
- **Skill Form**: Create/edit page with Label (primary), Description,
and Content (markdown editor)
- **API Name**: Following existing patterns, name is derived from label
with advanced settings toggle for custom API names
- **Standard vs Custom**: Standard skills are read-only, custom skills
can be edited/deleted

## Key Design Decisions
- Skills are stored in the database (Salesforce-like approach) rather
than files
- Name is derived from Label by default (isLabelSyncedWithName pattern)
- Skills reference functions/files via @ mentions in markdown content
rather than explicit relations
- Standard skills are synced from code, custom skills are created via UI

## Screenshots
Skills table and form UI follow existing settings patterns.

## Testing
- [x] Lint passes
- [x] Typecheck passes
- [ ] CI tests
2026-01-02 14:22:01 +00:00

165 lines
4.2 KiB
TypeScript

import { faker } from '@faker-js/faker';
import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
import { createSkill } from 'test/integration/metadata/suites/skill/utils/create-skill.util';
import { deleteSkill } from 'test/integration/metadata/suites/skill/utils/delete-skill.util';
import { findSkills } from 'test/integration/metadata/suites/skill/utils/find-skills.util';
import { updateSkill } from 'test/integration/metadata/suites/skill/utils/update-skill.util';
import {
eachTestingContextFilter,
type EachTestingContext,
} from 'twenty-shared/testing';
import { type UpdateSkillInput } from 'src/engine/metadata-modules/skill/dtos/update-skill.input';
type TestContext = {
input: (testSetup: TestSetup) => UpdateSkillInput;
};
type TestSetup = {
testSkillId: string;
existingSkillNameForDuplicate: string;
};
type GlobalTestContext = {
existingSkillNameForDuplicate: string;
};
const globalTestContext: GlobalTestContext = {
existingSkillNameForDuplicate: 'existingSkillForDuplicateTest',
};
type UpdateSkillTestingContext = EachTestingContext<TestContext>[];
describe('Skill update should fail', () => {
let testSkillId: string;
let existingSkillIdForDuplicate: string;
beforeAll(async () => {
const { data: duplicateData } = await createSkill({
expectToFail: false,
input: {
name: globalTestContext.existingSkillNameForDuplicate,
label: 'Existing Skill For Duplicate Test',
content: 'Existing skill for duplicate test',
},
});
existingSkillIdForDuplicate = duplicateData.createSkill.id;
});
beforeEach(async () => {
const { data } = await createSkill({
expectToFail: false,
input: {
name: 'testSkillToUpdate',
label: 'Test Skill To Update',
description: 'Original description',
icon: 'IconSparkles',
content: 'Original content',
},
});
testSkillId = data.createSkill.id;
});
afterEach(async () => {
await deleteSkill({
expectToFail: false,
input: { id: testSkillId },
});
});
afterAll(async () => {
await deleteSkill({
expectToFail: false,
input: { id: existingSkillIdForDuplicate },
});
});
const failingSkillUpdateTestCases: UpdateSkillTestingContext = [
{
title: 'when updating with empty label',
context: {
input: (testSetup) => ({
id: testSetup.testSkillId,
label: '',
}),
},
},
{
title: 'when updating with empty content',
context: {
input: (testSetup) => ({
id: testSetup.testSkillId,
content: '',
}),
},
},
];
it.each(eachTestingContextFilter(failingSkillUpdateTestCases))(
'$title',
async ({ context }) => {
const testSetup: TestSetup = {
testSkillId,
existingSkillNameForDuplicate:
globalTestContext.existingSkillNameForDuplicate,
};
const input = context.input(testSetup);
const { errors } = await updateSkill({
expectToFail: true,
input,
});
expectOneNotInternalServerErrorSnapshot({
errors,
});
},
);
it('should fail when updating a non-existent skill', async () => {
const nonExistentSkillId = faker.string.uuid();
const { errors } = await updateSkill({
expectToFail: true,
input: {
id: nonExistentSkillId,
label: 'Updated Label',
},
});
expectOneNotInternalServerErrorSnapshot({
errors,
});
});
it('should fail when attempting to update a standard skill', async () => {
const { data } = await findSkills({
expectToFail: false,
input: undefined,
gqlFields: 'id name isCustom',
});
const standardSkill = data.skills.find((skill) => skill.isCustom === false);
// If there are no standard skills, skip this test
if (!standardSkill) {
return;
}
const { errors } = await updateSkill({
expectToFail: true,
input: {
id: standardSkill.id,
label: 'Attempted Update to Standard Skill',
},
});
expectOneNotInternalServerErrorSnapshot({
errors,
});
});
});