szl-drift 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.
- szl_drift-0.1.0/LICENSE +202 -0
- szl_drift-0.1.0/NOTICE +17 -0
- szl_drift-0.1.0/PKG-INFO +70 -0
- szl_drift-0.1.0/README.md +56 -0
- szl_drift-0.1.0/probe.py +192 -0
- szl_drift-0.1.0/pyproject.toml +23 -0
- szl_drift-0.1.0/setup.cfg +4 -0
- szl_drift-0.1.0/szl_drift.egg-info/PKG-INFO +70 -0
- szl_drift-0.1.0/szl_drift.egg-info/SOURCES.txt +12 -0
- szl_drift-0.1.0/szl_drift.egg-info/dependency_links.txt +1 -0
- szl_drift-0.1.0/szl_drift.egg-info/top_level.txt +2 -0
- szl_drift-0.1.0/tests/test_probe.py +496 -0
- szl_drift-0.1.0/tests/test_verdict.py +130 -0
- szl_drift-0.1.0/verdict.py +60 -0
szl_drift-0.1.0/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.
|
szl_drift-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
SZL Holdings
|
|
2
|
+
Copyright 2026 SZL Holdings
|
|
3
|
+
|
|
4
|
+
This product includes software developed at SZL Holdings
|
|
5
|
+
(https://github.com/szl-holdings).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
szl_drift-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: szl-drift
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Origin-drift receipts: compare a-11-oy.com, a11oy.net, and a Ring 1 preview. Λ = Conjecture 1. Apache-2.0.
|
|
5
|
+
Author-email: Stephen Lutar <stephen@szlholdings.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://a-11-oy.com
|
|
8
|
+
Project-URL: Repository, https://github.com/szl-holdings/szl-drift
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# szl-drift
|
|
16
|
+
|
|
17
|
+
Origin-drift receipts. **Not a second flagship.**
|
|
18
|
+
|
|
19
|
+
<!-- szl:header v1 -->
|
|
20
|
+
<!-- Native identity: szl-brand@4309f6fce89179331b0b3ed8c99494e76c5be256; Orbit v2 icon. -->
|
|
21
|
+
<p>
|
|
22
|
+
<a href="https://github.com/szl-holdings">
|
|
23
|
+
<img src="https://raw.githubusercontent.com/szl-holdings/szl-brand/4309f6fce89179331b0b3ed8c99494e76c5be256/kit/logos/orbit-v2/suite/szl-icon-32.svg" alt="SZL Holdings — Orbit v2" width="32" height="32" />
|
|
24
|
+
</a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
**Control before action. Evidence after.**
|
|
28
|
+
|
|
29
|
+
[Product](https://a-11-oy.com) · [Proof](https://a11oy.net) · [GitHub organization](https://github.com/szl-holdings)
|
|
30
|
+
<!-- /szl:header -->
|
|
31
|
+
|
|
32
|
+
Compares:
|
|
33
|
+
|
|
34
|
+
| Origin | Probe | Meaning |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| Product | `https://a-11-oy.com/api/a11oy/v1/honest` + `/readyz` | Runtime doctrine + readiness |
|
|
37
|
+
| Proof | `https://a11oy.net/health.json` | Static GitHub Pages document. Not DSSE-LIVE. |
|
|
38
|
+
| Preview | Ring 1 kernel catalog | This surface is not the product origin |
|
|
39
|
+
|
|
40
|
+
A `200` from product `/readyz` is **not** a production certificate. Factory bind `AO-2026-08-29-001` still holds that certificate **CLOSED**.
|
|
41
|
+
|
|
42
|
+
## Run
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python3 probe.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Exit `0` always prints JSON. Missing, malformed, or non-object origin responses populate `errors`;
|
|
49
|
+
a known HTTP status is retained. No upstream response can set `certified_production_ready` to true.
|
|
50
|
+
|
|
51
|
+
The scheduled `verdict.py drift-report.json` check fails when an origin did not
|
|
52
|
+
answer HTTP 200 or its response was rejected by the probe. A 200 response with
|
|
53
|
+
malformed JSON, a non-object body, or an oversized body remains an alert. A
|
|
54
|
+
passing verdict does not evaluate doctrine values or certify production readiness.
|
|
55
|
+
|
|
56
|
+
## Honesty
|
|
57
|
+
|
|
58
|
+
- Doctrine v11 LOCKED
|
|
59
|
+
- Λ = Conjecture 1
|
|
60
|
+
- locked-8 paints only when live `locked_formula_count === 8`
|
|
61
|
+
- Warhacker v1.0.0 is archived
|
|
62
|
+
- Apache-2.0
|
|
63
|
+
|
|
64
|
+
Interactive verify stays on [a-11-oy.com/verify](https://a-11-oy.com/verify).
|
|
65
|
+
|
|
66
|
+
Estate on Hugging Face: models, datasets and Spaces are published under the [SZLHOLDINGS](https://huggingface.co/SZLHOLDINGS) org.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# szl-drift
|
|
2
|
+
|
|
3
|
+
Origin-drift receipts. **Not a second flagship.**
|
|
4
|
+
|
|
5
|
+
<!-- szl:header v1 -->
|
|
6
|
+
<!-- Native identity: szl-brand@4309f6fce89179331b0b3ed8c99494e76c5be256; Orbit v2 icon. -->
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://github.com/szl-holdings">
|
|
9
|
+
<img src="https://raw.githubusercontent.com/szl-holdings/szl-brand/4309f6fce89179331b0b3ed8c99494e76c5be256/kit/logos/orbit-v2/suite/szl-icon-32.svg" alt="SZL Holdings — Orbit v2" width="32" height="32" />
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
**Control before action. Evidence after.**
|
|
14
|
+
|
|
15
|
+
[Product](https://a-11-oy.com) · [Proof](https://a11oy.net) · [GitHub organization](https://github.com/szl-holdings)
|
|
16
|
+
<!-- /szl:header -->
|
|
17
|
+
|
|
18
|
+
Compares:
|
|
19
|
+
|
|
20
|
+
| Origin | Probe | Meaning |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| Product | `https://a-11-oy.com/api/a11oy/v1/honest` + `/readyz` | Runtime doctrine + readiness |
|
|
23
|
+
| Proof | `https://a11oy.net/health.json` | Static GitHub Pages document. Not DSSE-LIVE. |
|
|
24
|
+
| Preview | Ring 1 kernel catalog | This surface is not the product origin |
|
|
25
|
+
|
|
26
|
+
A `200` from product `/readyz` is **not** a production certificate. Factory bind `AO-2026-08-29-001` still holds that certificate **CLOSED**.
|
|
27
|
+
|
|
28
|
+
## Run
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python3 probe.py
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Exit `0` always prints JSON. Missing, malformed, or non-object origin responses populate `errors`;
|
|
35
|
+
a known HTTP status is retained. No upstream response can set `certified_production_ready` to true.
|
|
36
|
+
|
|
37
|
+
The scheduled `verdict.py drift-report.json` check fails when an origin did not
|
|
38
|
+
answer HTTP 200 or its response was rejected by the probe. A 200 response with
|
|
39
|
+
malformed JSON, a non-object body, or an oversized body remains an alert. A
|
|
40
|
+
passing verdict does not evaluate doctrine values or certify production readiness.
|
|
41
|
+
|
|
42
|
+
## Honesty
|
|
43
|
+
|
|
44
|
+
- Doctrine v11 LOCKED
|
|
45
|
+
- Λ = Conjecture 1
|
|
46
|
+
- locked-8 paints only when live `locked_formula_count === 8`
|
|
47
|
+
- Warhacker v1.0.0 is archived
|
|
48
|
+
- Apache-2.0
|
|
49
|
+
|
|
50
|
+
Interactive verify stays on [a-11-oy.com/verify](https://a-11-oy.com/verify).
|
|
51
|
+
|
|
52
|
+
Estate on Hugging Face: models, datasets and Spaces are published under the [SZLHOLDINGS](https://huggingface.co/SZLHOLDINGS) org.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
szl_drift-0.1.0/probe.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Origin drift probe. Fail closed. Never fabricates a certificate."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import math
|
|
8
|
+
import urllib.error
|
|
9
|
+
import urllib.parse
|
|
10
|
+
import urllib.request
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
PRODUCT = "https://a-11-oy.com"
|
|
14
|
+
PROOF = "https://a11oy.net"
|
|
15
|
+
TIMEOUT = 8
|
|
16
|
+
# Observed origin bodies are under 2 KB; anything past 1 MiB is not a probe response.
|
|
17
|
+
MAX_BODY_BYTES = 1024 * 1024
|
|
18
|
+
_DEFAULT_PORTS = {"http": 80, "https": 443}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _origin(url: str) -> tuple[str, str, int | None]:
|
|
22
|
+
"""Return (scheme, host, port) with the default port filled in. Raises ValueError on a bad port."""
|
|
23
|
+
parts = urllib.parse.urlsplit(url)
|
|
24
|
+
scheme = parts.scheme.lower()
|
|
25
|
+
port = parts.port if parts.port is not None else _DEFAULT_PORTS.get(scheme)
|
|
26
|
+
return scheme, (parts.hostname or "").lower(), port
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _origin_label(url: str) -> str:
|
|
30
|
+
try:
|
|
31
|
+
scheme, host, port = _origin(url)
|
|
32
|
+
except ValueError:
|
|
33
|
+
return "an unparseable origin"
|
|
34
|
+
return f"{scheme}://{host}" if port == _DEFAULT_PORTS.get(scheme) else f"{scheme}://{host}:{port}"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class SameOriginRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
38
|
+
"""Follow a redirect only when it stays on the origin that was requested."""
|
|
39
|
+
|
|
40
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
41
|
+
try:
|
|
42
|
+
same_origin = _origin(newurl) == _origin(req.full_url)
|
|
43
|
+
except ValueError:
|
|
44
|
+
same_origin = False
|
|
45
|
+
# Close the 3xx response first: urllib otherwise drains its body with an
|
|
46
|
+
# unbounded read() before following the redirect.
|
|
47
|
+
fp.close()
|
|
48
|
+
if not same_origin:
|
|
49
|
+
reason = (
|
|
50
|
+
f"cross-origin redirect refused: {_origin_label(req.full_url)} -> {_origin_label(newurl)}"
|
|
51
|
+
)
|
|
52
|
+
raise urllib.error.HTTPError(req.full_url, code, reason, headers, None)
|
|
53
|
+
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
_OPENER = urllib.request.build_opener(SameOriginRedirectHandler)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _read_capped(res: Any, cap: int) -> bytes:
|
|
60
|
+
"""Read at most cap + 1 bytes, so an oversized body is detectable without buffering it."""
|
|
61
|
+
chunks: list[bytes] = []
|
|
62
|
+
total = 0
|
|
63
|
+
while total <= cap:
|
|
64
|
+
chunk = res.read(cap + 1 - total)
|
|
65
|
+
if not chunk:
|
|
66
|
+
break
|
|
67
|
+
chunks.append(chunk)
|
|
68
|
+
total += len(chunk)
|
|
69
|
+
return b"".join(chunks)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _reject_duplicate_keys(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
|
|
73
|
+
value: dict[str, Any] = {}
|
|
74
|
+
for key, item in pairs:
|
|
75
|
+
if key in value:
|
|
76
|
+
raise ValueError("duplicate JSON object key")
|
|
77
|
+
value[key] = item
|
|
78
|
+
return value
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _reject_nonfinite_constant(_value: str) -> Any:
|
|
82
|
+
raise ValueError("non-finite JSON number")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _parse_finite_float(value: str) -> float:
|
|
86
|
+
number = float(value)
|
|
87
|
+
if not math.isfinite(number):
|
|
88
|
+
raise ValueError("non-finite JSON number")
|
|
89
|
+
return number
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _strict_json(raw: str) -> Any:
|
|
93
|
+
return json.loads(
|
|
94
|
+
raw,
|
|
95
|
+
object_pairs_hook=_reject_duplicate_keys,
|
|
96
|
+
parse_constant=_reject_nonfinite_constant,
|
|
97
|
+
parse_float=_parse_finite_float,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def get(url: str) -> dict[str, Any]:
|
|
102
|
+
req = urllib.request.Request(url, headers={"User-Agent": "szl-drift/1", "Accept": "application/json"})
|
|
103
|
+
try:
|
|
104
|
+
with _OPENER.open(req, timeout=TIMEOUT) as res:
|
|
105
|
+
cap = MAX_BODY_BYTES
|
|
106
|
+
data = _read_capped(res, cap)
|
|
107
|
+
if len(data) > cap:
|
|
108
|
+
return {
|
|
109
|
+
"ok": False,
|
|
110
|
+
"status": res.status,
|
|
111
|
+
"body": None,
|
|
112
|
+
"error": f"response body exceeds {cap} bytes",
|
|
113
|
+
}
|
|
114
|
+
try:
|
|
115
|
+
raw = data.decode("utf-8")
|
|
116
|
+
body: Any = _strict_json(raw)
|
|
117
|
+
except (UnicodeDecodeError, ValueError) as exc:
|
|
118
|
+
message = exc.msg if isinstance(exc, json.JSONDecodeError) else str(exc)
|
|
119
|
+
return {
|
|
120
|
+
"ok": False,
|
|
121
|
+
"status": res.status,
|
|
122
|
+
"body": None,
|
|
123
|
+
"error": f"invalid JSON response: {message}",
|
|
124
|
+
}
|
|
125
|
+
if not isinstance(body, dict):
|
|
126
|
+
return {
|
|
127
|
+
"ok": False,
|
|
128
|
+
"status": res.status,
|
|
129
|
+
"body": None,
|
|
130
|
+
"error": f"invalid JSON object: got {type(body).__name__}",
|
|
131
|
+
}
|
|
132
|
+
return {"ok": True, "status": res.status, "body": body, "error": None}
|
|
133
|
+
except urllib.error.HTTPError as exc:
|
|
134
|
+
return {"ok": False, "status": exc.code, "body": None, "error": str(exc)}
|
|
135
|
+
except Exception as exc:
|
|
136
|
+
return {"ok": False, "status": None, "body": None, "error": str(exc)}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def main() -> int:
|
|
140
|
+
honest = get(f"{PRODUCT}/api/a11oy/v1/honest")
|
|
141
|
+
readyz = get(f"{PRODUCT}/readyz")
|
|
142
|
+
health = get(f"{PROOF}/health.json")
|
|
143
|
+
# Keep the defensive shape guard even though get() rejects non-object JSON:
|
|
144
|
+
# tests and future callers can replace get(), and main must still degrade
|
|
145
|
+
# rather than crash on a malformed result.
|
|
146
|
+
raw_body = honest.get("body")
|
|
147
|
+
body = raw_body if isinstance(raw_body, dict) else {}
|
|
148
|
+
raw_doctrine = body.get("doctrine_lock")
|
|
149
|
+
doctrine = raw_doctrine if isinstance(raw_doctrine, dict) else {}
|
|
150
|
+
# Presence, not truthiness, selects the authoritative top-level observation.
|
|
151
|
+
# An explicit 0/null must not be replaced by a nested fallback and thereby
|
|
152
|
+
# hide drift in the source response.
|
|
153
|
+
locked_formula_count = (
|
|
154
|
+
body["locked_formula_count"]
|
|
155
|
+
if "locked_formula_count" in body
|
|
156
|
+
else doctrine.get("locked_formula_count")
|
|
157
|
+
)
|
|
158
|
+
report = {
|
|
159
|
+
"schema": "szl.origin-drift/v1",
|
|
160
|
+
"certified_production_ready": False,
|
|
161
|
+
"product_honest": {
|
|
162
|
+
"status": honest["status"],
|
|
163
|
+
"locked_formula_count": locked_formula_count,
|
|
164
|
+
"lambda": doctrine.get("lambda"),
|
|
165
|
+
"kernel": doctrine.get("commit"),
|
|
166
|
+
"git_sha": body.get("git_sha"),
|
|
167
|
+
},
|
|
168
|
+
"product_readyz": {
|
|
169
|
+
"status": readyz["status"],
|
|
170
|
+
"body": readyz.get("body"),
|
|
171
|
+
"note": "200 ready is not a production certificate.",
|
|
172
|
+
},
|
|
173
|
+
"proof_health": {
|
|
174
|
+
"status": health["status"],
|
|
175
|
+
"sha": (health.get("body") or {}).get("sha") if isinstance(health.get("body"), dict) else None,
|
|
176
|
+
"signer": (health.get("body") or {}).get("signer")
|
|
177
|
+
if isinstance(health.get("body"), dict)
|
|
178
|
+
else None,
|
|
179
|
+
"note": "Static document. Not DSSE-LIVE.",
|
|
180
|
+
},
|
|
181
|
+
"errors": {
|
|
182
|
+
"honest": honest["error"],
|
|
183
|
+
"readyz": readyz["error"],
|
|
184
|
+
"health": health["error"],
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
print(json.dumps(report, indent=2, sort_keys=True))
|
|
188
|
+
return 0
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
if __name__ == "__main__":
|
|
192
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "szl-drift"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Origin-drift receipts: compare a-11-oy.com, a11oy.net, and a Ring 1 preview. Λ = Conjecture 1. Apache-2.0."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{ name = "Stephen Lutar", email = "stephen@szlholdings.com" }]
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://a-11-oy.com"
|
|
17
|
+
Repository = "https://github.com/szl-holdings/szl-drift"
|
|
18
|
+
|
|
19
|
+
[tool.setuptools]
|
|
20
|
+
py-modules = ["probe", "verdict"]
|
|
21
|
+
|
|
22
|
+
[tool.pytest.ini_options]
|
|
23
|
+
minversion = "7.0"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: szl-drift
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Origin-drift receipts: compare a-11-oy.com, a11oy.net, and a Ring 1 preview. Λ = Conjecture 1. Apache-2.0.
|
|
5
|
+
Author-email: Stephen Lutar <stephen@szlholdings.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://a-11-oy.com
|
|
8
|
+
Project-URL: Repository, https://github.com/szl-holdings/szl-drift
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# szl-drift
|
|
16
|
+
|
|
17
|
+
Origin-drift receipts. **Not a second flagship.**
|
|
18
|
+
|
|
19
|
+
<!-- szl:header v1 -->
|
|
20
|
+
<!-- Native identity: szl-brand@4309f6fce89179331b0b3ed8c99494e76c5be256; Orbit v2 icon. -->
|
|
21
|
+
<p>
|
|
22
|
+
<a href="https://github.com/szl-holdings">
|
|
23
|
+
<img src="https://raw.githubusercontent.com/szl-holdings/szl-brand/4309f6fce89179331b0b3ed8c99494e76c5be256/kit/logos/orbit-v2/suite/szl-icon-32.svg" alt="SZL Holdings — Orbit v2" width="32" height="32" />
|
|
24
|
+
</a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
**Control before action. Evidence after.**
|
|
28
|
+
|
|
29
|
+
[Product](https://a-11-oy.com) · [Proof](https://a11oy.net) · [GitHub organization](https://github.com/szl-holdings)
|
|
30
|
+
<!-- /szl:header -->
|
|
31
|
+
|
|
32
|
+
Compares:
|
|
33
|
+
|
|
34
|
+
| Origin | Probe | Meaning |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| Product | `https://a-11-oy.com/api/a11oy/v1/honest` + `/readyz` | Runtime doctrine + readiness |
|
|
37
|
+
| Proof | `https://a11oy.net/health.json` | Static GitHub Pages document. Not DSSE-LIVE. |
|
|
38
|
+
| Preview | Ring 1 kernel catalog | This surface is not the product origin |
|
|
39
|
+
|
|
40
|
+
A `200` from product `/readyz` is **not** a production certificate. Factory bind `AO-2026-08-29-001` still holds that certificate **CLOSED**.
|
|
41
|
+
|
|
42
|
+
## Run
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python3 probe.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Exit `0` always prints JSON. Missing, malformed, or non-object origin responses populate `errors`;
|
|
49
|
+
a known HTTP status is retained. No upstream response can set `certified_production_ready` to true.
|
|
50
|
+
|
|
51
|
+
The scheduled `verdict.py drift-report.json` check fails when an origin did not
|
|
52
|
+
answer HTTP 200 or its response was rejected by the probe. A 200 response with
|
|
53
|
+
malformed JSON, a non-object body, or an oversized body remains an alert. A
|
|
54
|
+
passing verdict does not evaluate doctrine values or certify production readiness.
|
|
55
|
+
|
|
56
|
+
## Honesty
|
|
57
|
+
|
|
58
|
+
- Doctrine v11 LOCKED
|
|
59
|
+
- Λ = Conjecture 1
|
|
60
|
+
- locked-8 paints only when live `locked_formula_count === 8`
|
|
61
|
+
- Warhacker v1.0.0 is archived
|
|
62
|
+
- Apache-2.0
|
|
63
|
+
|
|
64
|
+
Interactive verify stays on [a-11-oy.com/verify](https://a-11-oy.com/verify).
|
|
65
|
+
|
|
66
|
+
Estate on Hugging Face: models, datasets and Spaces are published under the [SZLHOLDINGS](https://huggingface.co/SZLHOLDINGS) org.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
NOTICE
|
|
3
|
+
README.md
|
|
4
|
+
probe.py
|
|
5
|
+
pyproject.toml
|
|
6
|
+
verdict.py
|
|
7
|
+
szl_drift.egg-info/PKG-INFO
|
|
8
|
+
szl_drift.egg-info/SOURCES.txt
|
|
9
|
+
szl_drift.egg-info/dependency_links.txt
|
|
10
|
+
szl_drift.egg-info/top_level.txt
|
|
11
|
+
tests/test_probe.py
|
|
12
|
+
tests/test_verdict.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 SZL Holdings
|
|
3
|
+
"""Offline tests for the origin drift probe.
|
|
4
|
+
|
|
5
|
+
These tests never touch the public network. `probe.get` is exercised against a
|
|
6
|
+
stubbed `probe._OPENER.open` and against a throwaway HTTP server bound to
|
|
7
|
+
127.0.0.1, and `probe.main` is exercised with `probe.get` itself replaced, so
|
|
8
|
+
the suite is deterministic and safe to run in CI on a fork.
|
|
9
|
+
|
|
10
|
+
The properties under test are the two the probe exists to guarantee:
|
|
11
|
+
|
|
12
|
+
1. **Fail closed.** Every failure path returns a well-formed dict with
|
|
13
|
+
``ok=False`` rather than raising, so a dead or malformed endpoint degrades
|
|
14
|
+
the report instead of crashing the run or being recorded as healthy.
|
|
15
|
+
2. **Never fabricates a certificate.** ``certified_production_ready`` is
|
|
16
|
+
``False`` in the report unconditionally — including when every upstream
|
|
17
|
+
endpoint returns a healthy 200.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import io
|
|
23
|
+
import json
|
|
24
|
+
import sys
|
|
25
|
+
import threading
|
|
26
|
+
import urllib.error
|
|
27
|
+
import urllib.request
|
|
28
|
+
from collections.abc import Iterator
|
|
29
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
from types import SimpleNamespace
|
|
32
|
+
|
|
33
|
+
import pytest
|
|
34
|
+
|
|
35
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
36
|
+
|
|
37
|
+
import probe
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class _FakeResponse:
|
|
41
|
+
def __init__(self, payload: bytes, status: int = 200) -> None:
|
|
42
|
+
self._buf = io.BytesIO(payload)
|
|
43
|
+
self.status = status
|
|
44
|
+
|
|
45
|
+
def read(self, amt: int | None = None) -> bytes:
|
|
46
|
+
return self._buf.read(amt)
|
|
47
|
+
|
|
48
|
+
def __enter__(self) -> _FakeResponse:
|
|
49
|
+
return self
|
|
50
|
+
|
|
51
|
+
def __exit__(self, *_exc: object) -> bool:
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_get_parses_json_body(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
56
|
+
monkeypatch.setattr(
|
|
57
|
+
probe._OPENER,
|
|
58
|
+
"open",
|
|
59
|
+
lambda *_a, **_k: _FakeResponse(b'{"doctrine_lock": {"lambda": 14}}'),
|
|
60
|
+
)
|
|
61
|
+
result = probe.get("https://example.test/x")
|
|
62
|
+
assert result["ok"] is True
|
|
63
|
+
assert result["status"] == 200
|
|
64
|
+
assert result["body"] == {"doctrine_lock": {"lambda": 14}}
|
|
65
|
+
assert result["error"] is None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@pytest.mark.parametrize(
|
|
69
|
+
("payload", "expected"),
|
|
70
|
+
[(b'{"value":1.5}', 1.5), (b'{"value":1e2}', 100.0)],
|
|
71
|
+
)
|
|
72
|
+
def test_get_accepts_finite_json_numbers(
|
|
73
|
+
monkeypatch: pytest.MonkeyPatch, payload: bytes, expected: float
|
|
74
|
+
) -> None:
|
|
75
|
+
monkeypatch.setattr(
|
|
76
|
+
probe._OPENER,
|
|
77
|
+
"open",
|
|
78
|
+
lambda *_a, **_k: _FakeResponse(payload),
|
|
79
|
+
)
|
|
80
|
+
result = probe.get("https://example.test/x")
|
|
81
|
+
assert result == {
|
|
82
|
+
"ok": True,
|
|
83
|
+
"status": 200,
|
|
84
|
+
"body": {"value": expected},
|
|
85
|
+
"error": None,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.mark.parametrize(
|
|
90
|
+
"payload",
|
|
91
|
+
[
|
|
92
|
+
b'{"locked_formula_count":0,"locked_formula_count":749}',
|
|
93
|
+
b'{"doctrine_lock":{"lambda":0,"lambda":14}}',
|
|
94
|
+
b'{"value":NaN}',
|
|
95
|
+
b'{"value":Infinity}',
|
|
96
|
+
b'{"value":-Infinity}',
|
|
97
|
+
b'{"value":1e999}',
|
|
98
|
+
b'{"value":"\xff"}',
|
|
99
|
+
],
|
|
100
|
+
)
|
|
101
|
+
def test_get_fails_closed_on_ambiguous_nonfinite_or_undecodable_json(
|
|
102
|
+
monkeypatch: pytest.MonkeyPatch, payload: bytes
|
|
103
|
+
) -> None:
|
|
104
|
+
monkeypatch.setattr(
|
|
105
|
+
probe._OPENER,
|
|
106
|
+
"open",
|
|
107
|
+
lambda *_a, **_k: _FakeResponse(payload),
|
|
108
|
+
)
|
|
109
|
+
result = probe.get("https://example.test/x")
|
|
110
|
+
assert result["ok"] is False
|
|
111
|
+
assert result["status"] == 200
|
|
112
|
+
assert result["body"] is None
|
|
113
|
+
assert result["error"].startswith("invalid JSON response:")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_get_fails_closed_on_invalid_json(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
117
|
+
monkeypatch.setattr(
|
|
118
|
+
probe._OPENER,
|
|
119
|
+
"open",
|
|
120
|
+
lambda *_a, **_k: _FakeResponse(b"<!doctype html><title>nope</title>"),
|
|
121
|
+
)
|
|
122
|
+
result = probe.get("https://example.test/x")
|
|
123
|
+
assert result["ok"] is False
|
|
124
|
+
assert result["status"] == 200
|
|
125
|
+
assert result["body"] is None
|
|
126
|
+
assert result["error"].startswith("invalid JSON response:")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@pytest.mark.parametrize(
|
|
130
|
+
("payload", "kind"),
|
|
131
|
+
[
|
|
132
|
+
(b'["not", "an", "object"]', "list"),
|
|
133
|
+
(b'"a string"', "str"),
|
|
134
|
+
(b"42", "int"),
|
|
135
|
+
(b"true", "bool"),
|
|
136
|
+
(b"null", "NoneType"),
|
|
137
|
+
],
|
|
138
|
+
)
|
|
139
|
+
def test_get_fails_closed_on_json_that_is_not_an_object(
|
|
140
|
+
monkeypatch: pytest.MonkeyPatch, payload: bytes, kind: str
|
|
141
|
+
) -> None:
|
|
142
|
+
monkeypatch.setattr(
|
|
143
|
+
probe._OPENER,
|
|
144
|
+
"open",
|
|
145
|
+
lambda *_a, **_k: _FakeResponse(payload),
|
|
146
|
+
)
|
|
147
|
+
result = probe.get("https://example.test/x")
|
|
148
|
+
assert result["ok"] is False
|
|
149
|
+
assert result["status"] == 200
|
|
150
|
+
assert result["body"] is None
|
|
151
|
+
assert result["error"] == f"invalid JSON object: got {kind}"
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_get_fails_closed_on_http_error(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
155
|
+
def _raise(*_a: object, **_k: object) -> None:
|
|
156
|
+
raise urllib.error.HTTPError( # type: ignore[arg-type]
|
|
157
|
+
"https://example.test/x", 503, "boom", {}, None
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
monkeypatch.setattr(probe._OPENER, "open", _raise)
|
|
161
|
+
result = probe.get("https://example.test/x")
|
|
162
|
+
assert result["ok"] is False
|
|
163
|
+
assert result["status"] == 503
|
|
164
|
+
assert result["body"] is None
|
|
165
|
+
assert result["error"]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def test_get_fails_closed_on_transport_error(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
169
|
+
def _raise(*_a: object, **_k: object) -> None:
|
|
170
|
+
raise OSError("name or service not known")
|
|
171
|
+
|
|
172
|
+
monkeypatch.setattr(probe._OPENER, "open", _raise)
|
|
173
|
+
result = probe.get("https://example.test/x")
|
|
174
|
+
assert result["ok"] is False
|
|
175
|
+
assert result["status"] is None
|
|
176
|
+
assert result["error"]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class _EndlessResponse:
|
|
180
|
+
"""A body that never ends: an unbounded read() would never return."""
|
|
181
|
+
|
|
182
|
+
status = 200
|
|
183
|
+
|
|
184
|
+
def __init__(self) -> None:
|
|
185
|
+
self.requested = 0
|
|
186
|
+
|
|
187
|
+
def read(self, amt: int | None = None) -> bytes:
|
|
188
|
+
assert amt is not None, "get() must never issue an unbounded read"
|
|
189
|
+
self.requested += amt
|
|
190
|
+
return b" " * amt
|
|
191
|
+
|
|
192
|
+
def __enter__(self) -> _EndlessResponse:
|
|
193
|
+
return self
|
|
194
|
+
|
|
195
|
+
def __exit__(self, *_exc: object) -> bool:
|
|
196
|
+
return False
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def test_get_reads_at_most_cap_plus_one_bytes(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
200
|
+
endless = _EndlessResponse()
|
|
201
|
+
monkeypatch.setattr(probe, "MAX_BODY_BYTES", 1024)
|
|
202
|
+
monkeypatch.setattr(probe._OPENER, "open", lambda *_a, **_k: endless)
|
|
203
|
+
result = probe.get("https://example.test/x")
|
|
204
|
+
assert result == {
|
|
205
|
+
"ok": False,
|
|
206
|
+
"status": 200,
|
|
207
|
+
"body": None,
|
|
208
|
+
"error": "response body exceeds 1024 bytes",
|
|
209
|
+
}
|
|
210
|
+
assert endless.requested == 1025
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@pytest.fixture
|
|
214
|
+
def origin() -> Iterator[SimpleNamespace]:
|
|
215
|
+
"""A throwaway HTTP origin on 127.0.0.1 with scripted routes and a hit log."""
|
|
216
|
+
routes: dict[str, tuple[int, dict[str, str], bytes]] = {}
|
|
217
|
+
hits: list[str] = []
|
|
218
|
+
|
|
219
|
+
class Handler(BaseHTTPRequestHandler):
|
|
220
|
+
def log_message(self, *_args: object) -> None:
|
|
221
|
+
pass
|
|
222
|
+
|
|
223
|
+
def do_GET(self) -> None:
|
|
224
|
+
hits.append(self.path)
|
|
225
|
+
status, headers, body = routes.get(self.path, (404, {}, b""))
|
|
226
|
+
self.send_response(status)
|
|
227
|
+
for name, value in headers.items():
|
|
228
|
+
self.send_header(name, value)
|
|
229
|
+
self.end_headers()
|
|
230
|
+
self.wfile.write(body)
|
|
231
|
+
|
|
232
|
+
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
233
|
+
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
|
234
|
+
thread.start()
|
|
235
|
+
try:
|
|
236
|
+
yield SimpleNamespace(
|
|
237
|
+
base=f"http://127.0.0.1:{server.server_port}",
|
|
238
|
+
port=server.server_port,
|
|
239
|
+
routes=routes,
|
|
240
|
+
hits=hits,
|
|
241
|
+
)
|
|
242
|
+
finally:
|
|
243
|
+
server.shutdown()
|
|
244
|
+
server.server_close()
|
|
245
|
+
thread.join()
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _json_route(body: bytes) -> tuple[int, dict[str, str], bytes]:
|
|
249
|
+
return 200, {"Content-Type": "application/json", "Content-Length": str(len(body))}, body
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def test_get_accepts_a_valid_body_exactly_at_the_cap(
|
|
253
|
+
monkeypatch: pytest.MonkeyPatch, origin: SimpleNamespace
|
|
254
|
+
) -> None:
|
|
255
|
+
body = b'{"pad": "' + b"x" * 53 + b'"}'
|
|
256
|
+
assert len(body) == 64
|
|
257
|
+
monkeypatch.setattr(probe, "MAX_BODY_BYTES", 64)
|
|
258
|
+
origin.routes["/ok"] = _json_route(body)
|
|
259
|
+
result = probe.get(origin.base + "/ok")
|
|
260
|
+
assert result == {"ok": True, "status": 200, "body": {"pad": "x" * 53}, "error": None}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@pytest.mark.parametrize("declared_length", [True, False], ids=["content-length", "close-delimited"])
|
|
264
|
+
def test_get_refuses_an_oversized_body(
|
|
265
|
+
monkeypatch: pytest.MonkeyPatch, origin: SimpleNamespace, declared_length: bool
|
|
266
|
+
) -> None:
|
|
267
|
+
body = b'{"pad": "' + b"x" * 4096 + b'"}'
|
|
268
|
+
headers = {"Content-Type": "application/json"}
|
|
269
|
+
if declared_length:
|
|
270
|
+
headers["Content-Length"] = str(len(body))
|
|
271
|
+
monkeypatch.setattr(probe, "MAX_BODY_BYTES", 64)
|
|
272
|
+
origin.routes["/big"] = (200, headers, body)
|
|
273
|
+
result = probe.get(origin.base + "/big")
|
|
274
|
+
assert result == {
|
|
275
|
+
"ok": False,
|
|
276
|
+
"status": 200,
|
|
277
|
+
"body": None,
|
|
278
|
+
"error": "response body exceeds 64 bytes",
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def test_get_fails_closed_on_malformed_json_from_a_live_socket(origin: SimpleNamespace) -> None:
|
|
283
|
+
origin.routes["/bad"] = _json_route(b'{"truncated": ')
|
|
284
|
+
result = probe.get(origin.base + "/bad")
|
|
285
|
+
assert result["ok"] is False
|
|
286
|
+
assert result["status"] == 200
|
|
287
|
+
assert result["body"] is None
|
|
288
|
+
assert result["error"].startswith("invalid JSON response:")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def test_get_follows_a_same_origin_redirect(origin: SimpleNamespace) -> None:
|
|
292
|
+
origin.routes["/hop"] = (302, {"Location": "/ok", "Content-Length": "0"}, b"")
|
|
293
|
+
origin.routes["/ok"] = _json_route(b'{"ready": true}')
|
|
294
|
+
result = probe.get(origin.base + "/hop")
|
|
295
|
+
assert result == {"ok": True, "status": 200, "body": {"ready": True}, "error": None}
|
|
296
|
+
assert origin.hits == ["/hop", "/ok"]
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def test_get_does_not_drain_a_same_origin_redirect_body(origin: SimpleNamespace) -> None:
|
|
300
|
+
# The 3xx claims a 1 GB body and sends none. urllib's default handler would
|
|
301
|
+
# try to read all of it before following, and fail on the short read.
|
|
302
|
+
origin.routes["/hop"] = (302, {"Location": "/ok", "Content-Length": str(10**9)}, b"")
|
|
303
|
+
origin.routes["/ok"] = _json_route(b'{"ready": true}')
|
|
304
|
+
result = probe.get(origin.base + "/hop")
|
|
305
|
+
assert result == {"ok": True, "status": 200, "body": {"ready": True}, "error": None}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
@pytest.mark.parametrize(
|
|
309
|
+
("location", "target_label"),
|
|
310
|
+
[
|
|
311
|
+
("http://localhost:{port}/ok", "http://localhost:{port}"),
|
|
312
|
+
("http://127.0.0.1:1/ok", "http://127.0.0.1:1"),
|
|
313
|
+
("https://127.0.0.1:{port}/ok", "https://127.0.0.1:{port}"),
|
|
314
|
+
("//example.invalid/ok", "http://example.invalid"),
|
|
315
|
+
],
|
|
316
|
+
ids=["other-host", "other-port", "other-scheme", "scheme-relative"],
|
|
317
|
+
)
|
|
318
|
+
def test_get_refuses_a_cross_origin_redirect(
|
|
319
|
+
origin: SimpleNamespace, location: str, target_label: str
|
|
320
|
+
) -> None:
|
|
321
|
+
origin.routes["/hop"] = (302, {"Location": location.format(port=origin.port), "Content-Length": "0"}, b"")
|
|
322
|
+
origin.routes["/ok"] = _json_route(b'{"ready": true}')
|
|
323
|
+
result = probe.get(origin.base + "/hop")
|
|
324
|
+
assert result == {
|
|
325
|
+
"ok": False,
|
|
326
|
+
"status": 302,
|
|
327
|
+
"body": None,
|
|
328
|
+
"error": (
|
|
329
|
+
"HTTP Error 302: cross-origin redirect refused: "
|
|
330
|
+
f"{origin.base} -> {target_label.format(port=origin.port)}"
|
|
331
|
+
),
|
|
332
|
+
}
|
|
333
|
+
assert origin.hits == ["/hop"]
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
@pytest.mark.parametrize(
|
|
337
|
+
("newurl", "allowed"),
|
|
338
|
+
[
|
|
339
|
+
("https://a-11-oy.com/readyz/", True),
|
|
340
|
+
("https://A-11-OY.com:443/readyz", True),
|
|
341
|
+
("https://a-11-oy.com:0/readyz", False),
|
|
342
|
+
("http://a-11-oy.com/readyz", False),
|
|
343
|
+
("https://a-11-oy.com:8443/readyz", False),
|
|
344
|
+
("https://a-11-oy.com.example.invalid/readyz", False),
|
|
345
|
+
("https://a-11-oy.com@example.invalid/readyz", False),
|
|
346
|
+
("https://a-11-oy.com:notaport/readyz", False),
|
|
347
|
+
],
|
|
348
|
+
)
|
|
349
|
+
def test_redirect_handler_allows_only_the_requested_origin(newurl: str, allowed: bool) -> None:
|
|
350
|
+
handler = probe.SameOriginRedirectHandler()
|
|
351
|
+
req = urllib.request.Request("https://a-11-oy.com/readyz")
|
|
352
|
+
fp = io.BytesIO(b"redirect body")
|
|
353
|
+
if allowed:
|
|
354
|
+
follow = handler.redirect_request(req, fp, 301, "Moved", {}, newurl)
|
|
355
|
+
assert follow is not None
|
|
356
|
+
assert follow.full_url == newurl
|
|
357
|
+
else:
|
|
358
|
+
with pytest.raises(urllib.error.HTTPError) as refused:
|
|
359
|
+
handler.redirect_request(req, fp, 301, "Moved", {}, newurl)
|
|
360
|
+
assert refused.value.code == 301
|
|
361
|
+
assert "cross-origin redirect refused" in str(refused.value)
|
|
362
|
+
assert fp.closed
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
@pytest.mark.parametrize(("scheme", "default_port"), [("http", 80), ("https", 443)])
|
|
366
|
+
@pytest.mark.parametrize("port", [None, "default", 0, 8443])
|
|
367
|
+
def test_origin_defaults_only_an_omitted_port(scheme: str, default_port: int, port: int | str | None) -> None:
|
|
368
|
+
explicit_port = default_port if port == "default" else port
|
|
369
|
+
suffix = "" if explicit_port is None else f":{explicit_port}"
|
|
370
|
+
expected_port = default_port if explicit_port is None else explicit_port
|
|
371
|
+
assert probe._origin(f"{scheme}://EXAMPLE.test{suffix}/readyz") == (
|
|
372
|
+
scheme,
|
|
373
|
+
"example.test",
|
|
374
|
+
expected_port,
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _run_main(capsys: pytest.CaptureFixture[str]) -> dict:
|
|
379
|
+
assert probe.main() == 0
|
|
380
|
+
return json.loads(capsys.readouterr().out)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def test_main_emits_schema_and_never_certifies_on_healthy_upstream(
|
|
384
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
385
|
+
) -> None:
|
|
386
|
+
healthy = {
|
|
387
|
+
"ok": True,
|
|
388
|
+
"status": 200,
|
|
389
|
+
"body": {
|
|
390
|
+
"git_sha": "a" * 40,
|
|
391
|
+
"locked_formula_count": 749,
|
|
392
|
+
"doctrine_lock": {"lambda": 14, "commit": "c7c0ba17", "locked_formula_count": 749},
|
|
393
|
+
"sha": "b" * 40,
|
|
394
|
+
"signer": "yachay",
|
|
395
|
+
},
|
|
396
|
+
"error": None,
|
|
397
|
+
}
|
|
398
|
+
monkeypatch.setattr(probe, "get", lambda _url: healthy)
|
|
399
|
+
|
|
400
|
+
report = _run_main(capsys)
|
|
401
|
+
|
|
402
|
+
assert report["schema"] == "szl.origin-drift/v1"
|
|
403
|
+
# The load-bearing assertion: a fully healthy estate is still not certified.
|
|
404
|
+
assert report["certified_production_ready"] is False
|
|
405
|
+
assert report["product_honest"]["locked_formula_count"] == 749
|
|
406
|
+
assert report["product_honest"]["lambda"] == 14
|
|
407
|
+
assert report["product_honest"]["kernel"] == "c7c0ba17"
|
|
408
|
+
assert report["proof_health"]["signer"] == "yachay"
|
|
409
|
+
assert report["errors"] == {"honest": None, "readyz": None, "health": None}
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
@pytest.mark.parametrize("explicit_value", [0, None, False, ""])
|
|
413
|
+
def test_main_preserves_explicit_falsy_locked_formula_count(
|
|
414
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
415
|
+
capsys: pytest.CaptureFixture[str],
|
|
416
|
+
explicit_value: object,
|
|
417
|
+
) -> None:
|
|
418
|
+
"""An explicit top-level observation must never be hidden by fallback data."""
|
|
419
|
+
|
|
420
|
+
observed = {
|
|
421
|
+
"ok": True,
|
|
422
|
+
"status": 200,
|
|
423
|
+
"body": {
|
|
424
|
+
"locked_formula_count": explicit_value,
|
|
425
|
+
"doctrine_lock": {"locked_formula_count": 8},
|
|
426
|
+
},
|
|
427
|
+
"error": None,
|
|
428
|
+
}
|
|
429
|
+
monkeypatch.setattr(probe, "get", lambda _url: observed)
|
|
430
|
+
|
|
431
|
+
report = _run_main(capsys)
|
|
432
|
+
|
|
433
|
+
assert report["product_honest"]["locked_formula_count"] is explicit_value
|
|
434
|
+
assert report["certified_production_ready"] is False
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def test_main_uses_nested_locked_formula_count_only_when_top_level_is_absent(
|
|
438
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
439
|
+
) -> None:
|
|
440
|
+
observed = {
|
|
441
|
+
"ok": True,
|
|
442
|
+
"status": 200,
|
|
443
|
+
"body": {"doctrine_lock": {"locked_formula_count": 8}},
|
|
444
|
+
"error": None,
|
|
445
|
+
}
|
|
446
|
+
monkeypatch.setattr(probe, "get", lambda _url: observed)
|
|
447
|
+
|
|
448
|
+
report = _run_main(capsys)
|
|
449
|
+
|
|
450
|
+
assert report["product_honest"]["locked_formula_count"] == 8
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def test_main_degrades_without_raising_when_everything_is_down(
|
|
454
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
455
|
+
) -> None:
|
|
456
|
+
down = {"ok": False, "status": None, "body": None, "error": "unreachable"}
|
|
457
|
+
monkeypatch.setattr(probe, "get", lambda _url: down)
|
|
458
|
+
|
|
459
|
+
report = _run_main(capsys)
|
|
460
|
+
|
|
461
|
+
assert report["certified_production_ready"] is False
|
|
462
|
+
assert report["product_honest"]["status"] is None
|
|
463
|
+
assert report["product_honest"]["locked_formula_count"] is None
|
|
464
|
+
assert report["proof_health"]["sha"] is None
|
|
465
|
+
assert set(report["errors"].values()) == {"unreachable"}
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
@pytest.mark.parametrize("weird_body", [["not", "a", "dict"], "a string", 42, True])
|
|
469
|
+
def test_main_fails_closed_on_valid_json_that_is_not_an_object(
|
|
470
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], weird_body: object
|
|
471
|
+
) -> None:
|
|
472
|
+
"""Main stays defensive even if a caller substitutes get() with bad data."""
|
|
473
|
+
monkeypatch.setattr(
|
|
474
|
+
probe,
|
|
475
|
+
"get",
|
|
476
|
+
lambda _url: {"ok": True, "status": 200, "body": weird_body, "error": None},
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
report = _run_main(capsys)
|
|
480
|
+
|
|
481
|
+
assert report["certified_production_ready"] is False
|
|
482
|
+
assert report["product_honest"]["locked_formula_count"] is None
|
|
483
|
+
assert report["product_honest"]["lambda"] is None
|
|
484
|
+
assert report["proof_health"]["sha"] is None
|
|
485
|
+
assert report["proof_health"]["signer"] is None
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def test_report_is_json_serialisable_and_sorted(
|
|
489
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
490
|
+
) -> None:
|
|
491
|
+
monkeypatch.setattr(probe, "get", lambda _url: {"ok": True, "status": 200, "body": {}, "error": None})
|
|
492
|
+
probe.main()
|
|
493
|
+
out = capsys.readouterr().out
|
|
494
|
+
assert json.loads(out) # parses
|
|
495
|
+
keys = list(json.loads(out).keys())
|
|
496
|
+
assert keys == sorted(keys) # main() prints with sort_keys=True
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 SZL Holdings
|
|
3
|
+
"""Offline tests for the scheduled availability verdict.
|
|
4
|
+
|
|
5
|
+
The verdict reads a finished report and never touches the network. These
|
|
6
|
+
tests pin the property the scheduled job relies on: any probed origin that did
|
|
7
|
+
not answer 200 or had a rejected response makes the verdict exit 1, and a
|
|
8
|
+
healthy report exits 0.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import io
|
|
14
|
+
import json
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
21
|
+
|
|
22
|
+
import probe
|
|
23
|
+
import verdict
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _report(honest=200, readyz=200, health=200, errors=None):
|
|
27
|
+
return {
|
|
28
|
+
"schema": "szl.origin-drift/v1",
|
|
29
|
+
"certified_production_ready": False,
|
|
30
|
+
"product_honest": {"status": honest},
|
|
31
|
+
"product_readyz": {"status": readyz},
|
|
32
|
+
"proof_health": {"status": health},
|
|
33
|
+
"errors": errors or {"honest": None, "readyz": None, "health": None},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_all_200_passes():
|
|
38
|
+
assert verdict.reasons(_report()) == []
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.mark.parametrize("field", ["honest", "readyz", "health"])
|
|
42
|
+
@pytest.mark.parametrize("status", [503, 404, 301, None])
|
|
43
|
+
def test_any_unavailable_origin_fails(field, status):
|
|
44
|
+
failed = verdict.reasons(_report(**{field: status}))
|
|
45
|
+
assert len(failed) == 1
|
|
46
|
+
assert repr(status) in failed[0]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_outage_reports_every_origin_and_its_error():
|
|
50
|
+
# The shape recorded by the 2026-10-04..06 a11oy outage reports.
|
|
51
|
+
outage = "HTTP Error 503: Service Unavailable"
|
|
52
|
+
report = _report(honest=503, readyz=503, errors={"honest": outage, "readyz": outage, "health": None})
|
|
53
|
+
failed = verdict.reasons(report)
|
|
54
|
+
assert [line.split(":")[0] for line in failed] == ["product_honest", "product_readyz"]
|
|
55
|
+
assert all("503: Service Unavailable" in line for line in failed)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.mark.parametrize("bad", [None, [], "x", {}, {"schema": "other/v1"}])
|
|
59
|
+
def test_missing_or_foreign_report_fails(bad):
|
|
60
|
+
assert verdict.reasons(bad) == ["report is missing or not szl.origin-drift/v1"]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_missing_section_fails():
|
|
64
|
+
report = _report()
|
|
65
|
+
del report["proof_health"]
|
|
66
|
+
assert verdict.reasons(report) == ["proof_health: status None"]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_cli_exit_codes(tmp_path, capsys):
|
|
70
|
+
good = tmp_path / "good.json"
|
|
71
|
+
good.write_text(json.dumps(_report()), encoding="utf-8")
|
|
72
|
+
bad = tmp_path / "bad.json"
|
|
73
|
+
bad.write_text(json.dumps(_report(readyz=503)), encoding="utf-8")
|
|
74
|
+
assert verdict.main(["verdict.py", str(good)]) == 0
|
|
75
|
+
assert verdict.main(["verdict.py", str(bad)]) == 1
|
|
76
|
+
assert "ORIGIN UNAVAILABLE" in capsys.readouterr().out
|
|
77
|
+
assert verdict.main(["verdict.py", str(tmp_path / "absent.json")]) == 1
|
|
78
|
+
assert verdict.main(["verdict.py"]) == 2
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_verdict_reads_real_probe_output(monkeypatch, capsys, tmp_path):
|
|
82
|
+
# Drive probe.main with get() stubbed, then feed its exact stdout to the verdict.
|
|
83
|
+
def fake_get(url):
|
|
84
|
+
if url.endswith("/readyz"):
|
|
85
|
+
return {"ok": False, "status": 503, "body": None, "error": "HTTP Error 503: Service Unavailable"}
|
|
86
|
+
return {"ok": True, "status": 200, "body": {}, "error": None}
|
|
87
|
+
|
|
88
|
+
monkeypatch.setattr(probe, "get", fake_get)
|
|
89
|
+
assert probe.main() == 0
|
|
90
|
+
path = tmp_path / "drift-report.json"
|
|
91
|
+
path.write_text(capsys.readouterr().out, encoding="utf-8")
|
|
92
|
+
assert verdict.main(["verdict.py", str(path)]) == 1
|
|
93
|
+
assert "product_readyz: status 503 (HTTP Error 503: Service Unavailable)" in capsys.readouterr().out
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@pytest.mark.parametrize("origin", ["honest", "readyz", "health"])
|
|
97
|
+
@pytest.mark.parametrize(
|
|
98
|
+
"payload",
|
|
99
|
+
[b"<html>proxy error</html>", b"[]", b'{"padding":"' + b"x" * 64 + b'"}'],
|
|
100
|
+
ids=["invalid-json", "non-object", "oversized"],
|
|
101
|
+
)
|
|
102
|
+
def test_verdict_rejects_http_200_when_real_probe_rejects_body(
|
|
103
|
+
monkeypatch, capsys, tmp_path, origin, payload
|
|
104
|
+
):
|
|
105
|
+
"""A 200 proxy/error page must not become a green scheduled artifact."""
|
|
106
|
+
urls = {
|
|
107
|
+
"honest": f"{probe.PRODUCT}/api/a11oy/v1/honest",
|
|
108
|
+
"readyz": f"{probe.PRODUCT}/readyz",
|
|
109
|
+
"health": f"{probe.PROOF}/health.json",
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
def fake_open(request, **_kwargs):
|
|
113
|
+
response = io.BytesIO(payload if request.full_url == urls[origin] else b"{}")
|
|
114
|
+
response.status = 200
|
|
115
|
+
return response
|
|
116
|
+
|
|
117
|
+
monkeypatch.setattr(probe, "MAX_BODY_BYTES", 64)
|
|
118
|
+
monkeypatch.setattr(probe._OPENER, "open", fake_open)
|
|
119
|
+
assert probe.main() == 0
|
|
120
|
+
output = capsys.readouterr().out
|
|
121
|
+
report = json.loads(output)
|
|
122
|
+
section = next(name for name, key in verdict.ERROR_KEYS.items() if key == origin)
|
|
123
|
+
assert report[section]["status"] == 200
|
|
124
|
+
assert report["errors"][origin]
|
|
125
|
+
assert report["certified_production_ready"] is False
|
|
126
|
+
assert verdict.reasons(report) == [f"{section}: status 200 ({report['errors'][origin]})"]
|
|
127
|
+
path = tmp_path / "drift-report.json"
|
|
128
|
+
path.write_text(output, encoding="utf-8")
|
|
129
|
+
assert verdict.main(["verdict.py", str(path)]) == 1
|
|
130
|
+
assert report["errors"][origin] in capsys.readouterr().out
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
# Copyright 2026 SZL Holdings
|
|
4
|
+
"""Availability verdict for a drift report. Reads a report; never probes.
|
|
5
|
+
|
|
6
|
+
probe.py always exits 0 so a degraded report is still published. This verdict
|
|
7
|
+
is the separate, scheduled-only alert: it exits 1 when any probed origin did
|
|
8
|
+
not answer HTTP 200 or the probe rejected its response, so an outage or invalid
|
|
9
|
+
response turns the scheduled run red instead of being archived as a green
|
|
10
|
+
artifact. It does not judge doctrine values, and a pass is not a production
|
|
11
|
+
certificate.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import sys
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
ORIGINS = ("product_honest", "product_readyz", "proof_health")
|
|
21
|
+
ERROR_KEYS = {"product_honest": "honest", "product_readyz": "readyz", "proof_health": "health"}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def reasons(report: Any) -> list[str]:
|
|
25
|
+
"""Return one line per unavailable origin or rejected response."""
|
|
26
|
+
if not isinstance(report, dict) or report.get("schema") != "szl.origin-drift/v1":
|
|
27
|
+
return ["report is missing or not szl.origin-drift/v1"]
|
|
28
|
+
errors = report.get("errors") if isinstance(report.get("errors"), dict) else {}
|
|
29
|
+
out = []
|
|
30
|
+
for name in ORIGINS:
|
|
31
|
+
section = report.get(name)
|
|
32
|
+
status = section.get("status") if isinstance(section, dict) else None
|
|
33
|
+
error = errors.get(ERROR_KEYS[name])
|
|
34
|
+
if status != 200 or error:
|
|
35
|
+
out.append(f"{name}: status {status!r}" + (f" ({error})" if error else ""))
|
|
36
|
+
return out
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main(argv: list[str]) -> int:
|
|
40
|
+
if len(argv) != 2:
|
|
41
|
+
print("usage: verdict.py DRIFT_REPORT.json", file=sys.stderr)
|
|
42
|
+
return 2
|
|
43
|
+
try:
|
|
44
|
+
with open(argv[1], encoding="utf-8") as fh:
|
|
45
|
+
report = json.load(fh)
|
|
46
|
+
except (OSError, ValueError) as exc:
|
|
47
|
+
report = None
|
|
48
|
+
print(f"cannot read report: {exc}", file=sys.stderr)
|
|
49
|
+
failed = reasons(report)
|
|
50
|
+
if failed:
|
|
51
|
+
print("ORIGIN UNAVAILABLE")
|
|
52
|
+
for line in failed:
|
|
53
|
+
print(f"- {line}")
|
|
54
|
+
return 1
|
|
55
|
+
print("All probed origins answered HTTP 200 without probe errors. Not a production certificate.")
|
|
56
|
+
return 0
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
raise SystemExit(main(sys.argv))
|