-
-
Notifications
You must be signed in to change notification settings - Fork 7
[hardening] TT-7621 fix: stop the PBT blob-load dead-states and never-ending bootstrap poll #547
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
Draft
nabalone
wants to merge
3
commits into
develop
Choose a base branch
from
TT-7621_hang-state-diagnose
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/renderer/src/components/PassageDetail/carefulSpeech/useGuidedPhraseSegments.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,75 @@ | ||
| /** | ||
| * TT-7621 regression test for the Phrase Back Translate bootstrap. | ||
| * | ||
| * `PassageDetailGuidedPhraseRecord` runs a 250ms poll that calls | ||
| * `ensureSegments()` until it returns true. When auto-segment legitimately finds | ||
| * no boundaries (e.g. audio the silence math cannot split) `ensureSegments` | ||
| * returned false forever, so the poll — and its effect churn — never stopped. | ||
| * | ||
| * With audio actually loaded (duration > 0) it must instead fall back to a | ||
| * single full-length segment and return true, so the step can settle. Returning | ||
| * false stays correct only while the player has no audio yet. | ||
| */ | ||
| import { renderHook, act } from '@testing-library/react'; | ||
|
|
||
| jest.mock('../Internalization/useProjectSegmentSave', () => ({ | ||
| useProjectSegmentSave: () => jest.fn().mockResolvedValue(undefined), | ||
| })); | ||
|
|
||
| import { useGuidedPhraseSegments } from './useGuidedPhraseSegments'; | ||
| import { hasPhraseRegions } from './carefulSpeechBoundary'; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| function makeControls(overrides: Record<string, unknown> = {}): any { | ||
| return { | ||
| current: { | ||
| isReady: () => true, | ||
| getDuration: () => 10, | ||
| runAutoSegment: jest.fn().mockResolvedValue(0), | ||
| getRegionsJson: () => '{}', | ||
| loadRegionsJson: jest.fn(), | ||
| applyRegionColors: jest.fn(), | ||
| ...overrides, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const mediafile: any = { id: 'v1', attributes: { segments: '[]' } }; | ||
|
|
||
| describe('useGuidedPhraseSegments.ensureSegments (TT-7621)', () => { | ||
| it('falls back to one full-length segment when auto-segment finds none', async () => { | ||
| const controls = makeControls(); | ||
| const { result } = renderHook(() => | ||
| useGuidedPhraseSegments(mediafile, controls, { | ||
| namedRegion: 'BT:en', | ||
| persistSegments: true, | ||
| }) | ||
| ); | ||
|
|
||
| let ok: boolean | undefined; | ||
| await act(async () => { | ||
| ok = await result.current.ensureSegments(); | ||
| }); | ||
|
|
||
| expect(ok).toBe(true); | ||
| expect(hasPhraseRegions(result.current.phraseSegString)).toBe(true); | ||
| }); | ||
|
|
||
| it('still returns false while the player has no audio loaded', async () => { | ||
| const controls = makeControls({ getDuration: () => 0 }); | ||
| const { result } = renderHook(() => | ||
| useGuidedPhraseSegments(mediafile, controls, { | ||
| namedRegion: 'BT:en', | ||
| persistSegments: true, | ||
| }) | ||
| ); | ||
|
|
||
| let ok: boolean | undefined; | ||
| await act(async () => { | ||
| ok = await result.current.ensureSegments(); | ||
| }); | ||
|
|
||
| expect(ok).toBe(false); | ||
| }); | ||
| }); |
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,109 @@ | ||
| /** | ||
| * TT-7621 regression tests for the reference-audio blob loader. | ||
| * | ||
| * Two ways `useFetchMediaBlob` could leave the Phrase Back Translate step's top | ||
| * player stuck on "Loading..." forever (context `loading` never clears because | ||
| * `fetching.current` is never reset): | ||
| * | ||
| * 1. The signed URL resolves but the download is an error page (S3/CloudFront | ||
| * returns HTML/XML with a 200). The old code dispatched neither FETCHED nor | ||
| * ERROR for a text/html|application/xml blob, so `blobStat` stayed PENDING. | ||
| * 2. A persistently-403 object drove an unbounded RESET->PENDING->403 loop, | ||
| * re-issuing a signed-URL request and a blob GET on every turn (the network | ||
| * storm in the hung-PBT report), and never reaching a terminal state. | ||
| * | ||
| * Both must end in ERROR so the caller can stop waiting. | ||
| */ | ||
| import { renderHook, act, waitFor } from '@testing-library/react'; | ||
|
|
||
| const mockMediaClean = { | ||
| status: 0, | ||
| error: null, | ||
| url: '', | ||
| id: '', | ||
| remoteId: '', | ||
| cancelled: false, | ||
| }; | ||
|
|
||
| // eslint-disable-next-line prefer-const | ||
| let mockMediaState: typeof mockMediaClean = { ...mockMediaClean }; | ||
| const mockFetchMediaUrl = jest.fn(); | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| let mockLoadBlob: (url: string, cb: (u: string, b?: Blob) => void) => void; | ||
|
|
||
| jest.mock('./useFetchMediaUrl', () => ({ | ||
| __esModule: true, | ||
| mediaClean: mockMediaClean, | ||
| default: () => ({ | ||
| fetchMediaUrl: mockFetchMediaUrl, | ||
| mediaState: mockMediaState, | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('../context/useGlobal', () => ({ | ||
| useGlobal: () => [undefined, () => {}], | ||
| })); | ||
|
|
||
| jest.mock('../utils/loadBlob', () => ({ | ||
| loadBlob: (url: string, cb: (u: string, b?: Blob) => void) => | ||
| mockLoadBlob(url, cb), | ||
| })); | ||
|
|
||
| import { useFetchMediaBlob, BlobStatus } from './useFetchMediaBlob'; | ||
|
|
||
| beforeEach(() => { | ||
| mockMediaState = { ...mockMediaClean }; | ||
| mockFetchMediaUrl.mockReset(); | ||
| }); | ||
|
|
||
| describe('useFetchMediaBlob (TT-7621)', () => { | ||
| it('dispatches ERROR (not a permanent PENDING) when the download is an error page', async () => { | ||
| mockLoadBlob = (url, cb) => | ||
| cb(url, new Blob(['<Error>nope</Error>'], { type: 'application/xml' })); | ||
|
|
||
| const { result, rerender } = renderHook(() => useFetchMediaBlob()); | ||
| act(() => { | ||
| result.current[1]('m1'); | ||
| }); | ||
|
|
||
| // The signed URL arrives; the effect now runs loadBlob against it. | ||
| mockMediaState = { | ||
| ...mockMediaClean, | ||
| id: 'm1', | ||
| url: 'https://s3.invalid/x.wav', | ||
| }; | ||
| act(() => { | ||
| rerender(); | ||
| }); | ||
|
|
||
| await waitFor(() => | ||
| expect(result.current[0].blobStat).toBe(BlobStatus.ERROR) | ||
| ); | ||
| }); | ||
|
|
||
| it('reaches a terminal ERROR after bounded 403 retries instead of looping forever', async () => { | ||
| mockLoadBlob = (_url, cb) => cb('403 Forbidden', undefined); | ||
|
|
||
| const { result, rerender } = renderHook(() => useFetchMediaBlob()); | ||
| act(() => { | ||
| result.current[1]('m1'); | ||
| }); | ||
|
|
||
| // Feed a fresh signed URL each turn, exactly as a real re-request would, and | ||
| // let the RESET/PENDING cycle run. It must converge, not spin. | ||
| for (let i = 0; i < 16; i++) { | ||
| mockMediaState = { | ||
| ...mockMediaClean, | ||
| id: 'm1', | ||
| url: `https://s3.invalid/x.wav?sig=${i}`, | ||
| }; | ||
| // eslint-disable-next-line no-await-in-loop | ||
| await act(async () => { | ||
| rerender(); | ||
| }); | ||
| if (result.current[0].blobStat === BlobStatus.ERROR) break; | ||
| } | ||
|
|
||
| expect(result.current[0].blobStat).toBe(BlobStatus.ERROR); | ||
| }); | ||
| }); |
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
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.
Good catch — fixed in b0fcd8d. The
[mediaId]effect now dispatchesBlobStatus.IDLE(not PENDING) whenmediaIdis empty, so a consumer readingloadingfromblobStat === PENDINGno longer shows a spurious spinner before the firstfetchBlob.