Skip to content

Commit 20a936f

Browse files
authored
Merge pull request #43 from SpyrosPsarras/fix/model-tokens-int32-overflow
fix: stop per-model token totals wrapping negative
2 parents 4c29b39 + 7dc563c commit 20a936f

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎ClaudeCodeUsageWidget.qml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,10 @@ PluginComponent {
15111511

15121512
// When model is a ListModel, role names are direct properties.
15131513
// When model is a JS array, values are accessed via modelData.
1514+
// `real`, not `int`: a weekly per-model total passes the signed
1515+
// 32-bit range (2.1B tokens), and `int` wraps it negative.
15141516
property string _modelName: modelListData === modelRepeater.model ? modelName : (modelData ? modelData.modelName : "")
1515-
property int _modelTokens: modelListData === modelRepeater.model ? modelTokens : (modelData ? (modelData.modelTokens || 0) : 0)
1517+
property real _modelTokens: modelListData === modelRepeater.model ? modelTokens : (modelData ? (modelData.modelTokens || 0) : 0)
15161518

15171519
Row {
15181520
width: parent.width

‎tests/test-qml-syntax.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ for f in $QML_FILES; do
4747
fi
4848
done
4949

50+
echo "=== Test 4: Token counts are not declared as 32-bit int ==="
51+
for f in $QML_FILES; do
52+
name=$(basename "$f")
53+
# QML `int` is signed 32-bit, so it wraps negative past 2147483647. A weekly
54+
# per-model token total passes that, so token properties must be `real`.
55+
if grep -qE '^[[:space:]]*property[[:space:]]+int[[:space:]]+[A-Za-z_]*[Tt]okens' "$f"; then
56+
grep -nE '^[[:space:]]*property[[:space:]]+int[[:space:]]+[A-Za-z_]*[Tt]okens' "$f" >&2
57+
fail "$name declares a token count as int (wraps negative past 2.1B)"
58+
else
59+
pass "$name declares token counts as real"
60+
fi
61+
done
62+
5063
echo ""
5164
echo "Results: $PASS passed, $FAIL failed"
5265
[ "$FAIL" -eq 0 ] || exit 1

0 commit comments

Comments
 (0)