Skip to content

Commit 22187e0

Browse files
committed
test(flagd): declare @large-integers and withdraw @numeric-coercion
Follow the conformance assets at spec@15fe8611, which the base now pins: @numeric-coercion requires lossless coercion in both directions, and the new @large-integers tag asks for 2^53 - 1. Neither resolver satisfies all three @numeric-coercion scenarios, so neither declares it: - RPC passes back whatever flagd answers, and flagd v0.16.0 -- the image flagd-testbed v3.8.0 builds on -- resolves an integer request as a float64 and casts it with a bare int64(val), so float-flag's 0.5 is narrowed to 0 with no error code. The earlier claim in this file that flagd answers INVALID_ARGUMENT was not borne out by the server source. open-feature/flagd#1996 implements the lossless rule. - In-process admits only int for an integer request (flagd_core.py:25), so integral-float-flag's 10.0 is a TYPE_MISMATCH where 10 is required. The other direction is widened (flagd_core.py:113-114), which is why the lossy scenario alone was passing before. Both declare @large-integers: RPC carries the value as an int64 that the provider hands over as a Python int, and in-process parses the ruleset with json.loads, so nothing narrows 9007199254740991. Record in the conftest that flagd-testbed v3.8.0 does not seed the six flags the assets added, so the untagged falsy and precision scenarios, and the @large-integers one, fail FLAG_NOT_FOUND until the testbed is updated. Left as failures rather than xfails: the backend is behind, not the provider. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent a09a6f2 commit 22187e0

3 files changed

Lines changed: 70 additions & 12 deletions

File tree

