Skip to content
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

Updated Valijson to version 0.7, adding date validation for manifests. #2359

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jedieaston
Copy link
Contributor

@jedieaston jedieaston commented Jul 22, 2022


Resolves #1725.

This PR updates Valijson to version 0.7, which includes validation for dates and times in JSON Schemas. Without any other changes to winget, this has resolved my core ask from that issue, which was making sure that ReleaseDates were actually valid dates.

Valijson was updated via git subtree pull -P src/Valijson/valijson https://github.com/tristanpenman/valijson v0.7 --squash, just like last time. There was a merge conflict (since we don't have the tests for Valijson in the subtree in this repo), so I just kept the deleted files deleted.

@denelon, unless you think we need a better error message I'm happy with this being the fix. I can add an error message in an upcoming PR if you want (so that there aren't other changes mixed in with the Valijson update). If so, I'll make sure the issue doesn't close.

Behold:

PS C:\Users\easton> cat .\manifest.yaml
# yaml-language-server: $schema=https://aka.ms/winget-manifest.singleton.1.1.0.schema.json
PackageIdentifier: Microsoft.VisualStudio.2022.BuildTools
PackageVersion: 17.0.1
PackageName: Visual Studio Build Tools 2022 Current
Publisher: Microsoft
License: Copyright (c) Microsoft Corporation. All rights reserved.
LicenseUrl: https://visualstudio.microsoft.com/license-terms/
Tags:
- C++
- tools
- C#
- build
- vs
Moniker: vs2022-buildtools
ReleaseDate: "Uh, last Tuesday I think?"
ShortDescription: These Build Tools allow you to build Visual Studio projects from a command-line interface. Use of this tool requires a valid Visual Studio license.
PackageUrl: https://visualstudio.microsoft.com/
Installers:
- Architecture: x64
  InstallerUrl: https://download.visualstudio.microsoft.com/download/pr/8cea3871-c742-43fb-bf8b-8da0699ab4af/25c54d66f5cf07b14cdc0d6dab2e3d5da7ec22dead4757e69011bb2b2946e384/vs_BuildTools.exe
  InstallerSha256: 25C54D66F5CF07B14CDC0D6DAB2E3D5DA7EC22DEAD4757E69011BB2B2946E384
  InstallerType: exe
  InstallerSwitches:
    Silent: --quiet
    SilentWithProgress: --passive
    Custom: --wait
    Upgrade: update
PackageLocale: en-US
ManifestType: singleton
ManifestVersion: 1.1.0
PS C:\Users\easton> wingetdev validate .\manifest.yaml
Manifest validation failed.
Manifest Error: Schema validation failed.
Error context: <root>[ReleaseDate] Description: String should be a valid date
Error context: <root> Description: Failed to validate against schema associated with property name 'ReleaseDate'.
 File: manifest.yaml

PS C:\Users\easton>
Microsoft Reviewers: Open in CodeFlow

@jedieaston jedieaston requested a review from a team as a code owner July 22, 2022 14:32
@ghost ghost added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Jul 22, 2022
@JohnMcPMS
Copy link
Member

This doesn't have the actual subtree commits that I would expect, containing the subtree metadata that is needed for future pulls.

@jedieaston
Copy link
Contributor Author

I squashed, which is what we did last time. Do you want me to include the entire history? If so I can force push onto this branch.

@JohnMcPMS
Copy link
Member

You should --squash the subtree, but not the two commits the subtree command creates. Your last PR (#1721) has both of those commits.

@jedieaston
Copy link
Contributor Author

jedieaston commented Jul 22, 2022

Git doesn't seem to generate the two usual commits from a subtree pull --squash if there's been changes to the subtree in the repo you're pulling into, since there's a merge conflict. #2232 and #1871 both make changes to the subtree that Git can't merge since the files were also modified in the Valijson repo, and the only way I was able to resolve this was by reverting those two commits. I can reapply them onto this branch after the Valijson pull, but if you need to merge this branch into master without squashing it's going to clutter the history up.

If you have any tips on how I can fix this please let me know, this is getting farther than my Git knowledge usually goes :/ I've force pushed my most recent idea onto this branch.

@denelon
Copy link
Contributor

denelon commented Jul 22, 2022

@JohnMcPMS is my resident Git expert :)

@JohnMcPMS
Copy link
Member

I was able to do it like this:

> git subtree pull -P src/Valijson/valijson https://github.com/tristanpenman/valijson v0.7 --squash
> git rm <each of the files as they are all removes>
> git commit

I can create a new PR or push to this if you want (or you can recreate it).

