refactor(commands): shared register_lifecycle_commands; drop 8 local wrappers (#589 #11) - #593
Conversation
…wrappers (#589) Dedup audit (#589 finding #11, follow-up of #582/epic #584). Eight modules each defined a near-identical local `_<resource>_lifecycle(method, help_text)` wrapper purely to repeat `make_lifecycle_command(group, ..., id_param, id_help, create_client)` for delete/suspend/resume (and archive/unarchive/moderate on ads/campaigns/strategies). Those eight wrappers collapse into one shared `register_lifecycle_commands(group, id_param, id_help, create_client, specs)` in `_lifecycle.py`; each module now passes its `(method, help_text)` spec list. CLI surface byte-identical — every lifecycle command still registers via the factory's `@group.command` (the discarded module-level `delete=`/`suspend=` bindings were unreferenced). Full offline suite green (2536 passed); ruff clean. `make_set_bids_command` (#12) and `execute_add` (#13) remain in #589. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@claude @codex review. Focus on critical issues only. This is a mechanical dedup (#589 #11): 8 near-identical local lifecycle wrappers replaced by one shared register_lifecycle_commands in _lifecycle.py. CLI surface is byte-identical — every delete/suspend/resume/archive/unarchive/moderate command still registers via the factory's @group.command (the discarded module-level bindings were unreferenced). Please confirm (a) no lifecycle command is dropped or renamed across the 8 modules, (b) the dropped delete=/suspend= module-level bindings are truly unreferenced. Do NOT nitpick style/naming/formatting. |
|
Claude finished @axisrow's task in 1m 47s —— View job Review — #589 #11: shared
|
| Module | id_param / id_help | Commands (before == after) |
|---|---|---|
ads |
ad_id / "Ad ID" |
delete, archive, unarchive, suspend, resume, moderate |
campaigns |
campaign_id / "Campaign ID" |
delete, archive, unarchive, suspend, resume |
strategies |
strategy_id / "Strategy ID" |
archive, unarchive |
audiencetargets |
target_id / "Target ID" |
delete, suspend, resume |
dynamicads |
target_id / "Target ID" |
delete, suspend, resume |
dynamicfeedadtargets |
target_id / "Target ID" |
delete, suspend, resume |
keywords |
keyword_id / "Keyword ID" |
delete, suspend, resume |
smartadtargets |
target_id / "Target ID" |
delete, suspend, resume |
None of the migrated modules used the non-default kwargs (service, id_option, id_type, criteria_key), so the helper not exposing them is correct — the modules that need --hash/AdImageHash (e.g. adimages) were intentionally left on the old pattern. Registration is a decorator side-effect inside make_lifecycle_command (@group.command), so discarding the return value changes nothing.
(b) Dropped module-level bindings truly unreferenced ✓
commands/__init__.pyimports only the group symbols (from .ads import ads, etc.) — neverdelete/suspend/resume/archive/unarchive/moderate.- No
from .<module> import <lifecycle>orcommands.<module>.<lifecycle>reference anywhere indirect_cli/ortests/. (The onetest_v4_contracts.py:312delete.example_paramhit is an unrelated v4-contract object, not a command binding.) - A grep for the old module-level binding pattern matches only the non-migrated modules still using it — confirming the 8 targets no longer define those names and nothing depended on them.
Notes (non-blocking, not nitpicks)
- The factory verification I attempted (importing each group and asserting
.commandscontains the expected names) couldn't run here — the sandbox blockedpythonexecution — so the table above is from static diff analysis. The PR's reported full run (2536 passed) plustests/test_comprehensive.py::TestCommandsRegisteredcovers the live registration assertion.
•refactor/589-lifecycle-wrappers
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Thanks @claude @codex — both clean, no FIX items. Confirmed: all 8 modules' (method, help_text) lists + id_param/id_help are byte-for-byte preserved; dropped module-level bindings unreferenced (only group symbols are imported in commands/init.py); kwargs-less helper is correct (single-command non-default-id modules like adimages stay on the direct make_lifecycle_command path). #12/#13 remain in #589. Merging (CI green). |
|
To use Codex here, create an environment for this repo. |
|
Claude finished @axisrow's task in 36s —— View job Confirmed — merge looks correct ✅Verified the merged def register_lifecycle_commands(group, id_param, id_help, create_client, specs):
for method, help_text in specs:
make_lifecycle_command(
group, method, help_text, id_param, id_help, create_client
)
Both Claude and Codex reviews were clean, no FIX items, CI green. |
Part of #589 (finding #11) / follow-up of #582 / эпик #584.
Что сделано
Восемь модулей (dynamicads, audiencetargets, smartadtargets, dynamicfeedadtargets, ads, campaigns, keywords, strategies) определяли почти идентичную локальную обёртку
_<resource>_lifecycle(method, help_text)— только чтобы повторитьmake_lifecycle_command(group, ..., id_param, id_help, create_client)для delete/suspend/resume (+ archive/unarchive/moderate у ads/campaigns/strategies).Восемь обёрток сведены в один общий
register_lifecycle_commands(group, id_param, id_help, create_client, specs)в_lifecycle.py; каждый модуль передаёт свой список(method, help_text).Байт-идентичность
@group.commandвнутри фабрики; удалённые module-level биндинги (delete=/suspend=/…) нигде не импортировались (проверено grep).--help(ads delete, campaigns archive, strategies unarchive, dynamicads suspend) — на месте./simplify: 3 ревьюера; по сходящейся рекомендации убран преждевременный**kwargsиз сигнатуры хелпера (немигрированные модули с non-default id-путями имеют по одной команде — batch им не нужен; вернуть тривиально при появлении реального кейса). Остальное — без изменений (module-level биндинги не используются, имя/import-time/spec-валидация — приемлемо).Diff: +115 / −84 (структурный дедуп: 8 функций-обёрток → 1 общий хелпер; multi-line спеки от black дают нетто +31).
Остаётся в #589
make_set_bids_command(4 модуля).execute_add(~17 add-команд).🤖 Generated with Claude Code