Skip to content

Conversation

@ascandone
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Walkthrough

Several new NumScript test data files were added under internal/interpreter/testdata/numscript-cookbook/ and its experimental subdirectory. These scripts demonstrate various fund transfer scenarios, including fee capping, mixed source/destination allotments, overdraft top-ups, metadata calculations, and source preference logic. No changes to exported code entities were made; all updates are new test data scripts.

Changes

File(s) Change Summary
.../numscript-cookbook/max-fee.num Added script for capped fee transfer logic with variable declarations and conditional routing.
.../numscript-cookbook/mixed-source-dest-allotment.num Added script demonstrating mixed source and destination allotments in a send operation.
.../numscript-cookbook/send-max.num Added script for sending up to a maximum capped amount from one account to another.
.../numscript-cookbook/top-up-max.num Added script to top up an account without exceeding a specified balance limit.
.../numscript-cookbook/experimental/meta-calc.num Added script demonstrating arithmetic and metadata assignment in a transaction.
.../numscript-cookbook/experimental/mixed-source-prefer-single-source.num Added script testing nested and alternative source selection in a send operation.
.../numscript-cookbook/experimental/top-up-many.num Added script for prioritizing overdraft top-ups for multiple entities using a oneof destination construct.
.../numscript-cookbook/experimental/top-up.num Added script for topping up a single overdraft account from a global source.
.../numscript-cookbook/experimental/transfer-example.num Added script for sending funds from a bank overdraft wallet to a destination account.

Sequence Diagram(s)

sequenceDiagram
    participant Script
    participant Source
    participant FeeAccount
    participant DestAccount

    Script->>Source: Prepare $amt USD
    Script->>FeeAccount: Send min($amt * $fee, $cap) USD
    Script->>DestAccount: Send remaining USD
Loading
sequenceDiagram
    participant Script
    participant Src1
    participant Src2
    participant World
    participant Dest1
    participant Dest2

    Script->>Src1: Send 10% of 77 USD
    Script->>Src2: Send 20% of 77 USD
    Script->>World: Send remaining 70% of 77 USD
    Script->>Dest1: Send 50% of total
    Script->>Dest2: Send 50% of total
Loading
sequenceDiagram
    participant Script
    participant Alice
    participant Jon

    Script->>Alice: Calculate max($limit - $jon_balance)
    Script->>Jon: Send min($amt, max) EUR
Loading
sequenceDiagram
    participant Script
    participant World
    participant Alice

    Script->>World: Prepare $alice_overdraft EUR
    Script->>Alice: Send $alice_overdraft EUR
Loading
sequenceDiagram
    participant Script
    participant World
    participant Alice
    participant Bob

    Script->>World: Prepare $amt EUR
    alt Alice overdraft not full
        Script->>Alice: Top up overdraft
    else Bob overdraft not full
        Script->>Bob: Top up overdraft
    else
        Script->>World: Keep remaining
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hopping through scripts, so fresh and new,
Fees capped tight, and sources two.
Overdrafts topped with careful care,
Destinations split with flair to spare.
Metadata set, and funds align—
NumScript's magic, simply divine! ✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91c4867 and 93905da.

📒 Files selected for processing (1)
  • internal/interpreter/testdata/numscript-cookbook/experimental/meta-calc.num (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/interpreter/testdata/numscript-cookbook/experimental/meta-calc.num
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: Tests
  • GitHub Check: Dirty
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/numscript-cookbook

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.32%. Comparing base (dab7a80) to head (93905da).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   70.62%   71.32%   +0.70%     
==========================================
  Files          41       41              
  Lines        4677     4631      -46     
==========================================
  Hits         3303     3303              
+ Misses       1222     1176      -46     
  Partials      152      152              

☔ View full report in Codecov by Sentry.
📢 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.

@ascandone ascandone enabled auto-merge (squash) July 24, 2025 13:00
number $x = 10 + 1
}

set_tx_meta("key", $x/2)

Choose a reason for hiding this comment

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

I'm not really aware of how this is used, but it seems weird to me to not have any postings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only to show that values can have arbitrary math expressions

Copy link
Contributor

@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: 0

🧹 Nitpick comments (6)
internal/interpreter/testdata/numscript-cookbook/mixed-source-prefer-single-source.num (1)

