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.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
fix: review round 1 of #124, the reader alone bounds the pages and every order rule is pinned
Guido Boyke1b559aed3f6d
diff --git a/CLAUDE.md b/CLAUDE.mdindex c8470bd..c531262 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -956,7 +956,8 @@ malformed one answer the same 404 (MCP `not_found`, also for a malformed id); `pforms of its project first, outside the organisation or the token the same 404. `people` and`speakers` only with the people right (`PersonPolicy`), named as the directory names them to thereader; whom it does not list counts in `count` alone. No meeting, place or corrector in the-answer. Pages by 50, at most 100, a value outside is a 400. Guards:+answer. Pages by 50, at most 100, a value outside is a 400 (MCP `invalid_input`, the same text and+after the same checks: the bounds are the reader's, not the tool schema's). 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/lalabase/CLAUDE.md b/app/services/lalabase/CLAUDE.mdindex 1d04cc6..c3dc937 100644--- a/app/services/lalabase/CLAUDE.md+++ b/app/services/lalabase/CLAUDE.md@@ -48,7 +48,9 @@ Codebase-Verständnis.`not_found`, as REST's one 404 (not `invalid_input` like the people twins: one reader, onereading of the id). Then the tenant, the glossary right (`refused`, reason `glossary_forbidden`,REST's text) and `authorize!`. `project_id` is its own argument (it reorders, it does not narrow),- so `project_filter?` stays false; an unknown argument is `invalid_input`.+ so `project_filter?` stays false; an unknown argument is `invalid_input`. The bounds of `page` and+ `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.On `:mcp` the same two names are twins (`McpFindPeople`, `McpGetPerson`, People S3b, MCP0.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 everydiff --git a/app/services/lalabase/tools/get_glossary.rb b/app/services/lalabase/tools/get_glossary.rbindex b4dc531..8360cfa 100644--- a/app/services/lalabase/tools/get_glossary.rb+++ b/app/services/lalabase/tools/get_glossary.rb@@ -15,6 +15,9 @@ module Lalabase# id is no invalid_input here, unlike the people twins: the two doors of one reader read one# id the same way (the reason of get_meeting, R9). project_id is the tool's own argument: it# reorders, it does not narrow, so it is not the dispatcher's filter (project_filter? false).+ # The bounds of page and per_page are the reader's, not the schema's (no minimum, no maximum):+ # 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).## MCP only, no assistant twin: the assistant does not need the glossary today.class GetGlossary < Base@@ -63,9 +66,10 @@ module Lalabaseproject_id: { type: 'string',description: 'Optional. UUID of a project of that organisation whose heard forms ' \'come first in each term.' },- page: { type: 'integer', minimum: 1, description: 'Page of terms, 1-based.' },- per_page: { type: 'integer', minimum: 1, maximum: Glossary::Lookup::MAX_PER_PAGE,- description: "Terms per page (default #{Glossary::Lookup::DEFAULT_PER_PAGE})." }+ page: { type: 'integer', description: 'Page of terms, from 1.' },+ per_page: { type: 'integer',+ description: "Terms per page, from 1 to #{Glossary::Lookup::MAX_PER_PAGE} " \+ "(default #{Glossary::Lookup::DEFAULT_PER_PAGE})." }},required: ['organisation_id']}diff --git a/spec/requests/api/glossary_parity_spec.rb b/spec/requests/api/glossary_parity_spec.rbindex d34f64e..f026729 100644--- a/spec/requests/api/glossary_parity_spec.rb+++ b/spec/requests/api/glossary_parity_spec.rb@@ -151,11 +151,27 @@ RSpec.describe 'Glossary on REST and MCP', :ci_guard, type: :request doexpect([outside['_meta'], project_result['_meta']]).to all(eq('lalabase/code' => 'not_found'))end- it 'refuses a page value outside its bounds as invalid input on both' do+ # The bounds are the reader's on both doors, not the MCP schema's: the same words, in the token+ # owner's language, and the same order of the checks (review round 1 of #124).+ it 'refuses a page value outside its bounds as invalid input on both, with one text' dostatus, body = rest(per_page: 101)result = mcp(per_page: 101)expect([status, body['code']]).to eq([400, 'invalid_input'])expect(result['_meta']).to eq('lalabase/code' => 'invalid_input')+ expect(result.dig('content', 0, 'text')).to eq(body['message'])+ expect(body['message']).to eq('invalid per_page "101" (expected a whole number from 1 to 100)')+ end++ it 'asks the right and the reach before a page value on both' do+ refused = token(owner: nobody)+ status, = rest(with: refused, per_page: 101)+ result = mcp(with: refused, per_page: 0)+ outside_status, = rest(organisation_id: other_organisation.id, page: 0)+ outside = mcp(organisation_id: other_organisation.id, page: 0)++ expect([status, outside_status]).to eq([403, 404])+ expect(result['_meta']).to eq('lalabase/code' => 'refused', 'lalabase/reason' => 'glossary_forbidden')+ expect(outside['_meta']).to eq('lalabase/code' => 'not_found')endenddiff --git a/spec/requests/api/mcp_glossary_spec.rb b/spec/requests/api/mcp_glossary_spec.rbindex 32d08b5..e12c406 100644--- a/spec/requests/api/mcp_glossary_spec.rb+++ b/spec/requests/api/mcp_glossary_spec.rb@@ -107,14 +107,16 @@ RSpec.describe 'MCP get_glossary', :ci_guard, type: :request doexpect(tools.pluck('name').last(2)).to eq(%w[get_meeting get_glossary])end- # A read on a token: the organisation always, the project only as an order, pages with their- # bounds; no project_id injected as a gate and no idempotency key.+ # A read on a token: the organisation always, the project only as an order, pages; no project_id+ # injected as a gate and no idempotency key. The bounds of the pages are named, not enforced by+ # the schema: the reader refuses them after the right, as REST does (review round 1 of #124).it 'takes the organisation, a project to put first and pages' doschema = tools.find { |tool| tool['name'] == 'get_glossary' }['inputSchema']expect(schema['properties'].keys).to eq(%w[organisation_id project_id page per_page])expect(schema['required']).to eq(['organisation_id'])- expect(schema.dig('properties', 'per_page')).to include('type' => 'integer', 'minimum' => 1, 'maximum' => 100)+ expect(schema.dig('properties', 'per_page')).to eq('type' => 'integer', 'description' => 'Terms per page, from 1 to 100 (default 50).')+ expect(schema.dig('properties', 'page').keys).to eq(%w[type description])expect(schema.dig('properties', 'project_id', 'description')).to match(/come first/)endend@@ -211,6 +213,7 @@ RSpec.describe 'MCP get_glossary', :ci_guard, type: :request dounknown = refusal(glossary(query: 'lala'))expect([too_many, page_zero, as_text]).to all(eq('lalabase/code' => 'invalid_input'))+ expect(text(glossary(per_page: 101))).to eq('invalid per_page "101" (expected a whole number from 1 to 100)')expect(blank).to eq([{ 'lalabase/code' => 'invalid_input' }, 'organisation_id is required'])expect(unknown).to eq([{ 'lalabase/code' => 'invalid_input' }, 'unknown arguments: query'])enddiff --git a/spec/requests/api/mcp_result_codes_spec.rb b/spec/requests/api/mcp_result_codes_spec.rbindex 9255136..23cbd4b 100644--- a/spec/requests/api/mcp_result_codes_spec.rb+++ b/spec/requests/api/mcp_result_codes_spec.rb@@ -351,8 +351,7 @@ RSpec.describe 'MCP answers carry a machine field', :ci_guard, type: :request do['get_person', -> { { organisation_id: organisation.id, id: ' ' } }, /id is required/],['get_person', -> { { organisation_id: organisation.id, id: 'abc' } }, /invalid id/],['get_glossary', -> { { organisation_id: ' ' } }, /organisation_id is required/],- ['get_glossary', -> { { organisation_id: organisation.id, query: 'lala' } }, /unknown arguments: query/],- ['get_glossary', -> { { organisation_id: organisation.id, per_page: 101 } }, /per_page/]+ ['get_glossary', -> { { organisation_id: organisation.id, query: 'lala' } }, /unknown arguments: query/]]error_sites.each do |tool, arguments, text, mode|diff --git a/spec/services/glossary/lookup_spec.rb b/spec/services/glossary/lookup_spec.rbindex 1e5dd3b..af6d92a 100644--- a/spec/services/glossary/lookup_spec.rb+++ b/spec/services/glossary/lookup_spec.rb@@ -316,6 +316,42 @@ RSpec.describe Glossary::Lookup, :ci_guard doendend+ # Review round 1 of #124: every rule of the order, with rows made against the expected order, so a+ # missing or a turned sort cannot pass on the order the database happens to hand them out in. The+ # two ids of Alma and Zeta sort the other way round when read backwards.+ describe 'the order of the answer' do+ let(:quell) { create(:glossary_term, organisation: organisation, term: 'Quellwort') }+ let(:zeta) { create(:person, id: '00000000-0000-4000-8000-0000000000b1', organisation: organisation, name: 'Zeta Zander') }+ let(:alma) { create(:person, id: '00000000-0000-4000-8000-0000000000a9', organisation: organisation, name: 'Alma Abel') }++ it 'breaks a tie of forms by the compared form, and a tie of speakers by ref' do+ heard(quell, 'kalbe', replaced: 2, project: project, person: zeta)+ heard(quell, 'kalbe', replaced: 2, project: project, person: alma)+ heard(quell, 'kalb x', replaced: 4, project: project)++ tied = forms(lookup.read, quell)+ expect(tied.pluck(:form)).to eq(['kalb x', 'kalbe'])+ expect(tied.last[:speakers]).to eq([{ ref: "person:#{alma.id}", count: 2 }, { ref: "person:#{zeta.id}", count: 2 }])+ end++ it 'lists the people by name, not in the order they were heard' do+ heard(quell, 'quell z', project: project, person: zeta)+ heard(quell, 'quell a', project: project, person: alma)++ expect(lookup.read[:people].pluck(:name))+ .to eq(['Alma Abel', 'Ben Beispiel', 'Doris Dienstleister', 'Erika Muster', 'Zeta Zander'])+ end++ it 'puts first a form heard in project_id that was heard in another project too' do+ heard(quell, 'quell viel', replaced: 5, project: other_project)+ heard(quell, 'quell mix', replaced: 1, project: other_project)+ heard(quell, 'quell mix', replaced: 1, project: project)++ expect(forms(lookup.read, quell).pluck(:form)).to eq(['quell viel', 'quell mix'])+ expect(forms(lookup.read(project_id: project.id), quell).pluck(:form)).to eq(['quell mix', 'quell viel'])+ end+ end+describe 'pages' dobefore do%w[Birkenweg Eschenhof].each { |word| create(:glossary_term, organisation: organisation, term: word) }