Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

test(cli): resolve strict null checks in Qoder unit tests

diegosouzapw01ae0372053c
diff --git a/tests/unit/qoder-cli.test.ts b/tests/unit/qoder-cli.test.ts
index 7f92470c2e..310a2bda83 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<string, string | undefined | null>,
+ fn: () => void | Promise<void>
+) {
+ const previous = new Map<string, string | undefined>();
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;
}