|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { |
| 3 | + shadowSourceModelBadge, |
| 4 | + shadowSourceModelLabel, |
| 5 | + shadowSourceModelList, |
| 6 | +} from "../src/pages/shadow-call-source"; |
| 7 | + |
| 8 | +/** |
| 9 | + * The GUI used to spell the intercepted slug into six locale files, which went |
| 10 | + * stale every time Codex changed its helper model. It now renders whatever the |
| 11 | + * runtime reports, so the cases that matter are: the runtime reported a list, |
| 12 | + * the runtime is too old to report one, and the operator configured an override. |
| 13 | + * Without these, a fallback or formatting regression ships silently green. |
| 14 | + */ |
| 15 | +describe("shadowSourceModelList", () => { |
| 16 | + test("renders the models the runtime reported", () => { |
| 17 | + expect(shadowSourceModelList(["gpt-5.4-mini", "gpt-5.6-luna"])) |
| 18 | + .toEqual(["gpt-5.4-mini", "gpt-5.6-luna"]); |
| 19 | + }); |
| 20 | + |
| 21 | + test("renders a configured override rather than the defaults", () => { |
| 22 | + expect(shadowSourceModelList(["gpt-6-helper"])).toEqual(["gpt-6-helper"]); |
| 23 | + }); |
| 24 | + |
| 25 | + test("falls back when a runtime too old to report sourceModels omits it", () => { |
| 26 | + expect(shadowSourceModelList(undefined)).toEqual(["gpt-5.4-mini", "gpt-5.6-luna"]); |
| 27 | + }); |
| 28 | + |
| 29 | + // An empty array is what a runtime sends when every configured entry was |
| 30 | + // rejected; showing nothing there would read as "nothing is intercepted", |
| 31 | + // which is the opposite of the truth. |
| 32 | + test("falls back on an empty list instead of rendering nothing", () => { |
| 33 | + expect(shadowSourceModelList([])).toEqual(["gpt-5.4-mini", "gpt-5.6-luna"]); |
| 34 | + }); |
| 35 | + |
| 36 | + test("drops blank entries and trims the rest", () => { |
| 37 | + expect(shadowSourceModelList([" gpt-5.6-luna ", "", " "])).toEqual(["gpt-5.6-luna"]); |
| 38 | + }); |
| 39 | + |
| 40 | + test("falls back when the field is not an array at all", () => { |
| 41 | + expect(shadowSourceModelList("gpt-5.6-luna" as unknown as string[])) |
| 42 | + .toEqual(["gpt-5.4-mini", "gpt-5.6-luna"]); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +describe("shadow source model rendering", () => { |
| 47 | + test("label joins every reported model", () => { |
| 48 | + expect(shadowSourceModelLabel(["gpt-5.4-mini", "gpt-5.6-luna"])) |
| 49 | + .toBe("gpt-5.4-mini, gpt-5.6-luna"); |
| 50 | + }); |
| 51 | + |
| 52 | + test("badge drops the shared gpt- prefix to keep the row compact", () => { |
| 53 | + expect(shadowSourceModelBadge(["gpt-5.4-mini", "gpt-5.6-luna"])) |
| 54 | + .toBe("5.4-mini, 5.6-luna"); |
| 55 | + }); |
| 56 | + |
| 57 | + test("badge leaves a non-gpt id untouched", () => { |
| 58 | + expect(shadowSourceModelBadge(["helper-x"])).toBe("helper-x"); |
| 59 | + }); |
| 60 | + |
| 61 | + test("both renderings use the fallback when the runtime reported nothing", () => { |
| 62 | + expect(shadowSourceModelLabel(undefined)).toBe("gpt-5.4-mini, gpt-5.6-luna"); |
| 63 | + expect(shadowSourceModelBadge(undefined)).toBe("5.4-mini, 5.6-luna"); |
| 64 | + }); |
| 65 | +}); |
0 commit comments