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
test: review round 1 of #81, pin the MCP check order and a binary body
Guido Boyke16715caa0c3c
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1ddd480..1466775 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -795,9 +795,10 @@ feature by feature):`spec/architecture/api_v1_error_body_guard_spec.rb`. Answers outside the controllers carryno `code`: the Rack::Attack 429 (plain text), a 500 from the exceptions app, a 400 for aquery string Rack cannot decode (`?x=%`; raised in middleware before any controller), and a- 400 for a body parameter that is no valid UTF-8, form or JSON (Rails raises+ 400 for a body parameter of raw bytes that are no valid UTF-8, form or JSON (Rails raises`ActionController::BadRequest` when it first reads the parameters, in its params wrapper or- its request log, before any callback or `rescue_from` of `BaseController` runs). The 401 of `/api/mcp` (same concern,+ its request log, before any callback or `rescue_from` of `BaseController` runs; a JSON escape+ of a lone surrogate is a parse error instead, answered as 400 `bad_request` with `code`). The 401 of `/api/mcp` (same concern,`render_unauthorized`) keeps its old body.* **`Idempotency-Key`** on every write (`idempotent :create` in the controller,`Api::V1::Idempotent`): the same key and request replays the first 2xx answer (status and@@ -839,7 +840,7 @@ back to html), NUL in a plain body and a plain body that converts to nothing ans`validation_failed`/`invalid_input` with a text from `services.post_comment.*`, checked insidethe read gate. Without `format` the answer stays byte for byte: an empty body is the model'srefusal, after the write check, with every model message (the contract case `html_empty` was-recorded before R3a). Invalid UTF-8 never reaches the rule over REST (the 400 above); MCP+recorded before R3a), and a JSON `false` as body counts as none, as before. Invalid UTF-8 never reaches the rule over REST (the 400 above); MCPrefuses it. An unexpected actor failure (`internal_error`) answers 500 without the exception'stext, every other failure 422 `validation_failed` as before; MCP answers `comment failed:unexpected error`. Capability `posts.plain`. Guards:diff --git a/spec/services/lalabase/tools/post_comment_failure_spec.rb b/spec/services/lalabase/tools/post_comment_failure_spec.rbindex 14c88de..9eaf931 100644--- a/spec/services/lalabase/tools/post_comment_failure_spec.rb+++ b/spec/services/lalabase/tools/post_comment_failure_spec.rb@@ -2,12 +2,15 @@require 'rails_helper'-# What: how post_comment words a save that failed (REST R3a). Beside-# post_comment_spec.rb, which stays as it was: every answer it pins is-# the tool's answer before the rule moved into Posts::Comment.-# Why: BaseActor answers an unexpected exception as :internal_error with the-# exception's text where it does not re-raise (production). That text may-# name the database and reached the client through "comment failed: ...".+# What: what post_comment_spec.rb does not pin (REST R3a), beside it, so that+# file stays as it was: every answer it pins is the tool's answer before+# the rule moved into Posts::Comment. Here: the rule answers before the+# ticket is looked up, and how a failed save is worded.+# Why: The tool always refused unusable input before its lookup, so a missing+# or hidden ticket with broken input answers invalid_input, not "No ticket+# found". BaseActor answers an unexpected exception as :internal_error with+# the exception's text where it does not re-raise (production); that text+# may name the database and reached the client through "comment failed: ...".RSpec.describe Lalabase::Tools::PostComment, :ci_guard dolet(:organisation) { create(:organisation) }let(:user) { create(:user) }@@ -35,6 +38,27 @@ RSpec.describe Lalabase::Tools::PostComment, :ci_guard do.and_return(Actors::BaseActor::Result.new(success: false, errors: errors, code: code))end+ describe 'before the ticket lookup' do+ it 'refuses an unknown format for a missing ticket' do+ result = execute(ticket_id: SecureRandom.uuid, format: 'markdown')+ expect(result.error_code).to eq(:invalid_input)+ expect(result.error).to eq('format must be html or plain')+ end++ it 'refuses an empty body for a missing ticket' do+ result = execute(ticket_id: SecureRandom.uuid, body: ' ')+ expect(result.error_code).to eq(:invalid_input)+ expect(result.error).to eq('body is required')+ end++ it 'refuses a NUL byte for a ticket the caller may not read' do+ ProjectPermission.find_by!(user: user, project: project).update!(tickets_access: :no_access)+ result = execute(body: "a#{0.chr}b")+ expect(result.error_code).to eq(:invalid_input)+ expect(result.error).to eq('body must not contain NUL bytes')+ end+ end+it 'answers an unexpected failure with a fixed text, never the exception text' dofailing_save(:internal_error, ['PG::ConnectionBad: could not connect to server at 192.168.0.1'])result = executediff --git a/spec/services/posts/comment_spec.rb b/spec/services/posts/comment_spec.rbindex f4e77cb..2481821 100644--- a/spec/services/posts/comment_spec.rb+++ b/spec/services/posts/comment_spec.rb@@ -50,6 +50,8 @@ RSpec.describe Posts::Comment, :ci_guard do'an empty format' => [{ format: '' }, :format_unknown],'invalid UTF-8 in an html body' => [{ body: -> { invalid_utf8 } }, :body_invalid_utf8],'invalid UTF-8 in a plain body' => [{ format: 'plain', body: -> { invalid_utf8 } }, :body_invalid_utf8],+ # A binary string is always valid_encoding?: the rule reads it as UTF-8.+ 'invalid bytes in a binary body' => [{ format: 'plain', body: -> { "a#{255.chr}b".b } }, :body_invalid_utf8],'a NUL byte in a plain body' => [{ format: 'plain', body: "a#{0.chr}b" }, :body_nul],'an empty plain body' => [{ format: 'plain', body: '' }, :body_empty],'a plain body of blank lines' => [{ format: 'plain', body: " \n\t\r\n " }, :body_empty],