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:
20 files changed
+1304
-154
No files matched your search
@@ -80,29 +80,57 @@ export class HttpPostAdapter extends IOneBotNetworkAdapter<HttpClientNetwork> {
|
||||
}
|
||||
|
||||
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
||||
const startedAt = Date.now();
|
||||
let response: Response;
|
||||
try {
|
||||
const response = await fetch(config.url, {
|
||||
response = await fetch(config.url, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: payload,
|
||||
signal: AbortSignal.timeout(timeoutMs),
|
||||
});
|
||||
if (response.ok) {
|
||||
this.lastDelivery = { at: Date.now(), ok: true };
|
||||
const contentType = response.headers.get('content-type') ?? '';
|
||||
if (contentType.includes('application/json')) {
|
||||
const body = await response.text();
|
||||
if (body.trim()) {
|
||||
await this.handleQuickOperation(event, body);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.lastDelivery = { at: Date.now(), ok: false };
|
||||
this.log.warn('[%s] POST %s returned %d', this.name, config.url, response.status);
|
||||
}
|
||||
} catch (error) {
|
||||
this.lastDelivery = { at: Date.now(), ok: false };
|
||||
this.log.warn('[%s] POST %s failed: %s', this.name, config.url, error instanceof Error ? error.message : String(error));
|
||||
this.log.trace(() => [
|
||||
'http_report_terminal target=%s outcome=transport_failed ms=%d error=%s',
|
||||
this.name,
|
||||
Date.now() - startedAt,
|
||||
error instanceof Error ? (error.stack ?? error.message) : String(error),
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
this.lastDelivery = { at: Date.now(), ok: false };
|
||||
this.log.warn('[%s] POST %s returned %d', this.name, config.url, response.status);
|
||||
this.log.trace(
|
||||
'http_report_terminal target=%s outcome=rejected status=%d ms=%d',
|
||||
this.name,
|
||||
response.status,
|
||||
Date.now() - startedAt,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.lastDelivery = { at: Date.now(), ok: true };
|
||||
this.log.trace(
|
||||
'http_report_terminal target=%s outcome=accepted status=%d ms=%d',
|
||||
this.name,
|
||||
response.status,
|
||||
Date.now() - startedAt,
|
||||
);
|
||||
const contentType = response.headers.get('content-type') ?? '';
|
||||
if (!contentType.includes('application/json')) return;
|
||||
try {
|
||||
const body = await response.text();
|
||||
if (body.trim()) await this.handleQuickOperation(event, body);
|
||||
} catch (error) {
|
||||
this.log.warn(
|
||||
'[%s] quick operation response read failed: %s',
|
||||
this.name,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user