Skip to content

Commit c1125a3

Browse files
wydroxOtter
authored andcommitted
test(agent-variant): add edge case tests for findVariantInChain logic
1 parent 31f2155 commit c1125a3

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

src/shared/agent-variant.test.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,107 @@ describe("resolveVariantForModel", () => {
305305
// #then
306306
expect(variant).toBe("category-fallback-variant")
307307
})
308+
309+
// Edge case tests for PR #1307 fix
310+
test("does not select variant when provider matches but model does not", () => {
311+
// given
312+
const config = {
313+
agents: {
314+
testAgent: {
315+
fallback_chain: [
316+
{ providers: ["anthropic"], model: "claude-opus-4", variant: "max" }
317+
]
318+
}
319+
}
320+
} as OhMyOpenCodeConfig
321+
const model = { providerID: "anthropic", modelID: "claude-sonnet-4" } // Different model
322+
323+
// when
324+
const variant = resolveVariantForModel(config, "testAgent", model)
325+
326+
// then
327+
expect(variant).toBeUndefined()
328+
})
329+
330+
test("selects variant when provider matches and entry has no model", () => {
331+
// given
332+
const config = {
333+
agents: {
334+
testAgent: {
335+
fallback_chain: [
336+
{ providers: ["anthropic"], variant: "high" } // No model specified
337+
]
338+
}
339+
}
340+
} as OhMyOpenCodeConfig
341+
const model = { providerID: "anthropic", modelID: "any-model" }
342+
343+
// when
344+
const variant = resolveVariantForModel(config, "testAgent", model)
345+
346+
// then
347+
expect(variant).toBe("high")
348+
})
349+
350+
test("does not match when modelID is undefined but entry requires model", () => {
351+
// given
352+
const config = {
353+
agents: {
354+
testAgent: {
355+
fallback_chain: [
356+
{ providers: ["anthropic"], model: "claude-opus-4", variant: "max" }
357+
]
358+
}
359+
}
360+
} as OhMyOpenCodeConfig
361+
const model = { providerID: "anthropic", modelID: undefined } as any // Forced undefined
362+
363+
// when
364+
const variant = resolveVariantForModel(config, "testAgent", model)
365+
366+
// then
367+
expect(variant).toBeUndefined()
368+
})
369+
370+
test("skips mismatched entries and finds later matching entry", () => {
371+
// given
372+
const config = {
373+
agents: {
374+
testAgent: {
375+
fallback_chain: [
376+
{ providers: ["anthropic"], model: "claude-opus-4", variant: "max" }, // Wrong model
377+
{ providers: ["anthropic"], model: "claude-sonnet-4", variant: "high" } // Correct
378+
]
379+
}
380+
}
381+
} as OhMyOpenCodeConfig
382+
const model = { providerID: "anthropic", modelID: "claude-sonnet-4" }
383+
384+
// when
385+
const variant = resolveVariantForModel(config, "testAgent", model)
386+
387+
// then
388+
expect(variant).toBe("high")
389+
})
390+
391+
test("respects model matching for entries with multiple providers", () => {
392+
// given
393+
const config = {
394+
agents: {
395+
testAgent: {
396+
fallback_chain: [
397+
{ providers: ["anthropic", "openai"], model: "gpt-4", variant: "high" }
398+
]
399+
}
400+
}
401+
} as OhMyOpenCodeConfig
402+
// Provider matches (anthropic) but model (claude-opus-4) doesn't match gpt-4
403+
const model = { providerID: "anthropic", modelID: "claude-opus-4" }
404+
405+
// when
406+
const variant = resolveVariantForModel(config, "testAgent", model)
407+
408+
// then
409+
expect(variant).toBeUndefined()
410+
})
308411
})

0 commit comments

Comments
 (0)