diff --git a/stackinator/schema/compilers.json b/stackinator/schema/compilers.json index a0fd8d7..1647a5b 100644 --- a/stackinator/schema/compilers.json +++ b/stackinator/schema/compilers.json @@ -2,6 +2,8 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Schema for Spack Stack compilers.yaml recipe file", "type": "object", + "additionalProperties": false, + "required": ["bootstrap", "gcc"], "defs": { "gcc_version_spec": { "type": "string", @@ -65,8 +67,6 @@ ], "default": null } - }, - "additionalProperties": false, - "required": ["bootstrap", "gcc"] + } } diff --git a/stackinator/schema/config.json b/stackinator/schema/config.json index 59a55de..adc0356 100644 --- a/stackinator/schema/config.json +++ b/stackinator/schema/config.json @@ -2,6 +2,8 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Schema for Spack Stack config.yaml recipe file", "type" : "object", + "additionalProperties": false, + "required": ["name", "system", "spack"], "properties" : { "name" : { "type": "string" @@ -15,6 +17,7 @@ }, "spack" : { "type" : "object", + "additionalProperties": false, "properties" : { "repo": { "type": "string" @@ -26,11 +29,12 @@ ], "default": null } - }, - "additionalProperties": false + } }, "mirror" : { "type" : "object", + "additionalProperties": false, + "default": {"enable": true, "key": null}, "properties" : { "enable" : { "type": "boolean", @@ -43,15 +47,11 @@ ], "default": null } - }, - "additionalProperties": false, - "default": {"enable": true, "key": null} + } }, "modules" : { "type": "boolean", "default": true } - }, - "additionalProperties": false, - "required": ["name", "system", "spack"] + } } diff --git a/stackinator/schema/environments.json b/stackinator/schema/environments.json index 72bac65..1c802eb 100644 --- a/stackinator/schema/environments.json +++ b/stackinator/schema/environments.json @@ -7,6 +7,7 @@ "\\w[\\w-]*": { "type": "object", "required": ["compiler", "specs"], + "additionalProperties": false, "properties": { "unify": { "enum": ["when_possible", true, false], @@ -16,6 +17,7 @@ "type": "array", "items": { "type": "object", + "additionalProperties": false, "properties": { "toolchain": {"type": "string"}, "spec": {"type": "string"} @@ -35,6 +37,7 @@ "oneOf": [ { "type": "object", + "additionalProperties": false, "properties": { "spec": {"type": "string"}, "gpu": {"enum": ["cuda", "rocm", null, false]} diff --git a/unittests/test_schema.py b/unittests/test_schema.py index b882119..1fb9d4e 100644 --- a/unittests/test_schema.py +++ b/unittests/test_schema.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 +import jsonschema import pathlib - import pytest import yaml @@ -128,6 +128,16 @@ def test_environments_yaml(yaml_path): assert env["mpi"] == {"spec": "cray-mpich", "gpu": "cuda"} assert env["variants"] == ["+mpi", "+cuda"] + # check that only allowed fields are accepted + # from an example that was silently validated + with open(yaml_path / "environments.err-providers.yaml") as fid: + raw = yaml.load(fid, Loader=yaml.Loader) + with pytest.raises( + jsonschema.exceptions.ValidationError, + match=r"Additional properties are not allowed \('providers' was unexpected", + ): + schema.validator(schema.environments_schema).validate(raw) + def test_recipe_environments_yaml(recipe_paths): # validate the environments.yaml in the test recipes diff --git a/unittests/yaml/environments.err-providers.yaml b/unittests/yaml/environments.err-providers.yaml new file mode 100644 index 0000000..ba848e9 --- /dev/null +++ b/unittests/yaml/environments.err-providers.yaml @@ -0,0 +1,22 @@ +full-env: + compiler: + - toolchain: gcc + spec: gcc@11 + - toolchain: gcc + spec: gcc@12 + unify: when_possible + specs: + - osu-micro-benchmarks@5.9 + - hdf5 +mpi + mpi: + spec: cray-mpich + gpu: cuda + packages: + - perl + - git + variants: + - +mpi + - +cuda + # expect an error because 'providers' is not defined in schema. + providers: + libglx: [opengl]