feat(preflight): reject over-long SelectionCriteria arrays on remaining read-get commands#577
Merged
Merged
Conversation
…ng read-get commands (#571) Extend `enforce_criteria_array_limits` (added in #555) to 8 more read-get commands: ads, adgroups, bids, bidmodifiers, campaigns, keywords, dynamicfeedadtargets, audiencetargets. Each command now refuses an over-long SelectionCriteria array before the request and raises a UsageError naming the array and ceiling, instead of leaking the opaque API `error_code=4001`. Per-filter caps were measured live against the Yandex Direct sandbox on 2026-06-17 (probe set: N=10/100/1000/10000, anchored with --campaign-ids 1 for secondary fields). The measurement script and a documented audit set (`UNCAPPED_CRITERIA_KEYS` in utils.py) are committed so future drift is visible — see scripts/measure_criteria_limits.py and the per-command `*_GET_CRITERIA_LIMITS` constants for the exact transcripts. Downstream: the MCP plugin (axisrow/yandex-direct-mcp-plugin#201) can now drop its own batch-size guard and forward the CLI error. Tests: 18 new methods in TestSelectionCriteriaPreflight via a shared `_assert_preflight_rejects(cmd, flag, cap)` helper. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Owner
Author
🔍 Local review (cycle 1)Reviewed locally (Claude subagent + Codex companion), no bots pinged. Codex: approve, 0 findings.
Cycle 1/3 triage complete: 0 FIX, 3 SKIP. Proceeding to final cleanup pass (step 6.5). |
measure_criteria_limits.py was hardcoding `--profile default`; if the operator's only `direct auth` profile has another name, the sweep failed with a cryptic auth error before the first probe. Let YANDEX_DIRECT_MEASURE_PROFILE override. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Owner
Author
|
Final cleanup pass (step 6.5) applied in b817c0a: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
enforce_criteria_array_limits(added in #555 fordynamicads/keywordbids/smartadtargets) to the rest of the read-get surface: ads, adgroups, bids, bidmodifiers, campaigns, keywords, dynamicfeedadtargets, audiencetargets. Each command now refuses an over-longSelectionCriteriaarray before the request and surfaces the array name + ceiling, instead of leaking the opaque APIerror_code=4001(Exceed the maximum number of IDs per array …).Closes #571. Closes a downstream consistency gap for
axisrow/yandex-direct-mcp-plugin#201(the plugin can now drop its owncheck_batch_limit(max=10)and forward the CLI error).How per-filter caps were measured
Live, sandbox (
direct --sandbox --profile default), 2026-06-17, probe setN=10/100/1000/10000. For «secondary» fields (VCardIds,SitelinkSetIds,NegativeKeywordSharedSetIds) an anchor--campaign-ids 1was needed so the API would evaluate array length instead of returning «must specify at least one of Ids/AdGroupIds/CampaignIds».Script:
scripts/measure_criteria_limits.py(manual tool, not part of CI — re-run only when Yandex Direct is suspected of changing a cap). Full per-target transcripts: #571 (comment)*_GET_CRITERIA_LIMITS)4 commands (
strategies,sitelinks,vcards,adextensions) had their singleIdsarray measured uncapped, so they get no constant. The cleared list (14 uncapped keys total) is recorded indirect_cli/utils.py::UNCAPPED_CRITERIA_KEYSso future drift is visible and auditable.Other notes
TestSelectionCriteriaPreflightvia a shared_assert_preflight_rejects(cmd, flag, cap)helper (Russian/English-locale-agnostic, asserts"more than {cap} elements"and absence of4001).criteria = {}annotateddict[str, Any];dict[str, object]→dict[str, Any]on touched_build_*signatures; miscDict→dictfor consistency. No behavior change.scripts/_criteria_limits_results.json(live transcript cache) is gitignored — constants in code are the source of truth.Test plan
pytest tests/test_integration.py::TestSelectionCriteriaPreflight -v— 21/21 PASSED (3 from Add preflight validation for SelectionCriteria array sizes (and other uncovered limits) #555 + 18 new)pytest tests/test_dry_run.py tests/test_cli.py tests/test_integration.py::TestSelectionCriteriaPreflight— 1462/1462 PASSEDflake8 --max-line-length=88on touched files — cleanblack --checkon touched files — cleandirect ads/keywords/bids/dynamicfeedadtargets/campaigns get --…-ids "1,…,M+1"→UsageErrorwithSelectionCriteria.<key> ...and no API call🤖 Generated with Claude Code