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 1 of #89: say what a comment's files hold, pin two gaps

Guido Boykefd8bc86139b3
diff --git a/app/services/lalabase/tools/get_ticket.rb b/app/services/lalabase/tools/get_ticket.rb
index abd77e3..3bfd786 100644
--- a/app/services/lalabase/tools/get_ticket.rb
+++ b/app/services/lalabase/tools/get_ticket.rb
@@ -19,7 +19,8 @@ module Lalabase
# A `text_status` per file says whether that text exists, is missing, or was
# never extractable — silence would be answered with a guess. A comment's files
# are another matter: they come with the comment as name, type and size only
- # (Tickets::Serializer#post_attachments), metadata like its author, no text.
+ # (Tickets::Serializer#post_attachments), uncapped metadata like its author, and
+ # the description says that their text is not here.
#
# Caps (D9, over-fetching / DoS): long bodies are truncated, the posts list is
# bounded, and so are the attachments in both directions (how many, and how much
@@ -93,9 +94,11 @@ module Lalabase
'none, such as a scanned PDF ("empty"), has not been read out yet or the ' \
'reading failed, so the same file may answer later ("unavailable"), or is ' \
'a type we never read text from ("unsupported"). ' \
+ 'A comment lists its own files in attachments too, by name, type and size ' \
+ 'only: their text is not here. ' \
'status_functions says what the status means in its project (is_backlog, is_new, ' \
'is_open, is_in_progress, is_completed, is_closed), [] when the project gave it none. ' \
- 'Long bodies are truncated, the posts and attachment lists are capped, ' \
+ 'Long bodies are truncated, the posts and the ticket\'s attachments are capped, ' \
'and attachment download URLs are not included.'
end
diff --git a/spec/fixtures/mcp_contract.json b/spec/fixtures/mcp_contract.json
index 8e631ef..20ef017 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": "80d75a190772f8f15546fb4b7c200cc9a0b88de8",
+ "core_commit": "12988a8562ad16f99c9cd7e3c9ad07d9d0b72b00",
"core_dirty": true,
- "contract_sha256": "bce4a6d9eec92d9e35ccce8217316d3be5650ed01217ed6915125a1cf78790d2"
+ "contract_sha256": "d02a053ea887a9f409778ef5698d63ed69d01f5f67a2fa8edef684876ce485c5"
},
"contract": {
"mcp": {
@@ -235,7 +235,7 @@
},
{
"name": "get_ticket",
- "description": "Fetches a single ticket as JSON: head fields, description, custom attributes and discussion posts (oldest first). Address the ticket either by ticket_id (its UUID) or by number, the \"#187\" users see in the app; a number is unique within one project only. ticket_id wins when both are given. Authorized per-record against the token owner. The ticket's attachments come with the text extracted from each file, so a question about an attached PDF is answered from here; text_status says whether a file has readable text (\"available\"), was read and holds none, such as a scanned PDF (\"empty\"), has not been read out yet or the reading failed, so the same file may answer later (\"unavailable\"), or is a type we never read text from (\"unsupported\"). status_functions says what the status means in its project (is_backlog, is_new, is_open, is_in_progress, is_completed, is_closed), [] when the project gave it none. Long bodies are truncated, the posts and attachment lists are capped, and attachment download URLs are not included.",
+ "description": "Fetches a single ticket as JSON: head fields, description, custom attributes and discussion posts (oldest first). Address the ticket either by ticket_id (its UUID) or by number, the \"#187\" users see in the app; a number is unique within one project only. ticket_id wins when both are given. Authorized per-record against the token owner. The ticket's attachments come with the text extracted from each file, so a question about an attached PDF is answered from here; text_status says whether a file has readable text (\"available\"), was read and holds none, such as a scanned PDF (\"empty\"), has not been read out yet or the reading failed, so the same file may answer later (\"unavailable\"), or is a type we never read text from (\"unsupported\"). A comment lists its own files in attachments too, by name, type and size only: their text is not here. status_functions says what the status means in its project (is_backlog, is_new, is_open, is_in_progress, is_completed, is_closed), [] when the project gave it none. Long bodies are truncated, the posts and the ticket's attachments are capped, and attachment download URLs are not included.",
"inputSchema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
diff --git a/spec/requests/api/v1/comment_files_spec.rb b/spec/requests/api/v1/comment_files_spec.rb
index f8c865c..ebce759 100644
--- a/spec/requests/api/v1/comment_files_spec.rb
+++ b/spec/requests/api/v1/comment_files_spec.rb
@@ -47,8 +47,8 @@ RSpec.describe 'Comment files in the ticket view', :ci_guard, type: :request do
document
end
- # The file with the higher id is made first: the list follows the id, not the
- # order the rows were written in.
+ # The file with the higher id is made first and has the earlier name: the list
+ # follows the id, not the order the rows were written in, nor the name.
let(:higher_id) { 'ffffffff-ffff-4fff-8fff-ffffffffffff' }
let(:lower_id) { '00000000-0000-4000-8000-00000000000a' }
@@ -57,8 +57,8 @@ RSpec.describe 'Comment files in the ticket view', :ci_guard, type: :request do
Prosopite.pause do
ActsAsTenant.with_tenant(organisation) do
with_files = comment(0)
- file(with_files, 'screenshot.png', 'image/png', id: higher_id)
- file(with_files, 'bericht.pdf', 'application/pdf', id: lower_id)
+ file(with_files, 'bericht.pdf', 'application/pdf', id: higher_id)
+ file(with_files, 'screenshot.png', 'image/png', id: lower_id)
hidden = comment(1, is_private: true, visible_to_user: addressee)
file(hidden, 'geheim.txt', 'text/plain')
empty = comment(2)
@@ -108,8 +108,8 @@ RSpec.describe 'Comment files in the ticket view', :ci_guard, type: :request do
end
let(:both_files) do
- [{ 'id' => lower_id, 'filename' => 'bericht.pdf', 'content_type' => 'application/pdf', 'byte_size' => 6 },
- { 'id' => higher_id, 'filename' => 'screenshot.png', 'content_type' => 'image/png', 'byte_size' => 6 }]
+ [{ 'id' => lower_id, 'filename' => 'screenshot.png', 'content_type' => 'image/png', 'byte_size' => 6 },
+ { 'id' => higher_id, 'filename' => 'bericht.pdf', 'content_type' => 'application/pdf', 'byte_size' => 6 }]
end
describe 'on every road to a comment' do
@@ -171,7 +171,7 @@ RSpec.describe 'Comment files in the ticket view', :ci_guard, type: :request do
token = token_for(other)
get "#{ticket_path}/attachments", headers: { 'Authorization' => "Bearer #{token}" }
routed = response.parsed_body['data'].find { |entry| entry['filename'] == 'bericht.pdf' }
- expect(routed['id']).not_to eq(lower_id)
+ expect(routed['id']).not_to eq(higher_id)
sign_in other
proxy_get(routed['id'])
expect(response).to have_http_status(:not_found)
@@ -198,7 +198,7 @@ RSpec.describe 'Comment files in the ticket view', :ci_guard, type: :request do
# Each list is shown to be there, with the public files on it, so an absent
# name means the filter worked and not that the answer was empty.
context 'for a member who may not read the comment' do
- let(:public_names) { %w[bericht.pdf screenshot.png protokoll.txt] }
+ let(:public_names) { %w[screenshot.png bericht.pdf protokoll.txt] }
it 'is missing from the whole ticket' do
posts = get_json(other, ticket_path).dig('data', 'posts')
diff --git a/spec/services/tickets/serializer_spec.rb b/spec/services/tickets/serializer_spec.rb
index bfef5a1..5f9c549 100644
--- a/spec/services/tickets/serializer_spec.rb
+++ b/spec/services/tickets/serializer_spec.rb
@@ -179,6 +179,19 @@ RSpec.describe Tickets::Serializer do
expect(list.first[:text_status]).to eq('available')
end
+ # The row stays, what describes it is gone: left out of the list, as a comment's
+ # file is, and still counted, so the total says a file is there.
+ it 'drops a file that lost its blob and keeps counting it' do
+ list, total = ActsAsTenant.with_tenant(organisation) do
+ document = create(:ticket_document, ticket: ticket, organisation: organisation)
+ ActiveStorage::Attachment.where(record: document).delete_all
+ [serializer.attachments(ticket.reload), serializer.attachments_total(ticket)]
+ end
+
+ expect(list).to eq([])
+ expect(total).to eq(1)
+ end
+
# The difference the reader needs: "there is no text in this file" is an answer,
# "the text was never read out" is a defect on our side. Both look identical
# without the status, and the model would fill the silence either way.