|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | +import { SystemPrompt } from "../../src/session/system" |
| 3 | +import type { Provider } from "../../src/provider/provider" |
| 4 | + |
| 5 | +function makeModel(overrides: Partial<Provider.Model> & { api: Provider.Model["api"] }): Provider.Model { |
| 6 | + const { api, ...rest } = overrides |
| 7 | + return { |
| 8 | + id: "test-model" as any, |
| 9 | + providerID: "test-provider" as any, |
| 10 | + name: "Test Model", |
| 11 | + api, |
| 12 | + capabilities: { |
| 13 | + temperature: false, |
| 14 | + reasoning: false, |
| 15 | + attachment: false, |
| 16 | + toolcall: true, |
| 17 | + input: { text: true, audio: false, image: false, video: false, pdf: false }, |
| 18 | + output: { text: true, audio: false, image: false, video: false, pdf: false }, |
| 19 | + interleaved: false, |
| 20 | + }, |
| 21 | + cost: { input: 0, output: 0, cache: { read: 0, write: 0 } }, |
| 22 | + limit: { context: 128000, output: 4096 }, |
| 23 | + status: "active", |
| 24 | + options: {}, |
| 25 | + headers: {}, |
| 26 | + release_date: "2025-01-01", |
| 27 | + ...rest, |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +describe("SystemPrompt.provider", () => { |
| 32 | + test("returns custom prompt when model has prompt field", () => { |
| 33 | + const model = makeModel({ |
| 34 | + api: { id: "some-unknown-model", url: "", npm: "" }, |
| 35 | + prompt: "You are a custom coding assistant.", |
| 36 | + }) |
| 37 | + const result = SystemPrompt.provider(model) |
| 38 | + expect(result).toEqual(["You are a custom coding assistant."]) |
| 39 | + }) |
| 40 | + |
| 41 | + test("custom prompt takes priority over model ID matching", () => { |
| 42 | + const model = makeModel({ |
| 43 | + api: { id: "claude-sonnet-4", url: "", npm: "" }, |
| 44 | + prompt: "Custom prompt overrides claude matching.", |
| 45 | + }) |
| 46 | + const result = SystemPrompt.provider(model) |
| 47 | + expect(result).toEqual(["Custom prompt overrides claude matching."]) |
| 48 | + }) |
| 49 | + |
| 50 | + test("falls back to claude prompt when no custom prompt and model ID contains claude", () => { |
| 51 | + const model = makeModel({ |
| 52 | + api: { id: "claude-sonnet-4", url: "", npm: "" }, |
| 53 | + }) |
| 54 | + const result = SystemPrompt.provider(model) |
| 55 | + expect(result.length).toBe(1) |
| 56 | + expect(result[0]).not.toBe("") |
| 57 | + // Should not be the fallback prompt (qwen) |
| 58 | + const fallbackModel = makeModel({ |
| 59 | + api: { id: "some-unknown-model", url: "", npm: "" }, |
| 60 | + }) |
| 61 | + const fallback = SystemPrompt.provider(fallbackModel) |
| 62 | + expect(result[0]).not.toBe(fallback[0]) |
| 63 | + }) |
| 64 | + |
| 65 | + test("falls back to gemini prompt for gemini models", () => { |
| 66 | + const model = makeModel({ |
| 67 | + api: { id: "gemini-pro", url: "", npm: "" }, |
| 68 | + }) |
| 69 | + const result = SystemPrompt.provider(model) |
| 70 | + expect(result.length).toBe(1) |
| 71 | + expect(result[0]).not.toBe("") |
| 72 | + }) |
| 73 | + |
| 74 | + test("falls back to default prompt for unknown models without custom prompt", () => { |
| 75 | + const model = makeModel({ |
| 76 | + api: { id: "totally-unknown-model", url: "", npm: "" }, |
| 77 | + }) |
| 78 | + const result = SystemPrompt.provider(model) |
| 79 | + expect(result.length).toBe(1) |
| 80 | + expect(result[0]).not.toBe("") |
| 81 | + }) |
| 82 | + |
| 83 | + test("model without prompt field uses default matching", () => { |
| 84 | + const model = makeModel({ |
| 85 | + api: { id: "gpt-5-turbo", url: "", npm: "" }, |
| 86 | + }) |
| 87 | + const result = SystemPrompt.provider(model) |
| 88 | + expect(result.length).toBe(1) |
| 89 | + // gpt-5 should match PROMPT_CODEX, not the fallback |
| 90 | + const fallbackModel = makeModel({ |
| 91 | + api: { id: "unknown", url: "", npm: "" }, |
| 92 | + }) |
| 93 | + const fallback = SystemPrompt.provider(fallbackModel) |
| 94 | + expect(result[0]).not.toBe(fallback[0]) |
| 95 | + }) |
| 96 | +}) |
0 commit comments