Skip to content

Small fix for optional parameters on borrow recipes#26

Open
0xYoki wants to merge 2 commits intomainfrom
small-fix
Open

Small fix for optional parameters on borrow recipes#26
0xYoki wants to merge 2 commits intomainfrom
small-fix

Conversation

@0xYoki
Copy link
Copy Markdown
Contributor

@0xYoki 0xYoki commented Mar 25, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Corrected form field initialization behavior for required properties
    • Refined available trading actions to exclude unsupported options, preventing invalid selections

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

The PR refines prompt and action validation logic across two recipe files. In borrow.ts, promptFromSchema now conditionally sets the initial field only for required properties with non-empty placeholders or defaults. In perps.ts, executeTrade adds validation requiring that action types exist in ACTION_LABELS before inclusion in available actions.

Changes

Cohort / File(s) Summary
Recipe logic refinements
recipes/borrow.ts, recipes/perps.ts
borrow.ts: Conditional initial field assignment for required properties only when placeholders/defaults exist. perps.ts: Added ACTION_LABELS existence validation for action types in available actions filtering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Philippoes
  • jdomingos

Poem

🐰 A rabbit hops through prompts and trades,
Filtering wisely in the glades,
Required fields now shine so bright,
And actions validated just right!
Tidy logic, crisp and clean,
The best recipes we've ever seen! 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is completely missing. The required template sections (Added, Changed) are not present. Add a description following the template, documenting the changes made to recipes/borrow.ts and recipes/perps.ts under the appropriate sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Small fix for optional parameters on borrow recipes' directly describes the main change in recipes/borrow.ts, which updates how optional parameters are handled in the prompt configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch small-fix

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 `@recipes/borrow.ts`:
- Around line 454-456: The current truthy check (prop.placeholder ||
prop.default) skips valid values like 0; change it to explicitly test for
null/undefined/empty-string and use the nullish coalescing result when present.
Replace the expression with something like: compute const value =
prop.placeholder ?? prop.default; then if isRequired && value !== undefined &&
value !== null && value !== '' include { initial: String(value) } so numeric
defaults (0) are preserved; reference variables: prop, isRequired, initial,
placeholder, default.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1e9de9c1-f99c-412b-9736-942166f680d8

📥 Commits

Reviewing files that changed from the base of the PR and between 36b0249 and 8fa848a.

📒 Files selected for processing (2)
  • recipes/borrow.ts
  • recipes/perps.ts

Comment on lines +454 to +456
...(isRequired && (prop.placeholder || prop.default)
? { initial: (prop.placeholder || prop.default) as string }
: {}),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Required defaults like 0 are skipped by the truthy check.

At Line 454, (prop.placeholder || prop.default) filters out valid required defaults such as 0, so initial is not set for those fields. Use explicit null/empty checks instead of truthiness.

Suggested fix
+      const initialValue = prop.placeholder || prop.default;
       const response: any = await Enquirer.prompt({
         type: "input",
         name: "value",
         message,
-        ...(isRequired && (prop.placeholder || prop.default)
-          ? { initial: (prop.placeholder || prop.default) as string }
+        ...(isRequired && initialValue !== undefined && initialValue !== null && initialValue !== ""
+          ? { initial: String(initialValue) }
           : {}),
         validate: (input: string) => {
📝 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.

Suggested change
...(isRequired && (prop.placeholder || prop.default)
? { initial: (prop.placeholder || prop.default) as string }
: {}),
const initialValue = prop.placeholder || prop.default;
const response: any = await Enquirer.prompt({
type: "input",
name: "value",
message,
...(isRequired && initialValue !== undefined && initialValue !== null && initialValue !== ""
? { initial: String(initialValue) }
: {}),
validate: (input: string) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@recipes/borrow.ts` around lines 454 - 456, The current truthy check
(prop.placeholder || prop.default) skips valid values like 0; change it to
explicitly test for null/undefined/empty-string and use the nullish coalescing
result when present. Replace the expression with something like: compute const
value = prop.placeholder ?? prop.default; then if isRequired && value !==
undefined && value !== null && value !== '' include { initial: String(value) }
so numeric defaults (0) are preserved; reference variables: prop, isRequired,
initial, placeholder, default.

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.

1 participant