The legacy TCP API does not enforce AI safety tags, but unknown commands and bad params must still come back as structured errors.
(api: SerialStudioAPI, suite: TestSuite, available: set[str])
| 668 | |
| 669 | |
| 670 | def test_blocked_commands(api: SerialStudioAPI, suite: TestSuite, available: set[str]): |
| 671 | """The legacy TCP API does not enforce AI safety tags, but unknown |
| 672 | commands and bad params must still come back as structured errors.""" |
| 673 | print(bold(info("\n[ Error-shape checks ]"))) |
| 674 | |
| 675 | # Missing required parameter. |
| 676 | if "io.uart.setBaudRate" in available: |
| 677 | response = api.send_command("io.uart.setBaudRate") |
| 678 | if response and not response.get("success"): |
| 679 | code = response.get("error", {}).get("code", "") |
| 680 | if code in (ErrorCode.MISSING_PARAM, ErrorCode.INVALID_PARAM): |
| 681 | _record( |
| 682 | suite, |
| 683 | "missing required param -> structured error", |
| 684 | TestResult.PASSED, |
| 685 | ) |
| 686 | else: |
| 687 | _record( |
| 688 | suite, |
| 689 | "missing required param -> structured error", |
| 690 | TestResult.FAILED, |
| 691 | f"got {code}", |
| 692 | ) |
| 693 | else: |
| 694 | _record( |
| 695 | suite, |
| 696 | "missing required param -> structured error", |
| 697 | TestResult.FAILED, |
| 698 | "server accepted the command without baudRate", |
| 699 | ) |
| 700 | else: |
| 701 | _record( |
| 702 | suite, |
| 703 | "missing required param -> structured error", |
| 704 | TestResult.SKIPPED, |
| 705 | "io.uart.setBaudRate not registered", |
| 706 | ) |
| 707 | |
| 708 | # Wrong parameter type. |
| 709 | if "io.uart.setBaudRate" in available: |
| 710 | response = api.send_command( |
| 711 | "io.uart.setBaudRate", params={"baudRate": "not-a-number"} |
| 712 | ) |
| 713 | if response and not response.get("success"): |
| 714 | _record( |
| 715 | suite, "type-mismatched param -> structured error", TestResult.PASSED |
| 716 | ) |
| 717 | else: |
| 718 | _record( |
| 719 | suite, |
| 720 | "type-mismatched param -> structured error", |
| 721 | TestResult.FAILED, |
| 722 | "server accepted non-numeric baudRate", |
| 723 | ) |
| 724 | else: |
| 725 | _record( |
| 726 | suite, |
| 727 | "type-mismatched param -> structured error", |