6-13: Clarify oneof preference or add an inline comment

The third option in the oneof block is itself a group containing both @s1 and @s2. Depending on the interpreter’s resolution rules, the meaning of “prefer single source” versus “fallback to both” might not be obvious to future readers (or even to the test maintainer six months from now). A short inline comment explaining the expected selection order would eliminate any ambiguity.

internal/interpreter/testdata/numscript-cookbook/mixed-source-dest-allotment.num (1)

3-5: Double-check mixed units in allotment block

Percentage clauses (10%, 20%) are followed by a remaining catch-all, while the destination block below switches to fractional notation (1/2). Although the DSL allows this mix, consider using the same notation in both blocks for consistency (e.g., 50% instead of 1/2) unless the divergence is intentional for coverage.

internal/interpreter/testdata/numscript-cookbook/top-up-max.num (1)

12-13: Minor style polish & uninitialised variable reminder

  1. There is a trailing blank after @jon that you might want to trim to keep the examples tidy.
  2. $amt is declared but never initialised inside this snippet; ensure the harness injects it, otherwise the example could be misleading.
-  destination = @jon 
+  destination = @jon
internal/interpreter/testdata/numscript-cookbook/max-fee.num (1)

7-15: Clarify dual “remaining to @DesT” to avoid reader confusion

The script is correct—the inner remaining handles the leftover of the fee portion while the outer remaining routes the leftover of the overall amount—but the identical wording can be mis-read as duplicating the transfer.
A short inline comment or slightly different wording (e.g., leftover vs remaining) would improve readability for cookbook consumers.

internal/interpreter/testdata/numscript-cookbook/top-up.num (1)

5-8: Consider explicit currency for consistency

Elsewhere in the cookbook you use the [CUR xxx] syntax. Writing

