fora-protocol 1.0.3__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.
Files changed (30) hide show
  1. fora_protocol-1.0.3/LICENSE +201 -0
  2. fora_protocol-1.0.3/PKG-INFO +57 -0
  3. fora_protocol-1.0.3/README.md +44 -0
  4. fora_protocol-1.0.3/fora_protocol.egg-info/PKG-INFO +57 -0
  5. fora_protocol-1.0.3/fora_protocol.egg-info/SOURCES.txt +28 -0
  6. fora_protocol-1.0.3/fora_protocol.egg-info/dependency_links.txt +1 -0
  7. fora_protocol-1.0.3/fora_protocol.egg-info/requires.txt +1 -0
  8. fora_protocol-1.0.3/fora_protocol.egg-info/top_level.txt +2 -0
  9. fora_protocol-1.0.3/pyproject.toml +38 -0
  10. fora_protocol-1.0.3/setup.cfg +4 -0
  11. fora_protocol-1.0.3/tests/test_comment_first_paragraph.py +142 -0
  12. fora_protocol-1.0.3/tests/test_forward_compat.py +59 -0
  13. fora_protocol-1.0.3/tests/test_money_pattern.py +100 -0
  14. fora_protocol-1.0.3/tests/test_money_roundtrip.py +34 -0
  15. fora_protocol-1.0.3/tests/test_numeric_wire_forms.py +77 -0
  16. fora_protocol-1.0.3/tests/test_parity.py +44 -0
  17. fora_protocol-1.0.3/tests/test_snake_fields.py +32 -0
  18. fora_protocol-1.0.3/tests/test_unique_subclass.py +42 -0
  19. fora_protocol-1.0.3/tests/test_wire_policy.py +123 -0
  20. fora_protocol-1.0.3/vocab/functiontokens.py +85 -0
  21. fora_protocol-1.0.3/vocab/geographytokens.py +38 -0
  22. fora_protocol-1.0.3/vocab/pricingunits.py +64 -0
  23. fora_protocol-1.0.3/vocab/py.typed +0 -0
  24. fora_protocol-1.0.3/vocab/quotametrics.py +48 -0
  25. fora_protocol-1.0.3/vocab/usertypes.py +47 -0
  26. fora_protocol-1.0.3/wire/base.py +106 -0
  27. fora_protocol-1.0.3/wire/models.py +2145 -0
  28. fora_protocol-1.0.3/wire/names.py +50 -0
  29. fora_protocol-1.0.3/wire/py.typed +0 -0
  30. fora_protocol-1.0.3/wire/unique.py +12 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 FORA-Protocol contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: fora-protocol
