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
Offer summarize_time_sessions over MCP so clients can show a ticket's booked time
Guido Boyke4916e5afb669
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex 97230c0..49e4f79 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -264,6 +264,7 @@ jobs:spec/requests/api/mcp_ticket_existence_spec.rbspec/requests/api/mcp_update_ticket_spec.rbspec/requests/api/mcp_plain_comment_spec.rb+ spec/requests/api/mcp_time_report_spec.rbspec/services/posts/plain_text_body_spec.rbspec/services/lalabase/tools/post_comment_spec.rbspec/requests/api/inbox_organisation_filter_spec.rbdiff --git a/app/services/lalabase/CLAUDE.md b/app/services/lalabase/CLAUDE.mdindex 51e0ad6..8d12c2d 100644--- a/app/services/lalabase/CLAUDE.md+++ b/app/services/lalabase/CLAUDE.md@@ -1,4 +1,4 @@-# Karte: app/services/lalabase (Stand: 2026-10-26)+# Karte: app/services/lalabase (Stand: 2026-10-28)AI/RAG-Domäne (Produktname „Lalabase"): alles rund um LLM-Aufrufe, Embeddings undCodebase-Verständnis.@@ -51,7 +51,13 @@ Codebase-Verständnis.zitieren die Auswertung (`summarize_time_sessions`, Zitationstyp `time_report`). EinReport prüft seine Rechte SELBST, wo die Area zu grob ist: Zeiten gehen durch`TimeSessions::ViewingScope` (eigene/alle), die Area `time_sessions` bleibt nur für den- Riegel gesetzt (Plan `doc/persoenlicher_assistent_plan.md` §6.4, §13-9). Org-weite+ Riegel gesetzt (Plan `doc/persoenlicher_assistent_plan.md` §6.4, §13-9).+ `summarize_time_sessions` ist seit MCP 0.12.0 (Terminal-Client S6) auch im `:mcp`-Set,+ als letztes Werkzeug: Projektmodus (`project_id` Pflicht, die Naht prüft Projekt und+ Token-Reichweite), Rechte über `ViewingScope` im Werkzeug, Lesewerkzeug (auch für+ Nur-Lese-Token), keine Zitationen in der MCP-Antwort. Das org-weite Feld `project` steht+ dort mit im Schema, wird auf dem Projektpfad aber ignoriert. Spec:+ `spec/requests/api/mcp_time_report_spec.rb`. Org-weiteReichweite (S3a T3): `Context#scope` (`tools/scope.rb`, je Area über`accessible_project_ids`) ADDITIV zu `project` (R-M5, MCP unberührt), `Result#coverage`ist das L7-Deckungs-Vertragsfeld, mehrdeutige Ticketnummern antworten mit der geteiltendiff --git a/app/services/lalabase/tools/registry.rb b/app/services/lalabase/tools/registry.rbindex 74c11ad..b0b1b1b 100644--- a/app/services/lalabase/tools/registry.rb+++ b/app/services/lalabase/tools/registry.rb@@ -37,7 +37,8 @@ module Lalabase## summarize_time_sessions (S2) is a REPORT tool: numbers, no rows. It decides# own-vs-all itself (TimeSessions::ViewingScope) because the :time_sessions- # area gate cannot. The MCP wire order is pinned separately.+ # area gate cannot. Since MCP 0.12.0 it is in :mcp too, appended last there+ # (that wire order is pinned separately).## recent_activity (§13-11) is here and ONLY here. Its rows span areas and# only the ticket ones can carry a citation, so a shared thread's render@@ -119,7 +120,13 @@ module LalabaseMarkNotificationRead,# Terminal client S2: status, assignees and title of one ticket, through# the board's write paths. Appended for the same reason.- UpdateTicket+ UpdateTicket,+ # Terminal client S6: the booked time of a ticket, for the meta bar of the+ # client's ticket view. A read in project mode: the seam gates the project,+ # the tool narrows through TimeSessions::ViewingScope itself; its org-wide+ # `project` filter is ignored on this path. Appended so the pinned wire+ # order stays intact.+ SummarizeTimeSessions].freeze# Sets whose tools reach the LLM tool loop. The guard-spec enforces thediff --git a/app/services/mcp/dispatcher.rb b/app/services/mcp/dispatcher.rbindex 84e33ef..d82f666 100644--- a/app/services/mcp/dispatcher.rb+++ b/app/services/mcp/dispatcher.rb@@ -43,7 +43,9 @@ module Mcp# create_ticket takes the same title (one line, at most 255 characters,# anything else is invalid_input instead of being stored).# 0.11 = post_comment takes format: "plain" (terminal client S2b).- SERVER_VERSION = '0.11.0'+ # 0.12 = summarize_time_sessions (terminal client S6: the booked time of a+ # ticket).+ SERVER_VERSION = '0.12.0'# MCP surface — sourced from the single tool registry (D6): the :mcp set is the# ONE definition of this surface, so a registry refactor can't drift it (R3);diff --git a/spec/contracts/mcp_contract_recorder.rb b/spec/contracts/mcp_contract_recorder.rbindex bfc0482..8b9794e 100644--- a/spec/contracts/mcp_contract_recorder.rb+++ b/spec/contracts/mcp_contract_recorder.rb@@ -311,10 +311,49 @@ module McpContract# world, so every answer above stays as it was.'update_ticket' => update_ticket_calls(website, foreign),# S2b runs after all existing calls, without advancing the clock.- 'post_comment_formats' => post_comment_format_calls(website)+ 'post_comment_formats' => post_comment_format_calls(website),+ # Terminal client S6, appended last for the same reason: its bookings+ # and time rights are made right before it, without advancing the clock.+ 'summarize_time_sessions' => time_report_calls(website, foreign)}end+ # The booked time of the login ticket: Anna 30 minutes, Ben 45, plus 20 of+ # Ben's on the export ticket. The client has not settled on own time or the+ # ticket's total yet, so both answers are recorded, and the "own" tier once+ # Anna's right is narrowed to it.+ def time_report_calls(website, foreign)+ login = id(:login_ticket)+ in_org do+ create(:time_session_permission, user: @anna, project: @website, can_view_own: true, can_view_all: true)+ { @anna => [30, @login], @ben => [45, @login] }.each { |user, (minutes, ticket)| booking(user, minutes, ticket) }+ booking(@ben, 20, @export)+ end+ {+ 'ok_own' => tool_call(:read, 'summarize_time_sessions', project_id: website, ticket: login, creator: 'me'),+ 'ok_total' => tool_call(:read, 'summarize_time_sessions', project_id: website, ticket: login),+ 'empty' => tool_call(:read, 'summarize_time_sessions', project_id: website, ticket: id(:missing)),+ # Notes only in the handbook, no time permission row: refused, no numbers.+ 'refused' => tool_call(:read, 'summarize_time_sessions', project_id: id(:handbook), ticket: id(:hidden_ticket)),+ 'not_found' => tool_call(:read, 'summarize_time_sessions', project_id: foreign, ticket: login),+ # The tool refuses a malformed date without a code, which MCP answers as refused.+ 'invalid_date' => tool_call(:read, 'summarize_time_sessions', project_id: website, start_date: '05.01.2026'),+ 'ok_own_tier' => with_own_time_only(@anna, on: @website) do+ tool_call(:read, 'summarize_time_sessions', project_id: website, ticket: login)+ end+ }+ end++ def booking(user, minutes, ticket)+ create(:time_session, project: ticket.project, organisation: @organisation, creator: user, ticket: ticket,+ duration: minutes, occurred_on: START + 1.hour, description: 'Vertrag')+ end++ def with_own_time_only(user, on:)+ in_org { TimeSessionPermission.find_by!(user: user, project: on).update!(can_view_all: false) }+ yield+ end+def post_comment_format_calls(project)args = { project_id: project, ticket_id: id(:login_ticket) }{diff --git a/spec/fixtures/mcp_contract.json b/spec/fixtures/mcp_contract.jsonindex 5d438ce..b29b6f5 100644--- a/spec/fixtures/mcp_contract.json+++ b/spec/fixtures/mcp_contract.json@@ -1,9 +1,9 @@{"header": {"regenerate": "RAILS_ENV=test bin/rails mcp:contract",- "core_commit": "38c4d2ad6e9f191073d532fda754d5be3ddbec01",+ "core_commit": "fd599cb693f019c491228e081a54e59380d50b7d","core_dirty": true,- "contract_sha256": "0d74f7549e9cf134b87e79ee66e48495a1698088d5828795030b98255036fd79"+ "contract_sha256": "5bcc5e85d196623f5d95be207275d2f8493062b988703534cfc0e0633d84d8bc"},"contract": {"mcp": {@@ -42,7 +42,7 @@},"serverInfo": {"name": "lalabase",- "version": "0.11.0"+ "version": "0.12.0"}}}@@ -563,6 +563,43 @@"project_id"]}+ },+ {+ "name": "summarize_time_sessions",+ "description": "Sums the booked time of the project by billing state, from the database. Returns minutes, hours and session counts for three buckets: billed (invoice number recorded), in_billing (assigned to an open billing, not invoiced yet), without_billing (not assigned to any billing); plus total and not_invoiced (= in_billing + without_billing). Optional filters: start_date / end_date (YYYY-MM-DD, inclusive), creator (\"me\" or a user UUID), ticket (UUID or the \"#187\" number). The scope field says whether the numbers cover ALL sessions of the project or only the asking user's OWN (\"own\"); when it is \"own\", say so in the answer. Returns no individual sessions. In an org-wide assistant thread the sums span every project whose time the user may see, each narrowed to its own permission tier; scope is then \"all\", \"own\" or \"mixed\", and coverage says how many of the organisation's projects the numbers cover - state both in the answer.",+ "inputSchema": {+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "type": "object",+ "properties": {+ "start_date": {+ "type": "string",+ "description": "First day to include, YYYY-MM-DD."+ },+ "end_date": {+ "type": "string",+ "description": "Last day to include, YYYY-MM-DD (inclusive)."+ },+ "creator": {+ "type": "string",+ "description": "Only sessions booked by this user: \"me\" or a user UUID."+ },+ "ticket": {+ "type": "string",+ "description": "Only sessions booked on this ticket: its UUID or the number shown in the app, e.g. \"187\" or \"#187\"."+ },+ "project": {+ "type": "string",+ "description": "Restrict to THIS project: its name as shown in the app (e.g. \"Nordlicht\") or its UUID. Org-wide calls only. An ambiguous or unknown name answers with a candidate list instead of a result, so ask which one was meant rather than guessing."+ },+ "project_id": {+ "type": "string",+ "description": "UUID of the Lalabase project to scope this call to."+ }+ },+ "required": [+ "project_id"+ ]+ }}]}@@ -2679,6 +2716,247 @@}}}+ },+ "summarize_time_sessions": {+ "ok_own": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket": "00000000-0000-4000-8000-000000000041",+ "creator": "me"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "{\n \"scope\": \"all\",\n \"filters\": {\n \"creator_id\": \"00000000-0000-4000-8000-000000000011\",\n \"ticket\": {\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\"\n }\n },\n \"buckets\": {\n \"without_billing\": {\n \"minutes\": 30,\n \"sessions\": 1,\n \"hours\": 0.5\n },\n \"in_billing\": {\n \"minutes\": 0,\n \"sessions\": 0,\n \"hours\": 0.0\n },\n \"billed\": {\n \"minutes\": 0,\n \"sessions\": 0,\n \"hours\": 0.0\n }\n },\n \"not_invoiced\": {\n \"minutes\": 30,\n \"sessions\": 1,\n \"hours\": 0.5\n },\n \"total\": {\n \"minutes\": 30,\n \"sessions\": 1,\n \"hours\": 0.5\n }\n}"+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "ok"+ }+ }+ }+ }+ },+ "ok_total": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket": "00000000-0000-4000-8000-000000000041"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "{\n \"scope\": \"all\",\n \"filters\": {\n \"ticket\": {\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\"\n }\n },\n \"buckets\": {\n \"without_billing\": {\n \"minutes\": 75,\n \"sessions\": 2,\n \"hours\": 1.25\n },\n \"in_billing\": {\n \"minutes\": 0,\n \"sessions\": 0,\n \"hours\": 0.0\n },\n \"billed\": {\n \"minutes\": 0,\n \"sessions\": 0,\n \"hours\": 0.0\n }\n },\n \"not_invoiced\": {\n \"minutes\": 75,\n \"sessions\": 2,\n \"hours\": 1.25\n },\n \"total\": {\n \"minutes\": 75,\n \"sessions\": 2,\n \"hours\": 1.25\n }\n}"+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "ok"+ }+ }+ }+ }+ },+ "empty": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket": "00000000-0000-4000-8000-000000000999"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "No ticket found for 00000000-0000-4000-8000-000000000999."+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "empty"+ }+ }+ }+ }+ },+ "refused": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000033",+ "ticket": "00000000-0000-4000-8000-000000000043"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "no access to the time sessions of this project"+ }+ ],+ "isError": true,+ "_meta": {+ "lalabase/code": "refused"+ }+ }+ }+ }+ },+ "not_found": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000034",+ "ticket": "00000000-0000-4000-8000-000000000041"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "Project not found or not accessible."+ }+ ],+ "isError": true,+ "_meta": {+ "lalabase/code": "not_found"+ }+ }+ }+ }+ },+ "invalid_date": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "start_date": "05.01.2026"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "invalid start_date (expected YYYY-MM-DD)"+ }+ ],+ "isError": true,+ "_meta": {+ "lalabase/code": "refused"+ }+ }+ }+ }+ },+ "ok_own_tier": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "summarize_time_sessions",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket": "00000000-0000-4000-8000-000000000041"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "{\n \"scope\": \"own\",\n \"filters\": {\n \"ticket\": {\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\"\n }\n },\n \"buckets\": {\n \"without_billing\": {\n \"minutes\": 30,\n \"sessions\": 1,\n \"hours\": 0.5\n },\n \"in_billing\": {\n \"minutes\": 0,\n \"sessions\": 0,\n \"hours\": 0.0\n },\n \"billed\": {\n \"minutes\": 0,\n \"sessions\": 0,\n \"hours\": 0.0\n }\n },\n \"not_invoiced\": {\n \"minutes\": 30,\n \"sessions\": 1,\n \"hours\": 0.5\n },\n \"total\": {\n \"minutes\": 30,\n \"sessions\": 1,\n \"hours\": 0.5\n }\n}"+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "ok"+ }+ }+ }+ }+ }}}},diff --git a/spec/requests/api/mcp_time_report_spec.rb b/spec/requests/api/mcp_time_report_spec.rbnew file mode 100644index 0000000..9113cf1--- /dev/null+++ b/spec/requests/api/mcp_time_report_spec.rb@@ -0,0 +1,285 @@+# frozen_string_literal: true++require 'rails_helper'++# What: summarize_time_sessions over POST /api/mcp (terminal client S6: the booked+# time of a ticket, for the meta bar of the client's ticket view).+# Why: the tool decides own-vs-all itself (TimeSessions::ViewingScope), and the MCP+# seam only gates the project. A token must never see minutes its owner may not+# see in the app: not under the "own" tier, not through a foreign creator UUID,+# not without a permission row, not through a ticket of another project or one+# the owner may not read, not in a project outside the token's reach. And the+# answer must not tell a missing project or ticket from a hidden one.+RSpec.describe 'MCP summarize_time_sessions', :ci_guard, type: :request do+ let(:organisation) { create(:organisation) }+ let(:other_organisation) { create(:organisation) }+ let(:role) { create(:role, organisation: organisation) }+ let(:user) { create(:user) }+ let(:colleague) { create(:user) }++ let(:project) { create(:project, organisation: organisation) }+ # Same organisation, the owner may use it and read its tickets.+ let(:other_project) { create(:project, organisation: organisation) }+ # The owner may use it (notes) and sees all time here, but reads no ticket.+ let(:time_only_project) { create(:project, organisation: organisation) }+ let(:foreign_project) do+ ActsAsTenant.with_tenant(other_organisation) { create(:project, organisation: other_organisation) }+ end++ let(:ticket) { create(:ticket, project: project, organisation: organisation, creator: user) }+ let(:other_ticket) { create(:ticket, project: other_project, organisation: organisation, creator: user) }+ let(:unreadable_ticket) { create(:ticket, project: time_only_project, organisation: organisation, creator: colleague) }++ before do+ ActsAsTenant.current_tenant = organisation+ Prosopite.pause do+ [user, colleague].each do |member|+ create(:membership, user: member, organisation: organisation, role: role, active: true)+ end+ create(:project_permission, user: user, project: project, tickets_access: :read_write)+ create(:project_permission, user: user, project: other_project, tickets_access: :read_write)+ create(:project_permission, user: user, project: time_only_project, tickets_access: :no_access,+ notes_access: :read_only)+ create(:project_permission, user: colleague, project: time_only_project, tickets_access: :read_write)++ book(user, 30, ticket: ticket)+ book(colleague, 45, ticket: ticket)+ book(colleague, 20, project: project)+ book(user, 10, ticket: other_ticket)+ book(colleague, 15, ticket: unreadable_ticket)+ end+ end++ after { ActsAsTenant.current_tenant = nil }++ def book(creator, minutes, ticket: nil, project: ticket.project)+ create(:time_session, project: project, organisation: organisation, creator: creator,+ duration: minutes, ticket: ticket, occurred_on: Time.zone.parse('2026-08-10 10:00'))+ end++ # Fail-closed: only a persisted row grants anything (ViewingScope).+ def grant_time(on, view_all:)+ create(:time_session_permission, user: user, project: on, can_view_own: true, can_view_all: view_all)+ end++ def build_pat(read_only: true, project_scopes: {})+ build(:personal_access_token, user: user, organisations: [organisation],+ read_only: read_only, project_scopes: project_scopes).tap do |pat|+ pat.token_hash = nil+ pat.token_prefix = nil+ pat.generate_token!+ end+ end++ let(:pat) { build_pat }++ def rpc(method, params, token)+ post '/api/mcp', params: { jsonrpc: '2.0', id: 1, method: method, params: params }.to_json,+ headers: { 'Authorization' => "Bearer #{token.token}", 'CONTENT_TYPE' => 'application/json' }+ response.parsed_body+ end++ def call(token: pat, **arguments)+ rpc('tools/call', { name: 'summarize_time_sessions', arguments: arguments }, token)['result']+ end++ def report(token: pat, **arguments)+ result = call(token: token, **arguments)+ expect(result['isError']).to be_falsey, "expected a report, got #{result.inspect}"+ JSON.parse(result.dig('content', 0, 'text'))+ end++ def minutes(token: pat, **arguments)+ report(token: token, **arguments).dig('total', 'minutes')+ end++ # No numbers at all: neither the report keys nor a single bucket.+ def expect_no_numbers(result)+ text = result.dig('content', 0, 'text').to_s+ expect(text).not_to include('total', 'buckets', 'minutes')+ end++ describe 'tools/list' do+ let(:tools) { rpc('tools/list', {}, pat).dig('result', 'tools') }++ it 'advertises the tool LAST, the pinned order of every other tool unchanged' do+ expect(tools.pluck('name')).to eq(%w[+ search_code_symbols list_capabilities get_project_vision+ get_capability_details get_symbol_details list_tickets+ get_ticket search_knowledge create_ticket post_comment+ list_notifications create_time_session mark_notification_read+ update_ticket summarize_time_sessions+ ])+ end++ it 'requires project_id and offers no idempotency_key (a read, D6)' do+ schema = tools.last['inputSchema']+ expect(schema['required']).to eq(['project_id'])+ expect(schema['properties'].keys).to include('ticket', 'creator', 'start_date', 'end_date', 'project_id')+ expect(schema['properties']).not_to have_key('idempotency_key')+ end+ end++ it 'reports server version 0.12.0' do+ body = rpc('initialize', { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'rspec', version: '0' } },+ pat)+ expect(body.dig('result', 'serverInfo', 'version')).to eq('0.12.0')+ end++ context 'when the owner sees all time of the project' do+ before { grant_time(project, view_all: true) }++ it 'sums every booking on the ticket without creator, under scope "all"' do+ answer = report(project_id: project.id, ticket: ticket.id)+ expect(answer['scope']).to eq('all')+ expect(answer.dig('total', 'minutes')).to eq(75)+ expect(answer.dig('total', 'sessions')).to eq(2)+ expect(answer.dig('total', 'hours')).to eq(1.25)+ expect(answer.dig('filters', 'ticket', 'id')).to eq(ticket.id)+ end++ it 'sums only the own bookings with creator "me"' do+ expect(minutes(project_id: project.id, ticket: ticket.id, creator: 'me')).to eq(30)+ end++ it 'sums the whole project without a ticket' do+ expect(minutes(project_id: project.id)).to eq(95)+ end++ it 'answers with the report and nothing else: no single bookings, no citations' do+ result = call(project_id: project.id, ticket: ticket.id)+ expect(result['content'].size).to eq(1)+ expect(result['_meta']).to eq('lalabase/kind' => 'ok')+ expect(result.keys).not_to include('citations', 'structuredContent')+ answer = JSON.parse(result.dig('content', 0, 'text'))+ expect(answer.keys).to contain_exactly('scope', 'filters', 'buckets', 'not_invoiced', 'total')+ expect(answer['buckets'].keys).to contain_exactly('billed', 'in_billing', 'without_billing')+ expect(result.to_json).not_to include('citation', 'duration', 'occurred_on', 'description')+ end++ it 'is open to a read-only token and to a writable one alike' do+ expect(pat).to be_read_only+ expect(minutes(project_id: project.id, ticket: ticket.id)).to eq(75)+ expect(minutes(token: build_pat(read_only: false), project_id: project.id, ticket: ticket.id)).to eq(75)+ end+ end++ context 'when the owner sees only their own time' do+ before { grant_time(project, view_all: false) }++ it 'sums only the own bookings without creator, under scope "own"' do+ answer = report(project_id: project.id, ticket: ticket.id)+ expect(answer['scope']).to eq('own')+ expect(answer.dig('total', 'minutes')).to eq(30)+ end++ it 'sums only the own bookings with creator "me"' do+ expect(minutes(project_id: project.id, ticket: ticket.id, creator: 'me')).to eq(30)+ end++ it "sums a colleague's bookings to zero, never widening the tier" do+ expect(minutes(project_id: project.id, ticket: ticket.id, creator: colleague.id)).to eq(0)+ expect(minutes(project_id: project.id, creator: colleague.id)).to eq(0)+ end++ it 'sums only the own bookings of the whole project without a ticket' do+ expect(minutes(project_id: project.id)).to eq(30)+ end+ end++ context 'without a time permission row' do+ it 'refuses with an error and no numbers' do+ result = call(project_id: project.id, ticket: ticket.id)+ expect(result['isError']).to be(true)+ expect(result['_meta']).to eq('lalabase/code' => 'refused')+ expect_no_numbers(result)+ end++ it 'refuses with the same answer when the row grants no viewing at all' do+ create(:time_session_permission, :no_access, user: user, project: project)+ result = call(project_id: project.id, ticket: ticket.id)+ expect(result['_meta']).to eq('lalabase/code' => 'refused')+ expect_no_numbers(result)+ end+ end++ describe 'the ticket filter' do+ before do+ grant_time(project, view_all: true)+ grant_time(time_only_project, view_all: true)+ end++ it 'answers a ticket of another project like a missing one: empty, no numbers' do+ missing = call(project_id: project.id, ticket: SecureRandom.uuid)+ result = call(project_id: project.id, ticket: other_ticket.id)+ expect(result['isError']).to be_falsey+ expect(result['_meta']).to eq('lalabase/kind' => 'empty')+ expect_no_numbers(result)+ expect(result['content'].first['text'].sub(other_ticket.id, 'X'))+ .to eq(missing['content'].first['text'].sub(/\h{8}-\h{4}-\h{4}-\h{4}-\h{12}/, 'X'))+ end++ it 'answers a ticket the owner may not read like a missing one, though the time is visible' do+ expect(minutes(project_id: time_only_project.id)).to eq(15)+ result = call(project_id: time_only_project.id, ticket: unreadable_ticket.id)+ expect(result['_meta']).to eq('lalabase/kind' => 'empty')+ expect_no_numbers(result)+ end++ it 'answers a ticket number of another project like a missing one' do+ result = call(project_id: project.id, ticket: "##{other_ticket.number + 100}")+ expect(result['_meta']).to eq('lalabase/kind' => 'empty')+ end+ end++ describe 'the project gate' do+ before do+ grant_time(project, view_all: true)+ grant_time(other_project, view_all: true)+ end++ let(:missing) { call(project_id: SecureRandom.uuid) }++ def expect_like_missing(result)+ expect(result).to eq(missing)+ expect(result['_meta']).to eq('lalabase/code' => 'not_found')+ expect_no_numbers(result)+ end++ it 'answers a project outside the token reach like a missing one' do+ narrow = build_pat(project_scopes: { organisation => [other_project] })+ expect(minutes(token: narrow, project_id: other_project.id)).to eq(10)+ expect_like_missing(call(token: narrow, project_id: project.id, ticket: ticket.id))+ end++ it 'answers a project of a foreign organisation like a missing one' do+ ActsAsTenant.with_tenant(other_organisation) do+ create(:time_session, project: foreign_project, organisation: other_organisation, duration: 99)+ end+ expect_like_missing(call(project_id: foreign_project.id))+ end++ it 'answers a project of the organisation the owner has no right in like a missing one' do+ stranger = create(:project, organisation: organisation)+ expect_like_missing(call(project_id: stranger.id))+ end++ it 'refuses a call without project_id as invalid input' do+ result = call(ticket: ticket.id)+ expect(result['isError']).to be(true)+ expect(result['_meta']).to eq('lalabase/code' => 'invalid_input')+ end++ it 'ignores the org-wide project filter on the project path (D5)' do+ expect(minutes(project_id: project.id, project: other_project.name)).to eq(95)+ end+ end++ it 'refuses a malformed date without numbers, as the tool reports it (refused)' do+ grant_time(project, view_all: true)+ result = call(project_id: project.id, start_date: '31.08.2026')+ expect(result['isError']).to be(true)+ expect(result['_meta']).to eq('lalabase/code' => 'refused')+ expect_no_numbers(result)+ end+enddiff --git a/spec/services/lalabase/tools/registry_spec.rb b/spec/services/lalabase/tools/registry_spec.rbindex b9ed7ae..2a375b4 100644--- a/spec/services/lalabase/tools/registry_spec.rb+++ b/spec/services/lalabase/tools/registry_spec.rb@@ -79,8 +79,10 @@ RSpec.describe Lalabase::Tools::Registry doendend- it 'the time report stays out of :mcp (wire order pinned)' do- expect(described_class.for(:mcp)).not_to include(t::SummarizeTimeSessions)+ # Terminal client S6: the booked time of a ticket. Appended LAST, so the+ # pinned wire order of every tool before it stays intact.+ it 'offers the time report on :mcp as the last tool (wire order pinned)' do+ expect(described_class.for(:mcp).last).to eq(t::SummarizeTimeSessions)endit 'no chat set carries search_knowledge (deliberate omission)' do@@ -97,7 +99,7 @@ RSpec.describe Lalabase::Tools::Registry dot::SearchCodeSymbols, t::ListCapabilities, t::GetProjectVision,t::GetCapabilityDetails, t::GetSymbolDetails, t::ListTickets,t::GetTicket, t::SearchKnowledge, t::CreateTicket, t::PostComment, t::ListNotifications,- t::CreateTimeSession, t::MarkNotificationRead, t::UpdateTicket+ t::CreateTimeSession, t::MarkNotificationRead, t::UpdateTicket, t::SummarizeTimeSessions)end@@ -202,7 +204,7 @@ RSpec.describe Lalabase::Tools::Registry doget_capability_details get_symbol_details list_ticketsget_ticket search_knowledge create_ticket post_commentlist_notifications create_time_session mark_notification_read- update_ticket+ update_ticket summarize_time_sessions]end