mirror of
https://github.com/github/spec-kit.git
synced 2026-08-03 06:26:30 +08:00
fix(presets): validate required manifest mappings (#3898)
Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -299,6 +299,12 @@ class PresetManifest:
|
||||
f"(expected {self.SCHEMA_VERSION})"
|
||||
)
|
||||
|
||||
for section in ("preset", "requires", "provides"):
|
||||
if not isinstance(self.data[section], dict):
|
||||
raise PresetValidationError(
|
||||
f"Invalid {section}: expected a mapping"
|
||||
)
|
||||
|
||||
# Validate preset metadata
|
||||
pack = self.data["preset"]
|
||||
for field in ["id", "name", "version", "description"]:
|
||||
|
||||
@@ -198,6 +198,25 @@ class TestPresetManifest:
|
||||
with pytest.raises(PresetValidationError, match="YAML mapping"):
|
||||
PresetManifest(manifest_path)
|
||||
|
||||
@pytest.mark.parametrize("section", ["preset", "requires", "provides"])
|
||||
@pytest.mark.parametrize("bad_value", [None, [], "text"])
|
||||
def test_required_section_not_mapping_raises_validation_error(
|
||||
self, temp_dir, valid_pack_data, section, bad_value
|
||||
):
|
||||
"""Required manifest sections reject null, list, and scalar values."""
|
||||
valid_pack_data[section] = bad_value
|
||||
manifest_path = temp_dir / "preset.yml"
|
||||
manifest_path.write_text(
|
||||
yaml.safe_dump(valid_pack_data),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with pytest.raises(
|
||||
PresetValidationError,
|
||||
match=rf"Invalid {section}: expected a mapping",
|
||||
):
|
||||
PresetManifest(manifest_path)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"bad",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user