-
Notifications
You must be signed in to change notification settings - Fork 7
fix(pwa): flush pending state before a forced SW-update reload (DA-02) #517
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
812be32
fix(pwa): flush pending state before a forced SW-update reload (DA-02)
qnbs 8fb9c2b
fix(pwa): close DA-02 review-wave gaps in the flush-before-reload fix
qnbs 6868b91
fix(pwa): close DA-02's second review wave (codex P1/P2)
qnbs 75802ef
docs(pwa): correct DA-02 comments and PR description to match actual …
qnbs daf44e1
fix(pwa): close DA-02's third review wave — real implementation bugs
qnbs 3eec3da
fix(pwa): bound the pre-reload flush wait (DA-02, codex)
qnbs 21a9dfc
docs(pwa): conform QNBS-v3 comments to the literal repo format
qnbs 67328f9
fix(storage): dedupe concurrent auto-snapshot attempts (DA-02, codex)
qnbs 8d7f4ab
fix(pwa): compare only versionControl's persisted fields (DA-02, codex)
qnbs 1e6c418
fix(pwa): wait for coordinator drain, add real-IDB round trip (DA-02,…
qnbs 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
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
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
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,94 @@ | ||
| // QNBS-v3: proves a saveProject() call arriving before the first snapshot's success callback runs never starts a duplicate concurrent auto-snapshot. | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| vi.mock('../../services/logger', () => { | ||
| const noopLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn(), debug: vi.fn() }; | ||
| return { | ||
| logger: noopLogger, | ||
| createLogger: () => ({ ...noopLogger, withContext: () => ({ ...noopLogger }) }), | ||
| }; | ||
| }); | ||
|
|
||
| const fakeStore = { | ||
| put: vi.fn().mockImplementation(() => { | ||
| const r: Record<string, unknown> = {}; | ||
| Promise.resolve().then(() => { | ||
| if (typeof r['onsuccess'] === 'function') (r['onsuccess'] as () => void)(); | ||
| }); | ||
| return r; | ||
| }), | ||
| count: vi.fn().mockImplementation(() => { | ||
| const r = { result: 0 } as Record<string, unknown>; | ||
| Promise.resolve().then(() => { | ||
| if (typeof r['onsuccess'] === 'function') (r['onsuccess'] as () => void)(); | ||
| }); | ||
| return r; | ||
| }), | ||
| }; | ||
|
|
||
| const fakeDb = { | ||
| objectStoreNames: { contains: () => true }, | ||
| transaction: vi.fn().mockReturnValue({ objectStore: () => fakeStore }), | ||
| }; | ||
|
|
||
| async function flushMicrotasks(): Promise<void> { | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
| } | ||
|
|
||
| describe('dbService — saveProject auto-snapshot in-flight guard (DA-02, codex)', () => { | ||
| let saveSliceMock: ReturnType<typeof vi.fn>; | ||
| let createSnapshotMock: ReturnType<typeof vi.fn>; | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetModules(); | ||
| saveSliceMock = vi.fn().mockResolvedValue(undefined); | ||
| createSnapshotMock = vi.fn(); | ||
| }); | ||
|
|
||
| async function getService() { | ||
| const mod = await import('../../services/dbService'); | ||
| const svc = mod.dbService as unknown as Record<string, unknown>; | ||
| svc['stateDb'] = fakeDb; | ||
| svc['dataDb'] = fakeDb; | ||
| svc['saveSlice'] = saveSliceMock; | ||
| svc['createSnapshot'] = createSnapshotMock; | ||
| // Force the 5-minute interval to already have elapsed. | ||
| svc['lastAutoSnapshotTime'] = 0; | ||
| return mod.dbService; | ||
| } | ||
|
|
||
| const project = { title: 'T', manuscript: [{ id: '1', title: 'S', content: 'x' }] }; | ||
|
|
||
| it('does not start a second concurrent auto-snapshot while the first is still pending', async () => { | ||
| let resolveFirstSnapshot: (id: number) => void = () => {}; | ||
| createSnapshotMock.mockImplementationOnce( | ||
| () => new Promise<number>((resolve) => { resolveFirstSnapshot = resolve; }), | ||
| ); | ||
|
|
||
| const svc = await getService(); | ||
| const firstSave = svc.saveProject({ present: { data: project } } as never); | ||
| const secondSave = svc.saveProject({ present: { data: project } } as never); | ||
|
|
||
| await Promise.all([firstSave, secondSave]); | ||
| await flushMicrotasks(); | ||
| expect(createSnapshotMock).toHaveBeenCalledTimes(1); | ||
|
|
||
| resolveFirstSnapshot(1); | ||
| await flushMicrotasks(); | ||
| }); | ||
|
|
||
| it('allows a new auto-snapshot once the prior one has settled and the interval has elapsed again', async () => { | ||
| createSnapshotMock.mockResolvedValueOnce(1); | ||
| const svc = await getService(); | ||
|
|
||
| await svc.saveProject({ present: { data: project } } as never); | ||
| await flushMicrotasks(); | ||
| expect(createSnapshotMock).toHaveBeenCalledTimes(1); | ||
|
|
||
| (svc as unknown as Record<string, unknown>)['lastAutoSnapshotTime'] = 0; | ||
| createSnapshotMock.mockResolvedValueOnce(2); | ||
| await svc.saveProject({ present: { data: project } } as never); | ||
| await flushMicrotasks(); | ||
| expect(createSnapshotMock).toHaveBeenCalledTimes(2); | ||
| }); | ||
| }); |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.