Check Script Class Contracts
Audit all Python scripts in scripts/*.py and validate that script class overrides and UI-to-execution parameter contracts are correct.
When To Use
- New or changed files were added under
scripts/*.py
- A script crashes when selected or executed from UI
- A script UI was changed and runtime args no longer match
- You want a pre-PR quality gate for script API compatibility
Guidance
- Consult
.github/instructions/core.instructions.md for relevant core runtime guidance before proceeding.
Scope
Primary audit scope:
Contract references:
modules/scripts_manager.py (Script base class contracts for title, show, ui, run, process)
modules/scripts_postprocessing.py (ScriptPostprocessing contracts for ui and process)
Required Checks
A. Standard Overrides: __init__, title, show
For each class in scripts/*.py that subclasses scripts.Script or scripts_manager.Script:
title:
- method exists
- callable signature is valid
- returns non-empty string value
show:
- method exists
- signature is compatible with script runner usage (
show(is_img2img) or permissive *args/**kwargs)
- return behavior is compatible (
bool or scripts.AlwaysVisible / equivalent)
__init__ (if overridden):
- does not require mandatory constructor args that would break loader instantiation
- avoids side effects that require runtime-only globals at import time
- leaves class in a usable state before
ui()/run()/process() are called
Notes:
__init__ is optional; do not fail scripts that rely on inherited constructor.
- For dynamic patterns, flag as warning with rationale instead of hard fail.
B. ui() Output vs run()/process() Parameters
For each script class:
- Determine execution target:
- Prefer
run() if present for generation scripts
- Use
process() if present and run() is absent or script is postprocessing-oriented
- Compare
ui() output shape to target method parameter expectations:
ui() list/tuple output count should match target positional argument capacity after the first processing arg (p or pp), unless target uses *args
- if target is strict positional (no
*args/**kwargs), detect missing/extra UI values
- if target uses keyword-driven processing, ensure UI dict keys map to accepted params or
**kwargs
- Validate ordering assumptions:
- UI control order should align with positional parameter order when positional binding is used
- detect obvious drift when new UI control was added but method signature was not updated
- Validate optionality/defaults:
- required target parameters should be satisfiable by UI outputs
- defaulted target params are acceptable even if UI omits them
C. Runner Compatibility
Confirm script methods align with runner expectations in modules/scripts_manager.py:
ui() return type is compatible with runner collection (list/tuple or recognized mapping pattern where used)
run()/process() receive args in expected form from runner slices
- no obvious mismatch between
args_from/args_to assumptions and script method arity
For postprocessing-style scripts in scripts/*.py:
- verify compatibility with
modules/scripts_postprocessing.py conventions (ui() list/dict, process(pp, *args, **kwargs))
Procedure
- Enumerate all classes in
scripts/*.py and classify by base class type.
- For each generation script class, validate
title, show, optional __init__, and ui -> run/process contracts.
- For each postprocessing script class under
scripts/*.py, validate ui -> process mapping semantics.
- Cross-check ambiguous cases against script runner behavior from
modules/scripts_manager.py and modules/scripts_postprocessing.py.
- Report concrete mismatches with minimal fixes.
Reporting Format
Return findings by severity:
- Blocking script contract failures
- Runtime- likely arg/arity mismatches
- Signature/type compatibility warnings
- Style/consistency improvements
For each finding include:
- script file
- class name
- failing contract area (
init, title, show, ui->run, ui->process)
- mismatch summary
- minimal fix
Also include summary counts:
- total
scripts/*.py files checked
- total script classes checked
- classes with
run contract checked
- classes with
process contract checked
- override issues found (
init/title/show)
Pass Criteria
A full pass requires all of the following across audited scripts/*.py classes:
title and show overrides are valid and runner-compatible for generation scripts
- overridden
__init__ methods are safely instantiable
ui() output contracts are compatible with run() or process() args
- no blocking arity/signature mismatch remains
If a class uses runtime-determined argument mapping or dynamic method dispatch that cannot be proven statically, mark as conditional pass with explicit runtime validation recommendation.
1---2name: check-scripts3description: Run a phased scripts audit in scripts/*.py: validate Script overrides (init/title/show) first, then verify ui() output compatibility with run() or process() parameters.4---56# Check Script Class Contracts78Audit all Python scripts in `scripts/*.py` and validate that script class overrides and UI-to-execution parameter contracts are correct.910## When To Use1112- New or changed files were added under `scripts/*.py`13- A script crashes when selected or executed from UI14- A script UI was changed and runtime args no longer match15- You want a pre-PR quality gate for script API compatibility1617## Guidance1819- Consult `.github/instructions/core.instructions.md` for relevant core runtime guidance before proceeding.2021## Scope2223Primary audit scope:2425- `scripts/*.py`2627Contract references:2829- `modules/scripts_manager.py` (`Script` base class contracts for `title`, `show`, `ui`, `run`, `process`)30- `modules/scripts_postprocessing.py` (`ScriptPostprocessing` contracts for `ui` and `process`)3132## Required Checks3334### A. Standard Overrides: `__init__`, `title`, `show`3536For each class in `scripts/*.py` that subclasses `scripts.Script` or `scripts_manager.Script`:37381. `title`:39- method exists40- callable signature is valid41- returns non-empty string value42432. `show`:44- method exists45- signature is compatible with script runner usage (`show(is_img2img)` or permissive `*args/**kwargs`)46- return behavior is compatible (`bool` or `scripts.AlwaysVisible` / equivalent)47483. `__init__` (if overridden):49- does not require mandatory constructor args that would break loader instantiation50- avoids side effects that require runtime-only globals at import time51- leaves class in a usable state before `ui()`/`run()`/`process()` are called5253Notes:54- `__init__` is optional; do not fail scripts that rely on inherited constructor.55- For dynamic patterns, flag as warning with rationale instead of hard fail.5657### B. `ui()` Output vs `run()`/`process()` Parameters5859For each script class:60611. Determine execution target:62- Prefer `run()` if present for generation scripts63- Use `process()` if present and `run()` is absent or script is postprocessing-oriented64652. Compare `ui()` output shape to target method parameter expectations:66- `ui()` list/tuple output count should match target positional argument capacity after the first processing arg (`p` or `pp`), unless target uses `*args`67- if target is strict positional (no `*args`/`**kwargs`), detect missing/extra UI values68- if target uses keyword-driven processing, ensure UI dict keys map to accepted params or `**kwargs`69703. Validate ordering assumptions:71- UI control order should align with positional parameter order when positional binding is used72- detect obvious drift when new UI control was added but method signature was not updated73744. Validate optionality/defaults:75- required target parameters should be satisfiable by UI outputs76- defaulted target params are acceptable even if UI omits them7778### C. Runner Compatibility7980Confirm script methods align with runner expectations in `modules/scripts_manager.py`:8182- `ui()` return type is compatible with runner collection (`list/tuple` or recognized mapping pattern where used)83- `run()`/`process()` receive args in expected form from runner slices84- no obvious mismatch between `args_from/args_to` assumptions and script method arity8586For postprocessing-style scripts in `scripts/*.py`:8788- verify compatibility with `modules/scripts_postprocessing.py` conventions (`ui()` list/dict, `process(pp, *args, **kwargs)`)8990## Procedure91921. Enumerate all classes in `scripts/*.py` and classify by base class type.932. For each generation script class, validate `title`, `show`, optional `__init__`, and `ui` -> `run/process` contracts.943. For each postprocessing script class under `scripts/*.py`, validate `ui` -> `process` mapping semantics.954. Cross-check ambiguous cases against script runner behavior from `modules/scripts_manager.py` and `modules/scripts_postprocessing.py`.965. Report concrete mismatches with minimal fixes.9798## Reporting Format99100Return findings by severity:1011021. Blocking script contract failures1032. Runtime- likely arg/arity mismatches1043. Signature/type compatibility warnings1054. Style/consistency improvements106107For each finding include:108109- script file110- class name111- failing contract area (`init`, `title`, `show`, `ui->run`, `ui->process`)112- mismatch summary113- minimal fix114115Also include summary counts:116117- total `scripts/*.py` files checked118- total script classes checked119- classes with `run` contract checked120- classes with `process` contract checked121- override issues found (`init/title/show`)122123## Pass Criteria124125A full pass requires all of the following across audited `scripts/*.py` classes:126127- `title` and `show` overrides are valid and runner-compatible for generation scripts128- overridden `__init__` methods are safely instantiable129- `ui()` output contracts are compatible with `run()` or `process()` args130- no blocking arity/signature mismatch remains131132If a class uses runtime-determined argument mapping or dynamic method dispatch that cannot be proven statically, mark as conditional pass with explicit runtime validation recommendation.