prompt-variant.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, expect, test } from "bun:test"
  2. import { Instance } from "../../src/project/instance"
  3. import { Session } from "../../src/session"
  4. import { SessionPrompt } from "../../src/session/prompt"
  5. import { tmpdir } from "../fixture/fixture"
  6. describe("session.prompt agent variant", () => {
  7. test("applies agent variant only when using agent model", async () => {
  8. const prev = process.env.OPENAI_API_KEY
  9. process.env.OPENAI_API_KEY = "test-openai-key"
  10. try {
  11. await using tmp = await tmpdir({
  12. git: true,
  13. config: {
  14. agent: {
  15. build: {
  16. model: "openai/gpt-5.2",
  17. variant: "xhigh",
  18. },
  19. },
  20. },
  21. })
  22. await Instance.provide({
  23. directory: tmp.path,
  24. fn: async () => {
  25. const session = await Session.create({})
  26. const other = await SessionPrompt.prompt({
  27. sessionID: session.id,
  28. agent: "build",
  29. model: { providerID: "opencode", modelID: "kimi-k2.5-free" },
  30. noReply: true,
  31. parts: [{ type: "text", text: "hello" }],
  32. })
  33. if (other.info.role !== "user") throw new Error("expected user message")
  34. expect(other.info.variant).toBeUndefined()
  35. const match = await SessionPrompt.prompt({
  36. sessionID: session.id,
  37. agent: "build",
  38. noReply: true,
  39. parts: [{ type: "text", text: "hello again" }],
  40. })
  41. if (match.info.role !== "user") throw new Error("expected user message")
  42. expect(match.info.model).toEqual({ providerID: "openai", modelID: "gpt-5.2" })
  43. expect(match.info.variant).toBe("xhigh")
  44. const override = await SessionPrompt.prompt({
  45. sessionID: session.id,
  46. agent: "build",
  47. noReply: true,
  48. variant: "high",
  49. parts: [{ type: "text", text: "hello third" }],
  50. })
  51. if (override.info.role !== "user") throw new Error("expected user message")
  52. expect(override.info.variant).toBe("high")
  53. await Session.remove(session.id)
  54. },
  55. })
  56. } finally {
  57. if (prev === undefined) delete process.env.OPENAI_API_KEY
  58. else process.env.OPENAI_API_KEY = prev
  59. }
  60. })
  61. })