fix(bridge): bound process operations
This commit is contained in:
5 files changed
+137
-13
No files matched your search
@@ -116,6 +116,33 @@ describe('HookSession — load', () => {
|
||||
expect(info.status).toBe('connecting');
|
||||
});
|
||||
|
||||
it('keeps loading pending until asynchronous component loading completes', async () => {
|
||||
let finishLoading!: (result: { method: 'loadModuleManual'; handle: ManualMapHandle }) => void;
|
||||
const loading = new Promise<{ method: 'loadModuleManual'; handle: ManualMapHandle }>(resolve => {
|
||||
finishLoading = resolve;
|
||||
});
|
||||
const injector = {
|
||||
inject: vi.fn(() => loading),
|
||||
unload: vi.fn(),
|
||||
};
|
||||
const session = new HookSession(1234, {
|
||||
injector,
|
||||
makeClient: () => new FakeClient() as unknown as QqHookClient,
|
||||
pipeWatcher: { isPipeLive: () => false },
|
||||
});
|
||||
|
||||
const load = session.load();
|
||||
await flush();
|
||||
|
||||
expect(session.status).toBe('loading');
|
||||
finishLoading({ method: 'loadModuleManual', handle: DUMMY_HANDLE });
|
||||
await expect(load).resolves.toMatchObject({
|
||||
status: 'connecting',
|
||||
method: 'loadModuleManual',
|
||||
injected: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('inject failure → status error, error message captured', async () => {
|
||||
const injector = {
|
||||
inject: vi.fn(() => { throw new Error('inject boom'); }),
|
||||
@@ -130,6 +157,37 @@ describe('HookSession — load', () => {
|
||||
expect(info.status).toBe('error');
|
||||
expect(info.error).toBe('inject boom');
|
||||
});
|
||||
|
||||
it('can retry after asynchronous component loading fails', async () => {
|
||||
const injector = {
|
||||
inject: vi
|
||||
.fn()
|
||||
.mockRejectedValueOnce(new Error('component loading timed out'))
|
||||
.mockResolvedValueOnce({
|
||||
method: 'loadModuleManual' as const,
|
||||
handle: DUMMY_HANDLE,
|
||||
}),
|
||||
unload: vi.fn(),
|
||||
};
|
||||
const session = new HookSession(1234, {
|
||||
injector,
|
||||
makeClient: () => new FakeClient() as unknown as QqHookClient,
|
||||
pipeWatcher: { isPipeLive: () => false },
|
||||
});
|
||||
|
||||
await expect(session.load()).resolves.toMatchObject({
|
||||
status: 'error',
|
||||
error: 'component loading timed out',
|
||||
injected: false,
|
||||
});
|
||||
await expect(session.load()).resolves.toMatchObject({
|
||||
status: 'connecting',
|
||||
method: 'loadModuleManual',
|
||||
injected: true,
|
||||
error: '',
|
||||
});
|
||||
expect(injector.inject).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('HookSession — pipe up/down → connect lifecycle', () => {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const execMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock('child_process', () => ({ exec: execMock }));
|
||||
|
||||
import { probeQqLoginInfo } from '../src/qq-port-probe';
|
||||
|
||||
describe('probeQqLoginInfo — bounded execution', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
execMock.mockReset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('allows a later probe after a timed-out attempt', async () => {
|
||||
execMock.mockImplementation(() => undefined);
|
||||
const first = probeQqLoginInfo(4242);
|
||||
await vi.advanceTimersByTimeAsync(10_000);
|
||||
await expect(first).resolves.toBeNull();
|
||||
|
||||
execMock
|
||||
.mockImplementationOnce((_command, _options, callback) => {
|
||||
callback(null, { stdout: '', stderr: '' });
|
||||
})
|
||||
.mockImplementationOnce((_command, _options, callback) => {
|
||||
callback(null, { stdout: '1\n', stderr: '' });
|
||||
});
|
||||
|
||||
await expect(probeQqLoginInfo(4242)).resolves.toEqual({
|
||||
port: 0,
|
||||
uin: '',
|
||||
loggedIn: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user