ois-validator 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: ois-validator
3
+ Version: 0.1.0
4
+ Summary: Reference validator for the Open Intent Schema (OIS)
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Classifier: Development Status :: 2 - Pre-Alpha
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Classifier: Programming Language :: Python :: 3.14
11
+ Classifier: Programming Language :: Python :: 3.15
12
+ Classifier: Topic :: Software Development :: Quality Assurance
13
+ Requires-Dist: jsonschema[format-nongpl]>=4.26.0
14
+ Requires-Dist: rfc8785>=0.1.4
15
+ Requires-Python: >=3.13
16
+ Project-URL: Repository, https://github.com/openintentschema/validator
17
+ Project-URL: Specification, https://github.com/openintentschema/openintentschema
18
+ Description-Content-Type: text/markdown
19
+
20
+ # ois-validator
21
+
22
+ Reference validator for the [Open Intent Schema (OIS)](https://github.com/openintentschema/openintentschema).
23
+ It checks OIS records, bundles and Quality Passports against the specification and reports
24
+ every problem with its rule ID and level (spec section 11.1):
25
+
26
+ - **violation**: a MUST is broken; the input does not conform.
27
+ - **warning**: R8, R12 and R13 ask for a report; the input still conforms.
28
+ - **info**: a SHOULD is not followed.
29
+
30
+ Status: pre-alpha. The validator checks Appendix B and every rule of section 5 that can be
31
+ checked from the records at hand (R1–R5, R8–R17) and passes all conformance fixtures. Signatures
32
+ are not verified yet, so R12 reports every recorded context as self-declared.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ uvx ois-validator bundle.json # run without installing
38
+ pip install ois-validator # or install; Python 3.13 or later
39
+ ```
40
+
41
+ ## Validate
42
+
43
+ ```bash
44
+ ois-validator bundle.json passport.json
45
+ ois-validator --format json finding.json
46
+ cat bundle.json | ois-validator -
47
+ ```
48
+
49
+ The input is one JSON document per file: a single record, a bundle, or a passport as an in-toto
50
+ Statement v1. Exit code 0 means every file conforms, 1 means at least one violation, 2 means a
51
+ file could not be read.
52
+
53
+ From Python:
54
+
55
+ ```python
56
+ from ois_validator import validate
57
+
58
+ result = validate(document)
59
+ result.conforms # False if any report is a violation
60
+ result.reports # list of Report(level, rule, message, path)
61
+ ```
62
+
63
+ ## Level 1: records from JUnit XML
64
+
65
+ `ois-junit` turns the JUnit XML that almost every test framework writes (pytest `--junitxml`,
66
+ Maven Surefire, Gradle, jest-junit, Playwright, go-junit-report, ...) into a bundle, as the
67
+ quick start in spec section 11.4 describes. Run it in the Git checkout the tests ran in:
68
+
69
+ ```bash
70
+ ois-junit build/test-results/*.xml \
71
+ --namespace https://ois.acme.example \
72
+ --suite "Team Billing" \
73
+ --run "$CI_PIPELINE_URL" \
74
+ --output ois-bundle.json
75
+ ```
76
+
77
+ The bundle holds an actor for the adapter and one for the test suite, a characterization intent
78
+ in draft with one criterion per test case, an artifact per test file and an evidence record per
79
+ result with `derivedFrom: unknown`. Intent coverage is zero until intents are approved and
80
+ tests are derived from them: the honest baseline for an existing system.
81
+
82
+ - **Ids** live under `--namespace`, a URI under your domain. Criterion keys are `TC-` plus a hash
83
+ of class and test name, so they stay valid and stable for any test name. Artifact ids follow
84
+ path and content, so a changed test file becomes a new artifact.
85
+ - **Test files** come from the `file` attribute, or from the class name
86
+ (`com.acme.InvoiceTest` finds `src/test/java/com/acme/InvoiceTest.java`). Their digest is the
87
+ `sha256` of the file at `HEAD` plus `gitCommit`; a test whose file is not found gets
88
+ `gitCommit` alone.
89
+ - **Location** is `git+<origin>@<HEAD>` with any credentials removed; `--location` overrides it.
90
+ - **Timestamps:** a test suite's `timestamp` with an offset becomes `observedAt`; without an
91
+ offset, which JUnit allows, the time the report file was written is used.
92
+
93
+ `ois-junit` validates the bundle before writing it and exits with 1 instead of writing an
94
+ invalid one.
95
+
96
+ ## Development
97
+
98
+ Requires [uv](https://docs.astral.sh/uv/).
99
+
100
+ ```bash
101
+ uv sync
102
+ uv run pytest
103
+ uv run ruff check && uv run ruff format --check
104
+ uv run mypy src tests scripts
105
+ ```
106
+
107
+ The schema in `src/ois_validator/schemas/`, the examples in `tests/examples/` and the conformance
108
+ fixtures in `tests/fixtures/` are copies from the
109
+ [specification repository](https://github.com/openintentschema/openintentschema). `spec.lock`
110
+ names the commit they come from, and CI fails if a copy differs from that commit. Never edit them
111
+ here; update them from a clean checkout of the specification:
112
+
113
+ ```bash
114
+ uv run scripts/sync_spec.py ../openintentschema
115
+ ```
116
+
117
+ `tests/test_fixtures.py` runs every fixture and compares the reports for the rules listed in
118
+ `IMPLEMENTED`. Add a rule there once the validator checks it.
119
+
120
+ ## Releases
121
+
122
+ Set `version` in `pyproject.toml`, merge, then push a tag `v<version>`. The workflow
123
+ `release.yml` checks that tag and version match, builds the package, smoke-tests the wheel and
124
+ publishes it to PyPI with trusted publishing (no stored token; PyPI records signed attestations).
125
+
126
+ ## License
127
+
128
+ Apache-2.0. Commits need a DCO sign-off (`git commit -s`).
@@ -0,0 +1,109 @@
1
+ # ois-validator
2
+
3
+ Reference validator for the [Open Intent Schema (OIS)](https://github.com/openintentschema/openintentschema).
4
+ It checks OIS records, bundles and Quality Passports against the specification and reports
5
+ every problem with its rule ID and level (spec section 11.1):
6
+
7
+ - **violation**: a MUST is broken; the input does not conform.
8
+ - **warning**: R8, R12 and R13 ask for a report; the input still conforms.
9
+ - **info**: a SHOULD is not followed.
10
+
11
+ Status: pre-alpha. The validator checks Appendix B and every rule of section 5 that can be
12
+ checked from the records at hand (R1–R5, R8–R17) and passes all conformance fixtures. Signatures
13
+ are not verified yet, so R12 reports every recorded context as self-declared.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ uvx ois-validator bundle.json # run without installing
19
+ pip install ois-validator # or install; Python 3.13 or later
20
+ ```
21
+
22
+ ## Validate
23
+
24
+ ```bash
25
+ ois-validator bundle.json passport.json
26
+ ois-validator --format json finding.json
27
+ cat bundle.json | ois-validator -
28
+ ```
29
+
30
+ The input is one JSON document per file: a single record, a bundle, or a passport as an in-toto
31
+ Statement v1. Exit code 0 means every file conforms, 1 means at least one violation, 2 means a
32
+ file could not be read.
33
+
34
+ From Python:
35
+
36
+ ```python
37
+ from ois_validator import validate
38
+
39
+ result = validate(document)
40
+ result.conforms # False if any report is a violation
41
+ result.reports # list of Report(level, rule, message, path)
42
+ ```
43
+
44
+ ## Level 1: records from JUnit XML
45
+
46
+ `ois-junit` turns the JUnit XML that almost every test framework writes (pytest `--junitxml`,
47
+ Maven Surefire, Gradle, jest-junit, Playwright, go-junit-report, ...) into a bundle, as the
48
+ quick start in spec section 11.4 describes. Run it in the Git checkout the tests ran in:
49
+
50
+ ```bash
51
+ ois-junit build/test-results/*.xml \
52
+ --namespace https://ois.acme.example \
53
+ --suite "Team Billing" \
54
+ --run "$CI_PIPELINE_URL" \
55
+ --output ois-bundle.json
56
+ ```
57
+
58
+ The bundle holds an actor for the adapter and one for the test suite, a characterization intent
59
+ in draft with one criterion per test case, an artifact per test file and an evidence record per
60
+ result with `derivedFrom: unknown`. Intent coverage is zero until intents are approved and
61
+ tests are derived from them: the honest baseline for an existing system.
62
+
63
+ - **Ids** live under `--namespace`, a URI under your domain. Criterion keys are `TC-` plus a hash
64
+ of class and test name, so they stay valid and stable for any test name. Artifact ids follow
65
+ path and content, so a changed test file becomes a new artifact.
66
+ - **Test files** come from the `file` attribute, or from the class name
67
+ (`com.acme.InvoiceTest` finds `src/test/java/com/acme/InvoiceTest.java`). Their digest is the
68
+ `sha256` of the file at `HEAD` plus `gitCommit`; a test whose file is not found gets
69
+ `gitCommit` alone.
70
+ - **Location** is `git+<origin>@<HEAD>` with any credentials removed; `--location` overrides it.
71
+ - **Timestamps:** a test suite's `timestamp` with an offset becomes `observedAt`; without an
72
+ offset, which JUnit allows, the time the report file was written is used.
73
+
74
+ `ois-junit` validates the bundle before writing it and exits with 1 instead of writing an
75
+ invalid one.
76
+
77
+ ## Development
78
+
79
+ Requires [uv](https://docs.astral.sh/uv/).
80
+
81
+ ```bash
82
+ uv sync
83
+ uv run pytest
84
+ uv run ruff check && uv run ruff format --check
85
+ uv run mypy src tests scripts
86
+ ```
87
+
88
+ The schema in `src/ois_validator/schemas/`, the examples in `tests/examples/` and the conformance
89
+ fixtures in `tests/fixtures/` are copies from the
90
+ [specification repository](https://github.com/openintentschema/openintentschema). `spec.lock`
91
+ names the commit they come from, and CI fails if a copy differs from that commit. Never edit them
92
+ here; update them from a clean checkout of the specification:
93
+
94
+ ```bash
95
+ uv run scripts/sync_spec.py ../openintentschema
96
+ ```
97
+
98
+ `tests/test_fixtures.py` runs every fixture and compares the reports for the rules listed in
99
+ `IMPLEMENTED`. Add a rule there once the validator checks it.
100
+
101
+ ## Releases
102
+
103
+ Set `version` in `pyproject.toml`, merge, then push a tag `v<version>`. The workflow
104
+ `release.yml` checks that tag and version match, builds the package, smoke-tests the wheel and
105
+ publishes it to PyPI with trusted publishing (no stored token; PyPI records signed attestations).
106
+
107
+ ## License
108
+
109
+ Apache-2.0. Commits need a DCO sign-off (`git commit -s`).
@@ -0,0 +1,67 @@
1
+ [project]
2
+ name = "ois-validator"
3
+ version = "0.1.0"
4
+ description = "Reference validator for the Open Intent Schema (OIS)"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.13"
9
+ dependencies = [
10
+ "jsonschema[format-nongpl]>=4.26.0",
11
+ "rfc8785>=0.1.4",
12
+ ]
13
+ classifiers = [
14
+ "Development Status :: 2 - Pre-Alpha",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3.15",
19
+ "Topic :: Software Development :: Quality Assurance",
20
+ ]
21
+
22
+ [project.scripts]
23
+ ois-validator = "ois_validator.cli:main"
24
+ ois-junit = "ois_validator.junit_cli:main"
25
+
26
+ [project.urls]
27
+ Repository = "https://github.com/openintentschema/validator"
28
+ Specification = "https://github.com/openintentschema/openintentschema"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "mypy>=2.4.0",
33
+ "pytest>=9.2.0",
34
+ "ruff>=0.17.3",
35
+ ]
36
+
37
+ [build-system]
38
+ requires = ["uv_build>=0.13.6,<0.14"]
39
+ build-backend = "uv_build"
40
+
41
+ [tool.ruff]
42
+ line-length = 100
43
+
44
+ [tool.ruff.lint]
45
+ select = [
46
+ "E",
47
+ "F",
48
+ "W",
49
+ "I",
50
+ "B",
51
+ "UP",
52
+ "SIM",
53
+ "RUF",
54
+ ]
55
+
56
+ [tool.mypy]
57
+ strict = true
58
+
59
+ [[tool.mypy.overrides]]
60
+ module = [
61
+ "jsonschema.*",
62
+ "referencing.*",
63
+ ]
64
+ follow_untyped_imports = true
65
+
66
+ [tool.pytest.ini_options]
67
+ testpaths = ["tests"]
@@ -0,0 +1,55 @@
1
+ [project]
2
+ name = "ois-validator"
3
+ version = "0.1.0"
4
+ description = "Reference validator for the Open Intent Schema (OIS)"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.13"
9
+ dependencies = [
10
+ "jsonschema[format-nongpl]>=4.26.0",
11
+ "rfc8785>=0.1.4",
12
+ ]
13
+ classifiers = [
14
+ "Development Status :: 2 - Pre-Alpha",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3.15",
19
+ "Topic :: Software Development :: Quality Assurance",
20
+ ]
21
+
22
+ [project.scripts]
23
+ ois-validator = "ois_validator.cli:main"
24
+ ois-junit = "ois_validator.junit_cli:main"
25
+
26
+ [project.urls]
27
+ Repository = "https://github.com/openintentschema/validator"
28
+ Specification = "https://github.com/openintentschema/openintentschema"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "mypy>=2.4.0",
33
+ "pytest>=9.2.0",
34
+ "ruff>=0.17.3",
35
+ ]
36
+
37
+ [build-system]
38
+ requires = ["uv_build>=0.13.6,<0.14"]
39
+ build-backend = "uv_build"
40
+
41
+ [tool.ruff]
42
+ line-length = 100
43
+
44
+ [tool.ruff.lint]
45
+ select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF"]
46
+
47
+ [tool.mypy]
48
+ strict = true
49
+
50
+ [[tool.mypy.overrides]]
51
+ module = ["jsonschema.*", "referencing.*"]
52
+ follow_untyped_imports = true
53
+
54
+ [tool.pytest.ini_options]
55
+ testpaths = ["tests"]
@@ -0,0 +1,6 @@
1
+ """Reference validator for the Open Intent Schema (OIS)."""
2
+
3
+ from ois_validator.report import Level, Report, Result
4
+ from ois_validator.validator import validate
5
+
6
+ __all__ = ["Level", "Report", "Result", "validate"]
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from ois_validator.cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,59 @@
1
+ """Command line interface: ois-validator FILE..."""
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ from ois_validator.report import Level, Report, Result
9
+ from ois_validator.validator import validate
10
+
11
+ EXIT_CONFORMS = 0
12
+ EXIT_VIOLATION = 1
13
+ EXIT_USAGE = 2
14
+
15
+
16
+ def main(argv: list[str] | None = None) -> int:
17
+ parser = argparse.ArgumentParser(
18
+ prog="ois-validator",
19
+ description="Validate OIS records, bundles and Quality Passports.",
20
+ )
21
+ parser.add_argument("files", nargs="+", metavar="FILE", help="JSON file, or - for stdin")
22
+ parser.add_argument("--format", choices=("text", "json"), default="text")
23
+ args = parser.parse_args(argv)
24
+
25
+ results: dict[str, Result] = {}
26
+ for name in args.files:
27
+ try:
28
+ text = sys.stdin.read() if name == "-" else Path(name).read_text(encoding="utf-8")
29
+ except (OSError, UnicodeDecodeError) as error:
30
+ print(f"ois-validator: {name}: {error}", file=sys.stderr)
31
+ return EXIT_USAGE
32
+ results[name] = _validate_text(text)
33
+
34
+ if args.format == "json":
35
+ out = [
36
+ {"file": name, "conforms": r.conforms, "reports": [x.as_dict() for x in r.reports]}
37
+ for name, r in results.items()
38
+ ]
39
+ print(json.dumps(out, indent=2))
40
+ else:
41
+ for name, result in results.items():
42
+ if not result.reports:
43
+ print(f"{name}: conforms")
44
+ for report in result.reports:
45
+ print(f"{name}: {report.level} [{report.rule}] {report.path}: {report.message}")
46
+
47
+ return EXIT_CONFORMS if all(r.conforms for r in results.values()) else EXIT_VIOLATION
48
+
49
+
50
+ def _validate_text(text: str) -> Result:
51
+ try:
52
+ document = json.loads(text)
53
+ except json.JSONDecodeError as error:
54
+ return Result([Report(Level.VIOLATION, "json", f"not valid JSON: {error}", "$")])
55
+ return validate(document)
56
+
57
+
58
+ if __name__ == "__main__":
59
+ sys.exit(main())
@@ -0,0 +1,28 @@
1
+ """Digests of criteria and intents (spec section 6.4), over their RFC 8785 canonical form."""
2
+
3
+ import hashlib
4
+ from typing import Any
5
+
6
+ import rfc8785
7
+
8
+ Digest = dict[str, str] # in-toto DigestSet: algorithm -> lowercase hex
9
+
10
+ CRITERION_FIELDS = ("key", "statement", "notation", "kind", "target", "language")
11
+
12
+
13
+ def criterion_sha256(criterion: dict[str, Any]) -> str:
14
+ """Over the criterion's own key, statement, notation, kind, target and language."""
15
+ fields = {k: criterion[k] for k in CRITERION_FIELDS if k in criterion}
16
+ return hashlib.sha256(rfc8785.dumps(fields)).hexdigest()
17
+
18
+
19
+ def intent_sha256(intent: dict[str, Any]) -> str:
20
+ """Over the intent without its top-level digest and status, criterion digests included."""
21
+ content = {k: v for k, v in intent.items() if k not in ("digest", "status")}
22
+ return hashlib.sha256(rfc8785.dumps(content)).hexdigest()
23
+
24
+
25
+ def equal(a: Digest, b: Digest) -> bool:
26
+ """Two digest sets name the same content: they share an algorithm and agree on each."""
27
+ shared = a.keys() & b.keys()
28
+ return bool(shared) and all(a[name] == b[name] for name in shared)