Skip to content

Fail fast on test parameters the SDK test runner does not accept - #418

Merged
rquidute merged 7 commits into
project-chip:v2.16-developfrom
rquidute:fix/1215-validate-test-parameters-preflight
Nov 23, 2026
Merged

rquidute merged 7 commits into
project-chip:v2.16-developfrom
rquidute:fix/1215-validate-test-parameters-preflight

Conversation

@rquidute

@rquidute rquidute commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.

Closes #1215 together with the CLI PR certification-tool-cli#144.

Changes

1. Reject before a run is created

  • 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
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

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: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive 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 Passed checks: 3 passed

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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.

Share

@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

This pull request is merged.

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
MagicMock(spec=SDKContainer) created in parametrize raised AttributeError
while importing test_utils.py, breaking collection of the whole module.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review info

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: a23d5d2e-6376-4c24-a3dc-97397d2a5feb
Commits

Reviewing files that changed from the base of the PR and between 586a2f2 and 8a1d90b.

Files selected for processing: 9

  • .gitignore
  • app/api/api_v1/endpoints/test_run_executions.py
  • app/tests/api/api_v1/test_test_run_executions.py
  • test_collections/matter/sdk_tests/support/python_testing/models/test_suite.py
  • test_collections/matter/sdk_tests/support/python_testing/models/utils.py
  • test_collections/matter/sdk_tests/support/python_testing/runner_options.py
  • test_collections/matter/sdk_tests/support/python_testing/test_manager.py
  • test_collections/matter/sdk_tests/support/tests/python_tests/test_runner_options.py
  • test_collections/matter/sdk_tests/support/tests/python_tests/test_utils.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

"""
problems = []
for name in test_parameters:
if not name or any(option.startswith(name) for option in runner_options):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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
@rquidute rquidute self-assigned this Nov 19, 2026
The error is shown in a terminal by th-cli, where a single long line is hard
to read.

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.
@rquidute
rquidute merged commit 93bd4e2 into project-chip:v2.16-develop Nov 23, 2026
5 of 6 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in CSG issue tracking Nov 23, 2026
@rquidute
rquidute deleted the fix/1215-validate-test-parameters-preflight branch November 23, 2026 13:25
rquidute added a commit that referenced this pull request Nov 23, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug] th-cli run-tests silently accepts unknown options (e.g. --prompt_timeout) and fails later inside the test

3 participants