Skip to content

Commit fabdf32

Browse files
committed
Merge branch 'main' into feat_backend_frontend_code_generate
2 parents be118f0 + e614d06 commit fabdf32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2131
-1259
lines changed

backend/src/build-system/__tests__/test-database-schemas.spec.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

backend/src/build-system/__tests__/test-generate-doc.spec.ts

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
/* eslint-disable no-console */
2-
import { BuilderContext } from 'src/build-system/context';
31
import { BuildSequence } from '../types';
4-
import * as fs from 'fs';
5-
import * as path from 'path';
6-
import { writeToFile } from './utils';
2+
import { executeBuildSequence } from './utils';
73

4+
// TODO: adding integration flag
85
describe('Sequence: PRD -> UXSD -> UXDD -> UXSS', () => {
9-
// Generate a unique folder with a timestamp
10-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
11-
const logFolderPath = `./logs/generate-docs-${timestamp}`;
12-
fs.mkdirSync(logFolderPath, { recursive: true });
13-
146
it('should execute the full sequence and log results to individual files', async () => {
157
const sequence: BuildSequence = {
16-
id: 'test-sequence',
8+
id: 'test-backend-sequence',
179
version: '1.0.0',
18-
name: 'Test PRD to UX Sequence',
19-
description: 'Testing PRD to UX sequence execution',
10+
name: 'Spotify-like Music Web',
11+
description: 'Users can play music',
12+
databaseType: 'SQLite',
2013
steps: [
2114
{
2215
id: 'step-1',
@@ -35,7 +28,6 @@ describe('Sequence: PRD -> UXSD -> UXDD -> UXSS', () => {
3528
{
3629
id: 'op:UX:SMD',
3730
name: 'UX Sitemap Document Node',
38-
requires: ['op:PRD'],
3931
},
4032
],
4133
},
@@ -46,7 +38,6 @@ describe('Sequence: PRD -> UXSD -> UXDD -> UXSS', () => {
4638
{
4739
id: 'op:UX:SMS',
4840
name: 'UX Sitemap Structure Node',
49-
requires: ['op:UX:SMD'],
5041
},
5142
],
5243
},
@@ -57,73 +48,38 @@ describe('Sequence: PRD -> UXSD -> UXDD -> UXSS', () => {
5748
{
5849
id: 'op:UX:DATAMAP:DOC',
5950
name: 'UX Data Map Document node',
60-
requires: ['op:UX:SMD'],
6151
},
6252
],
6353
},
6454
{
6555
id: 'step-5',
66-
name: 'file structure generation',
67-
nodes: [
68-
{
69-
id: 'op:FILE:STRUCT',
70-
name: 'file structure generation',
71-
requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],
72-
options: {
73-
projectPart: 'frontend',
74-
},
75-
},
76-
],
77-
},
78-
{
79-
id: 'step-6',
80-
name: 'File_Arch Document',
56+
name: 'UX SMD LEVEL 2 Page Details',
8157
nodes: [
8258
{
83-
id: 'op:FILE:ARCH',
84-
name: 'File_Arch',
85-
requires: [
86-
'op:FILE:STRUCT',
87-
//TODO: here use datamap doc rather than datamap struct, we have to change this
88-
'op:UX:DATAMAP:DOC',
89-
],
59+
id: 'op:UX:SMS:LEVEL2',
60+
name: 'UX SMD LEVEL 2 Page Details Node',
9061
},
9162
],
9263
},
9364
],
9465
};
9566

96-
const context = new BuilderContext(sequence, 'test');
97-
98-
// Set input data for context
99-
context.setGlobalContext('projectName', 'spotify like music web');
100-
context.setGlobalContext('description', 'user can play music');
101-
context.setGlobalContext('platform', 'web');
102-
10367
try {
104-
await context.execute();
105-
106-
for (const step of sequence.steps) {
107-
for (const node of step.nodes) {
108-
const resultData = await context.getNodeData(node.id);
109-
console.log(resultData);
110-
if (resultData) {
111-
writeToFile(logFolderPath, node.id, resultData);
112-
}
113-
}
114-
}
68+
const result = await executeBuildSequence(
69+
'test-generate-all-ux-part',
70+
sequence,
71+
);
11572

11673
console.log(
11774
'Sequence completed successfully. Logs stored in:',
118-
logFolderPath,
75+
result.logFolderPath,
11976
);
77+
78+
if (!result.success) {
79+
throw result.error;
80+
}
12081
} catch (error) {
12182
console.error('Error during sequence execution:', error);
122-
fs.writeFileSync(
123-
path.join(logFolderPath, 'error.txt'),
124-
`Error: ${error.message}\n${error.stack}`,
125-
'utf8',
126-
);
12783
throw error;
12884
}
12985
}, 600000);
Lines changed: 18 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
/* eslint-disable no-console */
2-
import { BuilderContext } from 'src/build-system/context';
31
import { BuildSequence } from '../types';
4-
import * as fs from 'fs';
5-
import * as path from 'path';
6-
import { writeToFile } from './utils';
7-
import { BuildMonitor } from '../monitor';
2+
import { executeBuildSequence, objectToMarkdown, writeToFile } from './utils';
83

9-
describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas -> Frontend_File_struct -> Frontend_File_arch -> BackendCodeGenerator', () => {
10-
// Generate a unique folder with a timestamp
11-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
12-
const logFolderPath = `./logs/Fullstack_code_generator-${timestamp}`;
13-
fs.mkdirSync(logFolderPath, { recursive: true });
14-
15-
it('should execute the frontend and backend code generation sequence and log results to individual files', async () => {
16-
// Define the build sequence up to Backend Code Generator
4+
describe('Build Sequence Test', () => {
5+
it('should execute build sequence successfully', async () => {
176
const sequence: BuildSequence = {
187
id: 'test-backend-sequence',
198
version: '1.0.0',
@@ -28,7 +17,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
2817
nodes: [
2918
{
3019
id: 'op:PROJECT::STATE:SETUP',
31-
name: 'set up project folders',
20+
name: 'Project Folders Setup',
3221
},
3322
],
3423
},
@@ -39,7 +28,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
3928
nodes: [
4029
{
4130
id: 'op:PRD',
42-
name: 'PRD Generation Node',
31+
name: 'Project Requirements Document Node',
4332
},
4433
],
4534
},
@@ -67,7 +56,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
6756
},
6857
{
6958
id: 'op:UX:DATAMAP:DOC',
70-
name: 'UX Data Map Document Node',
59+
name: 'UX DataMap Document Node',
7160
requires: ['op:UX:SMD'],
7261
},
7362
],
@@ -84,12 +73,17 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
8473
},
8574
{
8675
id: 'op:FILE:STRUCT',
87-
name: 'file structure generation',
76+
name: 'File Structure Generation',
8877
requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],
8978
options: {
9079
projectPart: 'frontend',
9180
},
9281
},
82+
{
83+
id: 'op:UX:SMS:LEVEL2',
84+
name: 'Level 2 UX Sitemap Structure Node details',
85+
requires: ['op:UX:SMS'],
86+
},
9387
],
9488
},
9589
{
@@ -104,7 +98,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
10498
},
10599
{
106100
id: 'op:FILE:ARCH',
107-
name: 'File_Arch',
101+
name: 'File Arch',
108102
requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],
109103
},
110104
{
@@ -149,104 +143,10 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
149143
},
150144
],
151145
};
152-
const context = new BuilderContext(sequence, 'test-env');
153-
const monitor = BuildMonitor.getInstance();
154-
155-
try {
156-
console.time('Total Execution Time');
157-
158-
await context.execute();
159-
160-
console.timeEnd('Total Execution Time');
161-
162-
const monitorReport = monitor.generateTextReport(sequence.id);
163-
fs.writeFileSync(
164-
path.join(logFolderPath, 'execution-metrics.txt'),
165-
monitorReport,
166-
'utf8',
167-
);
168-
169-
const sequenceMetrics = monitor.getSequenceMetrics(sequence.id);
170-
if (sequenceMetrics) {
171-
const metricsJson = {
172-
totalDuration: `${sequenceMetrics.duration}ms`,
173-
successRate: `${sequenceMetrics.successRate.toFixed(2)}%`,
174-
totalSteps: sequenceMetrics.totalSteps,
175-
completedSteps: sequenceMetrics.completedSteps,
176-
failedSteps: sequenceMetrics.failedSteps,
177-
totalNodes: sequenceMetrics.totalNodes,
178-
startTime: new Date(sequenceMetrics.startTime).toISOString(),
179-
endTime: new Date(sequenceMetrics.endTime).toISOString(),
180-
};
181-
182-
fs.writeFileSync(
183-
path.join(logFolderPath, 'metrics.json'),
184-
JSON.stringify(metricsJson, null, 2),
185-
'utf8',
186-
);
187-
188-
console.log('\nSequence Metrics:');
189-
console.table(metricsJson);
190-
}
191-
192-
for (const step of sequence.steps) {
193-
const stepMetrics = sequenceMetrics?.stepMetrics.get(step.id);
194-
for (const node of step.nodes) {
195-
const resultData = await context.getNodeData(node.id);
196-
const nodeMetrics = stepMetrics?.nodeMetrics.get(node.id);
197-
if (resultData) {
198-
writeToFile(logFolderPath, `${node.name}`, resultData);
199-
} else {
200-
console.error(
201-
` Error: Handler ${node.name} failed to produce result data`,
202-
);
203-
writeToFile(logFolderPath, `${node.name}-error`, {
204-
error: 'No result data',
205-
metrics: nodeMetrics,
206-
});
207-
}
208-
}
209-
}
210-
211-
const summary = {
212-
timestamp: new Date().toISOString(),
213-
sequenceId: sequence.id,
214-
sequenceName: sequence.name,
215-
totalExecutionTime: `${sequenceMetrics?.duration}ms`,
216-
successRate: `${sequenceMetrics?.successRate.toFixed(2)}%`,
217-
nodesExecuted: sequenceMetrics?.totalNodes,
218-
completedNodes: sequenceMetrics?.stepMetrics.size,
219-
logFolder: logFolderPath,
220-
};
221-
222-
fs.writeFileSync(
223-
path.join(logFolderPath, 'execution-summary.json'),
224-
JSON.stringify(summary, null, 2),
225-
'utf8',
226-
);
227-
} catch (error) {
228-
const errorReport = {
229-
error: {
230-
message: error.message,
231-
stack: error.stack,
232-
},
233-
metrics: monitor.getSequenceMetrics(sequence.id),
234-
timestamp: new Date().toISOString(),
235-
};
236-
237-
fs.writeFileSync(
238-
path.join(logFolderPath, 'error-with-metrics.json'),
239-
JSON.stringify(errorReport, null, 2),
240-
'utf8',
241-
);
242146

243-
console.error('\nError during sequence execution:');
244-
console.error(error);
245-
console.error(
246-
'\nError report saved to:',
247-
path.join(logFolderPath, 'error-with-metrics.json'),
248-
);
249-
throw new Error('Sequence execution failed.');
250-
}
251-
}, 300000); // Timeout set to 10 minutes
147+
const result = await executeBuildSequence('fullstack-code-gen', sequence);
148+
expect(result.success).toBe(true);
149+
expect(result.metrics).toBeDefined();
150+
console.log(`Logs saved to: ${result.logFolderPath}`);
151+
}, 300000);
252152
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { EmbeddingProvider } from 'src/common/embedding-provider';
2+
3+
describe('Model Provider Test', () => {
4+
const embProvider = EmbeddingProvider.getInstance();
5+
it('should generate a response from the model provider', async () => {
6+
const res = await embProvider.generateEmbResponse(
7+
'Your text string goes here',
8+
'text-embedding-3-small',
9+
);
10+
console.log(res);
11+
});
12+
});

0 commit comments

Comments
 (0)