Evaluating AI Coding Capabilities: Single-File CRUD Tool Testing and Reproduction Method

    This article outlines a structured method for evaluating AI coding models by generating a single-file HTML CRUD tool. It covers testing scope, technical constraints, prompt engineering, a four-phase evaluation process, an 11-point acceptance checklist, and risk management. The methodology provides a reproducible baseline for assessing an AI model's requirement understanding, code generation, and self-repair capabilities in constrained frontend development tasks.

    1. Testing Scope and Prerequisites

    The test subject is a small local tool: a single HTML file capable of creating, reading, updating, and deleting records, with data persisted in the browser’s localStorage. Although the scope is narrow, it effectively evaluates the model’s capabilities in requirement understanding, UI interaction, input validation, and error handling. It does not involve backends, databases, user authentication, or multi-file engineering; therefore, conclusions apply only to tasks of similar scale.

    Before testing, the following information must be determined and documented in the report:

    • Model name and version: [To be filled: model name, version number, release date]
    • Coding environment: [To be filled: platform name and version, whether code execution or auto-run is enabled]
    • Browser: [To be filled: Chrome version number, e.g., full version of Chrome 130]
    • Operating system: [To be filled: Windows or macOS version number]
    • Test date and duration: [To be filled: start time, end time, total duration in minutes]
    • Cost metrics: [To be filled: input token count, output token count, calculated cost or free tier notes]

    Without recording this information, others cannot determine which version or environment the results originated from, making re-testing impossible.

    2. Technical Constraints and Data Format

    To minimize risks associated with the model taking excessive creative liberty, the following technical boundaries are established:

    • Language and format: Vanilla HTML, CSS, and JavaScript (ES2020 syntax) in a single index.html file, without build tools or third-party libraries.
    • Execution method: Runs by double-clicking the file or opening it in a browser; no dependencies to install, no network connection required.
    • Data format: Each record is an object with fields: id (string), name (string, 1-50 characters), category (string, selected from a dropdown), amount (non-negative number, two decimal places), and date (string in YYYY-MM-DD format).
    • Persistence: All records are saved as a JSON array under the records_v1 key in localStorage.
    • Export: An export button must be provided to download all current records as a JSON file for backup purposes.

    Once these constraints are written into the prompt, the generated code can be explicitly verified. For example, only by defining the field format can we evaluate whether “input validation is complete.”

    3. Prompt Template

    The following prompt is used in formal testing. It remains unchanged across tests, except for replacing the model name:

    1. [Role] You are an engineer proficient in vanilla frontend development.
    2. [Task] Implement a local accounting tool that supports creating, viewing, updating, and deleting records, with support for exporting a JSON backup.
    3. [Technical Constraints]
    4. 1. Output only a complete index.html file containing HTML, CSS, and JavaScript. Do not use any external libraries or network resources.
    5. 2. Data format: {id, name, category, amount, date}, where name is 1-50 characters, category is selected from a dropdown, amount is a non-negative number, and date is in YYYY-MM-DD format.
    6. 3. Save data to localStorage under the key `records_v1`. Data must persist after page refresh.
    7. 4. Validate all form inputs before submission. Display clear error messages for invalid input, and do not write invalid data to storage.
    8. 5. List rendering must not block the UI: when records exceed 500, rendering must be batched or debounced.
    9. 6. The list and total amount must refresh immediately after data changes.
    10. 7. All user data must be escaped before insertion into the page. Directly concatenating unescaped HTML is prohibited.
    11. [Output Requirements] First, list the task breakdown in no more than 10 lines. Then, output the complete code. Finally, list the potential risk points you identify.
    12. [Acceptance] After saving as index.html, the code must run directly in a browser without console errors and satisfy all constraints above.

    Each constraint in the prompt corresponds to an inspection item in the acceptance checklist below. If a constraint cannot be checked, it should be removed or rewritten.

    4. Four-Phase Testing Methodology

    Testing is divided into four phases, each requiring evidence retention. Conclusions without supporting evidence are not included in the report.

    4.1 Requirement Understanding and Task Breakdown

    Record the model’s first response after receiving the prompt. The evaluation criteria are: Does it provide a breakdown first? Does the breakdown cover the data model, UI layout, interaction logic, input validation, and persistence? Are any constraints missing? The evidence is the saved raw response text. If the model outputs code directly, record this as well, as it represents a different working style.

    4.2 Code Generation and Static Check

    Save the model’s output as index.html, then check the syntax of the script section. The following command extracts the script content from the page and passes it to Node.js for checking:

    1. sed -n '/<script>/,/<\/script>/p' index.html | sed '1d;$d' > check.js
    2. node --check check.js && echo "Syntax check passed"

    This command only verifies syntax correctness, not functional correctness. After passing syntax check, functional testing must be done item by item in the browser. If the page contains multiple script blocks, check them separately.

    To provide a benchmark for the “input validation” constraint, a reference implementation is provided below. It is not the model’s output, but illustrates how the check should be approached:

    1. // Reference implementation for validation criteria, not model output
    2. function validateRecord(input) {
    3. const errors = [];
    4. const name = String(input.name ?? '').trim();
    5. if (name === '') errors.push('Name cannot be empty');
    6. if (name.length > 50) errors.push('Name cannot exceed 50 characters');
    7. const rawAmount = String(input.amount ?? '').trim();
    8. const amount = rawAmount === '' ? NaN : Number(rawAmount);
    9. if (!Number.isFinite(amount) || amount < 0) errors.push('Amount must be a non-negative number');
    10. const date = String(input.date ?? '');
    11. if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || Number.isNaN(Date.parse(date))) {
    12. errors.push('Date format should be YYYY-MM-DD');
    13. }
    14. return errors;
    15. }

    During inspection, verify if the model’s code covers the same scenarios: empty values, overly long names, empty amounts, negative numbers, and invalid dates (e.g., 2026-13-45). If it only covers some, it should be marked as “partially passed.”

    4.3 Debugging and Self-Repair

    This phase requires deliberately injecting defects. During testing, paste a string of over 1000 characters into the name input box, then observe two things: whether the page correctly truncates or rejects it, and whether the model mentions this risk in its post-generation self-check.

    Distinguish between two scenarios. The first is the model discovering and fixing the issue without prompting, demonstrating self-auditing capability. The second is the tester pasting the error message back to the model, prompting a fix—this is human-triggered debugging. These two must be recorded separately to avoid overestimating the model’s self-repair ability.

    Evidence includes: the defect injection steps, page behavior, the model’s repair response, and the code diff before and after the fix. Use the following command to generate a diff:

    1. diff -u index_before.html index_after.html > fix.diff

    4.4 Delivery Completeness

    Delivery completeness is verified using a manual testing script. Record the result for each step:

    1. Open the page; there are no red errors in the console.
    2. Add a valid record; the list and total amount update instantly.
    3. Add a record with an empty name; the page displays an error message, and no data is added to records_v1 in localStorage.
    4. Modify a record’s amount; after refreshing the page, the modification persists.
    5. Delete a record; a confirmation dialog appears before deletion, and the total amount updates accordingly.
    6. Export the JSON; open the file and verify its contents match the page.
    7. Input over 500 records; observe if scrolling and input experience noticeable lag, and record the approximate operation time.

    The lag assessment in step 7 requires quantification. It is recommended to use the browser developer tools’ Performance panel to record the time taken for a single list refresh and include the metric in the report, rather than simply stating “no lag.”

    5. Acceptance Checklist

    The table below is used for item-by-item verification after each test. The “Test Result” column is filled by the tester and must not be pre-filled with “Pass”.

    ID Acceptance Item Test Step Pass Criteria Test Result
    A1 Page Load Double-click to open index.html No console errors [To be filled]
    A2 Add Record Enter valid data and submit List and total update instantly [To be filled]
    A3 Empty Name Interception Leave name empty and submit Error message appears, no storage write [To be filled]
    A4 Invalid Amount Interception Enter negative number and empty value Error message appears, no storage write [To be filled]
    A5 Invalid Date Interception Enter 2026-13-45 Error message appears, no storage write [To be filled]
    A6 Excessive Length Input Paste name with 1000+ characters Truncated or rejected, page does not crash [To be filled]
    A7 Persistence Refresh page after adding Data persists [To be filled]
    A8 Deletion and Total Delete one record Total decreases synchronously [To be filled]
    A9 Export Backup Click export and open file JSON content matches page [To be filled]
    A10 Large Data Volume Input 500+ records Single refresh time recorded, no noticeable lag [To be filled: Time (ms)]
    A11 Escaping Enter <img src=x onerror=alert(1)> as name Displayed as plain text, script not executed [To be filled]

    A11 is a security item. AI-generated frontend code often uses innerHTML to directly concatenate user input, leading to Cross-Site Scripting (XSS) vulnerabilities. This test only inputs a harmless tag into the local page and does not involve any external targets.

    6. Result Recording Template

    Each test report should include the following fields for horizontal comparison:

    • Test ID and date: [To be filled]
    • Model and version: [To be filled]
    • Requirement breakdown completeness (list missing items): [To be filled]
    • Syntax check result: [To be filled]
    • Acceptance checklist pass count (e.g., 9/11 passed): [To be filled]
    • Self-repair status (automatic discovery or human-triggered): [To be filled]
    • Total time (minutes) and manual rework count: [To be filled]
    • Cost metrics and amount: [To be filled]
    • Reasons for failed items: [To be filled]

    A human baseline must also be measured. It is recommended to have an experienced developer hand-write the same tool under identical constraints, recording time and rework count. Only with this baseline can we claim the AI-generated approach is “faster” or “easier.” Comparisons without a baseline are merely subjective feelings.

    7. Risks and Manual Review

    AI-generated code must undergo formal code review; it cannot be used directly just because it runs. The primary risks are:

    • Security Risks: Escaping, input validation, and storage methods in frontend code require manual verification. Data in localStorage is plaintext and must not be used to store passwords, tokens, or sensitive personal information.
    • Data Risks: Data exists only in the browser; clearing site data or changing browsers will result in loss. Users should export a backup before use and periodically save the JSON file.
    • Licensing Risks: Generated code may resemble existing code from training data. For commercial projects, review the platform’s Terms of Service and have legal or compliance personnel verify it.
    • Maintenance Risks: One-time generated code lacks test cases; subsequent modifications can easily introduce regressions. If the project will be maintained long-term, automated tests should be added.
    • Privacy Risks: Prompts and test data should not contain real customer information, accounts, or internal addresses. Test cases should use fictitious data.

    Manual review should focus on security boundaries and data integrity. Models excel at implementing localized features but will not determine where data is stored, who can access it, or how to recover from errors. These decisions remain the engineer’s responsibility.

    8. Frequently Asked Questions

    How should AI coding prompts be written?
    First, specify the inputs, outputs, and execution environment clearly. Then, list verifiable constraints, and finally, state the acceptance criteria. The prompt should not include immeasurable requirements like “make it better” or “ensure smooth UX.” If you can write “when the list exceeds 500 items, a single refresh should not exceed 100 milliseconds,” write it that way.

    What should I do if the model-generated code throws an error?
    Save the complete error message and reproduction steps, then provide them to the model along with the original code. Do not just say “it doesn’t work.” If the same error recurs, narrow the requirement scope and generate it step-by-step instead of appending more prompts.

    How do I judge if an AI-generated small tool is usable?
    Look at the pass rate of the acceptance checklist and whether the failed items involve security or data. Missing a button is acceptable, but data loss or escaping vulnerabilities are not. Only when the pass rate reaches over 90% and all security items pass can it proceed to the manual code review phase.

    Why are the results different for the same prompt?
    Model outputs are stochastic, and results may vary across different versions or times. This is why the report must record the model version and test date, and ideally, repeat the test three or more times to observe result stability.

    9. Conclusion Boundaries

    What this methodology can compare: the model’s ability to generate single-file tools under explicit constraints, including requirement breakdown, input validation, escaping, persistence, and self-repair. It cannot demonstrate the model’s performance in multi-file engineering, complex business logic, concurrent access, dependency management, or long-term maintenance. These scenarios require separate test designs.

    The value of testing lies in leaving evidence. A successful demonstration proves the model can complete a specific task, but not that it is reliable in all scenarios. Only by recording the environment, prompt, acceptance results, and failure reasons for each test can we form comparable, re-testable conclusions.