test: fix failing prompt test (#12847)

This commit is contained in:
Aiden Cline
2026-02-09 11:25:22 -06:00
committed by GitHub
parent fb94b4f8e8
commit f74c0339cc

View File

@@ -6,55 +6,63 @@ import { tmpdir } from "../fixture/fixture"
describe("session.prompt agent variant", () => { describe("session.prompt agent variant", () => {
test("applies agent variant only when using agent model", async () => { test("applies agent variant only when using agent model", async () => {
await using tmp = await tmpdir({ const prev = process.env.OPENAI_API_KEY
git: true, process.env.OPENAI_API_KEY = "test-openai-key"
config: {
agent: { try {
build: { await using tmp = await tmpdir({
model: "openai/gpt-5.2", git: true,
variant: "xhigh", config: {
agent: {
build: {
model: "openai/gpt-5.2",
variant: "xhigh",
},
}, },
}, },
}, })
})
await Instance.provide({ await Instance.provide({
directory: tmp.path, directory: tmp.path,
fn: async () => { fn: async () => {
const session = await Session.create({}) const session = await Session.create({})
const other = await SessionPrompt.prompt({ const other = await SessionPrompt.prompt({
sessionID: session.id, sessionID: session.id,
agent: "build", agent: "build",
model: { providerID: "opencode", modelID: "kimi-k2.5-free" }, model: { providerID: "opencode", modelID: "kimi-k2.5-free" },
noReply: true, noReply: true,
parts: [{ type: "text", text: "hello" }], parts: [{ type: "text", text: "hello" }],
}) })
if (other.info.role !== "user") throw new Error("expected user message") if (other.info.role !== "user") throw new Error("expected user message")
expect(other.info.variant).toBeUndefined() expect(other.info.variant).toBeUndefined()
const match = await SessionPrompt.prompt({ const match = await SessionPrompt.prompt({
sessionID: session.id, sessionID: session.id,
agent: "build", agent: "build",
noReply: true, noReply: true,
parts: [{ type: "text", text: "hello again" }], parts: [{ type: "text", text: "hello again" }],
}) })
if (match.info.role !== "user") throw new Error("expected user message") if (match.info.role !== "user") throw new Error("expected user message")
expect(match.info.model).toEqual({ providerID: "openai", modelID: "gpt-5.2" }) expect(match.info.model).toEqual({ providerID: "openai", modelID: "gpt-5.2" })
expect(match.info.variant).toBe("xhigh") expect(match.info.variant).toBe("xhigh")
const override = await SessionPrompt.prompt({ const override = await SessionPrompt.prompt({
sessionID: session.id, sessionID: session.id,
agent: "build", agent: "build",
noReply: true, noReply: true,
variant: "high", variant: "high",
parts: [{ type: "text", text: "hello third" }], parts: [{ type: "text", text: "hello third" }],
}) })
if (override.info.role !== "user") throw new Error("expected user message") if (override.info.role !== "user") throw new Error("expected user message")
expect(override.info.variant).toBe("high") expect(override.info.variant).toBe("high")
await Session.remove(session.id) await Session.remove(session.id)
}, },
}) })
} finally {
if (prev === undefined) delete process.env.OPENAI_API_KEY
else process.env.OPENAI_API_KEY = prev
}
}) })
}) })