Skip to content

fix: reinfer transformed value types - #31

Open
nrps9909 wants to merge 2 commits into
react-component:masterfrom
nrps9909:codex/reinfer-transform-type
Open

fix: reinfer transformed value types#31
nrps9909 wants to merge 2 commits into
react-component:masterfrom
nrps9909:codex/reinfer-transform-type

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 28, 2026

Copy link
Copy Markdown

Summary

  • clone object rules before applying transforms and inferred types
  • avoid persisting an inferred type into the reusable schema definition
  • cover sequential validations whose transformed values have different types

Problem

When a transform rule omits an explicit type, validate infers the type from the transformed value. That inference currently happens before the rule object is cloned, so the inferred type is written back into the Schema rules. Reusing the same Schema with a different transformed value type then validates against the stale type from the first call.

For example, a schema with an identity transform accepts a number first, but incorrectly rejects a string on the next validation because number was persisted as the rule type.

Validation

  • baseline regression reproduced: the second validation rejected with Async Validation Error
  • 16 suites, 117 tests, and 8 snapshots pass
  • npm run tsc
  • npm run lint (0 errors; 3 existing unused-disable warnings)
  • npm run compile
  • Prettier and git diff checks pass

Duplicate audit

I checked all current open issues and PRs plus repository searches for transform/schema/type reuse. The only open PR is the TypeScript dependency update (#28), and issue #18 concerns Promise typing; neither overlaps this change.

AI assistance disclosure: Codex was used to trace the mutation, write the regression test, run validation, and audit open work. The failure and fix were verified locally against current master.

Summary by CodeRabbit

  • Bug 修复

    • 改进验证规则的处理流程,确保不同类型的规则在验证时保持一致行为。
  • 测试

    • 增加多次验证场景测试,确保转换后的数字和字符串类型能够正确保留并返回。

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 50 minutes.

View limit details

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

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e62ac8d6-e705-41d1-97af-7e7404f7d83b

📥 Commits

Reviewing files that changed from the base of the PR and between 0157117 and 743b315.

📒 Files selected for processing (1)
  • src/index.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: db6ea2a7-5562-489f-bf91-b6c93addd8a6

📥 Commits

Reviewing files that changed from the base of the PR and between 8cca839 and 0157117.

📒 Files selected for processing (2)
  • src/index.ts
  • tests/number.spec.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

validate 中的非函数规则归一化逻辑已调整。新增测试验证带 transform 的 schema 在多次验证中保留正确的转换类型。

Changes

规则归一化与验证

Layer / File(s) Summary
规则归一化与重复验证
src/index.ts, tests/number.spec.ts
validate 在 transform 处理前独立浅拷贝非函数规则。新增异步测试,验证同一 schema 对数字和字符串输入进行多次验证时,解析结果与输入一致。

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 01571

This localized change prevents reused schemas from retaining a stale inferred type after transformation without changing public entry points or adding dependencies. The supplied checks pass, and no actionable merge-blocking risk remains after normal review.

Suggested reviewers: afc163

Poem

小兔展开规则页,
transform 前排整齐。
数字跳过验证门,
字符串也不迷离。
同一 schema 再相逢,
类型安稳如春泥。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更的主要目的:修复可复用 schema 中转换值的类型重新推断问题。标题简洁且与代码和回归测试一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.44%. Comparing base (8cca839) to head (743b315).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #31      +/-   ##
==========================================
+ Coverage   82.38%   82.44%   +0.05%     
==========================================
  Files          25       25              
  Lines         653      655       +2     
  Branches      236      240       +4     
==========================================
+ Hits          538      540       +2     
  Misses        114      114              
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

Comment thread src/index.ts Outdated
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