Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.9 KB
Raw Blame
/**
 * #5103 — Two startup log lines in the SQLite driver-fallback path were written in
 * pt-BR ("Pré-inicializando sql.js…", "Drivers síncronos indisponíveis…"), mixing
 * languages in the server logs. All user-facing server log strings must be English.
 *
 * Guard: scan the DB driver-fallback files for `console.*("…")` string literals that
 * contain Latin accented characters (the tell-tale of a non-English log line). This
 * fails on the pt-BR strings and stays green once they're translated, preventing
 * regressions in this path.
 */
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const here = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(here, "../..");

const DB_DRIVER_FILES = [
  "src/lib/db/core.ts",
  "src/lib/db/adapters/driverFactory.ts",
];

// Latin-1 Supplement accented letters used by pt-BR/es/etc. (á à â ã é ê í ó ô õ ú ç …).
const ACCENTED = /[À-ÿ]/;
// Match the string argument(s) of a console.{warn,error,log,info} call (single line).
const CONSOLE_CALL = /console\.(?:warn|error|log|info)\s*\(([^\n]*)\)/g;

test("#5103 DB driver-fallback log strings contain no non-English (accented) text", () => {
  const offenders: string[] = [];

  for (const rel of DB_DRIVER_FILES) {
    const abs = path.join(repoRoot, rel);
    const src = fs.readFileSync(abs, "utf8");
    const lines = src.split("\n");

    lines.forEach((line, i) => {
      let m: RegExpExecArray | null;
      CONSOLE_CALL.lastIndex = 0;
      while ((m = CONSOLE_CALL.exec(line)) !== null) {
        if (ACCENTED.test(m[1])) {
          offenders.push(`${rel}:${i + 1}  ${line.trim()}`);
        }
      }
    });
  }

  assert.deepEqual(
    offenders,
    [],
    `Non-English (accented) console log strings found in the DB driver path:\n${offenders.join("\n")}`
  );
});