feat(schema): support DEFAULT_PROPS export for default values#1118
feat(schema): support DEFAULT_PROPS export for default values#1118aka-sacci-ccr wants to merge 1 commit intomainfrom
Conversation
…values Allow sections to export a `DEFAULT_PROPS` constant that takes priority over function parameter defaults when generating the input schema. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tagging OptionsShould a new tag be published when this PR is merged?
|
📝 WalkthroughWalkthroughA new helper function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
2 issues found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="engine/schema/transform.ts">
<violation number="1" location="engine/schema/transform.ts:1537">
P2: `DEFAULT_PROPS` values that contain booleans are serialized as `null` because this path reuses a parser that does not handle `BooleanLiteral`.</violation>
<violation number="2" location="engine/schema/transform.ts:1614">
P2: Look up `DEFAULT_PROPS` in the resolved function module, not the entry module, so re-exported blocks keep their defaults.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| if (inputSchema.type === "object") { | ||
| inputSchema.default = defaultValue; | ||
| // Priority: DEFAULT_PROPS export > function parameter default > nothing | ||
| const exportedDefaultProps = findExportedDefaultProps(mProgram); |
There was a problem hiding this comment.
P2: Look up DEFAULT_PROPS in the resolved function module, not the entry module, so re-exported blocks keep their defaults.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At engine/schema/transform.ts, line 1614:
<comment>Look up `DEFAULT_PROPS` in the resolved function module, not the entry module, so re-exported blocks keep their defaults.</comment>
<file context>
@@ -1584,7 +1610,9 @@ export const programToBlockRef = async (
if (inputSchema.type === "object") {
- inputSchema.default = defaultValue;
+ // Priority: DEFAULT_PROPS export > function parameter default > nothing
+ const exportedDefaultProps = findExportedDefaultProps(mProgram);
+ inputSchema.default = exportedDefaultProps ?? defaultValue;
}
</file context>
| const exportedDefaultProps = findExportedDefaultProps(mProgram); | |
| const exportedDefaultProps = findExportedDefaultProps(parsedSource); |
| decl.id.value === "DEFAULT_PROPS" && | ||
| decl.init | ||
| ) { | ||
| return generateObject(decl.init); |
There was a problem hiding this comment.
P2: DEFAULT_PROPS values that contain booleans are serialized as null because this path reuses a parser that does not handle BooleanLiteral.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At engine/schema/transform.ts, line 1537:
<comment>`DEFAULT_PROPS` values that contain booleans are serialized as `null` because this path reuses a parser that does not handle `BooleanLiteral`.</comment>
<file context>
@@ -1516,6 +1516,32 @@ const getReturnFnFunction = async (
+ decl.id.value === "DEFAULT_PROPS" &&
+ decl.init
+ ) {
+ return generateObject(decl.init);
+ }
+ }
</file context>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@engine/schema/transform.ts`:
- Around line 1532-1538: The code currently treats any initializer for the
identifier DEFAULT_PROPS as an object by calling generateObject(decl.init);
update the conditional in the DEFAULT_PROPS branch to first verify the
initializer is an object literal (e.g., decl.init.type === "ObjectExpression" or
the project's AST equivalent) before calling generateObject, and skip/apply
no-default if it's not an object so inputSchema.default is not set to non-object
values; refer to the DEFAULT_PROPS identifier check and the
generateObject(decl.init) call when making this change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: db5cb395-7cf1-4fbe-86ed-f1b34452f2f2
📒 Files selected for processing (1)
engine/schema/transform.ts
| if ( | ||
| decl.id.type === "Identifier" && | ||
| decl.id.value === "DEFAULT_PROPS" && | ||
| decl.init | ||
| ) { | ||
| return generateObject(decl.init); | ||
| } |
There was a problem hiding this comment.
Validate DEFAULT_PROPS is an object literal before applying it.
Right now any initializer is accepted, so DEFAULT_PROPS can become a non-object default for an object schema. That can produce invalid inputSchema.default values.
Proposed fix
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
- return generateObject(decl.init);
+ if (decl.init.type !== "ObjectExpression") {
+ continue;
+ }
+ const parsed = generateObject(decl.init);
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
+ return parsed;
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if ( | |
| decl.id.type === "Identifier" && | |
| decl.id.value === "DEFAULT_PROPS" && | |
| decl.init | |
| ) { | |
| return generateObject(decl.init); | |
| } | |
| if ( | |
| decl.id.type === "Identifier" && | |
| decl.id.value === "DEFAULT_PROPS" && | |
| decl.init | |
| ) { | |
| if (decl.init.type !== "ObjectExpression") { | |
| continue; | |
| } | |
| const parsed = generateObject(decl.init); | |
| if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) { | |
| return parsed; | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@engine/schema/transform.ts` around lines 1532 - 1538, The code currently
treats any initializer for the identifier DEFAULT_PROPS as an object by calling
generateObject(decl.init); update the conditional in the DEFAULT_PROPS branch to
first verify the initializer is an object literal (e.g., decl.init.type ===
"ObjectExpression" or the project's AST equivalent) before calling
generateObject, and skip/apply no-default if it's not an object so
inputSchema.default is not set to non-object values; refer to the DEFAULT_PROPS
identifier check and the generateObject(decl.init) call when making this change.
Summary
findExportedDefaultPropsto extractexport const DEFAULT_PROPS = { ... }from section/block ASTDEFAULT_PROPStakes priority over function parameter defaults when populatinginputSchema.defaultdefinition.defaultExample usage
Priority:
DEFAULT_PROPSexport > function parameter default > nothingTest plan
export const DEFAULT_PROPSget those values ininputSchema.defaultDEFAULT_PROPSstill use param defaults (no regression)DEFAULT_PROPSvalues🤖 Generated with Claude Code
Summary by cubic
Adds support for
DEFAULT_PROPSexports in sections/blocks to define default values. These now take priority over function parameter defaults when settinginputSchema.default.findExportedDefaultPropsto readexport const DEFAULT_PROPS = { ... }from the AST.DEFAULT_PROPS> function parameter default > none.definition.default.Written for commit 54b7e23. Summary will update on new commits.
Summary by CodeRabbit