fix(integration): serialize browser add inputs

- serialize extension and deep-link Add-window events
- acknowledge successful extension handling at the frontend boundary
- add regression coverage for ordered input processing
This commit is contained in:
NimBold
2026-08-12 20:20:55 +03:30
parent e9ad226b93
commit 4b43e8ed5c
4 changed files with 85 additions and 12 deletions
+45
View File
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import { createSerialTaskQueue } from './serialTaskQueue';
describe('createSerialTaskQueue', () => {
it('runs tasks in enqueue order and waits for each previous task', async () => {
const queue = createSerialTaskQueue();
const events: string[] = [];
let releaseFirst!: () => void;
const firstReleased = new Promise<void>(resolve => {
releaseFirst = resolve;
});
const first = queue(async () => {
events.push('first-start');
await firstReleased;
events.push('first-end');
});
const second = queue(async () => {
events.push('second');
});
await new Promise<void>(resolve => setTimeout(resolve, 0));
expect(events).toEqual(['first-start']);
releaseFirst();
await Promise.all([first, second]);
expect(events).toEqual(['first-start', 'first-end', 'second']);
});
it('continues with later tasks after a failed task', async () => {
const queue = createSerialTaskQueue();
const events: string[] = [];
const failed = queue(async () => {
events.push('failed');
throw new Error('expected failure');
});
const continued = queue(async () => {
events.push('continued');
});
await expect(failed).rejects.toThrow('expected failure');
await expect(continued).resolves.toBeUndefined();
expect(events).toEqual(['failed', 'continued']);
});
});
+13
View File
@@ -0,0 +1,13 @@
export type SerialTask = () => void | Promise<void>;
export type SerialTaskQueue = (task: SerialTask) => Promise<void>;
export const createSerialTaskQueue = (): SerialTaskQueue => {
let tail: Promise<void> = Promise.resolve();
return task => {
const next = tail.catch(() => undefined).then(task);
tail = next.catch(() => undefined);
return next;
};
};