Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ app.get('/', (req, res) => {

app.post('/analyze', async (req,res) => {
try {
const {file,framework,options} = req.body;
const {file,framework} = req.body;
let options = req.body.options;

if(!file || !file.content){
return res.status(400).json({error: 'File content is required'})
Expand All @@ -43,6 +44,30 @@ app.post('/analyze', async (req,res) => {
return res.status(413).json({error: 'File content too large (max 1MB)'});
}

// Validate framework parameter
const SUPPORTED_FRAMEWORKS = ['jest', 'vitest', 'mocha'];
if (!framework) {
return res.status(400).json({error: 'Framework parameter is required'});
}
if (!SUPPORTED_FRAMEWORKS.includes(framework)) {
return res.status(400).json({
error: `Invalid framework. Supported frameworks are: ${SUPPORTED_FRAMEWORKS.join(', ')}`
});
}

// Ensure options is a non-null object with safe defaults
// Note: Arrays are excluded since they are typeof 'object' but shouldn't be used for options
if (!options || typeof options !== 'object' || Array.isArray(options)) {
options = {};
}
// Set safe defaults for options properties
if (typeof options.generateEdgeCases !== 'boolean') {
options.generateEdgeCases = false;
}
if (typeof options.includeSetup !== 'boolean') {
options.includeSetup = false;
}

console.log(`🔍 Analyzing ${file.name} with Cline CLI...`);

const testContent = await generateTestWithCline(file,framework,options);
Expand Down