From ecb1e398741eed246eb802c3c0259e99c13d591c Mon Sep 17 00:00:00 2001 From: merge-check <140916359+agentHits@users.noreply.github.com> Date: Tue, 6 Oct 2026 15:58:36 -0400 Subject: [PATCH] test: reuse the shared sql helper in backup listing tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Что: - Тест listBackupFiles в __test__/backup/restore-security.test.ts теперь берёт POSTGRES_MAX_FUNCTION_ARGS, maxJsonBuildArrayArgs и relationalQueryDb из общего __test__/helpers/postgres-function-args.ts. Локальная копия счётчика и создание drizzle.mock в тесте удалены. Зачем: - Счётчик аргументов json_build_array был в двух копиях: в этом тесте и в общем хелпере. Общий заодно пропускает строки в одинарных кавычках. Риски: - Не выявлены, меняется только тест. Проверки: - Команды и результаты: CI=true bunx vitest run --config __test__/vitest.config.ts __test__/backup/restore-security.test.ts - 40 тестов прошли; если в роутере временно вернуть application: true, тест падает с "expected 101 to be less than or equal to 100" (роутер возвращён). bun run typecheck - 4/4 без ошибок. bunx biome check для изменённого файла - 0 ошибок. - Ограничения: не выявлены. What: - The listBackupFiles test in __test__/backup/restore-security.test.ts now takes POSTGRES_MAX_FUNCTION_ARGS, maxJsonBuildArrayArgs and relationalQueryDb from the shared __test__/helpers/postgres-function-args.ts. The local counter copy and the drizzle.mock setup in the test are removed. Why: - The json_build_array argument counter existed twice: in this test and in the shared helper. The shared one also skips single-quoted strings. Risks: - None identified; only the test changes. Checks: - Commands and results: CI=true bunx vitest run --config __test__/vitest.config.ts __test__/backup/restore-security.test.ts - 40 tests passed; with application: true temporarily restored in the router, the test fails with "expected 101 to be less than or equal to 100" (the router was put back). bun run typecheck - 4/4 clean. bunx biome check on the changed file - 0 errors. - Limitations: none identified. Co-Authored-By: Claude Opus 5.5 --- .../__test__/backup/restore-security.test.ts | 46 +++---------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/apps/dokploy/__test__/backup/restore-security.test.ts b/apps/dokploy/__test__/backup/restore-security.test.ts index 3fca4240a11..9a4bcfa680a 100644 --- a/apps/dokploy/__test__/backup/restore-security.test.ts +++ b/apps/dokploy/__test__/backup/restore-security.test.ts @@ -1,8 +1,11 @@ -import * as schema from "@dokploy/server/db/schema"; import { TRPCError } from "@trpc/server"; -import { drizzle } from "drizzle-orm/postgres-js"; import { parse } from "shell-quote"; import { beforeEach, describe, expect, it, vi } from "vitest"; +import { + maxJsonBuildArrayArgs, + POSTGRES_MAX_FUNCTION_ARGS, + relationalQueryDb, +} from "../helpers/postgres-function-args"; const mocks = vi.hoisted(() => ({ checkPermission: vi.fn(), @@ -326,40 +329,6 @@ const emit = (log: string) => emittedLogs.push(log); const parseShellArgs = (command: string) => parse(command).filter((part): part is string => typeof part === "string"); -const POSTGRES_MAX_FUNCTION_ARGS = 100; - -const maxJsonBuildArrayArgs = (sqlText: string) => { - let max = 0; - for (const match of sqlText.matchAll(/json_build_array\(/g)) { - let depth = 1; - let args = 1; - let inIdentifier = false; - for ( - let index = match.index + match[0].length; - index < sqlText.length && depth > 0; - index++ - ) { - const char = sqlText[index]; - if (char === '"') { - inIdentifier = !inIdentifier; - continue; - } - if (inIdentifier) { - continue; - } - if (char === "(") { - depth++; - } else if (char === ")") { - depth--; - } else if (char === "," && depth === 1) { - args++; - } - } - max = Math.max(max, args); - } - return max; -}; - describe("backup destination ownership boundary", () => { beforeEach(() => { vi.clearAllMocks(); @@ -821,11 +790,10 @@ describe("backup restore route boundary", () => { }); it("keeps backup file listing queries within the Postgres function argument limit", async () => { - const relationalDb = drizzle.mock({ schema }); const compiledQueries: string[] = []; mocks.findRestoreBackups.mockImplementation(async (config) => { compiledQueries.push( - relationalDb.query.backups.findMany(config).toSQL().sql, + relationalQueryDb.query.backups.findMany(config).toSQL().sql, ); return [ { @@ -841,7 +809,7 @@ describe("backup restore route boundary", () => { }); mocks.findVolumeBackupSchedules.mockImplementation(async (config) => { compiledQueries.push( - relationalDb.query.volumeBackups.findMany(config).toSQL().sql, + relationalQueryDb.query.volumeBackups.findMany(config).toSQL().sql, ); return [ {