You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fail fast on test parameters the SDK test runner does not accept - #418
Test parameters are forwarded as --<name> <value> to test_harness_client.py. A mistyped one (e.g. --prompt_timeout instead of --prompt-timeout) only failed when the runner was first invoked, in the middle of the run, and the reason was visible only in the Python test log. The run was created, a container started and every step cancelled.
Whenever the Python test files are generated (backend startup / rescan), the options the runner accepts are read from its --help inside the SDK container and cached in sdk_tests/runner_options.json (git-ignored, like python_tests_info.json). Reading them from the runner means the list follows the pinned SDK and cannot go stale.
POST /test_run_executions/cli and POST /test_run_executions/{id}/start check the run's effective test_parameters (execution config if present, otherwise the project config) against the cache and answer 422 with the offending parameter. With th-cli, no run is created, so there is no run ID, container or cancelled steps.
Error example (one parameter per line):
Invalid test parameter(s) for the SDK test runner:
'--timeuot' (did you mean '--timeout'?)
No test was started. Test parameters are passed to test_harness_client.py as '--<name> <value>'.
The "did you mean" suggestion uses a strict similarity cutoff (0.8): the default one suggested unrelated runner options (--prompt-timeout -> --timeout, --tests-list -> --tests), and a wrong suggestion is worse than none. The backend deliberately knows nothing about any client's options; a hint for th-cli-only options belongs in the CLI.
2. Fallback at suite setup
PythonTestSuite.setup runs the same check against the container's --help, before any DUT interaction, for when the cache is unavailable.
Safety
Abbreviated options are accepted, as argparse does.
A missing, corrupt or malformed cache means "do not validate" (nothing is rejected on a guess). If a refresh cannot read the options, the old cache is deleted so a previous SDK version's list is never used. The refresh never fails the test file generation.
Tests
New unit tests: option parsing, cache save/load/clear and malformed-cache handling, the cache refresh, the message/hints (test_runner_options.py); the suite-setup check (test_utils.py); and the API rejection helper (test_test_run_executions.py). I could not run the backend suite where this was written, so please rely on CI.
Manual check: th-cli run-tests -t TC-DA-1.10 --project-id 1 -- --prompt_timeout 5 should fail right away with the 422 message and create no run (needs the cache, i.e. the backend must have generated the test files once after updating).
Not included
A clearer message for other commissioning failures, and an exit-code check in the test-case loop.
test_output.txt from a previous run is still dumped after a failed commissioning.
Test parameters are forwarded as --<name> <value> to test_harness_client.py.
A mistyped one (e.g. --prompt_timeout) only failed when the runner was first
invoked, in the middle of the run, with the reason visible only in the Python
test log.
At the start of the Python test suite setup, read the runner's options from
its --help (no side effects, never stale) and end the run with a clear
message, before any DUT interaction, if a test parameter is unknown. If the
options cannot be read the check is skipped.
Related to #1215
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 85147661-d1a5-4bb9-b7ec-1dbaa7d55a4c
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Walkthrough
The changes parse and cache options from the SDK test runner’s help output. SDK test setup and API execution entry points use those options to validate configured test parameters. Invalid parameters are reported before test execution; validation is skipped when runner options are unavailable.
Sequence Diagram(s)
sequenceDiagram
participant PythonTestSuiteSetup
participant validate_test_parameters
participant SDKTestRunner
PythonTestSuiteSetup->>validate_test_parameters: configured test parameters
validate_test_parameters->>SDKTestRunner: request --help
SDKTestRunner-->>validate_test_parameters: runner help options
validate_test_parameters-->>PythonTestSuiteSetup: accept parameters or raise validation error
Loading
Suggested reviewers:antonio-amjr, greens
Severity of issue fixed: Medium
Merge Risk: Low · previous review 8a1d9
The change adds early rejection of unsupported SDK test parameters. The remaining gaps are narrow: an ambiguous abbreviated option can still pass validation and fail inside the runner, and unusual cache-file or container errors could interrupt test-file generation or suite setup instead of skipping the optional check. These are worth tightening before or soon after merge, but they are not expected to affect normal runs.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
Issue #1215 has two expected behaviors. (a) Unknown options given before -- must fail at once with a clear message, ideally with a suggestion. (b) Only arguments after -- may become test parameter…
Provide the certification-tool-cli#144 diff, or the repository that contains th_cli/commands/run_tests.py at the commit under review, so that requirements (a) and (b) can be checked. Provide readable diffs for the backend files (`test_run…
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title states the main change: test parameters the SDK test runner does not accept are rejected early, before the run starts. The changeset adds cached runner-option validation at the API boundary …
Out of Scope Changes check
All listed changes support the validation of SDK test parameters that this PR introduces. .gitignore ignores the new runner_options.json cache, as python_tests_info.json already is. The endpoint…
Description check
The description is specific and on-topic. It explains that test parameters are forwarded to test_harness_client.py and that mistyped parameters fail late in a run. It describes the changes: reading th…
Full details: Title check
Explanation
The title states the main change: test parameters the SDK test runner does not accept are rejected early, before the run starts. The changeset adds cached runner-option validation at the API boundary (CLI create and start endpoints) and a suite-setup fallback, which matches the title's 'fail fast' intent. The title is specific and single-sentence, with no vague terms.
Full details: Out of Scope Changes check
Explanation
All listed changes support the validation of SDK test parameters that this PR introduces. .gitignore ignores the new runner_options.json cache, as python_tests_info.json already is. The endpoint changes add the 422 check. test_manager.py refreshes the cache during test-file generation. runner_options.py and utils.py parse the runner --help, save and load the cache, and build the error message. test_suite.py adds the suite-setup fallback. The three test modules cover these changes. No change addresses unrelated functionality. The summary lists no change to CLI parsing, which the PR states is in the companion CLI PR.
Full details: Description check
Explanation
The description is specific and on-topic. It explains that test parameters are forwarded to test_harness_client.py and that mistyped parameters fail late in a run. It describes the changes: reading the SDK runner's --help into a cache, validating test parameters at the CLI and start endpoints with HTTP 422, a suite-setup fallback, and the safety rules for missing or corrupt caches. It also lists the new tests, a manual check, and items not included. The description matches the changeset in the raw summary.
Full details: Linked Issues check
Explanation
Issue #1215 has two expected behaviors. (a) Unknown options given before -- must fail at once with a clear message, ideally with a suggestion. (b) Only arguments after -- may become test parameters. The cited code (cli/th_cli/commands/run_tests.py, ignore_unknown_options, allow_extra_args, _parse_extra_args) does not exist at the reviewed head (git show path lookup failed). The PR states that this CLI behavior lives in certification-tool-cli#144 and that this PR does not implement it. The backend part of this PR rejects invalid test parameters with HTTP 422 in POST /test_run_executions/cli and POST /test_run_executions/{id}/start. It also adds a suite-setup fallback in PythonTestSuite.setup through validate_test_parameters. This covers the late, in-run failure for parameters that reach the backend. It does not cover requirements (a) and (b) for the CLI. Repository diff blobs were unavailable, so the backend behavior rests on the PR summary and the raw change summary, not on a read of the changed code.
Resolution
Provide the certification-tool-cli#144 diff, or the repository that contains th_cli/commands/run_tests.py at the commit under review, so that requirements (a) and (b) can be checked. Provide readable diffs for the backend files (test_run_executions.py, utils.py, runner_options.py) so the backend validation can be confirmed from code.
Finishing Touches
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Cache the options the SDK test runner accepts (read from its --help) whenever
the Python test files are generated, in sdk_tests/runner_options.json. The
test run create (/cli) and start endpoints use it to answer 422 with the
offending parameter, so a mistyped one no longer creates a run, starts a
container and cancels every step.
The suite-setup check stays as a fallback for when the cache is unavailable.
An unreadable or malformed cache means "do not validate", and a failed
refresh drops the old cache so a previous SDK version's list is never used.
Related to #1215
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Reject ambiguous option prefixes.
With runner options timeout and tests, {"t": "5"} passes this check. Python 3.10 argparse rejects --t because the prefix matches both options. The API and suite checks therefore allow a parameter that still fails inside the runner. (docs.python.org)
Accept an exact option name first. Otherwise, require exactly one prefix match. Keep unique abbreviations such as time valid. Add an ambiguous-prefix test.
The backend should not know the options of one client. Drop the
th-cli run-tests hint and instead make the 'did you mean' suggestion
stricter (cutoff 0.8): the default suggested the unrelated --timeout for
--prompt-timeout and --tests for --tests-list. Real typos still get a
suggestion.
Related to #1215
- Do not fail the suite setup when the --help probe raises, and drop the
redundant warning when the options are unavailable (already logged).
- Reject ambiguous option abbreviations like argparse does: an exact name
is accepted, otherwise it must abbreviate exactly one option.
- Do not abort test file generation when the options cache cannot be
written or deleted; empty it instead so a stale list is never used.
Related to #1215
Resolve the test_utils.py conflict: keep both the new test parameter
validation tests and the native log line tests, which were each appended at
the end of the file.
…es not accept (#422)
* Fail fast on test parameters the SDK test runner does not accept
Test parameters are forwarded as --<name> <value> to test_harness_client.py.
A mistyped one (e.g. --prompt_timeout) only failed when the runner was first
invoked, in the middle of the run, with the reason visible only in the Python
test log.
At the start of the Python test suite setup, read the runner's options from
its --help (no side effects, never stale) and end the run with a clear
message, before any DUT interaction, if a test parameter is unknown. If the
options cannot be read the check is skipped.
Related to #1215
* Reject invalid test parameters before a test run is created
Cache the options the SDK test runner accepts (read from its --help) whenever
the Python test files are generated, in sdk_tests/runner_options.json. The
test run create (/cli) and start endpoints use it to answer 422 with the
offending parameter, so a mistyped one no longer creates a run, starts a
container and cancels every step.
The suite-setup check stays as a fallback for when the cache is unavailable.
An unreadable or malformed cache means "do not validate", and a failed
refresh drops the old cache so a previous SDK version's list is never used.
Related to #1215
* Test: build SDK container mocks inside the tests, not at collection time
MagicMock(spec=SDKContainer) created in parametrize raised AttributeError
while importing test_utils.py, breaking collection of the whole module.
* Remove CLI-specific hint from test parameter validation
The backend should not know the options of one client. Drop the
th-cli run-tests hint and instead make the 'did you mean' suggestion
stricter (cutoff 0.8): the default suggested the unrelated --timeout for
--prompt-timeout and --tests for --tests-list. Real typos still get a
suggestion.
Related to #1215
* Make the test parameter checks robust to probe and cache failures
- Do not fail the suite setup when the --help probe raises, and drop the
redundant warning when the options are unavailable (already logged).
- Reject ambiguous option abbreviations like argparse does: an exact name
is accepted, otherwise it must abbreviate exactly one option.
- Do not abort test file generation when the options cache cannot be
written or deleted; empty it instead so a stale list is never used.
Related to #1215
* List invalid test parameters one per line
The error is shown in a terminal by th-cli, where a single long line is hard
to read.
Related to #1215
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
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
Test parameters are forwarded as
--<name> <value>totest_harness_client.py. A mistyped one (e.g.--prompt_timeoutinstead of--prompt-timeout) only failed when the runner was first invoked, in the middle of the run, and the reason was visible only in the Python test log. The run was created, a container started and every step cancelled.Closes #1215 together with the CLI PR certification-tool-cli#144.
Changes
1. Reject before a run is created
--helpinside the SDK container and cached insdk_tests/runner_options.json(git-ignored, likepython_tests_info.json). Reading them from the runner means the list follows the pinned SDK and cannot go stale.POST /test_run_executions/cliandPOST /test_run_executions/{id}/startcheck the run's effectivetest_parameters(execution config if present, otherwise the project config) against the cache and answer 422 with the offending parameter. Withth-cli, no run is created, so there is no run ID, container or cancelled steps.--prompt-timeout->--timeout,--tests-list->--tests), and a wrong suggestion is worse than none. The backend deliberately knows nothing about any client's options; a hint forth-cli-only options belongs in the CLI.2. Fallback at suite setup
PythonTestSuite.setupruns the same check against the container's--help, before any DUT interaction, for when the cache is unavailable.Safety
Tests
New unit tests: option parsing, cache save/load/clear and malformed-cache handling, the cache refresh, the message/hints (
test_runner_options.py); the suite-setup check (test_utils.py); and the API rejection helper (test_test_run_executions.py). I could not run the backend suite where this was written, so please rely on CI.Manual check:
th-cli run-tests -t TC-DA-1.10 --project-id 1 -- --prompt_timeout 5should fail right away with the 422 message and create no run (needs the cache, i.e. the backend must have generated the test files once after updating).Not included
test_output.txtfrom a previous run is still dumped after a failed commissioning.