From 01ae0372053c47522db9d33ab330c10cc12eed1b Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Sat, 18 Apr 2026 10:29:30 -0300 Subject: [PATCH] test(cli): resolve strict null checks in Qoder unit tests --- tests/unit/qoder-cli.test.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/unit/qoder-cli.test.ts b/tests/unit/qoder-cli.test.ts index 7f92470c..310a2bda 100644 --- a/tests/unit/qoder-cli.test.ts +++ b/tests/unit/qoder-cli.test.ts @@ -3,14 +3,17 @@ import assert from "node:assert/strict"; const qoderCli = await import("../../open-sse/services/qoderCli.ts"); -function withEnv(overrides, fn) { - const previous = new Map(); +function withEnv( + overrides: Record, + fn: () => void | Promise +) { + const previous = new Map(); for (const [key, value] of Object.entries(overrides)) { previous.set(key, process.env[key]); - if (value === undefined) { + if (value === undefined || value === null) { delete process.env[key]; } else { - process.env[key] = value; + process.env[key] = String(value); } } @@ -280,7 +283,7 @@ test("validateQoderCliPat builds COSY headers and handles success, HTTP failures providerSpecificData: { modelId: "qwen3-max" }, }); assert.equal(denied.valid, false); - assert.match(denied.error, /Authentication failed/); + assert.match(denied.error!, /Authentication failed/); assert.equal(denied.unsupported, false); } @@ -292,7 +295,7 @@ test("validateQoderCliPat builds COSY headers and handles success, HTTP failures const failed = await qoderCli.validateQoderCliPat({ apiKey: "pat-token" }); assert.equal(failed.valid, false); - assert.match(failed.error, /Cannot reach Qoder API/); + assert.match(failed.error!, /Cannot reach Qoder API/); assert.equal(failed.unsupported, false); } @@ -315,7 +318,7 @@ test("validateQoderCliPat builds COSY headers and handles success, HTTP failures await withEnv({ QODER_PERSONAL_ACCESS_TOKEN: undefined }, async () => { const noToken = await qoderCli.validateQoderCliPat({ apiKey: "" }); assert.equal(noToken.valid, false); - assert.match(noToken.error, /No Qoder token provided/); + assert.match(noToken.error!, /No Qoder token provided/); }); } @@ -324,7 +327,7 @@ test("validateQoderCliPat builds COSY headers and handles success, HTTP failures const blobToken = "x".repeat(600); const blobResult = await qoderCli.validateQoderCliPat({ apiKey: blobToken }); assert.equal(blobResult.valid, false); - assert.match(blobResult.error, /encrypted auth blob/); + assert.match(blobResult.error!, /encrypted auth blob/); } globalThis.fetch = originalFetch; @@ -356,7 +359,7 @@ test("validateQoderCliPat treats 5xx HTTP failures as valid bypass", async () => try { const result = await qoderCli.validateQoderCliPat({ apiKey: "valid-pat" }); assert.equal(result.valid, true); - assert.match(result.error, /HTTP 500.*treating PAT as valid/); + assert.match(result.error!, /HTTP 500.*treating PAT as valid/); } finally { globalThis.fetch = originalFetch; }