sayfirst-testing 0.3.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.
- sayfirst_testing-0.3.0/.gitignore +10 -0
- sayfirst_testing-0.3.0/LICENSE +202 -0
- sayfirst_testing-0.3.0/NOTICE +12 -0
- sayfirst_testing-0.3.0/PKG-INFO +27 -0
- sayfirst_testing-0.3.0/README.md +6 -0
- sayfirst_testing-0.3.0/hatch_build.py +32 -0
- sayfirst_testing-0.3.0/pyproject.toml +50 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/__init__.py +6 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/account_directory_contract.py +95 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/clock_contract.py +49 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/decision_store_contract.py +142 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/doubles.py +121 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/guard_gates.py +145 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/peer_identity_contract.py +72 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/platforms.py +56 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/policy_archive_contract.py +87 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/policy_projection_contract.py +40 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/policy_store_contract.py +40 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/privileges.py +74 -0
- sayfirst_testing-0.3.0/src/sayfirst_testing/schemas.py +107 -0
- sayfirst_testing-0.3.0/tests/test_platform_gates.py +30 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
sayfirst control plane
|
|
2
|
+
Copyright 2026 Frédéric Aime
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use these files except in compliance with the License. A copy of the
|
|
6
|
+
License is in the LICENSE file at the root of this repository.
|
|
7
|
+
|
|
8
|
+
Distributions that incorporate this software must reproduce the attribution
|
|
9
|
+
notices this file carries (Apache License 2.0, section 4(d)).
|
|
10
|
+
|
|
11
|
+
The Apache License grants no rights in the names and marks of this project; see
|
|
12
|
+
TRADEMARKS.md.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sayfirst-testing
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Published conformance suites for control-plane ports
|
|
5
|
+
Project-URL: Repository, https://github.com/fredaime/sayfirst-control-plane
|
|
6
|
+
Project-URL: Documentation, https://github.com/fredaime/sayfirst-control-plane/blob/main/packages/testing/README.md
|
|
7
|
+
Project-URL: Changelog, https://github.com/fredaime/sayfirst-control-plane/blob/main/CHANGELOG.md
|
|
8
|
+
Author-email: fredaime <frederic.aime@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Python: <3.15,>=3.12
|
|
16
|
+
Requires-Dist: sayfirst-contract==0.3.0
|
|
17
|
+
Requires-Dist: sayfirst-control-plane==0.3.0
|
|
18
|
+
Provides-Extra: schemas
|
|
19
|
+
Requires-Dist: jsonschema<5,>=4.25; extra == 'schemas'
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
23
|
+
# `sayfirst` port conformance kit
|
|
24
|
+
|
|
25
|
+
This distribution publishes reusable contract suites for the policy authority,
|
|
26
|
+
policy projection, and append-only decision store ports. A provider is a
|
|
27
|
+
provider only when its adapter passes the corresponding suite.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
2
|
+
# `sayfirst` port conformance kit
|
|
3
|
+
|
|
4
|
+
This distribution publishes reusable contract suites for the policy authority,
|
|
5
|
+
policy projection, and append-only decision store ports. A provider is a
|
|
6
|
+
provider only when its adapter passes the corresponding suite.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Reproduce repository notices in the wheel."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CustomBuildHook(BuildHookInterface):
|
|
13
|
+
"""Include the repository licence and notice as wheel metadata."""
|
|
14
|
+
|
|
15
|
+
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
|
|
16
|
+
# In the workspace the notices live at the repository root and have to
|
|
17
|
+
# be carried in by hand. In an unpacked source distribution they
|
|
18
|
+
# travel beside the package, where the backend's own licence globs
|
|
19
|
+
# already find them, so carrying them again would add the same file
|
|
20
|
+
# twice.
|
|
21
|
+
root = Path(self.root)
|
|
22
|
+
if not (root / "LICENSE").is_file():
|
|
23
|
+
metadata_directory = (
|
|
24
|
+
f"{self.metadata.core.name.replace('-', '_')}-{self.metadata.version}.dist-info"
|
|
25
|
+
)
|
|
26
|
+
repository = root.parents[1]
|
|
27
|
+
build_data["force_include"].update(
|
|
28
|
+
{
|
|
29
|
+
str(repository / "LICENSE"): f"{metadata_directory}/licenses/LICENSE",
|
|
30
|
+
str(repository / "NOTICE"): f"{metadata_directory}/licenses/NOTICE",
|
|
31
|
+
}
|
|
32
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
[project]
|
|
3
|
+
name = "sayfirst-testing"
|
|
4
|
+
version = "0.3.0"
|
|
5
|
+
description = "Published conformance suites for control-plane ports"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.12,<3.15"
|
|
8
|
+
dependencies = ["sayfirst-contract==0.3.0", "sayfirst-control-plane==0.3.0"]
|
|
9
|
+
license = "Apache-2.0"
|
|
10
|
+
|
|
11
|
+
authors = [{ name = "fredaime", email = "frederic.aime@gmail.com" }]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 4 - Beta",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Programming Language :: Python :: 3.14",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
# The public repository this distribution sends a reader to. It was created
|
|
21
|
+
# fresh, as article 0 asks, in the act that published it on 2026-09-17, under
|
|
22
|
+
# the name the operator chose. `tests/test_pointers_survive_publication.py`
|
|
23
|
+
# holds these URLs, so a rename lands in every project file and in the guard
|
|
24
|
+
# together or not at all. No licence classifier: the licence is declared as an
|
|
25
|
+
# expression above, and an index refuses a distribution that carries both.
|
|
26
|
+
[project.urls]
|
|
27
|
+
Repository = "https://github.com/fredaime/sayfirst-control-plane"
|
|
28
|
+
Documentation = "https://github.com/fredaime/sayfirst-control-plane/blob/main/packages/testing/README.md"
|
|
29
|
+
Changelog = "https://github.com/fredaime/sayfirst-control-plane/blob/main/CHANGELOG.md"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
schemas = ["jsonschema>=4.25,<5"]
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["hatchling==1.32.0"]
|
|
36
|
+
build-backend = "hatchling.build"
|
|
37
|
+
|
|
38
|
+
[tool.uv.sources]
|
|
39
|
+
sayfirst-contract = { workspace = true }
|
|
40
|
+
sayfirst-control-plane = { workspace = true }
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/sayfirst_testing"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.sdist.force-include]
|
|
46
|
+
"../../LICENSE" = "LICENSE"
|
|
47
|
+
"../../NOTICE" = "NOTICE"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel.hooks.custom]
|
|
50
|
+
path = "hatch_build.py"
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""The contract of the AccountDirectory port, run against every provider.
|
|
3
|
+
|
|
4
|
+
Article 8: a provider that does not pass this suite is not a provider. The
|
|
5
|
+
suite asks only what the port promises — that ids resolve to names and
|
|
6
|
+
memberships, that an id with no entry is `None` and never an invented one,
|
|
7
|
+
and that the answers are the directory's own words.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from typing import Protocol
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _Directory(Protocol):
|
|
16
|
+
VERSION: int
|
|
17
|
+
|
|
18
|
+
def account(self, uid: int): ... # type: ignore[no-untyped-def]
|
|
19
|
+
|
|
20
|
+
def group_ids(self, name: str, primary_gid: int) -> tuple[int, ...]: ...
|
|
21
|
+
|
|
22
|
+
def group_name(self, gid: int) -> str | None: ...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def assert_the_port_is_versioned(directory: _Directory) -> None:
|
|
26
|
+
"""Article 8: a port carries an integer version, and so does its provider."""
|
|
27
|
+
assert isinstance(directory.VERSION, int)
|
|
28
|
+
assert not isinstance(directory.VERSION, bool)
|
|
29
|
+
assert directory.VERSION >= 1
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def assert_a_known_account_resolves(directory: _Directory, uid: int, name: str) -> None:
|
|
33
|
+
"""A uid the host knows is answered with its name and its primary group."""
|
|
34
|
+
account = directory.account(uid)
|
|
35
|
+
assert account is not None, f"uid {uid} has no account"
|
|
36
|
+
assert account.name == name
|
|
37
|
+
assert isinstance(account.primary_gid, int)
|
|
38
|
+
assert account.primary_gid >= 0
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def assert_an_unknown_id_is_none(directory: _Directory, absent_uid: int, absent_gid: int) -> None:
|
|
42
|
+
"""No entry is `None`, never a fabricated account and never an exception.
|
|
43
|
+
|
|
44
|
+
Article 2: the directory saying nothing about an id is its own answer.
|
|
45
|
+
"""
|
|
46
|
+
assert directory.account(absent_uid) is None
|
|
47
|
+
assert directory.group_name(absent_gid) is None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def assert_a_membership_includes_its_primary_group(
|
|
51
|
+
directory: _Directory, name: str, primary_gid: int
|
|
52
|
+
) -> None:
|
|
53
|
+
"""Rule G1: the primary group is a membership, listed with the others."""
|
|
54
|
+
gids = directory.group_ids(name, primary_gid)
|
|
55
|
+
assert isinstance(gids, tuple)
|
|
56
|
+
assert all(isinstance(gid, int) for gid in gids)
|
|
57
|
+
assert primary_gid in gids
|
|
58
|
+
assert len(set(gids)) == len(gids), "a group is listed twice"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def assert_group_names_are_returned_as_they_are(
|
|
62
|
+
directory: _Directory, gid: int, expected: str
|
|
63
|
+
) -> None:
|
|
64
|
+
"""Rule G6: no case folding, no trimming, no domain stripping."""
|
|
65
|
+
answered = directory.group_name(gid)
|
|
66
|
+
assert answered == expected
|
|
67
|
+
assert answered is not None
|
|
68
|
+
assert answered == answered.strip() or answered != expected.strip()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def assert_the_directory_answers_the_same_way_twice(
|
|
72
|
+
directory: _Directory, uid: int, gid: int
|
|
73
|
+
) -> None:
|
|
74
|
+
"""A resolution the daemon repeats within a lifetime must be repeatable."""
|
|
75
|
+
assert directory.account(uid) == directory.account(uid)
|
|
76
|
+
assert directory.group_name(gid) == directory.group_name(gid)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def run_the_account_directory_contract(
|
|
80
|
+
directory: _Directory,
|
|
81
|
+
*,
|
|
82
|
+
known_uid: int,
|
|
83
|
+
known_name: str,
|
|
84
|
+
known_primary_gid: int,
|
|
85
|
+
known_group_name: str,
|
|
86
|
+
absent_uid: int,
|
|
87
|
+
absent_gid: int,
|
|
88
|
+
) -> None:
|
|
89
|
+
"""Every promise of the port, against one provider."""
|
|
90
|
+
assert_the_port_is_versioned(directory)
|
|
91
|
+
assert_a_known_account_resolves(directory, known_uid, known_name)
|
|
92
|
+
assert_an_unknown_id_is_none(directory, absent_uid, absent_gid)
|
|
93
|
+
assert_a_membership_includes_its_primary_group(directory, known_name, known_primary_gid)
|
|
94
|
+
assert_group_names_are_returned_as_they_are(directory, known_primary_gid, known_group_name)
|
|
95
|
+
assert_the_directory_answers_the_same_way_twice(directory, known_uid, known_primary_gid)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""The contract of the Clock port, run against every provider.
|
|
3
|
+
|
|
4
|
+
Article 8: a provider that does not pass this suite is not a provider. Every
|
|
5
|
+
instant this project records comes through here, and every one of them is
|
|
6
|
+
offset-aware — an instant without an offset is not a time anyone can compare
|
|
7
|
+
across hosts (article 2).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from typing import Protocol
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _Clock(Protocol):
|
|
17
|
+
VERSION: int
|
|
18
|
+
|
|
19
|
+
def now(self) -> datetime: ...
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def assert_the_port_is_versioned(clock: _Clock) -> None:
|
|
23
|
+
"""Article 8: a port carries an integer version, and so does its provider."""
|
|
24
|
+
assert isinstance(clock.VERSION, int)
|
|
25
|
+
assert not isinstance(clock.VERSION, bool)
|
|
26
|
+
assert clock.VERSION >= 1
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def assert_every_instant_carries_its_offset(clock: _Clock) -> None:
|
|
30
|
+
"""An instant with no offset is one no other host can read."""
|
|
31
|
+
instant = clock.now()
|
|
32
|
+
assert isinstance(instant, datetime)
|
|
33
|
+
assert instant.tzinfo is not None
|
|
34
|
+
assert instant.utcoffset() is not None
|
|
35
|
+
assert datetime.fromisoformat(instant.isoformat()) == instant
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def assert_time_does_not_run_backwards(clock: _Clock) -> None:
|
|
39
|
+
"""Two readings in order are in order: a lifetime is computed from them."""
|
|
40
|
+
first = clock.now()
|
|
41
|
+
second = clock.now()
|
|
42
|
+
assert second >= first
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def run_the_clock_contract(clock: _Clock) -> None:
|
|
46
|
+
"""Every promise of the port, against one provider."""
|
|
47
|
+
assert_the_port_is_versioned(clock)
|
|
48
|
+
assert_every_instant_carries_its_offset(clock)
|
|
49
|
+
assert_time_does_not_run_backwards(clock)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Reusable contract suite for an append-only scoped decision authority.
|
|
3
|
+
|
|
4
|
+
Article 3: a decision is an authority record, appended once and never updated;
|
|
5
|
+
article 5: every read names its scope, and the local default never applies to
|
|
6
|
+
a read. Block 2.7 adds what a durable store owes on top: an append answers the
|
|
7
|
+
position it committed the record at, in a store it names, and the store says
|
|
8
|
+
where it keeps its records so the grade can inspect them (article 7).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from copy import deepcopy
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from sayfirst_contract.decisions import Decision, Outcome, Reason
|
|
17
|
+
from sayfirst_control_plane.ports.decision_store import (
|
|
18
|
+
DecisionAlreadyExists,
|
|
19
|
+
DecisionPosition,
|
|
20
|
+
DecisionStore,
|
|
21
|
+
ScopeRequired,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _decision(reference: str, *, scope: str = "local", outcome: Outcome = Outcome.DENY) -> Decision:
|
|
26
|
+
return Decision(
|
|
27
|
+
decision_ref=reference,
|
|
28
|
+
scope=scope,
|
|
29
|
+
capability="mail.send",
|
|
30
|
+
outcome=outcome,
|
|
31
|
+
reason=Reason.POLICY_ABSENT,
|
|
32
|
+
policy_version="sha256:" + "a" * 64,
|
|
33
|
+
approval_ref=None,
|
|
34
|
+
decided_at="2026-09-04T00:00:00Z",
|
|
35
|
+
correlation=None,
|
|
36
|
+
contract_generation=1,
|
|
37
|
+
extra={
|
|
38
|
+
"principal": {"kind": "process", "uid": 1000, "name": "build"},
|
|
39
|
+
"arguments_digest": None,
|
|
40
|
+
"rule_id": None,
|
|
41
|
+
"grant_id": None,
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def assert_decision_store_contract(
|
|
47
|
+
store: DecisionStore,
|
|
48
|
+
first: Decision,
|
|
49
|
+
replacement: Decision,
|
|
50
|
+
) -> None:
|
|
51
|
+
"""Prove append-only identity, copy isolation, and explicit scoped reads."""
|
|
52
|
+
assert store.VERSION == 1
|
|
53
|
+
expected = deepcopy(first)
|
|
54
|
+
store.append(first)
|
|
55
|
+
if isinstance(first.extra, dict):
|
|
56
|
+
first.extra["planted"] = "caller mutation"
|
|
57
|
+
assert store.get(expected.scope, expected.decision_ref) == expected
|
|
58
|
+
try:
|
|
59
|
+
store.append(replacement)
|
|
60
|
+
except DecisionAlreadyExists:
|
|
61
|
+
pass
|
|
62
|
+
else:
|
|
63
|
+
raise AssertionError("a duplicate decision was accepted")
|
|
64
|
+
assert store.get(expected.scope, expected.decision_ref) == expected
|
|
65
|
+
try:
|
|
66
|
+
store.get("", expected.decision_ref)
|
|
67
|
+
except ScopeRequired:
|
|
68
|
+
pass
|
|
69
|
+
else:
|
|
70
|
+
raise AssertionError("an unscoped read was accepted")
|
|
71
|
+
assert store.get(f"{expected.scope}-other", expected.decision_ref) is None
|
|
72
|
+
assert store.get(f"{expected.scope}-other", "never-existed") is None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class DecisionStoreContract:
|
|
76
|
+
"""Subclass, implement `make_store`, and every case below runs against the adapter."""
|
|
77
|
+
|
|
78
|
+
def make_store(self, tmp_path: Path) -> DecisionStore:
|
|
79
|
+
raise NotImplementedError
|
|
80
|
+
|
|
81
|
+
def test_a_decision_appended_is_read_back_as_appended(self, tmp_path: Path) -> None:
|
|
82
|
+
"""Article 3: the record read is the record appended, whole, not rebuilt."""
|
|
83
|
+
store = self.make_store(tmp_path)
|
|
84
|
+
given = _decision("decision-1", outcome=Outcome.ALLOW)
|
|
85
|
+
expected = deepcopy(given)
|
|
86
|
+
store.append(given)
|
|
87
|
+
given.extra["planted"] = "caller mutation" # type: ignore[index]
|
|
88
|
+
read = store.get("local", "decision-1")
|
|
89
|
+
assert read == expected
|
|
90
|
+
assert read is not given
|
|
91
|
+
|
|
92
|
+
def test_a_duplicate_decision_reference_is_refused_never_upserted(self, tmp_path: Path) -> None:
|
|
93
|
+
"""Article 3: an authority identity is append-only within its scope."""
|
|
94
|
+
store = self.make_store(tmp_path)
|
|
95
|
+
store.append(_decision("decision-1"))
|
|
96
|
+
try:
|
|
97
|
+
store.append(_decision("decision-1", outcome=Outcome.ALLOW))
|
|
98
|
+
except DecisionAlreadyExists:
|
|
99
|
+
pass
|
|
100
|
+
else:
|
|
101
|
+
raise AssertionError("a duplicate decision reference was accepted")
|
|
102
|
+
read = store.get("local", "decision-1")
|
|
103
|
+
assert read is not None and read.outcome is Outcome.DENY
|
|
104
|
+
|
|
105
|
+
def test_a_read_without_a_scope_is_refused(self, tmp_path: Path) -> None:
|
|
106
|
+
"""Article 5: the local default never applies to a read."""
|
|
107
|
+
store = self.make_store(tmp_path)
|
|
108
|
+
store.append(_decision("decision-1"))
|
|
109
|
+
try:
|
|
110
|
+
store.get("", "decision-1")
|
|
111
|
+
except ScopeRequired:
|
|
112
|
+
pass
|
|
113
|
+
else:
|
|
114
|
+
raise AssertionError("an unscoped read was accepted")
|
|
115
|
+
|
|
116
|
+
def test_another_scopes_decision_is_never_read_here(self, tmp_path: Path) -> None:
|
|
117
|
+
"""Article 5: an id in another scope is indistinguishable from no id."""
|
|
118
|
+
store = self.make_store(tmp_path)
|
|
119
|
+
store.append(_decision("decision-1", scope="one"))
|
|
120
|
+
assert store.get("two", "decision-1") is None
|
|
121
|
+
assert store.get("two", "never-existed") is None
|
|
122
|
+
read = store.get("one", "decision-1")
|
|
123
|
+
assert read is not None and read.scope == "one"
|
|
124
|
+
|
|
125
|
+
def test_an_append_answers_its_committed_position_in_a_named_store(
|
|
126
|
+
self, tmp_path: Path
|
|
127
|
+
) -> None:
|
|
128
|
+
"""C2: the position is fixed when the append completes, and never recycled."""
|
|
129
|
+
store = self.make_store(tmp_path)
|
|
130
|
+
first = store.append(_decision("decision-1"))
|
|
131
|
+
second = store.append(_decision("decision-2"))
|
|
132
|
+
other = store.append(_decision("decision-3", scope="other"))
|
|
133
|
+
assert isinstance(first, DecisionPosition) and isinstance(second, DecisionPosition)
|
|
134
|
+
assert first.store_id and first.store_id == second.store_id
|
|
135
|
+
assert (first.position, second.position) == (1, 2)
|
|
136
|
+
assert other.position == 1 and other.store_id != first.store_id
|
|
137
|
+
|
|
138
|
+
def test_the_store_says_where_it_keeps_its_records(self, tmp_path: Path) -> None:
|
|
139
|
+
"""Article 7: a grade inspects what it can name."""
|
|
140
|
+
location = self.make_store(tmp_path).location()
|
|
141
|
+
assert location.kind
|
|
142
|
+
assert location.retention
|