Skip to content

Comments

Refactor (gradio part1) events wiring contracts#652

Merged
ChuxiJ merged 1 commit intoace-step:mainfrom
1larity:sync/pr1-wiring-context-20260220
Feb 20, 2026
Merged

Refactor (gradio part1) events wiring contracts#652
ChuxiJ merged 1 commit intoace-step:mainfrom
1larity:sync/pr1-wiring-context-20260220

Conversation

@1larity
Copy link
Contributor

@1larity 1larity commented Feb 20, 2026

Summary

  • Functional decomposition of Gradio event wiring.
  • Extracts repeated wiring list contracts into shared helpers without changing public event facade interfaces.
  • Keeps behaviour unchanged while reducing copy-paste risk ahead of follow-up splits.

Scope

  • Added Acestep/ui/gradio/events/wiring/context.py with:

    • GenerationWiringContext
    • TrainingWiringContext
    • Build_auto_checkbox_inputs(...)
    • Build_auto_checkbox_outputs(...)
    • Build_mode_ui_outputs(...)
  • Added Acestep/ui/gradio/events/wiring/init.py re-exports.

  • Updated Acestep/ui/gradio/events/init.py to consume shared builders for:

    • auto-checkbox input/output lists
    • mode UI output list
  • Added Acestep/ui/gradio/events/wiring/context_test.py to lock ordering contracts.

  • No handler behaviour changes.

  • No interface signature changes for:

    • setup_event_handlers(...)
    • setup_training_event_handlers(...)
  • No cross-path runtime/hardware changes.

Validation

Code review by GLM5 with no issues.

Unit tests introduced

  • Acestep/ui/gradio/events/wiring/context_test.py
    • verifies auto-checkbox output ordering
    • verifies auto-checkbox input ordering
    • verifies mode UI output ordering
    • verifies training context reference integrity

Unit tests run

  • python -m unittest discover -s acestep/ui/gradio/events/wiring -p context_test.py (pass)

Manual UI tests passed

  • Generation and Training tabs load without startup errors.
  • Generation mode switching (Custom/Simple/Remix/Repaint/Extract/Complete) keeps UI visibility/labels consistent.
  • Auto-checkbox flows remain correct for reset + populated-field uncheck behaviour.
  • Send-to-Remix / Send-to-Repaint actions preserve expected mode/field transitions.
  • Batch navigation (Prev/Next/Restore Params) behaviour remains intact.
  • LRC display change updates subtitles on matching audio component.
  • Training tab interaction smoke checks (load/scan/dataset controls) remain wired.

Risk

  • Low. This is a wiring-contract extraction with ordering covered by dedicated tests.
  • Residual risk is primarily runtime key presence in component dicts (same behaviour as before).

Summary by CodeRabbit

  • Refactor

    • Improved internal structure of UI event handling system for better maintainability and code organization.
  • Tests

    • Added comprehensive test coverage for event wiring context and builder components.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new wiring abstraction framework for Gradio event setup. It creates context classes (GenerationWiringContext, TrainingWiringContext) and builder functions to encapsulate UI component lists, replacing inline component lists in the events module with programmatic wiring patterns and organized package structure.

Changes

Cohort / File(s) Summary
Core Wiring Package
acestep/ui/gradio/events/wiring/__init__.py, acestep/ui/gradio/events/wiring/context.py
Introduces new wiring package with context dataclasses for scoped generation and training event wiring, plus three builder functions (build_auto_checkbox_inputs, build_auto_checkbox_outputs, build_mode_ui_outputs) that fetch component lists from context mappings in deterministic order.
Wiring Tests
acestep/ui/gradio/events/wiring/context_test.py
Adds unit tests validating deterministic component ordering for builder functions against expected key sequences and verifies context reference preservation.
Events Module Refactoring
acestep/ui/gradio/events/__init__.py
Refactors setup_event_handlers and setup_training_event_handlers to instantiate context objects and replace inline component lists with builder-produced outputs, reducing configuration duplication across handlers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ChuxiJ

Poem

🐰 "Context flows like carrots in a row,
Builders gather what the wiring needs to know,
No more lists scattered, now they're home at last,
Frozen dataclasses, built to last!" 🥬✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor (gradio part1) events wiring contracts' accurately describes the primary change—extracting and formalizing event wiring contracts into reusable context structures and builders.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@1larity 1larity changed the title WIP PR1: refactor gradio events wiring contracts Refactor (gradio part1) events wiring contracts Feb 20, 2026
@1larity 1larity marked this pull request as ready for review February 20, 2026 13:52
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
acestep/ui/gradio/events/__init__.py (1)

1-1573: 🛠️ Refactor suggestion | 🟠 Major

Module exceeds 200 LOC — please split into smaller modules.
This file is far beyond the hard cap; consider extracting generation/results wiring and training wiring into separate modules to meet the size constraint and improve maintainability.

As per coding guidelines **/*.py: Target module size: optimal <= 150 LOC, hard cap 200 LOC.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@acestep/ui/gradio/events/__init__.py` around lines 1 - 1573, The file is too
large; split the big wiring into smaller modules by extracting the
generation/results wiring and the training wiring out of setup_event_handlers
and setup_training_event_handlers respectively: move the large body that builds
generation-related handlers (everything using GenerationWiringContext, gen_h,
res_h, build_auto_checkbox_inputs/outputs, build_mode_ui_outputs and the
download_existing_js + loops for save/send/score/lrc/convert/etc.) into a new
generation_wiring module exposing a function like
register_generation_handlers(demo, dit_handler, llm_handler, dataset_handler,
dataset_section, generation_section, results_section) and keep
setup_event_handlers only as a thin delegator that constructs
GenerationWiringContext and calls that function; likewise move the
training_section code (TrainingWiringContext usage and all train_h handlers,
wrappers, and button bindings) into a new training_wiring module exposing
register_training_handlers(demo, dit_handler, llm_handler, training_section) and
let setup_training_event_handlers delegate to it; finally update imports to
reference the new modules and ensure all referenced symbols
(GenerationWiringContext, TrainingWiringContext, gen_h, res_h, train_h,
build_auto_checkbox_inputs/outputs, build_mode_ui_outputs, generation_wrapper,
training_wrapper, lokr_training_wrapper) are either moved or re-exported so
tests/imports keep working.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@acestep/ui/gradio/events/__init__.py`:
- Around line 1-1573: The file is too large; split the big wiring into smaller
modules by extracting the generation/results wiring and the training wiring out
of setup_event_handlers and setup_training_event_handlers respectively: move the
large body that builds generation-related handlers (everything using
GenerationWiringContext, gen_h, res_h, build_auto_checkbox_inputs/outputs,
build_mode_ui_outputs and the download_existing_js + loops for
save/send/score/lrc/convert/etc.) into a new generation_wiring module exposing a
function like register_generation_handlers(demo, dit_handler, llm_handler,
dataset_handler, dataset_section, generation_section, results_section) and keep
setup_event_handlers only as a thin delegator that constructs
GenerationWiringContext and calls that function; likewise move the
training_section code (TrainingWiringContext usage and all train_h handlers,
wrappers, and button bindings) into a new training_wiring module exposing
register_training_handlers(demo, dit_handler, llm_handler, training_section) and
let setup_training_event_handlers delegate to it; finally update imports to
reference the new modules and ensure all referenced symbols
(GenerationWiringContext, TrainingWiringContext, gen_h, res_h, train_h,
build_auto_checkbox_inputs/outputs, build_mode_ui_outputs, generation_wrapper,
training_wrapper, lokr_training_wrapper) are either moved or re-exported so
tests/imports keep working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants