swarmauri_tests_lean_proof 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,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 reasonable and customary use in describing the
141
+ origin of the Work and 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 Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
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 [2025] [Jacob Stewart @ Swarmauri]
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,4 @@
1
+ Swarmauri SDK
2
+
3
+ This package is part of the Swarmauri SDK and is distributed under the
4
+ Apache License, Version 2.0. See LICENSE for the license terms.
@@ -0,0 +1,336 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_tests_lean_proof
3
+ Version: 0.1.0
4
+ Summary: Pytest plugin for Lean theorem audits and packaged proof sources.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Keywords: swarmauri,pytest,lean,formal verification,proof packaging
9
+ Author: Jacob Stewart
10
+ Author-email: jacob@swarmauri.com
11
+ Requires-Python: >=3.10,<3.15
12
+ Classifier: Development Status :: 1 - Planning
13
+ Classifier: Framework :: Pytest
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Requires-Dist: pytest (>=8.0)
20
+ Project-URL: Repository, https://github.com/swarmauri/swarmauri-sdk
21
+ Description-Content-Type: text/markdown
22
+
23
+ # swarmauri_tests_lean_proof
24
+
25
+ <!-- readme-standards:begin branding -->
26
+ <p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
27
+ <p align="center"><strong>swarmauri_tests_lean_proof</strong></p>
28
+ <p align="center">Pytest plugin for Lean theorem audits and packaged proof sources.</p>
29
+ <p align="center">
30
+ <a href="https://pypi.org/project/swarmauri_tests_lean_proof/"><img alt="pypi: swarmauri_tests_lean_proof unpublished" src="https://img.shields.io/static/v1?label=pypi&amp;message=swarmauri_tests_lean_proof%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
31
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/pyproject.toml"><img alt="Source version: 0.1.0" src="https://img.shields.io/static/v1?label=Source%20version&amp;message=0.1.0&amp;labelColor=292421&amp;color=994525"></a>
32
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.15" src="https://img.shields.io/static/v1?label=Python&amp;message=%3E%3D3.10%2C%3C3.15&amp;labelColor=292421&amp;color=994525"></a>
33
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/pyproject.toml"><img alt="Layer: tests" src="https://img.shields.io/static/v1?label=Layer&amp;message=tests&amp;labelColor=292421&amp;color=994525"></a>
34
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md#lifecycle-and-migration"><img alt="Lifecycle: experimental" src="https://img.shields.io/static/v1?label=Lifecycle&amp;message=experimental&amp;labelColor=292421&amp;color=67437E"></a>
35
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&amp;message=Apache-2.0&amp;labelColor=292421&amp;color=994525"></a>
36
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&amp;message=attribution&amp;labelColor=292421&amp;color=994525"></a>
37
+ </p>
38
+ <p align="center">
39
+ <a href="https://pypi.org/project/swarmauri_tests_lean_proof/"><img alt="pypi downloads: swarmauri_tests_lean_proof: unpublished" src="https://img.shields.io/static/v1?label=pypi%20downloads&amp;message=swarmauri_tests_lean_proof%3A%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
40
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md"><img alt="README hits: swarmauri_tests_lean_proof" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/95-tests/swarmauri_tests_lean_proof/README.md.svg?label=README%20hits&amp;labelColor=292421&amp;color=08704E"></a>
41
+ </p>
42
+ <p align="center">
43
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&amp;message=CI%20gate&amp;labelColor=292421&amp;color=67437E"></a>
44
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&amp;message=example%20source&amp;labelColor=292421&amp;color=67437E"></a>
45
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&amp;message=not%20certified&amp;labelColor=292421&amp;color=805500"></a>
46
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&amp;message=repository%20policy&amp;labelColor=292421&amp;color=67437E"></a>
47
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&amp;message=source%20and%20CI&amp;labelColor=292421&amp;color=67437E"></a>
48
+ </p>
49
+ <p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
50
+ <!-- readme-standards:end branding -->
51
+
52
+ ---
53
+
54
+ ## Overview
55
+
56
+ ### Summary
57
+
58
+ A pytest plugin for compiling Lean proofs, auditing named theorems, and checking proof sources in Python distributions.
59
+
60
+ ### Why This Package
61
+
62
+ Use the same assertions across packages that ship Lean proofs.
63
+
64
+ ### When to Use
65
+
66
+ Add the plugin to your development dependencies when a package ships Lean proof sources.
67
+
68
+ ### Features
69
+
70
+ - Verify named Lean theorem audits against an axiom allowlist.
71
+ - Compare proof sources byte for byte with wheel and source distribution entries.
72
+ - Require Lean explicitly in CI and optionally prepare Lake dependencies and Mathlib cache.
73
+
74
+ ### Non-Goals
75
+
76
+ Runtime numeric behavior is covered by the package's Python tests.
77
+
78
+ ---
79
+
80
+ ## Getting Started
81
+
82
+ ### Prerequisites
83
+
84
+ Use Python 3.10 through 3.14. Proof checks use Lake and the proof project's pinned Lean toolchain. Artifact checks use uv.
85
+
86
+ ### Installation
87
+
88
+ #### Install with uv
89
+
90
+ <!-- readme-standards:begin installation.uv -->
91
+ `swarmauri_tests_lean_proof` is not declared published. From the source checkout:
92
+
93
+ ```bash
94
+ uv pip install .
95
+ ```
96
+ <!-- readme-standards:end installation.uv -->
97
+
98
+ #### Install with pip
99
+
100
+ <!-- readme-standards:begin installation.pip -->
101
+ `swarmauri_tests_lean_proof` is not declared published. From the source checkout:
102
+
103
+ ```bash
104
+ python -m pip install .
105
+ ```
106
+ <!-- readme-standards:end installation.pip -->
107
+
108
+ #### Install with Poetry
109
+
110
+ <!-- readme-standards:begin installation.poetry -->
111
+ `swarmauri_tests_lean_proof` is not declared published. From a separate Poetry project, replace the path with your checkout:
112
+
113
+ ```bash
114
+ poetry add /path/to/swarmauri_tests_lean_proof
115
+ ```
116
+ <!-- readme-standards:end installation.poetry -->
117
+
118
+ ### Quick Start
119
+
120
+ #### Example
121
+
122
+ <!-- readme-standards:begin example.quick-start -->
123
+ Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/docs/readme/quick_start.py).
124
+
125
+ ```python
126
+ from importlib.metadata import entry_points
127
+
128
+ assert any(
129
+ plugin.name == "swarmauri_tests_lean_proof"
130
+ for plugin in entry_points(group="pytest11")
131
+ )
132
+ ```
133
+ <!-- readme-standards:end example.quick-start -->
134
+
135
+ #### Expected Result
136
+
137
+ The assertion succeeds when the installed package exposes its pytest entry point.
138
+
139
+ ---
140
+
141
+ ## Usage
142
+
143
+ ### Common Workflows
144
+
145
+ <!-- readme-standards:begin example.usage -->
146
+ Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/docs/readme/usage.py).
147
+
148
+ ```python
149
+ from pathlib import Path
150
+
151
+ import pytest
152
+
153
+
154
+ @pytest.mark.lean_proof
155
+ def test_metric_axioms(lean_proof, lean_project):
156
+ package = Path(__file__).resolve().parent
157
+ source = package / "example_metric" / "proofs" / "Metric.lean"
158
+ lean_proof.compile(
159
+ lean_project,
160
+ source,
161
+ theorems=("ExampleMetric.metric_axioms",),
162
+ )
163
+
164
+
165
+ def test_proof_distribution(lean_proof, tmp_path):
166
+ package = Path(__file__).resolve().parent
167
+ source = package / "example_metric" / "proofs" / "Metric.lean"
168
+ lean_proof.assert_distributions(package, (source,), tmp_path)
169
+ ```
170
+ <!-- readme-standards:end example.usage -->
171
+
172
+ Place the example in your package tests and substitute your source file and fully qualified theorem names. Run `pytest --require-lean --prepare-lean` to run the full suite, including compilation and distribution checks. Use `-m lean_proof` to select just the compiler checks.
173
+
174
+ ### Configuration
175
+
176
+ Use `--require-lean` to fail when Lake is unavailable. Use `--prepare-lean` to initialize Lake and fetch Mathlib cache for the proof imports. The `lean_project` fixture supplies the packaged Lake project. Use an explicit project path if your package pins a different Lean toolchain.
177
+
178
+ ### Error Handling
179
+
180
+ Failures identify the missing theorem audit, rejected axiom, compiler output, or artifact path. Compilation tests skip when Lake is unavailable in ordinary pytest runs. Distribution checks can run with uv alone.
181
+
182
+ ### Best Practices
183
+
184
+ Name the public theorems in each package's tests. Keep a pinned Lean project and pair theorem audits with runtime numerical tests.
185
+
186
+ ---
187
+
188
+ ## Package Boundary
189
+
190
+ ### What It Owns
191
+
192
+ The pytest entry point, `lean_proof` and `lean_project` fixtures, and the pinned Lake project used by the SDK metrics.
193
+
194
+ ### Public API and Import Surfaces
195
+
196
+ The `lean_proof` fixture exposes `compile` and `assert_distributions`. Import `LeanProofChecks` from `swarmauri_tests_lean_proof` for typing.
197
+
198
+ ### Entry Points
199
+
200
+ <!-- readme-standards:begin entry-points -->
201
+ - `pytest11` → `swarmauri_tests_lean_proof` → `swarmauri_tests_lean_proof`
202
+ <!-- readme-standards:end entry-points -->
203
+
204
+ ### Injected Dependencies
205
+
206
+ The package depends on pytest. The proof checks invoke Lake and uv from the test environment.
207
+
208
+ ### Protocol Consumers
209
+
210
+ The pytest entry point registers the fixture and command-line options.
211
+
212
+ ### Extensions
213
+
214
+ Reuse the fixture with any Lake project and supply the proof sources and theorem names in your tests.
215
+
216
+ ---
217
+
218
+ ## Operations and Readiness
219
+
220
+ ### Operational Requirements
221
+
222
+ Install Lean through Elan. The plugin ships a pinned Lake project and copies its configuration into a writable test cache before use.
223
+
224
+ ### Health and Observability
225
+
226
+ Pytest reports compiler diagnostics and identifies missing audits or misplaced proof sources.
227
+
228
+ ### Security and Resource Limits
229
+
230
+ Run Lean projects and package builds from sources you trust. Both tools execute project code.
231
+
232
+ ### Compatibility
233
+
234
+ Version 0.1.0 declares Python 3.10 through 3.14.
235
+
236
+ ---
237
+
238
+ ## Verification
239
+
240
+ ### Tests
241
+
242
+ Run `uv run --package swarmauri_tests_lean_proof pytest` from the package directory.
243
+
244
+ ### Certification Status
245
+
246
+ Planning release.
247
+
248
+ ### Evidence
249
+
250
+ Plugin tests cover theorem audit reporting, the missing-toolchain policy, and missing or altered distribution sources.
251
+
252
+ The source examples and package tests document the supported behavior.
253
+
254
+ ---
255
+
256
+ ## FAQ
257
+
258
+ ### Why
259
+
260
+ Pytest plugin for Lean proofs and packaged proof sources.
261
+
262
+ ### How
263
+
264
+ Run the source example under Getting Started.
265
+
266
+ ### When
267
+
268
+ Re-run the proof tests when Lean sources, theorem names, the toolchain, or package data declarations change.
269
+
270
+ ---
271
+
272
+ ## Documentation and Related Packages
273
+
274
+ ### More Documentation
275
+
276
+ See the [component source](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/95-tests/swarmauri_tests_lean_proof).
277
+
278
+ ### Related Packages
279
+
280
+ See [swarmauri-core](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/10-interfaces/swarmauri_core) for interfaces and shared types.
281
+
282
+ ### Project Links
283
+
284
+ <!-- readme-standards:begin project-links -->
285
+ - [Repository](https://github.com/swarmauri/swarmauri-sdk)
286
+ - [pypi: swarmauri_tests_lean_proof](https://pypi.org/project/swarmauri_tests_lean_proof/)
287
+ <!-- readme-standards:end project-links -->
288
+
289
+ ---
290
+
291
+ ## Contributing
292
+
293
+ ### How to Contribute
294
+
295
+ See the [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md).
296
+
297
+ ### Development Setup
298
+
299
+ Use the SDK workspace to run package tests and the README examples.
300
+
301
+ ### Notes for Maintainers
302
+
303
+ Update the fixture examples when changing its public API.
304
+
305
+ ---
306
+
307
+ ## Governance
308
+
309
+ ### Ownership and Decision Making
310
+
311
+ The SDK maintainer review process applies.
312
+
313
+ ### Standards and Policies
314
+
315
+ See the [README policy](https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md).
316
+
317
+ ### Lifecycle and Migration
318
+
319
+ Planning version 0.1.0. Install from an SDK checkout until a release is available.
320
+
321
+ ---
322
+
323
+ ## License and Attribution
324
+
325
+ ### License
326
+
327
+ <!-- readme-standards:begin license -->
328
+ Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/LICENSE).
329
+ <!-- readme-standards:end license -->
330
+
331
+ ### Notices
332
+
333
+ <!-- readme-standards:begin notices -->
334
+ See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/NOTICE) for attribution.
335
+ <!-- readme-standards:end notices -->
336
+
@@ -0,0 +1,313 @@
1
+ # swarmauri_tests_lean_proof
2
+
3
+ <!-- readme-standards:begin branding -->
4
+ <p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
5
+ <p align="center"><strong>swarmauri_tests_lean_proof</strong></p>
6
+ <p align="center">Pytest plugin for Lean theorem audits and packaged proof sources.</p>
7
+ <p align="center">
8
+ <a href="https://pypi.org/project/swarmauri_tests_lean_proof/"><img alt="pypi: swarmauri_tests_lean_proof unpublished" src="https://img.shields.io/static/v1?label=pypi&amp;message=swarmauri_tests_lean_proof%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
9
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/pyproject.toml"><img alt="Source version: 0.1.0" src="https://img.shields.io/static/v1?label=Source%20version&amp;message=0.1.0&amp;labelColor=292421&amp;color=994525"></a>
10
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.15" src="https://img.shields.io/static/v1?label=Python&amp;message=%3E%3D3.10%2C%3C3.15&amp;labelColor=292421&amp;color=994525"></a>
11
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/pyproject.toml"><img alt="Layer: tests" src="https://img.shields.io/static/v1?label=Layer&amp;message=tests&amp;labelColor=292421&amp;color=994525"></a>
12
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md#lifecycle-and-migration"><img alt="Lifecycle: experimental" src="https://img.shields.io/static/v1?label=Lifecycle&amp;message=experimental&amp;labelColor=292421&amp;color=67437E"></a>
13
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&amp;message=Apache-2.0&amp;labelColor=292421&amp;color=994525"></a>
14
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&amp;message=attribution&amp;labelColor=292421&amp;color=994525"></a>
15
+ </p>
16
+ <p align="center">
17
+ <a href="https://pypi.org/project/swarmauri_tests_lean_proof/"><img alt="pypi downloads: swarmauri_tests_lean_proof: unpublished" src="https://img.shields.io/static/v1?label=pypi%20downloads&amp;message=swarmauri_tests_lean_proof%3A%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
18
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md"><img alt="README hits: swarmauri_tests_lean_proof" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/95-tests/swarmauri_tests_lean_proof/README.md.svg?label=README%20hits&amp;labelColor=292421&amp;color=08704E"></a>
19
+ </p>
20
+ <p align="center">
21
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&amp;message=CI%20gate&amp;labelColor=292421&amp;color=67437E"></a>
22
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&amp;message=example%20source&amp;labelColor=292421&amp;color=67437E"></a>
23
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&amp;message=not%20certified&amp;labelColor=292421&amp;color=805500"></a>
24
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&amp;message=repository%20policy&amp;labelColor=292421&amp;color=67437E"></a>
25
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&amp;message=source%20and%20CI&amp;labelColor=292421&amp;color=67437E"></a>
26
+ </p>
27
+ <p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
28
+ <!-- readme-standards:end branding -->
29
+
30
+ ---
31
+
32
+ ## Overview
33
+
34
+ ### Summary
35
+
36
+ A pytest plugin for compiling Lean proofs, auditing named theorems, and checking proof sources in Python distributions.
37
+
38
+ ### Why This Package
39
+
40
+ Use the same assertions across packages that ship Lean proofs.
41
+
42
+ ### When to Use
43
+
44
+ Add the plugin to your development dependencies when a package ships Lean proof sources.
45
+
46
+ ### Features
47
+
48
+ - Verify named Lean theorem audits against an axiom allowlist.
49
+ - Compare proof sources byte for byte with wheel and source distribution entries.
50
+ - Require Lean explicitly in CI and optionally prepare Lake dependencies and Mathlib cache.
51
+
52
+ ### Non-Goals
53
+
54
+ Runtime numeric behavior is covered by the package's Python tests.
55
+
56
+ ---
57
+
58
+ ## Getting Started
59
+
60
+ ### Prerequisites
61
+
62
+ Use Python 3.10 through 3.14. Proof checks use Lake and the proof project's pinned Lean toolchain. Artifact checks use uv.
63
+
64
+ ### Installation
65
+
66
+ #### Install with uv
67
+
68
+ <!-- readme-standards:begin installation.uv -->
69
+ `swarmauri_tests_lean_proof` is not declared published. From the source checkout:
70
+
71
+ ```bash
72
+ uv pip install .
73
+ ```
74
+ <!-- readme-standards:end installation.uv -->
75
+
76
+ #### Install with pip
77
+
78
+ <!-- readme-standards:begin installation.pip -->
79
+ `swarmauri_tests_lean_proof` is not declared published. From the source checkout:
80
+
81
+ ```bash
82
+ python -m pip install .
83
+ ```
84
+ <!-- readme-standards:end installation.pip -->
85
+
86
+ #### Install with Poetry
87
+
88
+ <!-- readme-standards:begin installation.poetry -->
89
+ `swarmauri_tests_lean_proof` is not declared published. From a separate Poetry project, replace the path with your checkout:
90
+
91
+ ```bash
92
+ poetry add /path/to/swarmauri_tests_lean_proof
93
+ ```
94
+ <!-- readme-standards:end installation.poetry -->
95
+
96
+ ### Quick Start
97
+
98
+ #### Example
99
+
100
+ <!-- readme-standards:begin example.quick-start -->
101
+ Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/docs/readme/quick_start.py).
102
+
103
+ ```python
104
+ from importlib.metadata import entry_points
105
+
106
+ assert any(
107
+ plugin.name == "swarmauri_tests_lean_proof"
108
+ for plugin in entry_points(group="pytest11")
109
+ )
110
+ ```
111
+ <!-- readme-standards:end example.quick-start -->
112
+
113
+ #### Expected Result
114
+
115
+ The assertion succeeds when the installed package exposes its pytest entry point.
116
+
117
+ ---
118
+
119
+ ## Usage
120
+
121
+ ### Common Workflows
122
+
123
+ <!-- readme-standards:begin example.usage -->
124
+ Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/docs/readme/usage.py).
125
+
126
+ ```python
127
+ from pathlib import Path
128
+
129
+ import pytest
130
+
131
+
132
+ @pytest.mark.lean_proof
133
+ def test_metric_axioms(lean_proof, lean_project):
134
+ package = Path(__file__).resolve().parent
135
+ source = package / "example_metric" / "proofs" / "Metric.lean"
136
+ lean_proof.compile(
137
+ lean_project,
138
+ source,
139
+ theorems=("ExampleMetric.metric_axioms",),
140
+ )
141
+
142
+
143
+ def test_proof_distribution(lean_proof, tmp_path):
144
+ package = Path(__file__).resolve().parent
145
+ source = package / "example_metric" / "proofs" / "Metric.lean"
146
+ lean_proof.assert_distributions(package, (source,), tmp_path)
147
+ ```
148
+ <!-- readme-standards:end example.usage -->
149
+
150
+ Place the example in your package tests and substitute your source file and fully qualified theorem names. Run `pytest --require-lean --prepare-lean` to run the full suite, including compilation and distribution checks. Use `-m lean_proof` to select just the compiler checks.
151
+
152
+ ### Configuration
153
+
154
+ Use `--require-lean` to fail when Lake is unavailable. Use `--prepare-lean` to initialize Lake and fetch Mathlib cache for the proof imports. The `lean_project` fixture supplies the packaged Lake project. Use an explicit project path if your package pins a different Lean toolchain.
155
+
156
+ ### Error Handling
157
+
158
+ Failures identify the missing theorem audit, rejected axiom, compiler output, or artifact path. Compilation tests skip when Lake is unavailable in ordinary pytest runs. Distribution checks can run with uv alone.
159
+
160
+ ### Best Practices
161
+
162
+ Name the public theorems in each package's tests. Keep a pinned Lean project and pair theorem audits with runtime numerical tests.
163
+
164
+ ---
165
+
166
+ ## Package Boundary
167
+
168
+ ### What It Owns
169
+
170
+ The pytest entry point, `lean_proof` and `lean_project` fixtures, and the pinned Lake project used by the SDK metrics.
171
+
172
+ ### Public API and Import Surfaces
173
+
174
+ The `lean_proof` fixture exposes `compile` and `assert_distributions`. Import `LeanProofChecks` from `swarmauri_tests_lean_proof` for typing.
175
+
176
+ ### Entry Points
177
+
178
+ <!-- readme-standards:begin entry-points -->
179
+ - `pytest11` → `swarmauri_tests_lean_proof` → `swarmauri_tests_lean_proof`
180
+ <!-- readme-standards:end entry-points -->
181
+
182
+ ### Injected Dependencies
183
+
184
+ The package depends on pytest. The proof checks invoke Lake and uv from the test environment.
185
+
186
+ ### Protocol Consumers
187
+
188
+ The pytest entry point registers the fixture and command-line options.
189
+
190
+ ### Extensions
191
+
192
+ Reuse the fixture with any Lake project and supply the proof sources and theorem names in your tests.
193
+
194
+ ---
195
+
196
+ ## Operations and Readiness
197
+
198
+ ### Operational Requirements
199
+
200
+ Install Lean through Elan. The plugin ships a pinned Lake project and copies its configuration into a writable test cache before use.
201
+
202
+ ### Health and Observability
203
+
204
+ Pytest reports compiler diagnostics and identifies missing audits or misplaced proof sources.
205
+
206
+ ### Security and Resource Limits
207
+
208
+ Run Lean projects and package builds from sources you trust. Both tools execute project code.
209
+
210
+ ### Compatibility
211
+
212
+ Version 0.1.0 declares Python 3.10 through 3.14.
213
+
214
+ ---
215
+
216
+ ## Verification
217
+
218
+ ### Tests
219
+
220
+ Run `uv run --package swarmauri_tests_lean_proof pytest` from the package directory.
221
+
222
+ ### Certification Status
223
+
224
+ Planning release.
225
+
226
+ ### Evidence
227
+
228
+ Plugin tests cover theorem audit reporting, the missing-toolchain policy, and missing or altered distribution sources.
229
+
230
+ The source examples and package tests document the supported behavior.
231
+
232
+ ---
233
+
234
+ ## FAQ
235
+
236
+ ### Why
237
+
238
+ Pytest plugin for Lean proofs and packaged proof sources.
239
+
240
+ ### How
241
+
242
+ Run the source example under Getting Started.
243
+
244
+ ### When
245
+
246
+ Re-run the proof tests when Lean sources, theorem names, the toolchain, or package data declarations change.
247
+
248
+ ---
249
+
250
+ ## Documentation and Related Packages
251
+
252
+ ### More Documentation
253
+
254
+ See the [component source](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/95-tests/swarmauri_tests_lean_proof).
255
+
256
+ ### Related Packages
257
+
258
+ See [swarmauri-core](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/10-interfaces/swarmauri_core) for interfaces and shared types.
259
+
260
+ ### Project Links
261
+
262
+ <!-- readme-standards:begin project-links -->
263
+ - [Repository](https://github.com/swarmauri/swarmauri-sdk)
264
+ - [pypi: swarmauri_tests_lean_proof](https://pypi.org/project/swarmauri_tests_lean_proof/)
265
+ <!-- readme-standards:end project-links -->
266
+
267
+ ---
268
+
269
+ ## Contributing
270
+
271
+ ### How to Contribute
272
+
273
+ See the [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md).
274
+
275
+ ### Development Setup
276
+
277
+ Use the SDK workspace to run package tests and the README examples.
278
+
279
+ ### Notes for Maintainers
280
+
281
+ Update the fixture examples when changing its public API.
282
+
283
+ ---
284
+
285
+ ## Governance
286
+
287
+ ### Ownership and Decision Making
288
+
289
+ The SDK maintainer review process applies.
290
+
291
+ ### Standards and Policies
292
+
293
+ See the [README policy](https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md).
294
+
295
+ ### Lifecycle and Migration
296
+
297
+ Planning version 0.1.0. Install from an SDK checkout until a release is available.
298
+
299
+ ---
300
+
301
+ ## License and Attribution
302
+
303
+ ### License
304
+
305
+ <!-- readme-standards:begin license -->
306
+ Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/LICENSE).
307
+ <!-- readme-standards:end license -->
308
+
309
+ ### Notices
310
+
311
+ <!-- readme-standards:begin notices -->
312
+ See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/NOTICE) for attribution.
313
+ <!-- readme-standards:end notices -->
@@ -0,0 +1,84 @@
1
+ [project]
2
+ name = "swarmauri_tests_lean_proof"
3
+ version = "0.1.0"
4
+ description = "Pytest plugin for Lean theorem audits and packaged proof sources."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.10,<3.15"
8
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
9
+ keywords = ["swarmauri", "pytest", "lean", "formal verification", "proof packaging"]
10
+ classifiers = [
11
+ "Development Status :: 1 - Planning",
12
+ "Framework :: Pytest",
13
+ "Programming Language :: Python :: 3.10",
14
+ "Programming Language :: Python :: 3.11",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ ]
19
+ dependencies = ["pytest>=8.0"]
20
+ license-files = ["LICENSE", "NOTICE"]
21
+
22
+ [project.urls]
23
+ Repository = "https://github.com/swarmauri/swarmauri-sdk"
24
+
25
+ [project.entry-points.pytest11]
26
+ swarmauri_tests_lean_proof = "swarmauri_tests_lean_proof"
27
+
28
+ [tool.readme_standards]
29
+ policy = "package-guide-v1"
30
+ readme = "README.md"
31
+ brand = "swarmauri"
32
+ brand_catalog = "../../../tools/readme/brands.toml"
33
+ repository = "https://github.com/swarmauri/swarmauri-sdk"
34
+ ref = "master"
35
+ package_path = "pkgs/95-tests/swarmauri_tests_lean_proof"
36
+ layer = "tests"
37
+ lifecycle = "experimental"
38
+ license_file = "LICENSE"
39
+ notice_file = "NOTICE"
40
+
41
+ [tool.readme_standards.distributions.pypi]
42
+ name = "swarmauri_tests_lean_proof"
43
+ published = false
44
+
45
+ [tool.readme_standards.examples.quick_start]
46
+ source = "docs/readme/quick_start.py"
47
+ test = "tests/unit/test_readme_sources.py"
48
+ language = "python"
49
+ expected_exit_code = 0
50
+
51
+ [tool.readme_standards.examples.usage]
52
+ source = "docs/readme/usage.py"
53
+ test = "tests/unit/test_readme_sources.py"
54
+ language = "python"
55
+ expected_exit_code = 0
56
+
57
+ [tool.readme_standards.statuses.readme]
58
+ label = "CI gate"
59
+ url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
60
+
61
+ [tool.readme_standards.statuses.tests]
62
+ label = "example source"
63
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/tests/unit/test_readme_sources.py"
64
+
65
+ [tool.readme_standards.statuses.certification]
66
+ label = "not certified"
67
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/95-tests/swarmauri_tests_lean_proof/README.md#certification-status"
68
+
69
+ [tool.readme_standards.statuses.governance]
70
+ label = "repository policy"
71
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"
72
+
73
+ [tool.readme_standards.statuses.evidence]
74
+ label = "source and CI"
75
+ url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
76
+ [build-system]
77
+ requires = ["poetry-core>=2.0"]
78
+ build-backend = "poetry.core.masonry.api"
79
+
80
+ [dependency-groups]
81
+ dev = ["pytest>=8.0", "ruff>=0.9.9", "readme-standards==0.1.6; python_version >= \"3.11\""]
82
+
83
+ [tool.poetry]
84
+ include = [{ path = "swarmauri_tests_lean_proof/lean", format = ["sdist", "wheel"] }]
@@ -0,0 +1,196 @@
1
+ """Pytest assertions for Lean theorem audits and packaged proof sources."""
2
+
3
+ from hashlib import sha256
4
+ import os
5
+ from pathlib import Path
6
+ import re
7
+ import shutil
8
+ import subprocess
9
+ import tarfile
10
+ import tempfile
11
+ import zipfile
12
+
13
+ import pytest
14
+
15
+
16
+ _AUDIT = re.compile(
17
+ r"^'([^']+)' (?:depends on axioms:\s*\[([^\]]*)\]|"
18
+ r"does not depend on any axioms)\s*$",
19
+ re.MULTILINE,
20
+ )
21
+ _STANDARD_AXIOMS = frozenset({"propext", "Classical.choice", "Quot.sound"})
22
+ _PROJECT_FILES = ("lean-toolchain", "lakefile.toml", "lake-manifest.json")
23
+
24
+
25
+ def pytest_addoption(parser):
26
+ group = parser.getgroup("Lean proofs")
27
+ group.addoption(
28
+ "--require-lean", action="store_true", help="Fail if Lake is missing"
29
+ )
30
+ group.addoption(
31
+ "--prepare-lean",
32
+ action="store_true",
33
+ help="Prepare Lake dependencies and Mathlib cache",
34
+ )
35
+
36
+
37
+ def pytest_configure(config):
38
+ config.addinivalue_line(
39
+ "markers",
40
+ "lean_proof: compile Lean proof sources and audit named theorems",
41
+ )
42
+
43
+
44
+ def _run(command: list[str], cwd: Path, *, env=None) -> str:
45
+ result = subprocess.run(
46
+ command,
47
+ cwd=cwd,
48
+ env=env,
49
+ stdout=subprocess.PIPE,
50
+ stderr=subprocess.STDOUT,
51
+ encoding="utf-8",
52
+ errors="replace",
53
+ )
54
+ assert result.returncode == 0, (
55
+ f"{' '.join(command)} failed:\n{result.stdout}"
56
+ )
57
+ return result.stdout
58
+
59
+
60
+ def _assert_axioms(
61
+ output: str, theorems: tuple[str, ...], allowed_axioms: frozenset[str]
62
+ ):
63
+ audits = {
64
+ theorem: {
65
+ axiom.strip() for axiom in axioms.split(",") if axiom.strip()
66
+ }
67
+ for theorem, axioms in _AUDIT.findall(output)
68
+ }
69
+ assert theorems, "Name at least one theorem to audit"
70
+ missing = sorted(set(theorems) - audits.keys())
71
+ assert not missing, f"Missing Lean audits for {missing}:\n{output}"
72
+ for theorem, axioms in audits.items():
73
+ unexpected = axioms - allowed_axioms | (axioms & {"sorryAx"})
74
+ assert not unexpected, (
75
+ f"{theorem}: unexpected Lean axioms {sorted(unexpected)}"
76
+ )
77
+
78
+
79
+ class LeanProofChecks:
80
+ """Compile proof files and check their distribution contents."""
81
+
82
+ def __init__(self, config: pytest.Config):
83
+ self._config = config
84
+ self._prepared: dict[Path, set[str]] = {}
85
+
86
+ def compile(
87
+ self,
88
+ project: Path,
89
+ source: Path,
90
+ *,
91
+ theorems: tuple[str, ...],
92
+ allowed_axioms: frozenset[str] = _STANDARD_AXIOMS,
93
+ ) -> None:
94
+ """Compile one file and verify the compiler's named theorem audits."""
95
+ lake = shutil.which("lake")
96
+ if lake is None:
97
+ if self._config.getoption(
98
+ "--require-lean"
99
+ ) or self._config.getoption("--prepare-lean"):
100
+ pytest.fail(
101
+ "Lake is required. Install the pinned Lean toolchain."
102
+ )
103
+ pytest.skip("Lake is unavailable")
104
+ project = project.resolve()
105
+ source = source.resolve()
106
+ assert source.is_file(), f"Missing Lean source {source}"
107
+ if self._config.getoption("--prepare-lean"):
108
+ self._prepare(lake, project, source)
109
+ output = _run([lake, "env", "lean", str(source)], project)
110
+ _assert_axioms(output, theorems, allowed_axioms)
111
+
112
+ def _prepare(self, lake: str, project: Path, source: Path) -> None:
113
+ if project not in self._prepared:
114
+ _run(
115
+ [lake, "update"],
116
+ project,
117
+ env={**os.environ, "MATHLIB_NO_CACHE_ON_UPDATE": "1"},
118
+ )
119
+ self._prepared[project] = set()
120
+ imports = {
121
+ module
122
+ for line in source.read_text(encoding="utf-8").splitlines()
123
+ if line.startswith("import Mathlib")
124
+ for module in line.split()[1:]
125
+ if module == "Mathlib" or module.startswith("Mathlib.")
126
+ }
127
+ pending = imports - self._prepared[project]
128
+ if pending:
129
+ _run([lake, "exe", "cache", "get", *sorted(pending)], project)
130
+ self._prepared[project].update(pending)
131
+
132
+ def assert_distributions(
133
+ self, package: Path, sources: tuple[Path, ...], output: Path
134
+ ) -> None:
135
+ """Build a wheel and source distribution and compare proof bytes."""
136
+ package = package.resolve()
137
+ output = output.resolve()
138
+ assert sources, "Supply at least one proof source"
139
+ expected = {
140
+ source.resolve()
141
+ .relative_to(package)
142
+ .as_posix(): source.read_bytes()
143
+ for source in sources
144
+ }
145
+ _run(["uv", "build", "--out-dir", str(output)], package)
146
+ (wheel,) = output.glob("*.whl")
147
+ (sdist,) = output.glob("*.tar.gz")
148
+ with zipfile.ZipFile(wheel) as archive:
149
+ for path, source in expected.items():
150
+ assert path in archive.namelist(), (
151
+ f"{wheel.name}: missing {path}"
152
+ )
153
+ assert archive.read(path) == source, (
154
+ f"{wheel.name}: {path} differs from source"
155
+ )
156
+ with tarfile.open(sdist) as archive:
157
+ members = {
158
+ member.name.partition("/")[2]: member
159
+ for member in archive.getmembers()
160
+ if member.isfile()
161
+ }
162
+ for path, source in expected.items():
163
+ assert path in members, f"{sdist.name}: missing {path}"
164
+ stream = archive.extractfile(members[path])
165
+ assert stream is not None, f"{sdist.name}: unreadable {path}"
166
+ with stream:
167
+ assert stream.read() == source, (
168
+ f"{sdist.name}: {path} differs from source"
169
+ )
170
+
171
+
172
+ @pytest.fixture(scope="session")
173
+ def lean_project(pytestconfig) -> Path:
174
+ """Make the pinned, packaged Lake project available in pytest's cache."""
175
+ source = Path(__file__).with_name("lean")
176
+ files = {name: (source / name).read_bytes() for name in _PROJECT_FILES}
177
+ revision = sha256(b"\0".join(files.values())).hexdigest()[:16]
178
+ cache_name = f"swarmauri-lean-{revision}"
179
+ if os.name == "nt":
180
+ # Keep Lean dependency paths below the Windows path limit.
181
+ cache = Path(os.environ.get("LOCALAPPDATA", tempfile.gettempdir()))
182
+ project = cache / cache_name
183
+ project.mkdir(parents=True, exist_ok=True)
184
+ else:
185
+ project = pytestconfig.cache.mkdir(cache_name)
186
+ for name, content in files.items():
187
+ target = project / name
188
+ if not target.exists() or target.read_bytes() != content:
189
+ target.write_bytes(content)
190
+ return project
191
+
192
+
193
+ @pytest.fixture(scope="session")
194
+ def lean_proof(pytestconfig):
195
+ """Provide shared Lean proof and artifact assertions."""
196
+ return LeanProofChecks(pytestconfig)
@@ -0,0 +1,96 @@
1
+ {"version": "1.3.0",
2
+ "packagesDir": ".lake/packages",
3
+ "packages":
4
+ [{"url": "https://github.com/leanprover-community/mathlib4.git",
5
+ "type": "git",
6
+ "subDir": null,
7
+ "scope": "",
8
+ "rev": "0c200c9b54fe785fbaeea52be8f47c60245788bc",
9
+ "name": "mathlib",
10
+ "manifestFile": "lake-manifest.json",
11
+ "inputRev": "0c200c9b54fe785fbaeea52be8f47c60245788bc",
12
+ "inherited": false,
13
+ "configFile": "lakefile.lean"},
14
+ {"url": "https://github.com/leanprover-community/plausible",
15
+ "type": "git",
16
+ "subDir": null,
17
+ "scope": "leanprover-community",
18
+ "rev": "10a034bc597af9a00d9a375e525ec4a2cc927a07",
19
+ "name": "plausible",
20
+ "manifestFile": "lake-manifest.json",
21
+ "inputRev": "main",
22
+ "inherited": true,
23
+ "configFile": "lakefile.toml"},
24
+ {"url": "https://github.com/leanprover-community/LeanSearchClient",
25
+ "type": "git",
26
+ "subDir": null,
27
+ "scope": "leanprover-community",
28
+ "rev": "ea7f49dfb79d83c4be55752d361cac9a90586fb4",
29
+ "name": "LeanSearchClient",
30
+ "manifestFile": "lake-manifest.json",
31
+ "inputRev": "main",
32
+ "inherited": true,
33
+ "configFile": "lakefile.toml"},
34
+ {"url": "https://github.com/leanprover-community/import-graph",
35
+ "type": "git",
36
+ "subDir": null,
37
+ "scope": "leanprover-community",
38
+ "rev": "8ed31b1765ebc5b43f2076e6c166c578db04cc12",
39
+ "name": "importGraph",
40
+ "manifestFile": "lake-manifest.json",
41
+ "inputRev": "main",
42
+ "inherited": true,
43
+ "configFile": "lakefile.toml"},
44
+ {"url": "https://github.com/leanprover-community/ProofWidgets4",
45
+ "type": "git",
46
+ "subDir": null,
47
+ "scope": "leanprover-community",
48
+ "rev": "5ba14dbfd751c6cabd0e00ec7e483dbb058a4d1a",
49
+ "name": "proofwidgets",
50
+ "manifestFile": "lake-manifest.json",
51
+ "inputRev": "main",
52
+ "inherited": true,
53
+ "configFile": "lakefile.lean"},
54
+ {"url": "https://github.com/leanprover-community/aesop",
55
+ "type": "git",
56
+ "subDir": null,
57
+ "scope": "leanprover-community",
58
+ "rev": "b6c08e4ab3d2e53692e6ff1d59c05756b30633a7",
59
+ "name": "aesop",
60
+ "manifestFile": "lake-manifest.json",
61
+ "inputRev": "master",
62
+ "inherited": true,
63
+ "configFile": "lakefile.toml"},
64
+ {"url": "https://github.com/leanprover-community/quote4",
65
+ "type": "git",
66
+ "subDir": null,
67
+ "scope": "leanprover-community",
68
+ "rev": "7a1919c71246628c549c802b971212a21af77eb3",
69
+ "name": "Qq",
70
+ "manifestFile": "lake-manifest.json",
71
+ "inputRev": "master",
72
+ "inherited": true,
73
+ "configFile": "lakefile.toml"},
74
+ {"url": "https://github.com/leanprover-community/batteries",
75
+ "type": "git",
76
+ "subDir": null,
77
+ "scope": "leanprover-community",
78
+ "rev": "e8e5cbcdeaa844fd93d3b5cab6b64b05f16d633b",
79
+ "name": "batteries",
80
+ "manifestFile": "lake-manifest.json",
81
+ "inputRev": "main",
82
+ "inherited": true,
83
+ "configFile": "lakefile.toml"},
84
+ {"url": "https://github.com/leanprover/lean4-cli",
85
+ "type": "git",
86
+ "subDir": null,
87
+ "scope": "leanprover",
88
+ "rev": "ede83ee5d3be8ccd213d851768a67f53536c52b1",
89
+ "name": "Cli",
90
+ "manifestFile": "lake-manifest.json",
91
+ "inputRev": "v4.37.0-rc2",
92
+ "inherited": true,
93
+ "configFile": "lakefile.toml"}],
94
+ "name": "swarmauri_metric_proofs",
95
+ "lakeDir": ".lake",
96
+ "fixedToolchain": false}
@@ -0,0 +1,7 @@
1
+ name = "swarmauri_metric_proofs"
2
+ version = "0.1.0"
3
+
4
+ [[require]]
5
+ name = "mathlib"
6
+ git = "https://github.com/leanprover-community/mathlib4.git"
7
+ rev = "0c200c9b54fe785fbaeea52be8f47c60245788bc"
@@ -0,0 +1 @@
1
+ leanprover/lean4:v4.37.0-rc2