Skip to content

Commit 1e98eef

Browse files
authored
fix: ensure we don't allow extra in scopes config (#885)
Currently has the root object has "ignore" to allow root keys from the engine, we can't change the default validator
1 parent 7f03ac7 commit 1e98eef

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

mergify_cli/ci/scopes/config/scopes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616

1717
class FileFilters(pydantic.BaseModel):
18+
model_config = pydantic.ConfigDict(extra="forbid")
19+
1820
include: tuple[str, ...] = pydantic.Field(
1921
default_factory=lambda: ("**/*",),
2022
description=(
@@ -34,6 +36,8 @@ class FileFilters(pydantic.BaseModel):
3436

3537

3638
class SourceFiles(pydantic.BaseModel):
39+
model_config = pydantic.ConfigDict(extra="forbid")
40+
3741
files: dict[ScopeName, FileFilters] = pydantic.Field(
3842
description=(
3943
"Mapping of scope name to its file filters. "
@@ -44,6 +48,8 @@ class SourceFiles(pydantic.BaseModel):
4448

4549

4650
class SourceManual(pydantic.BaseModel):
51+
model_config = pydantic.ConfigDict(extra="forbid")
52+
4753
manual: None = pydantic.Field(
4854
description="Scopes are manually sent via API or `mergify scopes-send`",
4955
)

mergify_cli/tests/ci/scopes/test_cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_from_yaml_invalid_config(tmp_path: pathlib.Path) -> None:
106106
)
107107

108108
# Bad name and missing dict
109-
with pytest.raises(config.ConfigInvalidError, match="3 validation errors"):
109+
with pytest.raises(config.ConfigInvalidError, match="4 validation errors"):
110110
config.Config.from_yaml(str(config_file))
111111

112112

@@ -481,6 +481,22 @@ def test_detect_no_matches(
481481
assert result.scopes == set()
482482

483483

484+
def test_match_scopes_invalid() -> None:
485+
with pytest.raises(config.ConfigInvalidError, match="4 validation errors"):
486+
config.Config.from_dict(
487+
{
488+
"scopes": {
489+
"source": {
490+
"files": {
491+
"backend": {"includes": ("api/**/*.py",)},
492+
"frontend": {"includes": ("ui/**/*.js",)},
493+
},
494+
},
495+
},
496+
},
497+
)
498+
499+
484500
@mock.patch("mergify_cli.ci.scopes.changed_files.git_changed_files")
485501
def test_detect_debug_output(
486502
mock_git_changed: mock.Mock,

0 commit comments

Comments
 (0)