From 4f020041467a88a4c81501ab6409b4b8d4938c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 20 Oct 2026 10:55:42 +0200 Subject: [PATCH] test(guards): derive the rounding guard's directories from the connection keys The guard kept its own provider list and its own comment stripper next to the shared PROVIDER_DIRS and stripComments helpers, so a new integration could slip past it. It now uses both, plus the file importers, which are not a connection. --- src/__tests__/provider-rounding-guard.test.ts | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/__tests__/provider-rounding-guard.test.ts b/src/__tests__/provider-rounding-guard.test.ts index 6c4b279c2..697af441e 100644 --- a/src/__tests__/provider-rounding-guard.test.ts +++ b/src/__tests__/provider-rounding-guard.test.ts @@ -14,22 +14,15 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; -import { walkSourceFiles } from "./helpers/source-files"; +import { PROVIDER_DIRS } from "./helpers/provider-dirs"; +import { stripComments, walkSourceFiles } from "./helpers/source-files"; const LIB = join(process.cwd(), "src", "lib"); -const PROVIDER_DIRS = [ - "apple-health", - "dawarich", - "fitbit", - "google-health", - "nightscout", - "oura", - "polar", - "strava", - "whoop", - "withings", - "import", -]; +/** + * Every provider the product connects to, plus the file importers (Health + * Connect, the export parsers), which are not a connection of their own. + */ +const ROUNDING_DIRS = [...PROVIDER_DIRS, "import"]; const ROUNDING = /\.toFixed\s*\(|\b(?:function|const|let)\s+round2\b|Math\.round\s*\([^;]*\*\s*(10+)\s*\)\s*\/\s*\1\b/; @@ -41,16 +34,10 @@ const ALLOWED: Record = { "Prints a compression ratio into an error message.", }; -function strip(text: string): string { - return text - .replace(/\/\*[\s\S]*?\*\//g, "") - .replace(/(^|[^:])\/\/.*$/gm, "$1"); -} - describe("provider clients round through importValue", () => { const files = walkSourceFiles(LIB, { floor: 1000 }).filter( (f) => - PROVIDER_DIRS.some((d) => f.startsWith(`${d}/`)) && + ROUNDING_DIRS.some((d) => f.startsWith(`${d}/`)) && !f.includes("__tests__") && !f.endsWith(".test.ts"), ); @@ -63,7 +50,7 @@ describe("provider clients round through importValue", () => { const offenders = files.filter( (f) => !(f in ALLOWED) && - ROUNDING.test(strip(readFileSync(join(LIB, f), "utf8"))), + ROUNDING.test(stripComments(readFileSync(join(LIB, f), "utf8"))), ); expect(offenders).toEqual([]); });