|
| 1 | +// kilocode_change - new file |
| 2 | +import { describe, it, expect, afterEach } from "bun:test" |
| 3 | +import { buildKiloHeaders, getFeatureHeader, getEditorNameHeader } from "@kilocode/kilo-gateway" |
| 4 | +import { HEADER_FEATURE, ENV_FEATURE } from "@kilocode/kilo-gateway" |
| 5 | + |
| 6 | +describe("getFeatureHeader", () => { |
| 7 | + const original = process.env[ENV_FEATURE] |
| 8 | + |
| 9 | + afterEach(() => { |
| 10 | + if (original === undefined) { |
| 11 | + delete process.env[ENV_FEATURE] |
| 12 | + } else { |
| 13 | + process.env[ENV_FEATURE] = original |
| 14 | + } |
| 15 | + }) |
| 16 | + |
| 17 | + it("returns undefined when env var is not set", () => { |
| 18 | + delete process.env[ENV_FEATURE] |
| 19 | + expect(getFeatureHeader()).toBeUndefined() |
| 20 | + }) |
| 21 | + |
| 22 | + it("returns the env var value when set", () => { |
| 23 | + process.env[ENV_FEATURE] = "cloud-agent" |
| 24 | + expect(getFeatureHeader()).toBe("cloud-agent") |
| 25 | + }) |
| 26 | + |
| 27 | + it("returns undefined for empty string", () => { |
| 28 | + process.env[ENV_FEATURE] = "" |
| 29 | + expect(getFeatureHeader()).toBeUndefined() |
| 30 | + }) |
| 31 | +}) |
| 32 | + |
| 33 | +describe("buildKiloHeaders", () => { |
| 34 | + const original = process.env[ENV_FEATURE] |
| 35 | + |
| 36 | + afterEach(() => { |
| 37 | + if (original === undefined) { |
| 38 | + delete process.env[ENV_FEATURE] |
| 39 | + } else { |
| 40 | + process.env[ENV_FEATURE] = original |
| 41 | + } |
| 42 | + }) |
| 43 | + |
| 44 | + it("includes feature header when env var is set", () => { |
| 45 | + process.env[ENV_FEATURE] = "vscode-extension" |
| 46 | + const headers = buildKiloHeaders() |
| 47 | + expect(headers[HEADER_FEATURE]).toBe("vscode-extension") |
| 48 | + }) |
| 49 | + |
| 50 | + it("omits feature header when env var is not set", () => { |
| 51 | + delete process.env[ENV_FEATURE] |
| 52 | + const headers = buildKiloHeaders() |
| 53 | + expect(headers[HEADER_FEATURE]).toBeUndefined() |
| 54 | + }) |
| 55 | + |
| 56 | + it("always includes editor name header", () => { |
| 57 | + delete process.env[ENV_FEATURE] |
| 58 | + const headers = buildKiloHeaders() |
| 59 | + expect(headers["X-KILOCODE-EDITORNAME"]).toBe(getEditorNameHeader()) |
| 60 | + }) |
| 61 | + |
| 62 | + it("passes through any feature value from env", () => { |
| 63 | + process.env[ENV_FEATURE] = "custom-feature" |
| 64 | + const headers = buildKiloHeaders() |
| 65 | + expect(headers[HEADER_FEATURE]).toBe("custom-feature") |
| 66 | + }) |
| 67 | +}) |
0 commit comments