Problems: auto-fix & problem panel (#541)

Test cases:
- [x] create-ts-errors
  - [x] with auto-fix
  - [x] without auto-fix 
- [x] create-unfixable-ts-errors
- [x] manually edit file & click recheck
- [x] fix all
- [x] delete and rename case

THINGS
- [x] error handling for checkProblems isn't working as expected
- [x] make sure it works for both default templates (add tests) 
- [x] fix bad animation
- [x] change file context (prompt/files)

IF everything passes in Windows AND defensive try catch... then enable
by default
- [x] enable auto-fix by default
This commit is contained in:
Will Chen
2025-07-02 15:43:26 -07:00
committed by GitHub
parent 52205be9db
commit 678cd3277e
65 changed files with 5068 additions and 189 deletions

View File

@@ -0,0 +1,63 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`problem_prompt > createConciseProblemFixPrompt > should format a concise prompt for multiple errors 1`] = `
"Fix these 2 TypeScript compile-time errors:
1. src/main.ts:5:12 - Cannot find module 'react-dom/client' or its corresponding type declarations. (TS2307)
2. src/components/Modal.tsx:35:20 - Property 'isOpen' does not exist on type 'IntrinsicAttributes & ModalProps'. (TS2339)
Please fix all errors in a concise way."
`;
exports[`problem_prompt > createConciseProblemFixPrompt > should format a concise prompt for single error 1`] = `
"Fix these 1 TypeScript compile-time error:
1. src/App.tsx:10:5 - Cannot find name 'consol'. Did you mean 'console'? (TS2552)
Please fix all errors in a concise way."
`;
exports[`problem_prompt > createConciseProblemFixPrompt > should return a short message when no problems exist 1`] = `"No TypeScript problems detected."`;
exports[`problem_prompt > createProblemFixPrompt > should format a single error correctly 1`] = `
"Fix these 1 TypeScript compile-time error:
1. src/components/Button.tsx:15:23 - Property 'onClick' does not exist on type 'ButtonProps'. (TS2339)
Please fix all errors in a concise way."
`;
exports[`problem_prompt > createProblemFixPrompt > should format multiple errors across multiple files 1`] = `
"Fix these 4 TypeScript compile-time errors:
1. src/components/Button.tsx:15:23 - Property 'onClick' does not exist on type 'ButtonProps'. (TS2339)
2. src/components/Button.tsx:8:12 - Type 'string | undefined' is not assignable to type 'string'. (TS2322)
3. src/hooks/useApi.ts:42:5 - Argument of type 'unknown' is not assignable to parameter of type 'string'. (TS2345)
4. src/utils/helpers.ts:45:8 - Function lacks ending return statement and return type does not include 'undefined'. (TS2366)
Please fix all errors in a concise way."
`;
exports[`problem_prompt > createProblemFixPrompt > should handle realistic React TypeScript errors 1`] = `
"Fix these 4 TypeScript compile-time errors:
1. src/components/UserProfile.tsx:12:35 - Type '{ children: string; }' is missing the following properties from type 'UserProfileProps': user, onEdit (TS2739)
2. src/components/UserProfile.tsx:25:15 - Object is possibly 'null'. (TS2531)
3. src/hooks/useLocalStorage.ts:18:12 - Type 'string | null' is not assignable to type 'T'. (TS2322)
4. src/types/api.ts:45:3 - Duplicate identifier 'UserRole'. (TS2300)
Please fix all errors in a concise way."
`;
exports[`problem_prompt > createProblemFixPrompt > should return a message when no problems exist 1`] = `"No TypeScript problems detected."`;
exports[`problem_prompt > realistic TypeScript error scenarios > should handle common React + TypeScript errors 1`] = `
"Fix these 4 TypeScript compile-time errors:
1. src/components/ProductCard.tsx:22:18 - Property 'price' is missing in type '{ name: string; description: string; }' but required in type 'Product'. (TS2741)
2. src/components/SearchInput.tsx:15:45 - Type '(value: string) => void' is not assignable to type 'ChangeEventHandler<HTMLInputElement>'. (TS2322)
3. src/api/userService.ts:8:1 - Function lacks ending return statement and return type does not include 'undefined'. (TS2366)
4. src/utils/dataProcessor.ts:34:25 - Object is possibly 'undefined'. (TS2532)
Please fix all errors in a concise way."
`;

