From 0fb5afa4f18de4f7b860c11a23e3ff8070888117 Mon Sep 17 00:00:00 2001 From: Alex Schmitt Date: Tue, 18 Aug 2026 15:47:17 -0300 Subject: [PATCH] =?UTF-8?q?fix(canvas):=20fences=20indentados=20+=20erro?= =?UTF-8?q?=20vis=C3=ADvel=20quando=20a=20cria=C3=A7=C3=A3o=20falha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Regex de fences tolera até 3 espaços de indentação (CommonMark) e espaço antes da linguagem, cobrindo respostas do mistral indentadas - Falha de criação/atualização de canvas agora mostra toast com a causa em vez de falhar silenciosamente (resposta permanece íntegra) - Reprodução fiel da resposta flappy bird de 15:30 (fence html com template literals) em canvas-detector.flappy.test.ts — 4 testes --- components/chat/chat-page.tsx | 9 +- lib/canvas-detector.flappy.test.ts | 133 +++++++++++++++++++++++++++++ lib/canvas-detector.ts | 7 +- 3 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 lib/canvas-detector.flappy.test.ts diff --git a/components/chat/chat-page.tsx b/components/chat/chat-page.tsx index 7cbb016..49b2df6 100644 --- a/components/chat/chat-page.tsx +++ b/components/chat/chat-page.tsx @@ -1167,8 +1167,13 @@ export function ChatPage() { : message, ), ); - } catch { - // Canvas é best-effort: mantém o texto completo na bolha. + } catch (error) { + // Canvas é best-effort (a resposta permanece íntegra), mas o erro + // precisa ser visível para diagnóstico em produção. + console.error("[canvas] falha ao criar/atualizar canvas", error); + toast.error( + `Falha ao abrir o Canvas: ${error instanceof Error ? error.message : "erro desconhecido"}`, + ); } } diff --git a/lib/canvas-detector.flappy.test.ts b/lib/canvas-detector.flappy.test.ts new file mode 100644 index 0000000..40a5d2f --- /dev/null +++ b/lib/canvas-detector.flappy.test.ts @@ -0,0 +1,133 @@ +import { describe, expect, it } from "vitest"; +import { buildDisplayText, detectCanvas } from "./canvas-detector"; + +// Reprodução fiel da resposta real de 15:30 (mistral/ministral-8b): +// fence ```html GRANDE contendo template literals com backticks no meio das +// linhas (`${birdY}px`), CSS com #ids e estrutura HTML completa. +const flappyHtml = [ + "", + '', + "", + ' ', + " ", + "", + "", + '
', + '
Pontuação: 0
', + ' ', + '
', + "
", + "