[Bug]: Fractional numbers are silently truncated for int/long parameters in the testing agent

Open Beginner friendly
#84 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
backend

Research direction

The truncation happens in ConvertInputToAppFunctionDataUseCase, which calls Number.toInt() and toLong() in both the scalar and array branches. Start by reading those two branches and find where the Number value is converted. The change is to accept a Number only when it is a whole number within the target range, and otherwise throw an error that names the parameter. Done when 2.7 is rejected with a clear message, 3.0 is still accepted, and tests cover both the scalar and array cases.

Written by the indexing model from the issue text.

Description

Steps to Reproduce
  1. Have the model send 2.7 for an Int/Long parameter or an element of an IntArray/LongArray.
Expected

Conversion fails with an error naming the parameter, since the value isn't an integer. Whole-number
doubles such as 3.0 can still be accepted.

Observed

The value is silently truncated to 2, and the app function runs with a different value than
the model intended.

Root cause

ConvertInputToAppFunctionDataUseCase converts with Number.toInt() / toLong() for both scalar
and array branches.

Suggested fix

Accept a Number only if it is a whole number (e.g. toDouble() % 1.0 == 0.0, within range).
Otherwise fail with a clear message.

Found during review of the #62 fix.

Dominant language
Kotlin
Stars
222
Forks
54
Avg merge
1d 11h
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/appfunctions

All issues in android/appfunctions

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.