From 6d011a3d71cbbacb0c375217cfceceb3b7d16b53 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 02:51:24 +0000 Subject: [PATCH] Hook de dados operacionais trata caminhos C: com path.win32 em qualquer SO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No Linux, path.resolve("C:/repo/...") vira um caminho relativo ao cwd e barras invertidas não são separadores, então o caso de worktree do Windows falhava fora do Windows (a CI só roda os testes JS em windows-latest). O hook passa a usar path.win32 quando a raiz tem letra de unidade, e o teste monta os exemplos com path.win32 para ser o mesmo em todo SO. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Etk6cBbrVUxRVmptbMu3pM --- .claude/hooks/protect-operational-data.cjs | 14 +++++++++++--- .../test_protect_operational_data_hook.cjs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.claude/hooks/protect-operational-data.cjs b/.claude/hooks/protect-operational-data.cjs index 1a28103ee..6180f3e50 100644 --- a/.claude/hooks/protect-operational-data.cjs +++ b/.claude/hooks/protect-operational-data.cjs @@ -4,7 +4,12 @@ // Saída 2 bloqueia a ferramenta e devolve a mensagem de stderr ao agente. "use strict"; -const path = require("node:path"); +const nodePath = require("node:path"); + +// Caminho com letra de unidade (C:) segue as regras do Windows (separadores e maiúsculas) em qualquer SO. +function pathFor(value) { + return /^[a-zA-Z]:/.test(String(value)) ? nodePath.win32 : nodePath; +} const SPREADSHEET_EXTENSIONS = new Set([".xlsx", ".xls", ".xlsm", ".csv", ".tsv", ".zip"]); const ALLOWED_STATE_FILES = new Set([".gitkeep", "readme.md"]); @@ -16,7 +21,9 @@ function fromPosixDrive(value) { } function relativeToProject(filePath, projectDir) { + const path = pathFor(fromPosixDrive(projectDir)); const root = path.resolve(fromPosixDrive(projectDir)); + // Unidades do Windows não diferenciam maiúsculas; path.win32.relative já compara assim em qualquer SO. const relative = path.relative(root, path.resolve(root, fromPosixDrive(filePath))); if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) return null; return relative.split(path.sep).join("/").toLowerCase(); @@ -24,13 +31,14 @@ function relativeToProject(filePath, projectDir) { // Em worktree (/.claude/worktrees/), devolve a raiz do checkout principal. function mainCheckoutRoot(projectDir) { + const path = pathFor(fromPosixDrive(projectDir)); const root = path.resolve(fromPosixDrive(projectDir)); const match = root.split(path.sep).join("/").match(/^(.*?)\/\.claude\/worktrees\/[^/]+(?:\/|$)/i); return match ? path.resolve(match[1]) : null; } function reasonForRelative(relative) { - const name = path.posix.basename(relative); + const name = nodePath.posix.basename(relative); if (relative.startsWith("data/state/")) { return ALLOWED_STATE_FILES.has(name) ? null : "históricos, anotações e filas em data/state"; } @@ -38,7 +46,7 @@ function reasonForRelative(relative) { for (const root of ["data/planilhas_entrada/", "planilhas_entrada/"]) { if (!relative.startsWith(root)) continue; if (relative.startsWith(`${root}_backups/`)) return "backups de planilhas"; - if (SPREADSHEET_EXTENSIONS.has(path.posix.extname(relative))) return "planilhas operacionais"; + if (SPREADSHEET_EXTENSIONS.has(nodePath.posix.extname(relative))) return "planilhas operacionais"; } return null; } diff --git a/tests/frontend/test_protect_operational_data_hook.cjs b/tests/frontend/test_protect_operational_data_hook.cjs index 2add53b11..822cf84a9 100644 --- a/tests/frontend/test_protect_operational_data_hook.cjs +++ b/tests/frontend/test_protect_operational_data_hook.cjs @@ -1,7 +1,7 @@ "use strict"; const test = require("node:test"); const assert = require("node:assert/strict"); -const path = require("node:path"); +const path = require("node:path").win32; // fixtures do Windows em qualquer SO const { blockReason } = require("../../.claude/hooks/protect-operational-data.cjs");