refactor(ai): extracted canonical model ID variable in thinking demotion
- Extracted the evaluation of `bareModelId(modelId)` into a `canonicalId` variable to avoid duplicate calls. - Simplified assertions in the prior-turn thinking tests to check for an empty text blocks array directly.
This commit is contained in:
@@ -28,8 +28,9 @@ const CLAUDE_FABLE_ID = /(?:^|[./])claude[-.]fable(?:[-.]|$)/i;
|
||||
export function renderDemotedThinking(modelId: string, text: string): string {
|
||||
if (!text) return "";
|
||||
text = text.toWellFormed();
|
||||
const canonicalId = bareModelId(modelId);
|
||||
const dialect = preferredDialect(modelId);
|
||||
if (CLAUDE_FABLE_ID.test(bareModelId(modelId))) return `_Hmm. ${text}_\n`;
|
||||
if (CLAUDE_FABLE_ID.test(canonicalId)) return `_Hmm. ${text}_\n`;
|
||||
if (dialect === "harmony" || dialect === "gemma") return `<think>\n${text}\n</think>\n`;
|
||||
return `${getDialectDefinition(dialect).renderThinking(text)}\n`;
|
||||
}
|
||||
|
||||
@@ -344,9 +344,7 @@ describe("Anthropic prior-turn thinking preservation (#2257, #2265)", () => {
|
||||
if (!assistant) throw new Error("expected assistant wire message");
|
||||
const blocks = assistant.content as WireBlock[];
|
||||
const textBlocks = blocks.filter((b): b is WireTextBlock => b.type === "text");
|
||||
expect(textBlocks.every(block => block.text !== renderDemotedThinking(modelCase.id, reasoning))).toBe(true);
|
||||
expect(textBlocks.every(block => !block.text.startsWith("_Hmm."))).toBe(true);
|
||||
expect(textBlocks.every(block => !block.text.includes("<thinking>"))).toBe(true);
|
||||
expect(textBlocks).toHaveLength(0);
|
||||
expect(blocks.find(b => b.type === "thinking")).toBeUndefined();
|
||||
const toolUse = blocks.find(b => b.type === "tool_use") as WireToolUseBlock | undefined;
|
||||
expect(toolUse?.id).toBe(toolCallId);
|
||||
|
||||
Reference in New Issue
Block a user