-
Notifications
You must be signed in to change notification settings - Fork 473
Fixing model name normalizer logic #49001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+87
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff05d38
fix: leave short model names (< 6 chars) unchanged in reduceModelName…
Copilot a7a06df
Merge branch 'main' into copilot/fix-model-name-normalizer-code
github-actions[bot] 0fb4c1d
Apply remaining changes
Copilot 080314f
Apply remaining changes
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // @ts-check | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
| import { createRequire } from "module"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const { reduceModelNameToIdentifier, formatModelEmojiAlias, formatModelEmojiAliasLegend } = require("./model_aliases.cjs"); | ||
|
|
||
| describe("reduceModelNameToIdentifier", () => { | ||
| it('returns "auto" unchanged (short name, 4 chars)', () => { | ||
| expect(reduceModelNameToIdentifier("auto")).toBe("auto"); | ||
| }); | ||
|
|
||
| it("returns safe short model names (< 6 alphanumeric chars) unchanged", () => { | ||
| expect(reduceModelNameToIdentifier("o1")).toBe("o1"); | ||
| expect(reduceModelNameToIdentifier("o3")).toBe("o3"); | ||
| expect(reduceModelNameToIdentifier("gpt")).toBe("gpt"); | ||
| expect(reduceModelNameToIdentifier("mini")).toBe("mini"); | ||
| expect(reduceModelNameToIdentifier("haiku")).toBe("haiku"); | ||
| }); | ||
|
|
||
| it("sanitizes short model names that contain non-alphanumeric characters", () => { | ||
| // "a|b" has a pipe character that would split a Markdown table row — must be compacted | ||
| expect(reduceModelNameToIdentifier("a|b")).toBe("abx00"); | ||
| // "gpt-5" has a hyphen, so it falls through to the GPT family shortcut | ||
| expect(reduceModelNameToIdentifier("gpt-5")).toBe("gpt50"); | ||
| }); | ||
|
|
||
| it("processes names of exactly 6 characters through normalization (boundary)", () => { | ||
| // 6 chars is not < 6, so the short-name guard does not apply; normalization runs | ||
| expect(reduceModelNameToIdentifier("gpt-4o")).toBe("gpt40"); | ||
| }); | ||
|
|
||
| it("returns empty string for empty/null/undefined input", () => { | ||
| expect(reduceModelNameToIdentifier("")).toBe(""); | ||
| expect(reduceModelNameToIdentifier(null)).toBe(""); | ||
| expect(reduceModelNameToIdentifier(undefined)).toBe(""); | ||
| }); | ||
|
|
||
| it("handles known Claude model families", () => { | ||
| expect(reduceModelNameToIdentifier("claude-sonnet-4.5")).toBe("sonnet45"); | ||
| expect(reduceModelNameToIdentifier("claude-opus-5")).toBe("opus50"); | ||
| expect(reduceModelNameToIdentifier("claude-haiku-4.5")).toBe("haiku45"); | ||
| }); | ||
|
|
||
| it("handles GPT model families", () => { | ||
| expect(reduceModelNameToIdentifier("gpt-5")).toBe("gpt50"); | ||
| expect(reduceModelNameToIdentifier("gpt-4o")).toBe("gpt40"); | ||
| }); | ||
|
|
||
| it("handles Gemini model families", () => { | ||
| expect(reduceModelNameToIdentifier("gemini-3.1-pro")).toBe("gem31pro"); | ||
| }); | ||
|
|
||
| it("normalizes to lowercase before processing", () => { | ||
| expect(reduceModelNameToIdentifier("AUTO")).toBe("auto"); | ||
| expect(reduceModelNameToIdentifier("Auto")).toBe("auto"); | ||
| }); | ||
|
|
||
| it("uses fallback identifier for unrecognized longer model names", () => { | ||
| // "unknown-model" -> compact "unknownmodel" (12 chars) -> letterPart "unk", digitPart "00" -> "unk00" | ||
| expect(reduceModelNameToIdentifier("unknown-model")).toBe("unk00"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formatModelEmojiAlias", () => { | ||
| it('returns "auto" unchanged', () => { | ||
| expect(formatModelEmojiAlias("auto")).toBe("auto"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formatModelEmojiAliasLegend", () => { | ||
| it("produces legend entries for a list of models", () => { | ||
| const result = formatModelEmojiAliasLegend(["auto", "claude-sonnet-4.5"]); | ||
| expect(result).toContain("auto=auto"); | ||
| expect(result).toContain("sonnet45=claude-sonnet-4.5"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] ESM
importstatement in a.cjsfile will fail at runtime.Line 4 uses
import { describe, expect, it } from "vitest"—importis not valid in CommonJS modules. This test file will throw aSyntaxErrorunless vitest's config applies a transform, but the.cjsextension explicitly opts out of ESM.💡 Fix
Replace the ESM imports with CommonJS requires:
Or rename the file to
.test.mjsand remove thecreateRequirewrapper since native ESM can useimportdirectly.@copilot please address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change needed. Every other
.test.cjsfile inactions/setup/js/(e.g.generate_workflow_overview.test.cjs,safe_output_processor.test.cjs) uses the same ESMimportsyntax. The vitest config (include: ["**/*.test.{js,cjs}"]) transforms these files — confirmed by all 12 tests passing. Changing this file alone would create an inconsistency with the rest of the test suite.