test: Remove duplicate and theatrical tests (#1986)

* 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 <noreply@anthropic.com>

* fix: apply biome format to test files in qa/dedup-scanner

Agent: team-lead
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
A 2026-02-27 02:18:03 -08:00 committed by GitHub
parent edcdf78ba8
commit d02e298488
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 110 deletions

View file

@ -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:");
});
});

View file

@ -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",
]);
});
});
});

View file

@ -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<string, string | undefined> = {};
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<string, string | undefined> = {};
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",
]);
});
});

View file

@ -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");
}
});
});