From 4d4744ccf11d1cbb2d5a72df07e34fdc34a5b7fc Mon Sep 17 00:00:00 2001 From: Rhuan Barreto Date: Thu, 19 Mar 2026 01:04:00 +0100 Subject: [PATCH] fix: address valid AI code quality findings - install.sh: replace `head -c` with POSIX-compliant `cut -c1-200` - tests/commands/plugin/index.test.ts: extract duplicated setup into helper - tests/helpers/binary-upgrade.test.ts: assert non-null instead of silent return --- install.sh | 2 +- tests/commands/plugin/index.test.ts | 27 +++++++++++++-------------- tests/helpers/binary-upgrade.test.ts | 6 +++--- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index d9993da1..80be1f9f 100644 --- a/install.sh +++ b/install.sh @@ -70,7 +70,7 @@ resolve_version() { ;; *) echo "Error: unexpected response from GitHub releases API." >&2 - echo "Response (truncated): $(printf '%s' "$response" | head -c 200)" >&2 + echo "Response (truncated): $(printf '%s' "$response" | cut -c1-200)" >&2 exit 1 ;; esac diff --git a/tests/commands/plugin/index.test.ts b/tests/commands/plugin/index.test.ts index ade86384..737fc688 100644 --- a/tests/commands/plugin/index.test.ts +++ b/tests/commands/plugin/index.test.ts @@ -4,32 +4,31 @@ import { Command } from "@commander-js/extra-typings"; import { registerPluginCommand } from "../../../src/commands/plugin/index"; +const createProgramAndPlugin = () => { + const program = new Command(); + registerPluginCommand(program); + const plugin = program.commands.find((c) => c.name() === "plugin")!; + return { program, plugin }; +}; + describe("registerPluginCommand", () => { test("registers 'plugin' as a subcommand", () => { - const program = new Command(); - registerPluginCommand(program); - const sub = program.commands.find((c) => c.name() === "plugin"); - expect(sub).toBeDefined(); + const { plugin } = createProgramAndPlugin(); + expect(plugin).toBeDefined(); }); test("has a description", () => { - const program = new Command(); - registerPluginCommand(program); - const sub = program.commands.find((c) => c.name() === "plugin")!; - expect(sub.description()).toBeTruthy(); + const { plugin } = createProgramAndPlugin(); + expect(plugin.description()).toBeTruthy(); }); test("registers 'url' subcommand", () => { - const program = new Command(); - registerPluginCommand(program); - const plugin = program.commands.find((c) => c.name() === "plugin")!; + const { plugin } = createProgramAndPlugin(); expect(plugin.commands.find((c) => c.name() === "url")).toBeDefined(); }); test("registers 'install' subcommand", () => { - const program = new Command(); - registerPluginCommand(program); - const plugin = program.commands.find((c) => c.name() === "plugin")!; + const { plugin } = createProgramAndPlugin(); expect(plugin.commands.find((c) => c.name() === "install")).toBeDefined(); }); }); diff --git a/tests/helpers/binary-upgrade.test.ts b/tests/helpers/binary-upgrade.test.ts index 88bf2948..68c81d6c 100644 --- a/tests/helpers/binary-upgrade.test.ts +++ b/tests/helpers/binary-upgrade.test.ts @@ -29,9 +29,9 @@ describe("getArtifactInfo", () => { test("returns .tar.gz extension for non-win32", () => { const info = getArtifactInfo(); if (process.platform === "win32") return; - if (info === null) return; - expect(info.ext).toBe(".tar.gz"); - expect(info.binaryName).toBe("archgate"); + expect(info).not.toBeNull(); + expect(info!.ext).toBe(".tar.gz"); + expect(info!.binaryName).toBe("archgate"); }); });