94d3bfd3 Fix format regex escape sequences
25dcdb1c Merge pull request microsoft#160 from jrave/time-format-fields
dee2fa64 Support for time related format fields
5f49d77b Basic structure for format constraint
a6a4fbb5 Remove redundant call to baseline
0de61e0c Tidy up readme
1ff36254 Add script to bundle library into a single header
21322b2d Move Adapter and BasicAdapter classes to internal
23724b97 Merge pull request microsoft#159 from jackorobot/fix_poco_get_integer
72afeb1f Fixed PocoJsonValue::getInteger being limited to 32-bit integers
4d603df4 Update Authors file
0e3f48c8 Remove vendored copy of urdl
9e7dbd84 Remove outdated Xcode project files
2f6760f6 Merge pull request microsoft#154 from psigen/yaml-cpp-support
f4bbf4e0 Remove non-critical yaml-cpp files from PR.
b685584e Add optimization for find implementation.
c688aa3b Add a unit test for object member access.
76c9f40c Added simple loading utility.
66424a11 Added a column limit to the file.
f03461bb Fixed issue with YAML::Node reference usage.
7f23f369 Fix unit tests to match property tree.
698936ae Added missing dep for YAML-cpp.
328db2f6 Initial pass at yaml-cpp support.
34f75118 Add note about GCC versions to readme
5ca87a61 Remove very obsolete valgrind suppressions file
27d30658 Update vendored jsoncpp to version 1.9.5
c2822576 Update CMakeLists to use add_compile_definitions
f9701392 Remove unnecessary indentation from code snippets in readme
7d4ea908 Add boost::json example and delete problematic constructors
d34f78b4 Improve error messaging when parsing schemas and documents
dd32f66d Build tests for fuzzing
8b5f253c Tweak readme formatting
a2e39586 Remove Travis CI config
3940b361 Mention web-based demo in readme
f5f979b0 Mention boost compiler warnings in README
80afdef5 Merge pull request microsoft#150 from jonpetri/jonpetri/cmake-improvements
4622b958 Set valijson_BUILD_TESTS  OFF by default in cmake
50010fd9 Make VALIJSON_USE_EXCEPTIONS interface definition
c5dac2bc Install cmake export file
c7d5f2cb Remove valijson_INSTALL_HEADERS from cmake build
bfb5860c Fix fuzzer build
7b865438 Merge pull request microsoft#147 from keith-bennett-airmap/keith/shellcheck
1f25558c make shellcheck clean
3c185cb8 Merge pull request microsoft#145 from mporsch/smart-pointer-memory-management
828fc876 use implicit conversion of unique_ptr<T, DeleterA> to unique_ptr<const T, DeleterB>
cf841e10 use unique_ptr for memory management in constraints and subschema
4a99dd79 Add missing include
75ada05c Use strong types in external_schema example, and update README
26f3a847 Less const-ness
3eaf1bb9 Add note about VALIJSON_USE_EXCEPTIONS to the README
4990e352 Update inspector to enable and handle exceptions
af071f01 Update inspector build to work with Qt6
7b6d22f1 Update CMakeLists.txt to check for boost/json.hpp before building tests
5da89730 Merge pull request microsoft#139 from YangJiao1996/master
0f0cc2bc Always apply callback function when validating schema
9a2ebbde Merge pull request microsoft#137 from veselypeta/readme-cmake
e5530feb update README add with cmake

git-subtree-dir: src/Valijson/valijson
git-subtree-split: 94d3bfd39ad4dca1be0f700b5eea8e4234d0e7e8
@jedieaston

This comment was marked as outdated.

@jedieaston
Copy link
Contributor Author

Nope, I'm just very very silly and can't git log. I think it looks fine now if you want to take another look.

@JohnMcPMS
Copy link
Member

/azp run

@JohnMcPMS
Copy link
Member

Looks good now.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@JohnMcPMS
Copy link
Member

Looks like it is "working", but we have some invalid datetimes in our test data:

FAILED:
  REQUIRE( importOutput.str().find(Resource::LocString(Resource::String::ImportCommandReportDependencies).get()) != std::string::npos )
with expansion:
  4294967295 (0xffffffff)
  !=
  4294967295 (0xffffffff)
\x1B[91mJSON file is not valid
\x1B[91mSchema validation failed.
Error context: <root>[CreationDate] Description: String should be a valid date-time
Error context: <root> Description: Failed to validate against schema associated with property name 'CreationDate'.


at D:\a\1\s\src\AppInstallerCLITests\WorkFlow.cpp(2617)

Which brings up the next question, are we ok with a breaking change here? I don't know if it only breaks our test data, or if it would also break files in the wild. @denelon, I think this is now enforcing something that has been in the schema the whole time, but with no validation. Even so, it is a potential break in functionality, and I think we need to understand how much impact it would have before we check this in.

@denelon
Copy link
Contributor

denelon commented Jul 22, 2022

Do we have a method to test?

@JohnMcPMS
Copy link
Member

I think it would be:

  1. auditing every schema that we have
  2. finding all fields that would now be validated
  3. determining in which cases a bad value would now fail
  4. determining in which cases we would have a bad value

For 4, I'm thinking of things like files generated by tools vs by hand. And if/when those tools may have changed whether they were generating bad or good values.

I'm less concerned about manifests being rejected by winget-pkgs and more about import files, but at the same time, if we do have manifest fields that would start failing, we could really be causing some pain when this hits the service.

@Trenly
Copy link
Contributor

Trenly commented Sep 21, 2022

Thinking about this further - Is this something that can be applied only to specific manifest versions? E.g - Can 1.0.0 to 1.2.0 be validated as string, and 1.4.0 be validated as date, to prevent it from breaking existing manifests, but being enforced moving forward?

@jedieaston
Copy link
Contributor Author

My only hesitancy with that is that this has been a rule in the schema from when ReleaseDates were first a thing. The breakage is really with winget validate, not with the manifest format. If winget validate is the canonical source of truth for whether something is a valid winget manifest or not, then we probably should have some different validation rules, but if we think the schema is the source of truth then this is just better enforcement of an existing rule.

@denelon
Copy link
Contributor

denelon commented Jan 5, 2023

@jedieaston is this waiting on us for review or something else?

@yao-msft
Copy link
Contributor

yao-msft commented Jan 5, 2023

@jedieaston is this waiting on us for review or something else?

This is breaking existing tests and also we don't know how many existing manifests have the date field violation. We need to go through the entire pkgs repo and fix violating manifests before this can be merged.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Breaking-Change This is potentially a breaking change for a future major version label Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking-Change This is potentially a breaking change for a future major version Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReleaseDate is not validated as a date.
5 participants