(value: Any, index: int)
| 683 | |
| 684 | |
| 685 | def _normalize_preflight_patch(value: Any, index: int) -> dict[str, Any]: |
| 686 | label = f"Capability preflight remediation patch {index + 1}" |
| 687 | if not isinstance(value, dict): |
| 688 | raise SystemExit(f"{label} must be a JSON object.") |
| 689 | _require_object_keys( |
| 690 | value, |
| 691 | required={"path", "value"}, |
| 692 | optional={"kind"}, |
| 693 | label=label, |
| 694 | ) |
| 695 | normalized: dict[str, Any] = { |
| 696 | "path": _bounded_preflight_text(value.get("path"), 256, f"patch {index + 1} path") |
| 697 | } |
| 698 | if "kind" in value: |
| 699 | kind = value.get("kind") |
| 700 | if kind not in {"config", "host_setting"}: |
| 701 | raise SystemExit(f"{label} has an invalid kind.") |
| 702 | normalized["kind"] = kind |
| 703 | patch_value = value.get("value") |
| 704 | if isinstance(patch_value, str): |
| 705 | if _javascript_string_length(patch_value) > 2048: |
| 706 | raise SystemExit(f"{label} value must be no longer than 2048 characters.") |
| 707 | elif isinstance(patch_value, bool): |
| 708 | pass |
| 709 | elif isinstance(patch_value, (int, float)): |
| 710 | try: |
| 711 | finite = math.isfinite(float(patch_value)) |
| 712 | except OverflowError: |
| 713 | finite = False |
| 714 | if not finite: |
| 715 | raise SystemExit(f"{label} value must be a finite number.") |
| 716 | else: |
| 717 | raise SystemExit(f"{label} value must be text, a number, or a boolean.") |
| 718 | normalized["value"] = patch_value |
| 719 | return normalized |
| 720 | |
| 721 | |
| 722 | def require_target(value: str) -> Path: |
no test coverage detected