Skip to content

Commit 7acb58f

Browse files
nhortonclaude
andcommitted
refactor: use yaml.safe_load unconditionally since YAML is a JSON superset
Simplifies the implementation — no need to branch on file extension. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 95af696 commit 7acb58f

3 files changed

Lines changed: 10 additions & 36 deletions

File tree

specs/deepwork/jobs/JOBS-REQ-004-quality-review-system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The quality review system evaluates step outputs against defined quality criteri
1515
### JOBS-REQ-004.2: JSON Schema Validation
1616

1717
1. `validate_json_schemas()` MUST check all `file_path` type outputs that have a `json_schema` defined on their `StepArgument`.
18-
2. For each such output, the file content MUST be parsed and validated against the schema. Files with `.yml` or `.yaml` extensions MUST be parsed as YAML; all other files MUST be parsed as JSON.
18+
2. For each such output, the file content MUST be parsed as YAML (which is a superset of JSON) and validated against the schema.
1919
3. If file parsing fails, the error MUST be included in the returned error list.
2020
4. If schema validation fails, the error MUST be included in the returned error list.
2121
5. Files that do not exist MUST be skipped (not treated as errors by this function).

src/deepwork/jobs/mcp/quality_gate.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from __future__ import annotations
99

10-
import json
1110
import logging
1211
from pathlib import Path
1312

@@ -59,18 +58,11 @@ def validate_json_schemas(
5958
if not full_path.exists():
6059
continue
6160
try:
62-
content = full_path.read_text(encoding="utf-8")
63-
if full_path.suffix in (".yml", ".yaml"):
64-
import yaml
61+
import yaml
6562

66-
parsed = yaml.safe_load(content)
67-
else:
68-
parsed = json.loads(content)
69-
except (json.JSONDecodeError, UnicodeDecodeError) as e:
70-
errors.append(f"Output '{output_name}' file '{path}': failed to parse: {e}")
71-
continue
63+
content = full_path.read_text(encoding="utf-8")
64+
parsed = yaml.safe_load(content)
7265
except Exception as e:
73-
# Covers yaml.YAMLError and other parsing failures
7466
errors.append(f"Output '{output_name}' file '{path}': failed to parse: {e}")
7567
continue
7668

tests/unit/jobs/mcp/test_quality_gate.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,20 @@ def test_passes_when_json_schema_validates(self, tmp_path: Path) -> None:
9292

9393
# THIS TEST VALIDATES A HARD REQUIREMENT (JOBS-REQ-004.2.3).
9494
# YOU MUST NOT MODIFY THIS TEST UNLESS THE REQUIREMENT CHANGES
95-
def test_fails_when_json_is_invalid(self, tmp_path: Path) -> None:
96-
"""Non-JSON content in the output file produces an error."""
95+
def test_fails_when_file_is_unparseable(self, tmp_path: Path) -> None:
96+
"""Unparseable content in the output file produces an error."""
9797
schema = {"type": "object"}
9898
arg = StepArgument(
99-
name="data", description="JSON data", type="file_path", json_schema=schema
99+
name="data", description="data file", type="file_path", json_schema=schema
100100
)
101101
output_ref = StepOutputRef(argument_name="data", required=True)
102102
step = WorkflowStep(name="generate", outputs={"data": output_ref})
103103
job, _ = _make_job(tmp_path, [arg], step)
104104

105-
data_file = tmp_path / "data.json"
106-
data_file.write_text("not json {{{")
105+
data_file = tmp_path / "data.yml"
106+
data_file.write_text(":\n bad: [yaml\n unclosed")
107107

108-
errors = validate_json_schemas({"data": "data.json"}, step, job, tmp_path)
108+
errors = validate_json_schemas({"data": "data.yml"}, step, job, tmp_path)
109109
assert len(errors) == 1
110110
assert "failed to parse" in errors[0]
111111

@@ -192,24 +192,6 @@ def test_fails_when_yaml_file_violates_schema(self, tmp_path: Path) -> None:
192192
assert len(errors) == 1
193193
assert "schema validation failed" in errors[0]
194194

195-
# THIS TEST VALIDATES A HARD REQUIREMENT (JOBS-REQ-004.2.3).
196-
# YOU MUST NOT MODIFY THIS TEST UNLESS THE REQUIREMENT CHANGES
197-
def test_fails_when_yaml_is_invalid(self, tmp_path: Path) -> None:
198-
"""Invalid YAML content produces a parse error."""
199-
schema = {"type": "object"}
200-
arg = StepArgument(
201-
name="data", description="YAML data", type="file_path", json_schema=schema
202-
)
203-
output_ref = StepOutputRef(argument_name="data", required=True)
204-
step = WorkflowStep(name="generate", outputs={"data": output_ref})
205-
job, _ = _make_job(tmp_path, [arg], step)
206-
207-
data_file = tmp_path / "data.yml"
208-
data_file.write_text(":\n bad: [yaml\n unclosed")
209-
210-
errors = validate_json_schemas({"data": "data.yml"}, step, job, tmp_path)
211-
assert len(errors) == 1
212-
assert "failed to parse" in errors[0]
213195

214196

215197
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)