1- /* eslint-disable no-console */
2- import { BuilderContext } from 'src/build-system/context' ;
31import { 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 {
@@ -145,104 +139,10 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
145139 } ,
146140 ] ,
147141 } ;
148- const context = new BuilderContext ( sequence , 'test-env' ) ;
149- const monitor = BuildMonitor . getInstance ( ) ;
150-
151- try {
152- console . time ( 'Total Execution Time' ) ;
153-
154- await context . execute ( ) ;
155-
156- console . timeEnd ( 'Total Execution Time' ) ;
157-
158- const monitorReport = monitor . generateTextReport ( sequence . id ) ;
159- fs . writeFileSync (
160- path . join ( logFolderPath , 'execution-metrics.txt' ) ,
161- monitorReport ,
162- 'utf8' ,
163- ) ;
164-
165- const sequenceMetrics = monitor . getSequenceMetrics ( sequence . id ) ;
166- if ( sequenceMetrics ) {
167- const metricsJson = {
168- totalDuration : `${ sequenceMetrics . duration } ms` ,
169- successRate : `${ sequenceMetrics . successRate . toFixed ( 2 ) } %` ,
170- totalSteps : sequenceMetrics . totalSteps ,
171- completedSteps : sequenceMetrics . completedSteps ,
172- failedSteps : sequenceMetrics . failedSteps ,
173- totalNodes : sequenceMetrics . totalNodes ,
174- startTime : new Date ( sequenceMetrics . startTime ) . toISOString ( ) ,
175- endTime : new Date ( sequenceMetrics . endTime ) . toISOString ( ) ,
176- } ;
177-
178- fs . writeFileSync (
179- path . join ( logFolderPath , 'metrics.json' ) ,
180- JSON . stringify ( metricsJson , null , 2 ) ,
181- 'utf8' ,
182- ) ;
183-
184- console . log ( '\nSequence Metrics:' ) ;
185- console . table ( metricsJson ) ;
186- }
187-
188- for ( const step of sequence . steps ) {
189- const stepMetrics = sequenceMetrics ?. stepMetrics . get ( step . id ) ;
190- for ( const node of step . nodes ) {
191- const resultData = await context . getNodeData ( node . id ) ;
192- const nodeMetrics = stepMetrics ?. nodeMetrics . get ( node . id ) ;
193- if ( resultData ) {
194- writeToFile ( logFolderPath , `${ node . name } ` , resultData ) ;
195- } else {
196- console . error (
197- ` Error: Handler ${ node . name } failed to produce result data` ,
198- ) ;
199- writeToFile ( logFolderPath , `${ node . name } -error` , {
200- error : 'No result data' ,
201- metrics : nodeMetrics ,
202- } ) ;
203- }
204- }
205- }
206-
207- const summary = {
208- timestamp : new Date ( ) . toISOString ( ) ,
209- sequenceId : sequence . id ,
210- sequenceName : sequence . name ,
211- totalExecutionTime : `${ sequenceMetrics ?. duration } ms` ,
212- successRate : `${ sequenceMetrics ?. successRate . toFixed ( 2 ) } %` ,
213- nodesExecuted : sequenceMetrics ?. totalNodes ,
214- completedNodes : sequenceMetrics ?. stepMetrics . size ,
215- logFolder : logFolderPath ,
216- } ;
217-
218- fs . writeFileSync (
219- path . join ( logFolderPath , 'execution-summary.json' ) ,
220- JSON . stringify ( summary , null , 2 ) ,
221- 'utf8' ,
222- ) ;
223- } catch ( error ) {
224- const errorReport = {
225- error : {
226- message : error . message ,
227- stack : error . stack ,
228- } ,
229- metrics : monitor . getSequenceMetrics ( sequence . id ) ,
230- timestamp : new Date ( ) . toISOString ( ) ,
231- } ;
232-
233- fs . writeFileSync (
234- path . join ( logFolderPath , 'error-with-metrics.json' ) ,
235- JSON . stringify ( errorReport , null , 2 ) ,
236- 'utf8' ,
237- ) ;
238142
239- console . error ( '\nError during sequence execution:' ) ;
240- console . error ( error ) ;
241- console . error (
242- '\nError report saved to:' ,
243- path . join ( logFolderPath , 'error-with-metrics.json' ) ,
244- ) ;
245- throw new Error ( 'Sequence execution failed.' ) ;
246- }
247- } , 300000 ) ; // Timeout set to 10 minutes
143+ const result = await executeBuildSequence ( 'fullstack-code-gen' , sequence ) ;
144+ expect ( result . success ) . toBe ( true ) ;
145+ expect ( result . metrics ) . toBeDefined ( ) ;
146+ console . log ( `Logs saved to: ${ result . logFolderPath } ` ) ;
147+ } , 300000 ) ;
248148} ) ;
0 commit comments