MCPcopy
hub / github.com/openai/plugins / _normalize_preflight_patch

Function _normalize_preflight_patch

plugins/codex-security/scripts/workbench_db.py:685–719  ·  view source on GitHub ↗
(value: Any, index: int)

Source from the content-addressed store, hash-verified

683
684
685def _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
722def require_target(value: str) -> Path:

Callers 1

Calls 4

_require_object_keysFunction · 0.85
_bounded_preflight_textFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected