Skip to content

Improved error detection BEN-1078 #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
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
29 changes: 28 additions & 1 deletion app/api/generate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ const benchify = new Benchify({
apiKey: process.env.BENCHIFY_API_KEY,
});

const debug = false;
const buggyCode = [
{
path: "src/App.tsx",
content: `import React from 'react';

const App = () => {
const message = "Hello World; // Missing closing quote
const title = 'Welcome to my app';

return (
<div>
<h1>{title}</h1>
<p>{message}</p>
</div>
);
};

export default App;`
}
];

export async function POST(request: NextRequest) {
try {
const body = await request.json();
Expand All @@ -27,7 +49,12 @@ export async function POST(request: NextRequest) {
const { description } = validationResult.data;

// Generate the Vue app using OpenAI
const generatedFiles = await generateApp(description);
let generatedFiles;
if (debug) {
generatedFiles = buggyCode;
} else {
generatedFiles = await generateApp(description);
}

// Repair the generated code using Benchify's API
// const { data } = await benchify.fixer.run({
Expand Down
4 changes: 2 additions & 2 deletions components/ui-builder/preview-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export function PreviewCard({
</div>
<div className="flex-1 min-w-0">
<p className={`text-sm font-medium ${isCompleted ? 'text-green-700 dark:text-green-400' :
isCurrent ? 'text-primary' :
'text-muted-foreground'
isCurrent ? 'text-primary' :
'text-muted-foreground'
}`}>
{step.label}
</p>
Expand Down
123 changes: 41 additions & 82 deletions lib/e2b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { benchifyFileSchema } from './schemas';
import { z } from 'zod';
import { fetchAllSandboxFiles } from './file-filter';
import { applyTransformations } from './sandbox-helpers';
import { detectCodeErrors, parseTypeScriptErrors } from './error-detection';

const E2B_API_KEY = process.env.E2B_API_KEY;

Expand Down Expand Up @@ -59,8 +60,11 @@ export async function createSandbox({ files }: { files: z.infer<typeof benchifyF
console.log('New packages installed successfully:', result.stdout);
if (result.stderr) {
console.warn('npm install warnings:', result.stderr);
// Parse npm install errors
if (result.stderr.includes('npm ERR!')) {
// Only treat critical npm errors as build errors (not warnings or peer dep issues)
if (result.stderr.includes('npm ERR!') &&
(result.stderr.includes('ENOTFOUND') ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ File Writing Verification

Verify that transformed files are written to the sandbox's working directory at the specified paths.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[[[{"path":"DL3o5K~z4"... view full input 200 100.0%

view all inputs
The property-based test has passed, which means that the createSandbox function successfully wrote the transformed files to the sandbox's working directory with the correct paths. The test checked that the files were written with the prefix /app/ and that the contents were correctly transformed. The test used an array of files with different paths and contents, and the createSandbox function correctly handled these files and wrote them to the sandbox.

Unit Tests
// Unit Test for "File Writing Verification": Verify that transformed files are written to the sandbox's working directory at the specified paths.
function benchify_s(s) {
    return s.replace(/[^a-zA-Z0-9]/g, 'a');
}

it('benchify_s_exec_test_passing_0', () => {
  const args = superjson.parse(
    '{"json":[[[{"path":"DL3o5K~z4","content":"aaka"},{"path":"+fu:;Yi","content":"taaa4Lraaa3"},{"path":".N? HmM>","content":"jaatya"},{"path":",JdLIOS","content":"maamaa"}]]]}',
  );

  benchify_s(...args);
});

result.stderr.includes('ECONNREFUSED') ||
result.stderr.includes('permission denied'))) {
buildErrors.push({
type: 'build',
message: 'Package installation failed: ' + result.stderr.split('npm ERR!')[1]?.trim()
Expand All @@ -79,39 +83,47 @@ export async function createSandbox({ files }: { files: z.infer<typeof benchifyF
}
}

// Run TypeScript check to catch type errors
// Start the dev server and check logs for errors (let Vite handle error detection)
try {
console.log('Running TypeScript check...');
const tscResult = await sandbox.commands.run('cd /app && npx tsc --noEmit --skipLibCheck');

if (tscResult.exitCode !== 0 && tscResult.stderr) {
console.log('TypeScript errors found:', tscResult.stderr);
const tsErrors = parseTypeScriptErrors(tscResult.stderr);
buildErrors.push(...tsErrors);
console.log('Starting dev server...');
// Start dev server in background
const devServerResult = await sandbox.commands.run('cd /app && npm run dev', { background: true });

console.log('Dev server command executed');
console.log('Dev server exit code:', devServerResult.exitCode);
console.log('Dev server stderr:', devServerResult.stderr || 'No stderr');
console.log('Dev server stdout:', devServerResult.stdout || 'No stdout');

// Give it a moment to start and potentially fail
console.log('Waiting 3 seconds for dev server to start...');
await new Promise(resolve => setTimeout(resolve, 3000));

// Check the initial output for immediate errors
if (devServerResult.stderr || devServerResult.stdout) {
const allOutput = (devServerResult.stderr || '') + '\n' + (devServerResult.stdout || '');

// Use the error detection module
const errorResult = detectCodeErrors(allOutput);

if (errorResult.hasErrors) {
console.log('🔴 CODE ERRORS DETECTED!');
buildErrors.push(...errorResult.errors);
} else if (errorResult.isInfrastructureOnly) {
console.log('⚠️ Only infrastructure errors detected (ignoring)');
} else {
console.log('✅ No errors detected');
}
} else {
console.log('⚠️ No stderr or stdout from dev server command');
}
} catch (error) {
console.error('TypeScript check failed:', error);
buildErrors.push({
type: 'typescript',
message: `TypeScript check failed: ${error instanceof Error ? error.message : String(error)}`
});
}

// Try to build the project to catch build-time errors
try {
console.log('Running build check...');
const buildResult = await sandbox.commands.run('cd /app && npm run build');

if (buildResult.exitCode !== 0) {
console.log('Build errors found:', buildResult.stderr);
const viteErrors = parseViteBuildErrors(buildResult.stderr);
buildErrors.push(...viteErrors);
}
console.log('Dev server started, output checked');
console.log('Total build errors found:', buildErrors.length);
} catch (error) {
console.error('Build check failed:', error);
console.error('Dev server check failed:', error);
buildErrors.push({
type: 'build',
message: `Build failed: ${error instanceof Error ? error.message : String(error)}`
message: `Dev server failed to start: ${error instanceof Error ? error.message : String(error)}`
});
}

Expand All @@ -130,60 +142,7 @@ export async function createSandbox({ files }: { files: z.infer<typeof benchifyF
};
}

function parseTypeScriptErrors(stderr: string): BuildError[] {
const errors: BuildError[] = [];
const lines = stderr.split('\n');

for (const line of lines) {
// Match TypeScript error pattern: file(line,column): error TS####: message
const match = line.match(/(.+)\((\d+),(\d+)\): error TS\d+: (.+)/);
if (match) {
const [, file, line, column, message] = match;
errors.push({
type: 'typescript',
message: message.trim(),
file: file.replace('/app/', ''),
line: parseInt(line),
column: parseInt(column)
});
}
}

// If no specific errors found but stderr has content, add generic error
if (errors.length === 0 && stderr.trim()) {
errors.push({
type: 'typescript',
message: 'TypeScript compilation failed: ' + stderr.trim()
});
}

return errors;
}

function parseViteBuildErrors(stderr: string): BuildError[] {
const errors: BuildError[] = [];
const lines = stderr.split('\n');

for (const line of lines) {
// Match Vite build error patterns
if (line.includes('error') || line.includes('Error')) {
errors.push({
type: 'build',
message: line.trim()
});
}
}

// If no specific errors found but stderr has content, add generic error
if (errors.length === 0 && stderr.trim()) {
errors.push({
type: 'build',
message: 'Build failed: ' + stderr.trim()
});
}

return errors;
}

function extractNewPackages(packageJsonContent: string): string[] {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Handles Invalid JSON Gracefully

The function should catch JSON parsing errors and return an empty array if the packageJsonContent is not valid JSON.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[["TmaaN"]]}')... view full input 200 100.0%

view all inputs
The test has passed. The function extractNewPackages successfully handled the input string "{\"json\":[[\"TmaaN\"]]}" by catching the JSON parsing error and returning an empty array as expected. This demonstrates that the function is correctly implemented to return an empty array when the input is not a valid package.json structure.

Unit Tests
// Unit Test for "Handles Invalid JSON Gracefully": The function should catch JSON parsing errors and return an empty array if the `packageJsonContent` is not valid JSON.
function benchify_s(s) {
    return s.replace(/[^a-zA-Z0-9]/g, 'a');
}

it('benchify_s_exec_test_passing_0', () => {
  const args = superjson.parse('{"json":[["TmaaN"]]}');

  benchify_s(...args);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Excludes Base Packages

The function should exclude any package that is part of basePackages from its output.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[["{\"dependencies\":{... view full input 200 100.0%

view all inputs
The property-based test has passed, indicating that the extractNewPackages function successfully excluded base packages from its output. The test input was a package JSON content with various dependencies, and the function correctly identified and returned only the non-base packages. The function's behavior aligns with the expected property description, which states that it should exclude any package that is part of basePackages from its output.

Unit Tests
// Unit Test for "Excludes Base Packages": The function should exclude any package that is part of `basePackages` from its output.
function benchify_dependencies(dependencies) {
    return JSON.stringify({ dependencies });
}

it('benchify_dependencies_exec_test_passing_0', () => {
  const args = superjson.parse(
    '{"json":[["{\\"dependencies\\":{\\"[_1uJT(/+\\":\\"p\\",\\"]LS\\":\\"!}z\\\\\\\\#&\\",\\"i5Jiu\\":\\"SFzp\\",\\"x0\\":\\"-~#VBB\\\\\\"&!&\\",\\"H_-K@\\\\\\"2ru\\":\\"callertoSt\\",\\"J]gHO&Qs>\\":\\"ref\\"}}"]]}',
  );

  benchify_dependencies(...args);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Output Matches pkg@version Format

Each element in the returned array should be formatted as pkg@version.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[[{"#2]|s;48C":"a2z",... view full input 1121 94.8%
superjson.parse('{"json":[[{},{"basePackages":[... view full input 61 5.2%

view all inputs
Here is a summary of the analysis:

The test failed due to an AssertionError. The extractNewPackages function returned an array with unexpected elements. Specifically, the function returned an array containing elements in the format of pkg@version, but with unexpected package names, such as #2]|s;48C@a2z, =O[@0+rCDzi', and HKZw|t\"?L@"k(YM$n\Ad, instead of the expected [3#V<@tm]`. This suggests that the function is not correctly filtering out base packages from the dependency list.

Stack Trace
Error: expect(received).toEqual(expected)

  [
+   "#2]|s;48C@a2z",
+   "=O[@0+rCDzi'",
+   "HKZw|t\"?L`@\"k(YM$n\\Ad",
    "3#V<@Tm"
  ]

- Expected  - 0
+ Received  + 3

    at toEqual (unknown)
    at <anonymous> (/app/repo/lib/pver_78b8a9ce-9877-44b3-818e-1e77a420e42b.test.ts:78:24)
    at <anonymous> (/app/configuration/fc.setup.ts:183:11)
    at run (/app/node_modules/fast-check/lib/esm/check/property/Property.generic.js:46:33)
    at runIt (/app/node_modules/fast-check/lib/esm/check/runner/Runner.js:18:30)
    at check (/app/node_modules/fast-check/lib/esm/check/runner/Runner.js:62:11)
    at <anonymous> (/app/configuration/fc.setup.ts:197:14)
    at assertWithLogging (/app/configuration/fc.setup.ts:125:3)
    at <anonymous> (/app/repo/lib/pver_78b8a9ce-9877-44b3-818e-1e77a420e42b.test.ts:38:6)
Unit Tests
// Unit Test for "Output Matches pkg@version Format": Each element in the returned array should be formatted as `pkg@version`.
function benchify_packages(packages, additional) {
    const completePackages = { ...packages };
    additional.basePackages.forEach(basePkg => {
        completePackages[basePkg] = '1.0.0'; // Dummy version for base packages
    });
    completePackages[additional.newPackageName] = additional.newPackageVersion;
    const packageJsonContent = JSON.stringify({ dependencies: completePackages });
    const result = extractNewPackages(packageJsonContent);
    const expectedOutput = [`${additional.newPackageName}@${additional.newPackageVersion}`];
    expect(result).toEqual(expectedOutput);
}

it('benchify_packages_exec_test_failing_0', () => {
  const args = superjson.parse(
    '{"json":[[{"#2]|s;48C":"a2z","=O[":"0+rCDzi\'","HKZw|t\\"?L`":"\\"k(YM$n\\\\Ad"},{"basePackages":["vite","tailwindcss","tailwindcss","tailwindcss","react-dom","@vitejs/plugin-react"],"newPackageName":"3#V<","newPackageVersion":"Tm"}]]}',
  );

  benchify_packages(...args);
});

try {
Expand Down
149 changes: 149 additions & 0 deletions lib/error-detection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
interface BuildError {
type: 'typescript' | 'build' | 'runtime';
message: string;
file?: string;
line?: number;
column?: number;
}

export interface ErrorDetectionResult {
hasErrors: boolean;
errors: BuildError[];
isInfrastructureOnly: boolean;
}

/**
* Detects if output contains code-related errors (not infrastructure issues)
*/
export function detectCodeErrors(output: string): ErrorDetectionResult {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Detects Infrastructure Issues

The function should detect and correctly identify infrastructure-related issues, ensuring they do not get falsely categorized as code-related errors.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[["7z"]]}')... view full input 200 100.0%

view all inputs
The property-based test has passed. The test successfully validated that the detectCodeErrors function correctly identifies infrastructure-related issues and does not falsely categorize them as code-related errors. In this case, the input string "{\"json\":[[\"7z\"]]}" was used to generate an output that included the infrastructure error pattern 'EACCES: permission denied', and the function correctly classified it as infrastructure-only with no code errors.

Unit Tests
// Unit Test for "Detects Infrastructure Issues": The function should detect and correctly identify infrastructure-related issues, ensuring they do not get falsely categorized as code-related errors.
function benchify_s(s) {
    return s.replace(/[^a-zA-Z0-9]/g, 'a');
}

it('benchify_s_exec_test_passing_0', () => {
  const args = superjson.parse('{"json":[["7z"]]}');

  benchify_s(...args);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Identifies Code-Related Errors

The function should correctly identify and return code-related errors based on specific keywords in the output string.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[["azBaLF"]]}')... view full input 200 100.0%

view all inputs
The test has passed, indicating that the detectCodeErrors function correctly identified and handled both code-related errors and infrastructure-related errors. The test provided an input string that triggered both code errors and infrastructure errors, and the function correctly returned hasErrors as true for the code errors and false for the infrastructure errors. The function successfully distinguished between the two types of errors.

Unit Tests
// Unit Test for "Identifies Code-Related Errors": The function should correctly identify and return code-related errors based on specific keywords in the output string.
function benchify_s(s) {
    return s.replace(/[^a-zA-Z0-9]/g, 'a');
}

it('benchify_s_exec_test_passing_0', () => {
  const args = superjson.parse('{"json":[["azBaLF"]]}');

  benchify_s(...args);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Returns Structured Error Detection Result

The function should return a structured result indicating whether code errors are detected, and if only infrastructure issues are present, this should be flagged.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[[{"output":"Cannot re... view full input 95 23.8%
superjson.parse('{"json":[[{"output":"","expect... view full input 305 76.3%

view all inputs
Here is a summary of the test results:

The test failed due to an AssertionError. The function detectCodeErrors did not return the expected result when the input output contained both a code error ("Cannot resolve import") and an infrastructure error ("EACCES: permission denied"). The function should have returned hasErrors: true and isInfrastructureOnly: false, but instead returned hasErrors: false. This indicates that the function does not correctly handle mixed error scenarios.

Stack Trace
Error: expect(received).toBe(expected)

Expected: true
Received: false

    at toBe (unknown)
    at <anonymous> (/app/repo/lib/pver_346fef25-2a2e-4daa-b5a2-e421ce39beae.test.ts:79:36)
    at <anonymous> (/app/configuration/fc.setup.ts:183:11)
    at run (/app/node_modules/fast-check/lib/esm/check/property/Property.generic.js:46:33)
    at runIt (/app/node_modules/fast-check/lib/esm/check/runner/Runner.js:18:30)
    at check (/app/node_modules/fast-check/lib/esm/check/runner/Runner.js:62:11)
    at <anonymous> (/app/configuration/fc.setup.ts:197:14)
    at assertWithLogging (/app/configuration/fc.setup.ts:125:3)
    at <anonymous> (/app/repo/lib/pver_346fef25-2a2e-4daa-b5a2-e421ce39beae.test.ts:38:6)
Unit Tests
// Unit Test for "Returns Structured Error Detection Result": The function should return a structured result indicating whether code errors are detected, and if only infrastructure issues are present, this should be flagged.
function benchify_codeError(codeError) {
    return fc.constantFrom('EACCES: permission denied', 'failed to load config from /app/vite.config.ts', 'error when starting dev server', '/app/node_modules/.vite-temp/')
        .chain(infraError => fc.tuple(fc.boolean(), fc.boolean()).map(([includeCode, includeInfra]) => ({
        output: `${includeCode ? codeError : ''} ${includeInfra ? infraError : ''}`.trim(),
        expectCodeError: includeCode && !includeInfra,
        expectInfraError: includeInfra && !includeCode,
        expectMixedError: includeCode && includeInfra
    })));
}

it('benchify_codeError_exec_test_failing_0', () => {
  const args = superjson.parse(
    '{"json":[[{"output":"Cannot resolve import EACCES: permission denied","expectCodeError":false,"expectInfraError":false,"expectMixedError":true}]]}',
  );

  benchify_codeError(...args);
});

console.log('=== CHECKING OUTPUT FOR CODE ERRORS ===');
console.log('Output length:', output.length);
console.log('Full output:', output);

// Check for actual code errors that users care about
const hasSyntaxError = output.includes('SyntaxError');
const hasUnexpectedToken = output.includes('Unexpected token');
const hasParseError = output.includes('Parse error');
const hasUnterminatedString = output.includes('Unterminated string');
const hasModuleError = output.includes('Cannot resolve module') || output.includes('Module not found');
const hasImportError = output.includes('Cannot resolve import');

// Check for infrastructure errors that should be ignored
const isInfrastructureError = output.includes('EACCES: permission denied') ||
output.includes('failed to load config from /app/vite.config.ts') ||
output.includes('error when starting dev server') ||
output.includes('/app/node_modules/.vite-temp/');

console.log('Error pattern checks (focusing on code errors):');
console.log('- Has "SyntaxError":', hasSyntaxError);
console.log('- Has "Unexpected token":', hasUnexpectedToken);
console.log('- Has "Parse error":', hasParseError);
console.log('- Has "Unterminated string":', hasUnterminatedString);
console.log('- Has module/import errors:', hasModuleError || hasImportError);
console.log('- Is infrastructure error (ignoring):', isInfrastructureError);

const hasCodeErrors = hasSyntaxError || hasUnexpectedToken || hasParseError ||
hasUnterminatedString || hasModuleError || hasImportError;

// Only report actual code errors, not infrastructure issues
if (hasCodeErrors && !isInfrastructureError) {
console.log('🔴 CODE ERRORS DETECTED! Parsing...');
const errors = parseErrorsFromOutput(output);
console.log('Parsed errors:', errors);

return {
hasErrors: true,
errors,
isInfrastructureOnly: false
};
} else if (isInfrastructureError && !hasCodeErrors) {
console.log('⚠️ Only infrastructure errors detected (ignoring)');
return {
hasErrors: false,
errors: [],
isInfrastructureOnly: true
};
} else {
console.log('✅ No code errors detected');
return {
hasErrors: false,
errors: [],
isInfrastructureOnly: false
};
}
}

/**
* Parses TypeScript compilation errors
*/
export function parseTypeScriptErrors(stderr: string): BuildError[] {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Proper Handling of Input Splitting and Iteration

The function should split the input stderr string by new lines and correctly iterate through each line to check for valid TypeScript error patterns.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[[["example.ts(10,15):... view full input 135 33.8%
superjson.parse('{"json":[[["main.ts(20,5): err... view full input 265 66.3%

view all inputs
The test has failed due to a TypeError. The error occurs when trying to access the result of /d+/.exec(line)[0], which is null. This suggests that the regular expression /d+/.exec(line) is not matching the expected pattern in the input string, causing the exec method to return null. This is happening when processing the input ["{\"json\":[[[\"main.ts(20,5): error TS2304: Cannot find name\",\"xFeU\",\"05\"]]]}"], specifically when trying to extract the error code from the line "main.ts(20,5): error TS2304: Cannot find name".

Stack Trace
TypeError: null is not an object (evaluating '/d+/.exec(line)[0]')
    at <anonymous> (/app/repo/lib/pver_8ab72219-6782-4fda-8229-96aedc28e4f6.test.ts:66:48)
    at <anonymous> (/app/configuration/fc.setup.ts:183:11)
    at run (/app/node_modules/fast-check/lib/esm/check/property/Property.generic.js:46:33)
    at runIt (/app/node_modules/fast-check/lib/esm/check/runner/Runner.js:18:30)
    at check (/app/node_modules/fast-check/lib/esm/check/runner/Runner.js:62:11)
    at <anonymous> (/app/configuration/fc.setup.ts:197:14)
    at assertWithLogging (/app/configuration/fc.setup.ts:125:3)
    at <anonymous> (/app/repo/lib/pver_8ab72219-6782-4fda-8229-96aedc28e4f6.test.ts:38:6)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Filtering of Non-critical Errors

Filter out lines containing 'deprecated', 'unused', or 'implicit any', treating them as non-critical errors and not including them in the output array.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[[5,"cZ"]]}')... view full input 200 100.0%

view all inputs
The test has passed successfully. The property-based test verified that the parseTypeScriptErrors function correctly filters out lines containing 'deprecated', 'unused', or 'implicit any' and does not include them in the output array. The test generated 5 error lines with random messages, and the function correctly handled these errors, producing an output that meets the expected criteria.

Unit Tests
// Unit Test for "Filtering of Non-critical Errors": Filter out lines containing 'deprecated', 'unused', or 'implicit any', treating them as non-critical errors and not including them in the output array.
function benchify_lineCount(lineCount, message) {
    const lines = Array.from({ length: lineCount }, () => {
        const file = "someFile.ts";
        const line = `${Math.floor(Math.random() * 100)}`;
        const column = `${Math.floor(Math.random() * 100)}`;
        const tsErrorNumber = `TS${Math.floor(1000 + Math.random() * 9000)}`;
        return `${file}(${line},${column}): error ${tsErrorNumber}: ${message}`;
    });
    const criticalMessageLines = lines.map(line => line.includes('deprecated') || line.includes('unused') || line.includes('implicit any') ? line.replace(/deprecated|unused|implicit any/, '') : line).join('\\n');
    const errors = parseTypeScriptErrors(criticalMessageLines);
    expect(errors.every(error => !error.message.includes('deprecated') && !error.message.includes('unused') && !error.message.includes('implicit any'))).toBe(true);
}

it('benchify_lineCount_exec_test_passing_0', () => {
  const args = superjson.parse('{"json":[[5,"cZ"]]}');

  benchify_lineCount(...args);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Correct Construction of BuildError Objects

Each valid matched error should result in a correctly formed BuildError object, which includes the trimmed error message, file path (with '/app/' prefix removed), line and column as integers, and type set to 'typescript'.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[[["aaJaU"]]]}')... view full input 200 100.0%

view all inputs
The test has passed. The parseTypeScriptErrors function correctly parsed a TypeScript error string and returned a BuildError object with the expected properties (trimmed error message, file path with '/app/' prefix removed, line and column as integers, and type set to 'typescript'). The test provided a valid input error string that was successfully matched and processed by the function.

Unit Tests
// Unit Test for "Correct Construction of BuildError Objects": Each valid matched error should result in a correctly formed BuildError object, which includes the trimmed error message, file path (with '/app/' prefix removed), line and column as integers, and type set to 'typescript'.
function benchify_s(s) {
    return s.replace(/[^a-zA-Z0-9]/g, 'a');
}

it('benchify_s_exec_test_passing_0', () => {
  const args = superjson.parse('{"json":[[["aaJaU"]]]}');

  benchify_s(...args);
});

const errors: BuildError[] = [];
const lines = stderr.split('\n');

for (const line of lines) {
// Match TypeScript error pattern: file(line,column): error TS####: message
const match = line.match(/(.+)\((\d+),(\d+)\): error TS\d+: (.+)/);
if (match) {
const [, file, line, column, message] = match;
// Filter out common non-critical errors that might be false positives
const lowerMessage = message.toLowerCase();
if (!lowerMessage.includes('deprecated') &&
!lowerMessage.includes('unused') &&
!lowerMessage.includes('implicit any')) {
errors.push({
type: 'typescript',
message: message.trim(),
file: file.replace('/app/', ''),
line: parseInt(line),
column: parseInt(column)
});
}
}
}

return errors;
}

/**
* Parses errors from build/dev server output
*/
function parseErrorsFromOutput(output: string): BuildError[] {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Correctly Parse and Return Genuine Code Errors

The parseErrorsFromOutput function should identify and return an array of BuildError objects representing genuine code-related errors from the given output string while excluding infrastructure-related issues. If no genuine code-related errors are found, the function should return an empty array.

Outcome Example Input # Inputs % of Total
superjson.parse('{"json":[["seO"]]}')... view full input 200 100.0%

view all inputs
The test has passed successfully. The parseErrorsFromOutput function correctly identified and returned an empty array of BuildError objects, as there were no genuine code-related errors in the input string. The input string was "{\"json\":[[\"seO\"]]}" which did not contain any syntax errors or other code-related issues.

Unit Tests
// Unit Test for "Correctly Parse and Return Genuine Code Errors": The parseErrorsFromOutput function should identify and return an array of BuildError objects representing genuine code-related errors from the given output string while excluding infrastructure-related issues. If no genuine code-related errors are found, the function should return an empty array.
function benchify_s(s) {
    return s.replace(/[^a-zA-Z0-9]/g, 'a');
}

it('benchify_s_exec_test_passing_0', () => {
  const args = superjson.parse('{"json":[["seO"]]}');

  benchify_s(...args);
});

console.log('🔍 parseErrorsFromOutput called with input length:', output.length);
const errors: BuildError[] = [];
const lines = output.split('\n');
console.log('Total lines to process:', lines.length);

for (let i = 0; i < lines.length; i++) {
const line = lines[i];
console.log(`Line ${i + 1}: "${line}"`);

// Only match actual code errors, not infrastructure issues
const hasCodeError = line.includes('SyntaxError') ||
line.includes('Unexpected token') ||
line.includes('Parse error') ||
line.includes('Unterminated string') ||
line.includes('Cannot resolve module') ||
line.includes('Module not found') ||
line.includes('Cannot resolve import');

// Skip infrastructure errors
const isInfrastructureError = line.includes('EACCES: permission denied') ||
line.includes('failed to load config') ||
line.includes('error when starting dev server') ||
line.includes('/app/node_modules/.vite-temp/');

console.log(` - Has code error: ${hasCodeError}`);
console.log(` - Is infrastructure error (skip): ${isInfrastructureError}`);

if (hasCodeError && !isInfrastructureError) {
console.log(` ✅ FOUND ERROR: "${line}"`);
errors.push({
type: 'build',
message: line.trim()
});
}
}

console.log(`🎯 parseErrorsFromOutput found ${errors.length} errors:`, errors);
return errors;
}