@opensoftware/contracts 0.0.0-stage → 1.4.0

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.
Files changed (47) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +112 -2
  3. package/dist/breaking.d.ts +27 -0
  4. package/dist/breaking.js +157 -0
  5. package/dist/breaking.js.map +1 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +69 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/formats.d.ts +10 -0
  10. package/dist/formats.js +21 -0
  11. package/dist/formats.js.map +1 -0
  12. package/dist/generated/types.d.ts +636 -0
  13. package/dist/generated/types.js +2 -0
  14. package/dist/generated/types.js.map +1 -0
  15. package/dist/index.d.ts +31 -0
  16. package/dist/index.js +75 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/roundtrip.d.ts +3 -0
  19. package/dist/roundtrip.js +90 -0
  20. package/dist/roundtrip.js.map +1 -0
  21. package/dist/run-record.d.ts +18 -0
  22. package/dist/run-record.js +27 -0
  23. package/dist/run-record.js.map +1 -0
  24. package/events/asyncapi.yaml +186 -0
  25. package/events/gate-decided/gate-decided.schema.json +122 -0
  26. package/events/gate-requested/gate-requested.schema.json +135 -0
  27. package/events/pr-closed/pr-closed.schema.json +80 -0
  28. package/events/pr-opened/pr-opened.schema.json +138 -0
  29. package/events/pr-reviewed/pr-reviewed.schema.json +111 -0
  30. package/events/run-completed/run-completed.schema.json +163 -0
  31. package/events/score-recorded/score-recorded.schema.json +163 -0
  32. package/events/work-received/work-received.schema.json +182 -0
  33. package/evidence-bundle/evidence-bundle.schema.json +180 -0
  34. package/factory-definition/factory-definition.schema.json +371 -0
  35. package/openapi/openapi.json +1715 -0
  36. package/package.json +50 -3
  37. package/run-record/run-record.schema.json +179 -0
  38. package/score/score.schema.json +110 -0
  39. package/typespec/common.tsp +62 -0
  40. package/typespec/events.tsp +168 -0
  41. package/typespec/evidence-bundle.tsp +99 -0
  42. package/typespec/factory-definition.tsp +193 -0
  43. package/typespec/main.tsp +10 -0
  44. package/typespec/run-record.tsp +88 -0
  45. package/typespec/score.tsp +68 -0
  46. package/typespec/work-item.tsp +65 -0
  47. package/work-item/work-item.schema.json +129 -0
