deterministic-scenario-engine 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. deterministic_scenario_engine-1.0.0.dist-info/METADATA +146 -0
  2. deterministic_scenario_engine-1.0.0.dist-info/RECORD +46 -0
  3. deterministic_scenario_engine-1.0.0.dist-info/WHEEL +5 -0
  4. deterministic_scenario_engine-1.0.0.dist-info/entry_points.txt +2 -0
  5. deterministic_scenario_engine-1.0.0.dist-info/licenses/LICENSE +201 -0
  6. deterministic_scenario_engine-1.0.0.dist-info/top_level.txt +1 -0
  7. scenario_engine/__init__.py +41 -0
  8. scenario_engine/_version.py +3 -0
  9. scenario_engine/adapters/__init__.py +5 -0
  10. scenario_engine/adapters/json_file.py +58 -0
  11. scenario_engine/adapters/sqlalchemy.py +207 -0
  12. scenario_engine/address.py +37 -0
  13. scenario_engine/artifacts.py +16 -0
  14. scenario_engine/canonical.py +109 -0
  15. scenario_engine/clock.py +22 -0
  16. scenario_engine/context.py +25 -0
  17. scenario_engine/control_flow.py +63 -0
  18. scenario_engine/dsl/__init__.py +31 -0
  19. scenario_engine/dsl/compiler.py +232 -0
  20. scenario_engine/dsl/errors.py +23 -0
  21. scenario_engine/dsl/models.py +74 -0
  22. scenario_engine/dsl/parser.py +582 -0
  23. scenario_engine/dsl/runtime.py +211 -0
  24. scenario_engine/errors.py +13 -0
  25. scenario_engine/expressions.py +330 -0
  26. scenario_engine/faults.py +36 -0
  27. scenario_engine/history.py +38 -0
  28. scenario_engine/ids.py +36 -0
  29. scenario_engine/integrations/__init__.py +7 -0
  30. scenario_engine/integrations/hypothesis.py +103 -0
  31. scenario_engine/integrations/schemathesis.py +142 -0
  32. scenario_engine/invariants.py +21 -0
  33. scenario_engine/manifest.py +102 -0
  34. scenario_engine/oracle.py +29 -0
  35. scenario_engine/plugins.py +175 -0
  36. scenario_engine/provenance.py +27 -0
  37. scenario_engine/pytest_plugin.py +95 -0
  38. scenario_engine/reference_packs/__init__.py +1 -0
  39. scenario_engine/reference_packs/ecommerce.py +57 -0
  40. scenario_engine/resources.py +163 -0
  41. scenario_engine/result.py +99 -0
  42. scenario_engine/rng.py +36 -0
  43. scenario_engine/runner.py +103 -0
  44. scenario_engine/state.py +39 -0
  45. scenario_engine/validation.py +95 -0
  46. scenario_engine/values.py +66 -0
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.4
2
+ Name: deterministic-scenario-engine
3
+ Version: 1.0.0
4
+ Summary: Reproducible, state-consistent business scenarios with deterministic ground truth
5
+ License-Expression: Apache-2.0
6
+ Keywords: deterministic,scenario,testing,fixtures,replay
7
+ Classifier: Development Status :: 5 - Production/Stable
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Software Development :: Testing
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: PyYAML==6.0.3
21
+ Provides-Extra: pytest
22
+ Requires-Dist: pytest<10,>=9.1; extra == "pytest"
23
+ Provides-Extra: sqlalchemy
24
+ Requires-Dist: SQLAlchemy<3,>=2.0; extra == "sqlalchemy"
25
+ Provides-Extra: hypothesis
26
+ Requires-Dist: hypothesis<7,>=6; extra == "hypothesis"
27
+ Provides-Extra: schemathesis
28
+ Requires-Dist: hypothesis<7,>=6; extra == "schemathesis"
29
+ Requires-Dist: schemathesis<5,>=4; extra == "schemathesis"
30
+ Dynamic: license-file
31
+
32
+ # Deterministic Scenario Engine
33
+
34
+ **Generate test scenarios, not just test records.**
35
+
36
+ Deterministic Scenario Engine creates reproducible, state-consistent business
37
+ histories with deterministic ground truth for testing.
38
+
39
+ ## Why it exists
40
+
41
+ Fake-data libraries and random record generators produce values; fixtures often
42
+ describe isolated records. Scenario Engine executes histories: each committed
43
+ step sees a consistent state, produces traceable state changes and artifacts,
44
+ and advances an explicit logical clock. The same scenario and execution context
45
+ can be replayed byte-for-byte, while invariants, controlled faults, and an oracle
46
+ make expected behavior explicit.
47
+
48
+ ## Core capabilities
49
+
50
+ - DSL 1 parsing, compilation, and deterministic execution
51
+ - addressed randomness and logical IDs that do not depend on a shared stream
52
+ - current state plus append-only committed history and artifacts
53
+ - whole-step atomicity
54
+ - explicit external inputs, resource DAG resolution, validators, and constraints
55
+ - subflows, ordered branches, and bounded repeat
56
+ - invariants, deterministic fault injection, provenance, and oracle evaluation
57
+ - canonical result bytes and a `ReproducibilityManifest` for exact replay
58
+ - an explicit, versioned plugin boundary and a reference ecommerce plugin pack
59
+ - a JSON-file adapter
60
+ - optional pytest, SQLAlchemy Core, Hypothesis, and Schemathesis integrations
61
+
62
+ Core execution does not require a database, network service, plugin, or property
63
+ testing framework. See [security assumptions and non-goals](docs/security-and-non-goals.md).
64
+
65
+ ## Installation
66
+
67
+ From a source checkout, use a virtual environment and install the checkout:
68
+
69
+ ```console
70
+ python3 -m venv /tmp/scenario-engine-docs-venv
71
+ /tmp/scenario-engine-docs-venv/bin/python -m pip install .
72
+ ```
73
+
74
+ Install only the named optional integrations you need:
75
+
76
+ ```console
77
+ /tmp/scenario-engine-docs-venv/bin/python -m pip install '.[pytest]'
78
+ /tmp/scenario-engine-docs-venv/bin/python -m pip install '.[sqlalchemy]'
79
+ /tmp/scenario-engine-docs-venv/bin/python -m pip install '.[hypothesis]'
80
+ /tmp/scenario-engine-docs-venv/bin/python -m pip install '.[schemathesis]'
81
+ ```
82
+
83
+ The distribution is `deterministic-scenario-engine` 1.0.0. Install the package
84
+ with `pip install deterministic-scenario-engine`, or select an optional integration
85
+ with a command such as `pip install 'deterministic-scenario-engine[pytest]'`.
86
+
87
+ ## Minimal quickstart
88
+
89
+ The public [cart scenario](examples/cart.yaml) is an executable DSL 1 document.
90
+ Run it from the repository root:
91
+
92
+ ```python
93
+ from pathlib import Path
94
+
95
+ from scenario_engine import (
96
+ compile_document,
97
+ parse_yaml,
98
+ replay_scenario,
99
+ run_scenario,
100
+ )
101
+
102
+ yaml_text = Path("examples/cart.yaml").read_text(encoding="utf-8")
103
+ document = parse_yaml(yaml_text)
104
+ scenario = compile_document(document)
105
+ result = run_scenario(scenario, root_seed="quickstart", run_index=0)
106
+
107
+ print(result.final_state["checkout_complete"])
108
+ print(result.trace())
109
+ stable_bytes = result.to_json_bytes()
110
+ manifest = result.manifest
111
+
112
+ replayed = replay_scenario(yaml_text, manifest)
113
+ assert replayed.to_json_bytes() == stable_bytes
114
+ ```
115
+
116
+ `ScenarioResult.final_state` is the supported state-reading property; the stable
117
+ normalized result contains the same data under its `state` field.
118
+
119
+ ## Determinism contract
120
+
121
+ Generation derives from semantic `ExecutionAddress` values, not consumption of
122
+ a mutable global random stream. Exact replay requires the same canonical
123
+ scenario, explicit inputs, algorithms/plugins, and recorded execution context.
124
+ Unsupported cross-version replay fails explicitly. See the [determinism model](docs/determinism.md),
125
+ [reproducibility guide](docs/reproducibility.md), and normative
126
+ [compatibility contract](docs/compatibility.md).
127
+
128
+ ## Documentation
129
+
130
+ - [Quickstart](docs/quickstart.md)
131
+ - [DSL 1 reference](docs/dsl-reference.md)
132
+ - [Determinism model](docs/determinism.md)
133
+ - [Reproducibility and replay](docs/reproducibility.md)
134
+ - [Testing, faults, and oracle](docs/testing-oracle.md)
135
+ - [Plugins](docs/plugins.md)
136
+ - [SQLAlchemy adapter](docs/sqlalchemy.md)
137
+ - [Hypothesis integration](docs/hypothesis.md)
138
+ - [Schemathesis integration](docs/schemathesis.md)
139
+ - [Public Python API](docs/api.md)
140
+ - [Security assumptions and non-goals](docs/security-and-non-goals.md)
141
+ - [Compatibility contract](docs/compatibility.md)
142
+
143
+ ## Status
144
+
145
+ The distribution and engine compatibility version are both 1.0.0. The project is
146
+ licensed under Apache-2.0.
@@ -0,0 +1,46 @@
1
+ deterministic_scenario_engine-1.0.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
2
+ scenario_engine/__init__.py,sha256=juJ604J374mfeYSYqqOd2ddg80478z5p0eLQszJDcPg,1762
3
+ scenario_engine/_version.py,sha256=OTu3s9GGIsq_Yn-iNHtoScEfXckBEXDdYnU9fPunr0g,93
4
+ scenario_engine/address.py,sha256=bRoJ-wHq1exgQNgO6CbtOEWb35JjlMhsU0Ubi8V_cn8,1343
5
+ scenario_engine/artifacts.py,sha256=ueHoppX4Z2JN-cbOgAFWeqLSO3KqJqp7mTZEqMl4YTg,330
6
+ scenario_engine/canonical.py,sha256=6GokHCbMSE_2sL7d911XGBGr7H0J1qhSt4KY4rlVCLc,3900
7
+ scenario_engine/clock.py,sha256=xt6UoKzlMDJRz-ovRqd8jeOky3DT2NUNlTqktOe-mds,796
8
+ scenario_engine/context.py,sha256=1GL8U8q5fTgqDrbeq3cm0cF2iWqstCd1NqsoObckTvM,753
9
+ scenario_engine/control_flow.py,sha256=U3-p7X-3nBxnZ-mYRNkN0JKn07gd7V3WnD8L8o8iwKc,1757
10
+ scenario_engine/errors.py,sha256=W2HBiouJpAJ8T5VFduZ7AOMc2IN7_sPBlLGuFlx6B_8,438
11
+ scenario_engine/expressions.py,sha256=6O9_DKO2mUt14dv6n9i92m30ieJTfF75dsIqSVMHfsA,11987
12
+ scenario_engine/faults.py,sha256=y6Dl0mKby9UrjWflUBtEIROYW_rzImNlT_EX6G5obME,2105
13
+ scenario_engine/history.py,sha256=HTwOtW2vUlg9zScLFzKfNGH5PD5GPxqGitizEvph6FU,1206
14
+ scenario_engine/ids.py,sha256=ZhYXQSz19xuxyz5RXj5-h7TWmJsqMS7Hr9wkRitoKFs,1045
15
+ scenario_engine/invariants.py,sha256=k1u4-xXa3Ambq2oiyiU7aAdQBnxIBq0x8RdpZTpzeyI,1208
16
+ scenario_engine/manifest.py,sha256=k8A3D1WWs2Veh19YMvCEzfJtS-1TZblKFocL659gReQ,5090
17
+ scenario_engine/oracle.py,sha256=6iQHY2bdKkalqJ2woVkXZVf_D6adj4AgMNeH_PKHiiE,1059
18
+ scenario_engine/plugins.py,sha256=gKVkz4ys3ID8_x9uF3InNyXPM66jf8pa4bG82Z5Pp2M,6391
19
+ scenario_engine/provenance.py,sha256=2ra9Y6ZJpyyGRyRCCm7jA3YPMBJHYYEV5WmBbCflSf0,999
20
+ scenario_engine/pytest_plugin.py,sha256=SSIw9IOVGjgIUcz5MbJcO-RFLKt77DFJWUS46FxNGt8,3110
21
+ scenario_engine/resources.py,sha256=Oj2nc0-XGC17JMCio9jO1pgvWAHTsLLs8Lz7vZphcEg,6719
22
+ scenario_engine/result.py,sha256=T799Wb5_6M5uLsliHcnomSkF-lS9fQlB4m6NJlBvtBQ,3364
23
+ scenario_engine/rng.py,sha256=PtvGblctS6PdsHKQicGls7ZF48OpSZDfOzKwUhfr2Xw,1156
24
+ scenario_engine/runner.py,sha256=zi8KAZhQhJbEZ5QS0ifHsaXcLqKWVbYqkYxFXKnytlY,4300
25
+ scenario_engine/state.py,sha256=Db4TQwlwBxwqdHHChSmHIhHkQ6xndMphzY4IISrcQIA,1178
26
+ scenario_engine/validation.py,sha256=jFQw3RUEKky4oKYQEqziJ_GlUvspJ7ZO1AARUf7wIYI,3936
27
+ scenario_engine/values.py,sha256=MIeAQ1nuyRfZ-2EVzG3Fyxxp0g57OPGZSpYqSFEI5c8,2131
28
+ scenario_engine/adapters/__init__.py,sha256=wi2Cxr3My1l8Xa7NQMTDsyp0CQOm6MFKDqnHpYDcjc8,119
29
+ scenario_engine/adapters/json_file.py,sha256=XsQL-13AY1HSsMnnZwXgTOdbGOS-lJm3JdfmcDQI_xE,1827
30
+ scenario_engine/adapters/sqlalchemy.py,sha256=sERHBk3YS0TeVUhi1XXxeVvfTrT4dTMLBINypDVRfEk,7943
31
+ scenario_engine/dsl/__init__.py,sha256=KJCgKaUWkAp5FDWVdNPHh-j-DoHedAW7K9YdYgIdqXM,1935
32
+ scenario_engine/dsl/compiler.py,sha256=z5JP2dWBwIDpUhEDXG6Rrld2W01wb8Pb7EaBPbDuQ9g,10363
33
+ scenario_engine/dsl/errors.py,sha256=nPjpHX3HcPPFd7BdROCF4N3rQhjDx5c9SEdAxXF4OZQ,628
34
+ scenario_engine/dsl/models.py,sha256=9DqKbfGQi-lcssrHJfvjd7IgQmU0hpATSTnoDxKQ2w8,2116
35
+ scenario_engine/dsl/parser.py,sha256=d5xReSGKDSRn8_lNWCb5SkFAkekOKjLSEsia-uM2AWM,32443
36
+ scenario_engine/dsl/runtime.py,sha256=VS6m2OdL2zAEyJcskKnqD9Qydcw9f_GHgXS4loq2woM,13975
37
+ scenario_engine/integrations/__init__.py,sha256=iguyXRsZyt4YtHEfpQr4LAVBsxIO4OX6cCnI5M9FrLQ,205
38
+ scenario_engine/integrations/hypothesis.py,sha256=ry7L-pQLrPt-HRVWJkWqAQn9FXrfHp7yFuGJ8kuqlB0,3574
39
+ scenario_engine/integrations/schemathesis.py,sha256=7OSUwS8bC9GNA7Z8coKj2CweVGlkrzOJSNWnfc28rpU,5867
40
+ scenario_engine/reference_packs/__init__.py,sha256=oSdzMPEiKH2TogeZoll6XTkCPfE4m1Tc5XhHSwgB3CM,58
41
+ scenario_engine/reference_packs/ecommerce.py,sha256=CS5v_vDBSlWMtUQsWKgnx-6ka2CUfKJaXdytHgGi6pM,2203
42
+ deterministic_scenario_engine-1.0.0.dist-info/METADATA,sha256=P7FAQTdZGNOC3H5sO7nnJPcNZLJk3Y5Qwv3FVw-aGPo,5698
43
+ deterministic_scenario_engine-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
44
+ deterministic_scenario_engine-1.0.0.dist-info/entry_points.txt,sha256=j3-6RljmMjXArUkm-w2IpB0gtaQM6yzPnd7PKpBwdyY,59
45
+ deterministic_scenario_engine-1.0.0.dist-info/top_level.txt,sha256=6TwXMxB_Y68vYxsxsLWducxZNFJ5zYT2FdPaFDO57Fg,16
46
+ deterministic_scenario_engine-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ scenario_engine = scenario_engine.pytest_plugin
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ scenario_engine
@@ -0,0 +1,41 @@
1
+ """Deliberately small supported Python API for Deterministic Scenario Engine."""
2
+
3
+ from .address import ExecutionAddress
4
+ from .canonical import (
5
+ canonical_scenario_bytes, canonical_scenario_hash, canonical_scenario_payload,
6
+ )
7
+ from .control_flow import ControlFlowError
8
+ from .dsl import (
9
+ DSLCompilationError, DSLError, DSLParseError, DSLSchemaError,
10
+ compile_document, evaluate_scenario, parse_yaml, parse_yaml_file,
11
+ replay_scenario, run_scenario,
12
+ )
13
+ from .errors import ScenarioEngineError
14
+ from .expressions import ExpressionEvaluationError
15
+ from .faults import FaultError
16
+ from .ids import LogicalID
17
+ from .invariants import InvariantError
18
+ from .manifest import (
19
+ ENGINE_VERSION, ReplayCompatibilityError, ReproducibilityManifest,
20
+ )
21
+ from .oracle import OracleError
22
+ from .plugins import (
23
+ GeneratorPlugin, PluginError, PluginGenerationContext, PluginRegistry,
24
+ )
25
+ from .resources import ResourceError
26
+ from .result import ScenarioResult
27
+ from .validation import ConstraintError, ResourceValidationError
28
+ from .values import MISSING
29
+
30
+ __all__ = [
31
+ "ENGINE_VERSION", "MISSING", "LogicalID", "ExecutionAddress",
32
+ "ScenarioResult", "ReproducibilityManifest", "parse_yaml",
33
+ "parse_yaml_file", "compile_document", "run_scenario", "replay_scenario",
34
+ "evaluate_scenario", "canonical_scenario_payload", "canonical_scenario_bytes",
35
+ "canonical_scenario_hash", "GeneratorPlugin", "PluginRegistry",
36
+ "PluginGenerationContext", "ScenarioEngineError", "DSLError",
37
+ "DSLParseError", "DSLSchemaError", "DSLCompilationError",
38
+ "ExpressionEvaluationError", "ResourceError", "ResourceValidationError",
39
+ "ConstraintError", "ControlFlowError", "InvariantError", "FaultError",
40
+ "OracleError", "ReplayCompatibilityError", "PluginError",
41
+ ]
@@ -0,0 +1,3 @@
1
+ """Single authoritative distribution and engine compatibility version."""
2
+
3
+ VERSION = "1.0.0"
@@ -0,0 +1,5 @@
1
+ """Narrow deterministic output adapters."""
2
+
3
+ from .json_file import write_result_json
4
+
5
+ __all__ = ["write_result_json"]
@@ -0,0 +1,58 @@
1
+ """Atomic filesystem output for canonical :class:`ScenarioResult` JSON bytes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ import tempfile
8
+ from typing import Final
9
+
10
+ from scenario_engine.result import ScenarioResult
11
+
12
+
13
+ _TEMP_PREFIX: Final = ".scenario-result-"
14
+
15
+
16
+ def write_result_json(
17
+ result: ScenarioResult,
18
+ path: str | os.PathLike[str],
19
+ *,
20
+ overwrite: bool = False,
21
+ ) -> None:
22
+ """Write canonical result bytes using guarded, same-directory replacement.
23
+
24
+ This is process-level guarded atomic replacement, not a distributed
25
+ transaction. The caller must provide an existing parent directory.
26
+ """
27
+ if not isinstance(result, ScenarioResult):
28
+ raise TypeError("result must be a ScenarioResult")
29
+
30
+ target = Path(path)
31
+ parent = target.parent
32
+ if not parent.is_dir():
33
+ raise FileNotFoundError(f"target parent directory does not exist: {parent}")
34
+ if not overwrite and target.exists():
35
+ raise FileExistsError(target)
36
+
37
+ temporary_name: str | None = None
38
+ try:
39
+ descriptor, temporary_name = tempfile.mkstemp(prefix=_TEMP_PREFIX, dir=parent)
40
+ with os.fdopen(descriptor, "wb") as output:
41
+ output.write(result.to_json_bytes())
42
+ output.flush()
43
+ os.fsync(output.fileno())
44
+
45
+ if overwrite:
46
+ os.replace(temporary_name, target)
47
+ else:
48
+ # Hard-link publication is atomic and refuses an existing target,
49
+ # including one created after the process-level preflight check.
50
+ os.link(temporary_name, target)
51
+ os.unlink(temporary_name)
52
+ temporary_name = None
53
+ finally:
54
+ if temporary_name is not None:
55
+ try:
56
+ os.unlink(temporary_name)
57
+ except FileNotFoundError:
58
+ pass