From d02e298488ed69922b4fcf119a6cc7a65bdbd60b Mon Sep 17 00:00:00 2001 From: A <258483684+la14-1@users.noreply.github.com> Date: Fri, 27 Feb 2026 02:18:03 -0800 Subject: [PATCH] test: Remove duplicate and theatrical tests (#1986) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: Remove duplicate and theatrical tests - cmd-listing-output: Fix always-pass guard (if (localLine) → expect defined then check) - with-retry-result: Replace conditional if (!r.ok) expects with toMatchObject - run-path-credential-display: Remove 96 lines of duplicate tests - parseAuthEnvVars for credential status (duplicate of commands-exported-utils.test.ts) - credential function edge cases with weak OR assertions (duplicate of credential-hints.test.ts) - Migrated 2 unique edge cases (whitespace trimming, empty separator) to commands-exported-utils.test.ts Co-Authored-By: Claude Sonnet 4.6 * fix: apply biome format to test files in qa/dedup-scanner Agent: team-lead Co-Authored-By: Claude Sonnet 4.5 --------- Co-authored-by: spawn-qa-bot Co-authored-by: Claude Sonnet 4.6 Co-authored-by: B <6723574+louisgv@users.noreply.github.com> --- .../src/__tests__/cmd-listing-output.test.ts | 5 +- .../__tests__/commands-exported-utils.test.ts | 13 +++ .../run-path-credential-display.test.ts | 97 ------------------- .../src/__tests__/with-retry-result.test.ts | 28 ++++-- 4 files changed, 33 insertions(+), 110 deletions(-) diff --git a/packages/cli/src/__tests__/cmd-listing-output.test.ts b/packages/cli/src/__tests__/cmd-listing-output.test.ts index a1026e7d..91659e71 100644 --- a/packages/cli/src/__tests__/cmd-listing-output.test.ts +++ b/packages/cli/src/__tests__/cmd-listing-output.test.ts @@ -744,9 +744,8 @@ describe("cmdClouds output", () => { // Find lines containing "Local Machine" and check they don't have auth: none const lines = output.split("\n"); const localLine = lines.find((l) => l.includes("Local Machine")); - if (localLine) { - expect(localLine).not.toContain("auth:"); - } + expect(localLine).toBeDefined(); + expect(localLine).not.toContain("auth:"); }); }); diff --git a/packages/cli/src/__tests__/commands-exported-utils.test.ts b/packages/cli/src/__tests__/commands-exported-utils.test.ts index 7065800f..573b217c 100644 --- a/packages/cli/src/__tests__/commands-exported-utils.test.ts +++ b/packages/cli/src/__tests__/commands-exported-utils.test.ts @@ -168,6 +168,19 @@ describe("parseAuthEnvVars", () => { it("should handle string with multiple + and no valid vars", () => { expect(parseAuthEnvVars("a + b + c")).toEqual([]); }); + + it("should handle extra whitespace around a single var", () => { + expect(parseAuthEnvVars(" HCLOUD_TOKEN ")).toEqual([ + "HCLOUD_TOKEN", + ]); + }); + + it("should handle empty token between + separators", () => { + expect(parseAuthEnvVars("VAR_A + + VAR_B")).toEqual([ + "VAR_A", + "VAR_B", + ]); + }); }); }); diff --git a/packages/cli/src/__tests__/run-path-credential-display.test.ts b/packages/cli/src/__tests__/run-path-credential-display.test.ts index 47cdc512..b5579988 100644 --- a/packages/cli/src/__tests__/run-path-credential-display.test.ts +++ b/packages/cli/src/__tests__/run-path-credential-display.test.ts @@ -153,8 +153,6 @@ mock.module("@clack/prompts", () => ({ // Import after mocks are set up const { prioritizeCloudsByCredentials, - parseAuthEnvVars, - credentialHints, getImplementedClouds, getImplementedAgents, checkEntity, @@ -387,56 +385,6 @@ describe("prioritizeCloudsByCredentials", () => { }); }); -// ── buildCredentialStatusLines (tested via dry-run behavior) ───────────── - -describe("credential status display logic", () => { - const savedEnv: Record = {}; - - beforeEach(() => { - for (const v of [ - "OPENROUTER_API_KEY", - "HCLOUD_TOKEN", - "DO_API_TOKEN", - ]) { - savedEnv[v] = process.env[v]; - delete process.env[v]; - } - }); - - afterEach(() => { - for (const [k, v] of Object.entries(savedEnv)) { - if (v === undefined) { - delete process.env[k]; - } else { - process.env[k] = v; - } - } - }); - - describe("parseAuthEnvVars for credential status", () => { - it("should extract single env var", () => { - expect(parseAuthEnvVars("HCLOUD_TOKEN")).toEqual([ - "HCLOUD_TOKEN", - ]); - }); - - it("should extract multiple env vars", () => { - expect(parseAuthEnvVars("UPCLOUD_USERNAME + UPCLOUD_PASSWORD")).toEqual([ - "UPCLOUD_USERNAME", - "UPCLOUD_PASSWORD", - ]); - }); - - it("should return empty for CLI-based auth", () => { - expect(parseAuthEnvVars("sprite login")).toEqual([]); - }); - - it("should return empty for 'none'", () => { - expect(parseAuthEnvVars("none")).toEqual([]); - }); - }); -}); - // ── validateRunSecurity via checkEntity ────────────────────────────────── describe("entity validation for run path", () => { @@ -690,48 +638,3 @@ describe("prioritizeCloudsByCredentials with real-world patterns", () => { expect(result.hintOverrides["digitalocean"]).toBeUndefined(); }); }); - -// ── Edge cases for credential-related functions ───────────────────────── - -describe("credential function edge cases", () => { - const savedEnv: Record = {}; - - beforeEach(() => { - savedEnv.OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY; - delete process.env.OPENROUTER_API_KEY; - }); - - afterEach(() => { - if (savedEnv.OPENROUTER_API_KEY === undefined) { - delete process.env.OPENROUTER_API_KEY; - } else { - process.env.OPENROUTER_API_KEY = savedEnv.OPENROUTER_API_KEY; - } - }); - - it("credentialHints should always mention OPENROUTER_API_KEY when missing", () => { - const hints = credentialHints("hetzner", "HCLOUD_TOKEN"); - expect(hints.some((h: string) => h.includes("OPENROUTER_API_KEY") || h.includes("Missing"))).toBe(true); - }); - - it("credentialHints should not flag OPENROUTER_API_KEY when set", () => { - process.env.OPENROUTER_API_KEY = "key"; - process.env.HCLOUD_TOKEN = "token"; - const hints = credentialHints("hetzner", "HCLOUD_TOKEN"); - // When all are set, should show "appear to be set" message - expect(hints.some((h: string) => h.includes("set") || h.includes("appear"))).toBe(true); - }); - - it("parseAuthEnvVars should handle extra whitespace", () => { - expect(parseAuthEnvVars(" HCLOUD_TOKEN ")).toEqual([ - "HCLOUD_TOKEN", - ]); - }); - - it("parseAuthEnvVars should handle empty + separator", () => { - expect(parseAuthEnvVars("VAR_A + + VAR_B")).toEqual([ - "VAR_A", - "VAR_B", - ]); - }); -}); diff --git a/packages/cli/src/__tests__/with-retry-result.test.ts b/packages/cli/src/__tests__/with-retry-result.test.ts index 28ee4d12..8f726843 100644 --- a/packages/cli/src/__tests__/with-retry-result.test.ts +++ b/packages/cli/src/__tests__/with-retry-result.test.ts @@ -25,10 +25,12 @@ describe("Result constructors", () => { it("Err creates a failure result", () => { const r = Err(new Error("boom")); - expect(r.ok).toBe(false); - if (!r.ok) { - expect(r.error.message).toBe("boom"); - } + expect(r).toMatchObject({ + ok: false, + error: { + message: "boom", + }, + }); }); }); @@ -124,10 +126,12 @@ describe("wrapSshCall", () => { it("returns Err for transient SSH error (retryable)", async () => { const result = await wrapSshCall(Promise.reject(new Error("connection reset"))); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error.message).toBe("connection reset"); - } + expect(result).toMatchObject({ + ok: false, + error: { + message: "connection reset", + }, + }); }); it("returns Err for connection refused (retryable)", async () => { @@ -145,10 +149,14 @@ describe("wrapSshCall", () => { it("wraps non-Error rejects into Error for Err", async () => { const result = await wrapSshCall(Promise.reject("string error")); - expect(result.ok).toBe(false); + expect(result).toMatchObject({ + ok: false, + error: { + message: "string error", + }, + }); if (!result.ok) { expect(result.error).toBeInstanceOf(Error); - expect(result.error.message).toBe("string error"); } }); });