Skip to content

refactor(engine): generalize and simplify code schema definition#2126

Open
asrcpq wants to merge 4 commits into
mainfrom
refactor/engine/flowexpr-schema
Open

refactor(engine): generalize and simplify code schema definition#2126
asrcpq wants to merge 4 commits into
mainfrom
refactor/engine/flowexpr-schema

Conversation

@asrcpq
Copy link
Copy Markdown
Contributor

@asrcpq asrcpq commented Jun 2, 2026

Overview

Currently Code in schema is a fixed type, so all code fields must have identical allowed language list.

This PR adds const generics to define accepted code types optionally for some fields. For example, conditions in FeatureFilter should not take plain string literal types. This PR also updates schema to pass the accepted types to the frontend.

Example

Feature filter's condition. Before:

// per-action definitions:
"Code": {
  "type": "object",
  "required": ["type", "value"],
  "properties": {
    "type": { "$ref": "#/definitions/CodeType" },
    "value": { "type": "string" }
  }
},
"CodeType": {
  "type": "string",
  "enum": ["flowExpr", "string"]   // always ALL types — no per-field restriction
},

// field:
"expr": {
  "title": "Condition expression",
  "allOf": [{ "$ref": "#/definitions/Code" }]
}

Code definition repeated every action, also impossible to express acceptable codeTypes.

This PR:

"expr": {
  "title": "Condition expression",
  "type": "code",
  "codeTypes": ["flowExpr"]
}

@github-actions github-actions Bot added the engine label Jun 2, 2026
@asrcpq asrcpq force-pushed the refactor/engine/flowexpr-schema branch from db8408f to 25283ec Compare June 2, 2026 02:29
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 7.86%. Comparing base (070257c) to head (25283ec).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2126   +/-   ##
=====================================
  Coverage   7.86%   7.86%           
=====================================
  Files        224     224           
  Lines      37600   37600           
=====================================
  Hits        2956    2956           
  Misses     34391   34391           
  Partials     253     253           
Flag Coverage Δ
api 7.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asrcpq asrcpq force-pushed the refactor/engine/flowexpr-schema branch from 25283ec to 0fbb1fd Compare June 2, 2026 04:31
@asrcpq asrcpq changed the title refactor(engine): simplify code schema definition refactor(engine): generalize and simplify code schema definition Jun 2, 2026
@asrcpq asrcpq marked this pull request as ready for review June 2, 2026 07:30
@asrcpq asrcpq requested review from n4to4 and shunski as code owners June 2, 2026 07:30
Copilot AI review requested due to automatic review settings June 2, 2026 07:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Code schema definition in the engine: replaces the per-action JSON Schema Code/CodeType definitions with an inline custom schema fragment ({"type": "code", "codeTypes": [...]}), and introduces a const-generic Code<MASK> Rust type so that fields can restrict accepted code types at compile-time (e.g. FeatureFilter's condition expression now only accepts flowExpr). Custom Serialize/Deserialize/JsonSchema impls back the new representation. Generated schemas (per-locale + mdbook docs) and i18n files are updated accordingly, and the workspace version is bumped to 0.0.377.

Changes:

  • New const-generic Code<MASK> with custom serde + non-referenceable JsonSchema emitting type: "code" and a filtered codeTypes list, plus deserialize-time validation against the mask.
  • FeatureFilter.Condition.expr now uses Code<{ CodeType::FlowExpr as u32 }> to restrict to flowExpr only.
  • Regenerated schema JSONs, mdbook docs, and i18n files to remove inline Code/CodeType definitions and inline the new representation.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
engine/runtime/types/src/expr.rs Adds const-generic Code<MASK>, manual serde + custom JsonSchema, removes Expr::compile.
engine/runtime/action-processor/src/feature/filter.rs Uses Code<{ CodeType::FlowExpr as u32 }> for condition expressions.
engine/schema/actions.json (and _en/_es/_fr/_ja/_zh) Regenerated schemas with inline type: "code"/codeTypes and removed Code/CodeType definitions.
engine/schema/i18n/actions/*.json Removed obsolete Code entries from definitionI18n.
engine/docs/mdbook/src/action.md Regenerated mdbook docs to match new schemas.
engine/Cargo.toml, engine/Cargo.lock Workspace version bump to 0.0.377.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@asrcpq asrcpq force-pushed the refactor/engine/flowexpr-schema branch from 1e7da19 to 49ac84c Compare June 3, 2026 01:09
Copy link
Copy Markdown
Contributor

@n4to4 n4to4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants