From abec79abe8e35acee04663d1a661d115474183af Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Sat, 8 Aug 2026 13:00:42 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20address=20CodeRabbit=20review=20?= =?UTF-8?q?=E2=80=94=20typed=20mocks,=20robust=20benchmark=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace `as any` casts in integration-test-connection.spec.ts with Pick + mockResolvedValue - build-compare.sh: split local declarations (SC2318), clean .next between builds with --force, add EXIT trap for safe stash/cleanup --- .../integration-test-connection.spec.ts | 40 +++++-------------- scripts/benchmarks/build-compare.sh | 27 +++++++++++-- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/packages/api/src/router/test/integration/integration-test-connection.spec.ts b/packages/api/src/router/test/integration/integration-test-connection.spec.ts index 14670b2b7..c9fc7b9ea 100644 --- a/packages/api/src/router/test/integration/integration-test-connection.spec.ts +++ b/packages/api/src/router/test/integration/integration-test-connection.spec.ts @@ -1,10 +1,15 @@ import { describe, expect, test, vi } from "vitest"; import * as homarrDefinitions from "@homarr/definitions"; +import type { Integration } from "@homarr/integrations"; import * as homarrIntegrations from "@homarr/integrations"; import { testConnectionAsync } from "../../integration/integration-test-connection"; +const mockIntegration = (): Pick => ({ + testConnectionAsync: async () => ({ success: true }), +}); + vi.mock("@homarr/common/server", async (importActual) => { // eslint-disable-next-line @typescript-eslint/consistent-type-imports const actual = await importActual(); @@ -20,12 +25,7 @@ describe("testConnectionAsync should run test connection of integration", () => // Arrange const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync"); const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions"); - factorySpy.mockReturnValue( - Promise.resolve({ - testConnectionAsync: async () => await Promise.resolve({ success: true }), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any), - ); + factorySpy.mockResolvedValue(mockIntegration() as Awaited>); optionsSpy.mockReturnValue([["apiKey"]]); const integration = { @@ -64,12 +64,7 @@ describe("testConnectionAsync should run test connection of integration", () => // Arrange const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync"); const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions"); - factorySpy.mockReturnValue( - Promise.resolve({ - testConnectionAsync: async () => await Promise.resolve({ success: true }), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any), - ); + factorySpy.mockResolvedValue(mockIntegration() as Awaited>); optionsSpy.mockReturnValue([["apiKey"]]); const integration = { @@ -115,12 +110,7 @@ describe("testConnectionAsync should run test connection of integration", () => // Arrange const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync"); const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions"); - factorySpy.mockReturnValue( - Promise.resolve({ - testConnectionAsync: async () => await Promise.resolve({ success: true }), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any), - ); + factorySpy.mockResolvedValue(mockIntegration() as Awaited>); optionsSpy.mockReturnValue([["apiKey"]]); const integration = { @@ -166,12 +156,7 @@ describe("testConnectionAsync should run test connection of integration", () => // Arrange const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync"); const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions"); - factorySpy.mockReturnValue( - Promise.resolve({ - testConnectionAsync: async () => await Promise.resolve({ success: true }), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any), - ); + factorySpy.mockResolvedValue(mockIntegration() as Awaited>); optionsSpy.mockReturnValue([["username", "password"], ["apiKey"]]); const integration = { @@ -221,12 +206,7 @@ describe("testConnectionAsync should run test connection of integration", () => // Arrange const factorySpy = vi.spyOn(homarrIntegrations, "createIntegrationAsync"); const optionsSpy = vi.spyOn(homarrDefinitions, "getAllSecretKindOptions"); - factorySpy.mockReturnValue( - Promise.resolve({ - testConnectionAsync: async () => await Promise.resolve({ success: true }), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any), - ); + factorySpy.mockResolvedValue(mockIntegration() as Awaited>); optionsSpy.mockReturnValue([["username", "password"], ["apiKey"]]); const integration = { diff --git a/scripts/benchmarks/build-compare.sh b/scripts/benchmarks/build-compare.sh index eb7f76da2..06df1f165 100755 --- a/scripts/benchmarks/build-compare.sh +++ b/scripts/benchmarks/build-compare.sh @@ -7,18 +7,30 @@ REPO_ROOT="$(git rev-parse --show-toplevel)" CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" NEXT_DIR="$REPO_ROOT/apps/nextjs" OUT_DIR="$REPO_ROOT/.bench" +STASH_CREATED=false mkdir -p "$OUT_DIR" +cleanup() { + git checkout "$CURRENT_BRANCH" -q 2>/dev/null || true + if $STASH_CREATED; then + git stash pop -q 2>/dev/null || true + fi +} +trap cleanup EXIT + capture_metrics() { - local label="$1" out="$OUT_DIR/$label" + local label="$1" + local out="$OUT_DIR/$label" mkdir -p "$out" echo "=== Building $label ===" cd "$REPO_ROOT" + rm -rf "$NEXT_DIR/.next" + local start_ns start_ns=$(date +%s) - pnpm turbo build --filter=@homarr/nextjs 2>&1 | tee "$out/build.log" + pnpm turbo build --force --filter=@homarr/nextjs 2>&1 | tee "$out/build.log" local end_ns end_ns=$(date +%s) echo $((end_ns - start_ns)) > "$out/build_time_s" @@ -47,7 +59,11 @@ capture_metrics() { } echo "Stashing uncommitted changes..." -git stash --include-untracked -q 2>/dev/null || true +if git stash --include-untracked -q 2>/dev/null; then + if [ "$(git stash list | wc -l)" -gt 0 ]; then + STASH_CREATED=true + fi +fi echo "" echo "=== Phase 1: Build origin/dev ===" @@ -57,7 +73,10 @@ capture_metrics "dev" echo "" echo "=== Phase 2: Build $CURRENT_BRANCH ===" git checkout "$CURRENT_BRANCH" -q -git stash pop -q 2>/dev/null || true +if $STASH_CREATED; then + git stash pop -q 2>/dev/null || true + STASH_CREATED=false +fi capture_metrics "branch" echo ""