send [EUR $alice_overdraft] (

would keep the examples stylistically uniform and remove any doubt about the variable’s currency.

internal/interpreter/testdata/numscript-cookbook/top-up-many.num (1)

8-12: Tiny style nit – align indentation inside oneof

For visual parity with other cookbook files, indent the three options by two spaces:

-  destination = oneof {
-    max overdraft(@alice, EUR) to @alice
-    max overdraft(@bob, EUR) to @bob
-    remaining kept
-  }
+  destination = oneof {
+    max overdraft(@alice, EUR) to @alice
+    max overdraft(@bob, EUR) to @bob
+    remaining kept
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dab7a80 and bd4652b.

⛔ Files ignored due to path filters (9)
  • internal/interpreter/testdata/numscript-cookbook/max-fee.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/meta-calc.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/mixed-source-dest-allotment.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/mixed-source-prefer-single-source.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/send-max.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/top-up-many.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/top-up-max.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/top-up.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/transfer-example.num.specs.json is excluded by !**/*.json
📒 Files selected for processing (9)
  • internal/interpreter/testdata/numscript-cookbook/max-fee.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/meta-calc.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/mixed-source-dest-allotment.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/mixed-source-prefer-single-source.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/send-max.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/top-up-many.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/top-up-max.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/top-up.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/transfer-example.num (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: Dirty
  • GitHub Check: Tests
🔇 Additional comments (3)
internal/interpreter/testdata/numscript-cookbook/meta-calc.num (1)

5-5: Confirm meta value type is accepted

set_tx_meta("key", $x/2) passes a numeric expression. If downstream consumers expect a string, you may want to wrap it with str() (or the DSL equivalent) to avoid implicit type assumptions.

internal/interpreter/testdata/numscript-cookbook/send-max.num (1)

1-4: LGTM – concise coverage of the max source clause

The example cleanly exercises the max constraint with an unrestricted destination. No issues spotted.

internal/interpreter/testdata/numscript-cookbook/transfer-example.num (1)

8-9: Verify that @wallet contains the overdraft instrument

max $bank_overdraft from @wallet assumes @wallet is the ledger account holding the bank-overdraft asset. Double-check the surrounding test setup to ensure the balance really sits in @wallet; otherwise the interpreter will raise an “insufficient funds” error.

Copy link
Contributor

@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

🧹 Nitpick comments (2)
internal/interpreter/testdata/numscript-cookbook/experimental/top-up.num (1)

2-2: Consider edge case documentation.

While the implementation is correct, it would be valuable to document the behavior when overdraft(@alice, EUR) returns 0 (no overdraft). Does the script still execute a send of 0 amount, or should this be handled differently?

internal/interpreter/testdata/numscript-cookbook/experimental/top-up-many.num (1)

2-6: Consider consistency with monetary variable approach.

This script uses a number variable with currency specified in the send operation [EUR $amt], while the related top-up.num uses a monetary variable. Consider documenting why different approaches are used or standardizing the pattern for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd4652b and 91c4867.

⛔ Files ignored due to path filters (9)
  • internal/interpreter/testdata/numscript-cookbook/experimental/meta-calc.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/experimental/mixed-source-prefer-single-source.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/experimental/top-up-many.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/experimental/top-up.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/experimental/transfer-example.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/max-fee.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/mixed-source-dest-allotment.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/send-max.num.specs.json is excluded by !**/*.json
  • internal/interpreter/testdata/numscript-cookbook/top-up-max.num.specs.json is excluded by !**/*.json
📒 Files selected for processing (5)
  • internal/interpreter/testdata/numscript-cookbook/experimental/meta-calc.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/experimental/mixed-source-prefer-single-source.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/experimental/top-up-many.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/experimental/top-up.num (1 hunks)
  • internal/interpreter/testdata/numscript-cookbook/experimental/transfer-example.num (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • internal/interpreter/testdata/numscript-cookbook/experimental/meta-calc.num
  • internal/interpreter/testdata/numscript-cookbook/experimental/mixed-source-prefer-single-source.num
  • internal/interpreter/testdata/numscript-cookbook/experimental/transfer-example.num
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Tests
  • GitHub Check: Dirty
🔇 Additional comments (2)
internal/interpreter/testdata/numscript-cookbook/experimental/top-up.num (1)

1-8: LGTM! Clear and concise overdraft top-up example.

The script demonstrates a straightforward overdraft top-up scenario where Alice's overdraft amount is calculated and then transferred from the world entity. The syntax is clean and the logic is easy to follow.

internal/interpreter/testdata/numscript-cookbook/experimental/top-up-many.num (1)

6-13: Excellent demonstration of prioritized overdraft allocation.

The oneof construct effectively demonstrates how to handle multiple overdraft top-ups with priority ordering. The logic clearly shows Alice gets priority over Bob, and any remaining funds are kept rather than sent elsewhere.

Comment on lines +1 to +3
vars {
number $amt
}
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 25, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Uninitialized variable will cause runtime error.

The variable $amt is declared but never initialized. This will likely cause a runtime error when the script attempts to execute the send operation.

Add an initialization value to fix this issue:

 vars {
-  number $amt
+  number $amt = 100
 }

Or specify the amount directly in the send operation and remove the variable if it's meant to be a parameter.

📝 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
vars {
number $amt
}
vars {
number $amt = 100
}
🤖 Prompt for AI Agents
In internal/interpreter/testdata/numscript-cookbook/experimental/top-up-many.num
at lines 1 to 3, the variable $amt is declared but not initialized, which will
cause a runtime error. Fix this by either assigning an initial value to $amt in
the vars block or by removing the variable and specifying the amount directly in
the send operation if $amt is intended as a parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope

Copy link
Contributor

Choose a reason for hiding this comment

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

@ascandone Got it! I understand that the uninitialized variable is intentional for this example.

🐰
╭─────╮
│ ◕ ◕ │ curious about NumScript behavior
╰─────╯


✏️ Learnings added
Learnt from: ascandone
PR: formancehq/numscript#88
File: internal/interpreter/testdata/numscript-cookbook/experimental/top-up-many.num:1-3
Timestamp: 2025-07-25T08:12:46.359Z
Learning: In NumScript test data files under internal/interpreter/testdata/numscript-cookbook/, variables can be declared without initialization as they may be intended as parameters or templates where values are supplied externally at runtime.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@ascandone ascandone merged commit bc1d884 into main Jul 25, 2025
9 checks passed
@ascandone ascandone deleted the docs/numscript-cookbook branch July 25, 2025 08:19
ascandone added a commit that referenced this pull request Aug 26, 2025
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.

3 participants