feat(onebot): complete trace operation chains

Make short TRACE captures independently explain OneBot action and event lifecycles from complete input through a truthful terminal conclusion. Preserve request correlation across asynchronous work while keeping disabled TRACE paths allocation-free and lazy.

Cover shutdown rejection, stream cancellation, event conversion and suppression, reporter invocation settlement, and HTTP delivery outcomes without changing established transport or observer behavior. Add focused regression coverage for lifecycle uniqueness, context reuse, disconnect handling, and quiesce ingress boundaries.
This commit is contained in:
DrSmoothl committed 2026-07-30 17:13:40 +08:00
1 parent b9104f0a5b
commit f9c4063fc5
20 files changed
+1304 -154

No files matched your search

@@ -130,6 +130,48 @@ describe('HttpServerAdapter — optional WebSocket transport', () => {
});
});
it('records and drops a valid WebSocket action after API quiesce', async () => {
const ctx = context();
const api = ctx.api as unknown as {
isAcceptingActions: boolean;
processStreamRequest: ReturnType<typeof vi.fn>;
traceQuiescedStreamRequest: ReturnType<typeof vi.fn>;
};
api.traceQuiescedStreamRequest = vi.fn();
const config = {
name: 'quiesced-websocket',
host: '127.0.0.1',
port: 0,
path: '/',
enabled: true,
enableWebSocket: true,
messageFormat: 'array',
reportSelfMessage: false,
} satisfies HttpServerNetwork;
adapter = new HttpServerAdapter(config.name, config, ctx);
await adapter.open();
const address = (adapter as unknown as { server: http.Server }).server.address() as AddressInfo;
socket = new WebSocket(`ws://127.0.0.1:${String(address.port)}/api`);
await waitForOpen(socket);
const received = vi.fn();
socket.on('message', received);
api.isAcceptingActions = false;
const raw = JSON.stringify({
action: 'get_status',
params: { detail: 'complete' },
echo: 'dropped',
});
socket.send(raw);
await vi.waitFor(() => {
expect(api.traceQuiescedStreamRequest).toHaveBeenCalledWith(raw);
});
await new Promise((resolve) => setImmediate(resolve));
expect(api.processStreamRequest).not.toHaveBeenCalled();
expect(received).not.toHaveBeenCalled();
});
it('disconnects authenticated sockets when the shared token changes without rebinding HTTP', async () => {
const config = {
name: 'rotating-token',