-
Notifications
You must be signed in to change notification settings - Fork 672
fix: handle changes to supportsModelTypeTags #14160
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
AustinMroz
merged 9 commits into
main
from
synap5e/feat/model-type-flag-features-endpoint
Aug 4, 2026
+119
−2
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c57c86e
feat(assets): refresh supports_model_type_tags from /api/features
synap5e 92245e8
fix(assets): drop superseded /features responses in capability refresh
synap5e 837eaaa
fix: correct rationale comments for dedicated /features poller
claude 14a9826
test: follow timer/mock conventions; parse /features with zod
claude 35aeeea
fix(assets): single-flight the /features capability refresh; honor de…
claude 26becd1
fix: only honor boolean dev overrides for supportsModelTypeTags
claude ccb7424
Merge remote-tracking branch 'origin/main' into synap5e/feat/model-ty…
claude ee61632
fix: retain last-known-good remoteConfig on transient fetch errors
claude 71db868
Remove out of scope changes
AustinMroz 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
228 changes: 228 additions & 0 deletions
228
src/platform/assets/composables/useModelTypeTagsRefresh.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,228 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { effectScope } from 'vue' | ||
| import type { EffectScope } from 'vue' | ||
|
|
||
| import { | ||
| httpSupportsModelTypeTags, | ||
| refreshSupportsModelTypeTags, | ||
| useSupportsModelTypeTagsRefresh | ||
| } from '@/platform/assets/composables/useModelTypeTagsRefresh' | ||
| import { api } from '@/scripts/api' | ||
|
|
||
| function buildResponse( | ||
| body: unknown, | ||
| init: { ok?: boolean; status?: number } = {} | ||
| ): Response { | ||
| return { | ||
| ok: init.ok ?? true, | ||
| status: init.status ?? 200, | ||
| json: vi.fn().mockResolvedValue(body) | ||
| } as unknown as Response | ||
| } | ||
|
|
||
| const fetchApiSpy = vi.spyOn(api, 'fetchApi') | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetAllMocks() | ||
| httpSupportsModelTypeTags.value = undefined | ||
| }) | ||
|
|
||
| describe('refreshSupportsModelTypeTags', () => { | ||
| it('reads the flag from the raw /features response', async () => { | ||
| fetchApiSpy.mockResolvedValue( | ||
| buildResponse({ supports_model_type_tags: true }) | ||
| ) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledWith('/features', { | ||
| cache: 'no-store', | ||
| signal: expect.any(AbortSignal) | ||
| }) | ||
| expect(httpSupportsModelTypeTags.value).toBe(true) | ||
| }) | ||
|
|
||
| it('tracks a flip to false', async () => { | ||
| httpSupportsModelTypeTags.value = true | ||
| fetchApiSpy.mockResolvedValue( | ||
| buildResponse({ supports_model_type_tags: false }) | ||
| ) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(httpSupportsModelTypeTags.value).toBe(false) | ||
| }) | ||
|
|
||
| it('clears the value when the backend stops serving the key', async () => { | ||
| httpSupportsModelTypeTags.value = true | ||
| fetchApiSpy.mockResolvedValue(buildResponse({ other_flag: true })) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(httpSupportsModelTypeTags.value).toBeUndefined() | ||
| }) | ||
|
|
||
| it('ignores a non-boolean value', async () => { | ||
| fetchApiSpy.mockResolvedValue( | ||
| buildResponse({ supports_model_type_tags: 'yes' }) | ||
| ) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(httpSupportsModelTypeTags.value).toBeUndefined() | ||
| }) | ||
|
|
||
| it('keeps the last known value on an error response', async () => { | ||
| httpSupportsModelTypeTags.value = true | ||
| fetchApiSpy.mockResolvedValue(buildResponse({}, { ok: false, status: 500 })) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(httpSupportsModelTypeTags.value).toBe(true) | ||
| }) | ||
|
|
||
| it('keeps the last known value when the fetch fails', async () => { | ||
| httpSupportsModelTypeTags.value = false | ||
| fetchApiSpy.mockRejectedValue(new Error('offline')) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(httpSupportsModelTypeTags.value).toBe(false) | ||
| }) | ||
|
|
||
| it('coalesces overlapping refreshes into a single request', async () => { | ||
| let resolveFetch: (response: Response) => void | ||
| fetchApiSpy.mockReturnValueOnce( | ||
| new Promise<Response>((resolve) => { | ||
| resolveFetch = resolve | ||
| }) | ||
| ) | ||
| const first = refreshSupportsModelTypeTags() | ||
| const second = refreshSupportsModelTypeTags() | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
|
|
||
| resolveFetch!(buildResponse({ supports_model_type_tags: true })) | ||
| await Promise.all([first, second]) | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
| expect(httpSupportsModelTypeTags.value).toBe(true) | ||
| }) | ||
|
|
||
| it('fetches again once the previous refresh has settled', async () => { | ||
| fetchApiSpy.mockResolvedValue( | ||
| buildResponse({ supports_model_type_tags: true }) | ||
| ) | ||
|
|
||
| await refreshSupportsModelTypeTags() | ||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledTimes(2) | ||
| }) | ||
|
|
||
| it('aborts a stalled request on timeout so the next trigger can fetch', async () => { | ||
| const timeoutController = new AbortController() | ||
| const timeoutSpy = vi | ||
| .spyOn(AbortSignal, 'timeout') | ||
| .mockReturnValueOnce(timeoutController.signal) | ||
| fetchApiSpy.mockImplementationOnce( | ||
| (_route, options) => | ||
| new Promise<Response>((_resolve, reject) => { | ||
| options?.signal?.addEventListener('abort', () => | ||
| reject(new DOMException('The operation timed out.', 'TimeoutError')) | ||
| ) | ||
| }) | ||
| ) | ||
| const stalled = refreshSupportsModelTypeTags() | ||
| expect(timeoutSpy).toHaveBeenCalledWith(10_000) | ||
|
|
||
| timeoutController.abort() | ||
| await stalled | ||
| expect(httpSupportsModelTypeTags.value).toBeUndefined() | ||
|
|
||
| fetchApiSpy.mockResolvedValueOnce( | ||
| buildResponse({ supports_model_type_tags: true }) | ||
| ) | ||
| await refreshSupportsModelTypeTags() | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledTimes(2) | ||
| expect(httpSupportsModelTypeTags.value).toBe(true) | ||
| timeoutSpy.mockRestore() | ||
| }) | ||
| }) | ||
|
|
||
| describe('useSupportsModelTypeTagsRefresh', () => { | ||
| let scope: EffectScope | ||
|
|
||
| beforeEach(() => { | ||
| fetchApiSpy.mockResolvedValue( | ||
| buildResponse({ supports_model_type_tags: true }) | ||
| ) | ||
| scope = effectScope() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| scope.stop() | ||
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| it('fetches immediately and again on websocket reconnect', async () => { | ||
| scope.run(() => useSupportsModelTypeTagsRefresh()) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
| await vi.waitFor(() => expect(httpSupportsModelTypeTags.value).toBe(true)) | ||
|
|
||
| api.dispatchCustomEvent('reconnected') | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledTimes(2) | ||
| }) | ||
|
|
||
| it('re-fetches when the tab becomes visible again', async () => { | ||
| scope.run(() => useSupportsModelTypeTagsRefresh()) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
| await vi.waitFor(() => expect(httpSupportsModelTypeTags.value).toBe(true)) | ||
|
|
||
| document.dispatchEvent(new Event('visibilitychange')) | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledTimes(2) | ||
| }) | ||
|
|
||
| it('re-fetches on the polling interval', async () => { | ||
| vi.useFakeTimers() | ||
| scope.run(() => useSupportsModelTypeTagsRefresh()) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
|
|
||
| await vi.advanceTimersByTimeAsync(120_000) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(2) | ||
| await vi.advanceTimersByTimeAsync(120_000) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(3) | ||
| }) | ||
|
|
||
| it('does not fetch on visibility events or interval ticks while hidden', async () => { | ||
| vi.useFakeTimers() | ||
| const hiddenSpy = vi.spyOn(document, 'hidden', 'get').mockReturnValue(false) | ||
| scope.run(() => useSupportsModelTypeTagsRefresh()) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
|
|
||
| hiddenSpy.mockReturnValue(true) | ||
| document.dispatchEvent(new Event('visibilitychange')) | ||
| await vi.advanceTimersByTimeAsync(120_000) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
|
|
||
| hiddenSpy.mockReturnValue(false) | ||
| document.dispatchEvent(new Event('visibilitychange')) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(2) | ||
| hiddenSpy.mockRestore() | ||
| }) | ||
|
|
||
| it('stops all refresh triggers when the scope is disposed', async () => { | ||
| vi.useFakeTimers() | ||
| scope.run(() => useSupportsModelTypeTagsRefresh()) | ||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
|
|
||
| scope.stop() | ||
| api.dispatchCustomEvent('reconnected') | ||
| document.dispatchEvent(new Event('visibilitychange')) | ||
| await vi.advanceTimersByTimeAsync(120_000) | ||
|
|
||
| expect(fetchApiSpy).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
why different pattern for this flag?
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.
This flag resolves differently because it's a server capability that must be able to change mid-session: the WS copy (
api.getServerFeature) arrives once per connection and is never re-pushed, and theremoteConfig-based resolution used by the other flags inheritsrefreshRemoteConfig's problems — it clearsremoteConfigto{}on any fetch error (which would flap this flag and cause spurious model-library reloads), has no reconnect/visibility triggers, and has no out-of-order response guard. So this one prefers a dedicated refreshable HTTP value and falls back to the WS copy for backends that don't serve the key over HTTP.To be clear, the earlier code comment here claiming a dynamic-config entry could "shadow" the capability was wrong (remoteConfig is the verbatim
/featuresresponse) and has been rewritten at head 837eaaa with the real rationale above. The duplication is acknowledged as temporary: hardeningrefreshRemoteConfigand folding the dedicated poller into it is tracked in FE-1439 (assigned to Simon), after which this flag can resolve through the common path.Generated by Claude Code