AI Coding Test: Building a GUI Tool Without UI Freezes

    This article tests AI coding tools by building a complete GUI application rather than a simple script: a batch audio extraction tool in Python and tkinter. It explains why responsive UI is the dividing line between demo-grade and usable code, how to write acceptance-ready requirements, and how to decouple the UI thread from worker threads using threading and a queue with periodic polling via after. It also covers per-file error isolation, dependency pre-checks, output naming conflict handling, an eight-item acceptance checklist, and three steps toward maintainable code.

    1. Why “Build a GUI Tool” Is an Excellent Test Case

    When evaluating AI coding tools, many people look at algorithm problems or single-file scripts. What actually separates the strong from the weak is a complete application with a UI. The reason is simple: a CLI script runs as long as the main flow is correct, while a GUI application must satisfy three constraints at once — functional correctness, interaction smoothness, and recoverability from errors. Fail any one of them and users notice immediately.

    Take a “batch audio extraction tool for videos” as an example. It naturally carries the following complexity:

    • Multiple input and output formats: it must cover common video containers and mainstream audio codecs, which involves parameter mapping and compatibility checks;
    • Batch processing and directory structures: it may face hundreds or thousands of files, including nested directories;
    • Long-running tasks: transcoding is a typical CPU/IO-intensive operation, taking anywhere from seconds to minutes;
    • Strong interaction feedback: users need progress, the current item, and success/failure details;
    • Environment dependencies: transcoding usually relies on external command-line components, and a missing dependency should produce actionable guidance instead of a crash.

    The requirement most likely to “go wrong” is a UI that does not freeze. Put a long-running task directly on the main thread and the window becomes unresponsive within seconds, sometimes with a system-level “Not Responding” notice. This is exactly the dividing line between demo-grade code and usable code.

    2. Write Requirements That Are Verifiable, Not Adjective Stacks

    Many developers write prompts using adjectives like “friendly UI, full-featured, runs smoothly.” The problem is that such descriptions cannot be verified, so the model improvises and the result is unpredictable. A more effective approach is to rewrite the requirements as observable, testable items.

    A recommended requirement template has five parts:

    1. Runtime environment and language stack: specify the language, GUI framework, and target operating system;
    2. Input capabilities: which formats are supported, whether directory recursion is supported, whether drag-and-drop is supported;
    3. Output strategy: target format, parameters such as bitrate and sample rate, filename conflict handling;
    4. Interaction and feedback: progress bar, status bar, log area, cancel button;
    5. Robustness requirements: behavior when dependencies are missing, paths are invalid, or a single file fails.

    Example prompt (reusable as-is):

    1. Build a desktop tool in Python + tkinter that batch-converts video and audio files to audio, with these requirements:
    2. 1) Support importing multiple video files and entire directories (recursive);
    3. 2) Output to MP3 / WAV as an option, with configurable sample rate and bitrate;
    4. 3) The conversion must run in a background thread, the UI must not block, and it must be cancellable at any time;
    5. 4) Provide a progress bar, the current filename, success/failure counts, and a log area;
    6. 5) Append a sequence number automatically on output name collisions; check whether the external transcoding component is available at startup;
    7. 6) A single file failure must not affect subsequent tasks, and must produce a readable error reason.

    The key to this prompt is translating “no freezing” into “background thread + cancellable,” and translating “show errors” into “per-file failure isolation + readable reason.” The more verifiable the requirements, the more stable the generated result.

    3. Core Technique: The UI Thread and the Task Thread Must Be Decoupled

    The baseline for a smooth desktop application is that long-running work never occupies the UI thread. A common approach in the Python ecosystem is threading combined with a queue, where the UI thread only runs the event loop and refreshes the display.

    A skeletal example:

    1. import threading, queue, tkinter as tk
    2. q = queue.Queue()
    3. def worker(task_queue):
    4. while True:
    5. item = task_queue.get()
    6. if item is None:
    7. break
    8. # Run the long-running transcoding call here
    9. task_queue.task_done()
    10. def poll_ui():
    11. try:
    12. while True:
    13. msg = q.get_nowait()
    14. # Update the progress bar and status bar
    15. except queue.Empty:
    16. pass
    17. root.after(100, poll_ui)

    There are three key points:

    • Enqueue tasks: when the user clicks start, push the file list into the queue and return from the UI immediately;
    • Report progress back: the worker thread only writes messages to the queue and never touches widgets directly;
    • Poll on a timer: after lets the UI consume messages periodically, avoiding the undefined behavior of operating widgets across threads.

    This structure also explains why “writing the conversion inside the button callback” inevitably freezes: the callback runs on the UI thread, the event loop is occupied for a long time, and the window can neither repaint nor respond.

    4. Handle Exceptions by Isolation, Not by Failing the Whole Batch

    The most common failure in batch tasks: the 7th file fails because its path contains special characters, the entire task aborts, and the results of the first 6 files go unreported. A professional implementation follows the per-task isolation principle:

    1. for f in files:
    2. try:
    3. convert(f)
    4. stats["ok"] += 1
    5. except Exception as e:
    6. stats["fail"] += 1
    7. log(f"[FAIL] {f}: {e}")

    Error messages also need to be actionable:

    • Missing dependency: tell the user to install the external transcoding component or switch to a built-in alternative;
    • Path problem: tell the user to check permissions and filename validity;
    • Unsupported encoding: list the supported formats and guide the user to change the input.

    5. Dependency Pre-Checks and Naming Conflicts: Details Decide Usability

    Two frequent hidden pitfalls deserve separate handling.

    Dependency pre-check: when the external transcoding component is absent, detect it during the startup phase and give clear guidance, rather than waiting until the user clicks start to throw an error. The detection logic usually runs during application initialization, with the result shown in the status bar.

    Naming conflicts: batch output collides easily. A safe strategy is “append an incrementing sequence number and keep the extension,” for example audio_001.mp3, and state the renaming behavior in the log so users do not think files were lost.

    1. def unique_path(out_dir, base, ext):
    2. i = 1
    3. while True:
    4. p = f"{out_dir}/{base}_{i:03d}{ext}"
    5. if not os.path.exists(p):
    6. return p
    7. i += 1

    6. Acceptance Checklist: Turn “Experience” into Checkable Items

    After the code is generated, do not just check whether it runs. Verify it item by item against this checklist:

    • Dependency detection completes at startup, with a clear message when something is missing;
    • Multiple files and recursive directory import are supported, and the list can be added to and removed from;
    • The parameter area can switch output format and sampling parameters;
    • The UI stays responsive after clicking start, and the window can be dragged;
    • The progress bar and status bar update in real time and show the current file;
    • A single file failure does not abort the whole task, and the log is traceable;
    • Colliding output names are numbered automatically, without overwriting existing files;
    • Cancellation is available, and no leftover process remains after cancelling.

    The value of this checklist is that it converts the subjective “good experience” into objective, testable items, and makes regression verification easy in later iterations.

    7. Three Steps from “It Runs” to “It Is Maintainable”

    1. Layering: split transcoding logic, task scheduling, and UI rendering into separate modules so implementations can be swapped;
    2. Configurability: turn formats, parameters, and directories into configuration items instead of hardcoding them;
    3. Observability: keep structured logs that record elapsed time and failure reasons, providing a basis for later optimization.

    For further engineering, you can combine Baidu AI Cloud’s container platform to deploy a headless batch-processing version, use object storage to manage inputs and outputs centrally, and use a logging service with monitoring alerts to track task success rate and latency — forming a “desktop interaction + cloud batch processing” combination.

    8. Conclusion

    This test shows that the most convincing way to evaluate an AI coding tool is not whether it can generate a script, but whether it can deliver verifiable results under multi-constraint, interaction-heavy, error-prone real requirements. For developers, three capabilities are genuinely reusable: rewriting vague requirements into verifiable items, using thread decoupling to hold the line on smoothness, and using isolation-style exception handling to keep batch tasks resilient. Master these three points and, regardless of which AI coding tool you use, you can consistently produce desktop applications that are genuinely usable, not just runnable.