Skip to content

feat(feature-flags): add Python-format rule engine store - #5920

Merged
dreamorosi merged 9 commits into
mainfrom
feat/feature-flags-rule-engine
Nov 10, 2026
Merged

dreamorosi merged 9 commits into
mainfrom
feat/feature-flags-rule-engine

Conversation

@dreamorosi

Copy link
Copy Markdown
Contributor

Summary

Add ruleEngineStore, which evaluates Flag Documents in the Powertools for Python format locally, from any async JSON source. This lets TypeScript and Python functions share one freeform AppConfig document. Part of RFC discussion #5614.

Changes

  • Add the ruleEngineStore({ source, logger? }) factory, which returns a plain Store object, with validation, evaluation, and the action table as separate internal modules.
  • Validate the whole document on every retrieval: Python's shape, boolean_type (omitted means true), and rule and condition structure. Validation errors name the flag, rule, condition index, key, and action, never values.
  • Evaluate rules in document order, first match wins, with conditions combined with AND. A condition whose key is missing from the context never matches, including negative actions, which matches Python 3.36.0.
  • Support all 17 actions that are not time-based, using strict JSON comparison via the commons isStrictEqual helper and setting enabled via isTruthy.
  • Reject the time actions and MODULO_RANGE as "not supported yet" until Feature request: time Actions and MODULO_RANGE in ruleEngineStore #5903 adds them, so shared documents that use them fail loudly.
  • Add SchemaValidationError and ConditionEvaluationError.
  • Add conformance tests against Python 3.36.0, with the four intentional differences isolated in their own block: strict boolean/number equality, incompatible operands throw instead of not matching, numeric rule names such as "10" are rejected, and rules that is not an object is rejected.
  • Add type tests, 100% coverage, and an inline-document snippet.

Issue number: closes #5902


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Evaluate shared Python Flag Documents from an asynchronous JSON source.
Validate every retrieval and support all non-time Actions with strict
comparisons, first-match Rule priority, and value-free diagnostics.

Add Python 3.36.0 conformance cases, explicit compatibility differences,
and a typed inline-document example. Reject time and modulo Actions
until their separate implementation lands.

Fixes #5902
…rors

Include each Condition's zero-based index in validation diagnostics so
callers can locate malformed entries without exposing operand values.
Keep evaluation diagnostics unchanged and cover a malformed second
Condition in a three-Condition Rule.

Refs #5902
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/XXL PRs with 1K+ LOC, largely documentation related label Nov 5, 2026
@dreamorosi
dreamorosi requested a review from svozza November 5, 2026 15:19
Move the JMESPath comparator into commons without changing its body so
other packages can use Python-compatible Unicode ordering. Export
compareStringsByCodePoint from the root and cover string ordering,
prefixes, astral characters, and non-normalized strings.

Refs #5902
…e objects

Compare string operands with the shared Unicode comparator while
preserving native number ordering and incompatible-operand errors.
Cover all four ordering Actions with BMP-versus-astral operands and
record code-point ordering as Python parity.

Constrain test contexts to ContextValue and exercise object operands
only on the document side, as the public API requires.

Refs #5902
@dreamorosi
dreamorosi requested a review from svozza November 6, 2026 17:09
…string containers

Replace the array-only membership predicate that rejected otherwise
valid shared Python documents. Check own object keys and Unicode
code-point substrings while preserving strict array equality and
incompatible-operand errors, including through negation.

Keep array quantifiers separate and cover membership types, surrogate
boundaries, the reviewer regression, and Python parity. Retain the four
documented compatibility differences without adding restrictions.

Refs #5902
Replace UTF-16 prefix and suffix comparisons with code-point arrays so
lone surrogates cannot match half of an astral character. Preserve the
existing string operand guard and empty prefix and suffix behavior.

Cover surrogate boundaries, astral matches, standalone surrogates,
longer operands, empty strings, and Python parity for both Actions.

Refs #5902
@dreamorosi
dreamorosi merged commit c2c409a into main Nov 10, 2026
44 checks passed
@dreamorosi
dreamorosi deleted the feat/feature-flags-rule-engine branch November 10, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL PRs with 1K+ LOC, largely documentation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: ruleEngineStore evaluating Python-format Flag Documents

2 participants