Skip to content

fix: compare single-branch oneOf schemas correctly - #111

Merged
l1shen merged 1 commit into
oomol-lab:mainfrom
yanjizhong:fix/single-branch-oneof-comparison
Sep 7, 2026
Merged

fix: compare single-branch oneOf schemas correctly#111
l1shen merged 1 commit into
oomol-lab:mainfrom
yanjizhong:fix/single-branch-oneof-comparison

Conversation

@yanjizhong

Copy link
Copy Markdown
Contributor

Summary

oneOf with a single effective branch (for example oneOf: [{ type: 'string' }], or a two-branch list where one branch compiles to never) compared as compatible against unrelated schemas.

Changes

  • expression/calculator.ts: calculateOneOf returns the single expression directly when only one branch remains, because oneOf([X]) is equivalent to X.
  • expression/calculator.ts: calculateCombination now throws on an empty expression list. The previous length < 0 guard could never trigger.
  • test/designer/schema-compare.test.ts: regression cases for single-branch oneOf in both compatible and incompatible directions.

Motivation

With one expression, the ban-zone computation evaluated AnyOf([]), which returned ExpressionNone, and the defensive ExpressionContainedBy fallback in calculateNode then turned the empty result into a contained verdict. For example, compareJSONSchema({ oneOf: [{ type: 'string' }] }, { type: 'number' }) reported compatible, so a string output could be connected to a number input in the designer.

The compiler rejects empty oneOf lists and folds all-never lists into the never kind, so a combination reaching calculateOneOf always keeps at least one branch after never rejection; the empty-list guard is therefore unreachable hardening.

Testing

  • bun run check and bun run test in packages/open-flow.
  • New table cases: single-branch oneOf to a matching type (compatible) and to a mismatched type (incompatible).

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

On-demand reviews are free for the next 13 days. After that, they cost $0.25 per reviewed file.

Or wait 59 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 21899dbc-8391-43cd-b140-4996edc729ac

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1e960 and b0dc59c.

📒 Files selected for processing (2)
  • packages/open-flow/src/json-schema-subset/expression/calculator.ts
  • packages/open-flow/test/designer/schema-compare.test.ts

Comment @coderabbitai help to get the list of available commands.

@l1shen
l1shen merged commit e7c4e0c into oomol-lab:main Sep 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants