feat(bridge): detect local QQ accounts with shared process snapshots (#525)
Read QQ account databases and attribute identities to their owning processes. Share snapshots across REST, watcher updates and login reconciliation, discard stale results, and report detection failures.
This commit is contained in:
1 parent
8e24995fc3
commit
f6ca9d5f65
38 files changed
+2979
-1534
No files matched your search
@@ -44,7 +44,7 @@ describe('API client request deadline', () => {
|
||||
await rejection;
|
||||
});
|
||||
|
||||
it('cancels a login probe without preventing a later retry', async () => {
|
||||
it('cancels a request without preventing a later retry', async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockImplementationOnce(
|
||||
@@ -60,29 +60,22 @@ describe('API client request deadline', () => {
|
||||
}),
|
||||
)
|
||||
.mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
info: { port: 0, uin: '', identityKnown: false },
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
},
|
||||
),
|
||||
new Response(JSON.stringify({ list: [] }), {
|
||||
status: 200,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
}),
|
||||
);
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const client = createApiClient({ tokenStore });
|
||||
const controller = new AbortController();
|
||||
|
||||
const cancelled = client.processes.probeLoginInfo(4242, controller.signal);
|
||||
const cancelled = client.request('/api/processes', { signal: controller.signal });
|
||||
controller.abort();
|
||||
|
||||
await expect(cancelled).rejects.toMatchObject({ name: 'AbortError' });
|
||||
await expect(client.processes.probeLoginInfo(4242)).resolves.toEqual({
|
||||
port: 0,
|
||||
uin: '',
|
||||
identityKnown: false,
|
||||
});
|
||||
await expect(
|
||||
client.request('/api/processes').then((response) => response.json()),
|
||||
).resolves.toEqual({ list: [] });
|
||||
});
|
||||
|
||||
it('settles a pending login with a retryable timeout message', async () => {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { ProcessesPage } from '../src/components/pages/processes-page';
|
||||
import type { HookProcessInfo } from '../src/types';
|
||||
|
||||
const state = vi.hoisted(() => ({ processList: [] as HookProcessInfo[] }));
|
||||
|
||||
vi.mock('@/contexts/AppStateContext', () => ({
|
||||
useAppState: () => ({
|
||||
processList: state.processList,
|
||||
processOps: { statusOf: () => null, banner: null },
|
||||
refreshProcesses: vi.fn(),
|
||||
resources: { processList: { ready: true, error: '' } },
|
||||
}),
|
||||
}));
|
||||
vi.mock('@/contexts/LayoutContext', () => ({
|
||||
useLayout: () => ({ pages: { processesSort: 'pid' }, setPages: vi.fn() }),
|
||||
}));
|
||||
vi.mock('@/contexts/ThemeContext', () => ({
|
||||
useTheme: () => ({ appearance: { disableMotion: true } }),
|
||||
}));
|
||||
vi.mock('@/components/confirm-dialog', () => ({ ConfirmDialog: () => null }));
|
||||
|
||||
function renderProcess(overrides: Partial<HookProcessInfo>) {
|
||||
state.processList = [
|
||||
{
|
||||
pid: 4242,
|
||||
name: 'qq',
|
||||
path: '',
|
||||
injected: false,
|
||||
connected: false,
|
||||
loggedIn: false,
|
||||
uin: '0',
|
||||
status: 'available',
|
||||
error: '',
|
||||
method: '',
|
||||
account: null,
|
||||
...overrides,
|
||||
},
|
||||
];
|
||||
return renderToStaticMarkup(<ProcessesPage />);
|
||||
}
|
||||
|
||||
describe('process account labels', () => {
|
||||
it('does not label an unidentified process as signed out', () => {
|
||||
const markup = renderProcess({});
|
||||
expect(markup).toContain('PID 4242');
|
||||
expect(markup).not.toContain('未登录');
|
||||
expect(markup).not.toContain('/avatar/');
|
||||
});
|
||||
|
||||
it('shows the locally detected identity before hook login', () => {
|
||||
const markup = renderProcess({ account: { uin: '10001', nickname: 'Alice' } });
|
||||
expect(markup).toContain('Alice');
|
||||
expect(markup).toContain('/avatar/10001');
|
||||
expect(markup).toContain('QQ 10001');
|
||||
});
|
||||
|
||||
it('uses native login identity without an account database', () => {
|
||||
const markup = renderProcess({ loggedIn: true, uin: '10002', status: 'online' });
|
||||
expect(markup).toContain('/avatar/10002');
|
||||
expect(markup).toContain('已在线');
|
||||
});
|
||||
|
||||
it('does not apply a stale local nickname to a newly logged-in account', () => {
|
||||
const markup = renderProcess({
|
||||
loggedIn: true,
|
||||
uin: '10002',
|
||||
status: 'online',
|
||||
account: { uin: '10001', nickname: 'Alice' },
|
||||
});
|
||||
expect(markup).toContain('/avatar/10002');
|
||||
expect(markup).not.toContain('Alice');
|
||||
expect(markup).not.toContain('10001');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user