Repository navigation
fix(model): resolve [1m]-tagged aliases when 1M context is disabled #1822
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
kevincodex1
merged 3 commits into
Twigpine:main
from
0xfandom:fix/parse-model-1m-tag-when-disabled
Jul 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
143 changes: 143 additions & 0 deletions
143
src/utils/model/parseUserSpecifiedModel.disable1m.test.ts
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,143 @@ | ||
| import { afterEach, beforeEach, describe, expect, test } from 'bun:test' | ||
| import { parseUserSpecifiedModel } from './model.js' | ||
|
|
||
| // Regression: when 1M context is disabled (CLAUDE_CODE_DISABLE_1M_CONTEXT, used | ||
| // by C4E/HIPAA admins), `has1mContext` returns false. The parser gated the | ||
| // stripping of the `[1m]` tag on that flag, so an aliased request like | ||
| // `sonnet[1m]` kept the tag attached, never matched the `sonnet` alias, and | ||
| // returned the literal, unservable string `sonnet[1m]`. The tag must be stripped | ||
| // for matching regardless; only the re-appended suffix depends on 1M being on. | ||
| describe('parseUserSpecifiedModel — [1m] tag when 1M context is disabled', () => { | ||
| const original = process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT | ||
|
|
||
| beforeEach(() => { | ||
| process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT = '1' | ||
| }) | ||
| afterEach(() => { | ||
| if (original === undefined) { | ||
| delete process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT | ||
| } else { | ||
| process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT = original | ||
| } | ||
| }) | ||
|
|
||
| for (const alias of ['sonnet', 'opus', 'haiku', 'best', 'opusplan']) { | ||
| test(`${alias}[1m] resolves to the base model (no [1m]) when 1M is disabled`, () => { | ||
| const base = parseUserSpecifiedModel(alias) | ||
| const tagged = parseUserSpecifiedModel(`${alias}[1m]`) | ||
| // Base model is returned, with the 1M tag dropped — not a literal alias. | ||
| expect(tagged).toBe(base) | ||
| expect(tagged.endsWith('[1m]')).toBe(false) | ||
| expect(tagged).not.toBe(`${alias}[1m]`) | ||
| }) | ||
| } | ||
|
|
||
| test('case-insensitive tag is also resolved (SONNET[1M] → base sonnet)', () => { | ||
| expect(parseUserSpecifiedModel('SONNET[1M]')).toBe( | ||
| parseUserSpecifiedModel('sonnet'), | ||
| ) | ||
| }) | ||
|
|
||
| test('custom model id drops the [1m] suffix when 1M is disabled', () => { | ||
| expect(parseUserSpecifiedModel('my-custom-deploy[1m]')).toBe( | ||
| 'my-custom-deploy', | ||
| ) | ||
| }) | ||
|
|
||
| test('mixed-case custom id drops [1m]/[1M] but preserves casing when disabled', () => { | ||
| expect(parseUserSpecifiedModel('MyCustomDeploy[1M]')).toBe('MyCustomDeploy') | ||
| expect(parseUserSpecifiedModel('MyCustomDeploy[1m]')).toBe('MyCustomDeploy') | ||
| }) | ||
|
|
||
| // Codex aliases are resolved by a separate branch from the Claude-family | ||
| // aliases, so they need their own disabled-1M coverage. | ||
| test('codex aliases drop the [1m] tag when 1M is disabled', () => { | ||
| const codexplan = parseUserSpecifiedModel('codexplan') | ||
| const codexspark = parseUserSpecifiedModel('codexspark') | ||
| expect(parseUserSpecifiedModel('codexplan[1m]')).toBe(codexplan) | ||
| expect(parseUserSpecifiedModel('codexspark[1M]')).toBe(codexspark) | ||
| expect(parseUserSpecifiedModel('codexplan[1m]').endsWith('[1m]')).toBe(false) | ||
| expect(parseUserSpecifiedModel('codexspark[1M]').endsWith('[1m]')).toBe( | ||
| false, | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| // Guard the opposite direction: with 1M enabled (default), the tag is preserved. | ||
| describe('parseUserSpecifiedModel — [1m] tag when 1M context is enabled', () => { | ||
| const original = process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT | ||
|
|
||
| beforeEach(() => { | ||
| delete process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT | ||
| }) | ||
| afterEach(() => { | ||
| if (original === undefined) { | ||
| delete process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT | ||
| } else { | ||
| process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT = original | ||
| } | ||
| }) | ||
|
|
||
| test('sonnet[1m] keeps the tag on the resolved base model', () => { | ||
| const base = parseUserSpecifiedModel('sonnet') | ||
| expect(parseUserSpecifiedModel('sonnet[1m]')).toBe(`${base}[1m]`) | ||
| }) | ||
|
|
||
| test('custom model id keeps the [1m] suffix', () => { | ||
| expect(parseUserSpecifiedModel('my-custom-deploy[1m]')).toBe( | ||
| 'my-custom-deploy[1m]', | ||
| ) | ||
| }) | ||
|
|
||
| // Mixed-case custom deployment ids keep their casing; only the [1m]/[1M] tag | ||
| // is normalized/reattached. | ||
| test('mixed-case custom id preserves casing, tag normalized to [1m]', () => { | ||
| expect(parseUserSpecifiedModel('MyCustomDeploy[1M]')).toBe( | ||
| 'MyCustomDeploy[1m]', | ||
| ) | ||
| expect(parseUserSpecifiedModel('MyCustomDeploy[1m]')).toBe( | ||
| 'MyCustomDeploy[1m]', | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| // Custom default-model env overrides (ANTHROPIC_DEFAULT_SONNET_MODEL etc.) can | ||
| // bake a [1m] suffix into the resolved alias target. The disabled-1M path must | ||
| // strip that too, and the enabled path must honor it without duplicating it. | ||
| describe('parseUserSpecifiedModel — [1m] on custom default env overrides', () => { | ||
| const KEYS = [ | ||
| 'CLAUDE_CODE_DISABLE_1M_CONTEXT', | ||
| 'ANTHROPIC_DEFAULT_SONNET_MODEL', | ||
| 'ANTHROPIC_DEFAULT_OPUS_MODEL', | ||
| ] as const | ||
| const saved: Record<string, string | undefined> = {} | ||
|
|
||
| beforeEach(() => { | ||
| for (const k of KEYS) saved[k] = process.env[k] | ||
| process.env.ANTHROPIC_DEFAULT_SONNET_MODEL = 'MySonnetDeploy[1m]' | ||
| process.env.ANTHROPIC_DEFAULT_OPUS_MODEL = 'MyOpusDeploy[1M]' | ||
| }) | ||
| afterEach(() => { | ||
| for (const k of KEYS) { | ||
| if (saved[k] === undefined) delete process.env[k] | ||
| else process.env[k] = saved[k] | ||
| } | ||
| }) | ||
|
|
||
| test('disabled: alias drops the baked [1m] from the resolved default', () => { | ||
| process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT = '1' | ||
| // Casing of the custom deployment id is preserved; only the tag is dropped. | ||
| expect(parseUserSpecifiedModel('sonnet[1m]')).toBe('MySonnetDeploy') | ||
| expect(parseUserSpecifiedModel('sonnet')).toBe('MySonnetDeploy') | ||
| expect(parseUserSpecifiedModel('opus[1M]')).toBe('MyOpusDeploy') | ||
| }) | ||
|
|
||
| test('enabled: baked [1m] honored and never duplicated', () => { | ||
| delete process.env.CLAUDE_CODE_DISABLE_1M_CONTEXT | ||
| // Bare alias honors the env default's opt-in; tag normalized to [1m]. | ||
| expect(parseUserSpecifiedModel('sonnet')).toBe('MySonnetDeploy[1m]') | ||
| // Tagged alias does not double the suffix. | ||
| expect(parseUserSpecifiedModel('sonnet[1m]')).toBe('MySonnetDeploy[1m]') | ||
| expect(parseUserSpecifiedModel('opus')).toBe('MyOpusDeploy[1m]') | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.