Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

fix: review round 3 of #124, read a whole number sent as 2.0 as that number

Guido Boyke6205301ccadb
diff --git a/CLAUDE.md b/CLAUDE.md
index 0ef5831..3f2c3a7 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -959,7 +959,7 @@ reader; whom it does not list counts in `count` alone. No meeting, place or corr
answer. Pages by 50, at most 100, a whole number outside is a 400 (MCP `invalid_input`, the same text
after the same checks: the bounds are the reader's, not the tool schema's). The types stay the schema's:
a value of another type, `null` included, the MCP SDK refuses before any tool runs, in its own words,
-as for every tool. Guards:
+as for every tool; a whole number written as `2.0` is one (JSON Schema's integer). Guards:
`spec/requests/api/v1/terms_spec.rb`, `spec/requests/api/mcp_glossary_spec.rb`,
`spec/requests/api/glossary_parity_spec.rb` (REST and MCP answer the same),
`spec/services/glossary/lookup_spec.rb`.
diff --git a/app/services/glossary/lookup.rb b/app/services/glossary/lookup.rb
index 67208e1..a4ed989 100644
--- a/app/services/glossary/lookup.rb
+++ b/app/services/glossary/lookup.rb
@@ -193,17 +193,19 @@ module Glossary
id
end
- # A whole number from 1 to max, as text or as an Integer; absent or empty is
- # nil (the default). A refused value is quoted back only when it is text or a
- # number, and only its start.
+ # A whole number from 1 to max, as text (REST: digits only) or as a JSON
+ # number (MCP: an Integer, or a Float with a whole value, which JSON Schema
+ # counts as an integer: 2.0); absent or empty is nil (the default). A refused
+ # value is quoted back only when it is text or a number, and only its start.
def whole_number(name, raw, max:)
return nil if raw.nil? || raw == ''
number = raw if raw.is_a?(Integer)
+ number = raw.to_i if raw.is_a?(Float) && raw.finite? && raw == raw.floor
number = Integer(raw, 10) if raw.is_a?(String) && raw.match?(/\A\d+\z/)
return number if number&.between?(1, max)
- shown = raw.is_a?(String) || raw.is_a?(Integer) ? " #{raw.to_s.truncate(QUOTED_LENGTH).inspect}" : ''
+ shown = raw.is_a?(String) || raw.is_a?(Numeric) ? " #{raw.to_s.truncate(QUOTED_LENGTH).inspect}" : ''
raise InvalidArgument, I18n.t('services.glossary.lookup.invalid_number', name: name, shown: shown, max: max)
end
end
diff --git a/app/services/lalabase/CLAUDE.md b/app/services/lalabase/CLAUDE.md
index 08fc0be..46f4214 100644
--- a/app/services/lalabase/CLAUDE.md
+++ b/app/services/lalabase/CLAUDE.md
@@ -52,7 +52,7 @@ Codebase-Verständnis.
`per_page` are the reader's, not the schema's (no `minimum`/`maximum`): the SDK would refuse a value
ahead of the right and in its own English, where REST answers after the right in the owner's language.
The types stay the schema's: a value of another type (`null` included) the SDK refuses before the
- tool, as it does for every tool.
+ tool, as it does for every tool; `2.0` passes as an integer, and the reader takes it as 2.
On `:mcp` the same two names are twins (`McpFindPeople`, `McpGetPerson`, People S3b, MCP
0.13.0), own classes because their schema requires `organisation_id` (E3). `scope_mode
:token`; `PeopleTool.with_token_lookup` is their gate: only an organisation whose every
diff --git a/app/services/lalabase/tools/get_glossary.rb b/app/services/lalabase/tools/get_glossary.rb
index dd74246..b741b9b 100644
--- a/app/services/lalabase/tools/get_glossary.rb
+++ b/app/services/lalabase/tools/get_glossary.rb
@@ -19,7 +19,8 @@ module Lalabase
# the SDK would refuse a value before the tool runs, ahead of the right and in its own English,
# where REST refuses after the right in the owner's language (review round 1 of #124). The types
# stay the schema's: a value of another type, null included, the SDK refuses before the tool runs,
- # as for every tool (review round 2).
+ # as for every tool (review round 2). A whole number written as 2.0 passes the schema as an
+ # integer, and the reader takes it as one (round 3).
#
# MCP only, no assistant twin: the assistant does not need the glossary today.
class GetGlossary < Base
diff --git a/spec/requests/api/mcp_glossary_spec.rb b/spec/requests/api/mcp_glossary_spec.rb
index e12c406..4e65dbe 100644
--- a/spec/requests/api/mcp_glossary_spec.rb
+++ b/spec/requests/api/mcp_glossary_spec.rb
@@ -166,6 +166,11 @@ RSpec.describe 'MCP get_glossary', :ci_guard, type: :request do
expect(answer).to eq('data' => [], 'people' => [], 'meta' => { 'page' => 2, 'per_page' => 1, 'total' => 1 })
end
+
+ # JSON Schema's integer takes 2.0, and so does the SDK; the tool reads it as 2 (review round 3 of #124).
+ it 'reads a whole number sent as 1.0 as that number' do
+ expect(data(glossary(page: 1.0, per_page: 50.0))['meta']).to eq('page' => 1, 'per_page' => 50, 'total' => 1)
+ end
end
describe 'refusals' do
diff --git a/spec/services/glossary/lookup_spec.rb b/spec/services/glossary/lookup_spec.rb
index af190a8..da6955a 100644
--- a/spec/services/glossary/lookup_spec.rb
+++ b/spec/services/glossary/lookup_spec.rb
@@ -376,6 +376,12 @@ RSpec.describe Glossary::Lookup, :ci_guard do
expect(second[:meta]).to eq(page: 2, per_page: 2, total: 4)
end
+ # Review round 3 of #124: JSON Schema counts 2.0 as an integer, so the MCP SDK lets it through as
+ # a Float; it is the whole number it names.
+ it 'takes a whole number written with a point (2.0) as that number' do
+ expect(lookup.read(page: 2.0, per_page: 3.0)[:meta]).to eq(page: 2, per_page: 3, total: 4)
+ end
+
it 'takes page and per_page as text (REST) or as whole numbers (MCP)' do
expect(lookup.read(page: '2', per_page: '3')[:data].pluck(:term)).to eq(%w[Nordlicht])
expect(lookup.read(page: 2, per_page: 3)[:data].pluck(:term)).to eq(%w[Nordlicht])
@@ -403,7 +409,7 @@ RSpec.describe Glossary::Lookup, :ci_guard do
expect { lookup.read(page: 'abc') }.to raise_error(described_class::InvalidArgument, /page "abc"/)
expect { lookup.read(page: '-1') }.to raise_error(described_class::InvalidArgument)
expect { lookup.read(page: '1.5') }.to raise_error(described_class::InvalidArgument)
- expect { lookup.read(page: 1.0) }.to raise_error(described_class::InvalidArgument)
+ expect { lookup.read(page: 1.5) }.to raise_error(described_class::InvalidArgument, /page "1.5"/)
expect { lookup.read(page: described_class::MAX_PAGE + 1) }.to raise_error(described_class::InvalidArgument)
end