Repository navigation
Fix SDK version ordering and OrionBelt fallback validation #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b5a110
Fix SDK document ordering and schema-independent root validation
flyrain 2f7e99c
Make serialization schema test compatible with Pydantic 2.0
flyrain 74096cb
Clarify reduced validation coverage when JSON Schema is skipped
flyrain 242f435
Use document_data fixture in version serialization tests
jbonofre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
| from ossie_orionbelt.cli import _report_validation | ||
| from ossie_orionbelt.validation import _OSSIE_SCHEMA_PATH, validate_ossie | ||
|
|
||
|
|
||
| @pytest.fixture(params=["available", "missing_file", "missing_package"]) | ||
| def schema_mode(request): | ||
| return request.param | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def schema_path(schema_mode, tmp_path, monkeypatch): | ||
| if schema_mode == "missing_file": | ||
| return tmp_path / "missing-schema.json" | ||
| if schema_mode == "missing_package": | ||
| monkeypatch.setitem(sys.modules, "jsonschema", None) | ||
| return _OSSIE_SCHEMA_PATH | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "wrapper", | ||
| [None, [], {}, [{"name": "legacy", "datasets": []}]], | ||
| ) | ||
| @pytest.mark.parametrize("include_root_model", [False, True]) | ||
| def test_legacy_wrapper_is_always_invalid(schema_path, wrapper, include_root_model): | ||
| document = {"version": "0.2.0.dev0", "semantic_model": wrapper} | ||
| if include_root_model: | ||
| document.update(name="m", datasets=[{"name": "t", "source": "a.b.c"}]) | ||
|
|
||
| result = validate_ossie(document, schema_path=schema_path) | ||
|
|
||
| assert not result.valid | ||
| assert any("[LEGACY_WRAPPER]" in error for error in result.semantic_errors) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("document", [None, [], "not a mapping", 42]) | ||
| def test_non_mapping_document_is_always_invalid(schema_path, document): | ||
| result = validate_ossie(document, schema_path=schema_path) | ||
|
|
||
| assert not result.valid | ||
| assert any("[INVALID_DOCUMENT]" in error for error in result.semantic_errors) | ||
|
|
||
|
|
||
| def test_valid_flat_document_can_be_checked_without_schema(schema_path, schema_mode): | ||
| document = { | ||
| "version": "0.2.0.dev0", | ||
| "name": "m", | ||
| "datasets": [{"name": "t", "source": "a.b.c"}], | ||
| } | ||
|
|
||
| result = validate_ossie(document, schema_path=schema_path) | ||
|
|
||
| assert result.valid | ||
| assert result.schema_validation_performed == (schema_mode == "available") | ||
| expected_status = "✓ valid" if schema_mode == "available" else "skipped" | ||
| assert result.summary_lines()[0] == f" JSON Schema: {expected_status}" | ||
| if schema_mode != "available": | ||
| assert result.semantic_warnings | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "model", | ||
| [ | ||
| {"name": "m", "datasets": "not a list"}, | ||
| {"name": "m"}, | ||
| {"datasets": [{"name": "t", "source": "a.b.c"}]}, | ||
| {"name": "m", "datasets": [{"name": "t"}]}, | ||
| {"name": "m", "datasets": ["not an object"]}, | ||
| ], | ||
| ids=["datasets_type", "datasets_missing", "name_missing", "source_missing", "dataset_type"], | ||
| ) | ||
| def test_structural_validation_coverage_is_reported(schema_path, schema_mode, model): | ||
| result = validate_ossie({"version": "0.2.0.dev0", **model}, schema_path=schema_path) | ||
|
|
||
| assert not result.semantic_errors | ||
| if schema_mode == "available": | ||
| assert result.schema_validation_performed | ||
| assert not result.valid | ||
| assert result.schema_errors | ||
| assert result.summary_lines()[0] == f" JSON Schema: {len(result.schema_errors)} error(s)" | ||
| else: | ||
| assert not result.schema_validation_performed | ||
| assert result.valid | ||
| assert not result.schema_errors | ||
| assert result.semantic_warnings | ||
| assert result.summary_lines()[0] == " JSON Schema: skipped" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("error_code", ["DUPLICATE_DATASET", "UNKNOWN_DATASET_REF"]) | ||
| def test_semantic_checks_still_run_without_schema(schema_path, error_code): | ||
| document = { | ||
| "version": "0.2.0.dev0", | ||
| "name": "m", | ||
| "datasets": [{"name": "t", "source": "a.b.c"}], | ||
| } | ||
| if error_code == "DUPLICATE_DATASET": | ||
| document["datasets"].append({"name": "t", "source": "a.b.d"}) | ||
| else: | ||
| document["relationships"] = [ | ||
| { | ||
| "name": "r", | ||
| "from": "t", | ||
| "to": "missing", | ||
| "from_columns": ["id"], | ||
| "to_columns": ["id"], | ||
| } | ||
| ] | ||
|
|
||
| result = validate_ossie(document, schema_path=schema_path) | ||
|
|
||
| assert not result.valid | ||
| assert any(f"[{error_code}]" in error for error in result.semantic_errors) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("has_name", [True, False]) | ||
| def test_cli_reports_validation_coverage(schema_path, schema_mode, has_name, capsys): | ||
| document = {"version": "0.2.0.dev0", "datasets": [{"name": "t", "source": "a.b.c"}]} | ||
| if has_name: | ||
| document["name"] = "m" | ||
|
|
||
| has_errors = _report_validation( | ||
| "Ossie output", document, lambda doc: validate_ossie(doc, schema_path=schema_path) | ||
| ) | ||
| stderr = capsys.readouterr().err | ||
|
|
||
| if schema_mode != "available": | ||
| assert not has_errors | ||
| assert "JSON Schema: skipped" in stderr | ||
| assert "passed available checks (JSON Schema validation skipped)" in stderr | ||
| assert "Ossie output is valid" not in stderr | ||
| elif has_name: | ||
| assert not has_errors | ||
| assert "Ossie output is valid" in stderr | ||
| else: | ||
| assert has_errors | ||
| assert "Ossie output has validation errors" in stderr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fallback only catches two specific malformations (
ossie_dictnot a dict, or asemantic_modelwrapper).When
jsonschemais unavailable (orschema_pathpoints at a missing schema), every other structurally invalid document silently comes back asvalid=Truewith emptyschema_errors/semantic_errors. For instancedatasetsas a string instead of a list,datasetsmissing entirely,namemissing, or a dataset dict missing its requiredsourcefield.Since
_as_dict_list()already silently drops non-dict items instead of erroring, and the downstream unique-name/reference checks only ever see whatever survives that filter, none of these malformations get flagged anywhere in this fallback.Given this function docstring says it mirrors
validate.pythree layer validation, could we add guards at least the missing/malformeddatasetsand missingnamecases here too? Or explicitly document that JSON-Schema-unavailable mode is a reduced-coverage fallback and only guarantees the two checks above?I believe it's currently confusing because it reads as full validation but it isn't when
jsonschemais absent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue wasn't introduced by this PR. Fixed it anyway in the new commit. PTAL, @jbonofre !