package/LICENSE ADDED
@@ -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.
package/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
1
+ ---
2
+ covers: [contracts/typespec/**, contracts/src/**, contracts/scripts/**, contracts/events/asyncapi.yaml]
3
+ ---
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ # contracts
6
+
7
+ The formats that modules share, from one TypeSpec source: JSON Schemas for every format, the AsyncAPI document of
8
+ the events, and the TypeScript package `@opensoftware/contracts`. Decisions:
9
+ [ADR 0006](../docs/decisions/0006-contracts-typespec.md), [ADR 0012](../docs/decisions/0012-contracts-toolchain.md).
10
+
11
+ ## Quick start
12
+
13
+ This quick start is scenario `SCN-CTR-001` and is tested on every change.
14
+
15
+ ```sh
16
+ npx @opensoftware/contracts validate factory-definition factory.yaml
17
+ # factory.yaml: valid factory-definition
18
+ ```
19
+
20
+ From TypeScript:
21
+
22
+ ```ts
23
+ import { type FactoryDefinition, validate } from "@opensoftware/contracts";
24
+
25
+ const problems = validate("factory-definition", document); // [] when valid, else { path, message } per problem
26
+ ```
27
+
28
+ `runSpans(record)` reads a run record as runlog writes it: each span with its decoded resource and attributes, or
29
+ `undefined` when the value is no OTLP/JSON trace export request ([ADR 0041](../docs/decisions/0041-run-record-reader.md)).
30
+
31
+ The schema files are exported at the paths in the table below, for example
32
+ `@opensoftware/contracts/work-item/work-item.schema.json`, along with `events/asyncapi.yaml`, `openapi/*` and `typespec/*`.
33
+
34
+ ## Formats
35
+
36
+ Each format has one schema, generated from `typespec/`, and fixtures that CONTRACT checks on every change.
37
+
38
+ | Format | Schema | Model | Notes |
39
+ | --- | --- | --- | --- |
40
+ | factory definition | `factory-definition/factory-definition.schema.json` | `FactoryDefinition` | `factory.yaml`. Closed objects: an unknown field is an error. |
41
+ | work item | `work-item/work-item.schema.json` | `WorkItem` | The `data` of `work.received@v1`. |
42
+ | run record | `run-record/run-record.schema.json` | `RunRecord` | OTel resource and root-span attributes; pins in `typespec/run-record.tsp`. |
43
+ | evidence bundle | `evidence-bundle/evidence-bundle.schema.json` | `EvidenceManifest` | `evidence.json` at the bundle root. |
44
+ | score | `score/score.schema.json` | `Score` | Subset of Langfuse's create-score request; factory fields in `metadata`. |
45
+ | events | `events/<event>/<event>.schema.json`, `events/asyncapi.yaml` | `WorkReceived` … `PrClosed` | CloudEvents 1.0, structured JSON. |
46
+
47
+ Wire formats (everything but the factory definition) are open: readers ignore fields they do not know, so a minor
48
+ version may add optional fields. Read `factory.yaml` with a YAML 1.2 parser: YAML 1.1 parsers turn the key `on`
49
+ into `true`.
50
+
51
+ ## Commands
52
+
53
+ | Command | What it does |
54
+ | --- | --- |
55
+ | `osf-contracts validate <format> <file>` | Check a YAML or JSON document. Prints `<file>: valid <format>`, or one `<file> <JSON Pointer>: <problem>` line per problem and exits 1. |
56
+ | `osf-contracts breaking [--base <ref>]` | Compare every schema with the last `contracts-v*` tag (or `<ref>`). A change that makes released documents invalid fails unless `contracts/package.json` has a new major version. |
57
+ | `osf-contracts roundtrip --client typescript [dir]` | Load every valid fixture under `dir` (default `contracts`) with the generated TypeScript types and compare what they write back. TypeScript is the only client (ADR 0012). |
58
+
59
+ ## Changing a format
60
+
61
+ 1. Change `typespec/`. Run `pnpm build` in `contracts/`; it regenerates the schemas, `openapi/openapi.json`,
62
+ `src/generated/types.ts` and `dist/`. `pnpm lint` fails when a committed generated file is out of date.
63
+ 2. Add or update fixtures in `<format>/fixtures/{valid,invalid}/`.
64
+ 3. A breaking change (removed or newly required field, changed type, removed enum value, closed object, tighter
65
+ bound or pattern) needs a new major version in `package.json`. Prefer a new optional field, or for events a new
66
+ type `name@v2` next to the old one.
67
+
68
+ ## Releases
69
+
70
+ release-please opens a release pull request from the Conventional Commits under `contracts/`. Merging it creates
71
+ the tag `contracts-v<version>`. The release pull request also sets the version in `openapi/openapi.json`, which
72
+ `pnpm build` copies from `package.json`, so the generated file stays current. The workflow `.github/workflows/publish-contracts.yml` then builds the package and
73
+ publishes it to npm as `@opensoftware/contracts`. npm accepts a provenance statement only from a public
74
+ repository, so the workflow adds one only when this repository is public. To publish a tag again, run the
75
+ workflow by hand with the tag. The CONTRACT check and `osf-contracts breaking` compare with the newest `contracts-v*` tag.
76
+
77
+ Only the TypeScript package exists (ADR 0012). A client for another language can be generated from
78
+ `openapi/openapi.json` with any OpenAPI generator when someone needs one.
79
+
80
+ One-time setup (no credential is ever stored in the repository):
81
+
82
+ 1. npm: the organization `opensoftware` owns the scope `@opensoftware`, under which every package of this
83
+ repository is published.
84
+ 2. GitHub: the publish job runs in the environment `npm` (Settings → Environments; GitHub creates it on the first
85
+ run).
86
+ 3. First version only: npm configures trusted publishing per existing package, so `1.0.0` needs a token. Add a
87
+ granular npm access token with read and write access to the `opensoftware` organization's packages as the
88
+ secret `NPM_TOKEN` (a repository secret or a secret of the environment `npm`), or publish `1.0.0` by hand.
89
+ 4. After the first version: on npmjs.com, package settings → Trusted publishing, add GitHub Actions with the
90
+ repository `sesigl/open-software-factory`, the workflow `publish-contracts.yml` and the environment `npm`.
91
+ Then delete the secret `NPM_TOKEN` and revoke the token. Later versions publish through OIDC only.
92
+
93
+ ## Configuration
94
+
95
+ None. The CLI reads no environment variables.
96
+
97
+ ## Scenarios
98
+
99
+ <!-- generated by make docs from features/: do not edit -->
100
+
101
+ | ID | Status | Scenario |
102
+ | --- | --- | --- |
103
+ | SCN-CTR-001 | implemented | A valid factory definition validates |
104
+ | SCN-CTR-002 | implemented | A factory definition with an unknown agent field is rejected with its path |
105
+ | SCN-CTR-003 | implemented | A run record that names its transcript, artifacts and pull request validates |
106
+ | SCN-CTR-004 | implemented | A run record without a requester is rejected with its path |
107
+ | SCN-CTR-005 | implemented | A breaking change to a released schema fails the compatibility check |
108
+ | SCN-CTR-006 | implemented | The generated TypeScript types round-trip every valid fixture |
109
+ | SCN-CTR-007 | deprecated | The generated Python client round-trips every valid fixture |
110
+ | SCN-CTR-008 | deprecated | The generated Java client round-trips every valid fixture |
111
+ | SCN-CTR-009 | implemented | A tighter form of a "exactly one of" rule fails the compatibility check |
112
+ | SCN-CTR-010 | implemented | runSpans gives each span of a run record with its resource and decoded attributes |
113
+ | SCN-CTR-011 | implemented | runSpans gives no spans for a value that is not a trace export request |
@@ -0,0 +1,27 @@
1
+ export interface Schema {
2
+ type?: string | string[];
3
+ properties?: Record<string, Schema>;
4
+ required?: string[];
5
+ enum?: unknown[];
6
+ const?: unknown;
7
+ items?: Schema;
8
+ anyOf?: Schema[];
9
+ oneOf?: Schema[];
10
+ additionalProperties?: boolean | Schema;
11
+ unevaluatedProperties?: boolean | Schema;
12
+ pattern?: string;
13
+ format?: string;
14
+ minLength?: number;
15
+ maxLength?: number;
16
+ minimum?: number;
17
+ maximum?: number;
18
+ exclusiveMinimum?: number;
19
+ exclusiveMaximum?: number;
20
+ minItems?: number;
21
+ maxItems?: number;
22
+ minProperties?: number;
23
+ maxProperties?: number;
24
+ }
25
+ export declare function breaking(baseRef: string | undefined): number;
26
+ /** Changes that make data valid under `before` invalid under `after`. */
27
+ export declare function diff(before: Schema, after: Schema, path?: string): string[];
@@ -0,0 +1,157 @@
1
+ // `osf-contracts breaking`: schema changes since the last release that make documents valid under the released
2
+ // schema invalid, unless the version in contracts/package.json has a new major number.
3
+ import { spawnSync } from "node:child_process";
4
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
5
+ import { join, relative } from "node:path";
6
+ const RELEASE_TAGS = "contracts-v*";
7
+ export function breaking(baseRef) {
8
+ const root = git(["rev-parse", "--show-toplevel"], process.cwd());
9
+ if (root === undefined)
10
+ return fail("osf-contracts breaking runs inside a Git repository");
11
+ const base = baseRef ?? git(["tag", "--list", RELEASE_TAGS, "--sort=-v:refname"], root)?.split("\n")[0];
12
+ if (!base) {
13
+ process.stdout.write(`no ${RELEASE_TAGS} release tag: nothing to compare\n`);
14
+ return 0;
15
+ }
16
+ if (git(["rev-parse", "--verify", "--quiet", `${base}^{commit}`], root) === undefined) {
17
+ return fail(`${base} is not a commit, tag or branch`);
18
+ }
19
+ const version = (at) => {
20
+ const text = at ? git(["show", `${at}:contracts/package.json`], root) : read(join(root, "contracts/package.json"));
21
+ return text ? JSON.parse(text).version : undefined;
22
+ };
23
+ const before = version(base);
24
+ const after = version();
25
+ const major = (value) => Number(value?.split(".")[0] ?? Number.NaN);
26
+ const allowed = major(after) > major(before);
27
+ const released = (git(["ls-tree", "-r", "--name-only", base, "--", "contracts"], root) ?? "")
28
+ .split("\n")
29
+ .filter(isSchema);
30
+ const current = new Set(schemaFiles(join(root, "contracts")).map((file) => relative(root, file)));
31
+ let failures = 0;
32
+ for (const file of released) {
33
+ const changes = current.has(file)
34
+ ? diff(JSON.parse(git(["show", `${base}:${file}`], root) ?? "{}"), JSON.parse(readFileSync(join(root, file), "utf8")))
35
+ : ["removed the format"];
36
+ if (changes.length === 0)
37
+ continue;
38
+ if (allowed) {
39
+ process.stdout.write(`${file}: breaking change allowed by the major version ${before} → ${after}: ${changes.join("; ")}\n`);
40
+ continue;
41
+ }
42
+ failures++;
43
+ process.stdout.write(`${file}: breaking change since ${base} without a major version (${before ?? "?"} → ${after ?? "?"}): ${changes.join("; ")}\n`);
44
+ }
45
+ if (failures === 0)
46
+ process.stdout.write(`no breaking change since ${base}\n`);
47
+ return failures === 0 ? 0 : 1;
48
+ }
49
+ /** Changes that make data valid under `before` invalid under `after`. */
50
+ export function diff(before, after, path = "") {
51
+ const changes = [];
52
+ const at = path || "the root";
53
+ const name = (key) => (path ? `${path}.${key}` : key);
54
+ const types = (schema) => [schema.type ?? []].flat().sort().join("|");
55
+ if (before.type !== undefined && types(before) !== types(after)) {
56
+ const widened = types(before) === "integer" && types(after) === "number";
57
+ if (!widened)
58
+ changes.push(`changed the type of ${at} from ${types(before)} to ${types(after) || "any"}`);
59
+ }
60
+ for (const key of Object.keys(before.properties ?? {})) {
61
+ const next = after.properties?.[key];
62
+ if (!next)
63
+ changes.push(`removed property ${name(key)}`);
64
+ else
65
+ changes.push(...diff(before.properties?.[key], next, name(key)));
66
+ }
67
+ for (const key of after.required ?? []) {
68
+ if (!(before.required ?? []).includes(key))
69
+ changes.push(`made ${name(key)} required`);
70
+ }
71
+ if (after.enum) {
72
+ for (const value of before.enum ?? []) {
73
+ if (!after.enum.some((candidate) => same(candidate, value))) {
74
+ changes.push(`removed the value ${JSON.stringify(value)} from ${at}`);
75
+ }
76
+ }
77
+ }
78
+ if ("const" in after && !("const" in before && same(before.const, after.const))) {
79
+ changes.push(`fixed ${at} to ${JSON.stringify(after.const)}`);
80
+ }
81
+ for (const keyword of ["additionalProperties", "unevaluatedProperties"]) {
82
+ const old = before[keyword];
83
+ const next = after[keyword];
84
+ if (old !== false && next === false)
85
+ changes.push(`closed ${at} to unknown properties`);
86
+ if (typeof old === "object" && typeof next === "object")
87
+ changes.push(...diff(old, next, name("*")));
88
+ }
89
+ if (before.items && after.items)
90
+ changes.push(...diff(before.items, after.items, `${path}[]`));
91
+ for (const keyword of ["anyOf", "oneOf"]) {
92
+ const old = before[keyword];
93
+ const next = after[keyword];
94
+ if (!old || !next)
95
+ continue;
96
+ if (next.length < old.length)
97
+ changes.push(`removed a form of ${at}`);
98
+ old.forEach((form, index) => {
99
+ const replaced = next[index];
100
+ if (replaced)
101
+ changes.push(...diff(form, replaced, `${path}|${index + 1}`));
102
+ });
103
+ }
104
+ changes.push(...constraints(before, after, at));
105
+ return changes;
106
+ }
107
+ /** Tighter bounds, a new or changed pattern, a new format. */
108
+ function constraints(before, after, at) {
109
+ const changes = [];
110
+ const lower = ["minLength", "minimum", "exclusiveMinimum", "minItems", "minProperties"];
111
+ const upper = ["maxLength", "maximum", "exclusiveMaximum", "maxItems", "maxProperties"];
112
+ for (const key of lower) {
113
+ const next = after[key];
114
+ if (next !== undefined && next > (before[key] ?? Number.NEGATIVE_INFINITY))
115
+ changes.push(`raised ${key} of ${at} to ${next}`);
116
+ }
117
+ for (const key of upper) {
118
+ const next = after[key];
119
+ if (next !== undefined && next < (before[key] ?? Number.POSITIVE_INFINITY))
120
+ changes.push(`lowered ${key} of ${at} to ${next}`);
121
+ }
122
+ if (after.pattern !== undefined && after.pattern !== before.pattern)
123
+ changes.push(`changed the pattern of ${at}`);
124
+ if (after.format !== undefined && after.format !== before.format)
125
+ changes.push(`required the format ${after.format} for ${at}`);
126
+ return changes;
127
+ }
128
+ function same(a, b) {
129
+ return JSON.stringify(a) === JSON.stringify(b);
130
+ }
131
+ function isSchema(file) {
132
+ return file.endsWith(".schema.json") && !file.includes("/node_modules/") && !file.includes("/fixtures/");
133
+ }
134
+ function schemaFiles(dir) {
135
+ if (!existsSync(dir))
136
+ return [];
137
+ return readdirSync(dir).flatMap((entry) => {
138
+ if (entry === "node_modules" || entry === "fixtures" || entry.startsWith("."))
139
+ return [];
140
+ const full = join(dir, entry);
141
+ if (statSync(full).isDirectory())
142
+ return schemaFiles(full);
143
+ return isSchema(full) ? [full] : [];
144
+ });
145
+ }
146
+ function read(file) {
147
+ return existsSync(file) ? readFileSync(file, "utf8") : undefined;
148
+ }
149
+ function git(args, cwd) {
150
+ const result = spawnSync("git", args, { cwd, encoding: "utf8" });
151
+ return result.status === 0 ? result.stdout.trim() : undefined;
152
+ }
153
+ function fail(message) {
154
+ process.stderr.write(`${message}\n`);
155
+ return 2;
156
+ }
157
+ //# sourceMappingURL=breaking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breaking.js","sourceRoot":"","sources":["../src/breaking.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,uFAAuF;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EA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usr/bin/env node
2
+ // osf-contracts: validate documents against the shared formats, check schema compatibility with the last release,
3
+ // and round-trip the fixtures through the generated clients.
4
+ import { readFileSync } from "node:fs";
5
+ import { parse } from "yaml";
6
+ import { breaking } from "./breaking.js";
7
+ import { FORMATS, formatNamed } from "./formats.js";
8
+ import { validate } from "./index.js";
9
+ import { CLIENTS, roundtrip } from "./roundtrip.js";
10
+ const USAGE = `Usage: osf-contracts <command>
11
+
12
+ validate <format> <file> check a YAML or JSON document; formats: ${FORMATS.map((format) => format.name).join(", ")}
13
+ breaking [--base <ref>] breaking schema changes since the last contracts-v* tag (or <ref>) without a major version
14
+ roundtrip --client <client> [dir]
15
+ load every valid fixture under dir (default contracts) with a generated client and
16
+ compare what it writes back; clients: ${CLIENTS.join(", ")}
17
+ `;
18
+ function main(argv) {
19
+ const [command, ...args] = argv;
20
+ switch (command) {
21
+ case "validate":
22
+ return validateCommand(args);
23
+ case "breaking": {
24
+ const at = args.indexOf("--base");
25
+ return breaking(at === -1 ? undefined : args[at + 1]);
26
+ }
27
+ case "roundtrip": {
28
+ const at = args.indexOf("--client");
29
+ const client = at === -1 ? undefined : args[at + 1];
30
+ const dir = args.filter((_, index) => index !== at && index !== at + 1)[0] ?? "contracts";
31
+ if (!client || !CLIENTS.includes(client))
32
+ return usage(`Give a client: ${CLIENTS.join(", ")}`);
33
+ return roundtrip(client, dir);
34
+ }
35
+ case undefined:
36
+ case "help":
37
+ case "--help":
38
+ process.stdout.write(USAGE);
39
+ return command === undefined ? 2 : 0;
40
+ default:
41
+ return usage(`Unknown command: ${command}`);
42
+ }
43
+ }
44
+ function validateCommand([name, file]) {
45
+ const format = name ? formatNamed(name) : undefined;
46
+ if (!format || !file)
47
+ return usage(name && !format ? `Unknown format: ${name}` : "Give a format and a file");
48
+ let document;
49
+ try {
50
+ document = parse(readFileSync(file, "utf8"));
51
+ }
52
+ catch (error) {
53
+ process.stdout.write(`${file}: not readable as YAML or JSON: ${error.message}\n`);
54
+ return 1;
55
+ }
56
+ const problems = validate(format, document);
57
+ for (const problem of problems)
58
+ process.stdout.write(`${file} ${problem.path}: ${problem.message}\n`);
59
+ if (problems.length > 0)
60
+ return 1;
61
+ process.stdout.write(`${file}: valid ${format.name}\n`);
62
+ return 0;
63
+ }
64
+ function usage(message) {
65
+ process.stderr.write(`${message}\n\n${USAGE}`);
66
+ return 2;
67
+ }
68
+ process.exitCode = main(process.argv.slice(2));
69
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,kHAAkH;AAClH,6DAA6D;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,KAAK,GAAG;;2EAE6D,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;yEAIjD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;CAC1F,CAAC;AAEF,SAAS,IAAI,CAAC,IAAc;IAC1B,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,UAAU;YACb,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;QAC/B,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,QAAQ,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4
+ /** Folder under contracts/. */
5
+ path: string;
6
+ /** The TypeSpec model, also the name of the generated type and class. */
7
+ model: string;
8
+ }
9
+ export declare const FORMATS: readonly Format[];
10
+ export declare function formatNamed(name: string): Format | undefined;
@@ -0,0 +1,21 @@
1
+ // The formats of the contracts: the name used on the CLI, the folder of the schema and the TypeSpec model.
2
+ const format = (path, model) => ({ name: path.split("/").pop(), path, model });
3
+ export const FORMATS = [
4
+ format("factory-definition", "FactoryDefinition"),
5
+ format("work-item", "WorkItem"),
6
+ format("run-record", "RunRecord"),
7
+ format("evidence-bundle", "EvidenceManifest"),
8
+ format("score", "Score"),
9
+ format("events/work-received", "WorkReceived"),
10
+ format("events/run-completed", "RunCompleted"),
11
+ format("events/gate-requested", "GateRequested"),
12
+ format("events/gate-decided", "GateDecided"),
13
+ format("events/score-recorded", "ScoreRecorded"),
14
+ format("events/pr-opened", "PrOpened"),
15
+ format("events/pr-reviewed", "PrReviewed"),
16
+ format("events/pr-closed", "PrClosed"),
17
+ ];
18
+ export function formatNamed(name) {
19
+ return FORMATS.find((candidate) => candidate.name === name);
20
+ }
21
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAW3G,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAY,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAEjH,MAAM,CAAC,MAAM,OAAO,GAAsB;IACxC,MAAM,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;IACjD,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC;IAC/B,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC;IACjC,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;IAC7C,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAC9C,MAAM,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAC9C,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC;IAChD,MAAM,CAAC,qBAAqB,EAAE,aAAa,CAAC;IAC5C,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC;IAChD,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC;IACtC,MAAM,CAAC,oBAAoB,EAAE,YAAY,CAAC;IAC1C,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC;CACvC,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC9D,CAAC"}