From c217d9568237c10bfb855003dbbd56c80a715f1f Mon Sep 17 00:00:00 2001 From: Marcos Gabriel Moraes Date: Tue, 3 Nov 2026 07:45:08 -0400 Subject: [PATCH] fix(ci): torna o guard de atalho de teclado independente de CRLF O job windows-latest falhava em 'AI SQL runs only from one click handler'. O teste recortava o corpo de onKeyDown procurando a string literal '\n }\n', que nunca casa com checkout CRLF (core.autocrlf=true no runner). O indexOf retornava -1, o slice(keyStart, -1) devolvia o resto do arquivo e o assert encontrava o runApproved() de outro trecho. - read() normaliza CRLF para LF antes das guardas de texto-fonte - a extracao do handler valida o delimitador em vez de fatiar ate o EOF - .gitattributes fixa eol=lf, deixando Linux e Windows com a mesma arvore Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .gitattributes | 16 ++++++++++++++++ scripts/ai-safety.test.mjs | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dcfb3ad --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +# Keep line endings deterministic across Linux and Windows checkouts (CI parity). +* text=auto eol=lf + +# Binaries must never be normalised. +*.ico binary +*.jpg binary +*.jpeg binary +*.png binary +*.gif binary +*.webp binary +*.zip binary + +# Windows tooling that expects CRLF. +*.bat text eol=crlf +*.cmd text eol=crlf +*.ps1 text eol=crlf diff --git a/scripts/ai-safety.test.mjs b/scripts/ai-safety.test.mjs index d8ee5e6..be97227 100644 --- a/scripts/ai-safety.test.mjs +++ b/scripts/ai-safety.test.mjs @@ -25,7 +25,11 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') -const read = async (relative) => fs.readFile(path.join(projectRoot, relative), 'utf8') + +// Checkouts on Windows (core.autocrlf=true) deliver CRLF. Normalising here keeps +// the source-text guards below independent of the platform and of git settings. +const read = async (relative) => + (await fs.readFile(path.join(projectRoot, relative), 'utf8')).replace(/\r\n/g, '\n') // The aliases are registered by --import (scripts/lib/ts-alias-register.mjs), // so the production modules below load with their real '@shared/*' imports. @@ -599,7 +603,9 @@ check('AI SQL runs only from one click handler in the panel (no effect/shortcut) // Keyboard input sends messages only — it never runs SQL. const keyStart = panel.indexOf('function onKeyDown(') assert.ok(keyStart > 0, 'the panel still has a keydown handler') - const keyHandler = panel.slice(keyStart, panel.indexOf('\n }\n', keyStart)) + const keyEnd = panel.indexOf('\n }\n', keyStart) + assert.ok(keyEnd > keyStart, 'the keydown handler body is delimited') + const keyHandler = panel.slice(keyStart, keyEnd) assert.ok(keyHandler.length > 0, 'keydown handler body is readable') assert.ok(!/runApproved\(|onRun\(/.test(keyHandler), 'no keyboard shortcut runs AI SQL')