Skip to content

Commit f5a4002

Browse files
Copilothotlong
andcommitted
Add comprehensive tests for all enterprise plugin enhancements
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 5d837af commit f5a4002

5 files changed

Lines changed: 1456 additions & 0 deletions

File tree

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
import { describe, expect, it } from 'vitest';
2+
import {
3+
CodeGenerationRequestSchema,
4+
GeneratedCodeSchema,
5+
AICodeReviewResultSchema,
6+
PluginCompositionRequestSchema,
7+
PluginRecommendationRequestSchema,
8+
} from './plugin-development.zod';
9+
10+
describe('AI Plugin Development Schemas', () => {
11+
describe('CodeGenerationRequestSchema', () => {
12+
it('should validate basic code generation request', () => {
13+
const request = {
14+
description: 'Create a plugin to connect to PostgreSQL database',
15+
pluginType: 'driver' as const,
16+
};
17+
const result = CodeGenerationRequestSchema.parse(request);
18+
expect(result.description).toBe('Create a plugin to connect to PostgreSQL database');
19+
expect(result.pluginType).toBe('driver');
20+
expect(result.outputFormat).toBe('source-code');
21+
expect(result.language).toBe('typescript');
22+
});
23+
24+
it('should validate low-code schema generation request', () => {
25+
const request = {
26+
description: 'Create a CRM app with contacts and deals management',
27+
pluginType: 'app' as const,
28+
outputFormat: 'low-code-schema' as const,
29+
schemaOptions: {
30+
format: 'typescript' as const,
31+
includeExamples: true,
32+
strictValidation: true,
33+
generateUI: true,
34+
generateDataModels: true,
35+
},
36+
options: {
37+
generateTests: true,
38+
generateDocs: true,
39+
},
40+
};
41+
const result = CodeGenerationRequestSchema.parse(request);
42+
expect(result.outputFormat).toBe('low-code-schema');
43+
expect(result.schemaOptions?.format).toBe('typescript');
44+
expect(result.schemaOptions?.generateUI).toBe(true);
45+
expect(result.schemaOptions?.generateDataModels).toBe(true);
46+
});
47+
48+
it('should validate DSL generation request', () => {
49+
const request = {
50+
description: 'Create a workflow automation plugin',
51+
pluginType: 'automation' as const,
52+
outputFormat: 'dsl' as const,
53+
capabilities: ['flow-execution', 'trigger-management'],
54+
examples: [
55+
{
56+
input: 'When a new contact is created',
57+
expectedOutput: 'Send welcome email',
58+
description: 'Welcome email automation',
59+
},
60+
],
61+
};
62+
const result = CodeGenerationRequestSchema.parse(request);
63+
expect(result.outputFormat).toBe('dsl');
64+
expect(result.capabilities).toHaveLength(2);
65+
expect(result.examples).toHaveLength(1);
66+
});
67+
68+
it('should validate source code generation with framework preferences', () => {
69+
const request = {
70+
description: 'Create a UI widget for data visualization',
71+
pluginType: 'widget' as const,
72+
outputFormat: 'source-code' as const,
73+
language: 'typescript' as const,
74+
framework: {
75+
runtime: 'browser' as const,
76+
uiFramework: 'react' as const,
77+
testing: 'vitest' as const,
78+
},
79+
style: {
80+
indentation: '2spaces' as const,
81+
quotes: 'single' as const,
82+
semicolons: true,
83+
trailingComma: true,
84+
},
85+
options: {
86+
generateTests: true,
87+
generateDocs: true,
88+
targetCoverage: 90,
89+
optimizationLevel: 'aggressive' as const,
90+
},
91+
};
92+
const result = CodeGenerationRequestSchema.parse(request);
93+
expect(result.framework?.uiFramework).toBe('react');
94+
expect(result.style?.quotes).toBe('single');
95+
expect(result.options?.targetCoverage).toBe(90);
96+
});
97+
});
98+
99+
describe('GeneratedCodeSchema', () => {
100+
it('should validate source code output', () => {
101+
const generated = {
102+
outputFormat: 'source-code' as const,
103+
code: 'export class PostgresDriver implements Driver { ... }',
104+
language: 'typescript',
105+
files: [
106+
{
107+
path: 'src/index.ts',
108+
content: 'export * from "./driver";',
109+
},
110+
{
111+
path: 'src/driver.ts',
112+
content: 'export class PostgresDriver { ... }',
113+
},
114+
],
115+
tests: [
116+
{
117+
path: 'src/driver.test.ts',
118+
content: 'describe("PostgresDriver", () => { ... })',
119+
coverage: 85,
120+
},
121+
],
122+
confidence: 92,
123+
};
124+
const result = GeneratedCodeSchema.parse(generated);
125+
expect(result.outputFormat).toBe('source-code');
126+
expect(result.files).toHaveLength(2);
127+
expect(result.tests).toHaveLength(1);
128+
expect(result.confidence).toBe(92);
129+
});
130+
131+
it('should validate low-code schema output', () => {
132+
const generated = {
133+
outputFormat: 'low-code-schema' as const,
134+
schemas: [
135+
{
136+
type: 'object' as const,
137+
path: 'src/objects/contact.object.ts',
138+
content: 'export const ContactObject = defineObject({ ... })',
139+
description: 'Contact data model',
140+
},
141+
{
142+
type: 'view' as const,
143+
path: 'src/views/contact-list.view.ts',
144+
content: 'export const ContactListView = defineView({ ... })',
145+
description: 'Contact list view',
146+
},
147+
{
148+
type: 'dashboard' as const,
149+
path: 'src/dashboards/crm.dashboard.ts',
150+
content: 'export const CRMDashboard = defineDashboard({ ... })',
151+
description: 'CRM dashboard',
152+
},
153+
],
154+
files: [
155+
{
156+
path: 'package.json',
157+
content: '{ "name": "@acme/crm-plugin", ... }',
158+
},
159+
],
160+
confidence: 88,
161+
suggestions: [
162+
'Consider adding more field validations',
163+
'Add relationship to Deal object',
164+
],
165+
};
166+
const result = GeneratedCodeSchema.parse(generated);
167+
expect(result.outputFormat).toBe('low-code-schema');
168+
expect(result.schemas).toHaveLength(3);
169+
expect(result.schemas?.[0].type).toBe('object');
170+
expect(result.schemas?.[1].type).toBe('view');
171+
expect(result.suggestions).toHaveLength(2);
172+
});
173+
174+
it('should validate DSL output', () => {
175+
const generated = {
176+
outputFormat: 'dsl' as const,
177+
files: [
178+
{
179+
path: 'workflows/welcome-email.flow',
180+
content: 'trigger: contact.created\nactions:\n - send-email\n',
181+
description: 'Welcome email workflow',
182+
},
183+
],
184+
confidence: 90,
185+
};
186+
const result = GeneratedCodeSchema.parse(generated);
187+
expect(result.outputFormat).toBe('dsl');
188+
expect(result.files).toHaveLength(1);
189+
});
190+
});
191+
192+
describe('AICodeReviewResultSchema', () => {
193+
it('should validate code review result', () => {
194+
const review = {
195+
assessment: 'good' as const,
196+
score: 85,
197+
issues: [
198+
{
199+
severity: 'warning' as const,
200+
category: 'performance' as const,
201+
file: 'src/driver.ts',
202+
line: 42,
203+
message: 'Consider using connection pooling',
204+
suggestion: 'Implement pg.Pool instead of creating new connections',
205+
autoFixable: false,
206+
},
207+
{
208+
severity: 'info' as const,
209+
category: 'documentation' as const,
210+
file: 'src/driver.ts',
211+
line: 15,
212+
message: 'Missing JSDoc comment',
213+
autoFixable: true,
214+
autoFix: '/** Query execution method */',
215+
},
216+
],
217+
recommendations: [
218+
{
219+
priority: 'medium' as const,
220+
title: 'Add error handling',
221+
description: 'Implement comprehensive error handling for connection failures',
222+
effort: 'small' as const,
223+
},
224+
],
225+
};
226+
const result = AICodeReviewResultSchema.parse(review);
227+
expect(result.assessment).toBe('good');
228+
expect(result.score).toBe(85);
229+
expect(result.issues).toHaveLength(2);
230+
});
231+
});
232+
233+
describe('PluginCompositionRequestSchema', () => {
234+
it('should validate plugin composition request', () => {
235+
const request = {
236+
goal: 'Create a complete CRM system with email integration',
237+
availablePlugins: [
238+
{
239+
pluginId: 'com.objectstack.crm',
240+
version: '1.0.0',
241+
capabilities: ['contact-management', 'deal-tracking'],
242+
},
243+
{
244+
pluginId: 'com.objectstack.email',
245+
version: '2.0.0',
246+
capabilities: ['send-email', 'email-templates'],
247+
},
248+
],
249+
constraints: {
250+
maxPlugins: 3,
251+
requiredPlugins: ['com.objectstack.crm'],
252+
performance: {
253+
maxLatency: 500,
254+
maxMemory: 536870912, // 512MB
255+
},
256+
},
257+
optimize: 'reliability' as const,
258+
};
259+
const result = PluginCompositionRequestSchema.parse(request);
260+
expect(result.goal).toBeDefined();
261+
expect(result.availablePlugins).toHaveLength(2);
262+
expect(result.constraints?.maxPlugins).toBe(3);
263+
});
264+
});
265+
266+
describe('PluginRecommendationRequestSchema', () => {
267+
it('should validate plugin recommendation request', () => {
268+
const request = {
269+
context: {
270+
installedPlugins: ['com.objectstack.core'],
271+
industry: 'healthcare',
272+
useCases: ['patient-management', 'appointment-scheduling'],
273+
teamSize: 25,
274+
budget: 'medium' as const,
275+
},
276+
criteria: {
277+
prioritize: 'compatibility' as const,
278+
certifiedOnly: true,
279+
minRating: 4.5,
280+
maxResults: 10,
281+
},
282+
};
283+
const result = PluginRecommendationRequestSchema.parse(request);
284+
expect(result.context.industry).toBe('healthcare');
285+
expect(result.criteria?.certifiedOnly).toBe(true);
286+
expect(result.criteria?.minRating).toBe(4.5);
287+
});
288+
});
289+
});

0 commit comments

Comments
 (0)