generated from coulomb/repo-seed
Add schedule smoke test routine
This commit is contained in:
@@ -22,6 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# Matches {field.path} placeholders in prompt templates.
|
||||
_PLACEHOLDER_RE = re.compile(r"\{([a-zA-Z_][a-zA-Z0-9_.]*)\}")
|
||||
_FENCED_JSON_RE = re.compile(r"^```(?:json)?\s*(.*?)\s*```\s*$", re.DOTALL)
|
||||
|
||||
|
||||
class UntrustedFieldError(ValueError):
|
||||
@@ -240,7 +241,7 @@ def _invalid_output_report(
|
||||
raw_preview: str | None = None
|
||||
if isinstance(raw_output, str):
|
||||
try:
|
||||
partial_output = json.loads(raw_output)
|
||||
partial_output = _parse_json_output(raw_output)
|
||||
except json.JSONDecodeError:
|
||||
partial_output = None
|
||||
raw_preview = raw_output[:4000]
|
||||
@@ -282,7 +283,7 @@ def _validate_output(
|
||||
"""
|
||||
try:
|
||||
if isinstance(raw_output, str):
|
||||
data = json.loads(raw_output)
|
||||
data = _parse_json_output(raw_output)
|
||||
else:
|
||||
data = raw_output
|
||||
|
||||
@@ -328,6 +329,29 @@ def _validate_output(
|
||||
return [], None, str(exc)
|
||||
|
||||
|
||||
def _parse_json_output(raw_output: str) -> Any:
|
||||
"""Parse JSON output, accepting a single Markdown JSON fence when present."""
|
||||
text = raw_output.strip()
|
||||
try:
|
||||
return json.loads(text)
|
||||
except json.JSONDecodeError as original_error:
|
||||
fence_match = _FENCED_JSON_RE.match(text)
|
||||
if fence_match:
|
||||
return json.loads(fence_match.group(1).strip())
|
||||
|
||||
decoder = json.JSONDecoder()
|
||||
for marker in ("{", "["):
|
||||
start = text.find(marker)
|
||||
if start < 0:
|
||||
continue
|
||||
try:
|
||||
data, _ = decoder.raw_decode(text[start:])
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
return data
|
||||
raise original_error
|
||||
|
||||
|
||||
def _validate_against_schema(data: Any, schema_path: str) -> str | None:
|
||||
if not schema_path:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user