Split the QQ NT client lifecycle / hook injection layer out of @snowluma/core into its own self-contained package. The new bridge package owns: - native hook addon loader (injector) - HookManager + per-PID HookSession orchestration - PipeWatcher for QQ process discovery - QqHookClient pipe protocol - qq-port-probe for early UIN sniffing The hook layer used to type its main collaborator as `BridgeManager` directly. To keep the new package free of any dependency on @snowluma/core, the cross-package coupling is now expressed via a 3-method `BridgeManagerSink` interface that lives in the bridge package. BridgeManager (in core) satisfies the interface structurally with no source changes; the top-level app/webui still inject it the same way. Pure file relocation otherwise: git mv preserves history at 100% on every file, the only logic edit is the interface introduction in hook-manager.ts and an updated `nativeSearchDirs()` offset (one fewer `..` since hook now lives at packages/bridge/src instead of packages/core/src/hook).
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { mkdtemp, rm, writeFile } from 'fs/promises';
|
|
import os from 'os';
|
|
import path from 'path';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { listLiveLinuxPipePids } from '../src/qq-hook-client';
|
|
|
|
let tmpDir: string | null = null;
|
|
|
|
async function makeRuntimeDir(): Promise<string> {
|
|
tmpDir = await mkdtemp(path.join(os.tmpdir(), 'snowluma-hook-'));
|
|
return tmpDir;
|
|
}
|
|
|
|
afterEach(async () => {
|
|
if (!tmpDir) return;
|
|
await rm(tmpDir, { recursive: true, force: true });
|
|
tmpDir = null;
|
|
});
|
|
|
|
describe('listLiveLinuxPipePids', () => {
|
|
it('ignores stale-looking control socket names when the probe rejects them', async () => {
|
|
const runtimeDir = await makeRuntimeDir();
|
|
await writeFile(path.join(runtimeDir, 'mojo.55.control.sock'), '');
|
|
await writeFile(path.join(runtimeDir, 'mojo.55.recv.sock'), '');
|
|
|
|
const pids = await listLiveLinuxPipePids(runtimeDir, async () => false);
|
|
|
|
expect([...pids]).toEqual([]);
|
|
});
|
|
|
|
it('returns only connectable control sockets', async () => {
|
|
const runtimeDir = await makeRuntimeDir();
|
|
await writeFile(path.join(runtimeDir, 'mojo.55.control.sock'), '');
|
|
await writeFile(path.join(runtimeDir, 'mojo.56.control.sock'), '');
|
|
await writeFile(path.join(runtimeDir, 'mojo.56.recv.sock'), '');
|
|
await writeFile(path.join(runtimeDir, 'mojo.not-a-pid.control.sock'), '');
|
|
|
|
const probe = vi.fn(async (socketPath: string) => socketPath.endsWith('mojo.56.control.sock'));
|
|
const pids = await listLiveLinuxPipePids(runtimeDir, probe);
|
|
|
|
expect([...pids]).toEqual([56]);
|
|
expect(probe).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|