View File

@@ -0,0 +1,214 @@
import { describe, it, expect } from "vitest";
import { createProblemFixPrompt } from "../shared/problem_prompt";
import type { ProblemReport } from "../ipc/ipc_types";
describe("problem_prompt", () => {
describe("createProblemFixPrompt", () => {
it("should return a message when no problems exist", () => {
const problemReport: ProblemReport = {
problems: [],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
it("should format a single error correctly", () => {
const problemReport: ProblemReport = {
problems: [
{
file: "src/components/Button.tsx",
line: 15,
column: 23,
message: "Property 'onClick' does not exist on type 'ButtonProps'.",
code: 2339,
},
],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
it("should format multiple errors across multiple files", () => {
const problemReport: ProblemReport = {
problems: [
{
file: "src/components/Button.tsx",
line: 15,
column: 23,
message: "Property 'onClick' does not exist on type 'ButtonProps'.",
code: 2339,
},
{
file: "src/components/Button.tsx",
line: 8,
column: 12,
message:
"Type 'string | undefined' is not assignable to type 'string'.",
code: 2322,
},
{
file: "src/hooks/useApi.ts",
line: 42,
column: 5,
message:
"Argument of type 'unknown' is not assignable to parameter of type 'string'.",
code: 2345,
},
{
file: "src/utils/helpers.ts",
line: 45,
column: 8,
message:
"Function lacks ending return statement and return type does not include 'undefined'.",
code: 2366,
},
],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
it("should handle realistic React TypeScript errors", () => {
const problemReport: ProblemReport = {
problems: [
{
file: "src/components/UserProfile.tsx",
line: 12,
column: 35,
message:
"Type '{ children: string; }' is missing the following properties from type 'UserProfileProps': user, onEdit",
code: 2739,
},
{
file: "src/components/UserProfile.tsx",
line: 25,
column: 15,
message: "Object is possibly 'null'.",
code: 2531,
},
{
file: "src/hooks/useLocalStorage.ts",
line: 18,
column: 12,
message: "Type 'string | null' is not assignable to type 'T'.",
code: 2322,
},
{
file: "src/types/api.ts",
line: 45,
column: 3,
message: "Duplicate identifier 'UserRole'.",
code: 2300,
},
],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
});
describe("createConciseProblemFixPrompt", () => {
it("should return a short message when no problems exist", () => {
const problemReport: ProblemReport = {
problems: [],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
it("should format a concise prompt for single error", () => {
const problemReport: ProblemReport = {
problems: [
{
file: "src/App.tsx",
line: 10,
column: 5,
message: "Cannot find name 'consol'. Did you mean 'console'?",
code: 2552,
},
],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
it("should format a concise prompt for multiple errors", () => {
const problemReport: ProblemReport = {
problems: [
{
file: "src/main.ts",
line: 5,
column: 12,
message:
"Cannot find module 'react-dom/client' or its corresponding type declarations.",
code: 2307,
},
{
file: "src/components/Modal.tsx",
line: 35,
column: 20,
message:
"Property 'isOpen' does not exist on type 'IntrinsicAttributes & ModalProps'.",
code: 2339,
},
],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
});
describe("realistic TypeScript error scenarios", () => {
it("should handle common React + TypeScript errors", () => {
const problemReport: ProblemReport = {
problems: [
// Missing interface property
{
file: "src/components/ProductCard.tsx",
line: 22,
column: 18,
message:
"Property 'price' is missing in type '{ name: string; description: string; }' but required in type 'Product'.",
code: 2741,
},
// Incorrect event handler type
{
file: "src/components/SearchInput.tsx",
line: 15,
column: 45,
message:
"Type '(value: string) => void' is not assignable to type 'ChangeEventHandler<HTMLInputElement>'.",
code: 2322,
},
// Async/await without Promise return type
{
file: "src/api/userService.ts",
line: 8,
column: 1,
message:
"Function lacks ending return statement and return type does not include 'undefined'.",
code: 2366,
},
// Strict null check
{
file: "src/utils/dataProcessor.ts",
line: 34,
column: 25,
message: "Object is possibly 'undefined'.",
code: 2532,
},
],
};
const result = createProblemFixPrompt(problemReport);
expect(result).toMatchSnapshot();
});
});
});