fix(mcp): over-long reason gets VALIDATION_ERROR and a specific Swedish message (#1811)

* fix(mcp): over-long reason gets VALIDATION_ERROR and a specific Swedish message

gnubok_reverse_journal_entry / gnubok_undo_sie_import cap `reason` at 500
characters, but exceeding it produced code UNKNOWN_ERROR with message_sv
"Något gick fel. Försök igen." while the cause sat only in message_en.
getStructuredError now infers VALIDATION_ERROR from the message and
getErrorMessage maps it to "Motiveringen får vara högst 500 tecken.".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(errors): pin the reason-length pattern to 500 and assert the envelope on undo_sie_import

Review findings: the Swedish message hard-codes 500, so the pattern must
match that limit only; the undo_sie_import 501-char test now asserts code
and both localized messages like the reverse test does.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Mattsson
2026-08-23 04:05:33 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent 158ef0f484
commit d35c401c0c
6 changed files with 62 additions and 7 deletions
@@ -35,6 +35,12 @@ describe('getStructuredError', () => {
expect(result.remediation?.tool).toBe('gnubok_lock_period')
})
it('maps an over-long reason to VALIDATION_ERROR with a specific Swedish message', () => {
const result = getStructuredError(new Error('reason must be 500 characters or fewer'))
expect(result.code).toBe('VALIDATION_ERROR')
expect(result.message_sv).toBe('Motiveringen får vara högst 500 tecken.')
})
it('infers PERIOD_HAS_UNBOOKED_TRANSACTIONS from Swedish lock-error message', () => {
const result = getStructuredError(
new Error('Kan inte låsa period: 3 affärstransaktion(er) saknar bokföring.')