-
Notifications
You must be signed in to change notification settings - Fork 280
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
Open
flyrain
wants to merge
2
commits into
apache:main
Choose a base branch
from
flyrain:yf/fix-flat-model-followups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # 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.validation import _OSSIE_SCHEMA_PATH, validate_ossie | ||
|
|
||
|
|
||
| @pytest.fixture(params=["available", "missing_file", "missing_package"]) | ||
| def schema_path(request, tmp_path, monkeypatch): | ||
| if request.param == "missing_file": | ||
| return tmp_path / "missing-schema.json" | ||
| if request.param == "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): | ||
| 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 |
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
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.