mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-24 04:47:03 +00:00
* fix(cursor): pin Auto to CLI --model auto instead of account default Selecting Auto was treated as unset/ACP default[] after the Default→Auto rename. Persist and spawn `auto` so the picker matches `agent --list-models`. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor): keep live ACP model until Auto actually applies Pin session.model to auto for the next `--model auto` spawn, but do not claim the live backend switched when ACP only advertises default[]. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor): reject live Auto unless ACP auto or spawn confirmed it Do not persist Auto when the running catalog has no auto option. Clear the spawn-auto flag after a concrete model apply so Auto → concrete → Auto cannot fake a live switch. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor): keep ACP wire ids spawn-safe and apply effort Cursor's parameterized picker (`clientCapabilities._meta.parameterizedModelPicker`) advertises bare model bases plus separate `fast` / `thought_level` config options. `buildCursorModelsSnapshotFromAcp` synthesized every base as `${base}[fast=${fast}]`, and Cursor rejects any bracket id whose parameter set is not that model's complete set, so 74 of the 76 published picker ids failed at ACP `session/new` with `Cannot use this model` (#1818). - Stop synthesizing wire ids: keep the advertised values verbatim (bare bases are accepted by `--model`, defaults applied). Parameter sets differ per model, so a synthesized id cannot be validated from the options alone. - Flag such catalogs as `parameterized` so variant CLI skus still attach to their base rows — the ACP apply path expresses them through config options. - Apply effort in `applyParameterizedCursorModel` (ids `effort`, `reasoning`, `reasoning_effort`), applied against the config options Cursor re-advertises for the newly selected model, and skipped on models without that axis. - Match CLI sku bases across Cursor's legacy `cursor-` family prefix (`cursor-grok-4.6-high` → ACP base `grok-4.6`) so those variant rows are not dropped. - Version the shared on-disk catalog cache (v2) so runners that already cached the rejected synthesized ids re-probe instead of serving them. Verified with live `cursor-agent 2026.09.10-fd3934a` ACP runs: the catalog no longer contains bracket ids, every advertised base and sampled variant sku spawns, and in-session `claude-opus-4-8-low` / `cursor-grok-4.6-low` set the matching `effort`/`reasoning` option. * test(cursor): cover aliased effort ids and thinking coexistence Covers the branches the HAPI bot review called out for #1818: the `xhigh` → `extra-high` alias on `gpt-5.5` (`reasoning`), the `reasoning_effort` id used by `gemini-3.8-flash`, and switching effort on a model that also advertises Claude's separate `thought_level` `thinking` toggle. * test(cursor): cover legacy sku base and post-switch effort option Adds the two apply-path cases the HAPI bot review called out for #1818: resolving `cursor-grok-4.6-high` onto an advertised `grok-4.6` base, and reading the effort option Cursor advertises for the newly selected model (`reasoning` for gpt-5.5 → `effort` for claude-opus-4-8) instead of the previous model's options. * test(cursor): create the cache dir in the migration test The version-envelope test wrote $HAPI_HOME/cache/cursor-models.json without creating the directory, so running it alone (or filtering with -t) failed with ENOENT before the assertion; it only passed because sibling tests in the same file had already created the path. Reported in the HAPI bot review of #1822. Verified: `vitest run ... -t 'ignores pre-versioned'` → 1 passed, whole file → 4 passed, and every other changed test file passes when run standalone. * Clarify Cursor Auto live-switch limitation in session pickers * Reconcile partial Cursor model changes before acknowledging Auto * Serialize Cursor model changes across clients with the existing async lock --------- Co-authored-by: Cursor <cursoragent@cursor.com>
201 lines
9.0 KiB
TypeScript
201 lines
9.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
buildCursorEffortPickerOptions,
|
|
buildCursorModelCatalog,
|
|
buildFlatCursorModelPickerOptions,
|
|
CURSOR_AUTO_MODEL_LABEL,
|
|
cursorCatalogHasMultiVariantBases,
|
|
shouldUseCursorDualPickers,
|
|
cursorEffortPickerLabel,
|
|
cursorModelBaseId,
|
|
cursorModelDedupeKey,
|
|
cursorModelVariantId,
|
|
cursorVariantDisambiguationSuffix,
|
|
cursorVariantLabel,
|
|
cursorVaryingWireParamKeys,
|
|
filterCursorModelOptionsForCompactView,
|
|
formatCursorModelPickerLabel,
|
|
parseCursorWireParams,
|
|
resolveCursorBaseKey,
|
|
resolveCursorVariantOptions
|
|
} from './cursorModelOptions'
|
|
|
|
const acpModels = [
|
|
{ modelId: 'default[]', name: 'Auto' },
|
|
{ modelId: 'composer-2.5[fast=true]', name: 'Composer 2.5 Fast' },
|
|
{ modelId: 'composer-2.5[fast=false]', name: 'Composer 2.5' },
|
|
{ modelId: 'claude-opus-4-8[thinking=true,context=300k,effort=high,fast=false]', name: 'Claude Opus 4.8' },
|
|
{ modelId: 'claude-opus-4-8[thinking=true,context=300k,effort=low,fast=false]', name: 'Claude Opus 4.8' },
|
|
] as const
|
|
|
|
describe('raw Cursor ACP model splitting', () => {
|
|
it('splits wire ids into raw base and variant parts', () => {
|
|
expect(cursorModelBaseId('composer-2.5[fast=true]')).toBe('composer-2.5')
|
|
expect(cursorModelDedupeKey('composer-2.5-fast')).toBe('composer-2.5-fast')
|
|
expect(cursorModelVariantId('composer-2.5[fast=true]')).toBe('fast=true')
|
|
expect(cursorVariantLabel('claude-opus-4-8[thinking=true,context=300k,effort=high,fast=false]')).toBe(
|
|
'thinking=true,context=300k,effort=high,fast=false'
|
|
)
|
|
})
|
|
|
|
it('parses raw comma-separated wire parameters without changing labels', () => {
|
|
expect(
|
|
parseCursorWireParams('claude-opus-4-8[thinking=true,context=300k,effort=high,fast=false]')
|
|
).toEqual({
|
|
thinking: 'true',
|
|
context: '300k',
|
|
effort: 'high',
|
|
fast: 'false',
|
|
})
|
|
expect(cursorVaryingWireParamKeys([
|
|
'composer-2.5[fast=true]',
|
|
'composer-2.5[fast=false]',
|
|
])).toEqual(['fast'])
|
|
})
|
|
})
|
|
|
|
describe('buildCursorModelCatalog', () => {
|
|
it('groups exact ACP wire variants by raw base id and sorts model bases', () => {
|
|
const catalog = buildCursorModelCatalog([...acpModels])
|
|
expect(catalog.baseOptions.map((o) => o.label)).toEqual([
|
|
CURSOR_AUTO_MODEL_LABEL,
|
|
'claude-opus-4-8',
|
|
'composer-2.5',
|
|
])
|
|
expect(resolveCursorVariantOptions('composer-2.5', catalog).map((v) => v.label)).toEqual([
|
|
'fast=true',
|
|
'fast=false',
|
|
])
|
|
})
|
|
|
|
it('does not merge legacy sku aliases into ACP bases', () => {
|
|
const catalog = buildCursorModelCatalog([
|
|
{ modelId: 'composer-2.5-fast', name: 'Composer 2.5 Fast' },
|
|
{ modelId: 'composer-2.5[fast=true]', name: 'composer-2.5' },
|
|
])
|
|
expect(catalog.baseOptions.map((o) => o.value)).toEqual([
|
|
'auto',
|
|
'composer-2.5',
|
|
'composer-2.5-fast',
|
|
])
|
|
})
|
|
|
|
it('resolves current wire to base and variant list', () => {
|
|
const catalog = buildCursorModelCatalog([...acpModels], {
|
|
currentModel: 'composer-2.5[fast=true]',
|
|
})
|
|
expect(resolveCursorBaseKey('composer-2.5[fast=true]', catalog)).toBe('composer-2.5')
|
|
expect(resolveCursorVariantOptions('composer-2.5', catalog)).toHaveLength(2)
|
|
})
|
|
|
|
it('ignores Cursor-provided display names for picker labels', () => {
|
|
const catalog = buildCursorModelCatalog([
|
|
{ modelId: 'gpt-5.3-codex[reasoning=medium,fast=false]', name: 'Codex 5.3' },
|
|
], { defaultValue: 'auto' })
|
|
expect(catalog.baseOptions.find((entry) => entry.value === 'gpt-5.3-codex')?.label).toBe('gpt-5.3-codex')
|
|
})
|
|
})
|
|
|
|
describe('picker labels and modes', () => {
|
|
it('formats flat labels as raw base when a base has one variant', () => {
|
|
const catalog = buildCursorModelCatalog([
|
|
{ modelId: 'claude-opus-4-7[thinking=true,context=300k,effort=xhigh,fast=false]', name: 'Claude Opus 4.7' },
|
|
{ modelId: 'composer-2.5[fast=true]', name: 'Composer 2.5' },
|
|
], { defaultValue: 'auto' })
|
|
expect(cursorCatalogHasMultiVariantBases(catalog)).toBe(false)
|
|
expect(buildFlatCursorModelPickerOptions(catalog, { defaultValue: 'auto' })).toEqual([
|
|
{ value: 'auto', label: CURSOR_AUTO_MODEL_LABEL },
|
|
{
|
|
value: 'claude-opus-4-7[thinking=true,context=300k,effort=xhigh,fast=false]',
|
|
label: 'claude-opus-4-7 · thinking=true,context=300k,effort=xhigh,fast=false'
|
|
},
|
|
{ value: 'composer-2.5[fast=true]', label: 'composer-2.5 · fast=true' }
|
|
])
|
|
})
|
|
|
|
it('lists a single variant row when a base has one wire', () => {
|
|
const catalog = buildCursorModelCatalog([
|
|
{ modelId: 'gpt-5.5[context=272k,reasoning=medium,fast=false]', name: 'gpt-5.5' },
|
|
], { defaultValue: 'auto' })
|
|
expect(buildCursorEffortPickerOptions(resolveCursorVariantOptions('gpt-5.5', catalog))).toEqual([
|
|
{
|
|
value: 'gpt-5.5[context=272k,reasoning=medium,fast=false]',
|
|
label: 'context=272k,reasoning=medium,fast=false'
|
|
}
|
|
])
|
|
})
|
|
|
|
it('shows raw variant labels when a base has multiple variants', () => {
|
|
const catalog = buildCursorModelCatalog([
|
|
{ modelId: 'composer-2.5[fast=true]', name: 'Composer 2.5' },
|
|
{ modelId: 'composer-2.5[fast=false]', name: 'Composer 2.5' },
|
|
], { defaultValue: 'auto' })
|
|
expect(buildFlatCursorModelPickerOptions(catalog, { defaultValue: 'auto' })).toEqual([
|
|
{ value: 'auto', label: CURSOR_AUTO_MODEL_LABEL },
|
|
{ value: 'composer-2.5[fast=true]', label: 'fast=true' },
|
|
{ value: 'composer-2.5[fast=false]', label: 'fast=false' },
|
|
])
|
|
expect(buildCursorEffortPickerOptions(resolveCursorVariantOptions('composer-2.5', catalog))).toEqual([
|
|
{ value: 'composer-2.5[fast=true]', label: 'fast=true' },
|
|
{ value: 'composer-2.5[fast=false]', label: 'fast=false' },
|
|
])
|
|
})
|
|
|
|
it('enables dual pickers when a base has multiple exact wire ids', () => {
|
|
const catalog = buildCursorModelCatalog([
|
|
{ modelId: 'claude-opus-4-7[thinking=true,context=300k,effort=xhigh,fast=false]', name: 'Claude Opus 4.7' },
|
|
{ modelId: 'composer-2.5[fast=true]', name: 'Composer 2.5' },
|
|
{ modelId: 'composer-2.5[fast=false]', name: 'Composer 2.5' },
|
|
], { defaultValue: 'auto' })
|
|
expect(cursorCatalogHasMultiVariantBases(catalog)).toBe(true)
|
|
expect(shouldUseCursorDualPickers(catalog, 'composer-2.5[fast=false]')).toBe(true)
|
|
})
|
|
|
|
it('uses raw variant suffixes for compatibility helpers', () => {
|
|
expect(cursorEffortPickerLabel('claude-opus-4-8[effort=high,fast=false]', [])).toBe('effort=high,fast=false')
|
|
expect(cursorVariantDisambiguationSuffix('claude-opus-4-8[effort=high,fast=false]')).toBe('effort=high,fast=false')
|
|
expect(formatCursorModelPickerLabel('composer-2.5[fast=true]', 'ignored')).toBe('composer-2.5 · fast=true')
|
|
})
|
|
})
|
|
|
|
describe('filterCursorModelOptionsForCompactView (iOS-style nested picker)', () => {
|
|
const options: { value: string | null; label: string }[] = [
|
|
{ value: 'auto', label: 'Default' },
|
|
{ value: 'claude-fable-5', label: 'claude-fable-5' },
|
|
{ value: 'claude-opus-4-7', label: 'claude-opus-4-7' },
|
|
{ value: 'composer-2.5', label: 'composer-2.5' },
|
|
{ value: 'gpt-5.5', label: 'gpt-5.5' }
|
|
]
|
|
|
|
it('passes the full list through when nothing or Default is selected', () => {
|
|
expect(filterCursorModelOptionsForCompactView(options, undefined)).toEqual(options)
|
|
expect(filterCursorModelOptionsForCompactView(options, null)).toEqual(options)
|
|
expect(filterCursorModelOptionsForCompactView(options, 'auto')).toEqual(options)
|
|
})
|
|
|
|
it('collapses to Default + the selected base when a non-Default base is picked', () => {
|
|
expect(filterCursorModelOptionsForCompactView(options, 'claude-fable-5')).toEqual([
|
|
{ value: 'auto', label: 'Default' },
|
|
{ value: 'claude-fable-5', label: 'claude-fable-5' }
|
|
])
|
|
})
|
|
|
|
it('treats `null`-valued Default rows as the Default passthrough', () => {
|
|
const withNullDefault: { value: string | null; label: string }[] = [
|
|
{ value: null, label: 'Default' },
|
|
{ value: 'composer-2.5', label: 'composer-2.5' },
|
|
{ value: 'gpt-5.5', label: 'gpt-5.5' }
|
|
]
|
|
expect(filterCursorModelOptionsForCompactView(withNullDefault, 'gpt-5.5')).toEqual([
|
|
{ value: null, label: 'Default' },
|
|
{ value: 'gpt-5.5', label: 'gpt-5.5' }
|
|
])
|
|
})
|
|
|
|
it('returns just Default when the selected base is not in the option set (catalog drift)', () => {
|
|
expect(filterCursorModelOptionsForCompactView(options, 'phantom-model-9')).toEqual([
|
|
{ value: 'auto', label: 'Default' }
|
|
])
|
|
})
|
|
})
|