‎providers/openfeature-provider-flagd/tests/tck/conftest.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212
TCK drives the testbed's launchpad through the standardised control API, which
1313
the launchpad already implements, and reuses the container lifecycle already in
1414
``tests/e2e``.
15+
16+
**The testbed does not yet serve the whole canonical flag set.** The
17+
conformance assets at spec@15fe8611 added six flags -- ``false-flag``,
18+
``zero-flag``, ``empty-string-flag``, ``large-integer-flag``,
19+
``huge-integer-flag`` and ``integral-float-flag`` -- and flagd-testbed v3.8.0
20+
(``openfeature/test-harness/version.txt``) seeds none of them. Until
21+
open-feature/flagd-testbed catches up, both suites fail these scenarios with
22+
``FLAG_NOT_FOUND``, for every resolver alike:
23+
24+
* ``A falsy value is a value, not an absence`` -- three rows, untagged;
25+
* ``A large integer resolves without loss of precision`` -- untagged;
26+
* ``An integer beyond 32 bits resolves without loss of precision`` -- under
27+
``@large-integers``, which both suites declare.
28+
29+
``integral-float-flag`` is asked for only under ``@numeric-coercion``, which
30+
neither suite declares, so its scenario is skipped rather than failed. The
31+
failures are deliberately left as failures: they say something true about the
32+
stack under test, and an ``xfail`` would say the provider is at fault when it is
33+
the backend that is behind.
1534
"""
1635

1736
from __future__ import annotations

‎providers/openfeature-provider-flagd/tests/tck/test_in_process_conformance.py‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,29 @@
5050
# deadline passes without a synced ruleset, which the SDK's registry turns
5151
# into PROVIDER_ERROR.
5252
#
53-
# NUMERIC_COERCION
54-
# Local, and strict: flagd_core.py:25 admits only `int` for an integer
55-
# request, and flagd_core.py:228-231 raises TypeMismatchError for anything
56-
# else -- so `float-flag`'s 0.5 is reported as a mismatch rather than
57-
# narrowed to 0. (The float mapping at flagd_core.py:26 is deliberately the
58-
# wider one, `(int, float)`, but widening towards float loses nothing.)
53+
# LARGE_INTEGERS
54+
# The ruleset arrives as JSON text over the sync stream and FlagdCore parses
55+
# it with `json.loads` (flagd_core.py:73), which gives an unbounded Python
56+
# int for 9007199254740991; nothing between the parser and the SDK routes
57+
# the value through a float or a 32-bit field.
5958
#
6059
# Not declared, and why:
6160
#
61+
# NUMERIC_COERCION
62+
# Local, and strict in one direction only. flagd_core.py:25 admits only
63+
# `int` for an integer request and `_check_type` (flagd_core.py:228-231)
64+
# raises TypeMismatchError for anything else, so `float-flag`'s 0.5 is a
65+
# mismatch rather than 0 -- the lossy half holds. The float mapping at
66+
# flagd_core.py:26 is the wider `(int, float)`, and `resolve_float_value`
67+
# (flagd_core.py:113-114) widens an int result to a float, so `integer-flag`
68+
# requested as a Float is 10.0 -- that lossless half holds too. But the
69+
# same `(int,)` rule rejects `integral-float-flag`'s 10.0 requested as an
70+
# Integer, where the tag requires 10: two of three, and a declaration is
71+
# all or nothing. flagd's numeric-coercion ADR
72+
# (docs/architecture-decisions/numeric-coercion.md) commits every flagd
73+
# implementation to the lossless rule; when openfeature-flagd-core follows
74+
# it, this is declared again.
75+
#
6276
# TARGETING, CACHING
6377
# Reserved in the Capability enum; no scenario carries either tag. Declaring
6478
# a capability nothing exercises would be a claim with no evidence behind it,
@@ -70,7 +84,7 @@
7084
Capability.CONFIGURATION_CHANGE,
7185
Capability.OBJECT,
7286
Capability.UNAVAILABLE_INIT,
73-
Capability.NUMERIC_COERCION,
87+
Capability.LARGE_INTEGERS,
7488
}
7589
)
7690

‎providers/openfeature-provider-flagd/tests/tck/test_rpc_conformance.py‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,38 @@
5353
# passes without a connection, which the SDK's registry turns into
5454
# PROVIDER_ERROR.
5555
#
56-
# NUMERIC_COERCION
57-
# RPC does not type-check locally; it asks flagd for an Int and flagd answers
58-
# INVALID_ARGUMENT for a float-valued flag, which grpc.py:461-462 maps to
59-
# TypeMismatchError. So 0.5 is never narrowed to 0.
56+
# LARGE_INTEGERS
57+
# RPC never narrows an integer. flagd holds every numeric variant as a
58+
# float64 -- Go's encoding/json decodes an untyped number into one -- and
59+
# 2^53 - 1 is exactly the largest integer a float64 represents without
60+
# rounding, which is why the canonical set asks for nothing larger. The
61+
# server casts it to the int64 of ResolveIntResponse.value, and grpc.py:448
62+
# hands that to the SDK as a Python int, unbounded. Nothing in between is
63+
# 32 bits wide.
6064
#
6165
# Not declared, and why:
6266
#
67+
# NUMERIC_COERCION
68+
# RPC does not type-check locally: grpc.py:444-448 asks flagd for an Int and
69+
# passes back whatever the server answers, so the whole decision is flagd's.
70+
# flagd's evaluator resolves the variant as a float64 and casts it with a
71+
# bare `int64(val)` (core/pkg/evaluator/json.go, ResolveIntValue, at the
72+
# v0.16.0 the testbed's `flagd/Dockerfile` builds on), so `float-flag`'s 0.5
73+
# comes back as 0 with reason STATIC and no error code -- silently narrowed,
74+
# which is the one thing the lossy scenario forbids. The two lossless
75+
# scenarios pass for the same reason: 10.0 casts to 10, and a float
76+
# accessor sees the float64 the server already holds. One of three is a
77+
# failure, and a declaration is all or nothing.
78+
#
79+
# An earlier revision of this file claimed flagd answers INVALID_ARGUMENT
80+
# here. The server source says otherwise: INVALID_ARGUMENT is what
81+
# grpc.py:461-462 would map to TypeMismatchError if it ever arrived, and
82+
# for a float-valued flag it does not. The Java reference adoption recorded
83+
# the same narrowing against the same server. flagd's numeric-coercion ADR
84+
# (docs/architecture-decisions/numeric-coercion.md) commits it to lossless
85+
# coercion, tracked as open-feature/flagd#1996; this is declared again once
86+
# the testbed ships a flagd that implements it.
87+
#
6388
# TARGETING, CACHING
6489
# Reserved in the Capability enum; no scenario carries either tag. Declaring
6590
# a capability nothing exercises would be a claim with no evidence behind it,
@@ -71,7 +96,7 @@
7196
Capability.CONFIGURATION_CHANGE,
7297
Capability.OBJECT,
7398
Capability.UNAVAILABLE_INIT,
74-
Capability.NUMERIC_COERCION,
99+
Capability.LARGE_INTEGERS,
75100
}
76101
)
77102

0 commit comments

Comments
 (0)