3
+ Version: 1.0.3
4
+ Summary: Generated types export for Python: Pydantic v2 models (wire.models, extending wire.base.WireModel) + registered vocabulary constants (vocab.*), generated from the proto via JSON Schema.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://fora-protocol.org
7
+ Project-URL: Source, https://github.com/FORA-Protocol/protocol
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pydantic>=2.0
12
+ Dynamic: license-file
13
+
14
+ # Generated Python types export
15
+
16
+ Generated from [`proto/`](../../proto) via JSON Schema. **Do not edit by hand** —
17
+ regenerate with `scripts/gen-sdk-types.sh` and commit the result (CI drift-gates it).
18
+
19
+ A **types export**, not a full SDK: Pydantic models + registered vocabulary constants.
20
+ Transport (Connect), request signing (RFC 9421), and key management are a separate,
21
+ hand-written SDK layer.
22
+
23
+ Contents:
24
+ - `wire/base.py` — **`WireModel`**, the single base class every model extends (the one
25
+ seam: SDK-wide config + your override point; neutral name so a protocol rename never
26
+ touches consumer imports). **Hand-written, not regenerated.**
27
+ - `wire/models.py` — Pydantic v2 models for every message (`License`, `Pricing`,
28
+ `LicenseTerm`, `Offer`, …), all extending `WireModel`. They carry **shape + per-field
29
+ validation**: enums (named from the proto descriptor, `*_UNSPECIFIED` dropped),
30
+ string patterns, length/item bounds. Nested messages reference the same model
31
+ (`LicenseTerm.license` is a `License`), so the whole tree hydrates as typed models.
32
+ **Cross-field rules are NOT here** — enforced server-side by the Exchange/Broker.
33
+ - `vocab/` — registered vocabulary constants per axis (`pricingunits`, …) with
34
+ `is_registered()`, plus the accepted aliases authored beside the tokens (`ALIASES`,
35
+ `canonical()` — an exact lookup; the SDK folds case before it looks up).
36
+
37
+ ```python
38
+ from wire.models import LicenseTerm, License
39
+ from wire.base import WireModel # subclass this to customize ALL models at once
40
+
41
+ term = LicenseTerm.model_validate(incoming_json) # raises on shape/per-field violations
42
+ assert isinstance(term.license, License) # full nested hierarchy, typed
43
+ ```
44
+
45
+ Install (from this directory): `pip install .`
46
+
47
+ ## Import names and PyPI
48
+
49
+ The distribution is published on PyPI as `fora-protocol`. Its import packages are the
50
+ generic top-level names `wire` and `vocab`, so it can collide with any other distribution
51
+ that owns either name; install it into an environment that does not. This is a deliberate
52
+ tradeoff: a rename to a namespaced package would break every consumer that installs from
53
+ this repository by git ref, so the names stay as they are.
54
+
55
+ ```sh
56
+ pip install fora-protocol
57
+ ```
@@ -0,0 +1,44 @@
1
+ # Generated Python types export
2
+
3
+ Generated from [`proto/`](../../proto) via JSON Schema. **Do not edit by hand** —
4
+ regenerate with `scripts/gen-sdk-types.sh` and commit the result (CI drift-gates it).
5
+
6
+ A **types export**, not a full SDK: Pydantic models + registered vocabulary constants.
7
+ Transport (Connect), request signing (RFC 9421), and key management are a separate,
8
+ hand-written SDK layer.
9
+
10
+ Contents:
11
+ - `wire/base.py` — **`WireModel`**, the single base class every model extends (the one
12
+ seam: SDK-wide config + your override point; neutral name so a protocol rename never
13
+ touches consumer imports). **Hand-written, not regenerated.**
14
+ - `wire/models.py` — Pydantic v2 models for every message (`License`, `Pricing`,
15
+ `LicenseTerm`, `Offer`, …), all extending `WireModel`. They carry **shape + per-field
16
+ validation**: enums (named from the proto descriptor, `*_UNSPECIFIED` dropped),
17
+ string patterns, length/item bounds. Nested messages reference the same model
18
+ (`LicenseTerm.license` is a `License`), so the whole tree hydrates as typed models.
19
+ **Cross-field rules are NOT here** — enforced server-side by the Exchange/Broker.
20
+ - `vocab/` — registered vocabulary constants per axis (`pricingunits`, …) with
21
+ `is_registered()`, plus the accepted aliases authored beside the tokens (`ALIASES`,
22
+ `canonical()` — an exact lookup; the SDK folds case before it looks up).
23
+
24
+ ```python
25
+ from wire.models import LicenseTerm, License
26
+ from wire.base import WireModel # subclass this to customize ALL models at once
27
+
28
+ term = LicenseTerm.model_validate(incoming_json) # raises on shape/per-field violations
29
+ assert isinstance(term.license, License) # full nested hierarchy, typed
30
+ ```
31
+
32
+ Install (from this directory): `pip install .`
33
+
34
+ ## Import names and PyPI
35
+
36
+ The distribution is published on PyPI as `fora-protocol`. Its import packages are the
37
+ generic top-level names `wire` and `vocab`, so it can collide with any other distribution
38
+ that owns either name; install it into an environment that does not. This is a deliberate
39
+ tradeoff: a rename to a namespaced package would break every consumer that installs from
40
+ this repository by git ref, so the names stay as they are.
41
+
42
+ ```sh
43
+ pip install fora-protocol
44
+ ```
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: fora-protocol
3
+ Version: 1.0.3
4
+ Summary: Generated types export for Python: Pydantic v2 models (wire.models, extending wire.base.WireModel) + registered vocabulary constants (vocab.*), generated from the proto via JSON Schema.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://fora-protocol.org
7
+ Project-URL: Source, https://github.com/FORA-Protocol/protocol
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pydantic>=2.0
12
+ Dynamic: license-file
13
+
14
+ # Generated Python types export
15
+
16
+ Generated from [`proto/`](../../proto) via JSON Schema. **Do not edit by hand** —
17
+ regenerate with `scripts/gen-sdk-types.sh` and commit the result (CI drift-gates it).
18
+
19
+ A **types export**, not a full SDK: Pydantic models + registered vocabulary constants.
20
+ Transport (Connect), request signing (RFC 9421), and key management are a separate,
21
+ hand-written SDK layer.
22
+
23
+ Contents:
24
+ - `wire/base.py` — **`WireModel`**, the single base class every model extends (the one
25
+ seam: SDK-wide config + your override point; neutral name so a protocol rename never
26
+ touches consumer imports). **Hand-written, not regenerated.**
27
+ - `wire/models.py` — Pydantic v2 models for every message (`License`, `Pricing`,
28
+ `LicenseTerm`, `Offer`, …), all extending `WireModel`. They carry **shape + per-field
29
+ validation**: enums (named from the proto descriptor, `*_UNSPECIFIED` dropped),
30
+ string patterns, length/item bounds. Nested messages reference the same model
31
+ (`LicenseTerm.license` is a `License`), so the whole tree hydrates as typed models.
32
+ **Cross-field rules are NOT here** — enforced server-side by the Exchange/Broker.
33
+ - `vocab/` — registered vocabulary constants per axis (`pricingunits`, …) with
34
+ `is_registered()`, plus the accepted aliases authored beside the tokens (`ALIASES`,
35
+ `canonical()` — an exact lookup; the SDK folds case before it looks up).
36
+
37
+ ```python
38
+ from wire.models import LicenseTerm, License
39
+ from wire.base import WireModel # subclass this to customize ALL models at once
40
+
41
+ term = LicenseTerm.model_validate(incoming_json) # raises on shape/per-field violations
42
+ assert isinstance(term.license, License) # full nested hierarchy, typed
43
+ ```
44
+
45
+ Install (from this directory): `pip install .`
46
+
47
+ ## Import names and PyPI
48
+
49
+ The distribution is published on PyPI as `fora-protocol`. Its import packages are the
50
+ generic top-level names `wire` and `vocab`, so it can collide with any other distribution
51
+ that owns either name; install it into an environment that does not. This is a deliberate
52
+ tradeoff: a rename to a namespaced package would break every consumer that installs from
53
+ this repository by git ref, so the names stay as they are.
54
+
55
+ ```sh
56
+ pip install fora-protocol
57
+ ```
@@ -0,0 +1,28 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ fora_protocol.egg-info/PKG-INFO
5
+ fora_protocol.egg-info/SOURCES.txt
6
+ fora_protocol.egg-info/dependency_links.txt
7
+ fora_protocol.egg-info/requires.txt
8
+ fora_protocol.egg-info/top_level.txt
9
+ tests/test_comment_first_paragraph.py
10
+ tests/test_forward_compat.py
11
+ tests/test_money_pattern.py
12
+ tests/test_money_roundtrip.py
13
+ tests/test_numeric_wire_forms.py
14
+ tests/test_parity.py
15
+ tests/test_snake_fields.py
16
+ tests/test_unique_subclass.py
17
+ tests/test_wire_policy.py
18
+ vocab/functiontokens.py
19
+ vocab/geographytokens.py
20
+ vocab/pricingunits.py
21
+ vocab/py.typed
22
+ vocab/quotametrics.py
23
+ vocab/usertypes.py
24
+ wire/base.py
25
+ wire/models.py
26
+ wire/names.py
27
+ wire/py.typed
28
+ wire/unique.py
@@ -0,0 +1 @@
1
+ pydantic>=2.0
@@ -0,0 +1,2 @@
1
+ vocab
2
+ wire
@@ -0,0 +1,38 @@
1
+ # Packaging for the generated FORA Python types export (mirrors gen/ts/package.json).
2
+ # wire/models.py and vocab/* are generated from proto/ by scripts/gen-sdk-types.sh — do
3
+ # not edit them by hand. Only this file, README.md, and the hand-written wire/base.py
4
+ # seam are authored.
5
+ [build-system]
6
+ requires = ["setuptools>=77"] # license-files (PEP 639)
7
+ build-backend = "setuptools.build_meta"
8
+
9
+ [project]
10
+ name = "fora-protocol"
11
+ version = "1.0.3"
12
+ description = "Generated types export for Python: Pydantic v2 models (wire.models, extending wire.base.WireModel) + registered vocabulary constants (vocab.*), generated from the proto via JSON Schema."
13
+ readme = "README.md"
14
+ requires-python = ">=3.9"
15
+ license = "Apache-2.0"
16
+ license-files = ["LICENSE"]
17
+ # Pydantic for the message models; vocabulary constants are pure string literals.
18
+ dependencies = [
19
+ "pydantic>=2.0",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://fora-protocol.org"
24
+ Source = "https://github.com/FORA-Protocol/protocol"
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["."]
28
+ # PEP 420 namespace packages. Pydantic models + base at wire.* (neutral name, no
29
+ # protocol coupling); vocabulary constants at vocab.pricingunits (etc.).
30
+ namespaces = true
31
+ include = ["wire*", "vocab*"]
32
+
33
+ # The inline-types marker, one per namespace package (a namespace package has no
34
+ # __init__.py to carry it), in the wheel and the sdist.
35
+ [tool.setuptools.package-data]
36
+ wire = ["py.typed"]
37
+ vocab = ["py.typed"]
38
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,142 @@
1
+ """A proto comment's FIRST paragraph must survive into the generated clients.
2
+
3
+ protoschema splits a multi-paragraph proto comment: paragraph one becomes the JSON
4
+ Schema `title`, the remainder becomes `description`. The merge step used to remove every
5
+ key named `title` from the intermediate document, which cost two different things:
6
+
7
+ * the head of every multi-paragraph comment. `Offer.signature` reached Pydantic and Zod
8
+ describing the canonical-signing rules without ever saying the field IS the signature
9
+ or that it is required. Go was unaffected — fora.pb.go carries the whole comment — so
10
+ the loss was visible only in these two clients.
11
+ * three whole FIELDS. `Offer.title`, `ResourceEntry.title` and `UsageAsset.title` are
12
+ proto fields whose NAME is `title`, so a blanket key-strip deleted them from
13
+ `properties` outright. No corpus case populates any of them, so the canonical
14
+ round-trip gate saw nothing to lose and stayed green.
15
+
16
+ merge_schema.assert_no_surviving_titles is the structural guard: it fails the build when
17
+ a title reaches the write, so a site the resolver does not reach can no longer ship. This
18
+ file is the behavioral half, over the COMMITTED output a consumer actually installs.
19
+ Titles that merely restate the field's own enum or message type carry nothing the comment
20
+ said and are still dropped; that is asserted too, so a fix cannot over-correct into noise.
21
+
22
+ Run: PYTHONPATH=gen/python python3 -m pytest gen/python/tests/test_comment_first_paragraph.py -q
23
+ """
24
+
25
+ import re
26
+ import sys
27
+ from pathlib import Path
28
+
29
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
30
+
31
+ from wire import models # noqa: E402
32
+
33
+ # gen/python/tests -> gen/python -> gen -> <repo root>
34
+ _REPO_ROOT = Path(__file__).resolve().parents[3]
35
+ _ZOD = _REPO_ROOT / "gen" / "ts" / "wire" / "schemas.ts"
36
+
37
+ #: Fields whose NAME is `title`. Present in the proto, and absent from both clients until
38
+ #: the strip was replaced. One entry per message that declares one.
39
+ TITLE_FIELDS = ("Offer", "ResourceEntry", "UsageAsset")
40
+
41
+ #: (model, field, the comment head that must open the generated description). Each is a
42
+ #: field whose proto comment carries a blank line, so protoschema routed its first
43
+ #: paragraph into `title`. Spot checks, not the whole set — the build-time guard owns
44
+ #: completeness; these name the cases a reader can check against the .proto by eye.
45
+ FIRST_PARAGRAPH_HEADS = (
46
+ ("Offer", "signature", "REQUIRED. Hex-encoded detached Ed25519 signature over the canonical"),
47
+ ("Requester", "scopes", "Entitlement scopes. Declare what the requester can access."),
48
+ ("License", "uri", "Canonical identity of the license document (RFC 3986)."),
49
+ ("ResourceQuery", "supported_profiles", "Domain extension profiles the caller understands."),
50
+ ("Pricing", "unit", 'Metering basis — the "per what" of PER_UNIT pricing.'),
51
+ )
52
+
53
+ #: (model, field, the type-derived title that must NOT appear). protoschema fills `title`
54
+ #: in from the field's enum type when the comment is a single paragraph, so prepending it
55
+ #: would inject the type's name into a field whose comment lost nothing.
56
+ TYPE_DERIVED_TITLES = (
57
+ ("DisputeRequest", "reason", "Dispute Reason"),
58
+ ("Pricing", "model", "Pricing Model"),
59
+ ("WellKnownManifest", "role", "Role"),
60
+ ("ResourceIdentity", "c2pa_status", "C2PA Status"),
61
+ )
62
+
63
+
64
+ def _description(model_name: str, field_name: str) -> str:
65
+ cls = getattr(models, model_name)
66
+ field = cls.model_fields[field_name]
67
+ assert field.description is not None, f"{model_name}.{field_name} carries no description"
68
+ return field.description
69
+
70
+
71
+ def _collapsed(text: str) -> str:
72
+ """Whitespace-insensitive form. A proto comment wraps across `//` lines, so the
73
+ generated description carries the author's line breaks; only the words are the rule."""
74
+ return re.sub(r"\s+", " ", text).strip()
75
+
76
+
77
+ def _zod_schema_of(source: str, message: str) -> str:
78
+ """One generated Zod schema. json-schema-to-zod emits each on a single line."""
79
+ marker = f"export const {message}Schema = "
80
+ start = source.index(marker)
81
+ return source[start : source.index("\n", start)]
82
+
83
+
84
+ def test_fields_named_title_reach_the_generated_models():
85
+ missing = [m for m in TITLE_FIELDS if "title" not in getattr(models, m).model_fields]
86
+ assert not missing, (
87
+ "proto field `title` is absent from the generated Pydantic models "
88
+ f"({missing}) — a key-strip is deleting the field, not a JSON-Schema keyword"
89
+ )
90
+
91
+
92
+ def test_fields_named_title_reach_the_generated_zod_schemas():
93
+ source = _ZOD.read_text(encoding="utf-8")
94
+ missing = [m for m in TITLE_FIELDS if '"title"' not in _zod_schema_of(source, m)]
95
+ assert not missing, (
96
+ "proto field `title` is absent from the generated Zod schemas "
97
+ f"({missing}) — a key-strip is deleting the field, not a JSON-Schema keyword"
98
+ )
99
+
100
+
101
+ def test_first_comment_paragraph_opens_the_generated_description():
102
+ for model_name, field_name, head in FIRST_PARAGRAPH_HEADS:
103
+ description = _collapsed(_description(model_name, field_name))
104
+ assert description.startswith(_collapsed(head)), (
105
+ f"{model_name}.{field_name} description does not open with its comment's "
106
+ f"first paragraph — got {description[:80]!r}"
107
+ )
108
+
109
+
110
+ def test_type_derived_titles_are_not_prepended():
111
+ for model_name, field_name, type_title in TYPE_DERIVED_TITLES:
112
+ description = _description(model_name, field_name)
113
+ # The RAW description, and the paragraph break, are both load-bearing here: a
114
+ # carried title is prepended as its own paragraph, so that is the shape to refuse.
115
+ # A collapsed comparison would fire on WellKnownManifest.role, whose genuine
116
+ # comment legitimately opens with the word "Role".
117
+ assert not description.startswith(f"{type_title}\n\n"), (
118
+ f"{model_name}.{field_name} description opens with its own TYPE name "
119
+ f"({type_title!r}) as a carried paragraph — a title protoschema derived from "
120
+ "the type restates the type and must stay dropped"
121
+ )
122
+ assert description.strip() != type_title, (
123
+ f"{model_name}.{field_name} description IS its own type name ({type_title!r})"
124
+ )
125
+
126
+
127
+ def test_message_comment_first_paragraph_reaches_the_zod_schemas():
128
+ """The message-level half, which only the Zod export renders.
129
+
130
+ datamodel-code-generator emits no class docstring, so a message's description is
131
+ invisible in models.py; json-schema-to-zod emits it as the schema's own .describe(),
132
+ where the loss was observable.
133
+ """
134
+ source = _ZOD.read_text(encoding="utf-8")
135
+ for head in (
136
+ "Offer — A single resource offer from an Exchange.",
137
+ "LicenseTerm — Universal licensing unit.",
138
+ "Requester — Universal identity for any FORA client.",
139
+ ):
140
+ assert head in source, (
141
+ f"message comment head {head!r} is missing from the generated Zod schemas"
142
+ )
@@ -0,0 +1,59 @@
1
+ """Direct behavioral regression for wire forward-compatibility.
2
+
3
+ Core invariant: an UNKNOWN top-level field (a field a newer protocol version
4
+ adds that this older client has never seen) MUST be ACCEPTED and DROPPED — not
5
+ rejected, not retained. This is the whole point of WireModel's
6
+ `model_config = ConfigDict(extra="ignore")`: an older SDK keeps parsing a newer
7
+ message instead of failing closed.
8
+
9
+ This exercises the REAL generated models (wire.models) through their public
10
+ parse surface (model_validate on proto-JSON dicts, routed through
11
+ wire.base.WireModel). No corpus, no source scanning — behavior only.
12
+
13
+ Run: PYTHONPATH=gen/python python3 -m pytest gen/python/tests/test_forward_compat.py -q
14
+
15
+ It FAILS today: every generated model carries its own
16
+ `model_config = ConfigDict(extra='forbid')`, which SHADOWS the WireModel
17
+ extra='ignore' seam in Pydantic v2, so the unknown field raises ValidationError
18
+ instead of being dropped.
19
+ """
20
+ import pytest
21
+ from pydantic import ValidationError
22
+
23
+ import wire.models as models
24
+
25
+ # A key no protocol version defines — stands in for "a field a newer version added".
26
+ UNKNOWN_KEY = "__unknown_future_field__"
27
+
28
+ # Representative models with a minimally-valid proto-JSON body (only what the
29
+ # model REQUIRES) so the sole variable under test is the extra unknown field.
30
+ # (case_id, ModelClass, base_instance)
31
+ DROP_CASES = [
32
+ ("Cost", models.Cost, {"amount": "19.99"}),
33
+ ("Delegation", models.Delegation, {"principal_id": "user@acme.com"}),
34
+ ("Pricing", models.Pricing, {"model": models.PricingModel.PRICING_MODEL_FREE.value}),
35
+ ]
36
+
37
+
38
+ @pytest.mark.parametrize(
39
+ "cls,base",
40
+ [(cls, base) for _, cls, base in DROP_CASES],
41
+ ids=[cid for cid, *_ in DROP_CASES],
42
+ )
43
+ def test_unknown_top_level_field_accepted_and_dropped(cls, base):
44
+ instance = {**base, UNKNOWN_KEY: "a value from the future"}
45
+
46
+ # MUST NOT raise: an unknown top-level field is accepted (forward-compat).
47
+ parsed = cls.model_validate(instance)
48
+
49
+ # MUST be dropped, not retained: it is absent from the model and its dump.
50
+ assert not hasattr(parsed, UNKNOWN_KEY)
51
+ assert UNKNOWN_KEY not in parsed.model_dump()
52
+
53
+
54
+ def test_closed_enum_discriminator_still_rejects_bogus_value():
55
+ # Guard: opening up unknown *top-level* fields must not over-open a CLOSED
56
+ # enum. Pricing.model is a closed PricingModel enum; a bogus value must
57
+ # still raise (before AND after the fix).
58
+ with pytest.raises(ValidationError):
59
+ models.Pricing.model_validate({"model": "PRICING_MODEL_BOGUS"})