Designing and Implementing End-to-End Code Generation Evaluation: From Requirement Boundaries to Metric Definitions

    A practical guide to building reproducible end-to-end evaluations for code generation models: how to define evaluation boundaries, design executable acceptance tests, isolate execution environments, and calculate metrics such as pass rate, first-pass success, and repair rounds.

    Why End-to-End Generation Deserves Its Own Evaluation

    Early code model evaluations focused mostly on function-level completion. Evaluators provided a function signature, asked the model to fill in the body, and verified the result with unit tests. This approach is easy to automate, but it differs significantly from real-world development. A growing number of teams are experimenting with describing complete requirements in natural language—for example, “build a backend service that supports registration, login, and order queries”—and letting the model generate a multi-file project directly. These tasks require the model to handle directory structure, dependency relationships, interface contracts, and business rules simultaneously, and completion-only metrics cannot capture these capabilities.

    Evaluating code models in natural-language programming scenarios presents three challenges. First, requirements expressed in natural language are ambiguous, and the same requirement may admit multiple valid implementations. Second, a project consists of multiple files, and a single interface inconsistency can cause overall failure. Third, correctness cannot be judged by string comparison; it must be verified through executable acceptance tests.

    Fixing the Evaluation Target and Boundaries

    Before designing an evaluation, answer three questions:

    • Is the evaluation target the model itself, or the model plus a specific interaction workflow?
    • What inputs are provided, such as requirement documents, interface specifications, or existing code?
    • What counts as success: a successful build, passing all tests, or passing human review?

    It is recommended to fix the evaluation target as “requirement text plus an empty project template, generating a complete project.” This way, differences between models come primarily from generation capability itself rather than assistance from external tools. If models are allowed multiple rounds of repair based on test feedback, record the number of repair rounds as a separate metric—do not mix it with single-shot generation results.

    Designing Tasks and Acceptance Tests

    1. Requirements Must Be Specific

    Requirements should include functional points, input/output formats, edge cases, and technical constraints. Vague requirements measure comprehension ability rather than coding ability. “Implement user management” is too broad to verify, whereas “provide registration and login endpoints, store passwords as hashes, and lock the account for ten minutes after five consecutive failed logins” can be directly translated into test conditions.

    2. Acceptance Tests Must Be Executable

    Each task should come with a set of automated tests. When writing them, check each item:

    • Traceability: every test maps to a specific item in the requirements;
    • Coverage: include happy paths, boundary conditions, and invalid inputs;
    • Interface contracts: only call interfaces and fields explicitly specified in the requirements;
    • Data isolation: regenerate test data before each run and share no state;
    • Implementation neutrality: never assert on internal function names, class structures, or specific algorithms.

    Without the last item, reasonable but different implementations will be incorrectly marked as failures.

    3. Layer by Difficulty

    It makes sense to divide tasks into three tiers:

    1. Single-module utilities, such as format conversion or data validation;
    2. Small applications with a frontend and backend or multiple services;
    3. Incremental requirements that modify an existing codebase while maintaining compatibility.

    With tiers in place, you can see at which level a model’s performance starts to degrade significantly—far more informative than a single overall score.

    Building the Evaluation Pipeline

    A reproducible pipeline typically includes these steps:

    1. Prepare the task set and record a version number for each task;
    2. Invoke the model in an isolated environment, saving complete inputs and outputs;
    3. Write generated files into a temporary working directory and build the project;
    4. Run acceptance tests, recording exit codes and logs;
    5. Destroy the working directory and aggregate metrics.

    The isolated environment should meet the following conditions: dependencies installed from a mirror source with pinned versions; base images referenced by fixed digests; no external network access at runtime; CPU, memory, and per-execution time limits; template directories mounted read-only with only the working directory writable; no shared build caches between tasks; and logs retained until the evaluation completes.

    Here is a simplified evaluation skeleton, including path validation and exception handling:

    1. import os
    2. from dataclasses import dataclass, field
    3. @dataclass
    4. class EvalCase:
    5. case_id: str
    6. requirement: str # Natural language requirement
    7. test_targets: list[str] = field(default_factory=list)
    8. def safe_write(root, rel_path, content):
    9. root_real = os.path.realpath(root)
    10. target = os.path.realpath(os.path.join(root_real, rel_path))
    11. # The resolved real path must remain inside the working directory;
    12. # symlinks are already resolved, so any escape attempt is rejected
    13. if os.path.commonpath([root_real, target]) != root_real:
    14. raise ValueError(f"Path escape: {rel_path}")
    15. os.makedirs(os.path.dirname(target), exist_ok=True)
    16. with open(target, "w", encoding="utf-8") as f:
    17. f.write(content)
    18. def evaluate_case(case, generate_fn, sandbox, timeout_s=600):
    19. ws = sandbox.create_workspace(case.case_id)
    20. try:
    21. files = generate_fn(case.requirement) # Returns {relative path: file content}
    22. for rel_path, content in files.items():
    23. safe_write(ws.root, rel_path, content)
    24. build = ws.run(["build"], timeout=timeout_s)
    25. if build.timed_out or build.exit_code != 0:
    26. return {"case": case.case_id, "built": False,
    27. "pass_rate": 0.0, "log": build.log_tail(200)}
    28. result = ws.run_tests(case.test_targets, timeout=timeout_s)
    29. return {"case": case.case_id, "built": True,
    30. "pass_rate": result.passed / max(result.total, 1),
    31. "log": result.log_tail(200)}
    32. except Exception as e:
    33. return {"case": case.case_id, "built": False,
    34. "pass_rate": 0.0, "error": str(e)}
    35. finally:
    36. sandbox.destroy(ws)

    Replace sandbox and ws with your team’s own integration layer. files comes from model output and must pass path validation before being written. In the path validation, realpath resolves symbolic links, so rejecting symlinks also blocks ../-style path traversal.

    How to Calculate Each Metric

    Metric Definition Cycle and Unit Common Misreading
    Build success rate Successful builds / total tasks Per evaluation run, counted per task A successful build does not mean correct functionality
    Test pass rate Passed test points / total test points Per run, counted per test point; can also report per test case With few test cases, a single case causes large fluctuations
    First-pass rate Tasks passing everything on the first generation / total tasks Per run, counted per task Different from the final pass rate; do not conflate them
    Repair rounds Rounds from first generation to full pass, with the first generation counted as round 0 Report median and P90 for solved tasks; count unsolved tasks separately Unsolved tasks should not be ignored
    Resource cost Input and output tokens, elapsed time, cost Sum tokens per task; report P50 and P90 for time; cost per task Averages hide long-tail latency

    For enterprise users, first-pass rate and cost often matter more than the maximum achievable pass rate. A model that needs five repair rounds may not actually reduce development time compared to one that occasionally errs but repairs quickly.

    Why Results Get Distorted

    Data contamination. If evaluation tasks are public and have been absorbed into training data, scores will be inflated. Rotate tasks periodically and keep a private, non-public task set.

    Prompt sensitivity. The same model can be sensitive to prompt wording, number of examples, and formatting. Fix the prompt template during evaluation and note its version in the report.

    Randomness. With sampling temperature above zero, results vary across runs of the same task. Run each task at least three times and report the mean, sample standard deviation, and min–max range. If the gap between two models is smaller than the variance, do not declare a winner. Record temperature and top_p values at run time.

    Version drift. Providers may update weights or inference parameters without changing the model name. Reports should record the call date, model version identifier, and all inference parameters.

    Unifying Evaluation Standards

    When selecting a model, teams should not rely solely on public leaderboard rankings; they should reproduce evaluations themselves under unified conditions: the same task set, the same prompt template, the same output length limit, the same repair-round limit, and the same test environment.

    Only with consistent definitions are comparisons meaningful. Otherwise, differences may come from prompts, decoding parameters, or repair opportunities rather than the model’s actual capability.

    Troubleshooting Checklist and Implementation Tips

    Start with 20 to 50 internal tasks covering all three difficulty tiers, then expand gradually. Keep evaluation scripts under version control, run automatic regressions after every model or prompt change, and build dashboards keyed by model version, date, and task tier.

    When scores look abnormal, check the following:

    • Task leakage: did the original task or reference answers appear in training corpora?
    • Environment drift: are dependencies pinned? Does the same code build identically at different times?
    • Cache pollution: was the build cache from a previous task reused?
    • Missing records: are model version, prompt version, and inference parameters fully saved?
    • Silent failures: are path escapes or write failures logged rather than ignored?

    If your evaluation relies on cloud-hosted inference services, you can use a container platform to run tasks in parallel, with logging and monitoring services to catch abnormal failures promptly.