graphddb-runtime 0.7.9__tar.gz → 0.7.10__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.
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/PKG-INFO +2 -2
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/runtime.py +16 -1
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/transactions.py +155 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime.egg-info/PKG-INFO +2 -2
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime.egg-info/SOURCES.txt +1 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime.egg-info/requires.txt +1 -1
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/pyproject.toml +2 -2
- graphddb_runtime-0.7.10/tests/test_guard_eval.py +146 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_spec_version_guard.py +64 -6
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/README.md +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/__init__.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/async_runtime.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/batch.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/concurrency.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/cursor.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/errors.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/filters.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/hydration.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/limits.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/middleware.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/per_key_cursor.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/relations.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime/templates.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime.egg-info/dependency_links.txt +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime.egg-info/top_level.txt +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/setup.cfg +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_concurrency.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_contract_runtime.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_crosslang_python_cells.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_description.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_description_followups.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_description_jsdoc.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_binding_contract.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_command.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_compose.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_contract.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_edge_derive.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_edge_write.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_events.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_maintain.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_middleware.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_referential.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_relations.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_unique.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_maintain.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_middleware.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_relations.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_ttl.py +0 -0
- {graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_unit.py +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphddb-runtime
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.10
|
|
4
4
|
Summary: Thin DynamoDB executor for GraphDDB-generated Python repositories (single-operation core, issue #44).
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: boto3>=1.26
|
|
9
|
-
Requires-Dist: behavior-contracts==0.1.
|
|
9
|
+
Requires-Dist: behavior-contracts==0.1.3
|
|
10
10
|
Provides-Extra: test
|
|
11
11
|
Requires-Dist: pytest>=7.0; extra == "test"
|
|
12
12
|
|
|
@@ -57,13 +57,21 @@ from .templates import (
|
|
|
57
57
|
validate_params,
|
|
58
58
|
)
|
|
59
59
|
from .transactions import MAX_TRANSACT_ITEMS, TransactionExpander
|
|
60
|
+
from .transactions import _guard_holds as _tx_guard_holds
|
|
60
61
|
from .transactions import _when_holds as _tx_when_holds
|
|
61
62
|
|
|
62
63
|
#: The operation-IR (spec) version this runtime implements — the newest
|
|
63
64
|
#: ``manifest.json`` / ``operations.json`` document version whose vocabulary it
|
|
64
65
|
#: fully understands. See :func:`_validate_spec_version` for the compatibility
|
|
65
66
|
#: rule.
|
|
66
|
-
|
|
67
|
+
#:
|
|
68
|
+
#: Phase 3 S6 (#266): bumped 1.1 -> 1.2 — the S6 half of the "one release column"
|
|
69
|
+
#: 1.2 bump (TS reached 1.2 in S5). This runtime now EVALUATES the 1.2 SCP
|
|
70
|
+
#: Expression IR ``guard`` vocabulary (see :func:`transactions._guard_holds`), so a
|
|
71
|
+
#: guard-bearing 1.2 bundle is ACCEPTED and executed on py/rust/go (matching TS).
|
|
72
|
+
#: Guard-free bundles remain stamped 1.1 by the generator (the conditional stamper
|
|
73
|
+
#: is unchanged), so an older runtime still runs them.
|
|
74
|
+
SPEC_VERSION_SUPPORTED = "1.2"
|
|
67
75
|
|
|
68
76
|
|
|
69
77
|
def _validate_spec_version(document: Mapping[str, Any], label: str) -> None:
|
|
@@ -1409,6 +1417,9 @@ class GraphDDBRuntime:
|
|
|
1409
1417
|
continue # ConditionCheck — not a logical write op.
|
|
1410
1418
|
for_each = item.get("forEach")
|
|
1411
1419
|
when = item.get("when")
|
|
1420
|
+
# Issue #266 (Phase 3 S6): a guard-false item is skipped here too, so
|
|
1421
|
+
# W1 does not fire for a write the expander drops (parity with `when`).
|
|
1422
|
+
guard = item.get("guard")
|
|
1412
1423
|
if for_each:
|
|
1413
1424
|
source = params.get(for_each["source"])
|
|
1414
1425
|
if not isinstance(source, list):
|
|
@@ -1416,6 +1427,8 @@ class GraphDDBRuntime:
|
|
|
1416
1427
|
for element in source:
|
|
1417
1428
|
if when and not _tx_when_holds(when, params, element):
|
|
1418
1429
|
continue
|
|
1430
|
+
if guard is not None and not _tx_guard_holds(guard, params, element):
|
|
1431
|
+
continue
|
|
1419
1432
|
op_params = dict(params)
|
|
1420
1433
|
op_params.update({f"item.{k}": v for k, v in element.items()})
|
|
1421
1434
|
op_params.update(element)
|
|
@@ -1423,6 +1436,8 @@ class GraphDDBRuntime:
|
|
|
1423
1436
|
else:
|
|
1424
1437
|
if when and not _tx_when_holds(when, params, None):
|
|
1425
1438
|
continue
|
|
1439
|
+
if guard is not None and not _tx_guard_holds(guard, params, None):
|
|
1440
|
+
continue
|
|
1426
1441
|
yield kind, item, dict(params)
|
|
1427
1442
|
|
|
1428
1443
|
# ── command-contract execution (issue #64) ──────────────────────────────
|
|
@@ -18,6 +18,9 @@ from __future__ import annotations
|
|
|
18
18
|
import re
|
|
19
19
|
from typing import Any, Dict, List, Mapping, Optional
|
|
20
20
|
|
|
21
|
+
from behavior_contracts import ExprFailure as _ExprFailure
|
|
22
|
+
from behavior_contracts import evaluate_expression as _evaluate_expression
|
|
23
|
+
|
|
21
24
|
from .filters import compile_filter
|
|
22
25
|
|
|
23
26
|
_PLACEHOLDER_RE = re.compile(r"\{[^{}]+\}")
|
|
@@ -168,6 +171,134 @@ def _when_holds(
|
|
|
168
171
|
return left == right if when["op"] == "eq" else left != right
|
|
169
172
|
|
|
170
173
|
|
|
174
|
+
# ── SCP guard evaluation seam (issue #266, Phase 3 S6) ────────────────────────
|
|
175
|
+
#
|
|
176
|
+
# The branch-for-branch port of the TS ``evaluateGuard`` seam
|
|
177
|
+
# (``src/runtime/guard-eval.ts``, S5 / #265). A ``guard`` on a transaction item is
|
|
178
|
+
# an SCP Expression IR node — a boolean predicate over the transaction ``input``
|
|
179
|
+
# surface and, inside a ``forEach``, the current ``item`` element. S1 loud-rejected
|
|
180
|
+
# every guard-bearing bundle; S6 turns that reject into EVALUATION for the
|
|
181
|
+
# client-side ``input`` / ``item`` class, delegating the normative semantics to the
|
|
182
|
+
# shared ``behavior_contracts`` evaluator (``evaluate_expression``) — the SAME SSoT
|
|
183
|
+
# the TS/Rust/Go runtimes evaluate against, so a guard decides identically in every
|
|
184
|
+
# language: typed ``eq`` (int != string), i64 checked arithmetic, code-point string
|
|
185
|
+
# ordering, truncated-division ``mod`` sign.
|
|
186
|
+
#
|
|
187
|
+
# The two-condition-class rule (identical to TS): a ``guard`` references ONLY
|
|
188
|
+
# ``input`` / ``item`` (known client-side before the write), so guard-false skips
|
|
189
|
+
# the item — the same semantics the legacy ``when`` string-compare guard has, no
|
|
190
|
+
# DynamoDB round-trip. An expression that reads a DynamoDB attribute of the row
|
|
191
|
+
# being written is the ``scpExpr`` write-condition class (out of S6 scope) and must
|
|
192
|
+
# lower to a ``ConditionExpression``; :func:`_assert_guard_scopes` fail-closes a
|
|
193
|
+
# guard whose refs escape ``input`` / ``item`` so a client-side stale check can
|
|
194
|
+
# never happen.
|
|
195
|
+
|
|
196
|
+
_GUARD_SCOPE_ROOTS = frozenset(("input", "item"))
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _assert_guard_scopes(node: Any, context: str) -> None:
|
|
200
|
+
"""Walk an expression IR node; reject any ``ref`` / ``refOpt`` whose ROOT segment
|
|
201
|
+
is not a client-side guard scope (``input`` / ``item``). Mirrors the TS
|
|
202
|
+
``assertGuardScopes`` — a ``prop``-rooted guard is the write-condition class that
|
|
203
|
+
must lower to a ``ConditionExpression``; evaluating it client-side would be a
|
|
204
|
+
stale read, so it is loud-rejected (issue #266)."""
|
|
205
|
+
if not isinstance(node, Mapping):
|
|
206
|
+
return
|
|
207
|
+
ref = node.get("ref")
|
|
208
|
+
if ref is None:
|
|
209
|
+
ref = node.get("refOpt")
|
|
210
|
+
if isinstance(ref, list):
|
|
211
|
+
root = ref[0] if ref else None
|
|
212
|
+
if isinstance(root, str) and root not in _GUARD_SCOPE_ROOTS:
|
|
213
|
+
raise ValueError(
|
|
214
|
+
f"{context}: this guard references '{root}', but a client-side guard "
|
|
215
|
+
"may only reference the transaction 'input' / fan-out 'item' scopes. "
|
|
216
|
+
"An expression that reads a DynamoDB attribute must lower to a "
|
|
217
|
+
"ConditionExpression (write-condition class), not be evaluated "
|
|
218
|
+
"client-side (issue #266). Refusing to evaluate a stale check."
|
|
219
|
+
)
|
|
220
|
+
return
|
|
221
|
+
# Recurse every nested node (operator args, obj values, arr elements).
|
|
222
|
+
for value in node.values():
|
|
223
|
+
if isinstance(value, list):
|
|
224
|
+
for child in value:
|
|
225
|
+
_assert_guard_scopes(child, context)
|
|
226
|
+
elif isinstance(value, Mapping):
|
|
227
|
+
# ``{obj: {...}}`` construction — its values are nested nodes.
|
|
228
|
+
for child in value.values():
|
|
229
|
+
_assert_guard_scopes(child, context)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _to_shared_value(v: Any) -> Any:
|
|
233
|
+
"""Convert a plain graphddb runtime value into the ``behavior_contracts`` value
|
|
234
|
+
model, classifying by the VALUE's integrality — NOT by its declared numeric
|
|
235
|
+
subtype. This is the branch-for-branch mirror of the TS ``toSharedValue``
|
|
236
|
+
(#253): TS maps an integral JS ``number`` (``5`` == ``5.0``) to a ``bigint``
|
|
237
|
+
(int), so a scope value of ``5.0`` compares equal to an ``{int:"5"}`` literal.
|
|
238
|
+
|
|
239
|
+
graphddb's ``@number`` (R7) draws no int/float type distinction, so the only
|
|
240
|
+
cross-language-consistent rule is to classify by value integrality: an
|
|
241
|
+
integral-valued ``float`` (``5.0``) becomes a Python ``int`` (an int in the
|
|
242
|
+
shared model), a fractional ``float`` stays a ``float``. Without this, Python's
|
|
243
|
+
native ``isinstance(v, float)`` would classify ``5.0`` as float and an
|
|
244
|
+
``input.n == {int:"5"}`` guard would TYPE_MISMATCH where TS returns True —
|
|
245
|
+
a cross-language divergence (S5 audit rule, issue #266)."""
|
|
246
|
+
if isinstance(v, bool):
|
|
247
|
+
# bool is an int subclass in Python; keep it a bool in the shared model.
|
|
248
|
+
return v
|
|
249
|
+
if isinstance(v, float):
|
|
250
|
+
# Integral-valued float -> int (matches TS Number.isInteger). NaN/Inf are
|
|
251
|
+
# non-integral, so they stay float and the shared core loud-rejects them.
|
|
252
|
+
if v.is_integer():
|
|
253
|
+
return int(v)
|
|
254
|
+
return v
|
|
255
|
+
if isinstance(v, list):
|
|
256
|
+
return [_to_shared_value(e) for e in v]
|
|
257
|
+
if isinstance(v, Mapping):
|
|
258
|
+
return {k: _to_shared_value(field) for k, field in v.items()}
|
|
259
|
+
return v
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _to_shared_params(params: Mapping[str, Any]) -> Dict[str, Any]:
|
|
263
|
+
return {name: _to_shared_value(value) for name, value in params.items()}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _guard_holds(
|
|
267
|
+
guard: Mapping[str, Any],
|
|
268
|
+
params: Mapping[str, Any],
|
|
269
|
+
element: Optional[Mapping[str, Any]],
|
|
270
|
+
context: str = "declarative transaction guard",
|
|
271
|
+
) -> bool:
|
|
272
|
+
"""Evaluate a ``guard`` ExpressionSpec against the transaction ``input`` params
|
|
273
|
+
and the (optional) ``forEach`` element, returning its boolean truth value.
|
|
274
|
+
Delegates the normative semantics to the shared ``behavior_contracts`` evaluator
|
|
275
|
+
— the same SSoT every other-language runtime evaluates against (S5/S6/S7).
|
|
276
|
+
|
|
277
|
+
Raises ``ValueError`` if the guard escapes the ``input`` / ``item`` scopes
|
|
278
|
+
(:func:`_assert_guard_scopes`), if the shared evaluator reports a Failure (i64
|
|
279
|
+
overflow, type mismatch, unknown op, unknown exprVersion, …), or if the guard
|
|
280
|
+
does not evaluate to a boolean — all fail-closed / loud (issue #266)."""
|
|
281
|
+
expr = guard["expr"]
|
|
282
|
+
_assert_guard_scopes(expr, context)
|
|
283
|
+
scope: Dict[str, Any] = {"input": _to_shared_params(params)}
|
|
284
|
+
if element is not None:
|
|
285
|
+
scope["item"] = _to_shared_value(dict(element))
|
|
286
|
+
try:
|
|
287
|
+
result = _evaluate_expression(expr, scope)
|
|
288
|
+
except _ExprFailure as exc:
|
|
289
|
+
code = getattr(exc, "code", "?")
|
|
290
|
+
raise ValueError(
|
|
291
|
+
f"{context}: guard evaluation failed ({code}): {exc}"
|
|
292
|
+
) from exc
|
|
293
|
+
if not isinstance(result, bool):
|
|
294
|
+
got = "null" if result is None else type(result).__name__
|
|
295
|
+
raise ValueError(
|
|
296
|
+
f"{context}: a guard expression must evaluate to a boolean, got {got} "
|
|
297
|
+
"(issue #266)."
|
|
298
|
+
)
|
|
299
|
+
return result
|
|
300
|
+
|
|
301
|
+
|
|
171
302
|
def _apply_maintain_transform(op: str, args: List[Any], value: Any) -> Any:
|
|
172
303
|
"""Apply one maintenance projection transform to a resolved source value (#129,
|
|
173
304
|
Epic #118) — the branch-for-branch mirror of the TS in-process
|
|
@@ -477,6 +608,19 @@ class TransactionExpander:
|
|
|
477
608
|
values[alias] = self._serializer.serialize(resolved)
|
|
478
609
|
target["ConditionExpression"] = condition["expression"]
|
|
479
610
|
return
|
|
611
|
+
if kind == "scpExpr":
|
|
612
|
+
# Issue #266 (Phase 3 S6): the ``scpExpr`` write-condition class refs a
|
|
613
|
+
# DynamoDB attribute of the row being written, so it must lower to a
|
|
614
|
+
# ConditionExpression — NOT be evaluated client-side (a stale read is a
|
|
615
|
+
# #242-type silent drop). That lowering is out of S6 scope, so fail
|
|
616
|
+
# loudly rather than execute the write with its condition ignored.
|
|
617
|
+
# (Mirrors the TS ``applyCondition`` scpExpr reject.)
|
|
618
|
+
raise ValueError(
|
|
619
|
+
"declarative transaction: this runtime does not evaluate scpExpr "
|
|
620
|
+
"write conditions yet (spec 1.2 expression vocabulary, issue #261); "
|
|
621
|
+
"the write-condition class must lower to a ConditionExpression. "
|
|
622
|
+
"Refusing to execute the write with its condition ignored."
|
|
623
|
+
)
|
|
480
624
|
clauses = []
|
|
481
625
|
for i, (field, tmpl) in enumerate(condition["fields"].items()):
|
|
482
626
|
n = f"#e{i}"
|
|
@@ -667,6 +811,13 @@ class TransactionExpander:
|
|
|
667
811
|
for item in spec.get("items", []):
|
|
668
812
|
for_each = item.get("forEach")
|
|
669
813
|
when = item.get("when")
|
|
814
|
+
# Issue #266 (Phase 3 S6): a `guard` (SCP Expression IR over the
|
|
815
|
+
# `input` / fan-out `item` scopes) is EVALUATED via behavior_contracts
|
|
816
|
+
# — the normative SSoT every runtime shares. Guard-false skips the item
|
|
817
|
+
# (matching the legacy string-compare `when`); guard-true keeps it. An
|
|
818
|
+
# attribute-referencing guard is loud-rejected inside `_guard_holds`
|
|
819
|
+
# (write-condition class, out of scope). Matches the TS S5 seam.
|
|
820
|
+
guard = item.get("guard")
|
|
670
821
|
if for_each:
|
|
671
822
|
source = params.get(for_each["source"])
|
|
672
823
|
if not isinstance(source, list):
|
|
@@ -677,9 +828,13 @@ class TransactionExpander:
|
|
|
677
828
|
for element in source:
|
|
678
829
|
if when and not _when_holds(when, params, element):
|
|
679
830
|
continue
|
|
831
|
+
if guard is not None and not _guard_holds(guard, params, element):
|
|
832
|
+
continue
|
|
680
833
|
expanded.append(self._build_item(item, params, element))
|
|
681
834
|
else:
|
|
682
835
|
if when and not _when_holds(when, params, None):
|
|
683
836
|
continue
|
|
837
|
+
if guard is not None and not _guard_holds(guard, params, None):
|
|
838
|
+
continue
|
|
684
839
|
expanded.append(self._build_item(item, params, None))
|
|
685
840
|
return _collapse_same_key_items(expanded)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphddb-runtime
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.10
|
|
4
4
|
Summary: Thin DynamoDB executor for GraphDDB-generated Python repositories (single-operation core, issue #44).
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: boto3>=1.26
|
|
9
|
-
Requires-Dist: behavior-contracts==0.1.
|
|
9
|
+
Requires-Dist: behavior-contracts==0.1.3
|
|
10
10
|
Provides-Extra: test
|
|
11
11
|
Requires-Dist: pytest>=7.0; extra == "test"
|
|
12
12
|
|
|
@@ -26,6 +26,7 @@ tests/test_crosslang_python_cells.py
|
|
|
26
26
|
tests/test_description.py
|
|
27
27
|
tests/test_description_followups.py
|
|
28
28
|
tests/test_description_jsdoc.py
|
|
29
|
+
tests/test_guard_eval.py
|
|
29
30
|
tests/test_integration.py
|
|
30
31
|
tests/test_integration_binding_contract.py
|
|
31
32
|
tests/test_integration_command.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "graphddb-runtime"
|
|
7
|
-
version = "0.7.
|
|
7
|
+
version = "0.7.10"
|
|
8
8
|
description = "Thin DynamoDB executor for GraphDDB-generated Python repositories (single-operation core, issue #44)."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -14,7 +14,7 @@ license = { text = "MIT" }
|
|
|
14
14
|
# canonicalisation) are delegated to the extracted shared package
|
|
15
15
|
# ``behavior-contracts`` (import name ``behavior_contracts``). The runtime
|
|
16
16
|
# imports it unconditionally, so it is a HARD dependency.
|
|
17
|
-
dependencies = ["boto3>=1.26", "behavior-contracts==0.1.
|
|
17
|
+
dependencies = ["boto3>=1.26", "behavior-contracts==0.1.3"]
|
|
18
18
|
|
|
19
19
|
[project.optional-dependencies]
|
|
20
20
|
test = ["pytest>=7.0"]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""SCP guard evaluation tests (issue #266, Phase 3 S6).
|
|
2
|
+
|
|
3
|
+
The py runtime evaluates a transaction-item ``guard`` (an SCP Expression IR node
|
|
4
|
+
over the ``input`` / fan-out ``item`` scopes) via the shared ``behavior_contracts``
|
|
5
|
+
evaluator — the SAME normative SSoT the TS S5 seam (``src/runtime/guard-eval.ts``)
|
|
6
|
+
evaluates against, so a guard decides IDENTICALLY across TS/py/rust/go. These
|
|
7
|
+
tests pin the adversarial matrix the S5 audit covered: typed ``eq`` (int != string),
|
|
8
|
+
i64 boundary, code-point string compare, truncated ``mod`` sign, non-bool loud,
|
|
9
|
+
unknown-op loud, scope-escape loud, and — the critical cross-language rule — an
|
|
10
|
+
integral-valued number classifies as int (matching the TS #253 adapter), NOT as
|
|
11
|
+
float -> TYPE_MISMATCH.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any, Optional
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
from graphddb_runtime.transactions import _guard_holds, _to_shared_value
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _holds(expr: Any, params: dict, element: Optional[dict] = None) -> bool:
|
|
24
|
+
return _guard_holds({"exprVersion": 1, "expr": expr}, params, element)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# ── the integral-float classification rule (the crux, S5 audit) ───────────────
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_integral_float_param_classifies_as_int():
|
|
31
|
+
# A param value of 5.0 must compare EQUAL to an {int:"5"} literal — matching
|
|
32
|
+
# the TS adapter (Number.isInteger(5.0) -> bigint). graphddb @number (R7) has
|
|
33
|
+
# no int/float distinction, so classification is by VALUE integrality.
|
|
34
|
+
assert _holds({"eq": [{"ref": ["input", "n"]}, {"int": "5"}]}, {"n": 5.0}) is True
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_integral_int_param_classifies_as_int():
|
|
38
|
+
assert _holds({"eq": [{"ref": ["input", "n"]}, {"int": "5"}]}, {"n": 5}) is True
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_fractional_float_param_mismatches_int_literal():
|
|
42
|
+
# 5.5 is genuinely a float; comparing it to an int literal is a TYPE_MISMATCH
|
|
43
|
+
# (int != float is normative) — matching TS.
|
|
44
|
+
with pytest.raises(ValueError, match="TYPE_MISMATCH"):
|
|
45
|
+
_holds({"eq": [{"ref": ["input", "n"]}, {"int": "5"}]}, {"n": 5.5})
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_to_shared_value_classifies_by_integrality():
|
|
49
|
+
assert _to_shared_value(5.0) == 5 and isinstance(_to_shared_value(5.0), int)
|
|
50
|
+
assert isinstance(_to_shared_value(5.5), float)
|
|
51
|
+
# bool is an int subclass in Python but must stay a bool in the shared model.
|
|
52
|
+
assert _to_shared_value(True) is True
|
|
53
|
+
# nested integral floats reclassify recursively.
|
|
54
|
+
assert _to_shared_value({"a": 2.0, "b": [3.0, 4.5]}) == {"a": 2, "b": [3, 4.5]}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ── typed eq (int != string) ──────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_typed_eq_int_never_equals_string():
|
|
61
|
+
with pytest.raises(ValueError, match="TYPE_MISMATCH"):
|
|
62
|
+
_holds({"eq": [{"int": "5"}, "5"]}, {})
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_string_eq_string_by_value():
|
|
66
|
+
assert _holds({"eq": [{"ref": ["input", "role"]}, "admin"]}, {"role": "admin"}) is True
|
|
67
|
+
assert _holds({"eq": [{"ref": ["input", "role"]}, "admin"]}, {"role": "user"}) is False
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ── i64 boundary ──────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_i64_max_boundary_ok():
|
|
74
|
+
# 2^63-1 is the max i64; adding within range is fine.
|
|
75
|
+
assert _holds(
|
|
76
|
+
{"eq": [{"add": [{"int": "9223372036854775806"}, {"int": "1"}]}, {"int": "9223372036854775807"}]},
|
|
77
|
+
{},
|
|
78
|
+
) is True
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_i64_overflow_is_loud():
|
|
82
|
+
with pytest.raises(ValueError, match="INT_OVERFLOW"):
|
|
83
|
+
_holds({"lt": [{"add": [{"int": "9223372036854775807"}, {"int": "1"}]}, {"int": "0"}]}, {})
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# ── code-point string compare ─────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_string_compare_is_code_point_order():
|
|
90
|
+
# 'Z' (0x5A) < 'a' (0x61) in code-point order.
|
|
91
|
+
assert _holds({"lt": ["Z", "a"]}, {}) is True
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ── truncated mod sign (sign of dividend) ─────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_mod_sign_follows_dividend_negative():
|
|
98
|
+
# -7 mod 3 == -1 (truncated division; sign follows dividend, NOT Python %).
|
|
99
|
+
assert _holds({"eq": [{"mod": [{"int": "-7"}, {"int": "3"}]}, {"int": "-1"}]}, {}) is True
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_mod_sign_follows_dividend_positive():
|
|
103
|
+
assert _holds({"eq": [{"mod": [{"int": "7"}, {"int": "-3"}]}, {"int": "1"}]}, {}) is True
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# ── non-bool result is loud ───────────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_non_bool_guard_is_loud():
|
|
110
|
+
with pytest.raises(ValueError, match="must evaluate to a boolean"):
|
|
111
|
+
_holds({"int": "5"}, {})
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_null_guard_result_is_loud():
|
|
115
|
+
with pytest.raises(ValueError, match="must evaluate to a boolean"):
|
|
116
|
+
_holds({"refOpt": ["input", "missing"]}, {"missing": None})
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# ── unknown op / unknown exprVersion is loud (fail-closed) ────────────────────
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_unknown_op_is_loud():
|
|
123
|
+
with pytest.raises(ValueError, match="UNKNOWN_OP"):
|
|
124
|
+
_holds({"frobnicate": [1, 2]}, {})
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# ── scope escape (prop-rooted guard) is loud ──────────────────────────────────
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_prop_rooted_guard_is_rejected():
|
|
131
|
+
with pytest.raises(ValueError, match="only reference the transaction 'input'"):
|
|
132
|
+
_holds({"eq": [{"ref": ["prop", "status"]}, "closed"]}, {})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_nested_prop_ref_is_rejected():
|
|
136
|
+
with pytest.raises(ValueError, match="only reference the transaction 'input'"):
|
|
137
|
+
_holds({"and": [True, {"eq": [{"ref": ["prop", "x"]}, "y"]}]}, {})
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# ── skip / keep semantics ─────────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def test_guard_true_keeps_guard_false_skips():
|
|
144
|
+
expr = {"eq": [{"ref": ["input", "active"]}, True]}
|
|
145
|
+
assert _holds(expr, {"active": True}) is True
|
|
146
|
+
assert _holds(expr, {"active": False}) is False
|
|
@@ -59,10 +59,20 @@ def _paths_with_versions(tmp_path, manifest_version, operations_version):
|
|
|
59
59
|
)
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
def
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
assert
|
|
62
|
+
def test_supported_version_constant_is_1_2():
|
|
63
|
+
# Phase 3 S6 (#266): the runtime now understands the 1.2 SCP Expression IR
|
|
64
|
+
# guard vocabulary.
|
|
65
|
+
assert SPEC_VERSION_SUPPORTED == "1.2"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_generated_fixtures_stamp_versions_correctly():
|
|
69
|
+
# #267 (Phase 3 S7): the committed generated fixtures now include a guard-bearing
|
|
70
|
+
# transaction (`addMembersAboveRoleGuarded`, the guarded-tx conformance case), so
|
|
71
|
+
# the conditional stamper stamps operations.json at 1.2 (SCP node present). The
|
|
72
|
+
# manifest carries no SCP vocabulary, so it stays 1.1. Both are <= this runtime's
|
|
73
|
+
# SUPPORTED (1.2), so they load fine.
|
|
74
|
+
assert _load(conftest.MANIFEST_PATH)["version"] == "1.1"
|
|
75
|
+
assert _load(conftest.OPERATIONS_PATH)["version"] == "1.2"
|
|
66
76
|
|
|
67
77
|
|
|
68
78
|
def test_current_version_documents_are_accepted():
|
|
@@ -75,7 +85,13 @@ def test_older_minor_is_accepted_backward_compatible(tmp_path):
|
|
|
75
85
|
assert _runtime(m, o) is not None
|
|
76
86
|
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
def test_supported_minor_1_2_is_accepted(tmp_path):
|
|
89
|
+
# A 1.2 (guard vocabulary) bundle now loads — S6 evaluates it.
|
|
90
|
+
m, o = _paths_with_versions(tmp_path, "1.2", "1.2")
|
|
91
|
+
assert _runtime(m, o) is not None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.mark.parametrize("version", ["1.3", "1.99", "2.0", "0.9"])
|
|
79
95
|
def test_newer_minor_or_wrong_major_is_a_loud_reject(tmp_path, version):
|
|
80
96
|
m, o = _paths_with_versions(tmp_path, version, SPEC_VERSION_SUPPORTED)
|
|
81
97
|
with pytest.raises(GraphDDBError, match="not supported"):
|
|
@@ -83,7 +99,7 @@ def test_newer_minor_or_wrong_major_is_a_loud_reject(tmp_path, version):
|
|
|
83
99
|
|
|
84
100
|
|
|
85
101
|
def test_operations_version_is_validated_independently(tmp_path):
|
|
86
|
-
m, o = _paths_with_versions(tmp_path, SPEC_VERSION_SUPPORTED, "1.
|
|
102
|
+
m, o = _paths_with_versions(tmp_path, SPEC_VERSION_SUPPORTED, "1.3")
|
|
87
103
|
with pytest.raises(GraphDDBError, match="operations.json.*not supported"):
|
|
88
104
|
_runtime(m, o)
|
|
89
105
|
|
|
@@ -93,3 +109,45 @@ def test_missing_or_malformed_version_is_a_loud_reject(tmp_path, version):
|
|
|
93
109
|
m, o = _paths_with_versions(tmp_path, version, SPEC_VERSION_SUPPORTED)
|
|
94
110
|
with pytest.raises(GraphDDBError, match="missing or malformed"):
|
|
95
111
|
_runtime(m, o)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# ── issue #266 (Phase 3 S6): SCP Expression IR guard vocabulary is EVALUATED ──
|
|
115
|
+
#
|
|
116
|
+
# A ``1.2`` bundle is one that actually CONTAINS an SCP Expression IR node — a
|
|
117
|
+
# ``guard`` on a transaction item, or a ``{"kind": "scpExpr"}`` write condition
|
|
118
|
+
# (conditional stamping). S1 loud-rejected such a bundle at LOAD (SUPPORTED was
|
|
119
|
+
# 1.1); S6 raised SUPPORTED to 1.2 and wired ``guard`` evaluation, so a
|
|
120
|
+
# guard-bearing 1.2 bundle now LOADS and is executed. The ``scpExpr``
|
|
121
|
+
# write-condition class is still out of scope — it loads (1.2 accepted) but
|
|
122
|
+
# loud-rejects at EXECUTION (never silently ignored, the #242 policy).
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _scp_expression():
|
|
126
|
+
return {
|
|
127
|
+
"exprVersion": 1,
|
|
128
|
+
"expr": {"eq": [{"ref": ["input", "status"]}, "closed"]},
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_guard_bearing_1_2_bundle_is_accepted(tmp_path):
|
|
133
|
+
# S6: SUPPORTED is 1.2 and the transaction-item guard is evaluated, so a
|
|
134
|
+
# guard-bearing bundle LOADS (no longer the S1 loud reject).
|
|
135
|
+
manifest = _load(conftest.MANIFEST_PATH)
|
|
136
|
+
operations = _load(conftest.OPERATIONS_PATH)
|
|
137
|
+
operations["version"] = "1.2"
|
|
138
|
+
transactions = operations.setdefault("transactions", {})
|
|
139
|
+
transactions["closeGroup"] = {
|
|
140
|
+
"params": {"groupId": {"type": "string", "required": True}},
|
|
141
|
+
"items": [
|
|
142
|
+
{
|
|
143
|
+
"type": "Delete",
|
|
144
|
+
"tableName": "UserPermissions",
|
|
145
|
+
"entity": "GroupModel",
|
|
146
|
+
"keyCondition": {"PK": "GROUP#{groupId}", "SK": "META"},
|
|
147
|
+
"guard": _scp_expression(),
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
}
|
|
151
|
+
m = _write(tmp_path, "manifest.json", manifest)
|
|
152
|
+
o = _write(tmp_path, "operations.json", operations)
|
|
153
|
+
assert _runtime(m, o) is not None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/graphddb_runtime.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graphddb_runtime-0.7.9 → graphddb_runtime-0.7.10}/tests/test_integration_binding_contract.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|